Search in sources :

Example 1 with JaxbGroup

use of org.opencastproject.security.api.JaxbGroup in project opencast by opencast.

the class GroupsListProvider method getList.

@Override
public Map<String, String> getList(String listName, ResourceListQuery query, Organization organization) {
    Map<String, String> groupsList = new HashMap<String, String>();
    List<JaxbGroup> groups = null;
    int limit = 0;
    int offset = 0;
    if (query != null) {
        if (query.getLimit().isSome())
            limit = query.getLimit().get();
        if (query.getOffset().isSome())
            offset = query.getOffset().get();
    }
    try {
        groups = groupRoleProvider.getGroupsAsJson(limit, offset).getGroups();
    } catch (IOException e) {
        logger.error("Not able to get the group list: " + e);
        return groupsList;
    }
    for (JaxbGroup g : groups) {
        if (NAME.equals(listName)) {
            groupsList.put(g.getName(), g.getName());
        } else if (DESCRIPTION.equals(listName)) {
            groupsList.put(g.getDescription(), g.getDescription());
        } else {
            groupsList.put(g.getGroupId(), g.getName());
        }
    }
    return groupsList;
}
Also used : JaxbGroup(org.opencastproject.security.api.JaxbGroup) HashMap(java.util.HashMap) IOException(java.io.IOException)

Example 2 with JaxbGroup

use of org.opencastproject.security.api.JaxbGroup in project opencast by opencast.

the class GroupParsingTest method testUnmarshalUser.

@Test
public void testUnmarshalUser() throws Exception {
    Set<JaxbRole> roles = new HashSet<JaxbRole>();
    roles.add(new JaxbRole("ROLE_COURSE_ADMIN", ORGANIZATION));
    roles.add(new JaxbRole("ROLE_USER", ORGANIZATION));
    Set<String> members = new HashSet<String>();
    members.add("admin1");
    members.add("admin2");
    JaxbGroup expectedGroup = new JaxbGroup("admin", ORGANIZATION, "Admin", "Admin group", roles, members);
    StreamSource streamSource = new StreamSource(getClass().getResourceAsStream(GROUP_XML_FILE));
    JaxbGroup group = jaxbContext.createUnmarshaller().unmarshal(streamSource, JaxbGroup.class).getValue();
    assertEquals(expectedGroup.getGroupId(), group.getGroupId());
    assertEquals(expectedGroup.getName(), group.getName());
    assertEquals(expectedGroup.getDescription(), group.getDescription());
    assertEquals(expectedGroup.getRole(), group.getRole());
    assertEquals(expectedGroup.getOrganization(), group.getOrganization());
    assertEquals(expectedGroup.getRoles(), group.getRoles());
    assertEquals(expectedGroup.getMembers(), group.getMembers());
}
Also used : JaxbGroup(org.opencastproject.security.api.JaxbGroup) JaxbRole(org.opencastproject.security.api.JaxbRole) StreamSource(javax.xml.transform.stream.StreamSource) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with JaxbGroup

use of org.opencastproject.security.api.JaxbGroup in project opencast by opencast.

the class GroupParsingTest method testMarshalUser.

@Test
public void testMarshalUser() throws Exception {
    StringWriter writer = new StringWriter();
    StringWriter writer2 = new StringWriter();
    Set<JaxbRole> roles = new HashSet<JaxbRole>();
    roles.add(new JaxbRole("ROLE_COURSE_ADMIN", ORGANIZATION));
    roles.add(new JaxbRole("ROLE_USER", ORGANIZATION));
    Set<String> members = new HashSet<String>();
    members.add("admin1");
    members.add("admin2");
    JaxbGroup group = new JaxbGroup("admin", ORGANIZATION, "Admin", "Admin group", roles, members);
    jaxbContext.createMarshaller().marshal(group, writer);
    String expectedOutput = IOUtils.toString(getClass().getResourceAsStream(GROUP_XML_FILE), "UTF-8");
    StreamSource streamSource = new StreamSource(getClass().getResourceAsStream(GROUP_XML_FILE));
    JaxbGroup groupFromFile = jaxbContext.createUnmarshaller().unmarshal(streamSource, JaxbGroup.class).getValue();
    jaxbContext.createMarshaller().marshal(groupFromFile, writer2);
    Diff diff = new Diff(writer2.toString(), writer.toString());
    /* We don't care about ordering. */
    diff.overrideElementQualifier(new ElementNameAndTextQualifier());
    XMLAssert.assertXMLEqual(diff, true);
}
Also used : JaxbGroup(org.opencastproject.security.api.JaxbGroup) JaxbRole(org.opencastproject.security.api.JaxbRole) StringWriter(java.io.StringWriter) Diff(org.custommonkey.xmlunit.Diff) ElementNameAndTextQualifier(org.custommonkey.xmlunit.ElementNameAndTextQualifier) StreamSource(javax.xml.transform.stream.StreamSource) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

JaxbGroup (org.opencastproject.security.api.JaxbGroup)3 HashSet (java.util.HashSet)2 StreamSource (javax.xml.transform.stream.StreamSource)2 Test (org.junit.Test)2 JaxbRole (org.opencastproject.security.api.JaxbRole)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 Diff (org.custommonkey.xmlunit.Diff)1 ElementNameAndTextQualifier (org.custommonkey.xmlunit.ElementNameAndTextQualifier)1