use of cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException in project perun by CESNET.
the class urn_perun_member_attribute_def_def_address method changedAttributeHook.
@Override
public void changedAttributeHook(PerunSessionImpl session, Member member, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
User user = session.getPerunBl().getUsersManagerBl().getUserByMember(session, member);
if (attribute.getValue() != null) {
Attribute userAddress = null;
try {
userAddress = session.getPerunBl().getAttributesManagerBl().getAttribute(session, user, A_U_address);
if (userAddress.getValue() == null) {
userAddress.setValue(attribute.getValue());
session.getPerunBl().getAttributesManagerBl().setAttribute(session, user, userAddress);
}
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
} catch (WrongAttributeValueException ex) {
throw new WrongReferenceAttributeValueException(attribute, userAddress, "Mismatch in checking of member address and user address (different checking rules)", ex);
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_def_projectName method checkAttributeValue.
public void checkAttributeValue(PerunSessionImpl sess, Resource resource, Group group, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
String name = (String) attribute.getValue();
if (name == null)
return;
Pattern pattern = Pattern.compile("^[-_a-zA-Z0-9]+$");
Matcher match = pattern.matcher(name);
if (!match.matches()) {
throw new WrongAttributeValueException(attribute, group, resource, "Bad format of attribute projectName (expected something like 'project_name-24').");
}
//Prepare this resource projectsBasePath
Attribute thisResourceProjectsBasePath = null;
try {
thisResourceProjectsBasePath = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, AttributesManager.NS_RESOURCE_ATTR_DEF + ":projectsBasePath");
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Attribute projectBasePath not exists!", ex);
}
//Prepare value of this resource projectsBasePath
String thisResourceProjectBasePathValue = null;
if (thisResourceProjectsBasePath.getValue() != null) {
thisResourceProjectBasePathValue = (String) thisResourceProjectsBasePath.getValue();
} else {
throw new WrongReferenceAttributeValueException(attribute, thisResourceProjectsBasePath, group, resource, resource, null, "Resource must have set projectsBasePath if attribute projectName for it's group need to be set.");
}
//Get All Resources with the same project_base_path
Facility facility = sess.getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
List<Resource> resources = sess.getPerunBl().getFacilitiesManagerBl().getAssignedResources(sess, facility);
resources.remove(resource);
//Remove all resources which has other
Iterator<Resource> iterator = resources.iterator();
while (iterator.hasNext()) {
Resource r = iterator.next();
Attribute otherResourceProjectsBasePath = null;
try {
otherResourceProjectsBasePath = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, r, AttributesManager.NS_RESOURCE_ATTR_DEF + ":projectsBasePath");
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Attribute projectBasePath not exists!", ex);
}
if (otherResourceProjectsBasePath.getValue() != null) {
String otherResourceProjectsBasePathValue = (String) otherResourceProjectsBasePath.getValue();
if (!thisResourceProjectBasePathValue.equals(otherResourceProjectsBasePathValue))
iterator.remove();
} else {
//If projectsBasePath is null, also remove resource
iterator.remove();
}
}
//For all resources with the same project_base_path look for groups with the same projectName
for (Resource r : resources) {
List<Group> groups = sess.getPerunBl().getGroupsManagerBl().getAssignedGroupsToResource(sess, r);
//Our group may aslo be part of assigned Group, need to be removed
groups.remove(group);
for (Group g : groups) {
Attribute groupProjectName = null;
try {
groupProjectName = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, r, g, AttributesManager.NS_GROUP_RESOURCE_ATTR_DEF + ":projectName");
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Attribute projectName not exists!", ex);
}
String groupProjectNameValue = null;
if (groupProjectName.getValue() != null) {
groupProjectNameValue = (String) groupProjectName.getValue();
}
//If the name is somewhere same, exception must be thrown
if (name.equals(groupProjectNameValue)) {
throw new WrongReferenceAttributeValueException(attribute, groupProjectName, group, resource, g, r, "Group " + group + " and " + g + " have the same projectName in the same projectsBasePath.");
}
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_virt_googleGroupName method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, Resource resource, Group group, AttributeDefinition attributeDefinition) throws InternalErrorException {
Attribute attribute = new Attribute(attributeDefinition);
Attribute googleGroupNameNamespaceAttribute;
try {
googleGroupNameNamespaceAttribute = sess.getPerunBl().getModulesUtilsBl().getGoogleGroupNameNamespaceAttributeWithNotNullValue(sess, resource);
} catch (WrongReferenceAttributeValueException ex) {
return attribute;
}
try {
Attribute groupNameAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, AttributesManager.NS_GROUP_ATTR_DEF + ":googleGroupName-namespace:" + googleGroupNameNamespaceAttribute.getValue());
attribute = Utils.copyAttributeToVirtualAttributeWithValue(groupNameAttribute, attribute);
return attribute;
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_virt_unixGID method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, Resource resource, Group group, AttributeDefinition attributeDefinition) throws InternalErrorException {
Attribute attribute = new Attribute(attributeDefinition);
Attribute unixGIDNamespaceAttribute;
try {
unixGIDNamespaceAttribute = sess.getPerunBl().getModulesUtilsBl().getUnixGIDNamespaceAttributeWithNotNullValue(sess, resource);
} catch (WrongReferenceAttributeValueException ex) {
return attribute;
}
try {
Attribute gidAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, AttributesManager.NS_GROUP_ATTR_DEF + ":unixGID-namespace:" + unixGIDNamespaceAttribute.getValue());
attribute = Utils.copyAttributeToVirtualAttributeWithValue(gidAttribute, attribute);
return attribute;
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException in project perun by CESNET.
the class urn_perun_member_attribute_def_def_organization method changedAttributeHook.
@Override
public void changedAttributeHook(PerunSessionImpl session, Member member, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
User user = session.getPerunBl().getUsersManagerBl().getUserByMember(session, member);
if (attribute.getValue() != null) {
Attribute userOrganization = null;
try {
userOrganization = session.getPerunBl().getAttributesManagerBl().getAttribute(session, user, A_U_organization);
if (userOrganization.getValue() == null) {
userOrganization.setValue(attribute.getValue());
session.getPerunBl().getAttributesManagerBl().setAttribute(session, user, userOrganization);
}
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
} catch (WrongAttributeValueException ex) {
throw new WrongReferenceAttributeValueException(attribute, userOrganization, "Mismatch in checking of member organization and user organization (different checking rules)", ex);
}
}
}
Aggregations