Project

General

Profile

Revision 6622

upgrade to 1.0.1-SNAPSHOT DataONE jars

View differences:

test/edu/ucsb/nceas/metacat/dataone/MockCNode.java
59 59
    @Override
60 60
    public boolean hasReservation(Session session, Identifier pid) 
61 61
    	throws InvalidToken, ServiceFailure, NotFound,
62
        NotAuthorized, IdentifierNotUnique, InvalidRequest, NotImplemented {
62
        NotAuthorized, IdentifierNotUnique, NotImplemented {
63 63
    	// always return true
64 64
        return true;
65 65
    }
test/edu/ucsb/nceas/metacat/dataone/CNodeServiceTest.java
285 285
			Identifier guid = new Identifier();
286 286
			guid.setValue("testReserveIdentifier." + System.currentTimeMillis());
287 287
			// reserve it
288
			boolean result = CNodeService.getInstance(request).reserveIdentifier(session, guid);
289
			assertTrue(result);
288
			Identifier resultPid = CNodeService.getInstance(request).reserveIdentifier(session, guid);
289
			assertNotNull(resultPid);
290
			assertEquals(guid.getValue(), resultPid.getValue());
290 291
	    } catch(NotImplemented ni) {
291 292
        	// this is not implemented in Metacat
292 293
            assertTrue(true);	
......
518 519
	    objectFormatList = CNodeService.getInstance(request).listFormats();
519 520
	  	assertTrue(objectFormatList.getTotal() >= formatsCount);
520 521
  	
521
  	} catch (InvalidRequest e) {
522
  		fail("Could not get the object format list: " + e.getMessage());
523
    
524 522
  	} catch (ServiceFailure e) {
525 523
  		fail("Could not get the object format list: " + e.getMessage());
526 524

  
527
    } catch (NotFound e) {
528
  		fail("Could not get the object format list: " + e.getMessage());
529

  
530 525
    } catch (InsufficientResources e) {
531 526
  		fail("Could not get the object format list: " + e.getMessage());
532 527

  
......
565 560
    } catch (NotFound nfe) {     
566 561
    	fail("The format " + knownFormat + " was not found: " + nfe.getMessage());
567 562
    	
568
    } catch (InvalidRequest ire) {
569
    	fail("The format " + knownFormat + " was not found: " + ire.getMessage());
570

  
571 563
    } catch (ServiceFailure sfe) {
572 564
    	fail("The format " + knownFormat + " was not found: " + sfe.getMessage());
573 565

  
src/edu/ucsb/nceas/metacat/restservice/CNResourceHandler.java
29 29
import java.io.InputStream;
30 30
import java.io.OutputStream;
31 31
import java.util.Date;
32
import java.util.Enumeration;
32 33
import java.util.Map;
33 34

  
34 35
import javax.servlet.ServletContext;
......
60 61
import org.dataone.service.types.v1.ObjectFormat;
61 62
import org.dataone.service.types.v1.ObjectFormatIdentifier;
62 63
import org.dataone.service.types.v1.ObjectFormatList;
64
import org.dataone.service.types.v1.ObjectList;
63 65
import org.dataone.service.types.v1.ObjectLocationList;
64 66
import org.dataone.service.types.v1.Permission;
65 67
import org.dataone.service.types.v1.Replica;
66 68
import org.dataone.service.types.v1.ReplicationPolicy;
67 69
import org.dataone.service.types.v1.ReplicationStatus;
68
import org.dataone.service.types.v1.Session;
69 70
import org.dataone.service.types.v1.Subject;
70 71
import org.dataone.service.types.v1.SystemMetadata;
71 72
import org.dataone.service.util.DateTimeMarshaller;
......
242 243
                    	if (extra != null) {
243 244
                    		getObject(extra);
244 245
                    	} else {
245
                    		query();
246
                    		listObjects();
246 247
                    	}
247 248
                        status = true;
248 249
                    } else if (httpVerb == POST) {
......
666 667
			logMetacat.warn("pid not specified");
667 668
		} 
