Project

General

Profile

« Previous | Next » 

Revision 6332

provisional replicate() implementation -- does not check if the session's subject is "allowed" to do this.
the test also requires 2 servers -- right now it attempts to replicate with itself which will fail because of duplicate IDs

View differences:

test/edu/ucsb/nceas/metacat/dataone/MNodeServiceTest.java
454 454
		    Session session = getTestSession();
455 455
		    Identifier guid = new Identifier();
456 456
		    guid.setValue("testReplicate." + System.currentTimeMillis());
457
		    SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), null);
458
			NodeReference sourceNode = new NodeReference();
459
			sourceNode.setValue("SOMETHING!!!");
457
		    InputStream object = new ByteArrayInputStream("test".getBytes("UTF-8"));
458
		    SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), object);
459
		    // save locally
460
		    Identifier pid = MNodeService.getInstance().create(session, guid, object, sysmeta);
461
		    // get our node reference (attempting to replicate with self
462
		    NodeReference sourceNode = MNodeService.getInstance().getCapabilities().getIdentifier();
463
		    // attempt to replicate with ourselves -- this should fail!
460 464
			boolean result = MNodeService.getInstance().replicate(session, sysmeta, sourceNode );
461 465
			assertTrue(result);
462 466
	    } catch (Exception e) {
src/edu/ucsb/nceas/metacat/dataone/MNodeService.java
33 33

  
34 34
import org.apache.commons.io.IOUtils;
35 35
import org.apache.log4j.Logger;
36
import org.dataone.client.D1Client;
37
import org.dataone.client.MNode;
36 38
import org.dataone.service.exceptions.IdentifierNotUnique;
37 39
import org.dataone.service.exceptions.InsufficientResources;
38 40
import org.dataone.service.exceptions.InvalidRequest;
......
419 421
    throws NotImplemented, ServiceFailure, NotAuthorized, InvalidRequest,
420 422
    InsufficientResources, UnsupportedType {
421 423

  
422
    return false;
424
    boolean result = false;
425

  
426
    // TODO: check credentials
427
    
428
    // get the referenced object
429
    Identifier pid = sysmeta.getIdentifier();
430
    
431
    // get from the membernode
432
    // TODO: switch credentials for the server retrieval?
433
    MNode mn = D1Client.getMN(sourceNode);
434
    InputStream object = null;
435

  
436
	try {
437
		object = mn.get(session, pid);
438
	} catch (InvalidToken e) {
439
		e.printStackTrace();
440
		throw new ServiceFailure("2151", "Could not retrieve object to replicate (InvalidToken): " + e.getMessage());
441
	} catch (NotFound e) {
442
		e.printStackTrace();
443
		throw new ServiceFailure("2151", "Could not retrieve object to replicate (NotFound): " + e.getMessage());
444
	}
445
	
446
    // add it to local store
447
	Identifier retPid;
448
	try {
449
		retPid = create(session, pid, object, sysmeta);
450
		result = (retPid.getValue().equals(pid.getValue()));
451
	} catch (InvalidToken e) {
452
		e.printStackTrace();
453
		throw new ServiceFailure("2151", "Could not save object to local store (InvalidToken): " + e.getMessage());
454
	} catch (IdentifierNotUnique e) {
455
		e.printStackTrace();
456
		throw new ServiceFailure("2151", "Could not save object to local store (IdentifierNotUnique): " + e.getMessage());
457
	} catch (InvalidSystemMetadata e) {
458
		e.printStackTrace();
459
		throw new ServiceFailure("2151", "Could not save object to local store (InvalidSystemMetadata): " + e.getMessage());
460
	}
461
	        
462
    return result;
463
	  
423 464
  }
424 465

  
425 466
  /**

Also available in: Unified diff