Search in sources :

Example 1 with UpdatePlanBean

use of io.apiman.manager.api.beans.plans.UpdatePlanBean 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 2 with UpdatePlanBean

use of io.apiman.manager.api.beans.plans.UpdatePlanBean in project apiman by apiman.

the class OrganizationResourceImpl method updatePlan.

/**
 * @see IOrganizationResource#updatePlan(java.lang.String,
 * java.lang.String, io.apiman.manager.api.beans.plans.UpdatePlanBean)
 */
@Override
public void updatePlan(String organizationId, String planId, UpdatePlanBean bean) throws PlanNotFoundException, NotAuthorizedException {
    securityContext.checkPermissions(PermissionType.planEdit, organizationId);
    EntityUpdatedData auditData = new EntityUpdatedData();
    try {
        storage.beginTx();
        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));
        storage.commitTx();
        // $NON-NLS-1$
        log.debug(String.format("Updated plan: %s", planForUpdate));
    } 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) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) UsagePerPlanBean(io.apiman.manager.api.beans.metrics.UsagePerPlanBean) NewPlanBean(io.apiman.manager.api.beans.plans.NewPlanBean) ApiPlanBean(io.apiman.manager.api.beans.apis.ApiPlanBean) UpdatePlanBean(io.apiman.manager.api.beans.plans.UpdatePlanBean) ResponseStatsPerPlanBean(io.apiman.manager.api.beans.metrics.ResponseStatsPerPlanBean) 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

EntityUpdatedData (io.apiman.manager.api.beans.audit.data.EntityUpdatedData)2 NewPlanBean (io.apiman.manager.api.beans.plans.NewPlanBean)2 PlanBean (io.apiman.manager.api.beans.plans.PlanBean)2 UpdatePlanBean (io.apiman.manager.api.beans.plans.UpdatePlanBean)2 ApiPlanBean (io.apiman.manager.api.beans.apis.ApiPlanBean)1 ResponseStatsPerPlanBean (io.apiman.manager.api.beans.metrics.ResponseStatsPerPlanBean)1 UsagePerPlanBean (io.apiman.manager.api.beans.metrics.UsagePerPlanBean)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