Revision 5379
Added by berkley over 14 years ago
src/edu/ucsb/nceas/metacat/dataone/CrudService.java | ||
---|---|---|
227 | 227 |
{ |
228 | 228 |
//generate required system metadata fields from the document |
229 | 229 |
SystemMetadata sm = createSystemMetadata(localId, token); |
230 |
System.out.println("sm: " + sm.toString());
|
|
230 |
System.out.println("sm: " + new String(serializeSystemMetadata(sm).toByteArray()));
|
|
231 | 231 |
//insert the systemmetadata object |
232 |
//associate the systemmetadata with the original id |
|
232 |
SessionData sessionData = getSessionData(token); |
|
233 |
insertSystemMetadata(sm, sessionData); |
|
233 | 234 |
} |
234 | 235 |
catch(Exception e) |
235 | 236 |
{ |
237 |
//e.printStackTrace(); |
|
236 | 238 |
System.out.println("Exception generating missing system metadata: " + e.getMessage()); |
237 | 239 |
logMetacat.error("Could not generate missing system metadata: " + e.getMessage()); |
238 | 240 |
} |
... | ... | |
240 | 242 |
} |
241 | 243 |
|
242 | 244 |
/** |
243 |
* create system metadata with a specified id, doc and format
|
|
245 |
* create an object via the crud interface
|
|
244 | 246 |
*/ |
245 |
private SystemMetadata createSystemMetadata(String localId, AuthToken token) |
|
246 |
throws Exception |
|
247 |
{ |
|
248 |
IdentifierManager im = IdentifierManager.getInstance(); |
|
249 |
Hashtable<String, String> docInfo = im.getDocumentInfo(localId); |
|
250 |
|
|
251 |
//get the document text |
|
252 |
int rev = im.getLatestRevForLocalId(localId); |
|
253 |
Identifier identifier = new Identifier(); |
|
254 |
identifier.setValue(im.getGUID(localId, rev)); |
|
255 |
InputStream is = this.get(token, identifier); |
|
256 |
|
|
257 |
SystemMetadata sm = new SystemMetadata(); |
|
258 |
//set the id |
|
259 |
sm.setIdentifier(identifier); |
|
260 |
|
|
261 |
//set the object format |
|
262 |
ObjectFormat format = ObjectFormat.convert(docInfo.get("doctype")); |
|
263 |
sm.setObjectFormat(format); |
|
264 |
|
|
265 |
//create the checksum |
|
266 |
String checksumS = checksum(is); |
|
267 |
ChecksumAlgorithm ca = ChecksumAlgorithm.convert("MD5"); |
|
268 |
Checksum checksum = new Checksum(); |
|
269 |
checksum.setValue(checksumS); |
|
270 |
checksum.setAlgorithm(ca); |
|
271 |
sm.setChecksum(checksum); |
|
272 |
|
|
273 |
//set the size |
|
274 |
is = this.get(token, identifier); |
|
275 |
sm.setSize(sizeOfStream(is)); |
|
276 |
|
|
277 |
//submitter |
|
278 |
Principal p = new Principal(); |
|
279 |
p.setValue(docInfo.get("user_owner")); |
|
280 |
sm.setSubmitter(p); |
|
281 |
sm.setRightsHolder(p); |
|
282 |
try |
|
283 |
{ |
|
284 |
Date dateCreated = parseMetacatDate(docInfo.get("date_created")); |
|
285 |
sm.setDateUploaded(dateCreated); |
|
286 |
Date dateUpdated = parseMetacatDate(docInfo.get("date_updated")); |
|
287 |
sm.setDateSysMetadataModified(dateUpdated); |
|
288 |
} |
|
289 |
catch(Exception e) |
|
290 |
{ |
|
291 |
System.out.println("couldn't parse a date: " + e.getMessage()); |
|
292 |
Date dateCreated = new Date(); |
|
293 |
sm.setDateUploaded(dateCreated); |
|
294 |
Date dateUpdated = new Date(); |
|
295 |
sm.setDateSysMetadataModified(dateUpdated); |
|
296 |
} |
|
297 |
NodeReference nr = new NodeReference(); |
|
298 |
nr.setValue("metacat"); |
|
299 |
sm.setOriginMemberNode(nr); |
|
300 |
sm.setAuthoritativeMemberNode(nr); |
|
301 |
return sm; |
|
302 |
} |
|
303 |
|
|
304 | 247 |
public Identifier create(AuthToken token, Identifier guid, |
305 | 248 |
InputStream object, SystemMetadata sysmeta) throws InvalidToken, |
306 | 249 |
ServiceFailure, NotAuthorized, IdentifierNotUnique, UnsupportedType, |
... | ... | |
1229 | 1172 |
} |
1230 | 1173 |
return size; |
1231 | 1174 |
} |
1175 |
|
|
1176 |
/** |
|
1177 |
* create system metadata with a specified id, doc and format |
|
1178 |
*/ |
|
1179 |
private SystemMetadata createSystemMetadata(String localId, AuthToken token) |
|
1180 |
throws Exception |
|
1181 |
{ |
|
1182 |
IdentifierManager im = IdentifierManager.getInstance(); |
|
1183 |
Hashtable<String, String> docInfo = im.getDocumentInfo(localId); |
|
1184 |
|
|
1185 |
//get the document text |
|
1186 |
int rev = im.getLatestRevForLocalId(localId); |
|
1187 |
Identifier identifier = new Identifier(); |
|
1188 |
identifier.setValue(im.getGUID(localId, rev)); |
|
1189 |
InputStream is = this.get(token, identifier); |
|
1190 |
|
|
1191 |
SystemMetadata sm = new SystemMetadata(); |
|
1192 |
//set the id |
|
1193 |
sm.setIdentifier(identifier); |
|
1194 |
|
|
1195 |
//set the object format |
|
1196 |
String doctype = docInfo.get("doctype"); |
|
1197 |
ObjectFormat format = ObjectFormat.convert(docInfo.get("doctype")); |
|
1198 |
if(format == null) |
|
1199 |
{ |
|
1200 |
if(doctype.trim().equals("BIN")) |
|
1201 |
{ |
|
1202 |
format = ObjectFormat.APPLICATIONOCTETSTREAM; |
|
1203 |
} |
|
1204 |
else |
|
1205 |
{ |
|
1206 |
format = ObjectFormat.convert("text/plain"); |
|
1207 |
} |
|
1208 |
} |
|
1209 |
sm.setObjectFormat(format); |
|
1210 |
|
|
1211 |
//create the checksum |
|
1212 |
String checksumS = checksum(is); |
|
1213 |
ChecksumAlgorithm ca = ChecksumAlgorithm.convert("MD5"); |
|
1214 |
Checksum checksum = new Checksum(); |
|
1215 |
checksum.setValue(checksumS); |
|
1216 |
checksum.setAlgorithm(ca); |
|
1217 |
sm.setChecksum(checksum); |
|
1218 |
|
|
1219 |
//set the size |
|
1220 |
is = this.get(token, identifier); |
|
1221 |
sm.setSize(sizeOfStream(is)); |
|
1222 |
|
|
1223 |
//submitter |
|
1224 |
Principal p = new Principal(); |
|
1225 |
p.setValue(docInfo.get("user_owner")); |
|
1226 |
sm.setSubmitter(p); |
|
1227 |
sm.setRightsHolder(p); |
|
1228 |
try |
|
1229 |
{ |
|
1230 |
Date dateCreated = parseMetacatDate(docInfo.get("date_created")); |
|
1231 |
sm.setDateUploaded(dateCreated); |
|
1232 |
Date dateUpdated = parseMetacatDate(docInfo.get("date_updated")); |
|
1233 |
sm.setDateSysMetadataModified(dateUpdated); |
|
1234 |
} |
|
1235 |
catch(Exception e) |
|
1236 |
{ |
|
1237 |
System.out.println("couldn't parse a date: " + e.getMessage()); |
|
1238 |
Date dateCreated = new Date(); |
|
1239 |
sm.setDateUploaded(dateCreated); |
|
1240 |
Date dateUpdated = new Date(); |
|
1241 |
sm.setDateSysMetadataModified(dateUpdated); |
|
1242 |
} |
|
1243 |
NodeReference nr = new NodeReference(); |
|
1244 |
nr.setValue("metacat"); |
|
1245 |
sm.setOriginMemberNode(nr); |
|
1246 |
sm.setAuthoritativeMemberNode(nr); |
|
1247 |
return sm; |
|
1248 |
} |
|
1232 | 1249 |
} |
Also available in: Unified diff
mostly done with generating systemmetadata from legacy knb docs. need to write a better test and enable this through the ResourceHandler then it will be done.