Revision 9086
Added by Jing Tao almost 10 years ago
test/edu/ucsb/nceas/metacat/dataone/SIDTest.java | ||
---|---|---|
273 | 273 |
p3Sys.setIdentifier(p3); |
274 | 274 |
p3Sys.setSeriesId(s2); |
275 | 275 |
p3Sys.setObsoletes(p2); |
276 |
p3Sys.setDateUploaded(new Date(300)); |
|
276 | 277 |
|
277 | 278 |
Vector<SystemMetadata> chain = new Vector<SystemMetadata>(); |
278 | 279 |
chain.add(p1Sys); |
... | ... | |
319 | 320 |
p3Sys.setIdentifier(p3); |
320 | 321 |
p3Sys.setSeriesId(s2); |
321 | 322 |
p3Sys.setObsoletes(p2); |
323 |
p3Sys.setDateUploaded(new Date(300)); |
|
322 | 324 |
|
323 | 325 |
Vector<SystemMetadata> chain = new Vector<SystemMetadata>(); |
324 | 326 |
chain.add(p1Sys); |
... | ... | |
367 | 369 |
p3Sys.setIdentifier(p3); |
368 | 370 |
//p3Sys.setSeriesId(s2); |
369 | 371 |
p3Sys.setObsoletes(p2); |
372 |
p3Sys.setDateUploaded(new Date(300)); |
|
370 | 373 |
|
371 | 374 |
Vector<SystemMetadata> chain = new Vector<SystemMetadata>(); |
372 | 375 |
chain.add(p1Sys); |
... | ... | |
415 | 418 |
//p3Sys.setSeriesId(s2); |
416 | 419 |
p3Sys.setObsoletes(p2); |
417 | 420 |
p3Sys.setObsoletedBy(p4); |
421 |
p3Sys.setDateUploaded(new Date(300)); |
|
418 | 422 |
|
419 | 423 |
SystemMetadata p4Sys = new SystemMetadata(); |
420 | 424 |
p4Sys.setIdentifier(p4); |
421 | 425 |
p4Sys.setSeriesId(s2); |
422 | 426 |
p4Sys.setObsoletes(p3); |
427 |
p4Sys.setDateUploaded(new Date(400)); |
|
423 | 428 |
|
424 | 429 |
Vector<SystemMetadata> chain = new Vector<SystemMetadata>(); |
425 | 430 |
chain.add(p1Sys); |
... | ... | |
472 | 477 |
p4Sys.setIdentifier(p4); |
473 | 478 |
p4Sys.setSeriesId(s1); |
474 | 479 |
p4Sys.setObsoletes(p3); |
480 |
p4Sys.setDateUploaded(new Date(400)); |
|
475 | 481 |
|
476 | 482 |
Vector<SystemMetadata> chain = new Vector<SystemMetadata>(); |
477 | 483 |
chain.add(p1Sys); |
... | ... | |
744 | 750 |
SystemMetadata p3Sys = new SystemMetadata(); |
745 | 751 |
p3Sys.setIdentifier(p3); |
746 | 752 |
p3Sys.setSeriesId(s2); |
753 |
p3Sys.setDateUploaded(new Date(300)); |
|
747 | 754 |
|
748 | 755 |
Vector<SystemMetadata> chain = new Vector<SystemMetadata>(); |
749 | 756 |
chain.add(p1Sys); |
... | ... | |
793 | 800 |
p4Sys.setSeriesId(s1); |
794 | 801 |
p4Sys.setObsoletes(p3); |
795 | 802 |
p4Sys.setObsoletedBy(p5); |
803 |
p4Sys.setDateUploaded(new Date(400)); |
|
796 | 804 |
|
797 | 805 |
SystemMetadata p5Sys = new SystemMetadata(); |
798 | 806 |
p5Sys.setIdentifier(p5); |
799 | 807 |
p5Sys.setSeriesId(s2); |
800 | 808 |
p5Sys.setObsoletes(p4); |
809 |
p5Sys.setDateUploaded(new Date(500)); |
|
801 | 810 |
|
802 | 811 |
|
803 | 812 |
Vector<SystemMetadata> chain = new Vector<SystemMetadata>(); |
... | ... | |
935 | 944 |
* @param sid |
936 | 945 |
* @return |
937 | 946 |
*/ |
938 |
public Identifier getHeadVersion(Identifier sid, Vector<SystemMetadata> chain) { |
|
947 |
/*public Identifier getHeadVersion(Identifier sid, Vector<SystemMetadata> chain) {
|
|
939 | 948 |
Identifier pid = null; |
940 | 949 |
Vector<SystemMetadata> sidChain = new Vector<SystemMetadata>(); |
941 | 950 |
int noObsoletedByCount =0; |
... | ... | |
944 | 953 |
for(SystemMetadata sysmeta : chain) { |
945 | 954 |
if(sysmeta.getSeriesId() != null && sysmeta.getSeriesId().equals(sid)) { |
946 | 955 |
//decorateSystemMetadata(sysmeta, chain); |
947 |
/*System.out.println("identifier "+sysmeta.getIdentifier().getValue()+" :");
|
|
956 |
System.out.println("identifier "+sysmeta.getIdentifier().getValue()+" :"); |
|
948 | 957 |
if(sysmeta.getObsoletes() == null) { |
949 | 958 |
System.out.println("obsolets "+sysmeta.getObsoletes()); |
950 | 959 |
} else { |
... | ... | |
954 | 963 |
System.out.println("obsoletedBy "+sysmeta.getObsoletedBy()); |
955 | 964 |
} else { |
956 | 965 |
System.out.println("obsoletedBy "+sysmeta.getObsoletedBy().getValue()); |
957 |
}*/
|
|
966 |
} |
|
958 | 967 |
if(!hasMissingObsolescenceFields) { |
959 | 968 |
if(hasMissingObsolescenceFields(sysmeta, chain)) { |
960 | 969 |
hasMissingObsolescenceFields = true; |
... | ... | |
1017 | 1026 |
} |
1018 | 1027 |
|
1019 | 1028 |
return pid; |
1020 |
} |
|
1029 |
}*/
|
|
1021 | 1030 |
|
1022 | 1031 |
|
1023 | 1032 |
private SystemMetadata getSystemMetadata(Identifier id, Vector<SystemMetadata> chain ){ |
... | ... | |
1032 | 1041 |
} |
1033 | 1042 |
return sysmeta; |
1034 | 1043 |
} |
1044 |
|
|
1045 |
/** |
|
1046 |
* Get the head version of the chain |
|
1047 |
* @param sid |
|
1048 |
* @return |
|
1049 |
*/ |
|
1050 |
public Identifier getHeadVersion(Identifier sid, Vector<SystemMetadata> chain) { |
|
1051 |
Identifier pid = null; |
|
1052 |
Vector<SystemMetadata> sidChain = new Vector<SystemMetadata>(); |
|
1053 |
int endCounter =0 ; |
|
1054 |
String status = null; |
|
1055 |
if(chain != null) { |
|
1056 |
for(SystemMetadata sysmeta : chain) { |
|
1057 |
if(sysmeta.getSeriesId() != null && sysmeta.getSeriesId().equals(sid)) { |
|
1058 |
status = endStatus(sysmeta, chain); |
|
1059 |
if(status.equals(END1) || status.equals(END2)) { |
|
1060 |
endCounter ++; |
|
1061 |
pid = sysmeta.getIdentifier(); |
|
1062 |
} |
|
1063 |
sidChain.add(sysmeta); |
|
1064 |
} |
|
1065 |
} |
|
1066 |
if(endCounter != 1) { |
|
1067 |
System.out.println("The chain has "+endCounter+" ends and it is not an ideal chain."); |
|
1068 |
Collections.sort(sidChain, new SystemMetadataDateUploadedComparator()); |
|
1069 |
pid =sidChain.lastElement().getIdentifier(); |
|
1070 |
} else { |
|
1071 |
System.out.println(""+status); |
|
1072 |
} |
|
1073 |
} |
|
1074 |
return pid; |
|
1075 |
} |
|
1076 |
|
|
1077 |
|
|
1078 |
/* |
|
1079 |
* Rules for ends: |
|
1080 |
* Rule 1. An object in the SID chain doesn't have the "obsoletedBy" field. |
|
1081 |
* Rule 2. An object in the SID chain does have the "obsoletedBy" filed, but the "obsoletedBy" value has different the SID value (including no SID value). |
|
1082 |
* It is tricky if the object in the "obsoletedBy" filed is missing since we don't have the knowledge of its series id. Generally we consider it an end except: |
|
1083 |
* if there is another object in the chain (has the same series id) obsoletes the missing object, the missing object is not an end. |
|
1084 |
*/ |
|
1085 |
private String endStatus(SystemMetadata targetSysmeta, Vector<SystemMetadata> chain) { |
|
1086 |
String status = END2; |
|
1087 |
if(targetSysmeta.getObsoletedBy() == null) { |
|
1088 |
status = END1; |
|
1089 |
} else { |
|
1090 |
Identifier orgSid = targetSysmeta.getSeriesId(); |
|
1091 |
Identifier obsoletedBy = targetSysmeta.getObsoletedBy(); |
|
1092 |
SystemMetadata obsoletedBySys = getSystemMetadata(obsoletedBy, chain); |
|
1093 |
if(obsoletedBySys != null) { |
|
1094 |
if(obsoletedBySys.getSeriesId() != null && obsoletedBySys.getSeriesId().equals(orgSid)) { |
|
1095 |
status = NOTEND; |
|
1096 |
} |
|
1097 |
} else { |
|
1098 |
// the obsoletedBy doesn't exist |
|
1099 |
for(SystemMetadata sys : chain) { |
|
1100 |
if(sys.getSeriesId() != null && sys.getSeriesId().equals(orgSid)) { |
|
1101 |
if(sys.getObsoletes() != null && sys.getObsoletes().equals(obsoletedBy)) { |
|
1102 |
status = NOTEND; |
|
1103 |
} |
|
1104 |
} |
|
1105 |
} |
|
1106 |
} |
|
1107 |
} |
|
1108 |
return status; |
|
1109 |
} |
|
1110 |
|
|
1111 |
private static final String END1 = "Rule 1"; |
|
1112 |
private static final String END2 = "Rule 2"; |
|
1113 |
private static final String NOTEND = "Not an end"; |
|
1035 | 1114 |
} |
Also available in: Unified diff
Used the new concept - end to determine the head object of an SID chain.