sonar 대응
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user