Search in sources :

Example 91 with AttributeDefinition

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

the class AttributesManagerEntryIntegrationTest method getRichAttributesWithHoldersForAttributeDefinitionGetGroupFromResourceAndMember.

@Test
public void getRichAttributesWithHoldersForAttributeDefinitionGetGroupFromResourceAndMember() throws Exception {
    System.out.println(CLASS_NAME + "getRichAttributesWithHoldersForAttributeDefinitionGetGroupFromResourceAndMember");
    //Prepare attribute, create it and set it with testing value
    Attribute attribute = setAttributeInNamespace(AttributesManager.NS_GROUP_ATTR);
    perun.getAttributesManagerBl().setAttribute(sess, group1InVo2, attribute);
    perun.getAttributesManagerBl().setAttribute(sess, group2InVo2, attribute);
    //Prepare richAttribute with holders (attribute is not needed but holders are needed)
    RichAttribute richAttr = new RichAttribute();
    richAttr.setPrimaryHolder(resource1InVo2);
    richAttr.setSecondaryHolder(member2OfUser1);
    List<RichAttribute> listOfRichAttributes = perun.getAttributesManagerBl().getRichAttributesWithHoldersForAttributeDefinition(sess, new AttributeDefinition(attribute), richAttr);
    assertTrue("Return no group.", listOfRichAttributes.size() == 0);
}
Also used : Attribute(cz.metacentrum.perun.core.api.Attribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) RichAttribute(cz.metacentrum.perun.core.api.RichAttribute) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 92 with AttributeDefinition

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

the class AttributesManagerEntryIntegrationTest method createAttributeWhenAttributeExists.

@Test(expected = AttributeExistsException.class)
public void createAttributeWhenAttributeExists() throws Exception {
    System.out.println(CLASS_NAME + "createAttributeWhenAttributeExists");
    AttributeDefinition attrDef = new AttributeDefinition();
    attrDef.setFriendlyName("attr-def-facility-tests-attr");
    attrDef.setNamespace("urn:perun:facility:attribute-def:opt");
    attrDef.setDescription("poznamka");
    attrDef.setType(String.class.getName());
    // create attr definition
    attributesManager.createAttribute(sess, attrDef);
    // store attr def in DB acording namespace
    attributesManager.createAttribute(sess, attrDef);
// shouldn't add attr def twice
}
Also used : AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 93 with AttributeDefinition

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

the class FacilitiesManagerEntryIntegrationTest method getMandatoryAttrs.

private List<AttributeDefinition> getMandatoryAttrs() throws InternalErrorException {
    List<String> MANDATORY_ATTRIBUTES_FOR_USER_IN_CONTACT = new ArrayList<>(Arrays.asList(AttributesManager.NS_USER_ATTR_DEF + ":organization", AttributesManager.NS_USER_ATTR_DEF + ":preferredMail"));
    List<AttributeDefinition> mandatoryAttrs = new ArrayList<>();
    for (String attrName : MANDATORY_ATTRIBUTES_FOR_USER_IN_CONTACT) {
        try {
            mandatoryAttrs.add(perun.getAttributesManagerBl().getAttributeDefinition(sess, attrName));
        } catch (AttributeNotExistsException ex) {
            throw new InternalErrorException("Some of mandatory attributes for users in facility contacts not exists.", ex);
        }
    }
    return mandatoryAttrs;
}
Also used : AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) ArrayList(java.util.ArrayList) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 94 with AttributeDefinition

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

the class GroupsManagerEntryIntegrationTest method getMemberGroupsByAttribute.

