use of cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException in project perun by CESNET.
the class AttributesManagerBlImpl method removeAllAttributes.
public void removeAllAttributes(PerunSession sess, UserExtSource ues) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException {
List<Attribute> attributes = getAttributes(sess, ues);
getAttributesManagerImpl().removeAllAttributes(sess, ues);
getPerunBl().getAuditer().log(sess, "All attributes removed for {}", ues);
for (Attribute attribute : attributes) attribute.setValue(null);
try {
checkAttributesValue(sess, ues, attributes);
this.checkAttributesDependencies(sess, ues, null, attributes);
} catch (WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
}
for (Attribute attribute : attributes) {
try {
getAttributesManagerImpl().changedAttributeHook(sess, ues, 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.WrongReferenceAttributeValueException in project perun by CESNET.
the class AttributesManagerBlImpl method removeAttributeWithoutCheck.
public boolean removeAttributeWithoutCheck(PerunSession sess, Member member, AttributeDefinition attribute) throws InternalErrorException, WrongAttributeAssignmentException {
getAttributesManagerImpl().checkNamespace(sess, attribute, NS_MEMBER_ATTR);
if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
throw new WrongAttributeAssignmentException(attribute);
boolean changed = getAttributesManagerImpl().removeAttribute(sess, member, attribute);
if (changed) {
try {
if (changed)
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);
}
getPerunBl().getAuditer().log(sess, "{} removed for {}", attribute, member);
}
return changed;
}
use of cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException in project perun by CESNET.
the class AttributesManagerBlImpl method removeAllAttributes.
@Override
public void removeAllAttributes(PerunSession sess, Member member, Group group) throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
List<Attribute> attributes = getAttributes(sess, member, group);
getAttributesManagerImpl().removeAllAttributes(sess, member, group);
getPerunBl().getAuditer().log(sess, "All attributes removed for {} and {}", member, group);
for (Attribute attribute : attributes) attribute.setValue(null);
try {
checkAttributesValue(sess, member, group, attributes);
} catch (WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
}
for (Attribute attribute : attributes) {
try {
getAttributesManagerImpl().changedAttributeHook(sess, member, group, 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.WrongReferenceAttributeValueException in project perun by CESNET.
the class AttributesManagerBlImpl method doTheMagic.
public void doTheMagic(PerunSession sess, Member member, boolean trueMagic) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
List<Resource> resources = getPerunBl().getResourcesManagerBl().getAllowedResources(sess, member);
for (Resource resource : resources) {
Facility facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
List<Attribute> requiredAttributes = getResourceRequiredAttributes(sess, resource, facility, resource, user, member);
boolean allOk = false;
AttributeDefinition lastWrongAttribute = null;
int safetyCounter = 0;
do {
try {
setRequiredAttributes(sess, facility, resource, user, member, requiredAttributes);
allOk = true;
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
} catch (WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
} catch (WrongAttributeValueException ex) {
if (!trueMagic)
throw ex;
AttributeDefinition wrongAttributeDefinition = ex.getAttribute();
if (wrongAttributeDefinition == null)
throw new ConsistencyErrorException("WrongAttributeValueException doesn't have set the wrong attribute.", ex);
if (wrongAttributeDefinition.equals(lastWrongAttribute))
throw new WrongAttributeValueException("Method doTheMagic can't fix this attribute value", ex);
lastWrongAttribute = wrongAttributeDefinition;
findAndSetValueInList(requiredAttributes, wrongAttributeDefinition, null);
} catch (WrongReferenceAttributeValueException ex) {
if (!trueMagic)
throw ex;
AttributeDefinition wrongAttributeDefinition = ex.getReferenceAttribute();
if (wrongAttributeDefinition == null)
throw new ConsistencyErrorException("WrongReferenceAttributeValueException doesn't have set reference attribute.", ex);
if (wrongAttributeDefinition.equals(lastWrongAttribute))
throw new WrongReferenceAttributeValueException("Method doTheMagic can't fix this attribute value", ex);
lastWrongAttribute = wrongAttributeDefinition;
if (!findAndSetValueInList(requiredAttributes, wrongAttributeDefinition, null)) {
//this attribute can't be fixed here
throw ex;
}
}
safetyCounter++;
if (safetyCounter == 50)
throw new InternalErrorException("Method doTheMagic possibly stays in infinite loop.");
} while (trueMagic && !allOk);
}
}
use of cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException in project perun by CESNET.
the class AttributesManagerBlImpl method removeAllAttributes.
public void removeAllAttributes(PerunSession sess, Facility facility, User user) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException {
List<Attribute> attributes = getAttributes(sess, facility, user);
//remove all non-virtual attributes
getAttributesManagerImpl().removeAllAttributes(sess, facility, user);
//remove all virtual attributes
List<Attribute> virtualAttributes = getVirtualAttributes(sess, facility, user);
for (Attribute attribute : virtualAttributes) {
getAttributesManagerImpl().removeVirtualAttribute(sess, facility, user, attribute);
}
attributes.addAll(virtualAttributes);
getPerunBl().getAuditer().log(sess, "All attributes removed for {} and {}", facility, user);
for (Attribute attribute : attributes) attribute.setValue(null);
try {
checkAttributesValue(sess, facility, user, attributes);
this.checkAttributesDependencies(sess, facility, user, attributes);
} catch (WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
}
for (Attribute attribute : attributes) {
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);
}
}
}
Aggregations