Search in sources :

Example 1 with PlanVersionBean

use of io.apiman.manager.api.beans.plans.PlanVersionBean in project apiman by apiman.

the class EsMarshalling method unmarshallPlanVersion.

/**
 * Unmarshals the given map source into a bean.
 * @param source the source
 * @return the plan version
 */
public static PlanVersionBean unmarshallPlanVersion(Map<String, Object> source) {
    if (source == null) {
        return null;
    }
    PlanVersionBean bean = new PlanVersionBean();
    bean.setVersion(asString(source.get("version")));
    bean.setStatus(asEnum(source.get("status"), PlanStatus.class));
    bean.setCreatedBy(asString(source.get("createdBy")));
    bean.setCreatedOn(asDate(source.get("createdOn")));
    bean.setModifiedBy(asString(source.get("modifiedBy")));
    bean.setModifiedOn(asDate(source.get("modifiedOn")));
    bean.setLockedOn(asDate(source.get("lockedOn")));
    postMarshall(bean);
    return bean;
}
Also used : PlanVersionBean(io.apiman.manager.api.beans.plans.PlanVersionBean) PlanStatus(io.apiman.manager.api.beans.plans.PlanStatus)

Example 2 with PlanVersionBean

use of io.apiman.manager.api.beans.plans.PlanVersionBean in project apiman by apiman.

the class EsStorage method getAllPlanVersions.

/**
 * @see io.apiman.manager.api.core.IStorage#getAllPlanVersions(java.lang.String, java.lang.String)
 */
@SuppressWarnings("nls")
@Override
public Iterator<PlanVersionBean> getAllPlanVersions(String organizationId, String planId) throws StorageException {
    BoolQueryBuilder qb = QueryBuilders.boolQuery();
    List<QueryBuilder> filter = qb.filter();
    filter.add(QueryBuilders.termQuery("organizationId", organizationId));
    filter.add(QueryBuilders.termQuery("planId", planId));
    return getAll(INDEX_MANAGER_POSTFIX_PLAN_VERSION, new // $NON-NLS-1$
    IUnmarshaller<PlanVersionBean>() {

        @Override
        public PlanVersionBean unmarshal(Map<String, Object> source) {
            return EsMarshalling.unmarshallPlanVersion(source);
        }
    }, qb);
}
Also used : BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) TermsQueryBuilder(org.elasticsearch.index.query.TermsQueryBuilder) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) PlanVersionBean(io.apiman.manager.api.beans.plans.PlanVersionBean)

Example 3 with PlanVersionBean

use of io.apiman.manager.api.beans.plans.PlanVersionBean in project apiman by apiman.

the class OrganizationResourceImpl method deletePlanPolicy.

/**
 * @see IOrganizationResource#deletePlanPolicy(java.lang.String, java.lang.String, java.lang.String, long)
 */
@Override
public void deletePlanPolicy(String organizationId, String planId, String version, long policyId) throws OrganizationNotFoundException, PlanVersionNotFoundException, PolicyNotFoundException, NotAuthorizedException {
    securityContext.checkPermissions(PermissionType.planEdit, organizationId);
    // Make sure the plan version exists
    PlanVersionBean pvb = getPlanVersionInternal(organizationId, planId, version);
    if (pvb.getStatus() == PlanStatus.Locked) {
        throw ExceptionFactory.invalidPlanStatusException();
    }
    try {
        storage.beginTx();
        PolicyBean policy = this.storage.getPolicy(PolicyType.Plan, organizationId, planId, version, policyId);
        if (policy == null) {
            throw ExceptionFactory.policyNotFoundException(policyId);
        }
        storage.deletePolicy(policy);
        storage.createAuditEntry(AuditUtils.policyRemoved(policy, PolicyType.Plan, securityContext));
        pvb.setModifiedBy(securityContext.getCurrentUser());
        pvb.setModifiedOn(new Date());
        storage.updatePlanVersion(pvb);
        storage.commitTx();
        // $NON-NLS-1$
        log.debug(String.format("Deleted plan policy %s", policy));
    } 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) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) NewPolicyBean(io.apiman.manager.api.beans.policies.NewPolicyBean) UpdatePolicyBean(io.apiman.manager.api.beans.policies.UpdatePolicyBean) 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) NewPlanVersionBean(io.apiman.manager.api.beans.plans.NewPlanVersionBean) PlanVersionBean(io.apiman.manager.api.beans.plans.PlanVersionBean)

Example 4 with PlanVersionBean

use of io.apiman.manager.api.beans.plans.PlanVersionBean in project apiman by apiman.

the class OrganizationResourceImpl method reorderPlanPolicies.

/**
 * @see IOrganizationResource#reorderPlanPolicies(java.lang.String, java.lang.String, java.lang.String, io.apiman.manager.api.beans.policies.PolicyChainBean)
 */