@Test
public void getMemberGroupsByAttribute() throws Exception {
    System.out.println(CLASS_NAME + "getMemberGroupsByAttribute");
    Vo createdVo = perun.getVosManager().createVo(sess, new Vo(0, "testik123456", "testik123456"));
    Member member = setUpMember(createdVo);
    Group group1 = new Group("Group1Test", "Group1Test");
    Group group2 = new Group("Group2Test", "Group2Test");
    Group group3 = new Group("Group3Test", "Group3Test");
    Group group4 = new Group("Group4Test", "Group4Test");
    group1 = groupsManagerBl.createGroup(sess, createdVo, group1);
    group2 = groupsManagerBl.createGroup(sess, createdVo, group2);
    group3 = groupsManagerBl.createGroup(sess, createdVo, group3);
    group4 = groupsManagerBl.createGroup(sess, createdVo, group4);
    groupsManagerBl.addMember(sess, group1, member);
    groupsManagerBl.addMember(sess, group2, member);
    groupsManagerBl.addMember(sess, group3, member);
    groupsManagerBl.addMember(sess, group4, member);
    AttributeDefinition attrDef = new AttributeDefinition();
    attrDef.setNamespace(AttributesManagerEntry.NS_GROUP_ATTR_DEF);
    attrDef.setDescription("Test attribute description");
    attrDef.setFriendlyName("testingAttribute");
    attrDef.setType(String.class.getName());
    attrDef = perun.getAttributesManagerBl().createAttribute(sess, attrDef);
    Attribute attribute = new Attribute(attrDef);
    attribute.setValue("Testing value");
    perun.getAttributesManagerBl().setAttribute(sess, group1, attribute);
    perun.getAttributesManagerBl().setAttribute(sess, group3, attribute);
    AttributeDefinition attrDefBad = new AttributeDefinition();
    attrDefBad.setNamespace(AttributesManagerEntry.NS_GROUP_ATTR_DEF);
    attrDefBad.setDescription("Test attribute description 2");
    attrDefBad.setFriendlyName("testingAttribute2");
    attrDefBad.setType(String.class.getName());
    attrDefBad = perun.getAttributesManagerBl().createAttribute(sess, attrDefBad);
    Attribute attributeBad = new Attribute(attrDefBad);
    attributeBad.setValue("Testing value");
    perun.getAttributesManagerBl().setAttribute(sess, group2, attributeBad);
    perun.getAttributesManagerBl().setAttribute(sess, group4, attributeBad);
    List<Group> groups1 = perun.getGroupsManager().getMemberGroupsByAttribute(sess, member, attribute);
    List<Group> groups2 = perun.getGroupsManager().getMemberGroupsByAttribute(sess, member, attributeBad);
    assertEquals("groups must have only 2 mambers", 2, groups1.size());
    assertEquals("groups must have only 2 mambers", 2, groups2.size());
    assertTrue("list of groups must containt this group", groups1.contains(group1));
    assertTrue("list of groups must containt this group", groups1.contains(group3));
    assertTrue("list of groups must containt this group", groups2.contains(group2));
    assertTrue("list of groups must containt this group", groups2.contains(group4));
}
Also used : Group(cz.metacentrum.perun.core.api.Group) RichGroup(cz.metacentrum.perun.core.api.RichGroup) Attribute(cz.metacentrum.perun.core.api.Attribute) Vo(cz.metacentrum.perun.core.api.Vo) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) Member(cz.metacentrum.perun.core.api.Member) AbstractPerunIntegrationTest(cz.metacentrum.perun.core.AbstractPerunIntegrationTest) Test(org.junit.Test)

Example 95 with AttributeDefinition

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

the class AppTest method prepareData.

