use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_virt_unixGroupName method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, Resource resource, Group group, AttributeDefinition attributeDefinition) throws InternalErrorException {
Attribute attribute = new Attribute(attributeDefinition);
Attribute unixGroupNameNamespaceAttribute;
try {
unixGroupNameNamespaceAttribute = sess.getPerunBl().getModulesUtilsBl().getUnixGroupNameNamespaceAttributeWithNotNullValue(sess, resource);
} catch (WrongReferenceAttributeValueException ex) {
return attribute;
}
try {
Attribute groupNameAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, AttributesManager.NS_GROUP_ATTR_DEF + ":unixGroupName-namespace:" + unixGroupNameNamespaceAttribute.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.WrongAttributeAssignmentException in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_virt_unixGroupName method setAttributeValue.
@Override
public boolean setAttributeValue(PerunSessionImpl sess, Resource resource, Group group, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
Attribute unixGroupNameNamespaceAttribute = sess.getPerunBl().getModulesUtilsBl().getUnixGroupNameNamespaceAttributeWithNotNullValue(sess, resource);
try {
Attribute groupNameAttribute = new Attribute(sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_GROUP_ATTR_DEF + ":unixGroupName-namespace:" + unixGroupNameNamespaceAttribute.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.WrongAttributeAssignmentException in project perun by CESNET.
the class urn_perun_member_attribute_def_def_phone 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 userPhone = null;
try {
userPhone = session.getPerunBl().getAttributesManagerBl().getAttribute(session, user, A_U_phone);
if (userPhone.getValue() == null) {
userPhone.setValue(attribute.getValue());
session.getPerunBl().getAttributesManagerBl().setAttribute(session, user, userPhone);
}
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
} catch (WrongAttributeValueException ex) {
throw new WrongReferenceAttributeValueException(attribute, userPhone, "Mismatch in checking of member phone and user phone (different checking rules)", ex);
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class urn_perun_resource_attribute_def_def_unixGroupName_namespace method changedAttributeHook.
@Override
public void changedAttributeHook(PerunSessionImpl session, Resource resource, Attribute attribute) throws InternalErrorException, WrongReferenceAttributeValueException {
//Need to know if this is remove or set, if value is null, its remove, otherway it is set
String groupNameNamespace = attribute.getFriendlyNameParameter();
try {
if (attribute.getValue() == null) {
//This is ok, for now no changes for removing some GroupName of this Resource
} else {
//First need to find facility for the group
Facility facilityOfResource = session.getPerunBl().getResourcesManagerBl().getFacility(session, resource);
String gidNamespace = null;
//If facility has the same namespace of GroupName like attribute unixGroupName-namespace, then prepare gidNamespace
Attribute facilityGroupNameNamespace = session.getPerunBl().getAttributesManagerBl().getAttribute(session, facilityOfResource, A_F_unixGroupName_namespace);
if (facilityGroupNameNamespace.getValue() != null) {
if (groupNameNamespace.equals(facilityGroupNameNamespace.getValue())) {
Attribute facilityGIDNamespace = session.getPerunBl().getAttributesManagerBl().getAttribute(session, facilityOfResource, A_F_unixGID_namespace);
if (facilityGIDNamespace.getValue() != null) {
gidNamespace = (String) facilityGIDNamespace.getValue();
}
}
}
//If there is any gidNamespace which is need to be set, do it there
if (gidNamespace != null) {
Attribute resourceUnixGIDNamespace = session.getPerunBl().getAttributesManagerBl().getAttribute(session, resource, A_R_unixGID_namespace + ":" + gidNamespace);
if (resourceUnixGIDNamespace.getValue() == null) {
resourceUnixGIDNamespace = session.getPerunBl().getAttributesManagerBl().fillAttribute(session, resource, resourceUnixGIDNamespace);
if (resourceUnixGIDNamespace.getValue() == null)
throw new WrongReferenceAttributeValueException(attribute, resourceUnixGIDNamespace);
try {
session.getPerunBl().getAttributesManagerBl().setAttribute(session, resource, resourceUnixGIDNamespace);
} catch (WrongAttributeValueException ex) {
throw new WrongReferenceAttributeValueException(attribute, resourceUnixGIDNamespace, ex);
}
} else {
try {
session.getPerunBl().getAttributesManagerBl().checkAttributeValue(session, resource, resourceUnixGIDNamespace);
} catch (WrongAttributeValueException ex) {
throw new WrongReferenceAttributeValueException(attribute, resourceUnixGIDNamespace, ex);
}
}
}
}
} catch (WrongAttributeAssignmentException ex) {
//TODO: need to add WrongAttributeAssignmentException to header of modules methods
throw new InternalErrorException(ex);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class urn_perun_resource_attribute_def_virt_unixGID method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, Resource resource, 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, resource, AttributesManager.NS_RESOURCE_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);
}
}
Aggregations