@Override
public void reorderPlanPolicies(String organizationId, String planId, String version, PolicyChainBean policyChain) throws OrganizationNotFoundException, PlanVersionNotFoundException, NotAuthorizedException {
    securityContext.checkPermissions(PermissionType.planEdit, organizationId);
    // Make sure the plan version exists
    PlanVersionBean pvb = getPlanVersionInternal(organizationId, planId, version);
    try {
        storage.beginTx();
        List<Long> newOrder = new ArrayList<>(policyChain.getPolicies().size());
        for (PolicySummaryBean psb : policyChain.getPolicies()) {
            newOrder.add(psb.getId());
        }
        storage.reorderPolicies(PolicyType.Plan, organizationId, planId, version, newOrder);
        storage.createAuditEntry(AuditUtils.policiesReordered(pvb, PolicyType.Plan, securityContext));
        pvb.setModifiedBy(securityContext.getCurrentUser());
        pvb.setModifiedOn(new Date());
        storage.updatePlanVersion(pvb);
        storage.commitTx();
    } 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) PolicySummaryBean(io.apiman.manager.api.beans.summary.PolicySummaryBean) ArrayList(java.util.ArrayList) 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) NewPlanVersionBean(io.apiman.manager.api.beans.plans.NewPlanVersionBean) PlanVersionBean(io.apiman.manager.api.beans.plans.PlanVersionBean)

Example 5 with PlanVersionBean

use of io.apiman.manager.api.beans.plans.PlanVersionBean in project apiman by apiman.

the class OrganizationResourceImpl method updatePlanPolicy.

/**
 * @see IOrganizationResource#updatePlanPolicy(java.lang.String,
 *      java.lang.String, java.lang.String, long, io.apiman.manager.api.beans.policies.UpdatePolicyBean)
 */
@Override
public void updatePlanPolicy(String organizationId, String planId, String version, long policyId, UpdatePolicyBean bean) throws OrganizationNotFoundException, PlanVersionNotFoundException, PolicyNotFoundException, NotAuthorizedException {
    securityContext.checkPermissions(PermissionType.planEdit, organizationId);
    // Make sure the plan version exists
    PlanVersionBean pvb = getPlanVersionInternal(organizationId, planId, version);
    try {
        storage.beginTx();
        PolicyBean policy = storage.getPolicy(PolicyType.Plan, organizationId, planId, version, policyId);
        if (policy == null) {
            throw ExceptionFactory.policyNotFoundException(policyId);
        }
        if (AuditUtils.valueChanged(policy.getConfiguration(), bean.getConfiguration())) {
            policy.setConfiguration(bean.getConfiguration());
        // Note: we do not audit the policy configuration since it may have sensitive data
        }
        policy.setModifiedOn(new Date());
        policy.setModifiedBy(this.securityContext.getCurrentUser());
        storage.updatePolicy(policy);
        storage.createAuditEntry(AuditUtils.policyUpdated(policy, PolicyType.Plan, securityContext));
        pvb.setModifiedBy(securityContext.getCurrentUser());
        pvb.setModifiedOn(new Date());
        storage.updatePlanVersion(pvb);
        storage.commitTx();
        // $NON-NLS-1$
        log.debug(String.format("Updated plan policy %s", policy));
    } 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) PolicyBean(io.apiman.manager.api.beans.policies.PolicyBean) NewPolicyBean(io.apiman.manager.api.beans.policies.NewPolicyBean) UpdatePolicyBean(io.apiman.manager.api.beans.policies.UpdatePolicyBean) 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) NewPlanVersionBean(io.apiman.manager.api.beans.plans.NewPlanVersionBean) PlanVersionBean(io.apiman.manager.api.beans.plans.PlanVersionBean)

Aggregations

PlanVersionBean (io.apiman.manager.api.beans.plans.PlanVersionBean)40 Date (java.util.Date)21 StorageException (io.apiman.manager.api.core.exceptions.StorageException)20 NewPlanVersionBean (io.apiman.manager.api.beans.plans.NewPlanVersionBean)19 NotAuthorizedException (io.apiman.manager.api.rest.exceptions.NotAuthorizedException)16 ApiVersionBean (io.apiman.manager.api.beans.apis.ApiVersionBean)15 ApiVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException)15 GatewayNotFoundException (io.apiman.manager.api.rest.exceptions.GatewayNotFoundException)15 PlanVersionNotFoundException (io.apiman.manager.api.rest.exceptions.PlanVersionNotFoundException)14 PolicyBean (io.apiman.manager.api.beans.policies.PolicyBean)13 ApiNotFoundException (io.apiman.manager.api.rest.exceptions.ApiNotFoundException)13 ClientVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException)13 InvalidNameException (io.apiman.manager.api.rest.exceptions.InvalidNameException)13 InvalidVersionException (io.apiman.manager.api.rest.exceptions.InvalidVersionException)13 OrganizationNotFoundException (io.apiman.manager.api.rest.exceptions.OrganizationNotFoundException)13 GatewayAuthenticationException (io.apiman.manager.api.gateway.GatewayAuthenticationException)12 ApiAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ApiAlreadyExistsException)12 ApiDefinitionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiDefinitionNotFoundException)12 ApiVersionAlreadyExistsException (io.apiman.manager.api.rest.exceptions.ApiVersionAlreadyExistsException)12 EntityStillActiveException (io.apiman.manager.api.rest.exceptions.EntityStillActiveException)12