Create methods for video
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package com.olympus.apollo.controllers.FeApi;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.olympus.model.apollo.VideoGroup;
|
||||
import com.olympus.apollo.services.VideoGroupService;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/fe-api/video-group")
|
||||
public class KSVideoGroupController {
|
||||
|
||||
@Autowired
|
||||
private VideoGroupService videoGroupService;
|
||||
|
||||
|
||||
@GetMapping("/project")
|
||||
public List<VideoGroup> getVideoGroupByProjectId(@RequestParam String projectId) {
|
||||
return videoGroupService.findByProjectId(projectId);
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public VideoGroup getVideoGroupById(@PathVariable String id) {
|
||||
return videoGroupService.getVideoGroupById(id);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -3,20 +3,14 @@ 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
|
||||
@@ -47,9 +41,9 @@ public class KsDocumentController {
|
||||
|
||||
|
||||
@PostMapping("/downloadKSDocument")
|
||||
public ResponseEntity<Resource> downloadFile(@RequestBody KSDocument doc) {
|
||||
public ResponseEntity<Resource> downloadFile(@RequestBody KSDocument doc) {
|
||||
|
||||
return ksDocumentService.downloadKSDocument(doc);
|
||||
return ksDocumentService.downloadKSDocument(doc);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.olympus.apollo.controllers.FeApi;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.olympus.model.apollo.KSVideo;
|
||||
import com.olympus.apollo.repository.KSVideoRepository;
|
||||
import com.olympus.apollo.services.KSVideoService;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/fe-api/ksvideos")
|
||||
public class KsVideoController {
|
||||
|
||||
@Autowired
|
||||
private KSVideoRepository ksVideoREpository;
|
||||
|
||||
@Autowired
|
||||
private KSVideoService ksVideoService;
|
||||
|
||||
@GetMapping("")
|
||||
public List<KSVideo> getVideos() {
|
||||
|
||||
List<KSVideo> result = ksVideoService.findByProjectNameAndApplicationName();
|
||||
|
||||
return result;
|
||||
}
|
||||
@GetMapping("/{id}")
|
||||
public KSVideo getVideo(@PathVariable String id) {
|
||||
|
||||
KSVideo result = ksVideoREpository.findById(id).get();
|
||||
|
||||
return result;
|
||||
}
|
||||
@GetMapping("/group/{groupId}")
|
||||
public List<KSVideo> getVideoByGroupId(@PathVariable String groupId) {
|
||||
|
||||
List<KSVideo> result = ksVideoService.findByGroupId(groupId);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@PostMapping("/downloadKSVideo")
|
||||
public ResponseEntity<Resource> downloadFile(@RequestBody KSVideo doc) {
|
||||
|
||||
return ksVideoService.downloadKSVideo(doc);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -62,6 +62,11 @@ public class TestController {
|
||||
return ksIngestor.setDocumentInQueueIngestion(id);
|
||||
}
|
||||
|
||||
@GetMapping("test/index_video/{id}")
|
||||
public IngestionOutput ingestVideoById(@PathVariable String id) {
|
||||
return ksIngestor.setVideoInQueueIngestion(id);
|
||||
}
|
||||
|
||||
@GetMapping("test/query_vector")
|
||||
public List<Document> testSimilaritySearch(@RequestParam String query, @RequestParam String filterQuery) {
|
||||
return ksIngestor.testSimilaritySearch(query, filterQuery);
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.olympus.apollo.controllers;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.ModelAttribute;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
|
||||
import com.olympus.apollo.repository.KSVideoRepository;
|
||||
import com.olympus.apollo.services.StorageService;
|
||||
import com.olympus.dto.VideoUploadDTO;
|
||||
import com.olympus.model.apollo.KSVideoIngestionInfo;
|
||||
import com.olympus.model.apollo.KSVideo;
|
||||
|
||||
@RestController
|
||||
public class VideoController {
|
||||
|
||||
@Autowired
|
||||
private StorageService storageService;
|
||||
@Autowired
|
||||
private KSVideoRepository ksVideoRepository;
|
||||
|
||||
@PostMapping("/upload_video")
|
||||
public ResponseEntity<KSVideo> handleVideoUpload(
|
||||
@RequestParam("file") MultipartFile file,
|
||||
@ModelAttribute VideoUploadDTO videoUploadDTO
|
||||
) {
|
||||
String filePath = storageService.store(file,videoUploadDTO.getKsProjectName());
|
||||
|
||||
KSVideo ksVideo = new KSVideo();
|
||||
ksVideo.setFilePath(filePath);
|
||||
ksVideo.setFileName(file.getOriginalFilename());
|
||||
ksVideo.setName(file.getOriginalFilename());
|
||||
ksVideo.setDescription(videoUploadDTO.getDescription());
|
||||
ksVideo.setIngestionStatus("LOADED");
|
||||
|
||||
Date now = new Date();
|
||||
ksVideo.setIngestionDate(now);
|
||||
ksVideo.setIngestionDateFormat(new SimpleDateFormat("MM/dd/yy").format(now));
|
||||
|
||||
|
||||
KSVideoIngestionInfo ksVideoIngestionInfo = new KSVideoIngestionInfo();
|
||||
ksVideoIngestionInfo.setType(videoUploadDTO.getType()); // != null ? type : "MD_Video"
|
||||
|
||||
HashMap<String, String> metadata = new HashMap<>();
|
||||
metadata.put("KsApplicationName", videoUploadDTO.getKsApplicationName());
|
||||
metadata.put("KsDoctype", videoUploadDTO.getKsDocType());
|
||||
metadata.put("KsDocSource", videoUploadDTO.getKsDocSource());
|
||||
metadata.put("KsFileSource", file.getOriginalFilename());
|
||||
metadata.put("KsVideoGroupId", videoUploadDTO.getKsVideoGroupId());
|
||||
metadata.put("KsProjectName", videoUploadDTO.getKsProjectName());
|
||||
|
||||
ksVideoIngestionInfo.setMetadata(metadata);
|
||||
ksVideoIngestionInfo.setNumberOfChunkToEmbed(videoUploadDTO.getNumberOfChunkToEmbed());
|
||||
ksVideoIngestionInfo.setChunkDurationInSeconds(videoUploadDTO.getChunkDurationInSeconds());
|
||||
|
||||
ksVideo.setIngestionInfo(ksVideoIngestionInfo);
|
||||
ksVideoRepository.save(ksVideo);
|
||||
return ResponseEntity.ok(ksVideo);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.olympus.apollo.controllers;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import com.olympus.model.apollo.VideoGroup;
|
||||
import com.olympus.apollo.repository.VideoGroupRepository;
|
||||
import com.olympus.apollo.services.VideoGroupService;
|
||||
import com.olympus.dto.VideoGroupDTO;
|
||||
|
||||
@RestController
|
||||
public class VideoGroupController {
|
||||
|
||||
@Autowired
|
||||
private VideoGroupRepository videoGroupRepository;
|
||||
|
||||
@Autowired
|
||||
private VideoGroupService videoGroupService;
|
||||
|
||||
@PostMapping("/create_video_group")
|
||||
public ResponseEntity<VideoGroup> handleVideoGroupCreation(
|
||||
@ModelAttribute VideoGroupDTO videoGroupDTO
|
||||
) {
|
||||
VideoGroup videoGroup = new VideoGroup();
|
||||
videoGroup.setName(videoGroupDTO.getName());
|
||||
videoGroup.setType(videoGroupDTO.getType());
|
||||
videoGroup.setProjectId(videoGroupDTO.getProjectId());
|
||||
videoGroup.setApplicationId(videoGroupDTO.getApplicationId());
|
||||
|
||||
Date now = new Date();
|
||||
videoGroup.setDate(now);
|
||||
videoGroup.setDateFormat(new SimpleDateFormat("MM/dd/yy").format(now));
|
||||
videoGroupRepository.save(videoGroup);
|
||||
return ResponseEntity.ok(videoGroup);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete/{id}")
|
||||
public ResponseEntity<?> deleteVideoGroup(@PathVariable String id) {
|
||||
try {
|
||||
boolean deleted = videoGroupService.deleteVideoGroup(id);
|
||||
if (!deleted) {
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
|
||||
return ResponseEntity.ok(Map.of(
|
||||
"status", "OK",
|
||||
"message", "Video group deleted successfully"
|
||||
));
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.internalServerError().body(Map.of(
|
||||
"status", "ERROR",
|
||||
"message", "Failed to delete video group: " + e.getMessage()
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
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.rest.core.annotation.RepositoryRestResource;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
|
||||
import com.olympus.model.apollo.KSVideo;
|
||||
|
||||
@RepositoryRestResource(collectionResourceRel = "ksvideos", path = "ksvideos")
|
||||
@CrossOrigin
|
||||
public interface KSVideoRepository extends MongoRepository<KSVideo, String> {
|
||||
|
||||
@Query("{ 'ingestionInfo.metadata.KsProjectName': ?0, 'ingestionInfo.metadata.KsApplicationName': ?1 }")
|
||||
List<KSVideo> findByProjectNameAndApplicationName(String projectName, String applicationName, Sort sort);
|
||||
|
||||
@Query("{ 'ingestionInfo.metadata.KsProjectName': ?0 }")
|
||||
public List<KSVideo> findByProjectName(String projectName, Sort sort);
|
||||
|
||||
@Query("{ 'ingestionInfo.metadata.KsVideoGroupId': ?0 }")
|
||||
public List<KSVideo> findByGroupId(String groupId, Sort sort);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.olympus.apollo.repository;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
import org.springframework.data.mongodb.repository.Query;
|
||||
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
|
||||
import org.springframework.web.bind.annotation.CrossOrigin;
|
||||
|
||||
import com.olympus.model.apollo.VideoGroup;
|
||||
|
||||
|
||||
@RepositoryRestResource(collectionResourceRel = "video_groups", path = "video_groups")
|
||||
@CrossOrigin
|
||||
public interface VideoGroupRepository extends MongoRepository<VideoGroup, String> {
|
||||
|
||||
@Query("{ 'projectId': ?0 }")
|
||||
public List<VideoGroup> findByProjectId(String projectId, Sort sort);
|
||||
|
||||
public Optional<VideoGroup> findById(String id);
|
||||
}
|
||||
@@ -24,10 +24,12 @@ import org.springframework.stereotype.Service;
|
||||
|
||||
import com.olympus.apollo.repository.KSDocumentRepository;
|
||||
import com.olympus.apollo.repository.KSTextsRepository;
|
||||
import com.olympus.apollo.repository.KSVideoRepository;
|
||||
import com.olympus.dto.IngestionOutput;
|
||||
import com.olympus.model.apollo.KSDocument;
|
||||
import com.olympus.model.apollo.KSIngestionInfo;
|
||||
import com.olympus.model.apollo.KSTexts;
|
||||
import com.olympus.model.apollo.KSVideo;
|
||||
|
||||
|
||||
@Service
|
||||
@@ -39,6 +41,9 @@ public class KSIngestor {
|
||||
@Autowired
|
||||
private KSTextsRepository ksTextsRepository;
|
||||
|
||||
@Autowired
|
||||
private KSVideoRepository ksVideoRepository;
|
||||
|
||||
@Autowired
|
||||
private FileSystemStorageService storageService;
|
||||
|
||||
@@ -338,4 +343,26 @@ public class KSIngestor {
|
||||
|
||||
return docs;
|
||||
}
|
||||
|
||||
public IngestionOutput setVideoInQueueIngestion(String id) {
|
||||
IngestionOutput ingestionOutput= new IngestionOutput();
|
||||
Optional<KSVideo> optionalVideo = ksVideoRepository.findById(id);
|
||||
if (optionalVideo.isPresent()) {
|
||||
KSVideo ksVideo = optionalVideo.get();
|
||||
if ("LOADED".equals(ksVideo.getIngestionStatus()) || "ERROR".equals(ksVideo.getIngestionStatus())) {
|
||||
ksVideo.setIngestionStatus("INGESTION_QUEUE");
|
||||
ksVideoRepository.save(ksVideo);
|
||||
ingestionOutput.setMessage("Video added to ingestion queue...");
|
||||
ingestionOutput.setStatus("INGESTION_QUEUE");
|
||||
return ingestionOutput;
|
||||
|
||||
} else {
|
||||
ingestionOutput.setMessage("OOPS: Video is already Injected");
|
||||
return ingestionOutput;
|
||||
}
|
||||
} else {
|
||||
ingestionOutput.setMessage("OOPS: Video Not found");
|
||||
return ingestionOutput;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.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.KSVideoRepository;
|
||||
import com.olympus.apollo.security.entity.User;
|
||||
import com.olympus.model.apollo.KSVideo;
|
||||
|
||||
@Service
|
||||
public class KSVideoService {
|
||||
private Logger logger = LoggerFactory.getLogger(KSVideoService.class);
|
||||
|
||||
@Autowired
|
||||
private KSVideoRepository ksVideoRepository;
|
||||
|
||||
public List<KSVideo> findByProjectNameAndApplicationName() {
|
||||
User principal = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
|
||||
|
||||
try {
|
||||
return ksVideoRepository.findByProjectName(principal.getSelectedProject().getInternal_name(), Sort.by(Sort.Direction.DESC, "ingestionDate"));
|
||||
} catch (Exception e) {
|
||||
logger.error("Error in findByProjectNameAndApplicationName function: " + e.getMessage());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<KSVideo> findByGroupId(String groupId) {
|
||||
return ksVideoRepository.findByGroupId(groupId, Sort.by(Sort.Direction.DESC, "ingestionDate"));
|
||||
}
|
||||
|
||||
public ResponseEntity<Resource> downloadKSVideo(KSVideo video) {
|
||||
|
||||
logger.info("downloadKSVideo function:");
|
||||
|
||||
try {
|
||||
// Percorso al file
|
||||
Path filePath = Paths.get(video.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.olympus.apollo.services;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.olympus.apollo.repository.VideoGroupRepository;
|
||||
import com.olympus.model.apollo.VideoGroup;
|
||||
|
||||
@Service
|
||||
public class VideoGroupService {
|
||||
|
||||
private Logger logger = LoggerFactory.getLogger(VideoGroupService.class);
|
||||
|
||||
@Autowired
|
||||
private VideoGroupRepository videoGroupRepository;
|
||||
|
||||
public VideoGroup getVideoGroupById(String id) {
|
||||
return videoGroupRepository.findById(id).get();
|
||||
}
|
||||
|
||||
public List<VideoGroup> findByProjectId(String projectId) {
|
||||
return videoGroupRepository.findByProjectId(projectId, Sort.by(Sort.Direction.DESC, "id"));
|
||||
}
|
||||
|
||||
public boolean deleteVideoGroup(String id) {
|
||||
try {
|
||||
VideoGroup videoGroup = videoGroupRepository.findById(id).orElse(null);
|
||||
if (videoGroup == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
videoGroupRepository.delete(videoGroup);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
logger.error("Error in deleteVideoGroup function: " + e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user