Search in sources :

Example 11 with GroupResourceMismatchException

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
        }
    }
}
Also used : Resource(cz.metacentrum.perun.core.api.Resource) PerunSession(cz.metacentrum.perun.core.api.PerunSession) Logger(org.slf4j.Logger) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) LoggerFactory(org.slf4j.LoggerFactory) Scheduled(org.springframework.scheduling.annotation.Scheduled) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) Collectors(java.util.stream.Collectors) Group(cz.metacentrum.perun.core.api.Group) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) List(java.util.List) ExtSourcesManager(cz.metacentrum.perun.core.api.ExtSourcesManager) PerunClient(cz.metacentrum.perun.core.api.PerunClient) GroupAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException) GroupAlreadyRemovedFromResourceException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyRemovedFromResourceException) AssignedGroup(cz.metacentrum.perun.core.api.AssignedGroup) PerunPrincipal(cz.metacentrum.perun.core.api.PerunPrincipal) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) GroupNotDefinedOnResourceException(cz.metacentrum.perun.core.api.exceptions.GroupNotDefinedOnResourceException) Group(cz.metacentrum.perun.core.api.Group) AssignedGroup(cz.metacentrum.perun.core.api.AssignedGroup) GroupAlreadyAssignedException(cz.metacentrum.perun.core.api.exceptions.GroupAlreadyAssignedException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 12 with GroupResourceMismatchException

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);
        }
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)

Example 13 with GroupResourceMismatchException

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);
    }
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)

Example 14 with GroupResourceMismatchException

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);
        }
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) BigDecimal(java.math.BigDecimal)

Example 15 with GroupResourceMismatchException

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);
        }
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) GroupResourceMismatchException(cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException) BigDecimal(java.math.BigDecimal)

Aggregations

GroupResourceMismatchException (cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException)43 Attribute (cz.metacentrum.perun.core.api.Attribute)29 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)20 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)18 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)15 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)13 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)12 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)12 Group (cz.metacentrum.perun.core.api.Group)11 Facility (cz.metacentrum.perun.core.api.Facility)9 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)8 Resource (cz.metacentrum.perun.core.api.Resource)7 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)6 AssignedGroup (cz.metacentrum.perun.core.api.AssignedGroup)5 AssignedResource (cz.metacentrum.perun.core.api.AssignedResource)5 Member (cz.metacentrum.perun.core.api.Member)5 Service (cz.metacentrum.perun.core.api.Service)5 ArrayList (java.util.ArrayList)5 GroupAssignedToResource (cz.metacentrum.perun.audit.events.ResourceManagerEvents.GroupAssignedToResource)4 User (cz.metacentrum.perun.core.api.User)4