Project

General

Profile

« Previous | Next » 

Revision 5362

Added by berkley over 14 years ago

listObjects is almost working. need to get the result set parsed when returned to CrudService.

View differences:

test/edu/ucsb/nceas/metacat/dataone/CrudServiceTest.java
31 31
import java.security.MessageDigest;
32 32

  
33 33
import edu.ucsb.nceas.MCTestCase;
34
import edu.ucsb.nceas.metacat.IdentifierManager;
34 35
import edu.ucsb.nceas.metacat.client.MetacatAuthException;
35 36
import edu.ucsb.nceas.metacat.client.MetacatException;
36 37
import edu.ucsb.nceas.metacat.client.MetacatInaccessibleException;
......
108 109
	        CrudService cs = CrudService.getInstance();
109 110
	        AuthToken token = getToken();
110 111
	        ObjectFormat of1 = ObjectFormat.convert("eml://ecoinformatics.org/eml-2.1.0");
111
	        ObjectFormat of2 = ObjectFormat.convert("text/plain");
112
	        ObjectFormat of2 = ObjectFormat.convert("eml://ecoinformatics.org/eml-2.0.0");
112 113
	        //create docs at different times
113 114
	        Date d1 = new Date();
114 115
	        Identifier id1 = createDoc(token, getTestDoc(), of1);
......
178 179
	    }
179 180
	    catch(Exception e)
180 181
	    {
182
	        //e.printStackTrace();
181 183
	        fail("Error in listObjects: " + e.getMessage());
182 184
	    }
183 185
	}
......
286 288
	        AuthToken token = getToken();
287 289
	        //run create
288 290
	        Identifier id = createDoc(token, getTestDoc());
291
	        //make these docs public for debugging purposes.
292
	        makeDocPublic(id, true);
289 293
            //compare the docs
290 294
            String gotDoc = getDoc(token, id);
291 295
            assertTrue(gotDoc.trim().equals(getTestDoc().trim()));
......
458 462
	}
459 463
	
460 464
	/**
465
	 *  make a document public in metacat by inserting an access document
466
	 * @param id
467
	 */
468
	private void makeDocPublic(Identifier id, boolean systemMetadataToo)
469
	  throws Exception
470
	{
471
	    CrudService cs = CrudService.getInstance();
472
	    IdentifierManager im = IdentifierManager.getInstance();
473
	    cs.setAccess(getToken(), id, "public", "read", "allow", "allowFirst");
474
	    if(systemMetadataToo)
475
	    {
476
	        String smidS = im.getSystemMetadataId(id.getValue());
477
	        Identifier smid = new Identifier();
478
	        smid.setValue(smidS);
479
	        cs.setAccess(getToken(), smid, "public", "read", "allow", "allowFirst");
480
	    }
481
	}
482
	
483
	/**
461 484
	 * print a header to start each test
462 485
	 */
463 486
	private void printTestHeader(String testName)
src/edu/ucsb/nceas/metacat/MetacatHandler.java
33 33
import java.io.OutputStreamWriter;
34 34
import java.io.PrintWriter;
35 35
import java.io.StringReader;
36
import java.io.ByteArrayOutputStream;
36 37
import java.io.Writer;
37 38
import java.net.MalformedURLException;
38 39
import java.net.URL;
......
168 169
                
169 170
                csv.flush();
170 171
                response.flushBuffer();
171
                
172
                 
172 173
                rs.close();
173 174
                
174 175
            } catch (SQLException e) {
......
905 906
        }
906 907
    }
907 908
    
909
    /**
910
     * 
911
     * @return
912
     */
913
    public void query(String metacatUrl, PrintWriter out, Hashtable<String, String[]>params, 
914
            String username, String[] groups, String sessionid)
915
      throws Exception
916
    {
917
        handleQuery(out, params, null, username, groups, sessionid);
918
    }
919
    
920
    /**
921
     * set the access permissions on the document specified
922
     */
923
    public void setAccess(String metacatUrl, String username, String docid, String principal, 
924
            String permission, String permissionType, String permissionOrder)
925
      throws Exception
926
    {
927
        Hashtable<String,String[]> params = new Hashtable();
928
        params.put("principal", new String[] {principal});
929
        params.put("permission", new String[] {permission});
930
        params.put("permType", new String[] {permissionType});
931
        params.put("permOrder", new String[] {permissionOrder});
932
        params.put("docid", new String[]{docid});
933
        
934
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
935
        PrintWriter out = new PrintWriter(baos);
936
        handleSetAccessAction(out, params, username, null, null);
937
        System.out.println("Set acces to " + permission + " for document " + docid);
938
    }