668 669
		// call the implementation
669
		boolean result = CNodeService.getInstance(request).reserveIdentifier(session, pid);
670
		Identifier resultPid = CNodeService.getInstance(request).reserveIdentifier(session, pid);
670 671
		OutputStream out = response.getOutputStream();
671 672
		response.setStatus(200);
672 673
		response.setContentType("text/xml");
673
		// nothing to send back
674
		// send back the reserved pid
675
		TypeMarshaller.marshalTypeToOutputStream(resultPid, out);
674 676
    }
675 677
    
676 678
    /**
......
874 876
    }
875 877
    
876 878
    /**
877
     *	Pass to the CN search service
879
     *	List the objects
878 880
     *
879 881
     * @throws NotImplemented 
880 882
     * @throws InvalidRequest 
881 883
     * @throws NotAuthorized 
882 884
     * @throws ServiceFailure 
883 885
     * @throws InvalidToken 
886
     * @throws NotFound 
887
     * @throws IOException 
888
     * @throws JiBXException
884 889
     * @throws Exception
885 890
     */
886
    private void query() 
887
        throws InvalidToken, ServiceFailure, NotAuthorized, InvalidRequest, NotImplemented {
888
        
889
    	  String query = null;
890
		    String queryType = null;
891
		    try {
892
		    	query = params.get("query")[0];
893
		    } catch (Exception e) {
894
		    	logMetacat.warn("query not specified");
895
		    }
896
		    try {
897
		    	String qt = params.get("queryType")[0];
898
		    	queryType = qt;
899
		    } catch (Exception e) {
900
		    	logMetacat.warn("queryType not specified");
901
		    }
902
		    
903
        	// expecting to throw NotImplemented
904
		    CNodeService.getInstance(request).search(session, queryType, query);
905
    }
891
    private void listObjects() throws InvalidToken, ServiceFailure, NotAuthorized,
892
			InvalidRequest, NotImplemented, NotFound, IOException,
893
			JiBXException {
894

  
895
		Date startTime = null;
896
		Date endTime = null;
897
		ObjectFormat objectFormat = null;
898
		boolean replicaStatus = false;
899
		int start = 0;
900
		int count = -1;
901
		Enumeration<String> paramlist = request.getParameterNames();
902
		while (paramlist.hasMoreElements()) {
903
			// parse the params and make the call
904
			String name = paramlist.nextElement();
905
			String[] value = request.getParameterValues(name);
906

  
907
			if (name.equals("startTime") && value != null) {
908
				try {
909
					startTime = DateTimeMarshaller.deserializeDateToUTC(value[0]);
910
				} catch (Exception e) { 
911
					// if we can't parse it, just don't use the startTime param
912
					logMetacat.warn("Could not parse startTime: " + value[0]);
913
					startTime = null;
914
				}
915
			} else if (name.equals("endTime") && value != null) {
916
				try {
917
					endTime = DateTimeMarshaller.deserializeDateToUTC(value[0]);
918
				} catch (Exception e) { 
919
					// if we can't parse it, just don't use the endTime param
920
					logMetacat.warn("Could not parse endTime: " + value[0]);
921
					endTime = null;
922
				}
923
			} else if (name.equals("objectFormat") && value != null) {
924
				objectFormat = ObjectFormatCache.getInstance().getFormat(value[0]);
925
			} else if (name.equals("replicaStatus") && value != null) {
926
				replicaStatus = Boolean.parseBoolean(value[0]);
927
			} else if (name.equals("start") && value != null) {
928
				start = Integer.valueOf(value[0]);
929
			} else if (name.equals("count") && value != null) {
930
				count = Integer.valueOf(value[0]);
931
			}
932
		}
933
		// make the call
934
		logMetacat.debug("session: " + session + " startTime: " + startTime
935
				+ " endtime: " + endTime + " objectFormat: " + objectFormat
936
				+ " replicaStatus: " + replicaStatus + " start: " + start
937
				+ " count: " + count);
938

  
939
		ObjectFormatIdentifier fmtid = null;
940
		if (objectFormat != null) {
941
			fmtid = objectFormat.getFormatId();
942
		}
943
		
944
		// get the list
945
		ObjectList ol = 
946
			CNodeService.getInstance(request).listObjects(session,
947
				startTime, endTime, fmtid, replicaStatus, start, count);
948

  
949
		// send it
950
		OutputStream out = response.getOutputStream();
951
		response.setStatus(200);
952
		response.setContentType("text/xml");
953
		// Serialize and write it to the output stream
954
		TypeMarshaller.marshalTypeToOutputStream(ol, out);
955
	}
