Search in sources :

Example 1 with EntityUpdatedData

use of io.apiman.manager.api.beans.audit.data.EntityUpdatedData in project apiman by apiman.

the class OrganizationResourceImpl method update.

/**
 * @see IOrganizationResource#update(java.lang.String, io.apiman.manager.api.beans.orgs.UpdateOrganizationBean)
 */
@Override
public void update(String organizationId, UpdateOrganizationBean bean) throws OrganizationNotFoundException, NotAuthorizedException {
    securityContext.checkPermissions(PermissionType.orgEdit, organizationId);
    try {
        storage.beginTx();
        OrganizationBean orgForUpdate = getOrganizationFromStorage(organizationId);
        EntityUpdatedData auditData = new EntityUpdatedData();
        if (AuditUtils.valueChanged(orgForUpdate.getDescription(), bean.getDescription())) {
            // $NON-NLS-1$
            auditData.addChange("description", orgForUpdate.getDescription(), bean.getDescription());
            orgForUpdate.setDescription(bean.getDescription());
        }
        storage.updateOrganization(orgForUpdate);
        storage.createAuditEntry(AuditUtils.organizationUpdated(orgForUpdate, auditData, securityContext));
        storage.commitTx();
        // $NON-NLS-1$
        log.debug(String.format("Updated organization %s: %s", orgForUpdate.getName(), orgForUpdate));
    } catch (AbstractRestException e) {
        storage.rollbackTx();
        throw e;
    } catch (Exception e) {
        storage.rollbackTx();
        throw new SystemErrorException(e);
    }
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) NewOrganizationBean(io.apiman.manager.api.beans.orgs.NewOrganizationBean) UpdateOrganizationBean(io.apiman.manager.api.beans.orgs.UpdateOrganizationBean) 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)

Example 2 with EntityUpdatedData

use of io.apiman.manager.api.beans.audit.data.EntityUpdatedData in project apiman by apiman.

the class OrganizationService method updateOrg.

public void updateOrg(String organizationId, UpdateOrganizationBean bean) throws OrganizationNotFoundException, NotAuthorizedException {
    OrganizationBean orgForUpdate = tryAction(() -> getOrganizationFromStorage(organizationId));
    EntityUpdatedData auditData = new EntityUpdatedData();
    if (AuditUtils.valueChanged(orgForUpdate.getDescription(), bean.getDescription())) {
        // $NON-NLS-1$
        auditData.addChange("description", orgForUpdate.getDescription(), bean.getDescription());
        orgForUpdate.setDescription(bean.getDescription());
    }
    tryAction(() -> {
        storage.updateOrganization(orgForUpdate);
        storage.createAuditEntry(AuditUtils.organizationUpdated(orgForUpdate, auditData, securityContext));
    });
    // $NON-NLS-1$
    LOGGER.debug(String.format("Updated organization %s: %s", orgForUpdate.getName(), orgForUpdate));
}
Also used : UpdateOrganizationBean(io.apiman.manager.api.beans.orgs.UpdateOrganizationBean) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) NewOrganizationBean(io.apiman.manager.api.beans.orgs.NewOrganizationBean) EntityUpdatedData(io.apiman.manager.api.beans.audit.data.EntityUpdatedData)

Example 3 with EntityUpdatedData

use of io.apiman.manager.api.beans.audit.data.EntityUpdatedData in project apiman by apiman.

the class PlanService method updatePlan.

public void updatePlan(String organizationId, String planId, UpdatePlanBean bean) throws PlanNotFoundException, NotAuthorizedException {
    EntityUpdatedData auditData = new EntityUpdatedData();
    tryAction(() -> {
        PlanBean planForUpdate = storage.getPlan(organizationId, planId);
        if (planForUpdate == null) {
            throw ExceptionFactory.planNotFoundException(planId);
        }
        if (AuditUtils.valueChanged(planForUpdate.getDescription(), bean.getDescription())) {
            // $NON-NLS-1$
            auditData.addChange("description", planForUpdate.getDescription(), bean.getDescription());
            planForUpdate.setDescription(bean.getDescription());
        }
        storage.updatePlan(planForUpdate);
        storage.createAuditEntry(AuditUtils.planUpdated(planForUpdate, auditData, securityContext));
        // $NON-NLS-1$
        LOGGER.debug(String.format("Updated plan: %s", planForUpdate));
    });
}
Also used : NewPlanBean(io.apiman.manager.api.beans.plans.NewPlanBean) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) UpdatePlanBean(io.apiman.manager.api.beans.plans.UpdatePlanBean) EntityUpdatedData(io.apiman.manager.api.beans.audit.data.EntityUpdatedData)

Example 4 with EntityUpdatedData

use of io.apiman.manager.api.beans.audit.data.EntityUpdatedData 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 5 with EntityUpdatedData

use of io.apiman.manager.api.beans.audit.data.EntityUpdatedData in project apiman by apiman.

the class ApiService method deleteApiImage.

public void deleteApiImage(String organizationId, String apiId) throws OrganizationNotFoundException, ApiVersionNotFoundException, NotAuthorizedException {
    tryAction(() -> {
        ApiBean apiForUpdate = getApiFromStorage(organizationId, apiId);
        EntityUpdatedData auditData = new EntityUpdatedData();
        if (apiForUpdate.getImage() != null) {
            blobStore.remove(apiForUpdate.getImage());
            apiForUpdate.setImage(null);
            auditData.addChange("image", apiForUpdate.getImage(), null);
        }
        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)

Aggregations

EntityUpdatedData (io.apiman.manager.api.beans.audit.data.EntityUpdatedData)11 StorageException (io.apiman.manager.api.core.exceptions.StorageException)6 GatewayAuthenticationException (io.apiman.manager.api.gateway.GatewayAuthenticationException)6 ApiAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ApiAlreadyExistsException)6 ApiDefinitionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiDefinitionNotFoundException)6 ApiNotFoundException (io.apiman.manager.api.rest.exceptions.ApiNotFoundException)6 ApiVersionAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ApiVersionAlreadyExistsException)6 ApiVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException)6 EntityStillActiveException (io.apiman.manager.api.rest.exceptions.EntityStillActiveException)6 GatewayNotFoundException (io.apiman.manager.api.rest.exceptions.GatewayNotFoundException)6 InvalidApiStatusException (io.apiman.manager.api.rest.exceptions.InvalidApiStatusException)6 InvalidNameException (io.apiman.manager.api.rest.exceptions.InvalidNameException)6 InvalidParameterException (io.apiman.manager.api.rest.exceptions.InvalidParameterException)6 InvalidVersionException (io.apiman.manager.api.rest.exceptions.InvalidVersionException)6 NotAuthorizedException (io.apiman.manager.api.rest.exceptions.NotAuthorizedException)6 OrganizationNotFoundException (io.apiman.manager.api.rest.exceptions.OrganizationNotFoundException)6 PlanNotFoundException (io.apiman.manager.api.rest.exceptions.PlanNotFoundException)6 AbstractRestException (io.apiman.manager.api.rest.exceptions.AbstractRestException)5 ClientAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ClientAlreadyExistsException)5 ClientNotFoundException (io.apiman.manager.api.rest.exceptions.ClientNotFoundException)5