private void prepareData() throws PerunException {
    // user
    User user = new User();
    user.setFirstName("John");
    user.setMiddleName("");
    user.setLastName("Smith");
    user.setTitleBefore("");
    user.setTitleAfter("");
    User newUser = perun.getUsersManagerBl().createUser(sess, user);
    userId = newUser.getId();
    // vo
    Vo vo = new Vo(0, "NotifTestVo", "NTestVo");
    Vo newVo = perun.getVosManager().createVo(sess, vo);
    voId = newVo.getId();
    // member
    Member member = perun.getMembersManagerBl().createMember(sess, newVo, newUser);
    memberId = member.getId();
    // attribute preferred laguage
    AttributeDefinition attrDef = perun.getAttributesManagerBl().getAttributeDefinition(sess, "urn:perun:user:attribute-def:def:preferredLanguage");
    Attribute attr = new Attribute(attrDef);
    attr.setValue("cs");
    System.out.println("attribute: " + perun.getAttributesManagerBl().getAttribute(sess, user, "urn:perun:user:attribute-def:def:preferredLanguage"));
    perun.getAttributesManagerBl().setAttribute(sess, user, attr);
    // template
    PerunNotifTemplate template = new PerunNotifTemplate();
    Map<String, List<String>> properties = new HashMap<>();
    properties.put("cz.metacentrum.perun.core.api.Member", new ArrayList<>(Arrays.asList("getId()", "getUserId()")));
    properties.put("METHOD", new ArrayList<>(Arrays.asList("getAttributesManagerBl().getAttribute(cz.metacentrum.perun.core.api.PerunSession, getUsersManagerBl().getUserByMember(cz.metacentrum.perun.core.api.PerunSession, cz.metacentrum.perun.core.api.Member), \"urn:perun:user:attribute-def:def:preferredLanguage\").getValue().equals(\"en\")", "getUsersManagerBl().getUserByMember(cz.metacentrum.perun.core.api.PerunSession, cz.metacentrum.perun.core.api.Member).getId()", "getAttributesManagerBl().getAttribute(cz.metacentrum.perun.core.api.PerunSession, getUsersManagerBl().getUserByMember(cz.metacentrum.perun.core.api.PerunSession, cz.metacentrum.perun.core.api.Member), \"urn:perun:user:attribute-def:def:preferredLanguage\").getValue().equals(\"cs\")")));
    template.setPrimaryProperties(properties);
    template.setNotifyTrigger(PerunNotifNotifyTrigger.ALL_REGEX_IDS);
    template.setYoungestMessageTime(10L);
    template.setOldestMessageTime(20L);
    template.setSender("noreply@meta.cz");
    // regex for creation
    PerunNotifRegex regexC = new PerunNotifRegex();
    regexC.setNote("Member created");
    regexC.setRegex("Member:.* created\\.");
    PerunNotifRegex newRegexC = manager.createPerunNotifRegex(sess, regexC);
    template.addPerunNotifRegex(newRegexC);
    // regex for validation
    PerunNotifRegex regexV = new PerunNotifRegex();
    regexV.setNote("Member validated");
    regexV.setRegex("Member:.* validated\\.");
    PerunNotifRegex newRegexV = manager.createPerunNotifRegex(sess, regexV);
    template.addPerunNotifRegex(newRegexV);
    // template message english
    PerunNotifTemplateMessage messageEn = new PerunNotifTemplateMessage();
    messageEn.setMessage("Good day," + "thank you for Your registration to virtual organization MetaCentrum VO," + "activity MetaCentrum association CESNET, which focuses on sophisticated computation." + "Name: ${perun.getUsersManagerBl().getUserByMember(perunSession, retrievedObjects[\"" + newRegexC.getId() + "\"][\"Member\"]).getFirstName()}<br/>" + "Surname: ${perun.getUsersManagerBl().getUserByMember(perunSession, retrievedObjects[\"" + newRegexC.getId() + "\"][\"Member\"]).getLastName()}<br/>" + "Accounts are valid on machines till $membershipExpiration");
    messageEn.setLocale(Locale.forLanguageTag("en"));
    messageEn.setSubject("Subject");
    template.addPerunNotifTemplateMessage(messageEn);
    // template message czech
    PerunNotifTemplateMessage messageCs = new PerunNotifTemplateMessage();
    messageCs.setMessage("Dobrý den,\n" + "  děkujeme za Vaši registraci do virtualni organizace MetaCentrum VO,\n" + "aktivity MetaCentrum sdružení CESNET, zaměřené na náročné výpočty.\n" + "  Váš účet je nyní propagován na všechny servery, plně funkční bude\n" + "během hodiny.\n" + "  Jméno: ${perun.getUsersManagerBl().getUserByMember(perunSession, retrievedObjects[\"" + newRegexC.getId() + "\"][\"Member\"]).getFirstName()}<br/>\n" + "  Přijmení: ${perun.getUsersManagerBl().getUserByMember(perunSession, retrievedObjects[\"" + newRegexC.getId() + "\"][\"Member\"]).getLastName()}<br/>\n" + "Jazyk: ${perun.getAttributesManagerBl().getAttribute(perunSession, perun.getUsersManagerBl().getUserByMember(perunSession, retrievedObjects[\"" + newRegexC.getId() + "\"][\"Member\"]), \"urn:perun:user:attribute-def:def:preferredLanguage\").getValue()}");
    messageCs.setLocale(Locale.forLanguageTag("cs"));
    messageCs.setSubject("Subject");
    template.addPerunNotifTemplateMessage(messageCs);
    // receiver
    PerunNotifReceiver receiver = new PerunNotifReceiver();
    receiver.setLocale("cs");
    receiver.setTypeOfReceiver(PerunNotifTypeOfReceiver.EMAIL_USER);
    receiver.setTarget("cz.metacentrum.perun.core.api.Member.getUserId");
    template.setReceivers(new ArrayList<>(Arrays.asList(receiver)));
    manager.createPerunNotifTemplate(sess, template);
}
Also used : User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) Vo(cz.metacentrum.perun.core.api.Vo) Member(cz.metacentrum.perun.core.api.Member)

Aggregations

AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)396 Attribute (cz.metacentrum.perun.core.api.Attribute)157 ArrayList (java.util.ArrayList)46 Test (org.junit.Test)38 AbstractPerunIntegrationTest (cz.metacentrum.perun.core.AbstractPerunIntegrationTest)33 User (cz.metacentrum.perun.core.api.User)24 RichAttribute (cz.metacentrum.perun.core.api.RichAttribute)22 Vo (cz.metacentrum.perun.core.api.Vo)15 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)14 Facility (cz.metacentrum.perun.core.api.Facility)12 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)12 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)12 Resource (cz.metacentrum.perun.core.api.Resource)10 LinkedHashMap (java.util.LinkedHashMap)10 Group (cz.metacentrum.perun.core.api.Group)8 Member (cz.metacentrum.perun.core.api.Member)8 PerunSession (cz.metacentrum.perun.core.api.PerunSession)7 ConsistencyErrorException (cz.metacentrum.perun.core.api.exceptions.ConsistencyErrorException)6 WrongAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException)5 WrongReferenceAttributeValueException (cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException)5