use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class AttributesManagerImpl method getAllAttributesStartWithNameWithoutNullValue.
public List<Attribute> getAllAttributesStartWithNameWithoutNullValue(PerunSession sess, Resource resource, String startPartOfName) throws InternalErrorException {
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("rId", resource.getId());
parameters.addValue("nSC", AttributesManager.NS_RESOURCE_ATTR_CORE);
parameters.addValue("nSO", AttributesManager.NS_RESOURCE_ATTR_OPT);
parameters.addValue("nSD", AttributesManager.NS_RESOURCE_ATTR_DEF);
parameters.addValue("startPartOfName", startPartOfName + "%");
try {
return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("ret") + " from attr_names " + "left join resource_attr_values ret on id=ret.attr_id and resource_id=:rId " + "where namespace in ( :nSC,:nSO,:nSD ) and attr_names.attr_name LIKE :startPartOfName", parameters, new AttributeRowMapper(sess, this, resource));
} catch (EmptyResultDataAccessException ex) {
return new ArrayList<Attribute>();
} catch (RuntimeException ex) {
throw new InternalErrorException(ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class AttributesManagerImpl method getAllAttributesStartWithNameWithoutNullValue.
public List<Attribute> getAllAttributesStartWithNameWithoutNullValue(PerunSession sess, Group group, String startPartOfName) throws InternalErrorException {
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("gId", group.getId());
parameters.addValue("nSC", AttributesManager.NS_GROUP_ATTR_CORE);
parameters.addValue("nSO", AttributesManager.NS_GROUP_ATTR_OPT);
parameters.addValue("nSD", AttributesManager.NS_GROUP_ATTR_DEF);
parameters.addValue("startPartOfName", startPartOfName + "%");
try {
return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("grt") + " from attr_names " + "left join group_attr_values grt on id=grt.attr_id and group_id=:gId " + "where namespace in ( :nSC,:nSO,:nSD ) and attr_names.attr_name LIKE :startPartOfName", parameters, new AttributeRowMapper(sess, this, group));
} catch (EmptyResultDataAccessException ex) {
return new ArrayList<Attribute>();
} catch (RuntimeException ex) {
throw new InternalErrorException(ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class AttributesManagerImpl method setAttribute.
@Override
public boolean setAttribute(final PerunSession sess, final Object object, final Attribute attribute) throws InternalErrorException, WrongAttributeAssignmentException {
String tableName;
String columnName;
Object identificator;
String namespace;
// check whether the object is String or Perun Bean:
if (object instanceof String) {
tableName = "entityless_attr_values";
columnName = "subject";
identificator = (String) object;
namespace = AttributesManager.NS_ENTITYLESS_ATTR;
} else if (object instanceof PerunBean) {
PerunBean bean = (PerunBean) object;
// Add underscore between two letters where first is lowercase and second is uppercase, then lowercase BeanName
String name = bean.getBeanName().replaceAll("(\\p{Ll})(\\p{Lu})", "$1_$2").toLowerCase();
// same behaviour for rich objects as for the simple ones -> cut off "rich_" prefix
if (name.startsWith("rich")) {
name = name.replaceFirst("rich_", "");
}
// get namespace of the perun bean
namespace = NAMESPACES_BEANS_MAP.get(name);
if (namespace == null) {
// perun bean is not in the namespace map
throw new InternalErrorException(new IllegalArgumentException("Setting attribute for perun bean " + bean + " is not allowed."));
}
tableName = name + "_attr_values";
columnName = name + "_id";
identificator = bean.getId();
} else {
throw new InternalErrorException(new IllegalArgumentException("Object " + object + " must be either String or PerunBean."));
}
// check that given object is consistent with the attribute
checkNamespace(sess, attribute, namespace);
// create map of parameters for the where clause of the SQL query
Map<String, Object> params = new HashMap<>();
params.put("attr_id", attribute.getId());
params.put(columnName, identificator);
// save attribute
return setAttributeInDB(sess, attribute, tableName, params);
}
use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class AttributesManagerImpl method getAttributes.
@Override
public List<Attribute> getAttributes(PerunSession sess, Member member, Group group, List<String> attrNames) throws InternalErrorException {
MapSqlParameterSource parameters = new MapSqlParameterSource();
parameters.addValue("mId", member.getId());
parameters.addValue("gId", group.getId());
parameters.addValue("nSO", AttributesManager.NS_MEMBER_GROUP_ATTR_OPT);
parameters.addValue("nSD", AttributesManager.NS_MEMBER_GROUP_ATTR_DEF);
parameters.addValue("nSV", AttributesManager.NS_MEMBER_GROUP_ATTR_VIRT);
parameters.addValue("attrNames", attrNames);
try {
return namedParameterJdbcTemplate.query("select " + getAttributeMappingSelectQuery("mem_gr") + " from attr_names " + "left join member_group_attr_values mem_gr on id=mem_gr.attr_id and member_id=:mId and group_id=:gId " + "where namespace in ( :nSO,:nSD,:nSV ) and attr_names.attr_name in ( :attrNames )", parameters, new AttributeRowMapper(sess, this, member, group));
} catch (EmptyResultDataAccessException ex) {
return new ArrayList<Attribute>();
} catch (RuntimeException ex) {
throw new InternalErrorException(ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.InternalErrorException in project perun by CESNET.
the class AttributesManagerImpl method createAttributeExistsForInitialize.
public void createAttributeExistsForInitialize(AttributeDefinition attribute) throws InternalErrorException {
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, default_attr_id) values (?,?,?,?,?,?,?,NULL)", attributeId, attribute.getName(), attribute.getType(), attribute.getDescription(), attribute.getNamespace(), attribute.getFriendlyName(), attribute.getDisplayName());
log.info("Attribute created during initialization of attributesManager: {}", attribute);
} catch (DataIntegrityViolationException e) {
throw new ConsistencyErrorException("Attribute already exists: " + attribute, e);
} catch (RuntimeException e) {
throw new InternalErrorException(e);
}
}
Aggregations