use of io.apiman.manager.api.rest.exceptions.PlanVersionNotFoundException 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.rest.exceptions.PlanVersionNotFoundException 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.rest.exceptions.PlanVersionNotFoundException 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);
}
}
use of io.apiman.manager.api.rest.exceptions.PlanVersionNotFoundException in project apiman by apiman.
the class ActionResourceImpl method lockPlan.
/**
* Locks the plan.
* @param action
*/
private void lockPlan(ActionBean action) throws ActionException, NotAuthorizedException {
securityContext.checkPermissions(PermissionType.planAdmin, action.getOrganizationId());
PlanVersionBean versionBean;
try {
versionBean = orgs.getPlanVersion(action.getOrganizationId(), action.getEntityId(), action.getEntityVersion());
} catch (PlanVersionNotFoundException e) {
// $NON-NLS-1$
throw ExceptionFactory.actionException(Messages.i18n.format("PlanNotFound"));
}
// Validate that it's ok to perform this action - plan must not already be locked
if (versionBean.getStatus() == PlanStatus.Locked) {
// $NON-NLS-1$
throw ExceptionFactory.actionException(Messages.i18n.format("InvalidPlanStatus"));
}
versionBean.setStatus(PlanStatus.Locked);
versionBean.setLockedOn(new Date());
try {
storage.beginTx();
storage.updatePlanVersion(versionBean);
storage.createAuditEntry(AuditUtils.planLocked(versionBean, securityContext));
storage.commitTx();
} catch (Exception e) {
storage.rollbackTx();
// $NON-NLS-1$
throw ExceptionFactory.actionException(Messages.i18n.format("LockError"), e);
}
log.debug(// $NON-NLS-1$
String.format(// $NON-NLS-1$
"Successfully locked Plan %s: %s", versionBean.getPlan().getName(), versionBean.getPlan()));
}
use of io.apiman.manager.api.rest.exceptions.PlanVersionNotFoundException in project apiman by apiman.
the class ActionService method lockPlan.
/**
* Locks the plan.
*/
public void lockPlan(String orgId, String planId, String planVersion) throws ActionException, NotAuthorizedException {
PlanVersionBean versionBean;
try {
versionBean = planService.getPlanVersion(orgId, planId, planVersion);
} catch (PlanVersionNotFoundException e) {
// $NON-NLS-1$
throw ExceptionFactory.actionException(Messages.i18n.format("PlanNotFound"));
}
// Validate that it's ok to perform this action - plan must not already be locked
if (versionBean.getStatus() == PlanStatus.Locked) {
// $NON-NLS-1$
throw ExceptionFactory.actionException(Messages.i18n.format("InvalidPlanStatus"));
}
versionBean.setStatus(PlanStatus.Locked);
versionBean.setLockedOn(new Date());
try {
storage.updatePlanVersion(versionBean);
storage.createAuditEntry(AuditUtils.planLocked(versionBean, securityContext));
} catch (Exception e) {
// $NON-NLS-1$
throw ExceptionFactory.actionException(Messages.i18n.format("LockError"), e);
}
LOGGER.debug(// $NON-NLS-1$
String.format(// $NON-NLS-1$
"Successfully locked Plan %s: %s", versionBean.getPlan().getName(), versionBean.getPlan()));
}
Aggregations