Search in sources :

Example 51 with AttributesManagerBl

use of cz.metacentrum.perun.core.bl.AttributesManagerBl in project perun by CESNET.

the class urn_perun_group_attribute_def_def_o365EmailAddresses_o365mu method checkAttributeSemantics.

@Override
public void checkAttributeSemantics(PerunSessionImpl sess, Group group, Attribute attribute) throws WrongReferenceAttributeValueException, WrongAttributeAssignmentException {
    List<String> emails = attribute.valueAsList();
    if (emails == null)
        emails = new ArrayList<>();
    // at least one value if adName is set
    AttributesManagerBl am = sess.getPerunBl().getAttributesManagerBl();
    try {
        if (emails.isEmpty()) {
            Attribute adName = am.getAttribute(sess, group, ADNAME_ATTRIBUTE);
            if (adName.getValue() != null) {
                throw new WrongReferenceAttributeValueException(attribute, adName, group, null, group, null, "at least one email must be defined");
            }
            return;
        }
    } catch (AttributeNotExistsException e) {
        throw new InternalErrorException(e.getMessage(), e);
    }
    // check for duplicities among users attributes and this one
    try {
        AttributesManagerBl attributesManagerBl = sess.getPerunBl().getAttributesManagerBl();
        Attribute userO365EmailAddresses = new Attribute(sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, USER_O365EMAIL_ADDRESSES_MU_ATTRIBUTE));
        userO365EmailAddresses.setValue(emails);
        Set<Pair<Integer, Integer>> usersPairs = attributesManagerBl.getPerunBeanIdsForUniqueAttributeValue(sess, userO365EmailAddresses);
        if (!usersPairs.isEmpty()) {
            throw new WrongReferenceAttributeValueException(attribute, userO365EmailAddresses, group, null, "member " + BeansUtils.getSingleId(usersPairs) + " ");
        }
    } catch (AttributeNotExistsException ex) {
        // If attribute not exists, we can log it and skip it, because there are no duplicates in not existing attributes
        log.debug("Attribute {} not exists to check duplicities in it while checkAttributeSemantics for {}.", USER_O365EMAIL_ADDRESSES_MU_ATTRIBUTE, attribute);
    }
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) ArrayList(java.util.ArrayList) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl) Pair(cz.metacentrum.perun.core.api.Pair)

Example 52 with AttributesManagerBl

use of cz.metacentrum.perun.core.bl.AttributesManagerBl in project perun by CESNET.

the class urn_perun_user_facility_attribute_def_virt_preferredUnixGroupNameTest method setUp.

@Before
public void setUp() throws Exception {
    classInstance = new urn_perun_user_facility_attribute_def_virt_preferredUnixGroupName();
    attributeToCheck = new Attribute();
    facilityGroupNameNamespace = new Attribute();
    facilityGroupNameNamespace.setValue("facility_group_namespace");
    preferredUnixGroupName = new Attribute();
    preferredUnixGroupName.setValue("preferred_unix_group_name");
    sess = mock(PerunSessionImpl.class);
    PerunBl perunBl = mock(PerunBl.class);
    when(sess.getPerunBl()).thenReturn(perunBl);
    AttributesManagerBl attributesManagerBl = mock(AttributesManagerBl.class);
    when(sess.getPerunBl().getAttributesManagerBl()).thenReturn(attributesManagerBl);
    when(attributesManagerBl.getAttribute(sess, facility, AttributesManager.NS_FACILITY_ATTR_DEF + ":unixGroupName-namespace")).thenReturn(facilityGroupNameNamespace);
    when(attributesManagerBl.getAttribute(sess, user, AttributesManager.NS_USER_ATTR_DEF + ":preferredUnixGroupName-namespace:" + facilityGroupNameNamespace.valueAsString())).thenReturn(preferredUnixGroupName);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl) Before(org.junit.Before)

Example 53 with AttributesManagerBl

use of cz.metacentrum.perun.core.bl.AttributesManagerBl in project perun by CESNET.

the class urn_perun_user_attribute_def_def_vsupMailTest method setUp.

@Before
public void setUp() throws Exception {
    classInstance = new urn_perun_user_attribute_def_def_vsupMail();
    session = mock(PerunSessionImpl.class);
    user = new User(0, "John", "Doe", "", "", "");
    attributeToCheck = new Attribute();
    reqAttribute = new Attribute();
    PerunBl perunBl = mock(PerunBl.class);
    when(session.getPerunBl()).thenReturn(perunBl);
    AttributesManagerBl attributesManagerBl = mock(AttributesManagerBl.class);
    when(session.getPerunBl().getAttributesManagerBl()).thenReturn(attributesManagerBl);
    when(session.getPerunBl().getAttributesManagerBl().getAttribute(session, user, AttributesManager.NS_USER_ATTR_DEF + ":login-namespace:vsup")).thenReturn(reqAttribute);
}
Also used : User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl) Before(org.junit.Before)

