Search in sources :

Example 1 with ApiNotFoundException

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

the class OrganizationResourceImpl method deletePlan.

@Override
public void deletePlan(@PathParam("organizationId") String organizationId, @PathParam("planId") String planId) throws ApiNotFoundException, NotAuthorizedException, InvalidPlanStatusException {
    securityContext.checkPermissions(PermissionType.planAdmin, organizationId);
    List<PlanVersionSummaryBean> lockedPlans = listPlanVersions(organizationId, planId).stream().filter(summary -> summary.getStatus() == PlanStatus.Locked).collect(toList());
    if (!lockedPlans.isEmpty())
        throw ExceptionFactory.invalidPlanStatusException(lockedPlans);
    try {
        storage.beginTx();
        PlanBean plan = storage.getPlan(organizationId, planId);
        storage.deletePlan(plan);
        storage.commitTx();
    } catch (AbstractRestException e) {
        storage.rollbackTx();
        throw e;
    } catch (Exception e) {
        storage.rollbackTx();
        throw new SystemErrorException(e);
    }
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) PolicyChainBean(io.apiman.manager.api.beans.policies.PolicyChainBean) MemberBean(io.apiman.manager.api.beans.members.MemberBean) ApiPlanSummaryBean(io.apiman.manager.api.beans.summary.ApiPlanSummaryBean) ClientAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ClientAlreadyExistsException) ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean) UpdateApiBean(io.apiman.manager.api.beans.apis.UpdateApiBean) ISecurityContext(io.apiman.manager.api.security.ISecurityContext) ApiVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ApiVersionAlreadyExistsException) GatewayNotFoundException(io.apiman.manager.api.rest.exceptions.GatewayNotFoundException) InvalidVersionException(io.apiman.manager.api.rest.exceptions.InvalidVersionException) IDataEncrypter(io.apiman.common.util.crypt.IDataEncrypter) OrganizationAlreadyExistsException(io.apiman.manager.api.rest.exceptions.OrganizationAlreadyExistsException) StringUtils(org.apache.commons.lang3.StringUtils) UserBean(io.apiman.manager.api.beans.idm.UserBean) ApiBean(io.apiman.manager.api.beans.apis.ApiBean) ApiVersionEndpointSummaryBean(io.apiman.manager.api.beans.summary.ApiVersionEndpointSummaryBean) MediaType(javax.ws.rs.core.MediaType) DownloadType(io.apiman.manager.api.beans.download.DownloadType) PagingBean(io.apiman.manager.api.beans.search.PagingBean) Map(java.util.Map) ApiManagerConfig(io.apiman.manager.api.core.config.ApiManagerConfig) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) EntityStillActiveException(io.apiman.manager.api.rest.exceptions.EntityStillActiveException) NewApiDefinitionBean(io.apiman.manager.api.beans.apis.NewApiDefinitionBean) ApiEntryBean(io.apiman.manager.api.beans.summary.ApiEntryBean) PolicyNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyNotFoundException) IApiValidator(io.apiman.manager.api.core.IApiValidator) IGatewayLink(io.apiman.manager.api.gateway.IGatewayLink) ApiVersionStatusBean(io.apiman.manager.api.beans.apis.ApiVersionStatusBean) PlanAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PlanAlreadyExistsException) Set(java.util.Set) StandardCharsets(java.nio.charset.StandardCharsets) ApiAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ApiAlreadyExistsException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) UserNotFoundException(io.apiman.manager.api.rest.exceptions.UserNotFoundException) IOUtils(org.apache.commons.io.IOUtils) AuditEntryBean(io.apiman.manager.api.beans.audit.AuditEntryBean) RoleMembershipBean(io.apiman.manager.api.beans.idm.RoleMembershipBean) UsageHistogramBean(io.apiman.manager.api.beans.metrics.UsageHistogramBean) PlanVersionSummaryBean(io.apiman.manager.api.beans.summary.PlanVersionSummaryBean) GatewayAuthenticationException(io.apiman.manager.api.gateway.GatewayAuthenticationException) IMetricsAccessor(io.apiman.manager.api.core.IMetricsAccessor) UpdateClientBean(io.apiman.manager.api.beans.clients.UpdateClientBean) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) PlanSummaryBean(io.apiman.manager.api.beans.summary.PlanSummaryBean) ApiStatus(io.apiman.manager.api.beans.apis.ApiStatus) ResponseStatsHistogramBean(io.apiman.manager.api.beans.metrics.ResponseStatsHistogramBean) ArrayList(java.util.ArrayList) HttpServletRequest(javax.servlet.http.HttpServletRequest) DataEncryptionContext(io.apiman.common.util.crypt.DataEncryptionContext) PlanVersionNotFoundException(io.apiman.manager.api.rest.exceptions.PlanVersionNotFoundException) IOrganizationResource(io.apiman.manager.api.rest.IOrganizationResource) RoleNotFoundException(io.apiman.manager.api.rest.exceptions.RoleNotFoundException) UsagePerClientBean(io.apiman.manager.api.beans.metrics.UsagePerClientBean) IStorageQuery(io.apiman.manager.api.core.IStorageQuery) StreamSupport(java.util.stream.StreamSupport) PolicyTemplateUtil(io.apiman.manager.api.core.util.PolicyTemplateUtil) InvalidNameException(io.apiman.manager.api.rest.exceptions.InvalidNameException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) UsagePerPlanBean(io.apiman.manager.api.beans.metrics.UsagePerPlanBean) NewPlanVersionBean(io.apiman.manager.api.beans.plans.NewPlanVersionBean) EntityUpdatedData(io.apiman.manager.api.beans.audit.data.EntityUpdatedData) GrantRolesBean(io.apiman.manager.api.beans.idm.GrantRolesBean) ClientVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException) IOException(java.io.IOException) BeanUtils(io.apiman.manager.api.beans.BeanUtils) NewOrganizationBean(io.apiman.manager.api.beans.orgs.NewOrganizationBean) ApiRegistryBean(io.apiman.manager.api.beans.summary.ApiRegistryBean) InvalidApiStatusException(io.apiman.manager.api.rest.exceptions.InvalidApiStatusException) DownloadBean(io.apiman.manager.api.beans.download.DownloadBean) TreeMap(java.util.TreeMap) UpdateApiVersionBean(io.apiman.manager.api.beans.apis.UpdateApiVersionBean) PolicyType(io.apiman.manager.api.beans.policies.PolicyType) Messages(io.apiman.manager.api.rest.exceptions.i18n.Messages) ApiNotFoundException(io.apiman.manager.api.rest.exceptions.ApiNotFoundException) ExceptionFactory(io.apiman.manager.api.rest.exceptions.util.ExceptionFactory) ContractAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ContractAlreadyExistsException) MemberRoleBean(io.apiman.manager.api.beans.members.MemberRoleBean) NewPlanBean(io.apiman.manager.api.beans.plans.NewPlanBean) InvalidClientStatusException(io.apiman.manager.api.rest.exceptions.InvalidClientStatusException) NewApiBean(io.apiman.manager.api.beans.apis.NewApiBean) ApiGatewayBean(io.apiman.manager.api.beans.apis.ApiGatewayBean) URL(java.net.URL) Date(java.util.Date) ApiVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException) HistogramIntervalType(io.apiman.manager.api.beans.metrics.HistogramIntervalType) StorageException(io.apiman.manager.api.core.exceptions.StorageException) NewContractBean(io.apiman.manager.api.beans.contracts.NewContractBean) IGatewayLinkFactory(io.apiman.manager.api.gateway.IGatewayLinkFactory) UpdateOrganizationBean(io.apiman.manager.api.beans.orgs.UpdateOrganizationBean) SearchCriteriaFilterOperator(io.apiman.manager.api.beans.search.SearchCriteriaFilterOperator) ApiDefinitionType(io.apiman.manager.api.beans.apis.ApiDefinitionType) IDownloadManager(io.apiman.manager.api.core.IDownloadManager) ByteArrayInputStream(java.io.ByteArrayInputStream) ResponseStatsPerClientBean(io.apiman.manager.api.beans.metrics.ResponseStatsPerClientBean) IClientValidator(io.apiman.manager.api.core.IClientValidator) ClientVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ClientVersionAlreadyExistsException) InvalidPlanStatusException(io.apiman.manager.api.rest.exceptions.InvalidPlanStatusException) ApimanLoggerFactory(io.apiman.common.logging.ApimanLoggerFactory) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) ContractNotFoundException(io.apiman.manager.api.rest.exceptions.ContractNotFoundException) ISODateTimeFormat(org.joda.time.format.ISODateTimeFormat) Context(javax.ws.rs.core.Context) ClientUsagePerApiBean(io.apiman.manager.api.beans.metrics.ClientUsagePerApiBean) GatewaySummaryBean(io.apiman.manager.api.beans.summary.GatewaySummaryBean) ApiVersionSummaryBean(io.apiman.manager.api.beans.summary.ApiVersionSummaryBean) InvalidParameterException(io.apiman.manager.api.rest.exceptions.InvalidParameterException) NewClientVersionBean(io.apiman.manager.api.beans.clients.NewClientVersionBean) ApiSummaryBean(io.apiman.manager.api.beans.summary.ApiSummaryBean) ClientSummaryBean(io.apiman.manager.api.beans.summary.ClientSummaryBean) IRoleResource(io.apiman.manager.api.rest.IRoleResource) List(java.util.List) IApimanLogger(io.apiman.common.logging.IApimanLogger) ApiPlanBean(io.apiman.manager.api.beans.apis.ApiPlanBean) PolicySummaryBean(io.apiman.manager.api.beans.summary.PolicySummaryBean) Response(javax.ws.rs.core.Response) Entry(java.util.Map.Entry) SearchCriteriaBean(io.apiman.manager.api.beans.search.SearchCriteriaBean) IUserResource(io.apiman.manager.api.rest.IUserResource) ClientNotFoundException(io.apiman.manager.api.rest.exceptions.ClientNotFoundException) PermissionType(io.apiman.manager.api.beans.idm.PermissionType) PathParam(javax.ws.rs.PathParam) ApiEndpoint(io.apiman.gateway.engine.beans.ApiEndpoint) HashMap(java.util.HashMap) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) PlanNotFoundException(io.apiman.manager.api.rest.exceptions.PlanNotFoundException) AuditUtils(io.apiman.manager.api.rest.impl.audit.AuditUtils) ContractBean(io.apiman.manager.api.beans.contracts.ContractBean) HashSet(java.util.HashSet) Inject(javax.inject.Inject) ClientBean(io.apiman.manager.api.beans.clients.ClientBean) ResponseStatsSummaryBean(io.apiman.manager.api.beans.metrics.ResponseStatsSummaryBean) FieldValidator(io.apiman.manager.api.rest.impl.util.FieldValidator) RoleBean(io.apiman.manager.api.beans.idm.RoleBean) IApiKeyGenerator(io.apiman.manager.api.core.IApiKeyGenerator) InvalidMetricCriteriaException(io.apiman.manager.api.rest.exceptions.InvalidMetricCriteriaException) SwaggerWsdlHelper(io.apiman.manager.api.rest.impl.util.SwaggerWsdlHelper) PlanVersionBean(io.apiman.manager.api.beans.plans.PlanVersionBean) ClientVersionSummaryBean(io.apiman.manager.api.beans.summary.ClientVersionSummaryBean) MembershipData(io.apiman.manager.api.beans.audit.data.MembershipData) Iterator(java.util.Iterator) EntityType(io.apiman.common.util.crypt.DataEncryptionContext.EntityType) GatewayBean(io.apiman.manager.api.beans.gateways.GatewayBean) MalformedURLException(java.net.MalformedURLException) ClientStatus(io.apiman.manager.api.beans.clients.ClientStatus) SearchResultsBean(io.apiman.manager.api.beans.search.SearchResultsBean) ContractSummaryBean(io.apiman.manager.api.beans.summary.ContractSummaryBean) PlanVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PlanVersionAlreadyExistsException) DateTime(org.joda.time.DateTime) PolicyDefinitionBean(io.apiman.manager.api.beans.policies.PolicyDefinitionBean) IStorage(io.apiman.manager.api.core.IStorage) ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) NewApiVersionBean(io.apiman.manager.api.beans.apis.NewApiVersionBean) NewPolicyBean(io.apiman.manager.api.beans.policies.NewPolicyBean) PolicyDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException) Collectors.toList(java.util.stream.Collectors.toList) OrganizationNotFoundException(io.apiman.manager.api.rest.exceptions.OrganizationNotFoundException) UpdatePolicyBean(io.apiman.manager.api.beans.policies.UpdatePolicyBean) UpdatePlanBean(io.apiman.manager.api.beans.plans.UpdatePlanBean) RequestScoped(javax.enterprise.context.RequestScoped) NewClientBean(io.apiman.manager.api.beans.clients.NewClientBean) ResponseStatsPerPlanBean(io.apiman.manager.api.beans.metrics.ResponseStatsPerPlanBean) PlanStatus(io.apiman.manager.api.beans.plans.PlanStatus) ApiDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiDefinitionNotFoundException) ApiKeyBean(io.apiman.manager.api.beans.clients.ApiKeyBean) RestHelper(io.apiman.manager.api.rest.impl.util.RestHelper) InputStream(java.io.InputStream) 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) PlanVersionSummaryBean(io.apiman.manager.api.beans.summary.PlanVersionSummaryBean) 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 ApiNotFoundException

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

