Search in sources :

Example 1 with GroupsManager

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

the class RegistrarBaseIntegrationTest method testEmbeddedGroupsSubmission.

@Test
public void testEmbeddedGroupsSubmission() 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 groups in VO
    Group group1 = new Group("GroupA", "Cool folks");
    Group group2 = new Group("GroupB", "Cooler folks");
    groupsManager.createGroup(session, vo, group1);
    groupsManager.createGroup(session, vo, group2);
    registrarManager.addGroupsToAutoRegistration(session, List.of(group1, group2));
    // create user
    User user = new User(-1, "Jo", "Doe", "", "", "");
    user = perun.getUsersManagerBl().createUser(session, user);
    // prepare application
    Application application = prepareApplicationToVo(user);
    // set embedded groups as item in application and fill with our two groups
    String embGroupsValue = String.format("Group A#%d|Group B#%d", group1.getId(), group2.getId());
    List<ApplicationFormItemData> appItemsData = new ArrayList<>();
    appItemsData.add(new ApplicationFormItemData(embeddedGroupsItem, "Embedded groups", embGroupsValue, "0"));
    registrarManager.submitApplication(session, application, appItemsData);
    List<Group> expectedEmbeddedGroups = List.of(group1, group2);
    RegistrarManagerImpl registrarManagerImpl = AopTestUtils.getTargetObject(registrarManager);
    assertEquals(expectedEmbeddedGroups, registrarManagerImpl.getEmbeddedGroups(session, application.getId()));
    assertEquals(1, registrarManager.getApplicationsForUser(user).size());
    registrarManager.approveApplication(session, application.getId());
    assertEquals(3, registrarManager.getApplicationsForUser(user).size());
    assertEquals(1, registrarManager.getApplicationsForGroup(session, group1, List.of("NEW", "VERIFIED")).size());
    assertEquals(1, registrarManager.getApplicationsForGroup(session, group2, List.of("NEW", "VERIFIED")).size());
}
Also used : RegistrarManagerImpl(cz.metacentrum.perun.registrar.impl.RegistrarManagerImpl) 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 2 with GroupsManager

use of cz.metacentrum.perun.core.api.GroupsManager 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 3 with GroupsManager

use of cz.metacentrum.perun.core.api.GroupsManager 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 4 with GroupsManager

use of cz.metacentrum.perun.core.api.GroupsManager 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 5 with GroupsManager

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

the class RegistrarBaseIntegrationTest method testEmbeddedGroupsSubmission_groupAutoApprove.

@Test
public void testEmbeddedGroupsSubmission_groupAutoApprove() 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 groups in VO
    Group group = new Group("GroupA", "Cool folks");
    groupsManager.createGroup(session, vo, group);
    registrarManager.addGroupsToAutoRegistration(session, List.of(group));
    // allow auto-approve
    ApplicationForm groupForm = registrarManager.getFormForGroup(group);
    groupForm.setAutomaticApprovalEmbedded(true);
    registrarManager.updateForm(session, groupForm);
    // create user
    final User user = new User(-1, "Jo", "Doe", "", "", "");
    perun.getUsersManagerBl().createUser(session, user);
    Application application = prepareApplicationToVo(user);
    String embGroupsValue = String.format("Group A#%d", group.getId());
    List<ApplicationFormItemData> appItemsData = new ArrayList<>();
    appItemsData.add(new ApplicationFormItemData(embeddedGroupsItem, "Embedded groups", embGroupsValue, "0"));
    registrarManager.submitApplication(session, application, appItemsData);
    registrarManager.approveApplication(session, application.getId());
    List<Member> groupMembers = groupsManager.getGroupMembers(session, group);
    assertThat(groupMembers).anyMatch(member -> member.getUserId() == user.getId());
}
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) Member(cz.metacentrum.perun.core.api.Member) GroupsManager(cz.metacentrum.perun.core.api.GroupsManager) Test(org.junit.Test)

Aggregations

Group (cz.metacentrum.perun.core.api.Group)5 GroupsManager (cz.metacentrum.perun.core.api.GroupsManager)5 ApplicationForm (cz.metacentrum.perun.registrar.model.ApplicationForm)5 User (cz.metacentrum.perun.core.api.User)4 Application (cz.metacentrum.perun.registrar.model.Application)4 ApplicationFormItemData (cz.metacentrum.perun.registrar.model.ApplicationFormItemData)4 RichApplication (cz.metacentrum.perun.registrar.model.RichApplication)4 Test (org.junit.Test)4 ApplicationFormItem (cz.metacentrum.perun.registrar.model.ApplicationFormItem)3 ExtSource (cz.metacentrum.perun.core.api.ExtSource)1 Member (cz.metacentrum.perun.core.api.Member)1 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)1 RegistrarManagerImpl (cz.metacentrum.perun.registrar.impl.RegistrarManagerImpl)1