use of cz.metacentrum.perun.registrar.model.ApplicationForm in project perun by CESNET.
the class RegistrarBaseIntegrationTest method testEmbeddedGroupsSubmission_initEmbeddedConflict.
@Test
public void testEmbeddedGroupsSubmission_initEmbeddedConflict() throws PerunException {
GroupsManager groupsManager = perun.getGroupsManager();
ApplicationForm form = registrarManager.getFormForVo(vo);
// create embedded groups form item
ApplicationFormItem embeddedGroupsItem = new ApplicationFormItem();
embeddedGroupsItem.setType(ApplicationFormItem.Type.EMBEDDED_GROUP_APPLICATION);
embeddedGroupsItem.setShortname("embeddedGroups");
embeddedGroupsItem = registrarManager.addFormItem(session, form, embeddedGroupsItem);
registrarManager.updateFormItems(session, form, Collections.singletonList(embeddedGroupsItem));
// create group in VO, generate group application form
Group group1 = new Group("GroupA", "Cool folks");
groupsManager.createGroup(session, vo, group1);
registrarManager.addGroupsToAutoRegistration(session, List.of(group1));
// create user
User user = new User(-1, "Jo", "Doe", "", "", "");
user = perun.getUsersManagerBl().createUser(session, user);
Application application = prepareApplicationToVo(user);
// set embedded groups in VO application
String embGroupsValue = String.format("Group A#%d", group1.getId());
List<ApplicationFormItemData> appItemsData = new ArrayList<>();
appItemsData.add(new ApplicationFormItemData(embeddedGroupsItem, "Embedded groups", embGroupsValue, "0"));
registrarManager.submitApplication(session, application, appItemsData);
// prepare group application and approve vo application
Application groupApp = prepareApplicationToVo(user);
groupApp.setGroup(group1);
registrarManager.submitApplication(session, groupApp, new ArrayList<>());
// normally, approval of VO generates and submits embedded groups applications
registrarManager.approveApplication(session, application.getId());
// embedded application is expected to not be created as init already exists
List<Application> group1Apps = registrarManager.getApplicationsForGroup(session, group1, List.of("NEW", "VERIFIED"));
assertEquals(1, group1Apps.size());
assertEquals(INITIAL, group1Apps.get(0).getType());
}
use of cz.metacentrum.perun.registrar.model.ApplicationForm in project perun by CESNET.
the class RegistrarBaseIntegrationTest method setGroupOptionsToGroupCheckbox.
@Test
// we know the exact type of the data
@SuppressWarnings("unchecked")
public void setGroupOptionsToGroupCheckbox() throws Exception {
Group groupA = new Group("A", "test");
groupA = perun.getGroupsManagerBl().createGroup(session, vo, groupA);
ApplicationForm formForVo = registrarManager.getFormForVo(vo);
ApplicationFormItem groupCheckboxItem = new ApplicationFormItem();
groupCheckboxItem.setShortname("groups");
groupCheckboxItem.setType(ApplicationFormItem.Type.EMBEDDED_GROUP_APPLICATION);
registrarManager.addFormItem(session, formForVo, groupCheckboxItem);
perun.getGroupsManagerBl().addGroupsToAutoRegistration(session, List.of(groupA));
Map<String, Object> data = registrarManager.initRegistrar(session, vo.getShortName(), null);
var items = (List<ApplicationFormItemWithPrefilledValue>) data.get("voFormInitial");
String expectedOptions = groupA.getId() + "#A";
assertThat(items.get(0).getFormItem().getI18n().get(ApplicationFormItem.EN).getOptions()).isEqualTo(expectedOptions);
assertThat(items.get(0).getFormItem().getI18n().get(ApplicationFormItem.CS).getOptions()).isEqualTo(expectedOptions);
}
use of cz.metacentrum.perun.registrar.model.ApplicationForm in project perun by CESNET.
the class RegistrarBaseIntegrationTest method setUpGroup.
private Group setUpGroup(String name, String desc) throws Exception {
GroupsManager groupsManager = perun.getGroupsManager();
// create group in VO, generate group application form
Group group = new Group(name, desc);
group = groupsManager.createGroup(session, vo, group);
registrarManager.createApplicationFormInGroup(session, group);
ApplicationForm groupForm = registrarManager.getFormForGroup(group);
groupForm.setAutomaticApproval(true);
registrarManager.updateForm(session, groupForm);
return group;
}
use of cz.metacentrum.perun.registrar.model.ApplicationForm in project perun by CESNET.
the class RegistrarBaseIntegrationTest method testHandleGroupApplications.
@Test
public void testHandleGroupApplications() throws PerunException {
GroupsManager groupsManager = perun.getGroupsManager();
// create group in VO, generate group application form
Group group1 = new Group("GroupA", "Cool folks");
group1 = groupsManager.createGroup(session, vo, group1);
registrarManager.createApplicationFormInGroup(session, group1);
ApplicationForm groupForm = registrarManager.getFormForGroup(group1);
groupForm.setAutomaticApproval(true);
registrarManager.updateForm(session, groupForm);
// create user
User user = new User(-1, "Jo", "Doe", "", "", "");
user = perun.getUsersManagerBl().createUser(session, user);
ExtSource source = new ExtSource("ExtSource", ExtSourcesManager.EXTSOURCE_IDP);
perun.getExtSourcesManagerBl().createExtSource(session, source, new HashMap<>());
UserExtSource ues = new UserExtSource(source, session.getPerunPrincipal().getActor());
perun.getUsersManagerBl().addUserExtSource(session, user, ues);
Application voApplication = prepareApplicationToVo(user);
Application groupApplication = prepareApplicationToGroup(null, group1);
List<ApplicationFormItemData> appItemsData = new ArrayList<>();
voApplication = registrarManager.submitApplication(session, voApplication, appItemsData);
registrarManager.submitApplication(session, groupApplication, appItemsData);
registrarManager.approveApplication(session, voApplication.getId());
// We have to call this method explicitly due to transactions
registrarManager.handleUsersGroupApplications(session, vo, user);
List<Application> group1Apps = registrarManager.getApplicationsForGroup(session, group1, List.of("APPROVED"));
assertEquals(1, group1Apps.size());
assertEquals(user, group1Apps.get(0).getUser());
}
use of cz.metacentrum.perun.registrar.model.ApplicationForm in project perun by CESNET.
the class RegistrarBaseIntegrationTest method createAppMail.
/*
@Test
public void stringTest() {
String text = "anytext{login-egi-ui}anytext{neco}and{login-neco}";
Pattern MY_PATTERN = Pattern.compile("\\-(.*?)\\}");
Matcher m = MY_PATTERN.matcher(text);
while (m.find()) {
System.out.println(m.group(0));
}
Pattern MY_PATTERN2 = Pattern.compile("\\{login-[^\\}]+\\}");
Matcher m2 = MY_PATTERN2.matcher(text);
while (m2.find()) {
System.out.println(m2.group(0));
}
}
@Test
public void getAppsTest() throws Exception {
List<String> apps = new ArrayList<String>();
apps.add("NEW");
apps.add("VERIFIED");
// get compass
Vo vo = perun.getVosManager().getVoById(session, 321);
System.out.println(vo);
List<Application> result = registrarManager.getApplicationsForVo(session, vo, apps);
System.out.println("APPS ["+result.size()+"]:" + result);
}
@Test
@Transactional
public void testModule() throws PerunException {
registrarManager.approveApplication(session, 1543);
}
*/
@Test
public void createAppMail() throws PerunException {
System.out.println("createAppMail()");
// get form for VO (if not exists, it's created)
// Vo vo = perun.getVosManager().getVoByShortName(session, "meta");
ApplicationForm form = registrarManager.getFormForVo(vo);
ApplicationMail mail = new ApplicationMail(0, AppType.INITIAL, form.getId(), MailType.APP_CREATED_USER, true);
MailText t = mail.getMessage(new Locale("cs"));
t.setText("Český text mailu.");
t.setSubject("Český předmět mailu");
MailText t2 = mail.getMessage(new Locale("en"));
t2.setSubject("Anglický předmět mailu");
t2.setText("Anglický text mailu.");
int id = mailManager.addMail(session, form, mail);
mail = mailManager.getMailById(session, id);
List<ApplicationMail> mails = mailManager.getApplicationMails(session, form);
assertTrue("Mails are empty", (mails != null && !mails.isEmpty()));
assertTrue("Our mail was not returned", mails.contains(mail));
// System.out.println(mails);
}
Aggregations