use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class AttributesManagerBlImpl method setAttributes.
public void setAttributes(PerunSession sess, Resource resource, Member member, List<Attribute> attributes, boolean workWithUserAttributes) 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, resource, member, attributesToRemove, workWithUserAttributes);
//fist we have to store attributes into DB because checkAttributesValue can be preformed only on stored attributes.
if (!workWithUserAttributes) {
long timer = Utils.startTimer();
for (Attribute attribute : attributesToSet) {
//skip core attributes
if (!getAttributesManagerImpl().isCoreAttribute(sess, attribute)) {
setAttributeWithoutCheck(sess, resource, member, attribute, false);
}
}
log.debug("addMember timer: setAttributes (for(Attribute attribute : attributes)) [{}].", Utils.getRunningTime(timer));
} else {
long timer = Utils.startTimer();
Facility facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
log.debug("addMember timer: getFacility and User [{}].", Utils.getRunningTime(timer));
for (Attribute attribute : attributesToSet) {
boolean changed = false;
//skip core attributes
if (!getAttributesManagerImpl().isCoreAttribute(sess, attribute)) {
if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_RESOURCE_ATTR)) {
timer = Utils.startTimer();
changed = setAttributeWithoutCheck(sess, resource, member, attribute, false);
if (changed) {
log.debug("addMember timer: setAttribute rm [{}] [{}].", attribute, Utils.getRunningTime(timer));
}
} else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_FACILITY_ATTR)) {
timer = Utils.startTimer();
changed = setAttributeWithoutCheck(sess, facility, user, attribute);
if (changed) {
log.debug("addMember timer: setAttribute uf [{}] [{}].", attribute, Utils.getRunningTime(timer));
}
} else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_USER_ATTR)) {
timer = Utils.startTimer();
changed = setAttributeWithoutCheck(sess, user, attribute);
if (changed) {
log.debug("addMember timer: setAttribute u [{}] [{}].", attribute, Utils.getRunningTime(timer));
}
} else if (getAttributesManagerImpl().isFromNamespace(sess, attribute, AttributesManager.NS_MEMBER_ATTR)) {
timer = Utils.startTimer();
changed = setAttributeWithoutCheck(sess, member, attribute);
if (changed) {
log.debug("addMember timer: setAttribute m [{}] [{}].", attribute, Utils.getRunningTime(timer));
}
} else {
throw new WrongAttributeAssignmentException(attribute);
}
}
}
}
//if checkAttributesValue fails it causes rollback so no attribute will be stored
checkAttributesValue(sess, resource, member, attributesToSet, workWithUserAttributes);
this.checkAttributesDependencies(sess, resource, member, attributesToSet, workWithUserAttributes);
}
use of cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException in project perun by CESNET.
the class AttributesManagerBlImpl method setAttributeWithoutCheck.
public boolean setAttributeWithoutCheck(PerunSession sess, User user, Attribute attribute) throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
getAttributesManagerImpl().checkNamespace(sess, attribute, AttributesManager.NS_USER_ATTR);
if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
throw new WrongAttributeAssignmentException(attribute);
boolean changed = true;
if (isVirtAttribute(sess, attribute)) {
return getAttributesManagerImpl().setVirtualAttribute(sess, user, attribute);
} else {
changed = getAttributesManagerImpl().setAttribute(sess, user, attribute);
}
if (changed) {
getPerunBl().getAuditer().log(sess, "{} set for {}.", attribute, user);
getAttributesManagerImpl().changedAttributeHook(sess, user, 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, Resource resource, Group group, Attribute attribute) throws InternalErrorException, WrongAttributeAssignmentException, WrongAttributeValueException, WrongReferenceAttributeValueException {
this.checkGroupIsFromTheSameVoLikeResource(sess, group, resource);
getAttributesManagerImpl().checkNamespace(sess, attribute, AttributesManager.NS_GROUP_RESOURCE_ATTR);
if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
throw new WrongAttributeAssignmentException(attribute);
boolean changed = true;
if (isVirtAttribute(sess, attribute)) {
//FIXME Zatim je zakazane nastavovani virtualnich atributu group_resource
Attribute storedAttribute;
try {
storedAttribute = getAttribute(sess, resource, group, attribute.getName());
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
if (!(storedAttribute.getValue() == null ? attribute.getValue() == null : storedAttribute.getValue().equals(attribute.getValue()))) {
//FIXME
if (attribute.getName().equals(AttributesManager.NS_GROUP_RESOURCE_ATTR_VIRT + ":unixGID") || attribute.getName().equals(AttributesManager.NS_GROUP_RESOURCE_ATTR_VIRT + ":unixGroupName")) {
return getAttributesManagerImpl().setVirtualAttribute(sess, resource, group, attribute);
} else {
throw new InternalErrorException("Virtual attribute can't be set this way yet. Please set physical attribute. " + attribute);
}
} else {
return false;
}
} else {
changed = getAttributesManagerImpl().setAttribute(sess, resource, group, attribute);
}
if (changed) {
getPerunBl().getAuditer().log(sess, "{} set for {} and {}.", attribute, group, resource);
getAttributesManagerImpl().changedAttributeHook(sess, resource, group, attribute);
}
return changed;
}
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) throws InternalErrorException, WrongAttributeValueException, WrongReferenceAttributeValueException {
List<Attribute> attributes = getAttributes(sess, resource);
getAttributesManagerImpl().removeAllAttributes(sess, resource);
//remove all virtual attributes
/*for(Attribute attribute : getVirtualAttributes(sess, resource)) {
getAttributesManagerImpl().removeVirtualAttribute(sess, resource, attribute);
}*/
getPerunBl().getAuditer().log(sess, "All attributes removed for {}", resource);
for (Attribute attribute : attributes) attribute.setValue(null);
try {
checkAttributesValue(sess, resource, attributes);
this.checkAttributesDependencies(sess, resource, null, attributes);
} catch (WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
}
for (Attribute attribute : attributes) {
try {
getAttributesManagerImpl().changedAttributeHook(sess, resource, 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 removeAttributeWithoutCheck.
public boolean removeAttributeWithoutCheck(PerunSession sess, Host host, AttributeDefinition attribute) throws InternalErrorException, WrongAttributeAssignmentException {
getAttributesManagerImpl().checkNamespace(sess, attribute, AttributesManager.NS_HOST_ATTR);
if (getAttributesManagerImpl().isCoreAttribute(sess, attribute))
throw new WrongAttributeAssignmentException(attribute);
boolean changed = getAttributesManagerImpl().removeAttribute(sess, host, attribute);
if (changed) {
//TODO HOOK FOR HOSTS!
/*try {
getAttributesManagerImpl().changedAttributeHook(sess, host, 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, host);
}
return changed;
}
Aggregations