use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class urn_perun_member_attribute_def_def_workplace 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 userWorkplace = null;
try {
userWorkplace = session.getPerunBl().getAttributesManagerBl().getAttribute(session, user, A_U_workplace);
if (userWorkplace.getValue() == null) {
userWorkplace.setValue(attribute.getValue());
session.getPerunBl().getAttributesManagerBl().setAttribute(session, user, userWorkplace);
}
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
} catch (WrongAttributeValueException ex) {
throw new WrongReferenceAttributeValueException(attribute, userWorkplace, "Mismatch in checking of member workplace and user workplace (different checking rules)", ex);
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class AttributesManagerBlImpl method removeAllAttributes.
public void removeAllAttributes(PerunSession sess, Resource resource, Member member) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
this.checkMemberIsFromTheSameVoLikeResource(sess, member, resource);
List<Attribute> attributes = getAttributes(sess, resource, member);
getAttributesManagerImpl().removeAllAttributes(sess, resource, member);
getPerunBl().getAuditer().log(sess, "All attributes removed for {} and {}", resource, member);
for (Attribute attribute : attributes) attribute.setValue(null);
try {
checkAttributesValue(sess, resource, member, attributes);
checkAttributesValue(sess, resource, member, attributes);
} catch (WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
}
for (Attribute attribute : attributes) {
try {
getAttributesManagerImpl().changedAttributeHook(sess, resource, member, new Attribute(attribute));
} catch (WrongAttributeValueException ex) {
//TODO better exception here
throw new InternalErrorException(ex);
} catch (WrongReferenceAttributeValueException ex) {
//TODO better exception here
throw new InternalErrorException(ex);
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class AttributesManagerBlImpl method setAttributeWithoutCheck.
public boolean setAttributeWithoutCheck(PerunSession sess, Facility facility, Attribute attribute) throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
getAttributesManagerImpl().checkNamespace(sess, attribute, NS_FACILITY_ATTR);
if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
throw new WrongAttributeAssignmentException(attribute);
boolean changed = true;
if (isVirtAttribute(sess, attribute)) {
//TODO
throw new InternalErrorException("Virtual attribute can't be set this way yet. Please set physical attribute.");
//getAttributesManagerImpl().setVirtualAttribute(sess, facility, attribute);
} else {
changed = getAttributesManagerImpl().setAttribute(sess, facility, attribute);
}
if (changed) {
getPerunBl().getAuditer().log(sess, "{} set for {}.", attribute, facility);
getAttributesManagerImpl().changedAttributeHook(sess, facility, attribute);
}
return changed;
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class AttributesManagerBlImpl method setAttributeWithoutCheck.
public boolean setAttributeWithoutCheck(PerunSession sess, Facility facility, User user, Attribute attribute) throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
getAttributesManagerImpl().checkNamespace(sess, attribute, AttributesManager.NS_USER_FACILITY_ATTR);
if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
throw new WrongAttributeAssignmentException(attribute);
boolean changed = true;
if (getAttributesManagerImpl().isVirtAttribute(sess, attribute)) {
//TODO better exception here
try {
changed = getAttributesManagerImpl().setVirtualAttribute(sess, facility, user, attribute);
} catch (WrongReferenceAttributeValueException ex) {
throw new InternalErrorException(ex);
}
//FIXME update changed variable
} else {
changed = getAttributesManagerImpl().setAttribute(sess, facility, user, attribute);
}
if (changed) {
getPerunBl().getAuditer().log(sess, "{} set for {} and {}.", attribute, facility, user);
getAttributesManagerImpl().changedAttributeHook(sess, facility, user, attribute);
}
return changed;
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class AttributesManagerBlImpl method getAttributeById.
public Attribute getAttributeById(PerunSession sess, Resource resource, Member member, int id) throws InternalErrorException, WrongAttributeAssignmentException, AttributeNotExistsException {
this.checkMemberIsFromTheSameVoLikeResource(sess, member, resource);
AttributeDefinition attributeDefinition = getAttributeDefinitionById(sess, id);
if (getAttributesManagerImpl().isFromNamespace(sess, attributeDefinition, AttributesManager.NS_MEMBER_RESOURCE_ATTR)) {
Attribute attribute = getAttributesManagerImpl().getAttributeById(sess, resource, member, id);
getAttributesManagerImpl().checkNamespace(sess, attribute, NS_MEMBER_RESOURCE_ATTR);
return attribute;
} else if (getAttributesManagerImpl().isFromNamespace(sess, attributeDefinition, AttributesManager.NS_USER_FACILITY_ATTR)) {
//user-facility attribues
User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
Facility facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
return getAttributesManagerImpl().getAttributeById(sess, facility, user, id);
} else if (getAttributesManagerImpl().isFromNamespace(sess, attributeDefinition, AttributesManager.NS_USER_ATTR)) {
//user and user core attributes
User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
return getAttributesManagerImpl().getAttributeById(sess, user, id);
} else {
throw new WrongAttributeAssignmentException(attributeDefinition);
}
}
Aggregations