Search in sources :

Example 1 with UpdateApiBean

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));
    });
}
Also used : UpdateApiBean(io.apiman.manager.api.beans.apis.UpdateApiBean) ApiBean(io.apiman.manager.api.beans.apis.ApiBean) NewApiBean(io.apiman.manager.api.beans.apis.NewApiBean) EntityUpdatedData(io.apiman.manager.api.beans.audit.data.EntityUpdatedData)

Example 2 with UpdateApiBean

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);
    }
}
Also used : UpdateApiBean(io.apiman.manager.api.beans.apis.UpdateApiBean) ApiBean(io.apiman.manager.api.beans.apis.ApiBean) NewApiBean(io.apiman.manager.api.beans.apis.NewApiBean) ClientUsagePerApiBean(io.apiman.manager.api.beans.metrics.ClientUsagePerApiBean) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) EntityUpdatedData(io.apiman.manager.api.beans.audit.data.EntityUpdatedData) ClientAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ClientAlreadyExistsException) ApiVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ApiVersionAlreadyExistsException) GatewayNotFoundException(io.apiman.manager.api.rest.exceptions.GatewayNotFoundException) InvalidVersionException(io.apiman.manager.api.rest.exceptions.InvalidVersionException) OrganizationAlreadyExistsException(io.apiman.manager.api.rest.exceptions.OrganizationAlreadyExistsException) EntityStillActiveException(io.apiman.manager.api.rest.exceptions.EntityStillActiveException) PolicyNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyNotFoundException) PlanAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PlanAlreadyExistsException) ApiAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ApiAlreadyExistsException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) UserNotFoundException(io.apiman.manager.api.rest.exceptions.UserNotFoundException) GatewayAuthenticationException(io.apiman.manager.api.gateway.GatewayAuthenticationException) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) PlanVersionNotFoundException(io.apiman.manager.api.rest.exceptions.PlanVersionNotFoundException) RoleNotFoundException(io.apiman.manager.api.rest.exceptions.RoleNotFoundException) InvalidNameException(io.apiman.manager.api.rest.exceptions.InvalidNameException) ClientVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException) IOException(java.io.IOException) InvalidApiStatusException(io.apiman.manager.api.rest.exceptions.InvalidApiStatusException) ApiNotFoundException(io.apiman.manager.api.rest.exceptions.ApiNotFoundException) ContractAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ContractAlreadyExistsException) InvalidClientStatusException(io.apiman.manager.api.rest.exceptions.InvalidClientStatusException) ApiVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) ClientVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ClientVersionAlreadyExistsException) InvalidPlanStatusException(io.apiman.manager.api.rest.exceptions.InvalidPlanStatusException) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) ContractNotFoundException(io.apiman.manager.api.rest.exceptions.ContractNotFoundException) InvalidParameterException(io.apiman.manager.api.rest.exceptions.InvalidParameterException) ClientNotFoundException(io.apiman.manager.api.rest.exceptions.ClientNotFoundException) PlanNotFoundException(io.apiman.manager.api.rest.exceptions.PlanNotFoundException) InvalidMetricCriteriaException(io.apiman.manager.api.rest.exceptions.InvalidMetricCriteriaException) MalformedURLException(java.net.MalformedURLException) PlanVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PlanVersionAlreadyExistsException) PolicyDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException) OrganizationNotFoundException(io.apiman.manager.api.rest.exceptions.OrganizationNotFoundException) ApiDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiDefinitionNotFoundException)

Aggregations

ApiBean (io.apiman.manager.api.beans.apis.ApiBean)2 NewApiBean (io.apiman.manager.api.beans.apis.NewApiBean)2 UpdateApiBean (io.apiman.manager.api.beans.apis.UpdateApiBean)2 EntityUpdatedData (io.apiman.manager.api.beans.audit.data.EntityUpdatedData)2 ClientUsagePerApiBean (io.apiman.manager.api.beans.metrics.ClientUsagePerApiBean)1 StorageException (io.apiman.manager.api.core.exceptions.StorageException)1 GatewayAuthenticationException (io.apiman.manager.api.gateway.GatewayAuthenticationException)1 AbstractRestException (io.apiman.manager.api.rest.exceptions.AbstractRestException)1 ApiAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ApiAlreadyExistsException)1 ApiDefinitionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiDefinitionNotFoundException)1 ApiNotFoundException (io.apiman.manager.api.rest.exceptions.ApiNotFoundException)1 ApiVersionAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ApiVersionAlreadyExistsException)1 ApiVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException)1 ClientAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ClientAlreadyExistsException)1 ClientNotFoundException (io.apiman.manager.api.rest.exceptions.ClientNotFoundException)1 ClientVersionAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ClientVersionAlreadyExistsException)1 ClientVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException)1 ContractAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ContractAlreadyExistsException)1 ContractNotFoundException (io.apiman.manager.api.rest.exceptions.ContractNotFoundException)1 EntityStillActiveException (io.apiman.manager.api.rest.exceptions.EntityStillActiveException)1