Search in sources :

Example 1 with NewPolicyBean

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

use of io.apiman.manager.api.beans.policies.NewPolicyBean in project apiman by apiman.

the class OrganizationResourceImpl method createClientVersion.

/**
 * @see IOrganizationResource#createClientVersion(java.lang.String, java.lang.String, io.apiman.manager.api.beans.clients.NewClientVersionBean)
 */
@Override
public ClientVersionBean createClientVersion(String organizationId, String clientId, NewClientVersionBean bean) throws ClientNotFoundException, NotAuthorizedException, InvalidVersionException, ClientVersionAlreadyExistsException {
    securityContext.checkPermissions(PermissionType.clientEdit, organizationId);
    FieldValidator.validateVersion(bean.getVersion());
    ClientVersionBean newVersion;
    try {
        storage.beginTx();
        ClientBean client = getClientFromStorage(organizationId, clientId);
        if (storage.getClientVersion(organizationId, clientId, bean.getVersion()) != null) {
            throw ExceptionFactory.clientVersionAlreadyExistsException(clientId, bean.getVersion());
        }
        newVersion = createClientVersionInternal(bean, client);
        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 {
            List<ContractSummaryBean> contracts = getClientVersionContracts(organizationId, clientId, bean.getCloneVersion());
            for (ContractSummaryBean contract : contracts) {
                NewContractBean ncb = new NewContractBean();
                ncb.setPlanId(contract.getPlanId());
                ncb.setApiId(contract.getApiId());
                ncb.setApiOrgId(contract.getApiOrganizationId());
                ncb.setApiVersion(contract.getApiVersion());
                createContract(organizationId, clientId, newVersion.getVersion(), ncb);
            }
            List<PolicySummaryBean> policies = listClientPolicies(organizationId, clientId, bean.getCloneVersion());
            for (PolicySummaryBean policySummary : policies) {
                PolicyBean policy = getClientPolicy(organizationId, clientId, bean.getCloneVersion(), policySummary.getId());
                NewPolicyBean npb = new NewPolicyBean();
                npb.setDefinitionId(policy.getDefinition().getId());
                npb.setConfiguration(policy.getConfiguration());
                createClientPolicy(organizationId, clientId, newVersion.getVersion(), npb);
            }
        } catch (Exception e) {
        // TODO it's ok if the clone fails - we did our best
        }
    }
    return newVersion;
}
Also used : NewClientVersionBean(io.apiman.manager.api.beans.clients.NewClientVersionBean) ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) NewContractBean(io.apiman.manager.api.beans.contracts.NewContractBean) PolicySummaryBean(io.apiman.manager.api.beans.summary.PolicySummaryBean) UpdateClientBean(io.apiman.manager.api.beans.clients.UpdateClientBean) UsagePerClientBean(io.apiman.manager.api.beans.metrics.UsagePerClientBean) ResponseStatsPerClientBean(io.apiman.manager.api.beans.metrics.ResponseStatsPerClientBean) ClientBean(io.apiman.manager.api.beans.clients.ClientBean) NewClientBean(io.apiman.manager.api.beans.clients.NewClientBean) NewPolicyBean(io.apiman.manager.api.beans.policies.NewPolicyBean) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) NewPolicyBean(io.apiman.manager.api.beans.policies.NewPolicyBean) UpdatePolicyBean(io.apiman.manager.api.beans.policies.UpdatePolicyBean) ContractSummaryBean(io.apiman.manager.api.beans.summary.ContractSummaryBean) 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 3 with NewPolicyBean

use of io.apiman.manager.api.beans.policies.NewPolicyBean in project apiman by apiman.

the class ClientAppService method createClientPolicy.

@Transactional
public PolicyBean createClientPolicy(String organizationId, String clientId, String version, NewPolicyBean bean) throws OrganizationNotFoundException, ClientVersionNotFoundException, NotAuthorizedException {
    return tryAction(() -> {
        // Make sure the Client exists
        ClientVersionBean cvb = getClientVersionInternal(organizationId, clientId, version);
        PolicyBean policy = policyService.createPolicy(organizationId, clientId, version, bean, PolicyType.Client);
        cvb.setModifiedBy(securityContext.getCurrentUser());
        cvb.setModifiedOn(new Date());
        return policy;
    });
}
Also used : NewClientVersionBean(io.apiman.manager.api.beans.clients.NewClientVersionBean) ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) NewPolicyBean(io.apiman.manager.api.beans.policies.NewPolicyBean) UpdatePolicyBean(io.apiman.manager.api.beans.policies.UpdatePolicyBean) Date(java.util.Date) Transactional(javax.transaction.Transactional)

Example 4 with NewPolicyBean

use of io.apiman.manager.api.beans.policies.NewPolicyBean in project apiman by apiman.

the class PolicyService method createPolicy.

/**
 * Creates a policy for the given entity (supports creating policies for clients,
 * APIs, and plans).
 *
 * @param organizationId
 * @param entityId
 * @param entityVersion
 * @param bean
 * @return the stored policy bean (with updated information)
 */
