use of io.apiman.manager.api.beans.clients.UpdateClientBean in project apiman by apiman.
the class ClientAppService method updateClient.
public void updateClient(String organizationId, String clientId, UpdateClientBean bean) throws ClientNotFoundException, NotAuthorizedException {
tryAction(() -> {
ClientBean clientForUpdate = getClientFromStorage(organizationId, clientId);
EntityUpdatedData auditData = new EntityUpdatedData();
if (AuditUtils.valueChanged(clientForUpdate.getDescription(), bean.getDescription())) {
// $NON-NLS-1$
auditData.addChange("description", clientForUpdate.getDescription(), bean.getDescription());
clientForUpdate.setDescription(bean.getDescription());
}
if (AuditUtils.valueChanged(clientForUpdate.getImage(), bean.getImage())) {
// $NON-NLS-1$
auditData.addChange("image", clientForUpdate.getImage(), bean.getImage());
// Remove old image
if (clientForUpdate.getImage() != null) {
blobstore.remove(clientForUpdate.getImage());
}
// Attach to new image
clientForUpdate.setImage(bean.getImage());
if (bean.getImage() != null) {
blobstore.attachToBlob(bean.getImage());
}
}
storage.updateClient(clientForUpdate);
storage.createAuditEntry(AuditUtils.clientUpdated(clientForUpdate, auditData, securityContext));
// $NON-NLS-1$
LOGGER.debug("Updated client {0}: {1}", clientForUpdate.getName(), clientForUpdate);
});
}
use of io.apiman.manager.api.beans.clients.UpdateClientBean in project apiman by apiman.
the class OrganizationResourceImpl method updateClient.
/**
* @see IOrganizationResource#updateClient(java.lang.String, java.lang.String, io.apiman.manager.api.beans.clients.UpdateClientBean)
*/
@Override
public void updateClient(String organizationId, String clientId, UpdateClientBean bean) throws ClientNotFoundException, NotAuthorizedException {
securityContext.checkPermissions(PermissionType.clientEdit, organizationId);
try {
storage.beginTx();
ClientBean clientForUpdate = getClientFromStorage(organizationId, clientId);
EntityUpdatedData auditData = new EntityUpdatedData();
if (AuditUtils.valueChanged(clientForUpdate.getDescription(), bean.getDescription())) {
// $NON-NLS-1$
auditData.addChange("description", clientForUpdate.getDescription(), bean.getDescription());
clientForUpdate.setDescription(bean.getDescription());
}
storage.updateClient(clientForUpdate);
storage.createAuditEntry(AuditUtils.clientUpdated(clientForUpdate, auditData, securityContext));
storage.commitTx();
// $NON-NLS-1$
log.debug(String.format("Updated client %s: %s", clientForUpdate.getName(), clientForUpdate));
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
Aggregations