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);
}
}
Aggregations