sonar 대응

This commit is contained in:
현성필
2023-08-22 13:57:28 +09:00
parent 32a5719a12
commit 1063aaf19e
36 changed files with 188 additions and 243 deletions
@@ -18,6 +18,10 @@ import java.util.UUID;
@Transactional
public class ApiRequestMgmtService {
private static final String API_COLLECTION_NOT_FOUND = "api collection[%s] not found";
private static final String API_NOT_FOUND = "api collection[%s] not found";
@Autowired
ApiCollectionRepository apiCollectionRepository;
@@ -30,9 +34,9 @@ public class ApiRequestMgmtService {
}
public void deleteApiCollection(String id) {
ApiCollection collection = apiCollectionRepository.findById(id).orElseThrow(() -> new NotFoundException("api collection[" + id + "] not found"));
ApiCollection collection = apiCollectionRepository.findById(id).orElseThrow(() -> new NotFoundException(String.format(API_COLLECTION_NOT_FOUND, id)));
if (collection.getApis().size()>0){
if (!collection.getApis().isEmpty()) {
throw new RuntimeException("api collection[" + id + "] is not empty");
}
apiCollectionRepository.deleteById(id);
@@ -44,20 +48,20 @@ public class ApiRequestMgmtService {
}
public void updateApiCollection(String id, ApiCollection updated) {
ApiCollection collection = apiCollectionRepository.findById(id).orElseThrow(() -> new NotFoundException("api collection[" + id + "] not found"));
ApiCollection collection = apiCollectionRepository.findById(id).orElseThrow(() -> new NotFoundException(String.format(API_COLLECTION_NOT_FOUND, id)));
collection.setName(updated.getName());
apiCollectionRepository.save(collection);
}
public String saveApiToCollection(String id, ApiRequestInfo api) {
ApiCollection collection = apiCollectionRepository.findById(id).orElseThrow(() -> new NotFoundException("api collection[" + id + "] not found"));
ApiCollection collection = apiCollectionRepository.findById(id).orElseThrow(() -> new NotFoundException(String.format(API_COLLECTION_NOT_FOUND, id)));
if (StringUtils.isEmpty(api.getId())) {
api.setId(UUID.randomUUID().toString());
apiRequestRepository.save(api);
} else {
String apiId = api.getId();
ApiRequestInfo existing = apiRequestRepository.findById(apiId).orElseThrow(() -> new NotFoundException("api[" + apiId + "] not found"));
ApiRequestInfo existing = apiRequestRepository.findById(apiId).orElseThrow(() -> new NotFoundException(String.format(API_NOT_FOUND, apiId)));
existing.setName(api.getName());
existing.setMethod(api.getMethod());
existing.setPath(api.getPath());
@@ -79,8 +83,8 @@ public class ApiRequestMgmtService {
}
public void removeApiFromCollection(String id, String apiId) {
ApiCollection collection = apiCollectionRepository.findById(id).orElseThrow(() -> new NotFoundException("api collection[" + id + "] not found"));
ApiRequestInfo api = apiRequestRepository.findById(apiId).orElseThrow(() -> new NotFoundException("api[" + apiId + "] not found"));
ApiCollection collection = apiCollectionRepository.findById(id).orElseThrow(() -> new NotFoundException(String.format(API_COLLECTION_NOT_FOUND, id)));
ApiRequestInfo api = apiRequestRepository.findById(apiId).orElseThrow(() -> new NotFoundException(String.format(API_NOT_FOUND, apiId)));
collection.getApis().remove(api);
apiCollectionRepository.save(collection);