public PolicyBean createPolicy(String organizationId, String entityId, String entityVersion, NewPolicyBean bean, PolicyType type) throws PolicyDefinitionNotFoundException {
    return tryAction(() -> {
        if (bean.getDefinitionId() == null) {
            // $NON-NLS-1$
            throw ExceptionFactory.policyDefNotFoundException("null");
        }
        PolicyDefinitionBean def = storage.getPolicyDefinition(bean.getDefinitionId());
        if (def == null) {
            throw ExceptionFactory.policyDefNotFoundException(bean.getDefinitionId());
        }
        int newIdx = query.getMaxPolicyOrderIndex(organizationId, entityId, entityVersion, type) + 1;
        PolicyBean policy = new PolicyBean();
        policy.setId(null);
        policy.setDefinition(def);
        policy.setName(def.getName());
        policy.setConfiguration(bean.getConfiguration());
        policy.setCreatedBy(securityContext.getCurrentUser());
        policy.setCreatedOn(new Date());
        policy.setModifiedBy(securityContext.getCurrentUser());
        policy.setModifiedOn(new Date());
        policy.setOrganizationId(organizationId);
        policy.setEntityId(entityId);
        policy.setEntityVersion(entityVersion);
        policy.setType(type);
        policy.setOrderIndex(newIdx);
        if (type == PolicyType.Client) {
            ClientVersionBean cvb = storage.getClientVersion(organizationId, entityId, entityVersion);
            cvb.setModifiedBy(securityContext.getCurrentUser());
            cvb.setModifiedOn(new Date());
            storage.updateClientVersion(cvb);
        } else if (type == PolicyType.Api) {
            ApiVersionBean avb = storage.getApiVersion(organizationId, entityId, entityVersion);
            avb.setModifiedBy(securityContext.getCurrentUser());
            avb.setModifiedOn(new Date());
            storage.updateApiVersion(avb);
        } else if (type == PolicyType.Plan) {
            PlanVersionBean pvb = storage.getPlanVersion(organizationId, entityId, entityVersion);
            pvb.setModifiedBy(securityContext.getCurrentUser());
            pvb.setModifiedOn(new Date());
            storage.updatePlanVersion(pvb);
        }
        storage.createPolicy(policy);
        storage.createAuditEntry(AuditUtils.policyAdded(policy, type, securityContext));
        PolicyTemplateUtil.generatePolicyDescription(policy);
        // $NON-NLS-1$
        LOGGER.debug(String.format("Created client policy: %s", policy));
        return policy;
    });
}
Also used : ClientVersionBean(io.apiman.manager.api.beans.clients.ClientVersionBean) PolicyDefinitionBean(io.apiman.manager.api.beans.policies.PolicyDefinitionBean) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) NewPolicyBean(io.apiman.manager.api.beans.policies.NewPolicyBean) ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean) Date(java.util.Date) PlanVersionBean(io.apiman.manager.api.beans.plans.PlanVersionBean)

Example 5 with NewPolicyBean

use of io.apiman.manager.api.beans.policies.NewPolicyBean in project apiman by apiman.

the class ApiService method createApiVersion.

