use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class AttributesManagerBlImpl method removeAttributeWithoutCheck.
public boolean removeAttributeWithoutCheck(PerunSession sess, Facility facility, User user, AttributeDefinition attribute) throws InternalErrorException, WrongAttributeAssignmentException {
getAttributesManagerImpl().checkNamespace(sess, attribute, NS_USER_FACILITY_ATTR);
if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
throw new WrongAttributeAssignmentException(attribute);
boolean changed = false;
if (getAttributesManagerImpl().isVirtAttribute(sess, attribute)) {
changed = getAttributesManagerImpl().removeVirtualAttribute(sess, facility, user, attribute);
} else {
changed = getAttributesManagerImpl().removeAttribute(sess, facility, user, attribute);
}
if (changed) {
try {
getAttributesManagerImpl().changedAttributeHook(sess, facility, user, 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 {} and {}", attribute, facility, user);
}
return changed;
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class AttributesManagerBlImpl method fillAttributes.
public List<Attribute> fillAttributes(PerunSession sess, Facility facility, Resource resource, User user, Member member, List<Attribute> attributes) throws InternalErrorException, WrongAttributeAssignmentException {
this.checkMemberIsFromTheSameVoLikeResource(sess, member, resource);
List<Attribute> filledAttributes = new ArrayList<Attribute>();
for (Attribute attribute : attributes) {
if (attribute.getValue() == null) {
if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_RESOURCE_ATTR)) {
filledAttributes.add(getAttributesManagerImpl().fillAttribute(sess, resource, member, attribute));
} else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_FACILITY_ATTR)) {
filledAttributes.add(getAttributesManagerImpl().fillAttribute(sess, facility, user, attribute));
} else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_ATTR)) {
filledAttributes.add(getAttributesManagerImpl().fillAttribute(sess, user, attribute));
} else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_ATTR)) {
filledAttributes.add(getAttributesManagerImpl().fillAttribute(sess, member, attribute));
} else {
throw new WrongAttributeAssignmentException(attribute);
}
} else {
//skip non-empty attribute
filledAttributes.add(attribute);
//TODO and check it's namespace
}
}
return filledAttributes;
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class AttributesManagerBlImpl method removeAllAttributes.
public void removeAllAttributes(PerunSession sess, Member member) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException {
List<Attribute> attributes = getAttributes(sess, member);
getAttributesManagerImpl().removeAllAttributes(sess, member);
getPerunBl().getAuditer().log(sess, "All attributes removed for {}", member);
for (Attribute attribute : attributes) attribute.setValue(null);
try {
checkAttributesValue(sess, member, attributes);
this.checkAttributesDependencies(sess, member, null, attributes);
} catch (WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
}
for (Attribute attribute : attributes) {
try {
getAttributesManagerImpl().changedAttributeHook(sess, 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, String key, Attribute attribute) throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
getAttributesManagerImpl().checkNamespace(sess, attribute, AttributesManager.NS_ENTITYLESS_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.");
} else {
changed = getAttributesManagerImpl().setAttribute(sess, key, attribute);
}
if (changed) {
getPerunBl().getAuditer().log(sess, "{} set for {}.", attribute, key);
//TODO this method not existed yet
//getAttributesManagerImpl().changedAttributeHook(sess, key, attribute);
}
return changed;
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class AttributesManagerBlImpl method removeAttributeWithoutCheck.
public boolean removeAttributeWithoutCheck(PerunSession sess, Facility facility, AttributeDefinition attribute) throws InternalErrorException, WrongAttributeAssignmentException {
getAttributesManagerImpl().checkNamespace(sess, attribute, NS_FACILITY_ATTR);
if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
throw new WrongAttributeAssignmentException(attribute);
boolean changed = getAttributesManagerImpl().removeAttribute(sess, facility, attribute);
if (changed) {
try {
getAttributesManagerImpl().changedAttributeHook(sess, facility, 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, facility);
}
return changed;
}
Aggregations