939
    
908 940
    /** read metadata or data from Metacat
909 941
     * @throws PropertyNotFoundException 
910 942
     * @throws ParseLSIDException 
src/edu/ucsb/nceas/metacat/DBQuery.java
366 366
      if (qformat != null && qformat.equals(MetacatUtil.XMLFORMAT))
367 367
      {
368 368
        //xml format
369
        response.setContentType("text/xml");
370
        createResultDocument(xmlquery, qspec, out, user, groups, useXMLIndex, 
369
        if(response != null)
370
            response.setContentType("text/xml");
371
        StringBuffer sb = createResultDocument(xmlquery, qspec, out, user, groups, useXMLIndex, 
371 372
          pagesize, pagestart, sessionid);
373
        System.out.println("result from createResultDocument: " + sb.toString());
372 374
      }//if
373 375
      else
374 376
      {
src/edu/ucsb/nceas/metacat/dataone/CrudService.java
282 282
    }
283 283
    
284 284
    /**
285
     * set the permission on the document
286
     * @param token
287
     * @param principal
288
     * @param permission
289
     * @param permissionType
290
     * @param permissionOrder
291
     * @return
292
     */
293
    public void setAccess(AuthToken token, Identifier id, String principal, String permission,
294
            String permissionType, String permissionOrder)
295
      throws ServiceFailure
296
    {
297
        try
298
        {
299
            IdentifierManager im = IdentifierManager.getInstance();
300
            String docid = im.getLocalId(id.getValue());
301
            final SessionData sessionData = getSessionData(token);
302
            String permNum = "0";
303
            if(permission == "read")
304
            {
305
                permNum = "4";
306
            }
307
            else if(permission == "write")
308
            {
309
                permNum = "6";
310
            }
311
            handler.setAccess(metacatUrl, sessionData.getUserName(), docid, 
312
                    principal, permNum, permissionType, permissionOrder);
313
        }
314
        catch(Exception e)
315
        {
316
            throw new ServiceFailure("1000", "Could not set access on the document with id " + id.getValue());
317
        }
318
    }
319
    
320
    /**
285 321
     *  Retrieve the list of objects present on the MN that match the calling 
286 322
     *  parameters. This method is required to support the process of Member 
287 323
     *  Node synchronization. At a minimum, this method should be able to 
......
312 348
      throws NotAuthorized, InvalidRequest, NotImplemented, ServiceFailure, InvalidToken
313 349
    {
314 350
      ObjectList ol = new ObjectList();
315
      //do an squery on metacat to return systemMetadata docs where 
316
      //sm.dateSysMetadataModified >= startTime
317
      //sm.dateSysMetadataModified <= endTime
318
      //further slice the returned dataset if replicaStatus is false.
319
      //if start != 0, return only the documents with index >= start
320
      //if the number of results is > count, return the first count docs
351
      final SessionData sessionData = getSessionData(token);
352
      try
353
      {
354
          params.clear();
355
          params.put("returndoctype", new String[] {"http://dataone.org/service/types/SystemMetadata/0.1"});
356
          params.put("qformat", new String[] {"xml"});
357
          //params.put("returnvalue", new String[] {"dateSysMetadataModified", "identifier", "objectFormat"});
358
          //params.put("casesensitive", new String[] {"false"});
359
          params.put("anyfield", new String[] {"%"});
360
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
361
          PrintWriter out = new PrintWriter(baos);
362
          System.out.println("listing objects");
363
          handler.query(metacatUrl, out, params, sessionData.getUserName(), 
364
                  sessionData.getGroupNames(), sessionData.getId());
365
          baos.close();
366
          System.out.println("result from query: " + baos.toString());
367
          
368
          //do an squery on metacat to return systemMetadata docs where 
369
          //sm.dateSysMetadataModified >= startTime
370
          //sm.dateSysMetadataModified <= endTime
371
          //further slice the returned dataset if replicaStatus is false.
372
          //if start != 0, return only the documents with index >= start
373
          //if the number of results is > count, return the first count docs
374
      }
375
      catch(Exception e)
376
      {
377
          e.printStackTrace();
378
          throw new ServiceFailure("1580", "Error retrieving ObjectList: " + e.getMessage());
379
      }
321 380
      return ol;
322 381
    }
323 382
    

Also available in: Unified diff