use of io.apiman.manager.api.rest.exceptions.PolicyDefinitionAlreadyExistsException in project apiman by apiman.
the class PolicyDefinitionResourceImpl method create.
/**
* @see IPolicyDefinitionResource#create(io.apiman.manager.api.beans.policies.PolicyDefinitionBean)
*/
@Override
public PolicyDefinitionBean create(PolicyDefinitionBean bean) throws PolicyDefinitionAlreadyExistsException, NotAuthorizedException {
securityContext.checkAdminPermissions();
// Auto-generate an ID if one isn't provided.
if (bean.getId() == null || bean.getId().trim().isEmpty()) {
bean.setId(BeanUtils.idFromName(bean.getName()));
} else {
bean.setId(BeanUtils.idFromName(bean.getId()));
}
try {
storage.beginTx();
if (storage.getPolicyDefinition(bean.getId()) != null) {
throw ExceptionFactory.policyDefAlreadyExistsException(bean.getName());
}
if (bean.getFormType() == null) {
bean.setFormType(PolicyFormType.Default);
}
// Store/persist the new policyDef
storage.createPolicyDefinition(bean);
storage.commitTx();
return bean;
} catch (AbstractRestException e) {
storage.rollbackTx();
throw e;
} catch (Exception e) {
storage.rollbackTx();
throw new SystemErrorException(e);
}
}
Aggregations