use of io.apiman.manager.api.rest.exceptions.PlanVersionAlreadyExistsException in project apiman by apiman.
the class PlanService method createPlanVersion.
public PlanVersionBean createPlanVersion(String organizationId, String planId, NewPlanVersionBean bean) throws PlanNotFoundException, NotAuthorizedException, InvalidVersionException, PlanVersionAlreadyExistsException {
FieldValidator.validateVersion(bean.getVersion());
PlanVersionBean newVersion = tryAction(() -> {
PlanBean plan = storage.getPlan(organizationId, planId);
if (plan == null) {
throw ExceptionFactory.planNotFoundException(planId);
}
if (storage.getPlanVersion(organizationId, planId, bean.getVersion()) != null) {
throw ExceptionFactory.planVersionAlreadyExistsException(planId, bean.getVersion());
}
return createPlanVersionInternal(bean, plan);
});
if (bean.isClone() && bean.getCloneVersion() != null) {
try {
List<PolicySummaryBean> policies = listPlanPolicies(organizationId, planId, bean.getCloneVersion());
for (PolicySummaryBean policySummary : policies) {
PolicyBean policy = getPlanPolicy(organizationId, planId, bean.getCloneVersion(), policySummary.getId());
NewPolicyBean npb = new NewPolicyBean();
npb.setDefinitionId(policy.getDefinition().getId());
npb.setConfiguration(policy.getConfiguration());
createPlanPolicy(organizationId, planId, newVersion.getVersion(), npb);
}
} catch (Exception e) {
// TODO it's ok if the clone fails - we did our best
}
}
// $NON-NLS-1$
LOGGER.debug(String.format("Created plan %s version: %s", planId, newVersion));
return newVersion;
}
use of io.apiman.manager.api.rest.exceptions.PlanVersionAlreadyExistsException in project apiman by apiman.
the class OrganizationResourceImpl method createPlanVersion.
/**
* @see IOrganizationResource#createPlanVersion(java.lang.String,
* java.lang.String, io.apiman.manager.api.beans.plans.NewPlanVersionBean)
*/
@Override
public PlanVersionBean createPlanVersion(String organizationId, String planId, NewPlanVersionBean bean) throws PlanNotFoundException, NotAuthorizedException, InvalidVersionException, PlanVersionAlreadyExistsException {
securityContext.checkPermissions(PermissionType.planEdit, organizationId);
FieldValidator.validateVersion(bean.getVersion());
PlanVersionBean newVersion;
try {
storage.beginTx();
PlanBean plan = storage.getPlan(organizationId, planId);
if (plan == null) {
throw ExceptionFactory.planNotFoundException(planId);
}
if (storage.getPlanVersion(organizationId, planId, bean.getVersion()) != null) {
throw ExceptionFactory.planVersionAlreadyExistsException(planId, bean.getVersion());
}
newVersion = createPlanVersionInternal(bean, plan);
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<PolicySummaryBean> policies = listPlanPolicies(organizationId, planId, bean.getCloneVersion());
for (PolicySummaryBean policySummary : policies) {
PolicyBean policy = getPlanPolicy(organizationId, planId, bean.getCloneVersion(), policySummary.getId());
NewPolicyBean npb = new NewPolicyBean();
npb.setDefinitionId(policy.getDefinition().getId());
npb.setConfiguration(policy.getConfiguration());
createPlanPolicy(organizationId, planId, newVersion.getVersion(), npb);
}
} catch (Exception e) {
// TODO it's ok if the clone fails - we did our best
}
}
// $NON-NLS-1$
log.debug(String.format("Created plan %s version: %s", planId, newVersion));
return newVersion;
}
Aggregations