Search in sources :

Example 11 with ApplicationForm

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());
}
Also used : ApplicationForm(cz.metacentrum.perun.registrar.model.ApplicationForm) ApplicationFormItem(cz.metacentrum.perun.registrar.model.ApplicationFormItem) Group(cz.metacentrum.perun.core.api.Group) User(cz.metacentrum.perun.core.api.User) ApplicationFormItemData(cz.metacentrum.perun.registrar.model.ApplicationFormItemData) Application(cz.metacentrum.perun.registrar.model.Application) RichApplication(cz.metacentrum.perun.registrar.model.RichApplication) GroupsManager(cz.metacentrum.perun.core.api.GroupsManager) Test(org.junit.Test)

Example 12 with ApplicationForm

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);
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ApplicationForm(cz.metacentrum.perun.registrar.model.ApplicationForm) ApplicationFormItem(cz.metacentrum.perun.registrar.model.ApplicationFormItem) Test(org.junit.Test)

Example 13 with ApplicationForm

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;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ApplicationForm(cz.metacentrum.perun.registrar.model.ApplicationForm) GroupsManager(cz.metacentrum.perun.core.api.GroupsManager)

Example 14 with ApplicationForm

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());
}
Also used : Group(cz.metacentrum.perun.core.api.Group) ApplicationForm(cz.metacentrum.perun.registrar.model.ApplicationForm) User(cz.metacentrum.perun.core.api.User) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ExtSource(cz.metacentrum.perun.core.api.ExtSource) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) ApplicationFormItemData(cz.metacentrum.perun.registrar.model.ApplicationFormItemData) Application(cz.metacentrum.perun.registrar.model.Application) RichApplication(cz.metacentrum.perun.registrar.model.RichApplication) GroupsManager(cz.metacentrum.perun.core.api.GroupsManager) Test(org.junit.Test)

Example 15 with ApplicationForm

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);
}
Also used : ApplicationForm(cz.metacentrum.perun.registrar.model.ApplicationForm) MailText(cz.metacentrum.perun.registrar.model.ApplicationMail.MailText) ApplicationMail(cz.metacentrum.perun.registrar.model.ApplicationMail) Test(org.junit.Test)

Aggregations

ApplicationForm (cz.metacentrum.perun.registrar.model.ApplicationForm)22 Test (org.junit.Test)13 ApplicationFormItem (cz.metacentrum.perun.registrar.model.ApplicationFormItem)11 Group (cz.metacentrum.perun.core.api.Group)8 ApplicationFormItemData (cz.metacentrum.perun.registrar.model.ApplicationFormItemData)7 User (cz.metacentrum.perun.core.api.User)6 Application (cz.metacentrum.perun.registrar.model.Application)6 GroupsManager (cz.metacentrum.perun.core.api.GroupsManager)5 RichApplication (cz.metacentrum.perun.registrar.model.RichApplication)5 ApplicationMail (cz.metacentrum.perun.registrar.model.ApplicationMail)4 ExtSource (cz.metacentrum.perun.core.api.ExtSource)2 Vo (cz.metacentrum.perun.core.api.Vo)2 ApplicationMailNotExistsException (cz.metacentrum.perun.registrar.exceptions.ApplicationMailNotExistsException)2 RegistrarException (cz.metacentrum.perun.registrar.exceptions.RegistrarException)2 MailText (cz.metacentrum.perun.registrar.model.ApplicationMail.MailText)2 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)2 EmptyResultDataAccessException (org.springframework.dao.EmptyResultDataAccessException)2 MailForGroupIdUpdated (cz.metacentrum.perun.audit.events.MailManagerEvents.MailForGroupIdUpdated)1 MailForVoIdUpdated (cz.metacentrum.perun.audit.events.MailManagerEvents.MailForVoIdUpdated)1 MailSentForApplication (cz.metacentrum.perun.audit.events.MailManagerEvents.MailSentForApplication)1