use of io.apiman.manager.api.beans.apis.UpdateApiBean in project apiman by apiman.
the class ApiService method updateApi.
public void updateApi(String organizationId, String apiId, UpdateApiBean bean) throws ApiNotFoundException, NotAuthorizedException {
tryAction(() -> {
ApiBean apiForUpdate = getApiFromStorage(organizationId, apiId);
EntityUpdatedData auditData = new EntityUpdatedData();
if (AuditUtils.valueChanged(apiForUpdate.getDescription(), bean.getDescription())) {
// $NON-NLS-1$
auditData.addChange("description", apiForUpdate.getDescription(), bean.getDescription());
apiForUpdate.setDescription(bean.getDescription());
}
if (AuditUtils.valueChanged(apiForUpdate.getImage(), bean.getImage())) {
auditData.addChange("image", apiForUpdate.getImage(), bean.getImage());
// Remove old image
if (apiForUpdate.getImage() != null) {
blobStore.remove(apiForUpdate.getImage());
}
// Attach to new image
apiForUpdate.setImage(bean.getImage());
if (bean.getImage() != null) {
blobStore.attachToBlob(bean.getImage());
}
}
if (AuditUtils.valueChanged(tagMapper.toDto(apiForUpdate.getTags()), bean.getTags())) {
// TODO(msavy): add audit entry.
// auditData.addChange("tags", apiForUpdate.getTags(), bean.getTags());
apiForUpdate.setTags(tagMapper.toEntity(bean.getTags()));
}
storage.updateApi(apiForUpdate);
storage.createAuditEntry(AuditUtils.apiUpdated(apiForUpdate, auditData, securityContext));
});
}
use of io.apiman.manager.api.beans.apis.UpdateApiBean in project apiman by apiman.
the class OrganizationResourceImpl method updateApi.
/**
* @see IOrganizationResource#updateApi(java.lang.String, java.lang.String, io.apiman.manager.api.beans.apis.UpdateApiBean)
*/
@Override
public void updateApi(String organizationId, String apiId, UpdateApiBean bean) throws ApiNotFoundException, NotAuthorizedException {
securityContext.checkPermissions(PermissionType.apiEdit, organizationId);
try {
storage.beginTx();
ApiBean apiForUpdate = getApiFromStorage(organizationId, apiId);
EntityUpdatedData auditData = new EntityUpdatedData();
if (AuditUtils.valueChanged(apiForUpdate.getDescription(), bean.getDescription())) {
// $NON-NLS-1$
auditData.addChange("description", apiForUpdate.getDescription(), bean.getDescription());
apiForUpdate.setDescription(bean.getDescription());
}
storage.updateApi(apiForUpdate);
storage.createAuditEntry(AuditUtils.apiUpdated(apiForUpdate, auditData, securityContext));
storage.commitTx();
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
Aggregations