the class OrganizationResourceImpl method createContract.

/**
 * @see IOrganizationResource#createContract(java.lang.String, java.lang.String, java.lang.String, io.apiman.manager.api.beans.contracts.NewContractBean)
 */
@Override
public ContractBean createContract(String organizationId, String clientId, String version, NewContractBean bean) throws OrganizationNotFoundException, ClientNotFoundException, ApiNotFoundException, PlanNotFoundException, ContractAlreadyExistsException, NotAuthorizedException {
    securityContext.checkPermissions(PermissionType.clientEdit, organizationId);
    try {
        storage.beginTx();
        ContractBean contract = createContractInternal(organizationId, clientId, version, bean);
        storage.commitTx();
        // $NON-NLS-1$
        log.debug(String.format("Created new contract %s: %s", contract.getId(), contract));
        return contract;
    } catch (AbstractRestException e) {
        storage.rollbackTx();
        throw e;
    } catch (Exception e) {
        storage.rollbackTx();
        // reduce overhead on the typical happy path.
        if (contractAlreadyExists(organizationId, clientId, version, bean)) {
            throw ExceptionFactory.contractAlreadyExistsException();
        } else {
            throw new SystemErrorException(e);
        }
    }
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) 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) NewContractBean(io.apiman.manager.api.beans.contracts.NewContractBean) ContractBean(io.apiman.manager.api.beans.contracts.ContractBean)