Example 54 with AttributesManagerBl

use of cz.metacentrum.perun.core.bl.AttributesManagerBl in project perun by CESNET.

the class urn_perun_user_attribute_def_virt_associatedUsersMailsTest method setUp.

@Before
public void setUp() throws Exception {
    sess = mock(PerunSessionImpl.class);
    PerunBl perunBl = mock(PerunBl.class);
    AttributesManagerBl attributesManagerBl = mock(AttributesManagerBl.class);
    UsersManagerBl usersManagerBl = mock(UsersManagerBl.class);
    when(sess.getPerunBl()).thenReturn(perunBl);
    when(perunBl.getAttributesManagerBl()).thenReturn(attributesManagerBl);
    when(perunBl.getUsersManagerBl()).thenReturn(usersManagerBl);
    when(sess.getPerunBl().getUsersManagerBl().getUsersBySpecificUser(sess, specificUser)).thenReturn(Arrays.asList(user1, user2));
    when(sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user1, A_U_D_preferredMail)).thenReturn(user1MailAttribute);
    when(sess.getPerunBl().getAttributesManagerBl().getAttribute(sess, user2, A_U_D_preferredMail)).thenReturn(user2MailAttribute);
}
Also used : PerunBl(cz.metacentrum.perun.core.bl.PerunBl) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) UsersManagerBl(cz.metacentrum.perun.core.bl.UsersManagerBl) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl) Before(org.junit.Before)

Example 55 with AttributesManagerBl

use of cz.metacentrum.perun.core.bl.AttributesManagerBl in project perun by CESNET.

the class urn_perun_user_attribute_def_virt_tcsMails_muTest method setUp.

@Before
public void setUp() throws Exception {
    tcsMailsAttrDef.setId(100);
    // prepare mocks
    sess = mock(PerunSessionImpl.class);
    PerunBl perunBl = mock(PerunBl.class);
    AttributesManagerBl am = mock(AttributesManagerBl.class);
    UsersManagerBl um = mock(UsersManagerBl.class);
    when(sess.getPerunBl()).thenReturn(perunBl);
    when(perunBl.getAttributesManagerBl()).thenReturn(am);
    when(perunBl.getUsersManagerBl()).thenReturn(um);
    when(sess.getPerunBl().getAttributesManagerBl().getAttributes(sess, user, Arrays.asList(preferredMailAttr.getName(), isMailAttr.getName(), o365MailsAttr.getName(), publicMailsAttr.getName(), privateMailsAttr.getName()))).thenReturn(Arrays.asList(preferredMailAttr, isMailAttr, o365MailsAttr, publicMailsAttr, privateMailsAttr));
    when(sess.getPerunBl().getAttributesManagerBl().getAttributeDefinition(sess, tcsMailsAttrDef.getName())).thenReturn(tcsMailsAttrDef);
}
Also used : PerunBl(cz.metacentrum.perun.core.bl.PerunBl) PerunSessionImpl(cz.metacentrum.perun.core.impl.PerunSessionImpl) UsersManagerBl(cz.metacentrum.perun.core.bl.UsersManagerBl) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl) Before(org.junit.Before)

Aggregations

AttributesManagerBl (cz.metacentrum.perun.core.bl.AttributesManagerBl)56 Attribute (cz.metacentrum.perun.core.api.Attribute)48 PerunBl (cz.metacentrum.perun.core.bl.PerunBl)44 PerunSessionImpl (cz.metacentrum.perun.core.impl.PerunSessionImpl)43 Before (org.junit.Before)42 Facility (cz.metacentrum.perun.core.api.Facility)13 GroupsManagerBl (cz.metacentrum.perun.core.bl.GroupsManagerBl)11 User (cz.metacentrum.perun.core.api.User)9 ArrayList (java.util.ArrayList)9 ResourcesManagerBl (cz.metacentrum.perun.core.bl.ResourcesManagerBl)8 ModulesUtilsBl (cz.metacentrum.perun.core.bl.ModulesUtilsBl)6 UsersManagerBl (cz.metacentrum.perun.core.bl.UsersManagerBl)6 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)5 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)5 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)5 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)4 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)4 Group (cz.metacentrum.perun.core.api.Group)3 FacilitiesManagerBl (cz.metacentrum.perun.core.bl.FacilitiesManagerBl)3 AttributeChangedForUser (cz.metacentrum.perun.audit.events.AttributesManagerEvents.AttributeChangedForUser)2