906 956
    
907 957
    /**
908 958
     * Pass the request to get node replication authorization to CNodeService
src/edu/ucsb/nceas/metacat/dataone/ObjectFormatService.java
97 97
	 * @return objectFormat - the desired object format
98 98
	 */
99 99
	public ObjectFormat getFormat(ObjectFormatIdentifier fmtid)
100
			throws InvalidRequest, ServiceFailure, NotFound,
100
			throws ServiceFailure, NotFound,
101 101
			InsufficientResources, NotImplemented {
102 102

  
103 103
		logMetacat.debug("CNCoreImpl.getFormat() called.");
......
129 129
	 * 
130 130
	 * @return objectFormatList - the list of object formats
131 131
	 */
132
	public ObjectFormatList listFormats() throws InvalidRequest,
133
			ServiceFailure, NotFound, InsufficientResources, NotImplemented {
132
	public ObjectFormatList listFormats() throws ServiceFailure, InsufficientResources, NotImplemented {
134 133

  
135 134
		objectFormatList = getCachedList();
136 135

  
......
155 154
	/**
156 155
	 * Get the object format list cached in Metacat
157 156
	 */
158
	private ObjectFormatList getCachedList() throws NotFound, ServiceFailure {
157
	private ObjectFormatList getCachedList() throws ServiceFailure {
159 158

  
160 159
		ObjectFormatList objectFormatList = null;
161 160

  
......
217 216
				}
218 217

  
219 218
			} else {
220
				throw new NotFound("4843",
219
				throw new ServiceFailure("4841",
221 220
						"The object formats collection could not "
222 221
								+ "be found at this node.");
223 222
			}
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
53 53
import org.dataone.service.exceptions.ServiceFailure;
54 54
import org.dataone.service.exceptions.SynchronizationFailed;
55 55
import org.dataone.service.exceptions.UnsupportedType;
56
import org.dataone.service.exceptions.VersionMismatch;
56 57
import org.dataone.service.mn.tier1.v1.MNCore;
57 58
import org.dataone.service.mn.tier1.v1.MNRead;
58 59
import org.dataone.service.mn.tier2.v1.MNAuthorization;
......
465 466
        } catch (NotFound e) {
466 467
            // TODO Auto-generated catch block
467 468
            e.printStackTrace();
468
        }
469
        } catch (VersionMismatch e) {
470
			// TODO Auto-generated catch block
471
			e.printStackTrace();
472
		}
469 473
        return result;
470 474

  
471 475
    }
src/edu/ucsb/nceas/metacat/dataone/CNodeService.java
355 355
   * @throws ServiceFailure
356 356
   * @throws NotAuthorized
357 357
   * @throws NotFound
358
   * @throws InvalidRequest
359 358
   * @throws NotImplemented
360 359
   */
361 360
  @Override
362 361
  public Checksum getChecksum(Session session, Identifier pid)
363 362
    throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, 
364
    InvalidRequest, NotImplemented {
363
    NotImplemented {
365 364
        
366 365
    if (!isAuthorized(session, pid, Permission.READ)) {
367 366
        throw new NotAuthorized("1400", Permission.READ + " not allowed on " + pid.getValue());  
......
396 395
   * 
397 396
   * @return objectLocationList - the list of nodes known to contain the object
398 397
   * 
399
   * @throws InvalidRequest
400 398
   * @throws InvalidToken
401 399
   * @throws ServiceFailure
402 400
   * @throws NotAuthorized
......
405 403
   */
406 404
  @Override
407 405
  public ObjectLocationList resolve(Session session, Identifier pid)
408
    throws InvalidRequest, InvalidToken, ServiceFailure, NotAuthorized,
406
    throws InvalidToken, ServiceFailure, NotAuthorized,
409 407
    NotFound, NotImplemented {
410 408

  
411 409
    throw new NotImplemented("4131", "resolve not implemented");
......
511 509
   * 
512 510
   * @return objectFormat - the object format requested
513 511
   * 
514
   * @throws InvalidRequest
515 512
   * @throws ServiceFailure
516 513
   * @throws NotFound
517 514
   * @throws InsufficientResources
......
519 516
   */
520 517
  @Override
521 518
  public ObjectFormat getFormat(ObjectFormatIdentifier fmtid)
522
    throws InvalidRequest, ServiceFailure, NotFound, InsufficientResources,
519
    throws ServiceFailure, NotFound, InsufficientResources,
523 520
    NotImplemented {
524 521
     
525 522
      return ObjectFormatService.getInstance().getFormat(fmtid);
......
533 530
   * @return objectFormatList - The list of object formats registered in 
534 531
   *                            the DataONE Object Format Vocabulary
535 532
   * 
536
   * @throws InvalidRequest
537 533
   * @throws ServiceFailure
538 534
   * @throws NotImplemented
539
   * @throws NotFound
540 535
   * @throws InsufficientResources
541 536
   */
542 537
  @Override
543 538
  public ObjectFormatList listFormats() 
544
    throws InvalidRequest, ServiceFailure, NotFound, InsufficientResources, 
539
    throws ServiceFailure, InsufficientResources, 
545 540
    NotImplemented {
546 541

  
547 542
    return ObjectFormatService.getInstance().listFormats();
......
635 630
          pid.getValue(), "registerSystemMetadata");
636 631
      return pid;
637 632
  }
638

  
639
  /**
640
   * Provides a mechanism for updating system metadata independently of its 
641
   * associated object
642
    * 
643
   * @param session - the Session object containing the credentials for the Subject
644
   * @param pid - The identifier of the system metadata
645
   * @param sysmeta - The system metadata to be registered
646
   * 
647
   * @return true if the update succeeds
648
   * 
649
   * @throws NotImplemented
650
   * @throws NotAuthorized
651
   * @throws ServiceFailure
652
   * @throws InvalidRequest
653
   * @throws InvalidSystemMetadata
654
   * @throws NotFound
655
   */
656
  @Override
657
  public boolean updateSystemMetadata(Session session, Identifier guid,
658
      SystemMetadata sysmeta) 
659
      throws NotImplemented, NotAuthorized, ServiceFailure, InvalidRequest, 
660
      InvalidSystemMetadata, NotFound {
661

  
662
      // TODO: control who can call this?
663
      if (session == null) {
664
          //TODO: many of the thrown exceptions do not use the correct error codes
665
          //check these against the docs and correct them
666
          throw new NotAuthorized("4861", "No Session - could not authorize for update." +
667
                  "  If you are not logged in, please do so and retry the request.");
668
      }
669
      
670
      // verify that guid == SystemMetadata.getIdentifier()
671
      logMetacat.debug("Comparing guid|sysmeta_guid: " + guid.getValue() + "|" + 
672
          sysmeta.getIdentifier().getValue());
673
      if (!guid.getValue().equals(sysmeta.getIdentifier().getValue())) {
674
          throw new InvalidRequest("4863", 
675
              "GUID in method call (" + guid.getValue() + 
676
              ") does not match GUID in system metadata (" +
677
              sysmeta.getIdentifier().getValue() + ").");
678
      }
679

  
680
      logMetacat.debug("Checking if identifier exists...");
681
      // Check that the identifier exists
682
      if (!IdentifierManager.getInstance().identifierExists(guid.getValue())) {
683
          throw new NotFound("000", 
684
              "GUID does not exist");
685
      }
686

  
687
      // update the system metadata into the object store
688
      logMetacat.debug("Starting to update SystemMetadata...");
689
      
690
      // update system metadata
691
      try {
692
    	    HazelcastService.getInstance().getSystemMetadataMap().lock(sysmeta.getIdentifier());
693
          SystemMetadata currentSysMeta = 
694
              HazelcastService.getInstance().getSystemMetadataMap().get(sysmeta.getIdentifier());
695
          
696
          // only update if the requester has the most current system metadata
697
          if (sysmeta.getSerialVersion().compareTo(currentSysMeta.getSerialVersion()) != 0 ) {
698
              String msg = "The serial version of the system metadata " + 
699
                  "to be updated does not equal the serial version of the current " +
700
                  "system metadata for identifier " + guid + ". Ensure that the " +
701
                  "copy is the most current before updating.";
702
              logMetacat.warn(msg);
703
              HazelcastService.getInstance().getSystemMetadataMap().unlock(sysmeta.getIdentifier());
704
              throw new InvalidRequest("4913", msg);
705
              
706
          }
707
          
708
          sysmeta.setSerialVersion(currentSysMeta.getSerialVersion().add(BigInteger.ONE));
709
          sysmeta.setDateSysMetadataModified(Calendar.getInstance().getTime());
710
          HazelcastService.getInstance().getSystemMetadataMap().put(sysmeta.getIdentifier(), sysmeta);
711
    	    HazelcastService.getInstance().getSystemMetadataMap().unlock(sysmeta.getIdentifier());
712
    	    
713
      } catch (Exception e) {
714
    	throw new ServiceFailure("4852", e.getMessage());
715
    	
716
    	} finally {
717
    	    HazelcastService.getInstance().getSystemMetadataMap().unlock(sysmeta.getIdentifier());
718
    	  
719
    	}
720
      
721
      logMetacat.debug("Returning from updateSystemMetadata");
722
      EventLog.getInstance().log(request.getRemoteAddr(), 
723
                                 request.getHeader("User-Agent"), 
724
                                 session.getSubject().getValue(), 
725
                                 guid.getValue(), "updateSystemMetadata");
726
      return true;
727
  }
728 633
  
729 634
  /**
730 635
   * Given an optional scope and format, reserves and returns an identifier 
......
754 659
   * @throws NotImplemented
755 660
   */
756 661
  @Override
757
  public boolean reserveIdentifier(Session session, Identifier pid)
662
  public Identifier reserveIdentifier(Session session, Identifier pid)
758 663
  throws InvalidToken, ServiceFailure,
759 664
        NotAuthorized, IdentifierNotUnique, NotImplemented, InvalidRequest {
760 665

  
......
1185 1090
      return true;
1186 1091
      
1187 1092
  }
1093
  
1094
  	@Override
1095
  	public ObjectList listObjects(Session session, Date startTime, 
1096
            Date endTime, ObjectFormatIdentifier formatid, Boolean replicaStatus,
1097
            Integer start, Integer count)
1098
			throws InvalidRequest, InvalidToken, NotAuthorized, NotImplemented,
1099
			ServiceFailure {
1100
  		
1101
  		ObjectList objectList = null;
1102
        try {
1103
            objectList = IdentifierManager.getInstance().querySystemMetadata(startTime, endTime, formatid, replicaStatus, start, count);
1104
        } catch (Exception e) {
1105
            throw new ServiceFailure("1580", "Error querying system metadata: " + e.getMessage());
1106
        }
1107

  
1108
        return objectList;
1109
	}
1188 1110
}

Also available in: Unified diff