Example 3 with ApiNotFoundException

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

the class OrganizationResourceImpl method createApiVersion.

/**
 * @see IOrganizationResource#createApiVersion(java.lang.String, java.lang.String, io.apiman.manager.api.beans.apis.NewApiVersionBean)
 */
@Override
public ApiVersionBean createApiVersion(String organizationId, String apiId, NewApiVersionBean bean) throws ApiNotFoundException, NotAuthorizedException, InvalidVersionException, ApiVersionAlreadyExistsException {
    securityContext.checkPermissions(PermissionType.apiEdit, organizationId);
    FieldValidator.validateVersion(bean.getVersion());
    ApiVersionBean newVersion;
    try {
        GatewaySummaryBean gateway = getSingularGateway();
        storage.beginTx();
        ApiBean api = getApiFromStorage(organizationId, apiId);
        if (storage.getApiVersion(organizationId, apiId, bean.getVersion()) != null) {
            throw ExceptionFactory.apiVersionAlreadyExistsException(apiId, bean.getVersion());
        }
        newVersion = createApiVersionInternal(bean, api, gateway);
        storage.commitTx();
    } catch (AbstractRestException e) {
        storage.rollbackTx();
        throw e;
    } catch (Exception e) {
        storage.rollbackTx();
        throw new SystemErrorException(e);
    }
    if (bean.isClone() && bean.getCloneVersion() != null) {
        try {
            ApiVersionBean cloneSource = getApiVersion(organizationId, apiId, bean.getCloneVersion());
            // Clone primary attributes of the API version unless those attributes
            // were included in the NewApiVersionBean.  In other words, information
            // sent as part of the "create version" payload take precedence over the
            // cloned attributes.
            UpdateApiVersionBean updatedApi = new UpdateApiVersionBean();
            if (bean.getEndpoint() == null) {
                updatedApi.setEndpoint(cloneSource.getEndpoint());
            }
            if (bean.getEndpointType() == null) {
                updatedApi.setEndpointType(cloneSource.getEndpointType());
            }
            if (bean.getEndpointContentType() == null) {
                updatedApi.setEndpointContentType(cloneSource.getEndpointContentType());
            }
            updatedApi.setEndpointProperties(cloneSource.getEndpointProperties());
            updatedApi.setGateways(cloneSource.getGateways());
            if (bean.getPlans() == null) {
                updatedApi.setPlans(cloneSource.getPlans());
            }
            if (bean.getPublicAPI() == null) {
                updatedApi.setPublicAPI(cloneSource.isPublicAPI());
            }
            if (bean.getParsePayload() == null) {
                updatedApi.setParsePayload(bean.getParsePayload());
            }
            newVersion = updateApiVersion(organizationId, apiId, bean.getVersion(), updatedApi);
            if (bean.getDefinitionUrl() == null) {
                // Clone the API definition document
                InputStream definition = null;
                try {
                    Response response = getApiDefinition(organizationId, apiId, bean.getCloneVersion());
                    definition = (InputStream) response.getEntity();
                    storeApiDefinition(organizationId, apiId, newVersion.getVersion(), cloneSource.getDefinitionType(), definition, cloneSource.getDefinitionUrl());
                } catch (ApiDefinitionNotFoundException svnfe) {
                // This is ok - it just means the API doesn't have one, so do nothing.
                } catch (Exception sdnfe) {
                    // $NON-NLS-1$
                    log.error("Unable to create response", sdnfe);
                } finally {
                    IOUtils.closeQuietly(definition);
                }
            }
            // Clone all API policies
            List<PolicySummaryBean> policies = listApiPolicies(organizationId, apiId, bean.getCloneVersion());
            for (PolicySummaryBean policySummary : policies) {
                PolicyBean policy = getApiPolicy(organizationId, apiId, bean.getCloneVersion(), policySummary.getId());
                NewPolicyBean npb = new NewPolicyBean();
                npb.setDefinitionId(policy.getDefinition().getId());
                npb.setConfiguration(policy.getConfiguration());
                createApiPolicy(organizationId, apiId, newVersion.getVersion(), npb);
            }
        } catch (Exception e) {
            // TODO it's ok if the clone fails - we did our best
            if (e != null) {
                Throwable t = e;
                e = (Exception) t;
            }
        }
    }
    return newVersion;
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) PolicySummaryBean(io.apiman.manager.api.beans.summary.PolicySummaryBean) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) NewPolicyBean(io.apiman.manager.api.beans.policies.NewPolicyBean) UpdatePolicyBean(io.apiman.manager.api.beans.policies.UpdatePolicyBean) UpdateApiVersionBean(io.apiman.manager.api.beans.apis.UpdateApiVersionBean) GatewaySummaryBean(io.apiman.manager.api.beans.summary.GatewaySummaryBean) 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) 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) Response(javax.ws.rs.core.Response) ApiDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiDefinitionNotFoundException) NewPolicyBean(io.apiman.manager.api.beans.policies.NewPolicyBean) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean) UpdateApiVersionBean(io.apiman.manager.api.beans.apis.UpdateApiVersionBean) NewApiVersionBean(io.apiman.manager.api.beans.apis.NewApiVersionBean)

