use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class AttributesManagerBlImpl method setAttributeWithoutCheck.
@Override
public boolean setAttributeWithoutCheck(PerunSession sess, Member member, Group group, Attribute attribute, boolean workWithUserAttributes) throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
throw new WrongAttributeAssignmentException(attribute);
boolean changed = true;
if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_GROUP_ATTR)) {
if (getAttributesManagerImpl().isVirtAttribute(sess, attribute)) {
changed = getAttributesManagerImpl().setVirtualAttribute(sess, member, group, attribute);
} else {
changed = getAttributesManagerImpl().setAttribute(sess, member, group, attribute);
if (changed) {
getPerunBl().getAuditer().log(sess, "{} set for {} and {}.", attribute, member, group);
getAttributesManagerImpl().changedAttributeHook(sess, member, group, attribute);
}
}
} else if (workWithUserAttributes) {
if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_ATTR)) {
User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
if (getAttributesManagerImpl().isVirtAttribute(sess, attribute)) {
changed = getAttributesManagerImpl().setVirtualAttribute(sess, user, attribute);
} else {
changed = setAttributeWithoutCheck(sess, user, attribute);
}
} else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_ATTR)) {
if (getAttributesManagerImpl().isVirtAttribute(sess, attribute)) {
changed = getAttributesManagerImpl().setVirtualAttribute(sess, member, attribute);
} else {
changed = setAttributeWithoutCheck(sess, member, attribute);
}
} else {
throw new WrongAttributeAssignmentException(attribute);
}
} else {
throw new WrongAttributeAssignmentException(attribute);
}
return changed;
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class AttributesManagerBlImpl method checkAttributesDependencies.
private void checkAttributesDependencies(PerunSession sess, Resource resource, Group group, List<Attribute> attributes, boolean workWithGroupAttributes) throws InternalErrorException, WrongAttributeValueException, WrongAttributeAssignmentException, WrongReferenceAttributeValueException {
if (workWithGroupAttributes) {
List<Attribute> groupAttributes = new ArrayList<Attribute>();
List<Attribute> groupResourceAttributes = new ArrayList<Attribute>();
for (Attribute attr : attributes) {
if (getAttributesManagerImpl().isFromNamespace(sess, attr, NS_GROUP_RESOURCE_ATTR)) {
groupResourceAttributes.add(attr);
} else if (getAttributesManagerImpl().isFromNamespace(sess, attr, NS_GROUP_ATTR)) {
groupAttributes.add(attr);
} else {
throw new WrongAttributeAssignmentException(attr);
}
}
checkAttributesDependencies(sess, resource, group, groupResourceAttributes);
checkAttributesDependencies(sess, group, null, groupAttributes);
} else {
checkAttributesDependencies(sess, resource, group, attributes);
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class AttributesManagerBlImpl method setAttributes.
public void setAttributes(PerunSession sess, Facility facility, Resource resource, User user, Member member, List<Attribute> attributes) throws InternalErrorException, WrongAttributeValueException, WrongAttributeAssignmentException, WrongReferenceAttributeValueException {
// clasification of attributes to attributes to remove and attributes to set
List<Attribute> attributesToRemove = new ArrayList<Attribute>();
List<Attribute> attributesToSet = new ArrayList<Attribute>();
for (Attribute attribute : attributes) {
if (attribute.getValue() == null) {
attributesToRemove.add(attribute);
} else {
attributesToSet.add(attribute);
}
}
removeAttributes(sess, facility, resource, user, member, attributesToRemove);
for (Attribute attribute : attributesToSet) {
//skip core attributes
if (!getAttributesManagerImpl().isCoreAttribute(sess, attribute)) {
if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_RESOURCE_ATTR)) {
setAttributeWithoutCheck(sess, resource, member, attribute, false);
} else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_FACILITY_ATTR)) {
setAttributeWithoutCheck(sess, facility, user, attribute);
} else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_ATTR)) {
setAttributeWithoutCheck(sess, user, attribute);
} else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_ATTR)) {
setAttributeWithoutCheck(sess, member, attribute);
} else {
throw new WrongAttributeAssignmentException(attribute);
}
}
}
//if checkAttributesValue fails it causes rollback so no attribute will be stored
checkAttributesValue(sess, facility, resource, user, member, attributesToSet);
this.checkAttributesDependencies(sess, resource, member, user, facility, attributesToSet);
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class AttributesManagerBlImpl method removeAttributeWithoutCheck.
public boolean removeAttributeWithoutCheck(PerunSession sess, Vo vo, AttributeDefinition attribute) throws InternalErrorException, WrongAttributeAssignmentException {
getAttributesManagerImpl().checkNamespace(sess, attribute, NS_VO_ATTR);
if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
throw new WrongAttributeAssignmentException(attribute);
boolean changed = getAttributesManagerImpl().removeAttribute(sess, vo, attribute);
if (changed) {
try {
getAttributesManagerImpl().changedAttributeHook(sess, vo, 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);
}
getPerunBl().getAuditer().log(sess, "{} removed for {}", attribute, vo);
}
return changed;
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class AttributesManagerBlImpl method setRequiredAttributes.
public void setRequiredAttributes(PerunSession sess, Facility facility, Resource resource, User user, Member member, List<Attribute> attributes) throws InternalErrorException, WrongAttributeAssignmentException, WrongReferenceAttributeValueException, AttributeNotExistsException, WrongAttributeValueException {
//fill attributes and get back only those which were really filled with new value
List<Attribute> filledAttributes = this.fillAttributes(sess, facility, resource, user, member, attributes, true);
//Remove all filledAttributes from all attributes list
Iterator<Attribute> iterAttr = attributes.iterator();
while (iterAttr.hasNext()) {
Attribute attributeFromAllAttrs = iterAttr.next();
for (Attribute attributeFromFillAttrs : filledAttributes) {
if (attributeFromAllAttrs.getName().equals(attributeFromFillAttrs.getName())) {
iterAttr.remove();
break;
}
}
}
//Set all filledAttributes withoutCheck
for (Attribute attribute : filledAttributes) {
//skip core attributes
if (!getAttributesManagerImpl().isCoreAttribute(sess, attribute)) {
if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_RESOURCE_ATTR)) {
this.setAttributeWithoutCheck(sess, resource, member, attribute, false);
} else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_FACILITY_ATTR)) {
this.setAttributeWithoutCheck(sess, facility, user, attribute);
} else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_ATTR)) {
this.setAttributeWithoutCheck(sess, user, attribute);
} else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_ATTR)) {
this.setAttributeWithoutCheck(sess, member, attribute);
} else {
throw new WrongAttributeAssignmentException(attribute);
}
}
}
//Join all attributes and filled attributes together
attributes.addAll(filledAttributes);
//refresh all virtual attributes with new value
for (Attribute attr : attributes) {
if (this.isVirtAttribute(sess, attr)) {
if (getAttributesManagerImpl().isFromNamespace(sess, attr, AttributesManager.NS_MEMBER_RESOURCE_ATTR)) {
attr.setValue(this.getAttribute(sess, resource, member, attr.getName()).getValue());
} else if (getAttributesManagerImpl().isFromNamespace(sess, attr, AttributesManager.NS_USER_FACILITY_ATTR)) {
attr.setValue(this.getAttribute(sess, facility, user, attr.getName()).getValue());
} else if (getAttributesManagerImpl().isFromNamespace(sess, attr, AttributesManager.NS_USER_ATTR)) {
attr.setValue(this.getAttribute(sess, user, attr.getName()).getValue());
} else if (getAttributesManagerImpl().isFromNamespace(sess, attr, AttributesManager.NS_MEMBER_ATTR)) {
attr.setValue(this.getAttribute(sess, member, attr.getName()).getValue());
} else {
throw new WrongAttributeAssignmentException(attr);
}
}
}
//Check all attributes
checkAttributesValue(sess, facility, resource, user, member, attributes);
//Check all attributes dependencies
this.checkAttributesDependencies(sess, resource, member, user, facility, attributes);
}
Aggregations