Search in sources :

Example 1 with AttributeExistsException

use of cz.metacentrum.perun.core.api.exceptions.AttributeExistsException in project perun by CESNET.

the class AttributesManagerImpl method createAttribute.

public AttributeDefinition createAttribute(PerunSession sess, AttributeDefinition attribute) throws InternalErrorException, AttributeExistsException {
    if (!attribute.getFriendlyName().matches(AttributesManager.ATTRIBUTES_REGEXP)) {
        throw new InternalErrorException(new IllegalArgumentException("Wrong attribute name " + attribute.getFriendlyName() + ", attribute name must match " + AttributesManager.ATTRIBUTES_REGEXP));
    }
    try {
        int attributeId = Utils.getNewId(jdbc, "attr_names_id_seq");
        jdbc.update("insert into attr_names (id, attr_name, type, dsc, namespace, friendly_name, display_name, created_by, created_at, modified_by, modified_at, created_by_uid, modified_by_uid) " + "values (?,?,?,?,?,?,?,?," + Compatibility.getSysdate() + ",?," + Compatibility.getSysdate() + ",?,?)", attributeId, attribute.getName(), attribute.getType(), attribute.getDescription(), attribute.getNamespace(), attribute.getFriendlyName(), attribute.getDisplayName(), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getUserId(), sess.getPerunPrincipal().getUserId());
        attribute.setId(attributeId);
        log.info("Attribute created: {}", attribute);
        return attribute;
    } catch (DataIntegrityViolationException e) {
        throw new AttributeExistsException("Attribute " + attribute.getName() + " already exists", e);
    } catch (RuntimeException e) {
        throw new InternalErrorException(e);
    }
}
Also used : AttributeExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeExistsException) ConsistencyErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException) InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Aggregations

AttributeExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeExistsException)1 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)1 ConsistencyErrorRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException)1 InternalErrorRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1