use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class GroupsManagerBlImpl method setRequiredAttributes.
/**
* Set required attributes when adding new direct or indirect members.
* @param sess perun session
* @param member member
* @param group group
* @throws InternalErrorException
* @throws WrongAttributeValueException
* @throws WrongReferenceAttributeValueException
*/
private void setRequiredAttributes(PerunSession sess, Member member, Group group) throws WrongAttributeValueException, WrongReferenceAttributeValueException {
// setting required attributes
User user = getPerunBl().getUsersManagerBl().getUserByMember(sess, member);
List<Resource> resources = getPerunBl().getResourcesManagerBl().getAssignedResources(sess, group);
for (Resource resource : resources) {
Facility facility = getPerunBl().getResourcesManagerBl().getFacility(sess, resource);
// check members attributes
try {
getPerunBl().getAttributesManagerBl().setRequiredAttributes(sess, facility, resource, user, member);
} catch (WrongAttributeAssignmentException | AttributeNotExistsException | MemberResourceMismatchException ex) {
throw new ConsistencyErrorException(ex);
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class ResourcesManagerBlImpl method copyAttributes.
@Override
public void copyAttributes(PerunSession sess, Resource sourceResource, Resource destinationResource) throws WrongReferenceAttributeValueException {
List<Attribute> sourceAttributes = getPerunBl().getAttributesManagerBl().getAttributes(sess, sourceResource);
List<Attribute> destinationAttributes = getPerunBl().getAttributesManagerBl().getAttributes(sess, destinationResource);
// do not get virtual attributes from source resource, they can't be set to destination
sourceAttributes.removeIf(attribute -> attribute.getNamespace().startsWith(AttributesManager.NS_RESOURCE_ATTR_VIRT));
// create intersection of destination and source attributes
List<Attribute> intersection = new ArrayList<>(destinationAttributes);
intersection.retainAll(sourceAttributes);
try {
// delete all common attributes from destination resource
getPerunBl().getAttributesManagerBl().removeAttributes(sess, destinationResource, intersection);
// add all attributes from the source resource to the destination resource
getPerunBl().getAttributesManagerBl().setAttributes(sess, destinationResource, sourceAttributes);
} catch (WrongAttributeAssignmentException ex) {
throw new InternalErrorException("Copying of attributes failed, wrong assignment.", ex);
} catch (WrongAttributeValueException ex) {
throw new ConsistencyErrorException("Copying of attributes failed.", ex);
}
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class ModulesUtilsBlImpl method getCommonGIDOfGroupsWithSameNameInSameNamespace.
@Override
public Integer getCommonGIDOfGroupsWithSameNameInSameNamespace(PerunSessionImpl sess, List<Group> groupsWithSameGroupNameInSameNamespace, String gidNamespace, Integer commonGID) throws WrongAttributeAssignmentException {
// If there are no groups, return commonGID from param (it can be null)
if (groupsWithSameGroupNameInSameNamespace == null || groupsWithSameGroupNameInSameNamespace.isEmpty())
return commonGID;
Utils.notNull(gidNamespace, "gidNamespace");
// only for more verbose exception messages
Group commonGIDGroup = null;
for (Group g : groupsWithSameGroupNameInSameNamespace) {
try {
Attribute attr = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, g, A_G_unixGID_namespace + ":" + gidNamespace);
if (attr.getValue() != null) {
if (commonGID == null) {
commonGIDGroup = g;
commonGID = (Integer) attr.getValue();
} else {
if (!commonGID.equals(attr.getValue()))
throw new ConsistencyErrorException("There are at least 1 groups/resources with same GroupName in same namespace but with different GID in same namespaces. Conflict found: " + g + "(gid=" + attr.getValue() + ") and " + commonGIDGroup + "(gid=" + commonGID + ")");
}
}
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
}
return commonGID;
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class ModulesUtilsBlImpl method getCommonGIDOfResourcesWithSameNameInSameNamespace.
@Override
public Integer getCommonGIDOfResourcesWithSameNameInSameNamespace(PerunSessionImpl sess, List<Resource> resourcesWithSameGroupNameInSameNamespace, String gidNamespace, Integer commonGID) throws WrongAttributeAssignmentException {
// If there are no resources, return commonGID from param (it can be null)
if (resourcesWithSameGroupNameInSameNamespace == null || resourcesWithSameGroupNameInSameNamespace.isEmpty())
return commonGID;
Utils.notNull(gidNamespace, "gidNamespace");
// only for more verbose exception messages
Resource commonGIDResource = null;
for (Resource r : resourcesWithSameGroupNameInSameNamespace) {
try {
Attribute attr = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, r, A_R_unixGID_namespace + ":" + gidNamespace);
if (attr.getValue() != null) {
if (commonGID == null) {
commonGIDResource = r;
commonGID = (Integer) attr.getValue();
} else {
if (!commonGID.equals(attr.getValue()))
throw new ConsistencyErrorException("There are at least 1 groups/resources with same GroupName in same namespace but with different GID in same namespaces. Conflict found: " + r + "(gid=" + attr.getValue() + ") and " + commonGIDResource + "(gid=" + commonGID + ")");
}
}
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException(ex);
}
}
return commonGID;
}
use of cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException in project perun by CESNET.
the class AttributesManagerBlImpl method removeAllAttributes.
@Override
public void removeAllAttributes(PerunSession sess, Facility facility, boolean removeAlsoUserFacilityAttributes) throws WrongAttributeValueException, WrongReferenceAttributeValueException {
removeAllAttributes(sess, facility);
if (removeAlsoUserFacilityAttributes) {
List<Attribute> userFacilityAttributes = getUserFacilityAttributesForAnyUser(sess, facility);
if (getAttributesManagerImpl().removeAllUserFacilityAttributesForAnyUser(sess, facility)) {
getPerunBl().getAuditer().log(sess, new AllUserFacilityAttributesRemoved(facility));
}
log.info("{} removed all attributes from any user on facility {}.", sess.getLogId(), facility.getId());
for (Attribute attribute : userFacilityAttributes) attribute.setValue(null);
List<User> facilityUsers = perunBl.getFacilitiesManagerBl().getAllowedUsers(sess, facility);
for (User user : facilityUsers) {
try {
checkAttributesSemantics(sess, facility, user, userFacilityAttributes);
checkAttributesDependencies(sess, facility, user, userFacilityAttributes);
} catch (WrongAttributeAssignmentException ex) {
throw new ConsistencyErrorException(ex);
}
for (Attribute attribute : userFacilityAttributes) {
getAttributesManagerImpl().changedAttributeHook(sess, facility, user, new Attribute(attribute));
}
}
}
}
Aggregations