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