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