Merged PR 38: refinements
This commit is contained in:
@@ -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<KSGitInfo> listGitInfo() {
|
||||
List<KSGitInfo> result = (List<KSGitInfo>) ksGitInfoRepository.findAll();
|
||||
List<KSGitInfo> result = ksGitInfoService.findByProjectNameAndApplication();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<KSGitInfo, String>
|
||||
|
||||
@Query("{'repoName': ?0, 'ksGitIngestionInfo.metadata.KsBranch': ?1}")
|
||||
Optional<KSGitInfo> findByRepoNameAndBranchName(String repoName, String KsApplicationName);
|
||||
|
||||
@Query("{ $and: [ { 'ksGitIngestionInfo.metadata.KsApplicationName': ?0 }, { 'projectName': ?1 } ] }")
|
||||
List<KSGitInfo> getByApplicationAndProject(String appName, String projectName);
|
||||
|
||||
List<KSGitInfo> findByProjectName(String projectName);
|
||||
}
|
||||
|
||||
@@ -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<KSGitInfoDTO> listGitInfo() {
|
||||
return ksGitInfoRepository.findAll().stream()
|
||||
.map(repo -> new KSGitInfoDTO(
|
||||
@@ -25,4 +33,24 @@ public class KSGitInfoService {
|
||||
))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<KSGitInfo> findByProjectNameAndApplication() {
|
||||
|
||||
List<KSGitInfo> 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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user