Search in sources :

Example 1 with PolicyDefinitionAlreadyExistsException

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);
    }
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) PolicyDefinitionAlreadyExistsException(io.apiman.manager.api.rest.exceptions.PolicyDefinitionAlreadyExistsException) SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) AbstractRestException(io.apiman.manager.api.rest.exceptions.AbstractRestException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) PolicyDefinitionNotFoundException(io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException)

Aggregations

StorageException (io.apiman.manager.api.core.exceptions.StorageException)1 AbstractRestException (io.apiman.manager.api.rest.exceptions.AbstractRestException)1 NotAuthorizedException (io.apiman.manager.api.rest.exceptions.NotAuthorizedException)1 PolicyDefinitionAlreadyExistsException (io.apiman.manager.api.rest.exceptions.PolicyDefinitionAlreadyExistsException)1 PolicyDefinitionNotFoundException (io.apiman.manager.api.rest.exceptions.PolicyDefinitionNotFoundException)1 SystemErrorException (io.apiman.manager.api.rest.exceptions.SystemErrorException)1