use of cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException in project perun by CESNET.
the class ResourceAssignmentChecker method assignSubgroupsToResource.
/**
* Filter subgroups of source group (with autoassign) which are not assigned and assign them.
* Runs in transaction.
* @param resource
* @param automaticallyAssignedSubgroups
* @param sourceGroup
*/
public void assignSubgroupsToResource(Resource resource, List<AssignedGroup> automaticallyAssignedSubgroups, AssignedGroup sourceGroup) {
List<Group> sourceGroupSubgroups = perunBl.getGroupsManagerBl().getAllSubGroups(sess, sourceGroup.getEnrichedGroup().getGroup());
sourceGroupSubgroups = sourceGroupSubgroups.stream().filter(sourceSubgroup -> automaticallyAssignedSubgroups.stream().noneMatch(assignedSubgroup -> assignedSubgroup.getSourceGroupId() == sourceGroup.getEnrichedGroup().getGroup().getId() && assignedSubgroup.getEnrichedGroup().getGroup().equals(sourceSubgroup))).collect(Collectors.toList());
for (Group subgroup : sourceGroupSubgroups) {
try {
perunBl.getResourcesManagerBl().assignAutomaticGroupToResource(sess, sourceGroup.getEnrichedGroup().getGroup(), subgroup, resource);
} catch (GroupResourceMismatchException e) {
log.error("Cannot activate group (id = " + subgroup.getId() + ") assignment on resource " + resource, e);
} catch (GroupAlreadyAssignedException | WrongReferenceAttributeValueException | WrongAttributeValueException e) {
// silently skip
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_def_isSystemUnixGroup method checkAttributeSemantics.
@Override
public void checkAttributeSemantics(PerunSessionImpl sess, Group group, Resource resource, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
Integer isSystemUnixGroup = attribute.valueAsInteger();
// isSystemUnixGroup can be null. It is equivalent to 0.
if (isSystemUnixGroup == null)
return;
Attribute sysUnixGroupName;
Attribute sysUnixGID;
if (isSystemUnixGroup == 1) {
try {
sysUnixGroupName = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, group, A_GR_systemUnixGroupName);
sysUnixGID = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, group, A_GR_systemUnixGID);
} catch (AttributeNotExistsException ex) {
// if any of these attributes not exist, its wrong
throw new ConsistencyErrorException("Attributes sysUnixGroupName or sysUnixGID not exist.", ex);
} catch (GroupResourceMismatchException ex) {
throw new InternalErrorException(ex);
}
try {
sess.getPerunBl().getAttributesManagerBl().checkAttributeSemantics(sess, resource, group, sysUnixGroupName);
} catch (GroupResourceMismatchException ex) {
throw new InternalErrorException(ex);
}
try {
sess.getPerunBl().getAttributesManagerBl().checkAttributeSemantics(sess, resource, group, sysUnixGID);
} catch (GroupResourceMismatchException ex) {
throw new InternalErrorException(ex);
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_def_o365EmailAddresses_mu method fillAttribute.
/**
* Prefills value created by joining value of urn:perun:group_resource:attribute-def:def:adName with "@group.muni.cz"
*/
@Override
public Attribute fillAttribute(PerunSessionImpl sess, Group group, Resource resource, AttributeDefinition attrDef) throws WrongAttributeAssignmentException {
if (!NAMESPACE.equals(attrDef.getNamespace()))
throw new WrongAttributeAssignmentException(attrDef);
try {
Attribute result = new Attribute(attrDef);
Object adName = sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, resource, group, ADNAME_ATTRIBUTE).getValue();
if (adName != null && adName instanceof String) {
result.setValue(Lists.newArrayList(adName + "@group.muni.cz"));
}
return result;
} catch (GroupResourceMismatchException | AttributeNotExistsException e) {
throw new InternalErrorException(e.getMessage(), e);
}
}
use of cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_def_projectDataQuota method checkAttributeSemantics.
@Override
public void checkAttributeSemantics(PerunSessionImpl perunSession, Group group, Resource resource, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
Attribute attrProjectDataLimit;
String projectDataLimit = null;
// Get ProjectDataQuota value
Pair<BigDecimal, String> quotaNumberAndLetter = ModulesUtilsBlImpl.getNumberAndUnitFromString(attribute.valueAsString());
BigDecimal quotaNumber = quotaNumberAndLetter.getLeft();
String projectDataQuotaLetter = quotaNumberAndLetter.getRight();
// Get ProjectDataLimit attribute
try {
attrProjectDataLimit = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, resource, group, A_GR_projectDataLimit);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Attribute with projectDataLimit from resource " + resource.getId() + " and group " + group.getId() + " could not obtain.", ex);
} catch (GroupResourceMismatchException ex) {
throw new InternalErrorException(ex);
}
if (attrProjectDataLimit != null)
projectDataLimit = attrProjectDataLimit.valueAsString();
// Get ProjectDataLimit value
Pair<BigDecimal, String> limitNumberAndLetter = ModulesUtilsBlImpl.getNumberAndUnitFromString(projectDataLimit);
BigDecimal limitNumber = limitNumberAndLetter.getLeft();
String projectDataLimitLetter = limitNumberAndLetter.getRight();
if (limitNumber.compareTo(BigDecimal.valueOf(0)) < 0) {
throw new WrongReferenceAttributeValueException(attribute, attrProjectDataLimit, attrProjectDataLimit + " cant be less than 0.");
}
// Compare ProjectDataQuota with ProjectDataLimit
if (quotaNumber.compareTo(BigDecimal.valueOf(0)) == 0) {
if (limitNumber.compareTo(BigDecimal.valueOf(0)) != 0) {
throw new WrongReferenceAttributeValueException(attribute, attrProjectDataLimit, "Try to set unlimited quota, but limit is still " + limitNumber + projectDataLimitLetter);
}
} else if (limitNumber.compareTo(BigDecimal.valueOf(0)) != 0 && projectDataLimitLetter != null && projectDataQuotaLetter != null) {
switch(projectDataLimitLetter) {
case "K":
limitNumber = limitNumber.multiply(BigDecimal.valueOf(K));
break;
case "M":
limitNumber = limitNumber.multiply(BigDecimal.valueOf(M));
break;
case "T":
limitNumber = limitNumber.multiply(BigDecimal.valueOf(T));
break;
case "P":
limitNumber = limitNumber.multiply(BigDecimal.valueOf(P));
break;
case "E":
limitNumber = limitNumber.multiply(BigDecimal.valueOf(E));
break;
default:
limitNumber = limitNumber.multiply(BigDecimal.valueOf(G));
break;
}
switch(projectDataQuotaLetter) {
case "K":
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(K));
break;
case "M":
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(M));
break;
case "T":
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(T));
break;
case "P":
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(P));
break;
case "E":
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(E));
break;
default:
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(G));
break;
}
if (limitNumber.compareTo(quotaNumber) < 0) {
throw new WrongReferenceAttributeValueException(attribute, attrProjectDataLimit, attribute + " must be less than or equals to " + projectDataLimit);
}
}
}
use of cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException in project perun by CESNET.
the class urn_perun_group_resource_attribute_def_def_projectDataLimit method checkAttributeSemantics.
@Override
public void checkAttributeSemantics(PerunSessionImpl perunSession, Group group, Resource resource, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
Attribute attrProjectDataQuota;
String projectDataQuota = null;
// Check if attribute value has the right exp pattern (can be null)
if (attribute.getValue() == null)
return;
// Get ProjectDataLimit value
Pair<BigDecimal, String> limitNumberAndLetter = ModulesUtilsBlImpl.getNumberAndUnitFromString(attribute.valueAsString());
BigDecimal limitNumber = limitNumberAndLetter.getLeft();
String projectDataLimitLetter = limitNumberAndLetter.getRight();
// Get ProjectDataQuota attribute
try {
attrProjectDataQuota = perunSession.getPerunBl().getAttributesManagerBl().getAttribute(perunSession, resource, group, A_GR_projectDataQuota);
} catch (AttributeNotExistsException ex) {
throw new ConsistencyErrorException("Attribute with projectDataQuota from resource " + resource.getId() + " and group + " + group.getId() + " could not obtain.", ex);
} catch (GroupResourceMismatchException ex) {
throw new InternalErrorException(ex);
}
if (attrProjectDataQuota != null)
projectDataQuota = attrProjectDataQuota.valueAsString();
// Get ProjectDataQuota value
Pair<BigDecimal, String> quotaNumberAndLetter = ModulesUtilsBlImpl.getNumberAndUnitFromString(projectDataQuota);
BigDecimal quotaNumber = quotaNumberAndLetter.getLeft();
String projectDataQuotaLetter = quotaNumberAndLetter.getRight();
if (quotaNumber.compareTo(BigDecimal.valueOf(0)) < 0) {
throw new WrongReferenceAttributeValueException(attribute, attrProjectDataQuota, attrProjectDataQuota + " cant be less than 0.");
}
// Compare ProjectDataLimit with ProjectDataQuota
if (quotaNumber.compareTo(BigDecimal.valueOf(0)) == 0) {
if (limitNumber.compareTo(BigDecimal.valueOf(0)) != 0) {
throw new WrongReferenceAttributeValueException(attribute, attrProjectDataQuota, "Try to set limited limit, but there is still set unlimited Quota.");
}
} else if ((quotaNumber.compareTo(BigDecimal.valueOf(0)) != 0) && (limitNumber.compareTo(BigDecimal.valueOf(0)) != 0) && projectDataQuotaLetter != null) {
switch(projectDataLimitLetter) {
case "K":
limitNumber = limitNumber.multiply(BigDecimal.valueOf(K));
break;
case "M":
limitNumber = limitNumber.multiply(BigDecimal.valueOf(M));
break;
case "T":
limitNumber = limitNumber.multiply(BigDecimal.valueOf(T));
break;
case "P":
limitNumber = limitNumber.multiply(BigDecimal.valueOf(P));
break;
case "E":
limitNumber = limitNumber.multiply(BigDecimal.valueOf(E));
break;
default:
limitNumber = limitNumber.multiply(BigDecimal.valueOf(G));
break;
}
switch(projectDataQuotaLetter) {
case "K":
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(K));
break;
case "M":
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(M));
break;
case "T":
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(T));
break;
case "P":
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(P));
break;
case "E":
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(E));
break;
default:
quotaNumber = quotaNumber.multiply(BigDecimal.valueOf(G));
break;
}
if (limitNumber.compareTo(quotaNumber) < 0) {
throw new WrongReferenceAttributeValueException(attribute, attrProjectDataQuota, group, resource, group, resource, attribute + " must be more than or equals to " + attrProjectDataQuota);
}
}
}
Aggregations