Project

General

Profile

« Previous | Next » 

Revision 7093

Modify owner() to set the rights holder from parameters parsed from the mime multipart entity rather than the request params. Need to check that the unit test uses MMp params. This partially addresses https://redmine.dataone.org/issues/2526.

View differences:

src/edu/ucsb/nceas/metacat/restservice/CNResourceHandler.java
900 900
     * @throws InstantiationException
901 901
     * @throws VersionMismatch 
902 902
     */
903
    private void owner(String id) throws JiBXException, InvalidToken,
904
            ServiceFailure, NotFound, NotAuthorized, NotImplemented,
905
            InvalidRequest, IOException, InstantiationException,
906
            IllegalAccessException, VersionMismatch {
903
    private void owner(String id) 
904
        throws JiBXException, InvalidToken, ServiceFailure, NotFound, 
905
        NotAuthorized, NotImplemented, InvalidRequest, InstantiationException, 
906
        IllegalAccessException, VersionMismatch {
907 907

  
908 908
        Identifier pid = new Identifier();
909 909
        pid.setValue(id);
910 910

  
911 911
        long serialVersion = 0L;
912 912
        String serialVersionStr = null;
913
        String userIdStr = null;
914
        Subject userId = null;
915
        
916
        // Parse the params out of the multipart form data
917
        // Read the incoming data from its Mime Multipart encoding
918
        logMetacat.debug("Parsing rights holder parameters from the mime multipart entity");
919
        try {
920
            collectMultipartParams();
921
            
922
        } catch (FileUploadException e1) {
923
            String msg = "FileUploadException: Couldn't parse the mime multipart information: " +
924
            e1.getMessage();
925
            logMetacat.debug(msg);
926
            throw new ServiceFailure("4490", msg);
913 927

  
928
        } catch (IOException e1) {
929
            String msg = "IOException: Couldn't parse the mime multipart information: " +
930
            e1.getMessage();
931
            logMetacat.debug(msg);
932
            throw new ServiceFailure("4490", msg);
933
        
934
        } catch (Exception e1) {
935
            String msg = "Exception: Couldn't parse the mime multipart information: " +
936
            e1.getMessage();
937
            logMetacat.debug(msg);
938
            throw new ServiceFailure("4490", msg);
939

  
940
        }
941
        
914 942
        // get the serialVersion
915 943
        try {
916
            serialVersionStr = params.get("serialVersion")[0];
944
            serialVersionStr = multipartparams.get("serialVersion").get(0);
917 945
            serialVersion = new Long(serialVersionStr).longValue();
946
            
947
        } catch (NumberFormatException nfe) {
948
            String msg = "The 'serialVersion' must be provided as a positive integer and was not.";
949
            logMetacat.error(msg);
950
            throw new InvalidRequest("4442", msg);
951
                        
952
        } catch (NullPointerException e) {
953
            String msg = "The 'serialVersion' must be provided as a parameter and was not.";
954
            logMetacat.error(msg);
955
            throw new InvalidRequest("4442", msg);
956
            
957
        }
918 958

  
959
        // get the subject userId that will become the rights holder
960
        try {
961
            userIdStr = multipartparams.get("userId").get(0);
962
            userId = new Subject();
963
            userId.setValue(userIdStr);
964
                                    
919 965
        } catch (NullPointerException e) {
920 966
            String msg = "The 'serialVersion' must be provided as a parameter and was not.";
921 967
            logMetacat.error(msg);
922 968
            throw new InvalidRequest("4442", msg);
969
            
970
        }
923 971

  
972
        // set the rights holder
973
        Identifier retPid = CNodeService.getInstance(request).setRightsHolder(session, pid, userId, serialVersion);
974
        
975
        try {
976
            OutputStream out = response.getOutputStream();
977
            response.setStatus(200);
978
            response.setContentType("text/xml");
979
            TypeMarshaller.marshalTypeToOutputStream(retPid, out);
980
            
981
        } catch (IOException e) {
982
            String msg = "Couldn't write the identifier to the response output stream: " +
983
                e.getMessage();
984
            logMetacat.debug(msg);
985
            throw new ServiceFailure("4490", msg);
924 986
        }
925

  
926
        // get the subject
927
        String subjectStr = params.get("subject")[0];
928
        Subject subject = TypeMarshaller.unmarshalTypeFromStream(Subject.class,
929
                new ByteArrayInputStream(subjectStr.getBytes("UTF-8")));
930

  
931
        Identifier retPid = CNodeService.getInstance(request).setRightsHolder(session, pid, subject, serialVersion);
932
        OutputStream out = response.getOutputStream();
933
        response.setStatus(200);
934
        response.setContentType("text/xml");
935
        TypeMarshaller.marshalTypeToOutputStream(retPid, out);
936 987
    }
937 988

  
938 989
    /**

Also available in: Unified diff