diff --git a/src/main/java/com/olympus/apollo/controllers/FeApi/KSGitController.java b/src/main/java/com/olympus/apollo/controllers/FeApi/KSGitController.java index fb9d113..d141daa 100644 --- a/src/main/java/com/olympus/apollo/controllers/FeApi/KSGitController.java +++ b/src/main/java/com/olympus/apollo/controllers/FeApi/KSGitController.java @@ -7,6 +7,7 @@ import java.util.List; import com.olympus.apollo.exception.GitCloneException; import com.olympus.apollo.services.GitService; +import com.olympus.apollo.services.KSGitInfoService; import com.olympus.apollo.utils.GitUtils; import com.olympus.dto.GitCloneInput; import com.olympus.dto.GitPullOutput; @@ -33,6 +34,9 @@ public class KSGitController { @Autowired private KSGitIngestionInfoRepository ksGitIngestionInfoRepository; + @Autowired + private KSGitInfoService ksGitInfoService; + @Autowired private GitService gitService; @@ -43,7 +47,7 @@ public class KSGitController { @GetMapping("") public List listGitInfo() { - List result = (List) ksGitInfoRepository.findAll(); + List result = ksGitInfoService.findByProjectNameAndApplication(); return result; } diff --git a/src/main/java/com/olympus/apollo/repository/KSGitInfoRepository.java b/src/main/java/com/olympus/apollo/repository/KSGitInfoRepository.java index 5e5a6c2..838395a 100644 --- a/src/main/java/com/olympus/apollo/repository/KSGitInfoRepository.java +++ b/src/main/java/com/olympus/apollo/repository/KSGitInfoRepository.java @@ -1,5 +1,6 @@ package com.olympus.apollo.repository; +import java.util.List; import java.util.Optional; import org.springframework.data.mongodb.repository.MongoRepository; @@ -17,4 +18,9 @@ public interface KSGitInfoRepository extends MongoRepository @Query("{'repoName': ?0, 'ksGitIngestionInfo.metadata.KsBranch': ?1}") Optional findByRepoNameAndBranchName(String repoName, String KsApplicationName); + + @Query("{ $and: [ { 'ksGitIngestionInfo.metadata.KsApplicationName': ?0 }, { 'projectName': ?1 } ] }") + List getByApplicationAndProject(String appName, String projectName); + + List findByProjectName(String projectName); } diff --git a/src/main/java/com/olympus/apollo/services/KSGitInfoService.java b/src/main/java/com/olympus/apollo/services/KSGitInfoService.java index fde1ec9..0d88d5f 100644 --- a/src/main/java/com/olympus/apollo/services/KSGitInfoService.java +++ b/src/main/java/com/olympus/apollo/services/KSGitInfoService.java @@ -1,13 +1,19 @@ package com.olympus.apollo.services; + import java.util.List; +import java.util.logging.Logger; import java.util.stream.Collectors; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Service; import com.olympus.dto.KSGitInfoDTO; +import com.olympus.model.apollo.KSGitInfo; import com.olympus.apollo.repository.KSGitInfoRepository; +import com.olympus.apollo.security.entity.User; + @Service public class KSGitInfoService { @@ -15,6 +21,8 @@ public class KSGitInfoService { @Autowired private KSGitInfoRepository ksGitInfoRepository; + private Logger logger = Logger.getLogger(KSGitInfoService.class.getName()); + public List listGitInfo() { return ksGitInfoRepository.findAll().stream() .map(repo -> new KSGitInfoDTO( @@ -25,4 +33,24 @@ public class KSGitInfoService { )) .collect(Collectors.toList()); } + + public List findByProjectNameAndApplication() { + + List result = null; + + try { + + User user = (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); + if(user.getSelectedApplication()!=null){ + result = ksGitInfoRepository.getByApplicationAndProject(user.getSelectedApplication().getInternal_name(), user.getSelectedProject().getInternal_name()); + }else{ + result = ksGitInfoRepository.findByProjectName(user.getSelectedProject().getInternal_name()); + } + + } catch (Exception e) { + logger.info("Error in fetching data from KSGitInfoRepository " + e.getMessage()); + } + + return result; + } }