use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException 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.WrongAttributeValueException 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.WrongAttributeValueException in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_def_projectOwnerLogin method checkAttributeValue.
public void checkAttributeValue(PerunSessionImpl sess, Resource resource, Group group, Attribute attribute) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
String ownerLogin = (String) attribute.getValue();
if (ownerLogin == null)
return;
Pattern pattern = Pattern.compile("^[a-zA-Z0-9][-A-z0-9_.@/]*$");
Matcher match = pattern.matcher(ownerLogin);
if (!match.matches()) {
throw new WrongAttributeValueException(attribute, group, resource, "Bad format of attribute projectOwnerLogin (expected something like 'alois25').");
}
//Get Facility from resource
Facility facility = sess.getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
//Get all users
List<User> users = sess.getPerunBl().getUsersManagerBl().getUsers(sess);
//Check if exists any user with this login
for (User u : users) {
Attribute userLogin = null;
try {
userLogin = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, u, AttributesManager.NS_USER_FACILITY_ATTR_VIRT + ":login");
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Not existing attribute user_login", ex);
}
if (ownerLogin.equals(userLogin.getValue()))
return;
}
throw new WrongAttributeValueException(attribute, group, resource, "There is no user with this login:'" + ownerLogin);
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_virt_googleGroupName method setAttributeValue.
@Override
public boolean setAttributeValue(PerunSessionImpl sess, Resource resource, Group group, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
Attribute googleGroupNameNamespaceAttribute = sess.getPerunBl().getModulesUtilsBl().getGoogleGroupNameNamespaceAttributeWithNotNullValue(sess, resource);
try {
Attribute groupNameAttribute = new Attribute(sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_GROUP_ATTR_DEF + ":googleGroupName-namespace:" + googleGroupNameNamespaceAttribute.getValue()));
groupNameAttribute.setValue(attribute.getValue());
return sess.getPerunBl().getAttributesManagerBl().setAttributeWithoutCheck(sess, group, groupNameAttribute);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
} catch (WrongAttributeValueException ex) {
throw new InternalErrorException(ex);
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException 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