public ApiVersionBeanDto createApiVersion(String organizationId, String apiId, NewApiVersionBean newApiVersion) throws ApiNotFoundException, NotAuthorizedException, InvalidVersionException, ApiVersionAlreadyExistsException {
    FieldValidator.validateVersion(newApiVersion.getVersion());
    ApiVersionBean newVersion = tryAction(() -> {
        GatewaySummaryBean gateway = getSingularGateway();
        ApiBean api = getApiFromStorage(organizationId, apiId);
        if (storage.getApiVersion(organizationId, apiId, newApiVersion.getVersion()) != null) {
            throw ExceptionFactory.apiVersionAlreadyExistsException(apiId, newApiVersion.getVersion());
        }
        return createApiVersionInternal(newApiVersion, api, gateway);
    });
    if (newApiVersion.isClone() && newApiVersion.getCloneVersion() != null) {
        try {
            ApiVersionBean cloneSource = storage.getApiVersion(organizationId, apiId, newApiVersion.getCloneVersion());
            // storage.flush();
            // 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 (newApiVersion.getEndpoint() == null) {
                updatedApi.setEndpoint(cloneSource.getEndpoint());
            }
            if (newApiVersion.getEndpointType() == null) {
                updatedApi.setEndpointType(cloneSource.getEndpointType());
            }
            if (newApiVersion.getEndpointContentType() == null) {
                updatedApi.setEndpointContentType(cloneSource.getEndpointContentType());
            }
            updatedApi.setEndpointProperties(cloneSource.getEndpointProperties());
            updatedApi.setGateways(cloneSource.getGateways());
            if (newApiVersion.getPlans() == null) {
                Set<UpdateApiPlanDto> plans = ApiVersionMapper.INSTANCE.toDto2(cloneSource.getPlans());
                updatedApi.setPlans(plans);
            }
            if (newApiVersion.getPublicAPI() == null) {
                updatedApi.setPublicAPI(cloneSource.isPublicAPI());
            }
            if (newApiVersion.getParsePayload() == null) {
                updatedApi.setParsePayload(cloneSource.isParsePayload());
            }
            if (newApiVersion.getExtendedDescription() == null) {
                updatedApi.setExtendedDescription(cloneSource.getExtendedDescription());
            }
            ApiVersionBean updated = updateApiVersion(newVersion, updatedApi);
            if (newApiVersion.getDefinitionUrl() == null) {
                // Clone the API definition document
                InputStream definition = null;
                try {
                    definition = getApiDefinition(organizationId, apiId, newApiVersion.getCloneVersion()).getDefinition();
                    setApiDefinition(organizationId, apiId, updated.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$
                    LOGGER.error("Unable to create response", sdnfe);
                } finally {
                    IOUtils.closeQuietly(definition);
                }
            }
            // Clone all API policies
            List<PolicySummaryBean> policies = listApiPolicies(organizationId, apiId, newApiVersion.getCloneVersion());
            for (PolicySummaryBean policySummary : policies) {
                PolicyBean policy = getApiPolicy(organizationId, apiId, newApiVersion.getCloneVersion(), policySummary.getId());
                NewPolicyBean npb = new NewPolicyBean();
                npb.setDefinitionId(policy.getDefinition().getId());
                npb.setConfiguration(policy.getConfiguration());
                createApiPolicy(organizationId, apiId, updated.getVersion(), npb);
            }
        } catch (Exception e) {
            e.printStackTrace();
            // TODO it's ok if the clone fails - we did our best
            if (e != null) {
                Throwable t = e;
                e = (Exception) t;
            }
        }
    }
    return apiVersionMapper.toDto(newVersion);
}
Also used : PolicySummaryBean(io.apiman.manager.api.beans.summary.PolicySummaryBean) 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) UpdateApiPlanDto(io.apiman.manager.api.beans.apis.dto.UpdateApiPlanDto) ApiVersionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ApiVersionAlreadyExistsException) GatewayNotFoundException(io.apiman.manager.api.rest.exceptions.GatewayNotFoundException) InvalidVersionException(io.apiman.manager.api.rest.exceptions.InvalidVersionException) EntityStillActiveException(io.apiman.manager.api.rest.exceptions.EntityStillActiveException) PolicyNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyNotFoundException) ApiAlreadyExistsException(io.apiman.manager.api.rest.exceptions.ApiAlreadyExistsException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) GatewayAuthenticationException(io.apiman.manager.api.gateway.GatewayAuthenticationException) InvalidNameException(io.apiman.manager.api.rest.exceptions.InvalidNameException) InvalidApiStatusException(io.apiman.manager.api.rest.exceptions.InvalidApiStatusException) ApiNotFoundException(io.apiman.manager.api.rest.exceptions.ApiNotFoundException) ApiVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) InvalidParameterException(io.apiman.manager.api.rest.exceptions.InvalidParameterException) PlanNotFoundException(io.apiman.manager.api.rest.exceptions.PlanNotFoundException) MalformedURLException(java.net.MalformedURLException) 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) ApiDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiDefinitionNotFoundException) NewPolicyBean(io.apiman.manager.api.beans.policies.NewPolicyBean) ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean) UpdateApiVersionBean(io.apiman.manager.api.beans.apis.UpdateApiVersionBean) NewApiVersionBean(io.apiman.manager.api.beans.apis.NewApiVersionBean)

Aggregations

NewPolicyBean (io.apiman.manager.api.beans.policies.NewPolicyBean)13 PolicyBean (io.apiman.manager.api.beans.policies.PolicyBean)13 UpdatePolicyBean (io.apiman.manager.api.beans.policies.UpdatePolicyBean)12 StorageException (io.apiman.manager.api.core.exceptions.StorageException)10 InvalidNameException (io.apiman.manager.api.rest.exceptions.InvalidNameException)10 InvalidVersionException (io.apiman.manager.api.rest.exceptions.InvalidVersionException)10 NotAuthorizedException (io.apiman.manager.api.rest.exceptions.NotAuthorizedException)10 OrganizationNotFoundException (io.apiman.manager.api.rest.exceptions.OrganizationNotFoundException)10 PolicyNotFoundException (io.apiman.manager.api.rest.exceptions.PolicyNotFoundException)10 ApiNotFoundException (io.apiman.manager.api.rest.exceptions.ApiNotFoundException)9 EntityStillActiveException (io.apiman.manager.api.rest.exceptions.EntityStillActiveException)9 PlanNotFoundException (io.apiman.manager.api.rest.exceptions.PlanNotFoundException)9 GatewayAuthenticationException (io.apiman.manager.api.gateway.GatewayAuthenticationException)8 AbstractRestException (io.apiman.manager.api.rest.exceptions.AbstractRestException)8 ApiAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ApiAlreadyExistsException)8 ApiDefinitionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiDefinitionNotFoundException)8 ApiVersionAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ApiVersionAlreadyExistsException)8 ApiVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException)8 ClientAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ClientAlreadyExistsException)8 ClientNotFoundException (io.apiman.manager.api.rest.exceptions.ClientNotFoundException)8