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;
}
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);
}
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);
}
}
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);
}
}
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);
}
}
Aggregations