Search in sources :

Example 1 with IPersonAttributesGroupDefinition

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

the class PagsRESTController method updatePagsGroup.

@RequestMapping(value = "/v4-3/pags/{pagsGroupName}.json", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.PUT)
@ResponseBody
public String updatePagsGroup(HttpServletRequest req, HttpServletResponse res, @PathVariable("pagsGroupName") String pagsGroupName, @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(pagsGroupName, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return "{ 'error': '" + e.toString() + "' }";
    }
    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.toString() + "' }";
    }
    if (inpt == null) {
        res.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return "{ 'error': 'Not found' }";
    }
    if (!name.equals(inpt.getName())) {
        res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return "{ 'error': 'Group name in URL parameter must match name in JSON payload' }";
    }
    IPerson person = personManager.getPerson(req);
    IPersonAttributesGroupDefinition rslt;
    try {
        IPersonAttributesGroupDefinition currentDef = pagsService.getPagsDefinitionByName(person, name);
        if (currentDef == null) {
            res.setStatus(HttpServletResponse.SC_NOT_FOUND);
            return "{ 'error': 'Not found' }";
        }
        /*
             * Copy over the information being passed in to the JPA-managed
             * instance;  the following do not support updates (currently):
             *   - Name
             *   - Members
             */
        currentDef.setDescription(inpt.getDescription());
        // little purpose and could be removed.
        for (IPersonAttributesGroupTestGroupDefinition testGroupDef : inpt.getTestGroups()) {
            // NOTE:  The deserializer handles testDef --> testGroupDef
            testGroupDef.setGroup(currentDef);
        }
        currentDef.setTestGroups(inpt.getTestGroups());
        rslt = pagsService.updatePagsDefinition(person, currentDef);
    } catch (IllegalArgumentException iae) {
        res.setStatus(HttpServletResponse.SC_NOT_FOUND);
        // should be escaped
        return "{ 'error': '" + iae.getMessage() + "' }";
    } catch (RuntimeAuthorizationException rae) {
        res.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return "{ 'error': 'not authorized' }";
    } catch (Exception e) {
        res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return "{ 'error': '" + e.toString() + "' }";
    }
    return respondPagsGroupJson(res, rslt, person, HttpServletResponse.SC_ACCEPTED);
}
Also used : 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) PersonAttributesGroupDefinitionImpl(org.apereo.portal.groups.pags.dao.jpa.PersonAttributesGroupDefinitionImpl) RuntimeAuthorizationException(org.apereo.portal.security.RuntimeAuthorizationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 2 with IPersonAttributesGroupDefinition

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

the class PersonAttributesGroupDefinitionImpl method toElement.

@Override
public void toElement(org.dom4j.Element parent) {
    if (parent == null) {
        String msg = "Argument 'parent' cannot be null.";
        throw new IllegalArgumentException(msg);
    }
    parent.addElement("name").addText(this.getName());
    parent.addElement("description").addText(this.getDescription());
    if (!members.isEmpty()) {
        org.dom4j.Element elementMembers = DocumentHelper.createElement(new QName("members"));
        for (IPersonAttributesGroupDefinition member : members) {
            elementMembers.addElement("member-name").addText(member.getName());
        }
        parent.add(elementMembers);
    }
    if (!testGroups.isEmpty()) {
        org.dom4j.Element elementSelectionTest = DocumentHelper.createElement(new QName("selection-test"));
        for (IPersonAttributesGroupTestGroupDefinition testGroup : testGroups) {
            testGroup.toElement(elementSelectionTest);
        }
        parent.add(elementSelectionTest);
    }
}
Also used : IPersonAttributesGroupDefinition(org.apereo.portal.groups.pags.dao.IPersonAttributesGroupDefinition) IPersonAttributesGroupTestGroupDefinition(org.apereo.portal.groups.pags.dao.IPersonAttributesGroupTestGroupDefinition) QName(org.dom4j.QName)

Example 3 with IPersonAttributesGroupDefinition

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

the class JpaPersonAttributesGroupDefinitionDao method deletePersonAttributesGroupDefinition.

@PortalTransactional
@Override
public void deletePersonAttributesGroupDefinition(IPersonAttributesGroupDefinition definition) {
    Validate.notNull(definition, "definition can not be null");
    final IPersonAttributesGroupDefinition persistentDefinition;
    final EntityManager entityManager = this.getEntityManager();
    if (entityManager.contains(definition)) {
        persistentDefinition = definition;
    } else {
        persistentDefinition = entityManager.merge(definition);
    }
    entityManager.remove(persistentDefinition);
}
Also used : EntityManager(javax.persistence.EntityManager) IPersonAttributesGroupDefinition(org.apereo.portal.groups.pags.dao.IPersonAttributesGroupDefinition)

Example 4 with IPersonAttributesGroupDefinition

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

the class PersonAttributesGroupImportHelper method getOrCreateGroup.

private IPersonAttributesGroupDefinition getOrCreateGroup(String name, String description) {
    Set<IPersonAttributesGroupDefinition> groups = personAttributesGroupDefinitionDao.getPersonAttributesGroupDefinitionByName(name);
    if (groups.size() == 0) {
        return personAttributesGroupDefinitionDao.createPersonAttributesGroupDefinition(name, description);
    } else {
        IPersonAttributesGroupDefinition group = groups.iterator().next();
        group.setDescription(description);
        return personAttributesGroupDefinitionDao.updatePersonAttributesGroupDefinition(group);
    }
}
Also used : IPersonAttributesGroupDefinition(org.apereo.portal.groups.pags.dao.IPersonAttributesGroupDefinition)

Example 5 with IPersonAttributesGroupDefinition

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

the class PersonAttributesGroupStoreExporter method exportDataElement.

@Override
protected Element exportDataElement(String name) {
    final Set<IPersonAttributesGroupDefinition> personAttributesGroupDefinitions = personAttributesGroupDefinitionDao.getPersonAttributesGroupDefinitionByName(name);
    if (personAttributesGroupDefinitions.isEmpty()) {
        return null;
    }
    final org.dom4j.Document pagsGroupDefDoc = new org.dom4j.DocumentFactory().createDocument();
    final Element pagsGroupDefElement = pagsGroupDefDoc.addElement("pags-group");
    pagsGroupDefElement.addAttribute("script", "classpath://org/jasig/portal/io/import-pags-group_v4-1.crn");
    personAttributesGroupDefinitions.iterator().next().toElement(pagsGroupDefElement);
    return pagsGroupDefElement;
}
Also used : IPersonAttributesGroupDefinition(org.apereo.portal.groups.pags.dao.IPersonAttributesGroupDefinition) Element(org.dom4j.Element)

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