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);
}
}
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);
}
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);
}
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);
}
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);
}
Aggregations