Project

General

Profile

« Previous | Next » 

Revision 6244

remove CrudService calls in favor of MNodeService

View differences:

src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java
53 53
import org.apache.maven.artifact.ant.shaded.IOUtil;
54 54
import org.dataone.client.MNode;
55 55
import org.dataone.client.ObjectFormatCache;
56
import org.dataone.client.auth.CertificateManager;
56 57
import org.dataone.mimemultipart.MultipartRequest;
57 58
import org.dataone.mimemultipart.MultipartRequestResolver;
58 59
import org.dataone.service.NodeListParser;
......
67 68
import org.dataone.service.exceptions.NotImplemented;
68 69
import org.dataone.service.exceptions.ServiceFailure;
69 70
import org.dataone.service.exceptions.UnsupportedType;
70
import org.dataone.service.types.AuthToken;
71
import org.dataone.service.types.AccessPolicy;
71 72
import org.dataone.service.types.Checksum;
72 73
import org.dataone.service.types.DescribeResponse;
73 74
import org.dataone.service.types.Event;
......
97 98
import edu.ucsb.nceas.metacat.MetaCatServlet;
98 99
import edu.ucsb.nceas.metacat.MetacatHandler;
99 100
import edu.ucsb.nceas.metacat.dataone.CNodeService;
100
import edu.ucsb.nceas.metacat.dataone.CrudService;
101 101
import edu.ucsb.nceas.metacat.dataone.HealthService;
102
import edu.ucsb.nceas.metacat.dataone.MNodeService;
102 103
import edu.ucsb.nceas.metacat.properties.PropertyService;
103 104
import edu.ucsb.nceas.metacat.service.SessionService;
104 105
import edu.ucsb.nceas.metacat.util.RequestUtil;
......
270 271
    private String[] groupNames;
271 272

  
272 273
    private Hashtable<String, String[]> params;
274
    
275
    // D1 certificate-based authentication
276
	private Session session;
273 277

  
274 278
    /**Initializes new instance by setting servlet context,request and response*/
