Project

General

Profile

« Previous | Next » 

Revision 6384

Update classes to use the DataONE 0.6.4 schema and types. Major changes involve using BigInteger vs long in SystemMetadata.size, and using ObjectFormatIdentifier rather than Object format.

View differences:

src/edu/ucsb/nceas/metacat/restservice/MNResourceHandler.java
572 572
        response.addHeader("checksum_algorithm", dr.getDataONE_Checksum().getAlgorithm().xmlValue());
573 573
        response.addHeader("content_length", dr.getContent_Length() + "");
574 574
        response.addHeader("last_modified", dateFormat.format(dr.getLast_Modified()));
575
        response.addHeader("format", dr.getDataONE_ObjectFormat().toString());
575
        response.addHeader("format", dr.getDataONE_ObjectFormatIdentifier().getValue());
576 576
       
577 577
    }
578 578
    
......
663 663
            SystemMetadata sm = MNodeService.getInstance().getSystemMetadata(session, id);
664 664
            
665 665
            //set the content type
666
            if (sm.getObjectFormat().getFmtid().getValue().trim().equals(
666
            if (sm.getFmtid().getValue().trim().equals(
667 667
            		ObjectFormatCache.getInstance().getFormat("text/csv").getFmtid().getValue()))
668 668
            {
669 669
                response.setContentType("text/csv");
670 670
                response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".csv");
671 671
            }
672
            else if (sm.getObjectFormat().getFmtid().getValue().trim().equals(
672
            else if (sm.getFmtid().getValue().trim().equals(
673 673
            		ObjectFormatCache.getInstance().getFormat("text/plain").getFmtid().getValue()))
674 674
            {
675 675
                response.setContentType("text/plain");
676 676
                response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".txt");
677 677
            } 
678
            else if (sm.getObjectFormat().getFmtid().getValue().trim().equals(
678
            else if (sm.getFmtid().getValue().trim().equals(
679 679
            		ObjectFormatCache.getInstance().getFormat("application/octet-stream").getFmtid().getValue()))
680 680
            {
681 681
                response.setContentType("application/octet-stream");
src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java
827 827
            response.addHeader("checksum_algorithm", dr.getDataONE_Checksum().getAlgorithm().xmlValue());
828 828
            response.addHeader("content_length", dr.getContent_Length() + "");
829 829
            response.addHeader("last_modified", dateFormat.format(dr.getLast_Modified()));
830
            response.addHeader("format", dr.getDataONE_ObjectFormat().toString());
830
            response.addHeader("format", dr.getDataONE_ObjectFormatIdentifier().getValue());
831 831
        }
832 832
        catch(InvalidRequest ir)
833 833
        {
......
1123 1123
                    SystemMetadata sm = MNodeService.getInstance().getSystemMetadata(session, id);
1124 1124
                    
1125 1125
                    //set the content type
1126
                    if(sm.getObjectFormat().getFmtid().getValue().trim().equals(
1126
                    if(sm.getFmtid().getValue().trim().equals(
1127 1127
                    		ObjectFormatCache.getInstance().getFormat("text/csv").getFmtid().getValue()))
1128 1128
                    {
1129 1129
                        response.setContentType("text/csv");
1130 1130
                        response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".csv");
1131 1131
                    }
1132
                    else if(sm.getObjectFormat().getFmtid().getValue().trim().equals(
1132
                    else if(sm.getFmtid().getValue().trim().equals(
1133 1133
                    		ObjectFormatCache.getInstance().getFormat("text/plain").getFmtid().getValue()))
1134 1134
                    {
1135 1135
                        response.setContentType("text/plain");
1136 1136
                        response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".txt");
1137 1137
                    } 
1138
                    else if(sm.getObjectFormat().getFmtid().getValue().trim().equals(
1138
                    else if(sm.getFmtid().getValue().trim().equals(
1139 1139
                    		ObjectFormatCache.getInstance().getFormat("application/octet-stream").getFmtid().getValue()))
1140 1140
                    {
1141 1141
                        response.setContentType("application/octet-stream");
src/edu/ucsb/nceas/metacat/restservice/CNResourceHandler.java
406 406
        SystemMetadata sm = CNodeService.getInstance().getSystemMetadata(session, id);
407 407
        
408 408
        //set the content type
409
        if(sm.getObjectFormat().getFmtid().getValue().trim().equals(
409
        if(sm.getFmtid().getValue().trim().equals(
410 410
        		ObjectFormatCache.getInstance().getFormat("text/csv").getFmtid().getValue()))
411 411
        {
412 412
            response.setContentType("text/csv");
413 413
            response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".csv");
414 414
        }
415
        else if(sm.getObjectFormat().getFmtid().getValue().trim().equals(
415
        else if(sm.getFmtid().getValue().trim().equals(
416 416
        		ObjectFormatCache.getInstance().getFormat("text/plain").getFmtid().getValue()))
417 417
        {
418 418
            response.setContentType("text/plain");
419 419
            response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".txt");
420 420
        } 
421
        else if(sm.getObjectFormat().getFmtid().getValue().trim().equals(
421
        else if(sm.getFmtid().getValue().trim().equals(
422 422
        		ObjectFormatCache.getInstance().getFormat("application/octet-stream").getFmtid().getValue()))
423 423
        {
424 424
            response.setContentType("application/octet-stream");
src/edu/ucsb/nceas/metacat/MetacatHandler.java
41 41
import java.io.StringReader;
42 42
import java.io.UnsupportedEncodingException;
43 43
import java.io.Writer;
44
import java.math.BigInteger;
44 45
import java.net.MalformedURLException;
45 46
import java.net.URL;
46 47
import java.security.NoSuchAlgorithmException;
......
81 82
import org.dataone.service.types.v1.Identifier;
82 83
import org.dataone.service.types.v1.NodeReference;
83 84
import org.dataone.service.types.v1.ObjectFormat;
85
import org.dataone.service.types.v1.ObjectFormatIdentifier;
84 86
import org.dataone.service.types.v1.Subject;
85 87
import org.dataone.service.types.v1.SystemMetadata;
86 88
import org.dataone.service.types.v1.util.ChecksumUtil;
......
3575 3577
      Hashtable<String, Object> docInfo = IdentifierManager.getInstance().getDocumentInfo(localId);
3576 3578
      //set the default object format
3577 3579
      String doctype = (String) docInfo.get("doctype");
3578
      ObjectFormat format = null;
3580
      ObjectFormatIdentifier fmtid = null;
3579 3581
      
3580 3582
      // set the object format, fall back to defaults
3581 3583
      try {
3582
	      format = ObjectFormatCache.getInstance().getFormat(doctype);
3584
	      fmtid = ObjectFormatCache.getInstance().getFormat(doctype).getFmtid();
3583 3585

  
3584 3586
      } catch (NotFound nfe) {
3585 3587
        
3586 3588
        try {
3587 3589
        	// format is not registered, use default
3588 3590
	        if (doctype.trim().equals("BIN")) {
3589
	        	format = ObjectFormatCache.getInstance().getFormat("application/octet-stream");
3591
	        	fmtid = ObjectFormatCache.getInstance().getFormat(
3592
	        			"application/octet-stream").getFmtid();
3590 3593
	        
3591 3594
	        } else {
3592
	        	format = ObjectFormatCache.getInstance().getFormat("text/plain");
3595
	        	fmtid = ObjectFormatCache.getInstance().getFormat("text/plain").getFmtid();
3593 3596
	        }
3594 3597
        
3595 3598
        } catch (NotFound nf) {
......
3600 3603

  
3601 3604
      }
3602 3605
      
3603
      sysMeta.setObjectFormat(format);
3604
      logMetacat.debug("The ObjectFormat for " + localId + " is " + format.toString());
3606
      sysMeta.setFmtid(fmtid);
3607
      logMetacat.debug("The ObjectFormat for " + localId + " is " + fmtid.getValue());
3605 3608
      
3606 3609
      // further parse EML documents to get data object format,
3607 3610
      // describes and describedBy information
3608
      if ( format == ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-2.0.0") ||
3609
           format == ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-2.0.1") ||
3610
           format == ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-2.1.0") ||
3611
           format == ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-2.1.1") ) {
3611
      if ( fmtid == ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-2.0.0").getFmtid() ||
3612
           fmtid == ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-2.0.1").getFmtid() ||
3613
           fmtid == ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-2.1.0").getFmtid() ||
3614
           fmtid == ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-2.1.1").getFmtid() ) {
3612 3615
        
3613 3616
        try {
3614 3617
        	
......
3668 3671
                      
3669 3672
                      // set object format
3670 3673
                      logMetacat.debug("Updating system metadata for " + dataGuid.getValue() + " to " + dataDocMimeType);
3671
                      ObjectFormat f = ObjectFormatCache.getInstance().getFormat(dataDocMimeType);
3672
                      if (f == null) {
3673
                    	  f = ObjectFormatCache.getInstance().getFormat("application/octet-stream");
3674
                      try {
3675
	                      ObjectFormatIdentifier fmt = 
3676
	                      ObjectFormatCache.getInstance().getFormat(dataDocMimeType).getFmtid();
3677
	                      dataSysMeta.setFmtid(fmt);
3678
                      
3679
                      } catch (NotFound nfe) {
3680
                      	logMetacat.debug("Couldn't find format identifier for: " +
3681
                      			dataDocMimeType + ". Setting it to application/octet-stream.");
3682
                        ObjectFormatIdentifier newFmtid = new ObjectFormatIdentifier();
3683
                        newFmtid.setValue("application/octet-stream");
3684
                      	
3674 3685
                      }
3675
                      dataSysMeta.setObjectFormat(f);
3676 3686
                  
3677 3687
            		  // update the values
3678 3688
            		  IdentifierManager.getInstance().updateSystemMetadata(dataSysMeta);
......
3735 3745
      
3736 3746
      //set the size
3737 3747
      inputStream = this.read(localId);
3738
      sysMeta.setSize(sizeOfStream(inputStream));
3748
      String sizeStr = new Long(sizeOfStream(inputStream)).toString();
3749
      sysMeta.setSize(new BigInteger(sizeStr));
3739 3750
      
3751
      
3740 3752
      //submitter
3741 3753
      Subject subject = new Subject();
3742 3754
      subject.setValue((String) docInfo.get("user_owner"));
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
496 496
    
497 497
    SystemMetadata sysmeta = getSystemMetadata(session, pid);
498 498
    DescribeResponse describeResponse = 
499
      new DescribeResponse(sysmeta.getObjectFormat(), 
499
      new DescribeResponse(sysmeta.getFmtid(), 
500 500
      sysmeta.getSize(), sysmeta.getDateSysMetadataModified(), sysmeta.getChecksum());
501 501
    
502 502
    return describeResponse;
......
858 858
			  // if we are filtering by format
859 859
			  if (formatId != null) {
860 860
				  SystemMetadata sysmeta = IdentifierManager.getInstance().getSystemMetadata(pid.getValue());
861
				  if (!sysmeta.getObjectFormat().getFmtid().getValue().equals(formatId.getValue())) {
861
				  if (!sysmeta.getFmtid().getValue().equals(formatId.getValue())) {
862 862
					  // does not match
863 863
					  continue;
864 864
				  }
......
959 959

  
960 960
  }
961 961

  
962
  /**
963
   * TODO: Implement this for D1 Tier 4 functionality
964
   */
965
	@Override
966
  public InputStream getReplica(Session session, Identifier pid)
967
    throws InvalidRequest, InvalidToken, NotAuthorized, NotImplemented,
968
    ServiceFailure, NotFound {
969

  
970
		throw new NotImplemented("4870", "isReplicationAuthorized not implemented");
971
  }
972

  
962 973
}
src/edu/ucsb/nceas/metacat/dataone/CNodeService.java
728 728
		return pid;
729 729
	}
730 730

  
731
	/**
732
	 * Verify that a replication task is authorized by comparing the target node's
733
	 * Subject (from the X.509 certificate-derived Session) with the list of 
734
	 * subjects in the known, pending replication tasks map.
735
	 * 
736
	 * @param originatingNodeSession - Session information that contains the 
737
	 *                                 identity of the calling user
738
	 * @param targetNodeSubject - Subject identifying the target node
739
	 * @param pid - the identifier of the object to be replicated
740
	 * @param replicatePermission - the execute permission to be granted
741
	 * 
742
	 * @throws ServiceFailure
743
	 * @throws NotImplemented
744
	 * @throws InvalidToken
745
	 * @throws NotAuthorized
746
	 * @throws InvalidRequest
747
	 * @throws NotFound
748
	 */
749
	@Override
750
  public boolean isReplicationAuthorized(Session originatingNodeSession, 
751
    Subject targetNodeSubject, Identifier pid, Permission replicatePermission) 
752
	  throws NotImplemented, NotAuthorized, InvalidToken, ServiceFailure, 
753
	  NotFound, InvalidRequest {
754

  
755
		throw new NotImplemented("4870", "isReplicationAuthorized not implemented");
756
		
757
  }
758

  
731 759
}
src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java
666 666
    boolean isScienceMetadata = false;
667 667
    
668 668
    try {
669
      objectFormat = ObjectFormatCache.getInstance().getFormat(sysmeta.getObjectFormat().getFmtid());
669
      objectFormat = ObjectFormatCache.getInstance().getFormat(sysmeta.getFmtid());
670 670
      isScienceMetadata = objectFormat.isScienceMetadata();
671 671
      
672 672
    } catch (InvalidRequest e) {
src/edu/ucsb/nceas/metacat/admin/upgrade/GenerateSystemMetadata.java
39 39
import org.dataone.service.exceptions.NotFound;
40 40
import org.dataone.service.exceptions.NotImplemented;
41 41
import org.dataone.service.exceptions.ServiceFailure;
42
import org.dataone.service.types.AuthToken;
42
import org.dataone.service.types.v1.Session;
43 43
import org.dataone.service.types.v1.SystemMetadata;
44 44

  
45 45
import edu.ucsb.nceas.metacat.AccessionNumberException;
......
93 93
     * @throws McdbDocNotFoundException 
94 94
     * @throws ServiceFailure 
95 95
     */
96
    public void generateMissingSystemMetadata(AuthToken token) 
96
    public void generateMissingSystemMetadata(Session session) 
97 97
    throws ServiceFailure, McdbDocNotFoundException, PropertyNotFoundException, InvalidToken, NotAuthorized, 
98 98
    NotFound, NotImplemented, InvalidRequest, NoSuchAlgorithmException, AccessionNumberException, SQLException 
99 99
    {
......
103 103
        for (String localId : idList) { 
104 104
            //for each id, add a system metadata doc
105 105
        	try {
106
        		generateMissingSystemMetadata(token, localId);
106
        		generateMissingSystemMetadata(session, localId);
107 107
        	} catch (Exception e) {
108 108
				log.error("Error generating system metadata for: " + localId, e);
109 109
			}
......
132 132
     * @throws PropertyNotFoundException 
133 133
     * @throws McdbDocNotFoundException 
134 134
     */
135
    public void generateMissingSystemMetadata(AuthToken token, String localId) 
135
    public void generateMissingSystemMetadata(Session session, String localId) 
136 136
    throws ServiceFailure, McdbDocNotFoundException, PropertyNotFoundException, InvalidToken, NotAuthorized,
137 137
    NotFound, NotImplemented, InvalidRequest, NoSuchAlgorithmException, AccessionNumberException, SQLException 
138 138
    {
src/edu/ucsb/nceas/metacat/IdentifierManager.java
24 24

  
25 25
package edu.ucsb.nceas.metacat;
26 26

  
27
import java.math.BigInteger;
27 28
import java.sql.PreparedStatement;
28 29
import java.sql.ResultSet;
29 30
import java.sql.SQLException;
......
108 109
    public SystemMetadata asSystemMetadata(Date dateUploaded, String rightsHolder,
109 110
            String checksum, String checksumAlgorithm, String originMemberNode,
110 111
            String authoritativeMemberNode, Date dateModified, String submitter, 
111
            String guid, String fmtidStr, long size) {
112
            String guid, String fmtidStr, BigInteger size) {
112 113
        SystemMetadata sysMeta = new SystemMetadata();
113 114

  
114 115
        Identifier sysMetaId = new Identifier();
......
133 134
        submitterSubject.setValue(submitter);
134 135
        sysMeta.setSubmitter(submitterSubject);
135 136
        try {
136
	        sysMeta.setObjectFormat(ObjectFormatCache.getInstance().getFormat(fmtidStr));
137
        	ObjectFormatIdentifier fmtid = 
138
        		ObjectFormatCache.getInstance().getFormat(fmtidStr).getFmtid();
139
        	sysMeta.setFmtid(fmtid);
137 140
        } catch (NotFound nfe) {
138 141
          logMetacat.error("The objectFormat " + fmtidStr +
139
          	" is not registered. Setting the default format.");
140
          ObjectFormat of = new ObjectFormat();
142
          	" is not registered. Setting the default format id.");
141 143
          ObjectFormatIdentifier fmtid = new ObjectFormatIdentifier();
142 144
          fmtid.setValue("application/octet-stream");
143
          of.setFmtid(fmtid);
144
          of.setFormatName("Octet Stream");
145
          sysMeta.setObjectFormat(of);
145
          sysMeta.setFmtid(fmtid);
146 146
        }
147 147
        sysMeta.setSize(size);
148 148
        
......
270 270
                Timestamp dateModified = rs.getTimestamp(8);
271 271
                String submitter = rs.getString(9);
272 272
                String fmtidStr = rs.getString(10);
273
                long size = new Long(rs.getString(11)).longValue();
273
                BigInteger size = new BigInteger(rs.getString(11));
274 274
                String obsoletes = rs.getString(12);
275 275
                String obsoletedBy = rs.getString(13);
276 276

  
......
297 297
                submitterSubject.setValue(submitter);
298 298
                sysMeta.setSubmitter(submitterSubject);
299 299
                try {
300
        	        sysMeta.setObjectFormat(ObjectFormatCache.getInstance().getFormat(fmtidStr));
300
                	ObjectFormatIdentifier fmtid = 
301
                		ObjectFormatCache.getInstance().getFormat(fmtidStr).getFmtid();
302
                	sysMeta.setFmtid(fmtid);
301 303
                } catch (NotFound nfe) {
302 304
                  logMetacat.error("The objectFormat " + fmtidStr +
303
                  	" is not registered. Setting the default format.");
304
                  ObjectFormat of = new ObjectFormat();
305
                  	" is not registered. Setting the default format id.");
305 306
                  ObjectFormatIdentifier fmtid = new ObjectFormatIdentifier();
306 307
                  fmtid.setValue("application/octet-stream");
307
                  of.setFmtid(fmtid);
308
                  of.setFormatName("Octet Stream");
309
                  sysMeta.setObjectFormat(of);
308
                  sysMeta.setFmtid(fmtid);
310 309
                }
311 310
                sysMeta.setSize(size);
312 311
                Identifier obsoletesId = new Identifier();
......
970 969
    private void updateSystemMetadataFields(long dateUploaded, String rightsHolder,
971 970
            String checksum, String checksumAlgorithm, String originMemberNode,
972 971
            String authoritativeMemberNode, long modifiedDate, String submitter, 
973
            String guid, String objectFormat, long size, boolean replicationAllowed,
972
            String guid, String objectFormat, BigInteger size, boolean replicationAllowed,
974 973
            int numberReplicas, String obsoletes, String obsoletedBy)
975 974
    {
976 975
        DBConnection dbConn = null;
......
1000 999
            stmt.setTimestamp(7, new java.sql.Timestamp(modifiedDate));
1001 1000
            stmt.setString(8, submitter);
1002 1001
            stmt.setString(9, objectFormat);
1003
            stmt.setString(10, new Long(size).toString());
1002
            stmt.setString(10, size.toString());
1004 1003
            stmt.setBoolean(11, replicationAllowed);
1005 1004
            stmt.setInt(12, numberReplicas);
1006 1005
            stmt.setString(13, obsoletes);
......
1146 1145
				sm.getAuthoritativeMemberNode() == null ? null: sm.getAuthoritativeMemberNode().getValue(), 
1147 1146
				sm.getDateSysMetadataModified() == null ? null: sm.getDateSysMetadataModified().getTime(),
1148 1147
				sm.getSubmitter() == null ? null: sm.getSubmitter().getValue(), 
1149
                sm.getIdentifier().getValue(),
1150
                sm.getObjectFormat() == null ? null: sm.getObjectFormat().getFmtid().getValue(),
1151
                sm.getSize(),
1152
                replicationAllowed, 
1153
                numberReplicas,
1154
                sm.getObsoletes() == null ? null:sm.getObsoletes().getValue(),
1155
                sm.getObsoletedBy() == null ? null: sm.getObsoletedBy().getValue());
1148
        sm.getIdentifier().getValue(),
1149
        sm.getFmtid() == null ? null: sm.getFmtid().getValue(),
1150
        sm.getSize(),
1151
        replicationAllowed, 
1152
        numberReplicas,
1153
        sm.getObsoletes() == null ? null:sm.getObsoletes().getValue(),
1154
        sm.getObsoletedBy() == null ? null: sm.getObsoletedBy().getValue());
1156 1155
        
1157 1156
        String guid = sm.getIdentifier().getValue();
1158 1157
        
......
1449 1448
                //String submitter = rs.getString(9);
1450 1449
                String fmtidStr = rs.getString(10);
1451 1450
                String sz = rs.getString(11);
1452
                long size = 0;
1451
                BigInteger size = new BigInteger("0");
1453 1452
                
1454 1453
                if (sz != null && !sz.trim().equals("")) {
1455
                    size = new Long(rs.getString(11)).longValue();
1454
                    size = new BigInteger(rs.getString(11));
1456 1455
                }
1457 1456
                
1458 1457
                ObjectInfo oi = new ObjectInfo();
......
1476 1475
                oi.setChecksum(cs);
1477 1476
                
1478 1477
                try {
1479
	                oi.setObjectFormat(ObjectFormatCache.getInstance().getFormat(fmtidStr));
1478
	                oi.setFmtid(ObjectFormatCache.getInstance().getFormat(fmtidStr).getFmtid());
1480 1479
                } catch (NotFound e) {
1481 1480
                	logMetacat.warn("could not find object format: " + fmtidStr, e);
1481

  
1482 1482
				}
1483 1483
                                
1484 1484
                oi.setSize(size);

Also available in: Unified diff