Merge remote-tracking branch 'refs/remotes/origin/develop' into develop
This commit is contained in:
44
src/main/java/com/olympus/apollo/config/ApolloConfig.java
Normal file
44
src/main/java/com/olympus/apollo/config/ApolloConfig.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package com.olympus.apollo.config;
|
||||
|
||||
import org.springframework.ai.azure.openai.AzureOpenAiEmbeddingModel;
|
||||
import org.springframework.ai.embedding.EmbeddingModel;
|
||||
import org.springframework.ai.openai.OpenAiEmbeddingModel;
|
||||
import org.springframework.ai.vectorstore.ChromaVectorStore;
|
||||
import org.springframework.ai.vectorstore.VectorStore;
|
||||
import org.springframework.ai.vectorstore.azure.AzureVectorStore;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
@Configuration
|
||||
public class ApolloConfig {
|
||||
|
||||
private final OpenAiEmbeddingModel openAiEmbeddingModel;
|
||||
private final AzureOpenAiEmbeddingModel azureOpenAiEmbeddingModel;
|
||||
|
||||
|
||||
// Autowiring beans from both libraries
|
||||
public ApolloConfig(OpenAiEmbeddingModel myServiceLib1,
|
||||
AzureOpenAiEmbeddingModel azureOpenAiEmbeddingModel) {
|
||||
this.openAiEmbeddingModel = myServiceLib1;
|
||||
this.azureOpenAiEmbeddingModel = azureOpenAiEmbeddingModel;
|
||||
|
||||
|
||||
}
|
||||
|
||||
// Re-declaring and marking one as primary
|
||||
@Bean
|
||||
public EmbeddingModel primaryMyService() {
|
||||
return openAiEmbeddingModel; // Choose the one you want as primary
|
||||
}
|
||||
|
||||
// Optionally declare the other bean without primary
|
||||
@Bean
|
||||
@Primary
|
||||
public EmbeddingModel secondaryMyService() {
|
||||
return azureOpenAiEmbeddingModel; // The other one
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,30 +1,22 @@
|
||||
package com.olympus.apollo.config;
|
||||
|
||||
import com.azure.core.credential.AzureKeyCredential;
|
||||
import com.azure.search.documents.indexes.SearchIndexClient;
|
||||
import com.azure.search.documents.indexes.SearchIndexClientBuilder;
|
||||
import org.springframework.ai.azure.openai.AzureOpenAiEmbeddingModel;
|
||||
import org.springframework.ai.embedding.EmbeddingModel;
|
||||
/*import org.springframework.ai.openai.OpenAiEmbeddingModel;
|
||||
import org.springframework.ai.openai.api.OpenAiApi;
|
||||
import org.springframework.ai.vectorstore.MongoDBAtlasVectorStore;*/
|
||||
|
||||
import org.springframework.ai.vectorstore.VectorStore;
|
||||
import org.springframework.ai.vectorstore.azure.AzureVectorStore;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.SpringBootConfiguration;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Configuration
|
||||
public class EmbeddingConfig {
|
||||
import org.springframework.ai.embedding.EmbeddingModel;
|
||||
import org.springframework.ai.vectorstore.VectorStore;
|
||||
import org.springframework.ai.vectorstore.azure.AzureVectorStore;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.azure.core.credential.AzureKeyCredential;
|
||||
import com.azure.search.documents.indexes.SearchIndexClient;
|
||||
import com.azure.search.documents.indexes.SearchIndexClientBuilder;
|
||||
|
||||
//@Configuration
|
||||
public class VectorStoreConfig {
|
||||
|
||||
|
||||
@Value("${spring.ai.vectorstore.azure.api-key}")
|
||||
@@ -42,7 +34,7 @@ public class EmbeddingConfig {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public VectorStore vectorStore(SearchIndexClient searchIndexClient, @Qualifier("azureOpenAiEmbeddingModel") EmbeddingModel embeddingModel) {
|
||||
public VectorStore azureVectorStore(SearchIndexClient searchIndexClient, @Qualifier("azureOpenAiEmbeddingModel") EmbeddingModel embeddingModel) {
|
||||
List<AzureVectorStore.MetadataField> fields = new ArrayList<>();
|
||||
|
||||
fields.add(AzureVectorStore.MetadataField.text("KsApplicationName"));
|
||||
@@ -56,3 +48,6 @@ public class EmbeddingConfig {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -3,10 +3,21 @@ package com.olympus.apollo.controllers.FeApi;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.olympus.model.apollo.KSDocument;
|
||||
import com.olympus.apollo.repository.KSDocumentRepository;
|
||||
import com.olympus.apollo.services.KSDocumentService;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import java.nio.file.Files;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/fe-api/ksdocuments")
|
||||
@@ -14,12 +25,14 @@ public class KsDocumentController {
|
||||
|
||||
@Autowired
|
||||
private KSDocumentRepository ksDocumentREpository;
|
||||
|
||||
|
||||
@Autowired
|
||||
private KSDocumentService ksDocumentService;
|
||||
|
||||
@GetMapping("")
|
||||
public List<KSDocument> getDocuments() {
|
||||
|
||||
List<KSDocument> result = (List<KSDocument>) ksDocumentREpository.findAll();
|
||||
List<KSDocument> result = ksDocumentService.findByProjectNameAndApplicationName();
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -30,4 +43,33 @@ public class KsDocumentController {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/* @PostMapping("/downloadKSDocument")
|
||||
public ResponseEntity<Resource> downloadFile(@RequestBody KSDocument doc) {
|
||||
try {
|
||||
// Percorso al file
|
||||
Path filePath = Paths.get(doc.getFilePath()).normalize();
|
||||
Resource resource = new UrlResource(filePath.toUri());
|
||||
|
||||
if (!resource.exists()) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
// Configurazione della risposta HTTP
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getFilename() + "\"")
|
||||
.body(resource);
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.internalServerError().build();
|
||||
}
|
||||
}*/
|
||||
|
||||
@PostMapping("/downloadKSDocument")
|
||||
public ResponseEntity<Resource> downloadFile(@RequestBody KSDocument doc) {
|
||||
|
||||
return ksDocumentService.downloadKSDocument(doc);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.olympus.apollo.controllers;
|
||||
|
||||
import java.util.Optional;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.olympus.apollo.repository.ProjectRepository;
|
||||
import com.olympus.apollo.security.entity.User;
|
||||
import com.olympus.apollo.services.ProjectService;
|
||||
import com.olympus.model.Application;
|
||||
import com.olympus.model.Project;
|
||||
|
||||
@RestController
|
||||
public class ProjectController {
|
||||
|
||||
@Autowired
|
||||
ProjectService projectService;
|
||||
|
||||
@Autowired
|
||||
ProjectRepository projectRepo;
|
||||
|
||||
@GetMapping("/userProjects")
|
||||
public Iterable<Project> getUserProjects() {
|
||||
return projectService.getListProjectsByUser();
|
||||
}
|
||||
|
||||
@PostMapping("/updateSelectedProject")
|
||||
public User setSelectedProjects(@RequestBody Project projectId) {
|
||||
return projectService.updateUserSelectedProject(projectId);
|
||||
}
|
||||
|
||||
@PostMapping("/updateSelectedApplication")
|
||||
public User setSelectedApplication(@RequestBody Application application) {
|
||||
return projectService.updateUserSelectedApplication(application);
|
||||
}
|
||||
@PostMapping("/getProject")
|
||||
public Optional<Project> getUserProjects(@RequestBody String projectId) {
|
||||
return projectRepo.findById(projectId);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.olympus.apollo.controllers;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.ai.document.Document;
|
||||
import org.springframework.ai.vectorstore.SearchRequest;
|
||||
import org.springframework.ai.vectorstore.VectorStore;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.olympus.apollo.dto.VectorSearchRequest;
|
||||
|
||||
import ch.qos.logback.classic.Logger;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/vsearch")
|
||||
|
||||
public class SearchDocController {
|
||||
|
||||
@Autowired
|
||||
private VectorStore vectorStore;
|
||||
|
||||
Logger logger = (Logger) LoggerFactory.getLogger(SearchDocController.class);
|
||||
|
||||
@PostMapping("/doc_search")
|
||||
public List<String> vectorSearch(@RequestBody VectorSearchRequest vectorSearchRequest) {
|
||||
|
||||
SearchRequest request = SearchRequest.defaults()
|
||||
.withQuery(vectorSearchRequest.getQuery())
|
||||
.withTopK(vectorSearchRequest.getTopK())
|
||||
.withSimilarityThreshold(vectorSearchRequest.getThreshold());
|
||||
|
||||
if(vectorSearchRequest.getFilterQuery() != null && !vectorSearchRequest.getFilterQuery().isEmpty()){
|
||||
request.withFilterExpression(vectorSearchRequest.getFilterQuery());
|
||||
logger.info("Using Filter expression: " + vectorSearchRequest.getFilterQuery());
|
||||
}
|
||||
|
||||
List<Document> docs = this.vectorStore.similaritySearch(request);
|
||||
logger.info("Number of VDB retrieved documents: " + docs.size());
|
||||
|
||||
List<String> results = new ArrayList<>();
|
||||
for(Document doc : docs){
|
||||
results.add(doc.getContent());
|
||||
}
|
||||
return results;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.olympus.apollo.dto;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class VectorSearchRequest {
|
||||
|
||||
|
||||
private String query;
|
||||
private String filterQuery;
|
||||
private int topK;
|
||||
private float threshold;
|
||||
|
||||
}
|
||||
@@ -1,7 +1,11 @@
|
||||
package com.olympus.apollo.repository;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
import org.springframework.data.mongodb.repository.Query;
|
||||
import org.springframework.data.repository.query.Param;
|
||||
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
@@ -13,4 +17,11 @@ import com.olympus.model.apollo.KSDocument;
|
||||
public interface KSDocumentRepository extends MongoRepository<KSDocument, String> {
|
||||
|
||||
public Iterable<KSDocument> findAllByIngestionStatus(String status);
|
||||
|
||||
@Query("{ 'ingestionInfo.metadata.KsProjectName': ?0, 'ingestionInfo.metadata.KsApplicationName': ?1 }")
|
||||
public List<KSDocument> findByProjectNameAndApplicationName(String projectName, String applicationName, Sort sort);
|
||||
|
||||
@Query("{ 'ingestionInfo.metadata.KsProjectName': ?0 }")
|
||||
public List<KSDocument> findByProjectName(String projectName, Sort sort);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.olympus.apollo.repository;
|
||||
|
||||
import org.bson.types.ObjectId;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import com.olympus.model.Project;
|
||||
|
||||
@Repository
|
||||
public interface ProjectRepository extends MongoRepository<Project, String> {
|
||||
|
||||
|
||||
}
|
||||
@@ -1,21 +1,14 @@
|
||||
package com.olympus.apollo.security.config;
|
||||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import org.springframework.context.annotation.Lazy;
|
||||
import org.springframework.security.authentication.AuthenticationManager;
|
||||
|
||||
import org.springframework.security.authentication.AuthenticationProvider;
|
||||
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
|
||||
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||
import org.springframework.security.config.http.SessionCreationPolicy;
|
||||
import org.springframework.security.core.userdetails.UserDetailsService;
|
||||
import org.springframework.security.crypto.password.NoOpPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.security.web.SecurityFilterChain;
|
||||
@@ -77,8 +70,9 @@ public class SecurityConfig {
|
||||
http.csrf(csrf -> csrf.disable())
|
||||
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
|
||||
.authorizeHttpRequests(auth -> auth.requestMatchers("/api/auth/**").permitAll()
|
||||
.requestMatchers("/api/test/**").permitAll()
|
||||
.anyRequest().authenticated()); //permitAll());
|
||||
.requestMatchers("/api/test/**").permitAll()
|
||||
.requestMatchers("/**").permitAll()
|
||||
.anyRequest().authenticated()); //permitAll());
|
||||
|
||||
http.authenticationProvider(authenticationProvider());
|
||||
|
||||
|
||||
@@ -4,10 +4,14 @@ import java.util.Collection;
|
||||
|
||||
import org.springframework.data.annotation.Id;
|
||||
import org.springframework.data.mongodb.core.mapping.Document;
|
||||
import org.springframework.data.mongodb.core.mapping.DocumentReference;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.core.userdetails.UserDetails;
|
||||
|
||||
import com.olympus.model.Application;
|
||||
import com.olympus.model.Project;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
@@ -31,6 +35,14 @@ public class User implements UserDetails{
|
||||
private String name;
|
||||
private String surname;
|
||||
|
||||
@DocumentReference
|
||||
private Project selectedProject;
|
||||
@DocumentReference
|
||||
private List<Project> lstProjects;
|
||||
|
||||
@DocumentReference
|
||||
private Application selectedApplication;
|
||||
|
||||
private Role role;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
package com.olympus.apollo.services;
|
||||
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.tomcat.util.openssl.openssl_h;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.olympus.apollo.repository.KSDocumentRepository;
|
||||
import com.olympus.apollo.repository.ProjectRepository;
|
||||
import com.olympus.apollo.security.entity.User;
|
||||
import com.olympus.model.apollo.KSDocument;
|
||||
|
||||
@Service
|
||||
public class KSDocumentService {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(KSDocumentService.class);
|
||||
|
||||
@Autowired
|
||||
private KSDocumentRepository ksdocRepo;
|
||||
|
||||
public List<KSDocument> findByProjectNameAndApplicationName() {
|
||||
logger.info("findByProjectNameAndApplicationName function:");
|
||||
User principal = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
|
||||
try {
|
||||
if( principal.getSelectedApplication()==null){
|
||||
return ksdocRepo.findByProjectName(principal.getSelectedProject().getInternal_name(), Sort.by(Sort.Direction.DESC, "ingestionDate"));
|
||||
}else{
|
||||
return ksdocRepo.findByProjectNameAndApplicationName(principal.getSelectedProject().getInternal_name(), principal.getSelectedApplication().getInternal_name(), Sort.by(Sort.Direction.DESC, "ingestionDate"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("Error in findByProjectNameAndApplicationName function: " + e.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ResponseEntity<Resource> downloadKSDocument(KSDocument doc) {
|
||||
|
||||
logger.info("downloadKSDocument function:");
|
||||
|
||||
try {
|
||||
// Percorso al file
|
||||
Path filePath = Paths.get(doc.getFilePath()).normalize();
|
||||
Resource resource = new UrlResource(filePath.toUri());
|
||||
|
||||
if (!resource.exists()) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
// Determina il tipo MIME dinamicamente
|
||||
String contentType = Files.probeContentType(filePath);
|
||||
if (contentType == null) {
|
||||
// Tipo MIME predefinito se non determinabile
|
||||
contentType = "application/octet-stream";
|
||||
}
|
||||
|
||||
// Configurazione della risposta HTTP
|
||||
return ResponseEntity.ok()
|
||||
.header(HttpHeaders.CONTENT_TYPE, contentType) // Tipo MIME dinamico
|
||||
.body(resource);
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.internalServerError().build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -233,6 +233,7 @@ public class KSIngestor {
|
||||
}
|
||||
|
||||
public List<String> testSimilaritySearch(String query,String filterQuery) {
|
||||
|
||||
SearchRequest searchRequest = SearchRequest.defaults().withQuery(query).withTopK(5).withSimilarityThreshold(0.1);
|
||||
|
||||
if(filterQuery!=null && !filterQuery.isEmpty()){
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.olympus.apollo.services;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bson.types.ObjectId;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.olympus.apollo.repository.ProjectRepository;
|
||||
import com.olympus.apollo.security.entity.User;
|
||||
import com.olympus.apollo.security.repository.UserRepository;
|
||||
import com.olympus.model.Application;
|
||||
import com.olympus.model.Project;
|
||||
|
||||
@Service
|
||||
public class ProjectService {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(ProjectService.class);
|
||||
|
||||
@Autowired
|
||||
private ProjectRepository projectRepo;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepo;
|
||||
|
||||
public List<Project> getListProjectsByUser(){
|
||||
logger.info("getListProjectByUser function:");
|
||||
|
||||
User principal = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
|
||||
return principal.getLstProjects();
|
||||
|
||||
}
|
||||
|
||||
public User updateUserSelectedProject(Project idProject){
|
||||
User principal = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
|
||||
principal.setSelectedProject(idProject);
|
||||
principal.setSelectedApplication(null);
|
||||
User u = userRepo.save(principal);
|
||||
return u;
|
||||
|
||||
}
|
||||
|
||||
public User updateUserSelectedApplication(Application application){
|
||||
User principal = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
|
||||
principal.setSelectedApplication(application);
|
||||
User u = userRepo.save(principal);
|
||||
return u;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static List<ObjectId> convertToObjectIdList(List<String> listProjectIds) {
|
||||
List<ObjectId> objectIdList = new ArrayList<>();
|
||||
|
||||
for (String idString : listProjectIds) {
|
||||
try {
|
||||
// Crea un nuovo ObjectId dalla stringa e aggiungilo alla lista
|
||||
objectIdList.add(new ObjectId(idString));
|
||||
} catch (IllegalArgumentException e) {
|
||||
// Gestione degli errori per stringhe non valide che non possono essere convertite in ObjectId
|
||||
System.err.println("Invalid ObjectId string: " + idString);
|
||||
}
|
||||
}
|
||||
|
||||
return objectIdList;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user