|
|
|
|
@@ -1,14 +1,14 @@
|
|
|
|
|
package com.olympus.apollo.services;
|
|
|
|
|
|
|
|
|
|
import com.olympus.apollo.dto.DeleteGitRepoDetailsRequest;
|
|
|
|
|
import com.olympus.apollo.models.KSGitIngestionInfo;
|
|
|
|
|
import com.olympus.apollo.repository.*;
|
|
|
|
|
import org.slf4j.Logger;
|
|
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
|
|
|
|
import com.olympus.apollo.dto.DeletionRequest;
|
|
|
|
|
import com.olympus.apollo.dto.VectorStoreMetadataDetails;
|
|
|
|
|
import com.olympus.apollo.models.VectorStore;
|
|
|
|
|
import com.olympus.apollo.repository.KSDocumentRepository;
|
|
|
|
|
import com.olympus.apollo.repository.KSIngestionInfoRepository;
|
|
|
|
|
import com.olympus.apollo.repository.VectorStoreRepository;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
@@ -25,6 +25,12 @@ public class DeletionService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private KSIngestionInfoRepository ksIngestionInfoRepository;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private KSGitIngestionInfoRepository ksGitIngestionInfoRepository;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private KSGitInfoRepository ksGitInfoRepository;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private VectorStoreRepository vectorStoreRepository;
|
|
|
|
|
|
|
|
|
|
@@ -67,4 +73,47 @@ public class DeletionService {
|
|
|
|
|
throw new RuntimeException("An error occurred while deleting records", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void deleteRecordsOfGitRepo(DeleteGitRepoDetailsRequest deleteGitRepoDetailsRequest) {
|
|
|
|
|
try {
|
|
|
|
|
boolean KSGitInfoExists = deleteGitRepoDetailsRequest.getKsGitInfoId() != null && !deleteGitRepoDetailsRequest.getKsGitInfoId().isEmpty() && ksGitInfoRepository.existsById(deleteGitRepoDetailsRequest.getKsGitInfoId());
|
|
|
|
|
logger.info("KSGitInfo with id {} exists.", deleteGitRepoDetailsRequest.getKsGitInfoId());
|
|
|
|
|
boolean KSGitIngestionInfoExists = deleteGitRepoDetailsRequest.getKsGitIngestionInfoId() != null && !deleteGitRepoDetailsRequest.getKsGitIngestionInfoId().isEmpty() && ksGitIngestionInfoRepository.existsById(deleteGitRepoDetailsRequest.getKsGitIngestionInfoId());
|
|
|
|
|
logger.info("KSGitIngestionInfo with id {} exists.", deleteGitRepoDetailsRequest.getKsGitIngestionInfoId());
|
|
|
|
|
boolean vectorStoreGitDetailsExists = deleteGitRepoDetailsRequest.getKsApplicationName() != null && deleteGitRepoDetailsRequest.getKsDocSource() != null && deleteGitRepoDetailsRequest.getKsFileSource() != null && deleteGitRepoDetailsRequest.getKsDoctype() != null;
|
|
|
|
|
logger.info("vectorStoreGitDetails records exists.");
|
|
|
|
|
|
|
|
|
|
List<VectorStore> vectorStoreMetadataDetails = vectorStoreGitDetailsExists ? vectorStoreRepository.findByMetadata(deleteGitRepoDetailsRequest.getKsDoctype(), deleteGitRepoDetailsRequest.getKsDocSource(), deleteGitRepoDetailsRequest.getKsFileSource(), deleteGitRepoDetailsRequest.getKsApplicationName()) : List.of();
|
|
|
|
|
|
|
|
|
|
if (KSGitInfoExists && KSGitIngestionInfoExists && !vectorStoreMetadataDetails.isEmpty()) {
|
|
|
|
|
if (deleteGitRepoDetailsRequest.getKsGitInfoId() != null && !deleteGitRepoDetailsRequest.getKsGitInfoId().isEmpty()) {
|
|
|
|
|
ksGitInfoRepository.deleteById(deleteGitRepoDetailsRequest.getKsGitInfoId());
|
|
|
|
|
logger.info("KsGitInfo with id {} deleted successfully.", deleteGitRepoDetailsRequest.getKsGitInfoId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (deleteGitRepoDetailsRequest.getKsGitIngestionInfoId() != null && !deleteGitRepoDetailsRequest.getKsGitIngestionInfoId().isEmpty()) {
|
|
|
|
|
ksGitIngestionInfoRepository.deleteById(deleteGitRepoDetailsRequest.getKsGitIngestionInfoId());
|
|
|
|
|
logger.info("KSGitIngestionInfo with id {} deleted successfully.", deleteGitRepoDetailsRequest.getKsGitIngestionInfoId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (VectorStore store : vectorStoreMetadataDetails) {
|
|
|
|
|
vectorStoreRepository.deleteById(store.getId());
|
|
|
|
|
logger.info("VectorStore with id {} deleted successfully.", store.getId());
|
|
|
|
|
}
|
|
|
|
|
logger.info("All records deleted successfully.");
|
|
|
|
|
} else {
|
|
|
|
|
if (!KSGitInfoExists) {
|
|
|
|
|
logger.warn("getKsGitInfo with id {} does not exist.", deleteGitRepoDetailsRequest.getKsGitInfoId());
|
|
|
|
|
} else if (!KSGitIngestionInfoExists) {
|
|
|
|
|
logger.warn("KSGitIngestionInfo with id {} does not exist.", deleteGitRepoDetailsRequest.getKsGitIngestionInfoId());
|
|
|
|
|
} else if (vectorStoreMetadataDetails.isEmpty()) {
|
|
|
|
|
logger.warn("No VectorStore Data available");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
logger.error("An error occurred while deleting records: ", e);
|
|
|
|
|
throw new RuntimeException("An error occurred while deleting records", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|