275 279
    public ResourceHandler(ServletContext servletContext,
......
305 309
            System.out.println("resource: '" + resource + "'");
306 310
            System.out.println("resource_monitor: '" + RESOURCE_MONITOR + "'");
307 311
            boolean status = false;
312
            // load session the old way
308 313
            loadSessionData();
309

  
314
            
315
            // load session from certificate in request
316
            session = CertificateManager.getInstance().getSession(request);
317
            
318
            
310 319
            if (resource != null) {
311 320
                //resource = request.getServletPath().substring(1);
312 321

  
......
505 514
                        
506 515
                        Identifier guidid = new Identifier();
507 516
                        guidid.setValue(guid);
508
                        AuthToken token = new AuthToken(sessionId);
509 517
                        try
510 518
                        {
511 519
                            checksumAlgorithm = params.get("checksumAlgorithm")[0];
......
518 526
                                " with algorithm " + checksumAlgorithm);
519 527
                        try
520 528
                        {
521
                            Checksum c = CrudService.getInstance().getChecksum(token, guidid, checksumAlgorithm);
529
                            Checksum c = MNodeService.getInstance().getChecksum(session, guidid, checksumAlgorithm);
522 530
                            System.out.println("got checksum " + c.getValue());
523 531
                            response.setStatus(200);
524 532
                            System.out.println("serializing response");
......
759 767
            nr.setValue(sourceNode);
760 768
            sm.setOriginMemberNode(nr);
761 769
            //get the document
762
            AuthToken token = new AuthToken(sessionId);
763 770
            MNode mnode = new MNode(nodeUrl);
764 771
            //get the doc from the remote host
765
            InputStream docStream = mnode.get(new Session(), sm.getIdentifier());
772
            InputStream docStream = mnode.get(session, sm.getIdentifier());
766 773
            File outputTmpFile = getTempFile();
767 774
            System.out.println("wrote xml file to " + outputTmpFile.getAbsolutePath());
768 775
            FileOutputStream outputTmpFileStream = new FileOutputStream(outputTmpFile);
......
898 905
        }
899 906
        response.setStatus(200);
900 907
        response.setContentType("text/xml");
901
        AuthToken token = new AuthToken(sessionId);
902
        CrudService cs = CrudService.getInstance();
903 908
        Identifier id = new Identifier();
904 909
        id.setValue(guid);
905 910
        try
906 911
        {
907
            DescribeResponse dr = cs.describe(token, id);
912
            DescribeResponse dr = MNodeService.getInstance().describe(session, id);
908 913
            DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss.SZ");
909 914
            response.addHeader("guid", guid);
910 915
            response.addHeader("checksum", dr.getDataONE_Checksum().getValue());
......
953 958
            out = response.getOutputStream();
954 959
            response.setStatus(200);
955 960
            response.setContentType("text/xml");
956
            AuthToken token = new AuthToken(sessionId);
957 961
            String fromDateS = params.get("fromDate")[0];
958 962
            System.out.println("param fromDateS: " + fromDateS);
959 963
            Date fromDate = null;
......
978 982
            }
979 983
            System.out.println("fromDate: " + fromDate + " toDate: " + toDate);
980 984
            
985
            Integer start = null;
986
            Integer count = null;
987
            try {
988
            	start =  Integer.parseInt(params.get("start")[0]);
989
            } catch (Exception e) {
990
				logMetacat.warn("Could not parse start: " + e.getMessage());
991
			}
992
            try {
993
            	count =  Integer.parseInt(params.get("count")[0]);
994
            } catch (Exception e) {
995
				logMetacat.warn("Could not count start: " + e.getMessage());
996
			}
997
            
981 998
            System.out.println("calling crudservice.getLogRecords");
982
            Log log = CrudService.getInstance().getLogRecords(token, fromDate, toDate, event);
999
            Log log = MNodeService.getInstance().getLogRecords(session, fromDate, toDate, event, start, count);
983 1000
            serializeServiceType(Log.class, log, out);
984 1001
        }
985 1002
        catch(Exception e)
......
1180 1197
     * @param guid ID of data object to be read
1181 1198
     */
1182 1199
    private void getObject(String guid) {
1183
        CrudService cs = CrudService.getInstance();
1184
        cs.setParamsFromRequest(request);
1185
        AuthToken token = new AuthToken(sessionId);
1186 1200
        OutputStream out = null;
1187 1201
        try {
1188 1202
            out = response.getOutputStream();
......
1194 1208
                id.setValue(guid);
1195 1209
                try
1196 1210
                {
1197
                    if(token == null)
1198
                    {
1199
                        token = new AuthToken("Public");
1200
                    }
1201
                    SystemMetadata sm = cs.getSystemMetadata(token, id);
1202 1211
                    
1212
                    SystemMetadata sm = MNodeService.getInstance().getSystemMetadata(session, id);
1213
                    
1203 1214
                    //set the content type
1204 1215
                    if(sm.getObjectFormat().getFmtid().getValue().trim().equals(
1205 1216
                    		ObjectFormatCache.getInstance().getFormat("text/csv").getFmtid().getValue()))
......
1224 1235
                        response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".xml");
1225 1236
                    }
1226 1237
                    
1227
                    InputStream data = cs.get(token, id);
1238
                    InputStream data = MNodeService.getInstance().get(session, id);
1228 1239
                    IOUtils.copyLarge(data, response.getOutputStream());
1229 1240
                }
1230 1241
                catch(InvalidToken it)
......
1332 1343
                    }
1333 1344
                }
1334 1345
                //make the crud call
