Search in sources :

Example 1 with ClientNotFoundException

use of io.apiman.manager.api.rest.exceptions.ClientNotFoundException 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 2 with ClientNotFoundException

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

the class OrganizationResourceImpl method getClient.

/**
 * @see IOrganizationResource#getClient(java.lang.String, java.lang.String)
 */
@Override
public ClientBean getClient(String organizationId, String clientId) throws ClientNotFoundException, NotAuthorizedException {
    securityContext.checkPermissions(PermissionType.clientView, organizationId);
    try {
        storage.beginTx();
        ClientBean clientBean = getClientFromStorage(organizationId, clientId);
        storage.commitTx();
        // $NON-NLS-1$
        log.debug(String.format("Got client %s: %s", clientBean.getName(), clientBean));
        return clientBean;
    } 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) 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) 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 ClientNotFoundException

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

the class OrganizationResourceImpl method deleteContract.

/**
 * @see IOrganizationResource#deleteContract(java.lang.String, java.lang.String, java.lang.String, java.lang.Long)
 */
@Override
public void deleteContract(String organizationId, String clientId, String version, Long contractId) throws ClientNotFoundException, ContractNotFoundException, NotAuthorizedException, InvalidClientStatusException {
    securityContext.checkPermissions(PermissionType.clientEdit, organizationId);
    try {
        storage.beginTx();
        ContractBean contract = storage.getContract(contractId);
        if (contract == null) {
            throw ExceptionFactory.contractNotFoundException(contractId);
        }
        if (!contract.getClient().getClient().getOrganization().getId().equals(organizationId)) {
            throw ExceptionFactory.contractNotFoundException(contractId);
        }
        if (!contract.getClient().getClient().getId().equals(clientId)) {
            throw ExceptionFactory.contractNotFoundException(contractId);
        }
        if (!contract.getClient().getVersion().equals(version)) {
            throw ExceptionFactory.contractNotFoundException(contractId);
        }
        if (contract.getClient().getStatus() == ClientStatus.Retired) {
            throw ExceptionFactory.invalidClientStatusException();
        }
        storage.deleteContract(contract);
        storage.createAuditEntry(AuditUtils.contractBrokenFromClient(contract, securityContext));
        storage.createAuditEntry(AuditUtils.contractBrokenToApi(contract, securityContext));
        // Update the version with new meta-data (e.g. modified-by)
        ClientVersionBean clientV = getClientVersionFromStorage(organizationId, clientId, version);
        clientV.setModifiedBy(securityContext.getCurrentUser());
        clientV.setModifiedOn(new Date());
        storage.updateClientVersion(clientV);
        storage.commitTx();
        // $NON-NLS-1$
        log.debug(String.format("Deleted contract: %s", contract));
    } catch (AbstractRestException e) {
        storage.rollbackTx();
        throw e;
    } catch (Exception e) {
        storage.rollbackTx();
        throw new SystemErrorException(e);
    }
}
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) 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) NewContractBean(io.apiman.manager.api.beans.contracts.NewContractBean) ContractBean(io.apiman.manager.api.beans.contracts.ContractBean)

Example 4 with ClientNotFoundException

use of io.apiman.manager.api.rest.exceptions.ClientNotFoundException 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 5 with ClientNotFoundException

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

the class OrganizationResourceImpl method getContract.

/**
 * @see IOrganizationResource#getContract(java.lang.String, java.lang.String, java.lang.String, java.lang.Long)
 */
@Override
public ContractBean getContract(String organizationId, String clientId, String version, Long contractId) throws ClientNotFoundException, ContractNotFoundException, NotAuthorizedException {
    securityContext.checkPermissions(PermissionType.clientView, organizationId);
    try {
        storage.beginTx();
        ContractBean contract = storage.getContract(contractId);
        if (contract == null)
            throw ExceptionFactory.contractNotFoundException(contractId);
        storage.commitTx();
        // $NON-NLS-1$
        log.debug(String.format("Got contract %s: %s", contract.getId(), contract));
        return contract;
    } 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) 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)

Aggregations

StorageException (io.apiman.manager.api.core.exceptions.StorageException)11 AbstractRestException (io.apiman.manager.api.rest.exceptions.AbstractRestException)11 ClientNotFoundException (io.apiman.manager.api.rest.exceptions.ClientNotFoundException)11 InvalidClientStatusException (io.apiman.manager.api.rest.exceptions.InvalidClientStatusException)11 NotAuthorizedException (io.apiman.manager.api.rest.exceptions.NotAuthorizedException)11 OrganizationNotFoundException (io.apiman.manager.api.rest.exceptions.OrganizationNotFoundException)11 SystemErrorException (io.apiman.manager.api.rest.exceptions.SystemErrorException)11 GatewayAuthenticationException (io.apiman.manager.api.gateway.GatewayAuthenticationException)10 ApiNotFoundException (io.apiman.manager.api.rest.exceptions.ApiNotFoundException)10 ClientAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ClientAlreadyExistsException)10 ClientVersionAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ClientVersionAlreadyExistsException)10 ClientVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException)10 ContractAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ContractAlreadyExistsException)10 ContractNotFoundException (io.apiman.manager.api.rest.exceptions.ContractNotFoundException)10 EntityStillActiveException (io.apiman.manager.api.rest.exceptions.EntityStillActiveException)10 InvalidNameException (io.apiman.manager.api.rest.exceptions.InvalidNameException)10 InvalidVersionException (io.apiman.manager.api.rest.exceptions.InvalidVersionException)10 PlanNotFoundException (io.apiman.manager.api.rest.exceptions.PlanNotFoundException)10 PolicyNotFoundException (io.apiman.manager.api.rest.exceptions.PolicyNotFoundException)10 ApiAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ApiAlreadyExistsException)9