Search in sources :

Example 11 with InternalErrorException

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);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ConsistencyErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException) InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 12 with InternalErrorException

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);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ConsistencyErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException) InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 13 with InternalErrorException

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);
}
Also used : PerunBean(cz.metacentrum.perun.core.api.PerunBean) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 14 with InternalErrorException

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);
    }
}
Also used : MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ConsistencyErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.ConsistencyErrorRuntimeException) InternalErrorRuntimeException(cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException) Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 15 with InternalErrorException

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);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) 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

InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)376 Attribute (cz.metacentrum.perun.core.api.Attribute)119 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)104 ArrayList (java.util.ArrayList)94 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)89 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)78 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)68 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)67 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)44 User (cz.metacentrum.perun.core.api.User)37 Group (cz.metacentrum.perun.core.api.Group)36 InternalErrorRuntimeException (cz.metacentrum.perun.core.api.exceptions.rt.InternalErrorRuntimeException)33 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)33 HashMap (java.util.HashMap)30 IOException (java.io.IOException)28 Member (cz.metacentrum.perun.core.api.Member)24 Map (java.util.Map)24 Facility (cz.metacentrum.perun.core.api.Facility)23 List (java.util.List)23 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)22