Search in sources :

Example 71 with ConsistencyErrorException

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

the class GroupsManagerBlImpl method getGroupMemberById.

@Override
public Member getGroupMemberById(PerunSession sess, Group group, int memberId) throws NotGroupMemberException {
    List<Member> members = getGroupsManagerImpl().getGroupMembersById(sess, group, memberId);
    if (members.isEmpty())
        throw new NotGroupMemberException("Member with ID=" + memberId + " is not member of " + group + " or doesn't exists at all.");
    List<Member> filteredMembers = this.filterMembersByMembershipTypeInGroup(members);
    if (filteredMembers.size() == 0)
        throw new InternalErrorException("Filtering DIRECT/INDIRECT members resulted in empty members list.");
    if (filteredMembers.size() > 1)
        throw new ConsistencyErrorException("Filtering DIRECT/INDIRECT members resulted with >1 members with same ID.");
    return filteredMembers.get(0);
}
Also used : NotGroupMemberException(cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException) ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) RichMember(cz.metacentrum.perun.core.api.RichMember) Member(cz.metacentrum.perun.core.api.Member)

Example 72 with ConsistencyErrorException

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

the class AttributesManagerImpl method setAttributeRight.

@Override
public void setAttributeRight(PerunSession sess, AttributeRights rights) {
    try {
        // get action types of the attribute and role from the database
        List<ActionType> dbActionTypes = jdbc.query("SELECT action_types.action_type AS action_type FROM attributes_authz JOIN action_types " + "ON attributes_authz.action_type_id=action_types.id WHERE attr_id=? AND " + "role_id=(SELECT id FROM roles WHERE name=?)", (rs, rowNum) -> ActionType.valueOf(rs.getString("action_type").toUpperCase()), rights.getAttributeId(), rights.getRole().toLowerCase());
        // inserting
        List<ActionType> actionTypesToInsert = new ArrayList<>(rights.getRights());
        actionTypesToInsert.removeAll(dbActionTypes);
        for (ActionType actionType : actionTypesToInsert) {
            jdbc.update("INSERT INTO attributes_authz (attr_id, role_id, action_type_id) VALUES " + "(?, (SELECT id FROM roles WHERE name=?), (SELECT id FROM action_types WHERE action_type=?))", rights.getAttributeId(), rights.getRole().toLowerCase(), actionType.getActionType());
        }
        // deleting
        List<ActionType> actionTypesToDelete = new ArrayList<>(dbActionTypes);
        actionTypesToDelete.removeAll(rights.getRights());
        for (ActionType actionType : actionTypesToDelete) {
            if (0 == jdbc.update("DELETE FROM attributes_authz WHERE attr_id=? AND role_id=(SELECT id FROM roles WHERE name=?) AND " + "action_type_id=(SELECT id FROM action_types WHERE action_type=?)", rights.getAttributeId(), rights.getRole().toLowerCase(), actionType.getActionType())) {
                throw new ConsistencyErrorException("Trying to delete non existing row : AttributeRight={ attributeId=" + rights.getAttributeId() + " role=" + rights.getRole().toLowerCase() + " actionType=" + actionType.getActionType());
            }
        }
    } catch (RuntimeException e) {
        throw new InternalErrorException(e);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) ActionType(cz.metacentrum.perun.core.api.ActionType) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 73 with ConsistencyErrorException

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

the class AttributesManagerImpl method updateAttributeDefinition.

@Override
public AttributeDefinition updateAttributeDefinition(PerunSession perunSession, AttributeDefinition attributeDefinition) {
    try {
        Map<String, Object> map = jdbc.queryForMap("SELECT attr_name, friendly_name, namespace, type, dsc, display_name, is_unique FROM attr_names WHERE id=?", attributeDefinition.getId());
        // update description
        if (!Objects.equals(attributeDefinition.getDescription(), map.get("dsc"))) {
            this.setAttributeDefinitionModified(perunSession, attributeDefinition);
            jdbc.update("update attr_names set dsc=?, modified_by=?, modified_by_uid=?, modified_at=" + Compatibility.getSysdate() + "  where id=?", attributeDefinition.getDescription(), perunSession.getPerunPrincipal().getActor(), perunSession.getPerunPrincipal().getUserId(), attributeDefinition.getId());
        }
        // if values not null && not equals, update
        if ((map.get("display_name") == null && attributeDefinition.getDisplayName() != null) || (map.get("display_name") != null && !Objects.equals(map.get("display_name"), attributeDefinition.getDisplayName()))) {
            this.setAttributeDefinitionModified(perunSession, attributeDefinition);
            jdbc.update("update attr_names set display_name=?, modified_by=?, modified_by_uid=?, modified_at=" + Compatibility.getSysdate() + "  where id=?", attributeDefinition.getDisplayName(), perunSession.getPerunPrincipal().getActor(), perunSession.getPerunPrincipal().getUserId(), attributeDefinition.getId());
        }
        // update unique
        boolean uniqueInDb = (Boolean) map.get("is_unique");
        if (uniqueInDb != attributeDefinition.isUnique()) {
            jdbc.update("UPDATE attr_names SET is_unique=?, modified_by=?, modified_by_uid=?, modified_at=" + Compatibility.getSysdate() + " WHERE id=?", attributeDefinition.isUnique(), perunSession.getPerunPrincipal().getActor(), perunSession.getPerunPrincipal().getUserId(), attributeDefinition.getId());
        }
        return attributeDefinition;
    } catch (EmptyResultDataAccessException ex) {
        throw new ConsistencyErrorException("Updating non existing attributeDefinition", ex);
    } catch (RuntimeException ex) {
        throw new InternalErrorException(ex);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) RoleObject(cz.metacentrum.perun.core.api.RoleObject) EmptyResultDataAccessException(org.springframework.dao.EmptyResultDataAccessException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 74 with ConsistencyErrorException

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

the class urn_perun_group_resource_attribute_def_virt_googleGroupName method checkAttributeSemantics.

@Override
public void checkAttributeSemantics(PerunSessionImpl sess, Group group, Resource resource, Attribute attribute) throws WrongAttributeAssignmentException, WrongReferenceAttributeValueException {
    Attribute googleGroupNameNamespaceAttribute = sess.getPerunBl().getModulesUtilsBl().getGoogleGroupNameNamespaceAttributeWithNotNullValue(sess, resource);
    // we don't allow dots in attribute friendlyName, so we convert domain dots to dash.
    String namespace = (googleGroupNameNamespaceAttribute.valueAsString()).replaceAll("\\.", "-");
    Attribute groupNameAttribute;
    try {
        groupNameAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, AttributesManager.NS_GROUP_ATTR_DEF + ":googleGroupName-namespace:" + namespace);
    } catch (AttributeNotExistsException ex) {
        throw new ConsistencyErrorException(ex);
    }
    groupNameAttribute.setValue(attribute.getValue());
    try {
        sess.getPerunBl().getAttributesManagerBl().checkAttributeSyntax(sess, group, groupNameAttribute);
        sess.getPerunBl().getAttributesManagerBl().checkAttributeSemantics(sess, group, groupNameAttribute);
    } catch (WrongAttributeValueException | WrongReferenceAttributeValueException ex) {
        throw new WrongReferenceAttributeValueException(attribute, ex.getAttribute(), ex);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 75 with ConsistencyErrorException

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

the class urn_perun_group_resource_attribute_def_virt_googleGroupName method fillAttribute.

@Override
public Attribute fillAttribute(PerunSessionImpl sess, Group group, Resource resource, AttributeDefinition attributeDefinition) throws WrongAttributeAssignmentException {
    Attribute attribute = new Attribute(attributeDefinition);
    Attribute googleGroupNameNamespaceAttribute;
    try {
        googleGroupNameNamespaceAttribute = sess.getPerunBl().getModulesUtilsBl().getGoogleGroupNameNamespaceAttributeWithNotNullValue(sess, resource);
    } catch (WrongReferenceAttributeValueException ex) {
        return attribute;
    }
    Attribute groupNameAttribute;
    try {
        // we don't allow dots in attribute friendlyName, so we convert domain dots to dash.
        String namespace = ((String) googleGroupNameNamespaceAttribute.getValue()).replaceAll("\\.", "-");
        groupNameAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, AttributesManager.NS_GROUP_ATTR_DEF + ":googleGroupName-namespace:" + namespace);
    } catch (AttributeNotExistsException ex) {
        throw new ConsistencyErrorException(ex);
    }
    try {
        sess.getPerunBl().getAttributesManagerBl().checkAttributeSyntax(sess, group, groupNameAttribute);
        sess.getPerunBl().getAttributesManagerBl().checkAttributeSemantics(sess, group, groupNameAttribute);
        // check passed, we can use value from this physical attribute
        attribute.setValue(groupNameAttribute.getValue());
        return attribute;
    } catch (WrongAttributeValueException ex) {
        // Physical attribute have wrong value, let's find a new one
        groupNameAttribute.setValue(null);
        groupNameAttribute = sess.getPerunBl().getAttributesManagerBl().fillAttribute(sess, group, groupNameAttribute);
        attribute.setValue(groupNameAttribute.getValue());
        return attribute;
    } catch (WrongReferenceAttributeValueException ex) {
        return attribute;
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Aggregations

ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)281 Attribute (cz.metacentrum.perun.core.api.Attribute)212 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)162 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)120 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)111 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)102 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)84 User (cz.metacentrum.perun.core.api.User)60 ArrayList (java.util.ArrayList)51 Group (cz.metacentrum.perun.core.api.Group)44 Facility (cz.metacentrum.perun.core.api.Facility)41 Resource (cz.metacentrum.perun.core.api.Resource)37 Member (cz.metacentrum.perun.core.api.Member)30 LinkedHashMap (java.util.LinkedHashMap)23 Vo (cz.metacentrum.perun.core.api.Vo)22 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)21 GroupResourceMismatchException (cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)20 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)19 MemberNotExistsException (cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException)17 VoNotExistsException (cz.metacentrum.perun.core.api.exceptions.VoNotExistsException)17