private void modifyDatastreamControlGroupAction(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String actionLabel = "modifying datastream control group";

        Context context =
                ReadOnlyContext.getContext(Constants.HTTP_REQUEST.REST.uri,
                                           request);
        if (m_server == null) {
            throw new InternalError500Exception(request,
                                                actionLabel,
                                                "server not available",
                                                EMPTY_STRING_ARRAY);
        }
        // FIXME: see FCREPO-765 Admin methods are currently in DefaultManagement and carried through to ManagementModule
        ManagementModule apimDefault = (ManagementModule) m_server.getModule("org.fcrepo.server.management.Management");

        // FIXME: see FCREPO-765. tidy up output writing

        // get parameters
        String pid = request.getParameter("pid");
        String dsID = request.getParameter("dsID");
        String controlGroup = request.getParameter("controlGroup");
        boolean addXMLHeader = getParameterAsBoolean(request, "addXMLHeader", false);
        boolean reformat = getParameterAsBoolean(request, "reformat", false);
        boolean setMIMETypeCharset = getParameterAsBoolean(request, "setMIMETypeCharset", false);

        // get datastream list (single ds id is a list of one)
        String[] datastreams = dsID.split(",");

        // get iterable for pid looping
        boolean singlePID;
        Iterable<String> pids = null;
        if (pid.startsWith(PROTOCOL_FILE)) {
            File pidFile = new File(pid.substring(PROTOCOL_FILE.length()));
            pids = new PIDStreamIterableWrapper(new FileInputStream(pidFile));
            singlePID = false;

        } else { // pid list
            String[] pidList = pid.split(",");
            pids = new ArrayList<String>(Arrays.asList(pidList));
            singlePID = (pidList.length == 1);
        }

        try {

            response.setStatus(HttpServletResponse.SC_OK);
            response.setCharacterEncoding("UTF-8");

            PrintWriter pw = response.getWriter();

            // if doing a single pid/datastream, simple xml output
            if (singlePID && datastreams.length == 1) {
                response.setContentType("text/xml; charset=UTF-8");
                Date[] versions = apimDefault.modifyDatastreamControlGroup(context, pid, dsID, controlGroup, addXMLHeader, reformat, setMIMETypeCharset);
                pw.write("<versions>\n");
                    for (Date version : versions) {
                        pw.write("<version>" + version.toString() + "</version>\n");
                    }
                pw.write("</versions>\n");

            } else { // logging style output
                response.setContentType("text/plain; charset=UTF-8");
                ServerUtilitySerializer ser = new ServerUtilitySerializer(pw);
                for (String curpid : pids) {
                    ser.startObject(curpid);
                    for (String curdsID : datastreams) {
                        ser.startDatastream(curdsID);
                        Date[] versions;
                        try {
                            versions = apimDefault.modifyDatastreamControlGroup(context, curpid, curdsID, controlGroup, addXMLHeader, reformat, setMIMETypeCharset);
                        } catch (DatastreamNotFoundException e) {
                            versions = null;
                        }
                        ser.writeVersions(versions);
                        ser.endDatastream();
                    }
                    ser.endObject();
                }

                ser.finish();
            }
            pw.flush();


        } catch (ObjectNotFoundException e) {
            logger.error("Object not found: " + pid + " - " + e.getMessage());
            throw new NotFound404Exception(request,
                                           actionLabel,
                                           e.getMessage(),
                                           EMPTY_STRING_ARRAY);
        } catch (DatastreamNotFoundException e) {
            logger.error("Datastream not found: " + pid + "/" + dsID + " - " + e.getMessage());
            throw new NotFound404Exception(request,
                                           actionLabel,
                                           e.getMessage(),
                                           EMPTY_STRING_ARRAY);


        } catch (GeneralException e) {
            logger.error(e.getMessage());
            throw new InternalError500Exception(request,
                                                actionLabel,
                                                e.getMessage(),
                                                EMPTY_STRING_ARRAY);
        } catch (AuthzOperationalException aoe) {
            throw new Forbidden403Exception(request,
                                            actionLabel,
                                            "authorization failed",
                                            EMPTY_STRING_ARRAY);
        } catch (AuthzDeniedException ade) {
            throw new Forbidden403Exception(request,
                                            actionLabel,
                                            "authorization denied",
                                            EMPTY_STRING_ARRAY);
        } catch (AuthzPermittedException ape) {
            throw new Continue100Exception(request,
                                           actionLabel,
                                           "authorization permitted",
                                           EMPTY_STRING_ARRAY);

        } catch (ServerException e) {
            logger.error(e.getMessage(),e);
            throw new InternalError500Exception(request,
                                                actionLabel,
                                                "Unexpected error: " + e.getMessage(),
                                                EMPTY_STRING_ARRAY);
        }

    }
