@RequestMapping(
            value = "/v4-3/pags/{parentGroupName}.json",
            produces = MediaType.APPLICATION_JSON_VALUE,
            method = RequestMethod.POST)
    public @ResponseBody 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);
            return "{ 'error': '" + e.getMessage() + "' }"; // should be escaped
        }

        // Obtain a real reference to the parent group
        EntityIdentifier[] eids =
                GroupService.searchForGroups(
                        name, IGroupConstants.SearchMethod.DISCRETE, IPerson.class);
        if (eids.length == 0) {
            res.setStatus(HttpServletResponse.SC_BAD_REQUEST);
            return "{ 'error': 'Parent group does not exist: " + name + "' }";
        }
        IEntityGroup parentGroup =
                (IEntityGroup) GroupService.getGroupMember(eids[0]); // Names must be unique

        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());
            // NOTE:  We are also obligated to establish the backlink
            // testGroupDef --> groupDef;  arguably this backlink serves
            // 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);
    }
@ RequestMapping ( value = "/v4-3/pags/{parentGroupName}.json" , produces = MediaType . APPLICATION_JSON_VALUE , method = RequestMethod . POST ) public @ ResponseBody String createPagsGroup ( HttpServletRequest request , HttpServletResponse res , @ PathVariable ( "parentGroupName" ) String parentGroupName , @ RequestBody String json ) { res . setContentType ( MediaType . APPLICATION_JSON_VALUE ) ; 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 ) ; return "{ 'error': '" + e . getMessage ( ) + "' }" ; } EntityIdentifier [ ] eids = GroupService . searchForGroups ( name , IGroupConstants . SearchMethod . DISCRETE , IPerson . class ) ; if ( eids . length == 0 ) { res . setStatus ( HttpServletResponse . SC_BAD_REQUEST ) ; return "{ 'error': 'Parent group does not exist: " + name + "' }" ; } IEntityGroup parentGroup = ( IEntityGroup ) GroupService . getGroupMember ( eids [ 0 ] ) ; IPerson person = personManager . getPerson ( request ) ; IPersonAttributesGroupDefinition rslt ; try { rslt = pagsService . createPagsDefinition ( person , parentGroup , inpt . getName ( ) , inpt . getDescription ( ) ) ; for ( IPersonAttributesGroupTestGroupDefinition testGroupDef : inpt . getTestGroups ( ) ) { 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 ) ; }
Parent group name is expected to be case sensitive.