Search in sources :

Example 86 with Attribute

use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.

the class GroupsManagerBlImpl method isThisLightweightSynchronization.

/**
 * Return true if attribute group:lightweightSynchronization is set to true.
 * False if not.
 *
 * True means: we don't want to update existing members (attributes, statuses etc.), just
 * add new members and remove former members
 * False means: we want to do whole synchronization process including updating operations
 *
 * @param sess
 * @param group to be synchronized
 *
 * @return true if this is lightweightSynchronization, false if not
 *
 * @throws InternalErrorException if something happens while getting lightweightSynchronization attribute
 * @throws WrongAttributeAssignmentException if bad assignment of lightweightSynchronization attribute
 * @throws AttributeNotExistsException if lightweightSynchronization attribute not exists in perun Database
 */
private boolean isThisLightweightSynchronization(PerunSession sess, Group group) throws WrongAttributeAssignmentException, AttributeNotExistsException {
    Attribute lightweightSynchronzationAttr = getPerunBl().getAttributesManagerBl().getAttribute(sess, group, GroupsManager.GROUPLIGHTWEIGHTSYNCHRONIZATION_ATTRNAME);
    boolean lightweightSynchronization = false;
    if (lightweightSynchronzationAttr != null && lightweightSynchronzationAttr.getValue() != null) {
        lightweightSynchronization = (Boolean) lightweightSynchronzationAttr.getValue();
    }
    return lightweightSynchronization;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute)

Example 87 with Attribute

use of cz.metacentrum.perun.core.api.Attribute 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);
    }
}
Also used : ConsistencyErrorException(cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)

Example 88 with Attribute

use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.

the class ModulesUtilsBlImpl method findCollisionResourcesWithSameGroupName.

public List<Resource> findCollisionResourcesWithSameGroupName(PerunSessionImpl sess, Group group, String namespace) throws WrongAttributeAssignmentException, AttributeNotExistsException {
    Utils.notNull(sess, "perunSessionImpl");
    Utils.notNull(group, "group");
    Utils.notNull(namespace, "namespace");
    Attribute groupUnixGroupName = getPerunBl().getAttributesManagerBl().getAttribute(sess, group, A_G_unixGroupName_namespace + ":" + namespace);
    Attribute copyResourceUnixGroupName = new Attribute(getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, A_R_unixGroupName_namespace + ":" + namespace));
    copyResourceUnixGroupName.setValue(groupUnixGroupName.getValue());
    return getPerunBl().getResourcesManagerBl().getResourcesByAttribute(sess, copyResourceUnixGroupName);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute)

Example 89 with Attribute

use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.

the class ModulesUtilsBlImpl method findCollisionResourcesWithSameGid.

public List<Resource> findCollisionResourcesWithSameGid(PerunSessionImpl sess, Group group, String namespace) throws WrongAttributeAssignmentException, AttributeNotExistsException {
    Utils.notNull(sess, "perunSessionImpl");
    Utils.notNull(group, "group");
    Utils.notNull(namespace, "namespace");
    Attribute groupUnixGid = getPerunBl().getAttributesManagerBl().getAttribute(sess, group, A_G_unixGID_namespace + ":" + namespace);
    Attribute copyResourceUnixGid = new Attribute(getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, A_R_unixGID_namespace + ":" + namespace));
    copyResourceUnixGid.setValue(groupUnixGid.getValue());
    return getPerunBl().getResourcesManagerBl().getResourcesByAttribute(sess, copyResourceUnixGid);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute)

Example 90 with Attribute

use of cz.metacentrum.perun.core.api.Attribute in project perun by CESNET.

the class ModulesUtilsBlImpl method getListOfResourceGIDsFromListOfGroupGIDs.

@Override
public List<Attribute> getListOfResourceGIDsFromListOfGroupGIDs(PerunSessionImpl sess, List<Attribute> groupGIDs) throws AttributeNotExistsException {
    List<Attribute> resourceGIDs = new ArrayList<>();
    if (groupGIDs == null || groupGIDs.isEmpty()) {
        return resourceGIDs;
    }
    for (Attribute a : groupGIDs) {
        Attribute resourceGID = new Attribute(sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, A_R_unixGID_namespace + ":" + a.getFriendlyNameParameter()));
        resourceGID.setValue(a.getValue());
        resourceGIDs.add(resourceGID);
    }
    return resourceGIDs;
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) ArrayList(java.util.ArrayList)

Aggregations

Attribute (cz.metacentrum.perun.core.api.Attribute)1689 Test (org.junit.Test)615 ArrayList (java.util.ArrayList)492 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)489 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)478 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)313 User (cz.metacentrum.perun.core.api.User)301 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)280 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)231 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)221 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)218 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)197 Facility (cz.metacentrum.perun.core.api.Facility)190 Resource (cz.metacentrum.perun.core.api.Resource)187 PerunSessionImpl (cz.metacentrum.perun.core.impl.PerunSessionImpl)180 List (java.util.List)177 LinkedHashMap (java.util.LinkedHashMap)158 Before (org.junit.Before)156 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)145 Method (java.lang.reflect.Method)140