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 |
|
Add contrains for the v1/v2.registerSystemMetadata method. See https://redmine.dataone.org/issues/7380