Revision 6303
Added by ben leinfelder over 13 years ago
test/edu/ucsb/nceas/metacat/dataone/CNodeServiceTest.java | ||
---|---|---|
50 | 50 |
import org.dataone.service.types.ObjectFormatList; |
51 | 51 |
import org.dataone.service.types.ObjectInfo; |
52 | 52 |
import org.dataone.service.types.ObjectList; |
53 |
import org.dataone.service.types.ObjectLocationList; |
|
54 | 53 |
import org.dataone.service.types.Permission; |
55 | 54 |
import org.dataone.service.types.Replica; |
56 | 55 |
import org.dataone.service.types.ReplicationPolicy; |
... | ... | |
108 | 107 |
suite.addTest(new CNodeServiceTest("testReplicationPolicy")); |
109 | 108 |
suite.addTest(new CNodeServiceTest("testReplicationStatus")); |
110 | 109 |
suite.addTest(new CNodeServiceTest("testReserveIdentifier")); |
111 |
suite.addTest(new CNodeServiceTest("testResolve")); |
|
112 | 110 |
suite.addTest(new CNodeServiceTest("testSearch")); |
113 | 111 |
suite.addTest(new CNodeServiceTest("testSetOwner")); |
114 | 112 |
|
... | ... | |
237 | 235 |
} |
238 | 236 |
} |
239 | 237 |
|
240 |
public void testResolve() { |
|
241 |
printTestHeader("testResolve"); |
|
242 |
|
|
243 |
try { |
|
244 |
Session session = getTestSession(); |
|
245 |
Identifier guid = new Identifier(); |
|
246 |
guid.setValue("testResolve." + System.currentTimeMillis()); |
|
247 |
SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject()); |
|
248 |
Replica replica = new Replica(); |
|
249 |
NodeReference replicaMemberNode = new NodeReference(); |
|
250 |
replicaMemberNode.setValue("testNode"); |
|
251 |
replica.setReplicaMemberNode(replicaMemberNode); |
|
252 |
replica.setReplicationStatus(ReplicationStatus.QUEUED); |
|
253 |
replica.setReplicaVerified(new Date()); |
|
254 |
sysmeta.addReplica(replica ); |
|
255 |
// save it |
|
256 |
boolean result = CNodeService.getInstance().registerSystemMetadata(session, guid, sysmeta); |
|
257 |
assertTrue(result); |
|
258 |
// resolve it |
|
259 |
ObjectLocationList locationList = CNodeService.getInstance().resolve(session, guid); |
|
260 |
// check it |
|
261 |
assertEquals(replicaMemberNode, locationList.getObjectLocation(0).getNodeIdentifier()); |
|
262 |
|
|
263 |
} catch(Exception e) { |
|
264 |
e.printStackTrace(); |
|
265 |
fail("Unexpected error: " + e.getMessage()); |
|
266 |
} |
|
267 |
} |
|
268 |
|
|
269 | 238 |
public void testSearch() { |
270 | 239 |
printTestHeader("testSearch"); |
271 | 240 |
|
src/edu/ucsb/nceas/metacat/dataone/CNodeService.java | ||
---|---|---|
23 | 23 |
|
24 | 24 |
package edu.ucsb.nceas.metacat.dataone; |
25 | 25 |
|
26 |
import java.io.InputStream; |
|
27 |
import java.math.BigInteger; |
|
28 | 26 |
import java.util.Date; |
29 | 27 |
import java.util.List; |
30 | 28 |
|
... | ... | |
42 | 40 |
import org.dataone.service.exceptions.NotFound; |
43 | 41 |
import org.dataone.service.exceptions.NotImplemented; |
44 | 42 |
import org.dataone.service.exceptions.ServiceFailure; |
45 |
import org.dataone.service.exceptions.UnsupportedType; |
|
46 | 43 |
import org.dataone.service.types.Checksum; |
47 | 44 |
import org.dataone.service.types.Identifier; |
48 |
import org.dataone.service.types.Node; |
|
49 | 45 |
import org.dataone.service.types.NodeList; |
50 |
import org.dataone.service.types.NodeReference; |
|
51 | 46 |
import org.dataone.service.types.ObjectFormat; |
52 | 47 |
import org.dataone.service.types.ObjectFormatIdentifier; |
53 | 48 |
import org.dataone.service.types.ObjectFormatList; |
54 | 49 |
import org.dataone.service.types.ObjectList; |
55 |
import org.dataone.service.types.ObjectLocation; |
|
56 | 50 |
import org.dataone.service.types.ObjectLocationList; |
57 | 51 |
import org.dataone.service.types.Permission; |
58 | 52 |
import org.dataone.service.types.QueryType; |
... | ... | |
66 | 60 |
import edu.ucsb.nceas.metacat.EventLog; |
67 | 61 |
import edu.ucsb.nceas.metacat.IdentifierManager; |
68 | 62 |
import edu.ucsb.nceas.metacat.McdbDocNotFoundException; |
69 |
import edu.ucsb.nceas.metacat.properties.PropertyService; |
|
70 | 63 |
import edu.ucsb.nceas.metacat.replication.ForceReplicationSystemMetadataHandler; |
71 |
import edu.ucsb.nceas.utilities.PropertyNotFoundException; |
|
72 | 64 |
|
73 | 65 |
/** |
74 | 66 |
* Represents Metacat's implementation of the DataONE Coordinating Node |
... | ... | |
354 | 346 |
throws InvalidRequest, InvalidToken, ServiceFailure, NotAuthorized, |
355 | 347 |
NotFound, NotImplemented { |
356 | 348 |
|
357 |
ObjectLocationList objLocList = new ObjectLocationList(); |
|
358 |
objLocList.setIdentifier(pid); |
|
359 |
|
|
360 |
// get the system metadata |
|
361 |
String guid = pid.getValue(); |
|
362 |
|
|
363 |
// are we allowed to do this? |
|
364 |
if (!isAuthorized(session, pid, Permission.READ)) { |
|
365 |
throw new NotAuthorized("4720", Permission.READ + " not allowed on " + guid); |
|
366 |
} |
|
367 |
|
|
368 |
SystemMetadata systemMetadata = null; |
|
369 |
try { |
|
370 |
systemMetadata = IdentifierManager.getInstance().getSystemMetadata(guid); |
|
371 |
} catch (McdbDocNotFoundException e) { |
|
372 |
throw new NotFound("4740", "No record found for: " + guid); |
|
373 |
} |
|
374 |
|
|
375 |
NodeList nodes = listNodes(); |
|
376 |
|
|
377 |
// get the locations |
|
378 |
List<Replica> replicas = systemMetadata.getReplicaList(); |
|
379 |
for (Replica replica: replicas) { |
|
380 |
NodeReference nodeReference = replica.getReplicaMemberNode(); |
|
381 |
ObjectLocation objectLocation = new ObjectLocation(); |
|
382 |
objectLocation.setNodeIdentifier(nodeReference); |
|
383 |
// get the node |
|
384 |
Node node = null; |
|
385 |
for (Node n: nodes.getNodeList()) { |
|
386 |
if (n.getIdentifier().equals(nodeReference)) { |
|
387 |
node = n; |
|
388 |
break; |
|
389 |
} |
|
390 |
} |
|
391 |
// set base URL |
|
392 |
objectLocation.setBaseURL(node.getBaseURL()); |
|
393 |
// set URL |
|
394 |
objectLocation.setUrl(node.getBaseURL() + "/object/" + pid.getValue()); |
|
395 |
// TODO set meaningful preference |
|
396 |
objectLocation.setPreference(BigInteger.ONE); |
|
397 |
objLocList.addObjectLocation(objectLocation); |
|
398 |
} |
|
399 |
|
|
400 |
return objLocList; |
|
349 |
throw new NotImplemented("4131", "resolve not implemented"); |
|
350 |
|
|
401 | 351 |
} |
402 | 352 |
|
403 | 353 |
/** |
Also available in: Unified diff
remove resolve() test -- not implemented in Metacat