Search in sources :

Example 1 with PlanAlreadyExistsException

use of io.apiman.manager.api.rest.exceptions.PlanAlreadyExistsException in project apiman by apiman.

the class OrganizationResourceImpl method createPlan.

/**
 * @see IOrganizationResource#createPlan(java.lang.String,
 *      io.apiman.manager.api.beans.plans.NewPlanBean)
 */
@Override
public PlanBean createPlan(String organizationId, NewPlanBean bean) throws OrganizationNotFoundException, PlanAlreadyExistsException, NotAuthorizedException, InvalidNameException {
    securityContext.checkPermissions(PermissionType.planEdit, organizationId);
    FieldValidator.validateName(bean.getName());
    PlanBean newPlan = new PlanBean();
    newPlan.setName(bean.getName());
    newPlan.setDescription(bean.getDescription());
    newPlan.setId(BeanUtils.idFromName(bean.getName()));
    newPlan.setCreatedOn(new Date());
    newPlan.setCreatedBy(securityContext.getCurrentUser());
    try {
        // Store/persist the new plan
        storage.beginTx();
        OrganizationBean orgBean = getOrganizationFromStorage(organizationId);
        if (storage.getPlan(orgBean.getId(), newPlan.getId()) != null) {
            throw ExceptionFactory.planAlreadyExistsException(newPlan.getName());
        }
        newPlan.setOrganization(orgBean);
        storage.createPlan(newPlan);
        storage.createAuditEntry(AuditUtils.planCreated(newPlan, securityContext));
        if (bean.getInitialVersion() != null) {
            NewPlanVersionBean newPlanVersion = new NewPlanVersionBean();
            newPlanVersion.setVersion(bean.getInitialVersion());
            createPlanVersionInternal(newPlanVersion, newPlan);
        }
        storage.commitTx();
        // $NON-NLS-1$
        log.debug(String.format("Created plan: %s", newPlan));
        return newPlan;
    } 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) NewPlanVersionBean(io.apiman.manager.api.beans.plans.NewPlanVersionBean) 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) 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) Date(java.util.Date) 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

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 NewOrganizationBean (io.apiman.manager.api.beans.orgs.NewOrganizationBean)1 OrganizationBean (io.apiman.manager.api.beans.orgs.OrganizationBean)1 UpdateOrganizationBean (io.apiman.manager.api.beans.orgs.UpdateOrganizationBean)1 NewPlanBean (io.apiman.manager.api.beans.plans.NewPlanBean)1 NewPlanVersionBean (io.apiman.manager.api.beans.plans.NewPlanVersionBean)1 PlanBean (io.apiman.manager.api.beans.plans.PlanBean)1 UpdatePlanBean (io.apiman.manager.api.beans.plans.UpdatePlanBean)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