use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_virt_unixGroupName method fillAttribute.
@Override
public Attribute fillAttribute(PerunSessionImpl sess, Group group, Resource resource, AttributeDefinition attributeDefinition) throws WrongAttributeAssignmentException {
Attribute attribute = new Attribute(attributeDefinition);
Attribute unixGroupNameNamespaceAttribute;
try {
unixGroupNameNamespaceAttribute = sess.getPerunBl().getModulesUtilsBl().getUnixGroupNameNamespaceAttributeWithNotNullValue(sess, resource);
} catch (WrongReferenceAttributeValueException ex) {
return attribute;
}
Attribute groupNameAttribute;
try {
groupNameAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, group, AttributesManager.NS_GROUP_ATTR_DEF + ":unixGroupName-namespace:" + unixGroupNameNamespaceAttribute.getValue());
} 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;
}
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_virt_unixGroupName method setAttributeValue.
@Override
public boolean setAttributeValue(PerunSessionImpl sess, Group group, Resource resource, Attribute attribute) throws 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 | WrongAttributeAssignmentException 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_unixGroupName method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, Group group, Resource resource, AttributeDefinition attributeDefinition) {
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());
return Utils.copyAttributeToVirtualAttributeWithValue(groupNameAttribute, attribute);
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class urn_perun_member_attribute_def_def_mail method changedAttributeHook.
@Override
public void changedAttributeHook(PerunSessionImpl session, Member member, Attribute attribute) throws WrongReferenceAttributeValueException {
User user = session.getPerunBl().getUsersManagerBl().getUserByMember(session, member);
if (attribute.getValue() != null) {
Attribute userPreferredMail = null;
try {
userPreferredMail = session.getPerunBl().getAttributesManagerBl().getAttribute(session, user, A_U_preferredMail);
if (userPreferredMail.getValue() == null) {
userPreferredMail.setValue(attribute.getValue());
session.getPerunBl().getAttributesManagerBl().setAttribute(session, user, userPreferredMail);
}
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
} catch (WrongAttributeValueException ex) {
throw new WrongReferenceAttributeValueException(attribute, userPreferredMail, "Mismatch in checking of member mail and user preferredMail (different checking rules).", ex);
}
}
/* This funcionality is not needed now
//if this mail has been removed, check user preffered mail if the value is still correct, if not set a new one or remove it if no other exists
User user = session.getPerunBl().getUsersManagerBl().getUserByMember(session, member);
try {
Attribute userPreferredMail = session.getPerunBl().getAttributesManagerBl().getAttribute(session, user, A_U_preferredMail);
//TODO: if userPreferredMail is null when memberMail has been removed, its error in consistency, but exception is not solution, need to log it
//If member mail has been removed
if(attribute.getValue() == null) {
try {
session.getPerunBl().getAttributesManagerBl().checkAttributeSemantics(session, user, userPreferredMail);
} catch (WrongAttributeValueException ex) {
List<Member> membersOfUser = session.getPerunBl().getMembersManagerBl().getMembersByUser(session, user);
for(Member m: membersOfUser) {
Attribute memberMail = session.getPerunBl().getAttributesManagerBl().getAttribute(session, member, A_M_mail);
if(memberMail.getValue() != null) {
userPreferredMail.setValue(memberMail.getValue());
session.getPerunBl().getAttributesManagerBl().setAttribute(session, user, userPreferredMail);
break;
}
}
userPreferredMail.setValue(null);
session.getPerunBl().getAttributesManagerBl().setAttribute(session, user, userPreferredMail);
}
//if member mail was new set or set to another value
} else {
//if userPreferredMail is null, so can save this new value there
if(userPreferredMail.getValue() == null) {
userPreferredMail.setValue(attribute.getValue());
session.getPerunBl().getAttributesManagerBl().setAttribute(session, user, userPreferredMail);
//if userPreferredMail is not null, need to try if the old value is still correct, if not, save new value there
} else {
try {
session.getPerunBl().getAttributesManagerBl().checkAttributeSemantics(session, user, userPreferredMail);
} catch (WrongAttributeValueException ex) {
//old value of userPreferredMail is not correct now, save the new value from member mail there
userPreferredMail.setValue(attribute.getValue());
session.getPerunBl().getAttributesManagerBl().setAttribute(session, user, attribute);
}
}
}
} catch(WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
} catch(AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
} catch(WrongAttributeValueException ex) {
throw new WrongReferenceAttributeValueException("There is mismatch between possible format of member mail and userPreferredMail", ex);
}*/
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException 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 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);
}
}
}
Aggregations