Update for Git integration
This commit is contained in:
@@ -0,0 +1,45 @@
|
|||||||
|
package com.olympus.apollo.controllers.FeApi;
|
||||||
|
|
||||||
|
import com.olympus.apollo.services.ApplicationService;
|
||||||
|
import com.olympus.dto.ApplicationDTO;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/fe-api/applications")
|
||||||
|
public class ApplicationController {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ApplicationController.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationService applicationService;
|
||||||
|
|
||||||
|
@GetMapping("")
|
||||||
|
public ResponseEntity<List<ApplicationDTO>> getAllApplications() {
|
||||||
|
try {
|
||||||
|
List<ApplicationDTO> applications = applicationService.getAllApplications();
|
||||||
|
return ResponseEntity.ok(applications);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error fetching applications", e);
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public ResponseEntity<ApplicationDTO> getApplicationById(@PathVariable String id) {
|
||||||
|
try {
|
||||||
|
return applicationService.getApplicationById(id)
|
||||||
|
.map(ResponseEntity::ok)
|
||||||
|
.orElse(ResponseEntity.notFound().build());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error fetching application by id: {}", id, e);
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
package com.olympus.apollo.controllers.FeApi;
|
||||||
|
|
||||||
|
import com.olympus.apollo.services.RepositoryManagementService;
|
||||||
|
import com.olympus.dto.RepositoryCreateDTO;
|
||||||
|
import com.olympus.dto.RepositoryResponseDTO;
|
||||||
|
import com.olympus.dto.RepositoryUpdateDTO;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController("feApiRepositoryController")
|
||||||
|
@RequestMapping("/fe-api/repositories")
|
||||||
|
public class RepositoryController {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(RepositoryController.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private RepositoryManagementService repositoryService;
|
||||||
|
|
||||||
|
@GetMapping("")
|
||||||
|
public ResponseEntity<List<RepositoryResponseDTO>> getAllRepositories() {
|
||||||
|
try {
|
||||||
|
List<RepositoryResponseDTO> repositories = repositoryService.getAllRepositories();
|
||||||
|
return ResponseEntity.ok(repositories);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error fetching repositories", e);
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{id}")
|
||||||
|
public ResponseEntity<RepositoryResponseDTO> getRepositoryById(@PathVariable String id) {
|
||||||
|
try {
|
||||||
|
return repositoryService.getRepositoryById(id)
|
||||||
|
.map(ResponseEntity::ok)
|
||||||
|
.orElse(ResponseEntity.notFound().build());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error fetching repository by id: {}", id, e);
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/by-application/{applicationId}")
|
||||||
|
public ResponseEntity<List<RepositoryResponseDTO>> getRepositoriesByApplication(@PathVariable String applicationId) {
|
||||||
|
try {
|
||||||
|
List<RepositoryResponseDTO> repositories = repositoryService.getRepositoriesByApplicationId(applicationId);
|
||||||
|
return ResponseEntity.ok(repositories);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error fetching repositories by application: {}", applicationId, e);
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/by-project/{projectName}")
|
||||||
|
public ResponseEntity<List<RepositoryResponseDTO>> getRepositoriesByProject(@PathVariable String projectName) {
|
||||||
|
try {
|
||||||
|
List<RepositoryResponseDTO> repositories = repositoryService.getRepositoriesByProjectName(projectName);
|
||||||
|
return ResponseEntity.ok(repositories);
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error fetching repositories by project: {}", projectName, e);
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("")
|
||||||
|
public ResponseEntity<?> createRepository(@RequestBody RepositoryCreateDTO createDTO) {
|
||||||
|
try {
|
||||||
|
RepositoryResponseDTO created = repositoryService.createRepository(createDTO);
|
||||||
|
return ResponseEntity.status(HttpStatus.CREATED).body(created);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
logger.warn("Invalid repository creation request: {}", e.getMessage());
|
||||||
|
return ResponseEntity.badRequest().body(e.getMessage());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error creating repository", e);
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{id}")
|
||||||
|
public ResponseEntity<?> updateRepository(@PathVariable String id, @RequestBody RepositoryUpdateDTO updateDTO) {
|
||||||
|
try {
|
||||||
|
RepositoryResponseDTO updated = repositoryService.updateRepository(id, updateDTO);
|
||||||
|
return ResponseEntity.ok(updated);
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
logger.warn("Invalid repository update request: {}", e.getMessage());
|
||||||
|
return ResponseEntity.badRequest().body(e.getMessage());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error updating repository: {}", id, e);
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{id}")
|
||||||
|
public ResponseEntity<?> deleteRepository(@PathVariable String id) {
|
||||||
|
try {
|
||||||
|
repositoryService.deleteRepository(id);
|
||||||
|
return ResponseEntity.ok().build();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
logger.warn("Invalid repository deletion request: {}", e.getMessage());
|
||||||
|
return ResponseEntity.badRequest().body(e.getMessage());
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.error("Error deleting repository: {}", id, e);
|
||||||
|
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package com.olympus.apollo.repository;
|
||||||
|
|
||||||
|
import com.olympus.model.Application;
|
||||||
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
|
import org.springframework.data.mongodb.repository.Query;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface ApplicationRepository extends MongoRepository<Application, String> {
|
||||||
|
|
||||||
|
@Query("{ 'internal_name' : ?0 }")
|
||||||
|
List<Application> findByInternalName(String internalName);
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package com.olympus.apollo.repository;
|
||||||
|
|
||||||
|
import com.olympus.model.apollo.KsGitInfoOpensearch;
|
||||||
|
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||||
|
import org.springframework.data.mongodb.repository.Query;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public interface KsGitInfoOpensearchRepository extends MongoRepository<KsGitInfoOpensearch, String> {
|
||||||
|
|
||||||
|
List<KsGitInfoOpensearch> findByApplicationId(String applicationId);
|
||||||
|
|
||||||
|
List<KsGitInfoOpensearch> findByProjectName(String projectName);
|
||||||
|
|
||||||
|
List<KsGitInfoOpensearch> findByIngestionStatus(String ingestionStatus);
|
||||||
|
|
||||||
|
@Query("{ 'applicationId': ?0, 'projectName': ?1 }")
|
||||||
|
List<KsGitInfoOpensearch> findByApplicationIdAndProjectName(String applicationId, String projectName);
|
||||||
|
|
||||||
|
Optional<KsGitInfoOpensearch> findByGitUrlAndBranch(String gitUrl, String branch);
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.olympus.apollo.services;
|
||||||
|
|
||||||
|
import com.olympus.apollo.repository.ApplicationRepository;
|
||||||
|
import com.olympus.dto.ApplicationDTO;
|
||||||
|
import com.olympus.model.Application;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class ApplicationService {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(ApplicationService.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationRepository applicationRepository;
|
||||||
|
|
||||||
|
public List<ApplicationDTO> getAllApplications() {
|
||||||
|
return applicationRepository.findAll().stream()
|
||||||
|
.map(this::convertToDTO)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<ApplicationDTO> getApplicationById(String id) {
|
||||||
|
return applicationRepository.findById(id).map(this::convertToDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ApplicationDTO convertToDTO(Application entity) {
|
||||||
|
ApplicationDTO dto = new ApplicationDTO();
|
||||||
|
dto.setId(entity.getId());
|
||||||
|
dto.setInternalName(entity.getInternal_name());
|
||||||
|
dto.setFeName(entity.getFE_name());
|
||||||
|
dto.setDescription(entity.getDescription());
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,169 @@
|
|||||||
|
package com.olympus.apollo.services;
|
||||||
|
|
||||||
|
import com.olympus.apollo.repository.KsGitInfoOpensearchRepository;
|
||||||
|
import com.olympus.dto.RepositoryCreateDTO;
|
||||||
|
import com.olympus.dto.RepositoryResponseDTO;
|
||||||
|
import com.olympus.dto.RepositoryUpdateDTO;
|
||||||
|
import com.olympus.model.apollo.IngestionDetail;
|
||||||
|
import com.olympus.model.apollo.IngestionResults;
|
||||||
|
import com.olympus.model.apollo.KsGitInfoOpensearch;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class RepositoryManagementService {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(RepositoryManagementService.class);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private KsGitInfoOpensearchRepository repository;
|
||||||
|
|
||||||
|
public List<RepositoryResponseDTO> getAllRepositories() {
|
||||||
|
return repository.findAll().stream()
|
||||||
|
.map(this::convertToDTO)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RepositoryResponseDTO> getRepositoriesByApplicationId(String applicationId) {
|
||||||
|
return repository.findByApplicationId(applicationId).stream()
|
||||||
|
.map(this::convertToDTO)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<RepositoryResponseDTO> getRepositoriesByProjectName(String projectName) {
|
||||||
|
return repository.findByProjectName(projectName).stream()
|
||||||
|
.map(this::convertToDTO)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public Optional<RepositoryResponseDTO> getRepositoryById(String id) {
|
||||||
|
return repository.findById(id).map(this::convertToDTO);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RepositoryResponseDTO createRepository(RepositoryCreateDTO createDTO) {
|
||||||
|
// Check if repository already exists
|
||||||
|
Optional<KsGitInfoOpensearch> existing = repository.findByGitUrlAndBranch(
|
||||||
|
createDTO.getGitUrl(), createDTO.getBranch());
|
||||||
|
|
||||||
|
if (existing.isPresent()) {
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Repository already exists with URL: " + createDTO.getGitUrl() + " and branch: " + createDTO.getBranch());
|
||||||
|
}
|
||||||
|
|
||||||
|
KsGitInfoOpensearch entity = new KsGitInfoOpensearch();
|
||||||
|
entity.setProjectName(createDTO.getProjectName());
|
||||||
|
entity.setApplicationId(createDTO.getApplicationId());
|
||||||
|
entity.setApplicationName(createDTO.getApplicationName());
|
||||||
|
entity.setBranch(createDTO.getBranch());
|
||||||
|
entity.setGitUrl(createDTO.getGitUrl());
|
||||||
|
|
||||||
|
// Set Git credentials if provided
|
||||||
|
if (createDTO.getGitCredentials() != null) {
|
||||||
|
KsGitInfoOpensearch.GitCredentials credentials = new KsGitInfoOpensearch.GitCredentials();
|
||||||
|
credentials.setUsername(createDTO.getGitCredentials().getUsername());
|
||||||
|
credentials.setPassword(createDTO.getGitCredentials().getPassword());
|
||||||
|
entity.setGitCredentials(credentials);
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.setIngestionStatus("RENAME TO_BE_STARTED");
|
||||||
|
entity.setCloneStatus("PENDING");
|
||||||
|
entity.setFirstIngestionDate(new Date());
|
||||||
|
entity.setStartedAt(new Date());
|
||||||
|
entity.setIngestionLastUpdated(new Date());
|
||||||
|
entity.setErrors(new ArrayList<>());
|
||||||
|
entity.setIngestionDetails(new ArrayList<>());
|
||||||
|
|
||||||
|
// Add initial ingestion detail
|
||||||
|
IngestionDetail initialDetail = new IngestionDetail();
|
||||||
|
initialDetail.setTimestamp(new Date());
|
||||||
|
initialDetail.setPhase("CREATED");
|
||||||
|
initialDetail.setMessage("Repository record created, waiting to be started");
|
||||||
|
initialDetail.setFilesProcessed(null);
|
||||||
|
initialDetail.setFilesTotal(null);
|
||||||
|
initialDetail.setErrorDetails(null);
|
||||||
|
entity.getIngestionDetails().add(initialDetail);
|
||||||
|
|
||||||
|
// Initialize results
|
||||||
|
IngestionResults results = new IngestionResults();
|
||||||
|
results.setClassesFound(0);
|
||||||
|
results.setMethodsFound(0);
|
||||||
|
results.setIndexedDocuments(0);
|
||||||
|
results.setTotalFiles(0);
|
||||||
|
results.setProcessedFiles(0);
|
||||||
|
results.setFailedFiles(0);
|
||||||
|
entity.setResults(results);
|
||||||
|
|
||||||
|
KsGitInfoOpensearch saved = repository.save(entity);
|
||||||
|
logger.info("Created new repository: {} with status TO_BE_STARTED", saved.getId());
|
||||||
|
|
||||||
|
return convertToDTO(saved);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RepositoryResponseDTO updateRepository(String id, RepositoryUpdateDTO updateDTO) {
|
||||||
|
KsGitInfoOpensearch entity = repository.findById(id)
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException("Repository not found with id: " + id));
|
||||||
|
if (updateDTO.getApplicationName() != null) {
|
||||||
|
entity.setApplicationName(updateDTO.getApplicationName());
|
||||||
|
}
|
||||||
|
if (updateDTO.getGitUrl() != null) {
|
||||||
|
entity.setGitUrl(updateDTO.getGitUrl());
|
||||||
|
}
|
||||||
|
if (updateDTO.getBranch() != null) {
|
||||||
|
entity.setBranch(updateDTO.getBranch());
|
||||||
|
}
|
||||||
|
if (updateDTO.getProjectName() != null) {
|
||||||
|
entity.setProjectName(updateDTO.getProjectName());
|
||||||
|
}
|
||||||
|
if (updateDTO.getIngestionStatus() != null) {
|
||||||
|
entity.setIngestionStatus(updateDTO.getIngestionStatus());
|
||||||
|
}
|
||||||
|
if (updateDTO.getCloneStatus() != null) {
|
||||||
|
entity.setCloneStatus(updateDTO.getCloneStatus());
|
||||||
|
}
|
||||||
|
|
||||||
|
entity.setIngestionLastUpdated(new Date());
|
||||||
|
|
||||||
|
KsGitInfoOpensearch updated = repository.save(entity);
|
||||||
|
logger.info("Updated repository: {}", id);
|
||||||
|
|
||||||
|
return convertToDTO(updated);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteRepository(String id) {
|
||||||
|
if (!repository.existsById(id)) {
|
||||||
|
throw new IllegalArgumentException("Repository not found with id: " + id);
|
||||||
|
}
|
||||||
|
repository.deleteById(id);
|
||||||
|
logger.info("Deleted repository: {}", id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private RepositoryResponseDTO convertToDTO(KsGitInfoOpensearch entity) {
|
||||||
|
RepositoryResponseDTO dto = new RepositoryResponseDTO();
|
||||||
|
dto.setId(entity.getId());
|
||||||
|
dto.setApplicationName(entity.getApplicationName());
|
||||||
|
dto.setGitUrl(entity.getGitUrl());
|
||||||
|
dto.setBranch(entity.getBranch());
|
||||||
|
dto.setIngestionStatus(entity.getIngestionStatus());
|
||||||
|
dto.setProjectName(entity.getProjectName());
|
||||||
|
dto.setIngestionLastUpdated(entity.getIngestionLastUpdated());
|
||||||
|
dto.setStartedAt(entity.getStartedAt());
|
||||||
|
dto.setIngestionDetails(entity.getIngestionDetails());
|
||||||
|
dto.setCloneStatus(entity.getCloneStatus());
|
||||||
|
dto.setCompletedAt(entity.getCompletedAt());
|
||||||
|
dto.setErrors(entity.getErrors());
|
||||||
|
dto.setClonePath(entity.getClonePath());
|
||||||
|
dto.setCommitSha(entity.getCommitSha());
|
||||||
|
dto.setIngestionProcessId(entity.getIngestionProcessId());
|
||||||
|
dto.setFirstIngestionDate(entity.getFirstIngestionDate());
|
||||||
|
dto.setResults(entity.getResults());
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user