Revision 6904
Added by Chris Jones about 12 years ago
IdentifierManager.java | ||
---|---|---|
37 | 37 |
|
38 | 38 |
import org.apache.log4j.Logger; |
39 | 39 |
import org.dataone.client.ObjectFormatCache; |
40 |
import org.dataone.service.exceptions.InvalidSystemMetadata; |
|
40 | 41 |
import org.dataone.service.exceptions.NotFound; |
41 | 42 |
import org.dataone.service.types.v1.AccessPolicy; |
42 | 43 |
import org.dataone.service.types.v1.AccessRule; |
... | ... | |
915 | 916 |
* @param localId the systemMetadata object to get the local id for |
916 | 917 |
* @throws McdbDocNotFoundException |
917 | 918 |
* @throws SQLException |
919 |
* @throws InvalidSystemMetadata |
|
918 | 920 |
*/ |
919 | 921 |
public void createSystemMetadata(SystemMetadata sysmeta) |
920 |
throws McdbDocNotFoundException, SQLException { |
|
922 |
throws McdbDocNotFoundException, SQLException, InvalidSystemMetadata {
|
|
921 | 923 |
String guid = sysmeta.getIdentifier().getValue(); |
922 | 924 |
// insert the record |
923 | 925 |
insertSystemMetadata(guid); |
... | ... | |
1142 | 1144 |
* @param sm |
1143 | 1145 |
* @throws McdbDocNotFoundException |
1144 | 1146 |
* @throws SQLException |
1147 |
* @throws InvalidSystemMetadata |
|
1145 | 1148 |
*/ |
1146 | 1149 |
public void updateSystemMetadata(SystemMetadata sm) |
1147 |
throws McdbDocNotFoundException, SQLException { |
|
1150 |
throws McdbDocNotFoundException, SQLException, InvalidSystemMetadata {
|
|
1148 | 1151 |
|
1149 | 1152 |
Boolean replicationAllowed = false; |
1150 | 1153 |
Integer numberReplicas = -1; |
... | ... | |
1156 | 1159 |
numberReplicas = numberReplicas == null ? -1: numberReplicas; |
1157 | 1160 |
} |
1158 | 1161 |
|
1162 |
// ensure certain system metadata fields are populated |
|
1163 |
try { |
|
1164 |
sm.getIdentifier().getValue(); |
|
1165 |
sm.getSerialVersion().intValue(); |
|
1166 |
sm.getDateUploaded().getTime(); |
|
1167 |
sm.getRightsHolder().getValue(); |
|
1168 |
sm.getChecksum().getValue(); |
|
1169 |
sm.getChecksum().getAlgorithm(); |
|
1170 |
sm.getOriginMemberNode().getValue(); |
|
1171 |
sm.getAuthoritativeMemberNode().getValue(); |
|
1172 |
sm.getDateSysMetadataModified().getTime(); |
|
1173 |
// sm.getSubmitter().getValue(); // filled in with identifier |
|
1174 |
sm.getFormatId().getValue(); |
|
1175 |
sm.getArchived().booleanValue(); |
|
1176 |
|
|
1177 |
} catch (NullPointerException npe) { |
|
1178 |
throw new InvalidSystemMetadata("0000", npe.getMessage()); |
|
1179 |
|
|
1180 |
} |
|
1181 |
|
|
1159 | 1182 |
// the main systemMetadata fields |
1160 | 1183 |
updateSystemMetadataFields( |
1161 | 1184 |
sm.getDateUploaded() == null ? null: sm.getDateUploaded().getTime(), |
... | ... | |
1166 | 1189 |
sm.getAuthoritativeMemberNode() == null ? null: sm.getAuthoritativeMemberNode().getValue(), |
1167 | 1190 |
sm.getDateSysMetadataModified() == null ? null: sm.getDateSysMetadataModified().getTime(), |
1168 | 1191 |
sm.getSubmitter() == null ? null: sm.getSubmitter().getValue(), |
1169 |
sm.getIdentifier().getValue(),
|
|
1170 |
sm.getFormatId() == null ? null: sm.getFormatId().getValue(),
|
|
1171 |
sm.getSize(),
|
|
1172 |
sm.getArchived() == null ? false: sm.getArchived(),
|
|
1173 |
replicationAllowed,
|
|
1174 |
numberReplicas,
|
|
1175 |
sm.getObsoletes() == null ? null:sm.getObsoletes().getValue(),
|
|
1176 |
sm.getObsoletedBy() == null ? null: sm.getObsoletedBy().getValue(),
|
|
1177 |
sm.getSerialVersion()
|
|
1192 |
sm.getIdentifier().getValue(), |
|
1193 |
sm.getFormatId() == null ? null: sm.getFormatId().getValue(), |
|
1194 |
sm.getSize(), |
|
1195 |
sm.getArchived() == null ? false: sm.getArchived(), |
|
1196 |
replicationAllowed, |
|
1197 |
numberReplicas, |
|
1198 |
sm.getObsoletes() == null ? null:sm.getObsoletes().getValue(), |
|
1199 |
sm.getObsoletedBy() == null ? null: sm.getObsoletedBy().getValue(), |
|
1200 |
sm.getSerialVersion() |
|
1178 | 1201 |
); |
1179 | 1202 |
|
1180 | 1203 |
String guid = sm.getIdentifier().getValue(); |
Also available in: Unified diff
In IdentifierManager.updateSystemMetadata(), add a check for invalid system metadata (fields that throw a NullPointerException on access) to ensure that system metadata is populated correctly. Updated calling classes to handle the exception.