Project

General

Profile

« Previous | Next » 

Revision 9359

Added by Jing Tao about 9 years ago

Add contrains for the v1/v2.registerSystemMetadata method. See https://redmine.dataone.org/issues/7380

View differences:

src/edu/ucsb/nceas/metacat/dataone/CNodeService.java
1416 1416
          // insert the system metadata into the object store
1417 1417
          logMetacat.debug("Starting to insert SystemMetadata...");
1418 1418
          try {
1419
              sysmeta.setSerialVersion(BigInteger.ONE);
1420
              sysmeta.setDateSysMetadataModified(Calendar.getInstance().getTime());
1419
              //for the object whose authoriative mn is v1. we need reset the modification date.
1420
              //d1-sync already set the serial version. so we don't need do again.
1421
              D1NodeVersionChecker checker = new D1NodeVersionChecker(sysmeta.getAuthoritativeMemberNode());
1422
              String version = checker.getVersion("MNStorage");
1423
              if(version != null && version.equalsIgnoreCase(D1NodeVersionChecker.V1)) {
1424
                  sysmeta.setDateSysMetadataModified(Calendar.getInstance().getTime());
1425
              }
1421 1426
              HazelcastService.getInstance().getSystemMetadataMap().put(sysmeta.getIdentifier(), sysmeta);
1422 1427
              
1423 1428
          } catch (RuntimeException e) {
src/edu/ucsb/nceas/metacat/dataone/v1/CNodeService.java
24 24
package edu.ucsb.nceas.metacat.dataone.v1;
25 25

  
26 26
import java.io.InputStream;
27
import java.math.BigInteger;
27 28
import java.sql.SQLException;
28 29
import java.util.Date;
29 30
import java.util.List;
......
73 74
import org.dataone.service.types.v2.TypeFactory;
74 75

  
75 76
import edu.ucsb.nceas.metacat.IdentifierManager;
77
import edu.ucsb.nceas.metacat.dataone.D1NodeVersionChecker;
76 78
import edu.ucsb.nceas.metacat.dataone.convert.LogV2toV1Converter;
77 79
import edu.ucsb.nceas.metacat.properties.PropertyService;
78 80

  
......
623 625
	public Identifier registerSystemMetadata(Session session, Identifier pid,
624 626
			SystemMetadata sysmeta) throws NotImplemented, NotAuthorized,
625 627
			ServiceFailure, InvalidRequest, InvalidSystemMetadata, InvalidToken {
628
	    if (pid == null || pid.getValue().trim().equals("")) {
629
	        throw new InvalidRequest("4863", "The pid should not be null in the register system metadata request");
630
	    }
631
	    if(sysmeta == null) {
632
	        throw new InvalidRequest("4863", "The system metadata object should not be null in the register system metadata request for the pid"+pid.getValue());
633
	    }
626 634
		//convert sysmeta to newer version
627 635
		org.dataone.service.types.v2.SystemMetadata v2Sysmeta = null;
628 636
		try {
629 637
			v2Sysmeta = TypeFactory.convertTypeFromType(sysmeta, org.dataone.service.types.v2.SystemMetadata.class);
638
			
630 639
		} catch (Exception e) {
631 640
			// report as service failure
632 641
			ServiceFailure sf = new ServiceFailure("1030", e.getMessage());
633 642
			sf.initCause(e);
634 643
			throw sf;
635 644
		}
636
		
645
		//this method will apply to the objects whose authoritative mn is v1.
646
        D1NodeVersionChecker checker = new D1NodeVersionChecker(v2Sysmeta.getAuthoritativeMemberNode());
647
        String version = checker.getVersion("MNStorage");
648
        if(version == null) {
649
            throw new ServiceFailure("4862", "Couldn't determine the authoritative member node version of the MNStorge for the "+pid.getValue());
650
        } else if (version.equalsIgnoreCase(D1NodeVersionChecker.V2)) {
651
            //we don't apply this method to an object whose authoritative node is v2
652
            throw new NotAuthorized("4861", edu.ucsb.nceas.metacat.dataone.CNodeService.V2V1MISSMATCH);
653
        } else if (!version.equalsIgnoreCase(D1NodeVersionChecker.V1)) {
654
            //we don't understand this version (it is not v1 or v2)
655
            throw new InvalidRequest("4863", "The version of the MNStorage is "+version+" for the authoritative member node of the object "+pid.getValue()+". We don't support it.");
656
        }
657
        //set the serial version to one
658
        v2Sysmeta.setSerialVersion(BigInteger.ONE);
659
        // the v2(impl).registerSysteMetadata will reset the system metadata modification date 
660
        //for the objects whose authoritative member node is v1. 
637 661
		return impl.registerSystemMetadata(session, pid, v2Sysmeta);
638 662
	}
639 663

  

Also available in: Unified diff