use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class urn_perun_resource_attribute_def_def_unixGroupName_namespace method changedAttributeHook.
@Override
public void changedAttributeHook(PerunSessionImpl session, Resource resource, Attribute attribute) throws WrongReferenceAttributeValueException {
// Need to know if this is remove or set, if value is null, its remove, otherway it is set
String groupNameNamespace = attribute.getFriendlyNameParameter();
try {
if (attribute.getValue() != null) {
// First need to find facility for the group
Facility facilityOfResource = session.getPerunBl().getResourcesManagerBl().getFacility(session, resource);
String gidNamespace = null;
// If facility has the same namespace of GroupName like attribute unixGroupName-namespace, then prepare gidNamespace
Attribute facilityGroupNameNamespace = session.getPerunBl().getAttributesManagerBl().getAttribute(session, facilityOfResource, A_F_unixGroupName_namespace);
if (facilityGroupNameNamespace.getValue() != null) {
if (groupNameNamespace.equals(facilityGroupNameNamespace.getValue())) {
Attribute facilityGIDNamespace = session.getPerunBl().getAttributesManagerBl().getAttribute(session, facilityOfResource, A_F_unixGID_namespace);
if (facilityGIDNamespace.getValue() != null) {
gidNamespace = (String) facilityGIDNamespace.getValue();
}
}
}
// If there is any gidNamespace which is need to be set, do it there
if (gidNamespace != null) {
Attribute resourceUnixGIDNamespace = session.getPerunBl().getAttributesManagerBl().getAttribute(session, resource, A_R_unixGID_namespace + ":" + gidNamespace);
if (resourceUnixGIDNamespace.getValue() == null) {
resourceUnixGIDNamespace = session.getPerunBl().getAttributesManagerBl().fillAttribute(session, resource, resourceUnixGIDNamespace);
if (resourceUnixGIDNamespace.getValue() == null)
throw new WrongReferenceAttributeValueException(attribute, resourceUnixGIDNamespace);
try {
session.getPerunBl().getAttributesManagerBl().setAttribute(session, resource, resourceUnixGIDNamespace);
} catch (WrongAttributeValueException ex) {
throw new WrongReferenceAttributeValueException(attribute, resourceUnixGIDNamespace, ex);
}
} else {
session.getPerunBl().getAttributesManagerBl().checkAttributeSemantics(session, resource, resourceUnixGIDNamespace);
}
}
}
// Attribute value can be null, for now, no changes for removing some GroupName of this Resource
} catch (WrongAttributeAssignmentException ex) {
// TODO: need to add WrongAttributeAssignmentException to header of modules methods
throw new InternalErrorException(ex);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class urn_perun_resource_attribute_def_virt_unixGID method getAttributeValue.
@Override
public Attribute getAttributeValue(PerunSessionImpl sess, Resource resource, AttributeDefinition attributeDefinition) {
Attribute attribute = new Attribute(attributeDefinition);
Attribute unixGIDNamespaceAttribute;
try {
unixGIDNamespaceAttribute = sess.getPerunBl().getModulesUtilsBl().getUnixGIDNamespaceAttributeWithNotNullValue(sess, resource);
} catch (WrongReferenceAttributeValueException ex) {
return attribute;
}
try {
Attribute gidAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, A_R_unixGID_namespace + unixGIDNamespaceAttribute.getValue());
return Utils.copyAttributeToVirtualAttributeWithValue(gidAttribute, attribute);
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException(ex);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class urn_perun_resource_attribute_def_def_fairshareGroupName method checkAttributeSemantics.
@Override
public void checkAttributeSemantics(PerunSessionImpl perunSession, Resource resource, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
// Null is ok, it means this resource is not fairshare group
if (attribute.getValue() == null) {
return;
}
String gName = attribute.valueAsString();
// On facility must be fairshare group name unique (between all resources of this facility)
Facility facility = perunSession.getPerunBl().getResourcesManagerBl().getFacility(perunSession, resource);
List<Resource> facilityResources = perunSession.getPerunBl().getFacilitiesManagerBl().getAssignedResources(perunSession, facility);
facilityResources.remove(resource);
for (Resource res : facilityResources) {
try {
Attribute resFairshareName = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, res, attribute.getName());
if (resFairshareName.getValue() != null && gName.equals(resFairshareName.valueAsString())) {
throw new WrongReferenceAttributeValueException(attribute, resFairshareName, resource, null, res, null, "This name is already taken (not unique). Choose another one.");
}
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class urn_perun_user_facility_attribute_def_virt_UID method setAttributeValue.
@Override
public boolean setAttributeValue(PerunSessionImpl sess, User user, Facility facility, Attribute attribute) throws WrongReferenceAttributeValueException {
AttributeDefinition userUidAttributeDefinition;
try {
// Get the f:uid-namespace attribute
Attribute uidNamespaceAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":uid-namespace");
if (uidNamespaceAttribute.getValue() == null) {
throw new WrongReferenceAttributeValueException(attribute, uidNamespaceAttribute);
}
userUidAttributeDefinition = sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, AttributesManager.NS_USER_ATTR_DEF + ":uid-namespace:" + uidNamespaceAttribute.getValue());
} catch (AttributeNotExistsException e) {
throw new InternalErrorException(e);
} catch (WrongAttributeAssignmentException e) {
throw new ConsistencyErrorException(e);
}
Attribute userUidAttribute = new Attribute(userUidAttributeDefinition);
userUidAttribute.setValue(attribute.getValue());
try {
return sess.getPerunBl().getAttributesManagerBl().setAttributeWithoutCheck(sess, user, userUidAttribute);
} catch (WrongAttributeValueException e) {
throw new InternalErrorException(e);
} catch (WrongAttributeAssignmentException e) {
throw new ConsistencyErrorException(e);
}
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class urn_perun_user_facility_attribute_def_virt_UID method fillAttribute.
/**
* Fills the new UID for the user at the specified facility. First empty slot
* in range (minUID, maxUID) is returned.
*/
@Override
public Attribute fillAttribute(PerunSessionImpl sess, User user, Facility facility, AttributeDefinition attribute) throws WrongAttributeAssignmentException {
try {
Attribute uidNamespaceAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":uid-namespace");
Attribute attr = new Attribute(attribute);
if (uidNamespaceAttribute.getValue() != null) {
// Get the u:uid-namespace[uidNamespaceAttribute]
Attribute uidAttribute = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":uid-namespace:" + uidNamespaceAttribute.getValue());
uidAttribute = sess.getPerunBl().getAttributesManagerBl().fillAttribute(sess, user, uidAttribute);
attr.setValue(uidAttribute.getValue());
} else {
attr.setValue(null);
}
return attr;
} catch (AttributeNotExistsException e) {
throw new ConsistencyErrorException(e);
}
}
Aggregations