Search in sources :

Example 1 with ApiAlreadyExistsException

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

the class OrganizationResourceImpl method createApi.

/**
 * @see IOrganizationResource#createApi(java.lang.String, io.apiman.manager.api.beans.apis.NewApiBean)
 */
@Override
public ApiBean createApi(String organizationId, NewApiBean bean) throws OrganizationNotFoundException, ApiAlreadyExistsException, NotAuthorizedException, InvalidNameException {
    securityContext.checkPermissions(PermissionType.apiEdit, organizationId);
    FieldValidator.validateName(bean.getName());
    ApiBean newApi = new ApiBean();
    newApi.setName(bean.getName());
    newApi.setDescription(bean.getDescription());
    newApi.setId(BeanUtils.idFromName(bean.getName()));
    newApi.setCreatedOn(new Date());
    newApi.setCreatedBy(securityContext.getCurrentUser());
    try {
        GatewaySummaryBean gateway = getSingularGateway();
        storage.beginTx();
        OrganizationBean orgBean = getOrganizationFromStorage(organizationId);
        if (storage.getApi(orgBean.getId(), newApi.getId()) != null) {
            throw ExceptionFactory.apiAlreadyExistsException(bean.getName());
        }
        newApi.setOrganization(orgBean);
        // Store/persist the new API
        storage.createApi(newApi);
        storage.createAuditEntry(AuditUtils.apiCreated(newApi, securityContext));
        if (bean.getInitialVersion() != null) {
            NewApiVersionBean newApiVersion = new NewApiVersionBean();
            newApiVersion.setEndpoint(bean.getEndpoint());
            newApiVersion.setEndpointType(bean.getEndpointType());
            newApiVersion.setEndpointContentType(bean.getEndpointContentType());
            newApiVersion.setPlans(bean.getPlans());
            newApiVersion.setPublicAPI(bean.getPublicAPI());
            newApiVersion.setParsePayload(bean.getParsePayload());
            newApiVersion.setDisableKeysStrip(bean.getDisableKeysStrip());
            newApiVersion.setVersion(bean.getInitialVersion());
            newApiVersion.setDefinitionUrl(bean.getDefinitionUrl());
            newApiVersion.setDefinitionType(bean.getDefinitionType());
            createApiVersionInternal(newApiVersion, newApi, gateway);
        }
        storage.commitTx();
        return newApi;
    } 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) GatewaySummaryBean(io.apiman.manager.api.beans.summary.GatewaySummaryBean) 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) NewApiVersionBean(io.apiman.manager.api.beans.apis.NewApiVersionBean) 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)1 NewApiBean (io.apiman.manager.api.beans.apis.NewApiBean)1 NewApiVersionBean (io.apiman.manager.api.beans.apis.NewApiVersionBean)1 UpdateApiBean (io.apiman.manager.api.beans.apis.UpdateApiBean)1 ClientUsagePerApiBean (io.apiman.manager.api.beans.metrics.ClientUsagePerApiBean)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 GatewaySummaryBean (io.apiman.manager.api.beans.summary.GatewaySummaryBean)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