Example 4 with ApiNotFoundException

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

the class OrganizationResourceImpl method getApiInternal.

/**
 * Gets the API internal.
 * This method can be also used to check if the API exists
 * @param organizationId
 * @param apiId
 * @return
 */
private ApiBean getApiInternal(String organizationId, String apiId) throws ApiNotFoundException {
    try {
        storage.beginTx();
        ApiBean bean = getApiFromStorage(organizationId, apiId);
        storage.commitTx();
        return bean;
    } 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) 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 5 with ApiNotFoundException

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

the class PlanService method deletePlan.

public void deletePlan(String organizationId, String planId) throws ApiNotFoundException, NotAuthorizedException, InvalidPlanStatusException {
    List<PlanVersionSummaryBean> lockedPlans = listPlanVersions(organizationId, planId).stream().filter(summary -> summary.getStatus() == PlanStatus.Locked).collect(toList());
    if (!lockedPlans.isEmpty())
        throw ExceptionFactory.invalidPlanStatusException(lockedPlans);
    tryAction(() -> {
        PlanBean plan = storage.getPlan(organizationId, planId);
        storage.deletePlan(plan);
    });
}
Also used : NewPlanBean(io.apiman.manager.api.beans.plans.NewPlanBean) PolicyChainBean(io.apiman.manager.api.beans.policies.PolicyChainBean) Date(java.util.Date) StorageException(io.apiman.manager.api.core.exceptions.StorageException) ISecurityContext(io.apiman.manager.api.security.ISecurityContext) InvalidVersionException(io.apiman.manager.api.rest.exceptions.InvalidVersionException) PagingBean(io.apiman.manager.api.beans.search.PagingBean) InvalidPlanStatusException(io.apiman.manager.api.rest.exceptions.InvalidPlanStatusException) ApimanLoggerFactory(io.apiman.common.logging.ApimanLoggerFactory) OrganizationBean(io.apiman.manager.api.beans.orgs.OrganizationBean) PolicyNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyNotFoundException) Transactional(javax.transaction.Transactional) PlanAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PlanAlreadyExistsException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) List(java.util.List) IApimanLogger(io.apiman.common.logging.IApimanLogger) PolicySummaryBean(io.apiman.manager.api.beans.summary.PolicySummaryBean) AuditEntryBean(io.apiman.manager.api.beans.audit.AuditEntryBean) ApplicationScoped(javax.enterprise.context.ApplicationScoped) PermissionType(io.apiman.manager.api.beans.idm.PermissionType) PlanVersionSummaryBean(io.apiman.manager.api.beans.summary.PlanVersionSummaryBean) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) PlanSummaryBean(io.apiman.manager.api.beans.summary.PlanSummaryBean) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) PlanNotFoundException(io.apiman.manager.api.rest.exceptions.PlanNotFoundException) AuditUtils(io.apiman.manager.api.rest.impl.audit.AuditUtils) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) PlanVersionNotFoundException(io.apiman.manager.api.rest.exceptions.PlanVersionNotFoundException) FieldValidator(io.apiman.manager.api.rest.impl.util.FieldValidator) IStorageQuery(io.apiman.manager.api.core.IStorageQuery) InvalidNameException(io.apiman.manager.api.rest.exceptions.InvalidNameException) DataAccessUtilMixin(io.apiman.manager.api.rest.impl.util.DataAccessUtilMixin) PlanVersionBean(io.apiman.manager.api.beans.plans.PlanVersionBean) NewPlanVersionBean(io.apiman.manager.api.beans.plans.NewPlanVersionBean) EntityUpdatedData(io.apiman.manager.api.beans.audit.data.EntityUpdatedData) SearchResultsBean(io.apiman.manager.api.beans.search.SearchResultsBean) PlanVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PlanVersionAlreadyExistsException) IStorage(io.apiman.manager.api.core.IStorage) BeanUtils(io.apiman.manager.api.beans.BeanUtils) NewPolicyBean(io.apiman.manager.api.beans.policies.NewPolicyBean) Collectors.toList(java.util.stream.Collectors.toList) OrganizationNotFoundException(io.apiman.manager.api.rest.exceptions.OrganizationNotFoundException) UpdatePolicyBean(io.apiman.manager.api.beans.policies.UpdatePolicyBean) UpdatePlanBean(io.apiman.manager.api.beans.plans.UpdatePlanBean) PolicyType(io.apiman.manager.api.beans.policies.PolicyType) PlanStatus(io.apiman.manager.api.beans.plans.PlanStatus) ApiNotFoundException(io.apiman.manager.api.rest.exceptions.ApiNotFoundException) ExceptionFactory(io.apiman.manager.api.rest.exceptions.util.ExceptionFactory) NewPlanBean(io.apiman.manager.api.beans.plans.NewPlanBean) PlanBean(io.apiman.manager.api.beans.plans.PlanBean) UpdatePlanBean(io.apiman.manager.api.beans.plans.UpdatePlanBean) PlanVersionSummaryBean(io.apiman.manager.api.beans.summary.PlanVersionSummaryBean)

Aggregations

StorageException (io.apiman.manager.api.core.exceptions.StorageException)7 ApiNotFoundException (io.apiman.manager.api.rest.exceptions.ApiNotFoundException)7 InvalidNameException (io.apiman.manager.api.rest.exceptions.InvalidNameException)7 InvalidVersionException (io.apiman.manager.api.rest.exceptions.InvalidVersionException)7 NotAuthorizedException (io.apiman.manager.api.rest.exceptions.NotAuthorizedException)7 OrganizationNotFoundException (io.apiman.manager.api.rest.exceptions.OrganizationNotFoundException)7 PlanNotFoundException (io.apiman.manager.api.rest.exceptions.PlanNotFoundException)7 PolicyNotFoundException (io.apiman.manager.api.rest.exceptions.PolicyNotFoundException)7 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 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 InvalidParameterException (io.apiman.manager.api.rest.exceptions.InvalidParameterException)6 SystemErrorException (io.apiman.manager.api.rest.exceptions.SystemErrorException)6 MalformedURLException (java.net.MalformedURLException)6 ApiBean (io.apiman.manager.api.beans.apis.ApiBean)5