1335
                System.out.println("token: " + token + " startTime: " + startTime +
1346
                System.out.println("session: " + session + " startTime: " + startTime +
1336 1347
                        " endtime: " + endTime + " objectFormat: " + 
1337 1348
                        objectFormat + " replicaStatus: " + replicaStatus + 
1338 1349
                        " start: " + start + " count: " + count);
1339 1350
               
1340
                ObjectList ol = cs.listObjects(token, startTime, endTime, 
1351
                ObjectList ol = MNodeService.getInstance().listObjects(session, startTime, endTime, 
1341 1352
                        objectFormat, replicaStatus, start, count);
1342 1353
                
1343 1354
                StringReader sr = new StringReader(ol.toString());                
......
1400 1411
     * @param guid ID of data object to be read
1401 1412
     */
1402 1413
    private void getSystemMetadataObject(String guid) {
1403
        CrudService cs = CrudService.getInstance();
1404
        cs.setParamsFromRequest(request);
1405
        AuthToken token = new AuthToken(sessionId);
1406 1414
        OutputStream out = null;
1407 1415
        try {
1408 1416
            response.setContentType("text/xml");
......
1410 1418
            out = response.getOutputStream();
1411 1419
            Identifier id = new Identifier();
1412 1420
            id.setValue(guid);
1413
            SystemMetadata sysmeta = cs.getSystemMetadata(token, id);
1421
            SystemMetadata sysmeta = MNodeService.getInstance().getSystemMetadata(session, id);
1414 1422
            
1415 1423
            // Serialize and write it to the output stream
1416 1424
            try {
......
1767 1775
                IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
1768 1776
                SystemMetadata smd = (SystemMetadata) uctx.unmarshalDocument(sysmeta, null);
1769 1777

  
1770
                CrudService cs = CrudService.getInstance();
1771
                AuthToken token = new AuthToken(sessionId); 
1772
                cs.setParamsFromRequest(request);
1773 1778
                Identifier id = new Identifier();
1774 1779
                id.setValue(pid);
1775 1780
                System.out.println("creating object with pid " + id.getValue());
1776
                Identifier rId = cs.create(token, id, object, smd);
1781
                Identifier rId = MNodeService.getInstance().create(session, id, object, smd);
1777 1782
                serializeServiceType(Identifier.class, rId, out);
1778 1783
                
1779 1784
            } else if (action.equals(FUNCTION_NAME_UPDATE)) { //handle updates
......
1796 1801
                newPid.setValue(newPidString);
1797 1802
                obsoletedPid.setValue(pid);
1798 1803
               
1799
            	
1800
                CrudService cs = CrudService.getInstance();
1801
                AuthToken token = new AuthToken(sessionId);
1802

  
1803 1804
                logMetacat.debug("Commence update...");
1804 1805
                
1805 1806
                //get the systemmetadata
......
1808 1809
                IUnmarshallingContext uctx = bfact.createUnmarshallingContext();
1809 1810
                SystemMetadata smd = (SystemMetadata) uctx.unmarshalDocument(sysmeta, null);
1810 1811

  
1811
                cs.setParamsFromRequest(request);
1812
                Identifier rId = cs.update(token, newPid, object, obsoletedPid, smd);
1812
                Identifier rId = MNodeService.getInstance().update(session, newPid, object, obsoletedPid, smd);
1813 1813
                serializeServiceType(Identifier.class, rId, out);
1814 1814
            } else {
1815 1815
                throw new InvalidRequest("1000", "Operation must be create or update.");
......
1884 1884
            serializeException(nf, out);
1885 1885
        }
1886 1886
       
1887
        AuthToken token = new AuthToken(sessionId);
1888
        CrudService cs = CrudService.getInstance();
1887
        
1889 1888
        Identifier id = new Identifier();
1890 1889
        id.setValue(guid);
1891 1890
        try
1892 1891
        {
1893 1892
            System.out.println("Calling delete");
1894
            cs.delete(token, id);
1893
            MNodeService.getInstance().delete(session, id);
1895 1894
            serializeServiceType(Identifier.class, id, out);
1896 1895
        } 
1897 1896
        catch (NotAuthorized e) {
......
1921 1920
    
1922 1921
    /**
1923 1922
     * set the access perms on a document
1924
     * @throws IOException
1923
     * @throws Exception
1925 1924
     */
1926 1925
    private void setaccess() throws Exception
1927 1926
    {
......
1930 1929
            String guid = params.get("guid")[0];
1931 1930
            Identifier id = new Identifier();
1932 1931
            id.setValue(guid);
1933
            AuthToken token = new AuthToken(sessionId);
1934
            String principal = params.get("principal")[0];
1935
            String permission = params.get("permission")[0];
1936
            String permissionType = params.get("permissionType")[0];
1937
            String permissionOrder = params.get("permissionOrder")[0];
1938
            String setSystemMetadata = params.get("setsystemmetadata")[0];
1939
            boolean ssm = false;
1940
            if(setSystemMetadata.equals("true") || setSystemMetadata.equals("TRUE") ||
1941
                    setSystemMetadata.equals("yes"))
1942
            {
1943
                ssm = true;
1944
            }
1945
            CrudService cs = CrudService.getInstance();
1946
            //TODO: remove the setsystemmetadata param and set this so the systemmetadata always gets set
1947
            cs.setAccess(token, id, principal, permission, permissionType, permissionOrder, ssm);
1932
            String accesspolicy = params.get("accesspolicy")[0];
1933
            AccessPolicy accessPolicy = (AccessPolicy) deserializeServiceType(AccessPolicy.class, new ByteArrayInputStream(accesspolicy.getBytes("UTF-8")));
1934
            MNodeService.getInstance().setAccessPolicy(session, id, accessPolicy);
1948 1935
        }
1949 1936
        catch(Exception e)
1950 1937
        {

Also available in: Unified diff