Search in sources :

Example 6 with IPersonAttributesGroupDefinition

use of org.apereo.portal.groups.pags.dao.IPersonAttributesGroupDefinition in project uPortal by Jasig.

the class PagsRESTController method createPagsGroup.

@RequestMapping(value = "/v4-3/pags/{parentGroupName}.json", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.POST)
@ResponseBody
public String createPagsGroup(HttpServletRequest request, HttpServletResponse res, @PathVariable("parentGroupName") String parentGroupName, @RequestBody String json) {
    res.setContentType(MediaType.APPLICATION_JSON_VALUE);
    /*
         * This step is necessary;  the incoming URLs will sometimes have '+'
         * characters for spaces, and the @PathVariable magic doesn't convert them.
         */
    String name;
    try {
        name = URLDecoder.decode(parentGroupName, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        res.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return "{ 'error': '" + e.getMessage() + "' }";
    }
    IPersonAttributesGroupDefinition inpt;
    try {
        inpt = objectMapper.readValue(json, PersonAttributesGroupDefinitionImpl.class);
    } catch (Exception e) {
        res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        // should be escaped
        return "{ 'error': '" + e.getMessage() + "' }";
    }
    // Obtain a real reference to the parent group
    EntityIdentifier[] eids = GroupService.searchForGroups(name, IGroupConstants.IS, IPerson.class);
    if (eids.length == 0) {
        res.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return "{ 'error': 'Parent group does not exist: " + name + "' }";
    }
    IEntityGroup parentGroup = // Names must be unique
    (IEntityGroup) GroupService.getGroupMember(eids[0]);
    IPerson person = personManager.getPerson(request);
    IPersonAttributesGroupDefinition rslt;
    try {
        // A little weird that we need to do both;
        // need some PAGS DAO/Service refactoring
        rslt = pagsService.createPagsDefinition(person, parentGroup, inpt.getName(), inpt.getDescription());
        // little purpose and could be removed.
        for (IPersonAttributesGroupTestGroupDefinition testGroupDef : inpt.getTestGroups()) {
            // NOTE:  The deserializer handles testDef --> testGroupDef
            testGroupDef.setGroup(rslt);
        }
        rslt.setTestGroups(inpt.getTestGroups());
        rslt.setMembers(inpt.getMembers());
        pagsService.updatePagsDefinition(person, rslt);
    } catch (RuntimeAuthorizationException rae) {
        res.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return "{ 'error': 'not authorized' }";
    } catch (IllegalArgumentException iae) {
        res.setStatus(HttpServletResponse.SC_CONFLICT);
        return "{ 'error': '" + iae.getMessage() + "' }";
    } catch (Exception e) {
        e.printStackTrace();
        res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return "{ 'error': '" + e.getMessage() + "' }";
    }
    return respondPagsGroupJson(res, rslt, person, HttpServletResponse.SC_CREATED);
}
Also used : IEntityGroup(org.apereo.portal.groups.IEntityGroup) IPerson(org.apereo.portal.security.IPerson) RuntimeAuthorizationException(org.apereo.portal.security.RuntimeAuthorizationException) IPersonAttributesGroupDefinition(org.apereo.portal.groups.pags.dao.IPersonAttributesGroupDefinition) IPersonAttributesGroupTestGroupDefinition(org.apereo.portal.groups.pags.dao.IPersonAttributesGroupTestGroupDefinition) UnsupportedEncodingException(java.io.UnsupportedEncodingException) EntityIdentifier(org.apereo.portal.EntityIdentifier) PersonAttributesGroupDefinitionImpl(org.apereo.portal.groups.pags.dao.jpa.PersonAttributesGroupDefinitionImpl) RuntimeAuthorizationException(org.apereo.portal.security.RuntimeAuthorizationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 7 with IPersonAttributesGroupDefinition

use of org.apereo.portal.groups.pags.dao.IPersonAttributesGroupDefinition in project uPortal by Jasig.

the class PagsRESTController method findPagsGroup.

@RequestMapping(value = "/v4-3/pags/{pagsGroupName}.json", produces = { MediaType.APPLICATION_JSON_VALUE }, method = RequestMethod.GET)
@ResponseBody
public String findPagsGroup(HttpServletRequest request, HttpServletResponse res, @PathVariable("pagsGroupName") String pagsGroupName) {
    res.setContentType(MediaType.APPLICATION_JSON_VALUE);
    /*
         * This step is necessary;  the incoming URLs will sometimes have '+'
         * characters for spaces, and the @PathVariable magic doesn't convert them.
         */
    String name;
    try {
        name = URLDecoder.decode(pagsGroupName, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return "{ 'error': '" + e.toString() + "' }";
    }
    IPerson person = personManager.getPerson(request);
    IPersonAttributesGroupDefinition pagsGroup = this.pagsService.getPagsDefinitionByName(person, name);
    return respondPagsGroupJson(res, pagsGroup, person, HttpServletResponse.SC_FOUND);
}
Also used : IPerson(org.apereo.portal.security.IPerson) IPersonAttributesGroupDefinition(org.apereo.portal.groups.pags.dao.IPersonAttributesGroupDefinition) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 8 with IPersonAttributesGroupDefinition

use of org.apereo.portal.groups.pags.dao.IPersonAttributesGroupDefinition in project uPortal by Jasig.

the class PersonAttributesGroupImportHelper method dropGroupMembers.

public void dropGroupMembers(String groupName) {
    Set<IPersonAttributesGroupDefinition> groups = personAttributesGroupDefinitionDao.getPersonAttributesGroupDefinitionByName(groupName);
    IPersonAttributesGroupDefinition group = groups.iterator().next();
    group.setMembers(new HashSet<IPersonAttributesGroupDefinition>(0));
    personAttributesGroupDefinitionDao.updatePersonAttributesGroupDefinition(group);
}
Also used : IPersonAttributesGroupDefinition(org.apereo.portal.groups.pags.dao.IPersonAttributesGroupDefinition)

Example 9 with IPersonAttributesGroupDefinition

use of org.apereo.portal.groups.pags.dao.IPersonAttributesGroupDefinition in project uPortal by Jasig.

the class PersonAttributesGroupImportHelper method dropTestGroupsAndTests.

public void dropTestGroupsAndTests(String groupName) {
    Set<IPersonAttributesGroupDefinition> groups = personAttributesGroupDefinitionDao.getPersonAttributesGroupDefinitionByName(groupName);
    IPersonAttributesGroupDefinition group = groups.iterator().next();
    Set<IPersonAttributesGroupTestGroupDefinition> testGroups = group.getTestGroups();
    // Disconnect the test groups
    group.setTestGroups(new HashSet<IPersonAttributesGroupTestGroupDefinition>());
    personAttributesGroupDefinitionDao.updatePersonAttributesGroupDefinition(group);
    // Cascade the test group delete to the tests
    for (IPersonAttributesGroupTestGroupDefinition testGroup : testGroups) {
        personAttributesGroupTestGroupDefinitionDao.deletePersonAttributesGroupTestGroupDefinition(testGroup);
    }
}
Also used : IPersonAttributesGroupDefinition(org.apereo.portal.groups.pags.dao.IPersonAttributesGroupDefinition) IPersonAttributesGroupTestGroupDefinition(org.apereo.portal.groups.pags.dao.IPersonAttributesGroupTestGroupDefinition)

Example 10 with IPersonAttributesGroupDefinition

use of org.apereo.portal.groups.pags.dao.IPersonAttributesGroupDefinition in project uPortal by Jasig.

the class PersonAttributesGroupImportHelper method addGroupMember.

public void addGroupMember(String groupName, String member) {
    Set<IPersonAttributesGroupDefinition> groups = personAttributesGroupDefinitionDao.getPersonAttributesGroupDefinitionByName(groupName);
    Set<IPersonAttributesGroupDefinition> attemptingToAddMembers = personAttributesGroupDefinitionDao.getPersonAttributesGroupDefinitionByName(member);
    if (groups.isEmpty() || attemptingToAddMembers.isEmpty()) {
        throw new RuntimeException("Group: " + groupName + " or member: " + member + " does not exist");
    } else {
        IPersonAttributesGroupDefinition group = groups.iterator().next();
        IPersonAttributesGroupDefinition attemptingToAddMember = attemptingToAddMembers.iterator().next();
        Set<IPersonAttributesGroupDefinition> groupMembers = group.getMembers();
        for (IPersonAttributesGroupDefinition groupMember : groupMembers) {
            if (groupMember.getName().equalsIgnoreCase(attemptingToAddMember.getName())) {
                return;
            }
        }
        groupMembers.add(attemptingToAddMember);
        group.setMembers(groupMembers);
        personAttributesGroupDefinitionDao.updatePersonAttributesGroupDefinition(group);
    }
}
Also used : IPersonAttributesGroupDefinition(org.apereo.portal.groups.pags.dao.IPersonAttributesGroupDefinition)

Aggregations

IPersonAttributesGroupDefinition (org.apereo.portal.groups.pags.dao.IPersonAttributesGroupDefinition)13 IPersonAttributesGroupTestGroupDefinition (org.apereo.portal.groups.pags.dao.IPersonAttributesGroupTestGroupDefinition)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 IPerson (org.apereo.portal.security.IPerson)3 EntityManager (javax.persistence.EntityManager)2 PersonAttributesGroupDefinitionImpl (org.apereo.portal.groups.pags.dao.jpa.PersonAttributesGroupDefinitionImpl)2 RuntimeAuthorizationException (org.apereo.portal.security.RuntimeAuthorizationException)2 ArrayList (java.util.ArrayList)1 EntityIdentifier (org.apereo.portal.EntityIdentifier)1 IEntityGroup (org.apereo.portal.groups.IEntityGroup)1 IPortalData (org.apereo.portal.io.xml.IPortalData)1 SimpleStringPortalData (org.apereo.portal.io.xml.SimpleStringPortalData)1 Element (org.dom4j.Element)1 QName (org.dom4j.QName)1