Merged PR 206: Create document picklist
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package com.olympus.hermione.controllers;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.hermione.services.KSDocumentService;
|
||||
import com.olympus.model.apollo.KSDocument;
|
||||
|
||||
@RestController
|
||||
public class KSDocumentController {
|
||||
|
||||
@Autowired
|
||||
private KSDocumentService ksDocumentService;
|
||||
|
||||
/**
|
||||
* Recupera tutti i KSDocument per il progetto selezionato dall'utente corrente
|
||||
* @return Lista di KSDocument
|
||||
*/
|
||||
@GetMapping("/ksDocuments")
|
||||
public List<KSDocument> getKSDocuments() {
|
||||
return ksDocumentService.getKSDocumentsByUserSelectedProject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Recupera tutti i KSDocument per un progetto specifico
|
||||
* @param projectId ID del progetto
|
||||
* @return Lista di KSDocument
|
||||
*/
|
||||
@PostMapping("/ksDocuments/byProject")
|
||||
public List<KSDocument> getIngestedKSDocumentsByProject() {
|
||||
return ksDocumentService.getIngestedKSDocumentsByUserSelectedProject();
|
||||
}
|
||||
}
|
||||
@@ -12,4 +12,5 @@ public class ScenarioInputs {
|
||||
private String name;
|
||||
private String type;
|
||||
private String label;
|
||||
private String dataSource; // "videoGroups", "ksDocuments", etc.
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.olympus.hermione.repository;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
import org.springframework.data.mongodb.repository.Query;
|
||||
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||
|
||||
import com.olympus.model.apollo.KSDocument;
|
||||
|
||||
@RepositoryRestResource(collectionResourceRel = "ksdocuments", path = "ksdocuments")
|
||||
public interface KSDocumentRepository extends MongoRepository<KSDocument, String> {
|
||||
|
||||
@Query("{'ingestionInfo.metadata.KsProjectName': ?0}")
|
||||
List<KSDocument> findByProjectName(String projectName);
|
||||
|
||||
@Query("{'ingestionInfo.metadata.KsProjectName': ?0, 'ingestionStatus': 'INGESTED'}")
|
||||
List<KSDocument> findByProjectNameAndIngested(String projectName);
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.olympus.hermione.services;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.olympus.hermione.repository.KSDocumentRepository;
|
||||
import com.olympus.hermione.security.entity.User;
|
||||
import com.olympus.model.apollo.KSDocument;
|
||||
|
||||
@Service
|
||||
public class KSDocumentService {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(KSDocumentService.class);
|
||||
|
||||
@Autowired
|
||||
private KSDocumentRepository ksDocumentRepository;
|
||||
|
||||
/**
|
||||
* Recupera tutti i KSDocument per il progetto selezionato dall'utente corrente
|
||||
* @return Lista di KSDocument
|
||||
*/
|
||||
public List<KSDocument> getKSDocumentsByUserSelectedProject() {
|
||||
logger.info("getKSDocumentsByUserSelectedProject function:");
|
||||
|
||||
User principal = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
|
||||
if (principal.getSelectedProject() == null) {
|
||||
logger.warn("No project selected for user: {}", principal.getUsername());
|
||||
return List.of();
|
||||
}
|
||||
|
||||
String projectName = principal.getSelectedProject().getInternal_name();
|
||||
logger.info("Retrieving KSDocuments for project: {}", projectName);
|
||||
|
||||
return ksDocumentRepository.findByProjectName(projectName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Recupera tutti i KSDocument completati per il progetto selezionato dall'utente corrente
|
||||
* @return Lista di KSDocument con stato COMPLETED
|
||||
*/
|
||||
public List<KSDocument> getIngestedKSDocumentsByUserSelectedProject() {
|
||||
logger.info("getIngestedKSDocumentsByUserSelectedProject function:");
|
||||
|
||||
User principal = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
|
||||
if (principal.getSelectedProject() == null) {
|
||||
logger.warn("No project selected for user: {}", principal.getUsername());
|
||||
return List.of();
|
||||
}
|
||||
|
||||
String projectName = principal.getSelectedProject().getInternal_name();
|
||||
logger.info("Retrieving ingested KSDocuments for project: {}", projectName);
|
||||
|
||||
return ksDocumentRepository.findByProjectNameAndIngested(projectName);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user