Skip to content
This repository has been archived by the owner on Aug 20, 2021. It is now read-only.

Commit

Permalink
fix(view): Update API views when removing a view
Browse files Browse the repository at this point in the history
  • Loading branch information
brasseld committed Nov 21, 2016
1 parent 7cc48bf commit 2318b57
Showing 1 changed file with 18 additions and 25 deletions.
Expand Up @@ -622,13 +622,29 @@ public ImageEntity getPicture(String apiId) {
@Override
public void deleteViewFromAPIs(final String viewId) {
findAll().forEach(api -> {
if (api.getViews()
if (api.getViews() != null && api.getViews()
.removeIf(view -> view.equals(viewId))) {
update(api.getId(), convert(api));
removeView(api.getId(), viewId);
}
});
}

private void removeView(String apiId, String viewId) throws TechnicalManagementException {
try {
Optional<Api> optApi = apiRepository.findById(apiId);
if (optApi.isPresent()) {
Api api = optApi.get();
api.getViews().remove(viewId);
apiRepository.update(api);
} else {
throw new ApiNotFoundException(apiId);
}
} catch (Exception ex) {
LOGGER.error("An error occurs while removing view from API: {}", apiId, ex);
throw new TechnicalManagementException("An error occurs while removing view from API: " + apiId, ex);
}
}

private void updateLifecycle(String apiId, LifecycleState lifecycleState, String username) throws TechnicalException {
Optional<Api> optApi = apiRepository.findById(apiId);
if (optApi.isPresent()) {
Expand All @@ -652,29 +668,6 @@ private void updateLifecycle(String apiId, LifecycleState lifecycleState, String
}
}

private UpdateApiEntity convert(final ApiEntity apiEntity) {
final UpdateApiEntity updateApiEntity = new UpdateApiEntity();

updateApiEntity.setDescription(apiEntity.getDescription());
updateApiEntity.setName(apiEntity.getName());
updateApiEntity.setViews(apiEntity.getViews());
updateApiEntity.setPaths(apiEntity.getPaths());
updateApiEntity.setPicture(apiEntity.getPicture());
updateApiEntity.setProperties(apiEntity.getProperties());
updateApiEntity.setProxy(apiEntity.getProxy());
updateApiEntity.setResources(apiEntity.getResources());
updateApiEntity.setServices(apiEntity.getServices());
updateApiEntity.setTags(apiEntity.getTags());
updateApiEntity.setVersion(apiEntity.getVersion());
updateApiEntity.setVisibility(apiEntity.getVisibility());
if (apiEntity.getGroup() != null && (
apiEntity.getGroup().getId() != null && !apiEntity.getGroup().getId().isEmpty())) {
updateApiEntity.setGroup(apiEntity.getGroup().getId());
}

return updateApiEntity;
}

private Set<ApiEntity> convert(Set<Api> apis, boolean readDefinition) throws TechnicalException {
if (apis == null || apis.isEmpty()) {
return Collections.emptySet();
Expand Down

0 comments on commit 2318b57

Please sign in to comment.