Revision 5352
Added by berkley over 14 years ago
test/edu/ucsb/nceas/metacat/dataone/CrudServiceTest.java | ||
---|---|---|
80 | 80 |
public static Test suite() |
81 | 81 |
{ |
82 | 82 |
TestSuite suite = new TestSuite(); |
83 |
/*suite.addTest(new CrudServiceTest("initialize"));
|
|
83 |
suite.addTest(new CrudServiceTest("initialize")); |
|
84 | 84 |
suite.addTest(new CrudServiceTest("testSingletonAccessor")); |
85 | 85 |
suite.addTest(new CrudServiceTest("testCreateAndGet")); |
86 |
suite.addTest(new CrudServiceTest("testGetSystemMetadata"));*/
|
|
86 |
suite.addTest(new CrudServiceTest("testGetSystemMetadata")); |
|
87 | 87 |
suite.addTest(new CrudServiceTest("testUpdate")); |
88 | 88 |
//suite.addTest(new CrudServiceTest("")); |
89 | 89 |
//suite.addTest(new CrudServiceTest("")); |
... | ... | |
105 | 105 |
CrudService cs = CrudService.getInstance(); |
106 | 106 |
AuthToken token = getToken(); |
107 | 107 |
//create a doc |
108 |
System.out.println("CST: creating document"); |
|
109 | 108 |
Identifier id = createDoc(token, getTestDoc()); |
110 |
System.out.println("CST: document created. Id: " + id.getValue()); |
|
111 | 109 |
|
112 | 110 |
//get the doc and sysmetadata |
113 |
System.out.println("CST: getting document with id " + id.getValue()); |
|
114 | 111 |
String gotDoc = getDoc(token, id); |
115 |
System.out.println("CST: getting sysmeta for doc with id " + id.getValue()); |
|
116 | 112 |
SystemMetadata sm = getSystemMetadata(token, id); |
117 | 113 |
|
118 | 114 |
//update the doc |
119 | 115 |
gotDoc = gotDoc.replaceAll("XXX", "YYY"); |
120 |
System.out.println("CST: Changed test doc to " + gotDoc); |
|
121 | 116 |
Identifier newid = new Identifier(); |
122 | 117 |
newid.setValue(generateDocumentId()); |
123 |
System.out.println("CST: Generated newid " + newid.getValue()); |
|
124 | 118 |
StringBufferInputStream sbis = new StringBufferInputStream(gotDoc); |
125 | 119 |
SystemMetadata newsm = createSystemMetadata(newid, gotDoc); |
126 |
System.out.println("CST: Created system metadata for new doc...updating newid: " + newid.getValue() + " obsId: " + id.getValue()); |
|
127 | 120 |
Identifier updatedid = cs.update(token, newid, sbis, id, newsm); |
128 |
System.out.println("CST: Called update. Returned id " + updatedid.getValue()); |
|
129 | 121 |
|
130 | 122 |
//get doc - check that it matches update |
131 | 123 |
String newdoc = getDoc(token, newid); |
132 | 124 |
assertTrue(gotDoc.equals(newdoc)); |
133 | 125 |
|
134 | 126 |
//get sysmeta - check that ids and other fields are updated |
135 |
System.out.println("CST: confirming obsoletedBy fields for sm doc with id " + id.getValue()); |
|
136 | 127 |
SystemMetadata newnewsm = getSystemMetadata(token, id); |
137 |
List obsoletedByList = newnewsm.getObsoletedByList(); |
|
138 |
assertTrue(obsoletedByList.size() == 1); |
|
139 |
String obsBy = ((Identifier)obsoletedByList.get(0)).getValue(); |
|
140 |
System.out.println("CST: obsBy: " + obsBy); |
|
141 |
System.out.println("CST: id: " + id.getValue()); |
|
142 |
assertTrue(obsBy.equals(newid.getValue())); |
|
128 |
assertTrue(newnewsm.getObsoletedBy(0).getValue().equals(newid.getValue())); |
|
129 |
|
|
130 |
//get the new sysmeta and make sure the obsoletes field is set |
|
131 |
SystemMetadata newnewnewsm = getSystemMetadata(token, newid); |
|
132 |
assertTrue(newnewnewsm.getObsolete(0).getValue().equals(id.getValue())); |
|
143 | 133 |
} |
144 | 134 |
catch(Exception e) |
145 | 135 |
{ |
... | ... | |
204 | 194 |
AuthToken token = getToken(); |
205 | 195 |
//run create |
206 | 196 |
Identifier id = createDoc(token, getTestDoc()); |
207 |
//run get
|
|
197 |
//compare the docs
|
|
208 | 198 |
String gotDoc = getDoc(token, id); |
209 |
System.out.println("got doc: " + gotDoc); |
|
210 |
//compare the docs |
|
211 | 199 |
assertTrue(gotDoc.trim().equals(getTestDoc().trim())); |
212 | 200 |
|
213 | 201 |
try |
... | ... | |
255 | 243 |
private SystemMetadata getSystemMetadata(AuthToken token, Identifier id) |
256 | 244 |
throws Exception |
257 | 245 |
{ |
258 |
System.out.println("getting system metadata for id: " + id.getValue()); |
|
259 | 246 |
CrudService cs = CrudService.getInstance(); |
260 | 247 |
return cs.getSystemMetadata(token, id); |
261 | 248 |
} |
... | ... | |
266 | 253 |
private String getDoc(AuthToken token, Identifier id) |
267 | 254 |
throws Exception |
268 | 255 |
{ |
269 |
System.out.println("getting doc for id " + id.getValue()); |
|
270 | 256 |
CrudService cs = CrudService.getInstance(); |
271 | 257 |
//try to get the same doc then compare them |
272 | 258 |
InputStream gotDocStream = cs.get(token, id); |
... | ... | |
278 | 264 |
sb.append(new String(b, 0, numread)); |
279 | 265 |
numread = gotDocStream.read(b, 0, 1024); |
280 | 266 |
} |
281 |
System.out.println("returning doc for id " + id.getValue()); |
|
282 | 267 |
return sb.toString(); |
283 | 268 |
} |
284 | 269 |
|
... | ... | |
298 | 283 |
{ |
299 | 284 |
CrudService cs = CrudService.getInstance(); |
300 | 285 |
//login and get a sessionid |
301 |
System.out.println("creating MetacatRestClient with url " + cs.getContextUrl()); |
|
302 | 286 |
MetacatRestClient restClient = new MetacatRestClient(cs.getContextUrl()); |
303 | 287 |
String username = PropertyService.getProperty("test.mcUser"); |
304 | 288 |
String password = PropertyService.getProperty("test.mcPassword"); |
305 |
System.out.println("logging in with username: " + username + " and password " + password + " to context " + cs.getContextUrl()); |
|
306 | 289 |
String response = restClient.login(username, password); |
307 |
//System.out.println("response to login: " + response); |
|
308 | 290 |
String sessionid = restClient.getSessionId(); |
309 | 291 |
SessionService sessionService = SessionService.getInstance(); |
310 | 292 |
sessionService.registerSession(new SessionData(sessionid, username, new String[0], password, "CrudServiceLogin")); |
311 |
System.out.println("sessionid: " + sessionid); |
|
312 | 293 |
AuthToken token = new AuthToken(sessionid); |
313 | 294 |
return token; |
314 | 295 |
} |
... | ... | |
324 | 305 |
id = new Identifier(); |
325 | 306 |
String docid = generateDocumentId(); |
326 | 307 |
id.setValue(docid); |
327 |
System.out.println("creating doc with id " + id.getValue()); |
|
328 | 308 |
|
329 | 309 |
//create the system metadata then run the create method |
330 | 310 |
StringBufferInputStream sbis = new StringBufferInputStream(testDoc); |
331 | 311 |
SystemMetadata sm = createSystemMetadata(id, testDoc); |
332 | 312 |
//create the doc |
333 | 313 |
cs.create(token, id, sbis, sm); |
334 |
System.out.println("document with id " + id.getValue() + " created."); |
|
335 | 314 |
return id; |
336 | 315 |
} |
337 | 316 |
|
... | ... | |
343 | 322 |
{ |
344 | 323 |
SystemMetadata sm = new SystemMetadata(); |
345 | 324 |
//set the id |
346 |
System.out.println("creating system metadata object for document with id " + id.getValue()); |
|
347 | 325 |
sm.setIdentifier(id); |
348 |
System.out.println("sm id is " + id.getValue()); |
|
349 | 326 |
sm.setObjectFormat(ObjectFormat.convert("eml://ecoinformatics.org/eml-2.1.0")); |
350 |
System.out.println("sm objectformat: " + sm.getObjectFormat()); |
|
351 | 327 |
//create the checksum |
352 | 328 |
String checksumS = checksum(testDoc); |
353 | 329 |
ChecksumAlgorithm ca = ChecksumAlgorithm.convert("MD5"); |
... | ... | |
355 | 331 |
checksum.setValue(checksumS); |
356 | 332 |
checksum.setAlgorithm(ca); |
357 | 333 |
sm.setChecksum(checksum); |
358 |
System.out.println("sm checksum is " + checksumS); |
|
359 | 334 |
//set the size |
360 | 335 |
sm.setSize(testDoc.getBytes().length); |
361 |
System.out.println("sm size: " + testDoc.getBytes().length); |
|
362 | 336 |
//submitter |
363 | 337 |
Principal p = new Principal(); |
364 | 338 |
p.setValue("joe"); |
src/edu/ucsb/nceas/metacat/DocumentImpl.java | ||
---|---|---|
2566 | 2566 |
|
2567 | 2567 |
logMetacat.debug("DocumentImpl.write - conn usage count before writting: " |
2568 | 2568 |
+ conn.getUsageCount()); |
2569 |
System.out.println("creating new accnum: " + accnum + " for action " + action); |
|
2570 | 2569 |
AccessionNumber ac = new AccessionNumber(accnum, action); |
2571 | 2570 |
String docid = ac.getDocid(); |
2572 | 2571 |
String rev = ac.getRev(); |
src/edu/ucsb/nceas/metacat/dataone/CrudService.java | ||
---|---|---|
327 | 327 |
|
328 | 328 |
try { |
329 | 329 |
IdentifierManager im = IdentifierManager.getInstance(); |
330 |
System.out.println("looking up systemmetadata id for guid " + guid.getValue()); |
|
331 | 330 |
final String localId = im.getSystemMetadataId(guid.getValue()); |
332 |
System.out.println("localId: " + localId); |
|
333 | 331 |
|
334 | 332 |
// Read system metadata from metacat's db |
335 | 333 |
final InputStreamFromOutputStream<String> objectStream = |
... | ... | |
387 | 385 |
|
388 | 386 |
//find the old systemmetadata (sm.old) document id (the one linked to obsoletedGuid) |
389 | 387 |
SystemMetadata sm = getSystemMetadata(token, obsoletedGuid); |
390 |
System.out.println("CS: got sm for obsoleteGuid: " + obsoletedGuid.getValue()); |
|
391 | 388 |
//change sm.old's obsoletedBy field |
392 | 389 |
List l = sm.getObsoletedByList(); |
393 | 390 |
l.add(guid); |
394 | 391 |
sm.setObsoletedByList(l); |
395 |
System.out.println("CS: set obsoletedBy to id: " + ((Identifier)l.get(0)).getValue()); |
|
396 | 392 |
//update sm.old |
397 |
System.out.println("CS: updating system metadata..."); |
|
398 | 393 |
updateSystemMetadata(sm, sessionData); |
399 |
System.out.println("CS: updated system metadata."); |
|
394 |
|
|
400 | 395 |
//change the obsoletes field of the new systemMetadata (sm.new) to point to the id of the old one |
401 |
System.out.println("CS: Adding obsoleteGuid to new sysmeta"); |
|
402 | 396 |
sysmeta.addObsolete(obsoletedGuid); |
403 | 397 |
//insert sm.new |
404 |
System.out.println("CS: inserting new sysmeta"); |
|
405 | 398 |
insertSystemMetadata(sysmeta, sessionData); |
406 |
//call update with sm.new.object.id for object |
|
407 |
//System.out.println("CS: updating old sm"); |
|
408 |
//updateSystemMetadata(sm, sessionData); |
|
409 |
System.out.println("CS: updating doc"); |
|
399 |
|
|
400 |
//update the doc |
|
410 | 401 |
updateDocument(object, obsoletedGuid, guid, sessionData); |
411 |
System.out.println("CS: Done updating document."); |
|
412 | 402 |
return guid; |
413 | 403 |
} |
414 | 404 |
catch(Exception e) |
... | ... | |
584 | 574 |
String localId = insertDocument(xml, sysMetaGuid, sessionData); |
585 | 575 |
//insert the system metadata doc id into the identifiers table to |
586 | 576 |
//link it to the data or metadata document |
587 |
System.out.println("mapping systemmetadata id to docid in im.insertSystemMetadata"); |
|
588 | 577 |
IdentifierManager.getInstance().createSystemMetadataMapping(sysmeta.getIdentifier().getValue(), sysMetaGuid.getValue()); |
589 | 578 |
} |
590 | 579 |
|
... | ... | |
596 | 585 |
{ |
597 | 586 |
try |
598 | 587 |
{ |
599 |
System.out.println("Updating SystemMetadata with id " + sm.getIdentifier().getValue()); |
|
600 | 588 |
String smId = IdentifierManager.getInstance().getSystemMetadataId(sm.getIdentifier().getValue()); |
601 |
System.out.println("smId: " + smId); |
|
602 | 589 |
sm.setDateSysMetadataModified(new Date()); |
603 | 590 |
String xml = new String(serializeSystemMetadata(sm).toByteArray()); |
604 | 591 |
Identifier id = new Identifier(); |
605 | 592 |
id.setValue(smId); |
606 |
System.out.println("updating sysmeta doc with new id " + id.getValue()); |
|
607 | 593 |
String localId = updateDocument(xml, id, null, sessionData); |
608 |
System.out.println("new updated localId: " + localId); |
|
609 |
System.out.println("CS: updateDocument returned localId: " + localId); |
|
610 | 594 |
IdentifierManager.getInstance().updateSystemMetadataMapping(sm.getIdentifier().getValue(), localId); |
611 | 595 |
} |
612 | 596 |
catch(Exception e) |
... | ... | |
706 | 690 |
action[0] = insertOrUpdate; |
707 | 691 |
params.put("action", action); |
708 | 692 |
String[] docid = new String[1]; |
709 |
System.out.println(insertOrUpdate + "ing with localId " + localId); |
|
710 | 693 |
docid[0] = localId; |
711 | 694 |
params.put("docid", docid); |
712 | 695 |
String[] doctext = new String[1]; |
src/edu/ucsb/nceas/metacat/IdentifierManager.java | ||
---|---|---|
245 | 245 |
|
246 | 246 |
// Execute the insert statement |
247 | 247 |
String query = "update systemmetadata set (docid, rev) = (?, ?) where guid='" + guid + "'"; |
248 |
System.out.println("query: " + query + " for params: (guid:" + guid + ", docid=" + docid + ", rev=" + rev + ")"); |
|
248 |
//System.out.println("query: " + query + " for params: (guid:" + guid + ", docid=" + docid + ", rev=" + rev + ")");
|
|
249 | 249 |
PreparedStatement stmt = dbConn.prepareStatement(query); |
250 | 250 |
stmt.setString(1, docid); |
251 | 251 |
stmt.setInt(2, rev); |
... | ... | |
300 | 300 |
int rev = 0; |
301 | 301 |
|
302 | 302 |
String query = "select guid, docid, rev from " + type + " where guid = ?"; |
303 |
System.out.println("query: " + query + " for params: (" + guid + ")"); |
|
303 |
//System.out.println("query: " + query + " for params: (" + guid + ")");
|
|
304 | 304 |
|
305 | 305 |
DBConnection dbConn = null; |
306 | 306 |
int serialNumber = -1; |
... | ... | |
361 | 361 |
|
362 | 362 |
// Execute the insert statement |
363 | 363 |
String query = "insert into " + type + " (guid, docid, rev) values (?, ?, ?)"; |
364 |
System.out.println("query: " + query + " for params: (" + guid + ", " + docid + ", " + rev + ")"); |
|
364 |
//System.out.println("query: " + query + " for params: (" + guid + ", " + docid + ", " + rev + ")");
|
|
365 | 365 |
PreparedStatement stmt = dbConn.prepareStatement(query); |
366 | 366 |
stmt.setString(1, guid); |
367 | 367 |
stmt.setString(2, docid); |
Also available in: Unified diff
removed system.outs