use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class AttributesManagerBlImpl method removeAttributes.
@Override
public void removeAttributes(PerunSession sess, Member member, Group group, List<? extends AttributeDefinition> attributes, boolean workWithUserAttributes) throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
if (!workWithUserAttributes) {
getAttributesManagerImpl().checkNamespace(sess, attributes, NS_MEMBER_GROUP_ATTR);
List<AttributeDefinition> attributesToCheck = new ArrayList<AttributeDefinition>();
for (AttributeDefinition attribute : attributes) {
if (!getAttributesManagerImpl().isCoreAttribute(sess, attribute)) {
if (removeAttributeWithoutCheck(sess, member, group, attribute))
attributesToCheck.add(attribute);
}
}
checkAttributesValue(sess, member, group, attributesFromDefinitions(attributesToCheck));
this.checkAttributesDependencies(sess, member, group, attributesFromDefinitions(attributesToCheck));
} else {
List<AttributeDefinition> attributesToCheck = new ArrayList<AttributeDefinition>();
for (AttributeDefinition attribute : attributes) {
if (!getAttributesManagerImpl().isCoreAttribute(sess, attribute)) {
User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_GROUP_ATTR)) {
if (removeAttributeWithoutCheck(sess, member, group, attribute))
attributesToCheck.add(attribute);
} else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_ATTR)) {
if (removeAttributeWithoutCheck(sess, user, attribute))
attributesToCheck.add(attribute);
} else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_ATTR)) {
if (removeAttributeWithoutCheck(sess, member, attribute))
attributesToCheck.add(attribute);
} else {
throw new WrongAttributeAssignmentException(attribute);
}
}
}
checkAttributesValue(sess, member, group, attributesFromDefinitions(attributesToCheck), workWithUserAttributes);
this.checkAttributesDependencies(sess, member, group, attributesFromDefinitions(attributesToCheck), workWithUserAttributes);
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class AttributesManagerBlImpl method removeAllUserFacilityAttributes.
public void removeAllUserFacilityAttributes(PerunSession sess, User user) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException {
List<RichAttribute<User, Facility>> userFacilitiesAttributes = getAttributesManagerImpl().getAllUserFacilityRichAttributes(sess, user);
//remove all non-virtual attributes
getAttributesManagerImpl().removeAllUserFacilityAttributes(sess, user);
getPerunBl().getAuditer().log(sess, "All non-virtual user-facility attributes removed for all facilities and {}", user);
for (RichAttribute<User, Facility> richAttribute : userFacilitiesAttributes) {
try {
checkAttributeValue(sess, richAttribute.getSecondaryHolder(), richAttribute.getPrimaryHolder(), new Attribute(richAttribute.getAttribute()));
this.checkAttributeDependencies(sess, richAttribute);
} catch (WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
}
}
for (RichAttribute<User, Facility> attribute : userFacilitiesAttributes) {
try {
getAttributesManagerImpl().changedAttributeHook(sess, attribute.getSecondaryHolder(), attribute.getPrimaryHolder(), new Attribute(attribute.getAttribute()));
} 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 removeAllAttributes.
public void removeAllAttributes(PerunSession sess, Facility facility, boolean removeAlsoUserFacilityAttributes) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException {
removeAllAttributes(sess, facility);
if (removeAlsoUserFacilityAttributes) {
List<Attribute> userFacilityAttributes = getUserFacilityAttributesForAnyUser(sess, facility);
getAttributesManagerImpl().removeAllUserFacilityAttributesForAnyUser(sess, facility);
getPerunBl().getAuditer().log(sess, "All user-facility attributes removed for {} for any user.", facility);
for (Attribute attribute : userFacilityAttributes) attribute.setValue(null);
List<User> facilityUsers = perunBl.getFacilitiesManagerBl().getAllowedUsers(sess, facility);
for (User user : facilityUsers) {
try {
checkAttributesValue(sess, facility, user, userFacilityAttributes);
this.checkAttributesDependencies(sess, facility, user, userFacilityAttributes);
} catch (WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
}
for (Attribute attribute : userFacilityAttributes) {
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);
}
}
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class AttributesManagerBlImpl method removeAttributes.
public void removeAttributes(PerunSession sess, Member member, boolean workWithUserAttributes, List<? extends AttributeDefinition> attributes) throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
if (!workWithUserAttributes) {
getAttributesManagerImpl().checkNamespace(sess, attributes, NS_MEMBER_ATTR);
List<AttributeDefinition> attributesToCheck = new ArrayList<AttributeDefinition>();
for (AttributeDefinition attribute : attributes) {
//skip core attributes
if (!getAttributesManagerImpl().isCoreAttribute(sess, attribute)) {
if (removeAttributeWithoutCheck(sess, member, attribute))
attributesToCheck.add(attribute);
}
}
this.checkAttributesValue(sess, member, attributesFromDefinitions(attributesToCheck));
this.checkAttributesDependencies(sess, member, null, attributesFromDefinitions(attributesToCheck));
} else {
User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
List<AttributeDefinition> attributesToCheck = new ArrayList<AttributeDefinition>();
for (AttributeDefinition attribute : attributes) {
//skip core attributes
if (!getAttributesManagerImpl().isCoreAttribute(sess, attribute)) {
if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_ATTR)) {
if (removeAttributeWithoutCheck(sess, member, attribute))
attributesToCheck.add(attribute);
} else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_ATTR)) {
if (removeAttributeWithoutCheck(sess, user, attribute))
attributesToCheck.add(attribute);
} else {
throw new WrongAttributeAssignmentException(attribute);
}
}
}
this.checkAttributesValue(sess, member, attributesFromDefinitions(attributesToCheck), true);
this.checkAttributesDependencies(sess, member, attributesFromDefinitions(attributesToCheck), workWithUserAttributes);
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class AttributesManagerBlImpl method removeAttributes.
public void removeAttributes(PerunSession sess, Resource resource, Group group, List<? extends AttributeDefinition> attributes, boolean workWithGroupAttributes) throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
if (!workWithGroupAttributes) {
removeAttributes(sess, resource, group, attributes);
} else {
List<AttributeDefinition> attributesToCheck = new ArrayList<AttributeDefinition>();
for (AttributeDefinition attribute : attributes) {
//skip core attributes
if (!getAttributesManagerImpl().isCoreAttribute(sess, attribute)) {
if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_GROUP_RESOURCE_ATTR)) {
if (removeAttributeWithoutCheck(sess, resource, group, attribute))
attributesToCheck.add(attribute);
} else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_GROUP_ATTR)) {
if (removeAttributeWithoutCheck(sess, group, attribute))
attributesToCheck.add(attribute);
} else {
throw new WrongAttributeAssignmentException(attribute);
}
}
}
checkAttributesValue(sess, resource, group, attributesFromDefinitions(attributesToCheck), workWithGroupAttributes);
this.checkAttributesDependencies(sess, resource, group, attributesFromDefinitions(attributesToCheck), workWithGroupAttributes);
}
}
Aggregations