Project

General

Profile

« Previous | Next » 

Revision 7464

CN.search() id not implemented by metacat -- making that explicit and also testing for it.

View differences:

test/edu/ucsb/nceas/metacat/dataone/CNodeServiceTest.java
55 55
import org.dataone.service.types.v1.ObjectFormat;
56 56
import org.dataone.service.types.v1.ObjectFormatIdentifier;
57 57
import org.dataone.service.types.v1.ObjectFormatList;
58
import org.dataone.service.types.v1.ObjectInfo;
59 58
import org.dataone.service.types.v1.ObjectList;
60 59
import org.dataone.service.types.v1.Permission;
61 60
import org.dataone.service.types.v1.Replica;
......
274 273

  
275 274
	    try {
276 275
            Session session = getTestSession();
277
			Identifier guid = new Identifier();
278
			guid.setValue("testSearch." + System.currentTimeMillis());
279
			InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
280
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
281 276
			
282
			// save it
283
			Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, sysmeta);
284
			assertEquals(guid.getValue(), retGuid.getValue());
285
			// search for it
286
			ObjectList objectList = CNodeService.getInstance(request).search(session, null, null);
287
			// check it
288
			assertNotNull(objectList);
289
			boolean result = false;
290
			for (ObjectInfo objectInfo: objectList.getObjectInfoList()) {
291
				Identifier pid = objectInfo.getIdentifier();
292
				if (pid.getValue().equals(guid.getValue())) {
293
					result = true;
294
					break;
295
				}
277
			// search for objects, but expect a NotImplemented exception
278
			try {
279
				ObjectList objectList = CNodeService.getInstance(request).search(session, null, null);
280
			} catch (NotImplemented ne) {
281
				assertTrue(true);
296 282
			}
297
			assertTrue(result);
283
			fail("Metacat should not implement CN.search");
284
			
298 285
        } catch(Exception e) {
299 286
            fail("Unexpected error: " + e.getMessage());
300 287
        }
src/edu/ucsb/nceas/metacat/dataone/CNodeService.java
808 808
  }
809 809

  
810 810
  /**
811
   * Search the metadata catalog for identifiers that match the criteria
812
   * 
813
   * @param session - the Session object containing the credentials for the Subject
814
   * @param queryType - An identifier for the type of query expression 
815
   *                    provided in the query
816
   * @param query -  The criteria for matching the characteristics of the 
817
   *                 metadata objects of interest
818
   * 
819
   * @return objectList - the list of objects matching the criteria
820
   * 
821
   * @throws InvalidToken
822
   * @throws ServiceFailure
823
   * @throws NotAuthorized
824
   * @throws InvalidRequest
825
   * @throws NotImplemented
811
   * Metacat does not implement this method at the CN level
826 812
   */
827 813
  @Override
828 814
  public ObjectList search(Session session, String queryType, String query)
829 815
    throws InvalidToken, ServiceFailure, NotAuthorized, InvalidRequest,
830 816
    NotImplemented {
831 817

  
832
    ObjectList objectList = null;
833
    try {
834
        objectList = 
835
          IdentifierManager.getInstance().querySystemMetadata(
836
              null, //startTime, 
837
              null, //endTime,
838
              null, //objectFormat, 
839
              false, //replicaStatus, 
840
              0, //start, 
841
              -1 //count
842
              );
843
        
844
    } catch (Exception e) {
845
      throw new ServiceFailure("4310", "Error querying system metadata: " + e.getMessage());
846
    }
847

  
848
      return objectList;
849
      
850
    //throw new NotImplemented("4281", "search not implemented");
851
    
852
    // the code block below is from an older implementation
853
    
854
    /*  This block commented out because of the EcoGrid circular dependency.
855
         *  For now, query will not be supported until the circularity can be
856
         *  resolved, probably by moving the ecogrid query syntax transformers
857
         *  directly into the Metacat codebase.  MBJ 2010-02-03
858
         
859
        try {
860
            EcogridQueryParser parser = new EcogridQueryParser(request
861
                    .getReader());
862
            parser.parseXML();
863
            QueryType queryType = parser.getEcogridQuery();
864
            EcogridJavaToMetacatJavaQueryTransformer queryTransformer = 
865
                new EcogridJavaToMetacatJavaQueryTransformer();
866
            QuerySpecification metacatQuery = queryTransformer
867
                    .transform(queryType);
868

  
869
            DBQuery metacat = new DBQuery();
870

  
871
            boolean useXMLIndex = (new Boolean(PropertyService
872
                    .getProperty("database.usexmlindex"))).booleanValue();
873
            String xmlquery = "query"; // we don't care the query in resultset,
874
            // the query can be anything
875
            PrintWriter out = null; // we don't want metacat result, so set out null
876

  
877
            // parameter: queryspecification, user, group, usingIndexOrNot
878
            StringBuffer result = metacat.createResultDocument(xmlquery,
879
                    metacatQuery, out, username, groupNames, useXMLIndex);
880

  
881
            // create result set transfer       
882
            String saxparser = PropertyService.getProperty("xml.saxparser");
883
            MetacatResultsetParser metacatResultsetParser = new MetacatResultsetParser(
884
                    new StringReader(result.toString()), saxparser, queryType
885
                            .getNamespace().get_value());
886
            ResultsetType records = metacatResultsetParser.getEcogridResult();
887

  
888
            System.out
889
                    .println(EcogridResultsetTransformer.toXMLString(records));
890
            response.setContentType("text/xml");
891
            out = response.getWriter();
892
            out.print(EcogridResultsetTransformer.toXMLString(records));
893

  
894
        } catch (Exception e) {
895
            e.printStackTrace();
896
        }*/
897
    
898

  
818
		  throw new NotImplemented("4281", "Metacat does not implement CN.search");
819
	  
820
//    ObjectList objectList = null;
821
//    try {
822
//        objectList = 
823
//          IdentifierManager.getInstance().querySystemMetadata(
824
//              null, //startTime, 
825
//              null, //endTime,
826
//              null, //objectFormat, 
827
//              false, //replicaStatus, 
828
//              0, //start, 
829
//              1000 //count
830
//              );
831
//        
832
//    } catch (Exception e) {
833
//      throw new ServiceFailure("4310", "Error querying system metadata: " + e.getMessage());
834
//    }
835
//
836
//      return objectList;
837
		  
899 838
  }
900 839
  
901 840
  /**

Also available in: Unified diff