use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class AttributesManagerBlImpl method fillAttributes.
public List<Attribute> fillAttributes(PerunSession sess, Resource resource, Group group, List<Attribute> attributes) throws InternalErrorException, WrongAttributeAssignmentException {
this.checkGroupIsFromTheSameVoLikeResource(sess, group, resource);
getAttributesManagerImpl().checkNamespace(sess, attributes, AttributesManager.NS_GROUP_RESOURCE_ATTR);
List<Attribute> filledAttributes = new ArrayList<Attribute>();
for (Attribute attribute : attributes) {
if (attribute.getValue() == null) {
filledAttributes.add(getAttributesManagerImpl().fillAttribute(sess, resource, group, attribute));
} else {
//skip non-empty attribute
filledAttributes.add(attribute);
}
}
return filledAttributes;
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class AttributesManagerBlImpl method getAttributeById.
public Attribute getAttributeById(PerunSession sess, Facility facility, int id) throws InternalErrorException, AttributeNotExistsException, WrongAttributeAssignmentException {
Attribute attribute = getAttributesManagerImpl().getAttributeById(sess, facility, id);
getAttributesManagerImpl().checkNamespace(sess, attribute, NS_FACILITY_ATTR);
return attribute;
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class AttributesManagerBlImpl method removeAllAttributes.
public void removeAllAttributes(PerunSession sess, Host host) throws InternalErrorException, WrongAttributeValueException {
List<Attribute> attributes = getAttributes(sess, host);
getAttributesManagerImpl().removeAllAttributes(sess, host);
getPerunBl().getAuditer().log(sess, "All attributes removed for {}", host);
for (Attribute attribute : attributes) attribute.setValue(null);
try {
checkAttributesValue(sess, host, attributes);
this.checkAttributesDependencies(sess, host, null, attributes);
} catch (WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
} catch (WrongReferenceAttributeValueException ex) {
throw new WrongAttributeValueException(ex);
}
//TODO HOOK FOR HOSTS
/*
for(Attribute attribute: attributes) {
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);
}
}*/
}
use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.
the class AttributesManagerBlImpl method fillAttributes.
public List<Attribute> fillAttributes(PerunSession sess, Group group, List<Attribute> groupReqAttributes) throws InternalErrorException, WrongAttributeAssignmentException {
getAttributesManagerImpl().checkNamespace(sess, groupReqAttributes, AttributesManager.NS_GROUP_ATTR);
List<Attribute> filledAttributes = new ArrayList<Attribute>();
for (Attribute attribute : groupReqAttributes) {
if (attribute.getValue() == null) {
filledAttributes.add(getAttributesManagerImpl().fillAttribute(sess, group, attribute));
} else {
//skip non-empty attribute
filledAttributes.add(attribute);
}
}
return filledAttributes;
}
use of cz.metacentrum.perun.core.api.Attribute 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);
}
Aggregations