private void modifyDatastreamControlGroupAction ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { String actionLabel = "modifying datastream control group" ; Context context = ReadOnlyContext . getContext ( Constants . HTTP_REQUEST . REST . uri , request ) ; if ( m_server == null ) { throw new InternalError500Exception ( request , actionLabel , "server not available" , EMPTY_STRING_ARRAY ) ; } ManagementModule apimDefault = ( ManagementModule ) m_server . getModule ( "org.fcrepo.server.management.Management" ) ; String pid = request . getParameter ( "pid" ) ; String dsID = request . getParameter ( "dsID" ) ; String controlGroup = request . getParameter ( "controlGroup" ) ; boolean addXMLHeader = getParameterAsBoolean ( request , "addXMLHeader" , false ) ; boolean reformat = getParameterAsBoolean ( request , "reformat" , false ) ; boolean setMIMETypeCharset = getParameterAsBoolean ( request , "setMIMETypeCharset" , false ) ; String [ ] datastreams = dsID . split ( "," ) ; boolean singlePID ; Iterable < String > pids = null ; if ( pid . startsWith ( PROTOCOL_FILE ) ) { File pidFile = new File ( pid . substring ( PROTOCOL_FILE . length ( ) ) ) ; pids = new PIDStreamIterableWrapper ( new FileInputStream ( pidFile ) ) ; singlePID = false ; } else { String [ ] pidList = pid . split ( "," ) ; pids = new ArrayList < String > ( Arrays . asList ( pidList ) ) ; singlePID = ( pidList . length == 1 ) ; } try { response . setStatus ( HttpServletResponse . SC_OK ) ; response . setCharacterEncoding ( "UTF-8" ) ; PrintWriter pw = response . getWriter ( ) ; if ( singlePID && datastreams . length == 1 ) { response . setContentType ( "text/xml; charset=UTF-8" ) ; Date [ ] versions = apimDefault . modifyDatastreamControlGroup ( context , pid , dsID , controlGroup , addXMLHeader , reformat , setMIMETypeCharset ) ; pw . write ( "<versions>\n" ) ; for ( Date version : versions ) { pw . write ( "<version>" + version . toString ( ) + "</version>\n" ) ; } pw . write ( "</versions>\n" ) ; } else { response . setContentType ( "text/plain; charset=UTF-8" ) ; ServerUtilitySerializer ser = new ServerUtilitySerializer ( pw ) ; for ( String curpid : pids ) { ser . startObject ( curpid ) ; for ( String curdsID : datastreams ) { ser . startDatastream ( curdsID ) ; Date [ ] versions ; try { versions = apimDefault . modifyDatastreamControlGroup ( context , curpid , curdsID , controlGroup , addXMLHeader , reformat , setMIMETypeCharset ) ; } catch ( DatastreamNotFoundException e ) { versions = null ; } ser . writeVersions ( versions ) ; ser . endDatastream ( ) ; } ser . endObject ( ) ; } ser . finish ( ) ; } pw . flush ( ) ; } catch ( ObjectNotFoundException e ) { logger . error ( "Object not found: " + pid + " - " + e . getMessage ( ) ) ; throw new NotFound404Exception ( request , actionLabel , e . getMessage ( ) , EMPTY_STRING_ARRAY ) ; } catch ( DatastreamNotFoundException e ) { logger . error ( "Datastream not found: " + pid + "/" + dsID + " - " + e . getMessage ( ) ) ; throw new NotFound404Exception ( request , actionLabel , e . getMessage ( ) , EMPTY_STRING_ARRAY ) ; } catch ( GeneralException e ) { logger . error ( e . getMessage ( ) ) ; throw new InternalError500Exception ( request , actionLabel , e . getMessage ( ) , EMPTY_STRING_ARRAY ) ; } catch ( AuthzOperationalException aoe ) { throw new Forbidden403Exception ( request , actionLabel , "authorization failed" , EMPTY_STRING_ARRAY ) ; } catch ( AuthzDeniedException ade ) { throw new Forbidden403Exception ( request , actionLabel , "authorization denied" , EMPTY_STRING_ARRAY ) ; } catch ( AuthzPermittedException ape ) { throw new Continue100Exception ( request , actionLabel , "authorization permitted" , EMPTY_STRING_ARRAY ) ; } catch ( ServerException e ) { logger . error ( e . getMessage ( ) , e ) ; throw new InternalError500Exception ( request , actionLabel , "Unexpected error: " + e . getMessage ( ) , EMPTY_STRING_ARRAY ) ; } }
FIXME: see FCREPO-765 - this should be migrated to an admin API (possibly with other methods from this class)