Project

General

Profile

« Previous | Next » 

Revision 6418

save system metadata and/or science metadata and/or ORE objects to the local CN if needed.

View differences:

src/edu/ucsb/nceas/metacat/dataone/CNReplicationTask.java
20 20

  
21 21
package edu.ucsb.nceas.metacat.dataone;
22 22

  
23
import java.io.InputStream;
23 24
import java.io.Serializable;
24 25
import java.util.concurrent.Callable;
25 26

  
......
28 29
import org.dataone.configuration.Settings;
29 30
import org.dataone.service.exceptions.InsufficientResources;
30 31
import org.dataone.service.exceptions.InvalidRequest;
32
import org.dataone.service.exceptions.InvalidToken;
31 33
import org.dataone.service.exceptions.NotAuthorized;
34
import org.dataone.service.exceptions.NotFound;
32 35
import org.dataone.service.exceptions.NotImplemented;
33 36
import org.dataone.service.exceptions.ServiceFailure;
34 37
import org.dataone.service.exceptions.UnsupportedType;
......
39 42
import org.dataone.service.types.v1.Subject;
40 43
import org.dataone.service.types.v1.SystemMetadata;
41 44

  
45
import quicktime.std.qtcomponents.SCInfo;
46

  
42 47
import com.hazelcast.core.Hazelcast;
43 48
import com.hazelcast.core.HazelcastInstance;
44 49
import com.hazelcast.core.IMap;
45 50

  
51
import edu.ucsb.nceas.metacat.IdentifierManager;
52
import edu.ucsb.nceas.metacat.McdbDocNotFoundException;
53

  
46 54
/**
47 55
 * A single CN replication task to be executed by the CN Replication Service. This 
48 56
 * applies to replication of system metadata, science metadata, and resource maps 
......
59 67
 * @author cjones
60 68
 *
61 69
 */
62
public class CNReplicationTask implements Serializable, Callable<String> {
70
public class CNReplicationTask implements Serializable, Callable<Identifier> {
63 71

  
64 72
  /* The identifier of this task */
65 73
  private String taskid;
66 74
  
67 75
  /* The identifier of the object to replicate */
68
  private String pid;
76
  private Identifier pid;
69 77
  
70 78
  /* The object format type stated in the system metadata (DATA/METADATA/RESOURCE) */
71 79
  private String formatType;
......
103 111
    Permission replicatePermission) {
104 112
    
105 113
    this.taskid = taskid;
106
    this.pid = pid.getValue();
114
    this.pid = pid;
107 115
    this.formatType = formatType;
108 116
    this.originatingNode = originatingNode;
109 117
    this.targetNode = targetNode;
......
134 142
   * @return the pid
135 143
   */
136 144
  public Identifier getPid() {
137
    Identifier identifier = new Identifier();
138
    identifier.setValue(pid);
139
    return identifier;
145
    return pid;
140 146
  }
141 147

  
142 148
  /**
......
144 150
   * @param pid the pid to set
145 151
   */
146 152
  public void setPid(Identifier pid) {
147
    this.pid = pid.getValue();
153
    this.pid = pid;
148 154
  }
149 155

  
150 156

  
......
262 268
   * 
263 269
   * @return pid - the identifier of the replicated object upon success
264 270
   */
265
  public String call() {
271
  public Identifier call() {
266 272
		
267 273
	// Get the D1 Hazelcast configuration parameters
268 274
	String hzSystemMetadata = 
......
271 277
	// get the system metadata for the pid	
272 278
	IMap<Identifier, SystemMetadata> sysMetaMap = Hazelcast.getMap(hzSystemMetadata);
273 279
	
274
	// TODO: Store the object in Metacat by calling the appropriate class
275
	    
280
	// get the systemMetadata
281
	SystemMetadata sm = sysMetaMap.get(pid);
276 282
	
277
    return null;
283
	
284
  	
285
  	// only system metadata - no data replicated
286
  	boolean isData = formatType.equals("??");
287
  	if (!isData) {
288
  		// TODO: get the science metadata/ORE from somewhere
289
  		InputStream sciMetaORE = null;
290
		try {
291
			sciMetaORE = CNodeService.getInstance().get(null, pid);
292
		} catch (NotFound nf) {
293
			try {
294
				sciMetaORE = D1Client.getCN().get(null, pid);
295
				// save it locally
296
		  		CNodeService.getInstance().create(null, pid, sciMetaORE, sm);
297
			} catch (Exception e) {
298
				// TODO Auto-generated catch block
299
				e.printStackTrace();
300
			}
301
		} catch (Exception e) {
302
			e.printStackTrace();
303
		}
304
  	} else {
305
  		// just system metadata
306
  		try {
307
  			if (!IdentifierManager.getInstance().identifierExists(pid.getValue())) {
308
  				IdentifierManager.getInstance().createSystemMetadata(sm);
309
  			} else {
310
  				IdentifierManager.getInstance().updateSystemMetadata(sm);
311
  			}  
312
  	  	} catch (McdbDocNotFoundException e) {
313
  			// TODO Auto-generated catch block
314
  			e.printStackTrace();
315
  			return null;
316
  		}
317
  	}
318
  	
319
    return pid;
278 320
  }
279 321

  
280 322
}

Also available in: Unified diff