Merge remote-tracking branch 'refs/remotes/origin/develop' into develop
This commit is contained in:
116
azure-pipelines.yml
Normal file
116
azure-pipelines.yml
Normal file
@@ -0,0 +1,116 @@
|
||||
trigger:
|
||||
- master
|
||||
|
||||
resources:
|
||||
repositories:
|
||||
- repository: olympus-common # Alias for the first repository
|
||||
type: git
|
||||
name: Olympus/olympus-common # Project and repository name
|
||||
ref: master
|
||||
|
||||
variables:
|
||||
dockerRegistryServiceConnection: 'docker-registry-olympus'
|
||||
imageName: 'apollo'
|
||||
shortCommitSha: ''
|
||||
envName: 'aks-olympus'
|
||||
azurecontainerRegistry: 'olympusreg.azurecr.io'
|
||||
resourceName: 'olympus'
|
||||
|
||||
stages:
|
||||
- stage: Build
|
||||
displayName: Build stage
|
||||
jobs:
|
||||
- job: Build
|
||||
displayName: "Build & push to ACR"
|
||||
pool:
|
||||
name: azureselfhosted
|
||||
steps:
|
||||
- checkout: self
|
||||
- checkout: olympus-common
|
||||
|
||||
- script: |
|
||||
echo "##vso[task.setvariable variable=shortCommitSha]$(echo $(Build.SourceVersion) | cut -c1-8)"
|
||||
displayName: 'Set Short Commit SHA'
|
||||
|
||||
- script: |
|
||||
echo "Building the first repository..."
|
||||
ls -lrth
|
||||
displayName: 'list files'
|
||||
|
||||
- task: Maven@3
|
||||
inputs:
|
||||
mavenPomFile: 'olympus-common/pom.xml'
|
||||
goals: 'install'
|
||||
displayName: 'Build olympus-common'
|
||||
|
||||
- task: Maven@3
|
||||
inputs:
|
||||
mavenPomFile: 'apollo/pom.xml'
|
||||
goals: 'install -DskipTests'
|
||||
displayName: 'Build apollo'
|
||||
|
||||
- script: |
|
||||
echo "Listing the docker images..."
|
||||
docker images
|
||||
displayName: 'list docker images'
|
||||
|
||||
- task: Docker@2
|
||||
inputs:
|
||||
command: 'buildAndPush'
|
||||
repository: '$(imageName)'
|
||||
Dockerfile: 'apollo/Dockerfile'
|
||||
containerRegistry: $(dockerRegistryServiceConnection)
|
||||
tags: '$(shortCommitSha)'
|
||||
displayName: 'Build and push an image to container registry'
|
||||
|
||||
- script: |
|
||||
echo "Listing the docker images..."
|
||||
docker images
|
||||
displayName: 'List docker images'
|
||||
|
||||
- upload: apollo/manifests
|
||||
artifact: manifests
|
||||
|
||||
- stage: Deploy
|
||||
displayName: Deploy stage
|
||||
dependsOn: Build
|
||||
|
||||
jobs:
|
||||
- deployment: Deploy
|
||||
condition: succeeded()
|
||||
displayName: "Deploy to ${{variables.envName}}"
|
||||
pool:
|
||||
name: azureselfhosted
|
||||
environment:
|
||||
name: $(envName).$(resourceName)
|
||||
resourceType: Kubernetes
|
||||
strategy:
|
||||
runOnce:
|
||||
deploy:
|
||||
steps:
|
||||
- checkout: self
|
||||
|
||||
- script: |
|
||||
echo "##vso[task.setvariable variable=shortCommitSha]$(echo $(Build.SourceVersion) | cut -c1-8)"
|
||||
displayName: 'Set Short Commit SHA'
|
||||
|
||||
- script: |
|
||||
echo $(shortCommitSha)
|
||||
echo "Updating imageName in deployment.yaml"
|
||||
displayName: 'Update ImageName in YAML file'
|
||||
|
||||
- task: KubernetesManifest@0
|
||||
displayName: Deploy to Kubernetes cluster
|
||||
inputs:
|
||||
action: deploy
|
||||
manifests: |
|
||||
$(Pipeline.Workspace)/manifests/apollo-deployment.yaml
|
||||
containers: |
|
||||
$(azurecontainerRegistry)/$(imageName):$(shortCommitSha)
|
||||
|
||||
- script: |
|
||||
echo "Removing Docker images to clean up..."
|
||||
docker rmi $(docker images -q)
|
||||
displayName: 'Clean up Docker Images'
|
||||
continueOnError: true
|
||||
condition: always()
|
||||
38
manifests/apollo-deployment.yaml
Normal file
38
manifests/apollo-deployment.yaml
Normal file
@@ -0,0 +1,38 @@
|
||||
kind: Deployment
|
||||
apiVersion: apps/v1
|
||||
metadata:
|
||||
name: apollo
|
||||
namespace: olympus
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: apollo
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: apollo
|
||||
spec:
|
||||
volumes:
|
||||
- name: apollo-pv-storage
|
||||
persistentVolumeClaim:
|
||||
claimName: private-azurefile-pvc
|
||||
containers:
|
||||
- name: apollo
|
||||
image: olympusreg.azurecr.io/apollo:2ac8bc10
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: olympus-db-shared-cfg
|
||||
- configMapRef:
|
||||
name: olympus-ai-shared-cfg
|
||||
- configMapRef:
|
||||
name: olympus-common-shared-cfg
|
||||
resources: {}
|
||||
volumeMounts:
|
||||
- name: apollo-pv-storage
|
||||
mountPath: /mnt/apollo_storage/documents
|
||||
subPath: documents
|
||||
- name: apollo-pv-storage
|
||||
mountPath: /mnt/apollo_storage/repository
|
||||
subPath: repository
|
||||
imagePullPolicy: Always
|
||||
10
pom.xml
10
pom.xml
@@ -62,12 +62,12 @@
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-mongodb-atlas-store-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
-->
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
@@ -79,6 +79,11 @@
|
||||
<artifactId>spring-ai-azure-store</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-chroma-store</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
|
||||
@@ -96,7 +101,6 @@
|
||||
<dependency>
|
||||
<groupId>org.springframework.ai</groupId>
|
||||
<artifactId>spring-ai-tika-document-reader</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,45 +5,47 @@ apollo:
|
||||
fe:
|
||||
url: "http://localhost:5173"
|
||||
java-parser-module:
|
||||
url: "http://java-parser-module-service.olympus.svc.cluster.local:8080"
|
||||
url: "http://localhost:8084"
|
||||
spring:
|
||||
application:
|
||||
name: apollo
|
||||
ai:
|
||||
azure:
|
||||
openai:
|
||||
endpoint: "https://ai-olympus.openai.azure.com/"
|
||||
api-key: "9fb33cc69d914d4c8225b974876510b5"
|
||||
endpoint: "https://ai-olympus-new.openai.azure.com/"
|
||||
api-key: "4eHwvw6h7vHxTmI2870cR3EpEBs5L9sXZabr9nz37y39TXtk0xY5JQQJ99AKAC5RqLJXJ3w3AAABACOGLdow"
|
||||
openai:
|
||||
api-key: "sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
vectorstore:
|
||||
azure:
|
||||
api-key: "jxKqZvbMKuo1MwXs8ilEAeRDeswtoTXO1lWX600jP2AzSeDXo1nq"
|
||||
api-key: "jxKxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
url: "https://search-olympus.search.windows.net"
|
||||
initialize-schema: true
|
||||
chroma:
|
||||
client:
|
||||
host: "http://108.142.74.161"
|
||||
port: "8000"
|
||||
key-token: "nVYLh3eq92aJP4x08dNdWngilPG2ooj9"
|
||||
initialize-schema: "true"
|
||||
collection-name: "olympus"
|
||||
data:
|
||||
mongodb:
|
||||
uri: mongodb+srv://olympus_adm:26111979@olympus.l6qor4p.mongodb.net/?retryWrites=true&w=majority&appName=Olympus
|
||||
uri: mongodb+srv://olympusadmin:Camilla123!@db-olympus.global.mongocluster.cosmos.azure.com/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000
|
||||
database: olympus
|
||||
username: olympus_adm
|
||||
password: 26111979
|
||||
username: olympusadmin
|
||||
password: Camilla123!
|
||||
servlet:
|
||||
multipart:
|
||||
max-file-size: 5000000MB
|
||||
max-request-size: 500000MB
|
||||
main:
|
||||
allow-circular-references: true
|
||||
|
||||
#path to the repository
|
||||
ingestion:
|
||||
repository:
|
||||
basepath: C:\\Users\\andrea.terzani\\dev\\Olympus
|
||||
gitlab:
|
||||
token: "xxxxxxxx"
|
||||
path: /mnt/apollo_storage/repository #C:\\repos\\olympus_ai\\gitClone
|
||||
cloud:
|
||||
url: "https://gi2tlab.com/api/v4"
|
||||
token: "xxxxxxxx"
|
||||
onpremises:
|
||||
url: "http://localhost:8081/api"
|
||||
token: "xxxxxxxx"
|
||||
|
||||
eureka:
|
||||
@@ -53,16 +55,11 @@ eureka:
|
||||
instance:
|
||||
preferIpAddress: true
|
||||
|
||||
#spring.jpa.show-sql=true
|
||||
#spring.jpa.hibernate.ddl-auto=update
|
||||
#spring.datasource.url=jdbc:postgresql://localhost:5432/olympus
|
||||
#spring.datasource.username=andreaterzani
|
||||
#spring.datasource.password=26111979
|
||||
#spring.datasource.driver-class-name=org.postgresql.Driver
|
||||
#spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
|
||||
|
||||
logging:
|
||||
level:
|
||||
root: INFO
|
||||
#feign: DEBUG
|
||||
#org.springframework.web.client: DEBUG
|
||||
#org.springframework.web.client: DEBUG
|
||||
|
||||
java-re-module:
|
||||
url: "http://localhost:8084"
|
||||
Reference in New Issue
Block a user