Project

General

Profile

« Previous | Next » 

Revision 6756

Added by Chris Jones over 12 years ago

Minor reformatting for readability.

View differences:

src/edu/ucsb/nceas/metacat/restservice/CNResourceHandler.java
83 83
/**
84 84
 * CN REST service implementation handler
85 85
 * 
86
 * ******************
87
 	CNCore -- DONE
88
		create() - POST /d1/cn/object/PID
89
		listFormats() - GET /d1/cn/formats
90
		getFormat() - GET /d1/cn/formats/FMTID
91
		getLogRecords - GET /d1/cn/log
92
		reserveIdentifier() - POST /d1/cn/reserve
93
		listNodes() - Not implemented
94
		registerSystemMetadata() - POST /d1/meta/PID
95
	
96
	CNRead -- DONE
97
		get() - GET /d1/cn/object/PID
98
		getSystemMetadata() - GET /d1/cn/meta/PID
99
		resolve() - GET /d1/cn/resolve/PID
100
		assertRelation() - GET /d1/cn/assertRelation/PID
101
		getChecksum() - GET /d1/cn/checksum
102
		search() - Not implemented in Metacat
103
	
104
	CNAuthorization
105
		setOwner() - PUT /d1/cn/owner/PID
106
		isAuthorized() - GET /d1/cn/isAuthorized/PID
107
		setAccessPolicy() - POST /d1/cn/accessRules
108
		
109
	CNIdentity - not implemented at all on Metacat
110
	
111
	CNReplication
112
		setReplicationStatus() - PUT /replicaNotifications/PID
113
		updateReplicationMetadata() - PUT /replicaMetadata/PID
114
		setReplicationPolicy() - PUT /replicaPolicies/PID
115
		isNodeAuthorized() - GET /replicaAuthorizations/PID
116
	
117
	CNRegister -- not implemented at all in Metacat
118
 * ******************
86
 * ****************** CNCore -- DONE create() - POST /d1/cn/object/PID
87
 * listFormats() - GET /d1/cn/formats getFormat() - GET /d1/cn/formats/FMTID
88
 * getLogRecords - GET /d1/cn/log reserveIdentifier() - POST /d1/cn/reserve
89
 * listNodes() - Not implemented registerSystemMetadata() - POST /d1/meta/PID
90
 * 
91
 * CNRead -- DONE get() - GET /d1/cn/object/PID getSystemMetadata() - GET
92
 * /d1/cn/meta/PID resolve() - GET /d1/cn/resolve/PID assertRelation() - GET
93
 * /d1/cn/assertRelation/PID getChecksum() - GET /d1/cn/checksum search() - Not
94
 * implemented in Metacat
95
 * 
96
 * CNAuthorization setOwner() - PUT /d1/cn/owner/PID isAuthorized() - GET
97
 * /d1/cn/isAuthorized/PID setAccessPolicy() - POST /d1/cn/accessRules
98
 * 
99
 * CNIdentity - not implemented at all on Metacat
100
 * 
101
 * CNReplication setReplicationStatus() - PUT /replicaNotifications/PID
102
 * updateReplicationMetadata() - PUT /replicaMetadata/PID setReplicationPolicy()
103
 * - PUT /replicaPolicies/PID isNodeAuthorized() - GET
104
 * /replicaAuthorizations/PID
105
 * 
106
 * CNRegister -- not implemented at all in Metacat ******************
107
 * 
119 108
 * @author leinfelder
120
 *
109
 * 
121 110
 */
122 111
public class CNResourceHandler extends D1ResourceHandler {
123 112

  
124
	/** CN-specific operations **/
113
    /** CN-specific operations **/
125 114
    protected static final String RESOURCE_RESERVE = "reserve";
126 115
    protected static final String RESOURCE_FORMATS = "formats";
127 116
    protected static final String RESOURCE_RESOLVE = "resolve";
......
131 120
    protected static final String RESOURCE_REPLICATION_META = "replicaMetadata";
132 121
    protected static final String RESOURCE_REPLICATION_AUTHORIZED = "replicaAuthorizations";
133 122
    protected static final String RESOURCE_REPLICATION_NOTIFY = "replicaNotifications";
134
	
123

  
135 124
    public CNResourceHandler(ServletContext servletContext,
136
			HttpServletRequest request, HttpServletResponse response) {
137
		super(servletContext, request, response);
125
            HttpServletRequest request, HttpServletResponse response) {
126
        super(servletContext, request, response);
138 127
        logMetacat = Logger.getLogger(CNResourceHandler.class);
139
	}
128
    }
140 129

  
141
	/**
142
     * This function is called from REST API servlet and handles each request to the servlet 
130
    /**
131
     * This function is called from REST API servlet and handles each request to
132
     * the servlet
143 133
     * 
144
     * @param httpVerb (GET, POST, PUT or DELETE)
134
     * @param httpVerb
135
     *            (GET, POST, PUT or DELETE)
145 136
     */
146 137
    @Override
147 138
    public void handle(byte httpVerb) {
148
    	// prepare the handler
149
    	super.handle(httpVerb);
150
    	
139
        // prepare the handler
140
        super.handle(httpVerb);
141

  
151 142
        try {
152 143

  
153
        	// get the resource
144
            // get the resource
154 145
            String resource = request.getPathInfo();
155 146
            resource = resource.substring(resource.indexOf("/") + 1);
156
                        
147

  
157 148
            // for the rest of the resouce
158 149
            String extra = null;
159
            
160
            logMetacat.debug("handling verb " + httpVerb + " request with resource '" + resource + "'");
150

  
151
            logMetacat.debug("handling verb " + httpVerb
152
                    + " request with resource '" + resource + "'");
161 153
            boolean status = false;
162 154

  
163 155
            if (resource != null) {
164 156

  
165
                if (resource.startsWith(RESOURCE_ACCESS_RULES) && httpVerb == PUT) {
157
                if (resource.startsWith(RESOURCE_ACCESS_RULES)
158
                        && httpVerb == PUT) {
166 159
                    logMetacat.debug("Setting access policy");
167 160
                    // after the command
168 161
                    extra = parseTrailing(resource, RESOURCE_ACCESS_RULES);
169 162
                    setAccess(extra);
170 163
                    status = true;
171 164
                    logMetacat.debug("done setting access");
172
                    
165

  
173 166
                } else if (resource.startsWith(RESOURCE_META)) {
174 167
                    logMetacat.debug("Using resource: " + RESOURCE_META);
175
                    
168

  
176 169
                    // after the command
177 170
                    extra = parseTrailing(resource, RESOURCE_META);
178
                    
171

  
179 172
                    // get
180 173
                    if (httpVerb == GET) {
181 174
                        getSystemMetadataObject(extra);
......
183 176
                    }
184 177
                    // post to register system metadata
185 178
                    if (httpVerb == POST) {
186
                    	registerSystemMetadata(extra);
187
                    	status = true;
179
                        registerSystemMetadata(extra);
180
                        status = true;
188 181
                    }
189 182

  
190 183
                } else if (resource.startsWith(RESOURCE_RESERVE)) {
191 184
                    // reserve the ID (in params)
192 185
                    if (httpVerb == POST) {
193
                    	reserve();
194
                    	status = true;
186
                        reserve();
187
                        status = true;
195 188
                    }
196 189
                } else if (resource.startsWith(RESOURCE_ASSERT_RELATION)) {
197
                	
198
                	// after the command
190

  
191
                    // after the command
199 192
                    extra = parseTrailing(resource, RESOURCE_ASSERT_RELATION);
200
                    
193

  
201 194
                    // reserve the ID (in params)
202 195
                    if (httpVerb == GET) {
203
                    	assertRelation(extra);
204
                    	status = true;
205
                    }    
196
                        assertRelation(extra);
197
                        status = true;
198
                    }
206 199
                } else if (resource.startsWith(RESOURCE_RESOLVE)) {
207
                	
208
                	// after the command
200

  
201
                    // after the command
209 202
                    extra = parseTrailing(resource, RESOURCE_RESOLVE);
210
                    
203

  
211 204
                    // resolve the object location
212 205
                    if (httpVerb == GET) {
213
                    	resolve(extra);
214
                    	status = true;
206
                        resolve(extra);
207
                        status = true;
215 208
                    }
216 209
                } else if (resource.startsWith(RESOURCE_OWNER)) {
217
                	
218
                	// after the command
210

  
211
                    // after the command
219 212
                    extra = parseTrailing(resource, RESOURCE_OWNER);
220
                    
213

  
221 214
                    // set the owner
222 215
                    if (httpVerb == PUT) {
223
                    	owner(extra);
224
                    	status = true;
225
                    }    
216
                        owner(extra);
217
                        status = true;
218
                    }
226 219
                } else if (resource.startsWith(RESOURCE_IS_AUTHORIZED)) {
227
                	
228
                	// after the command
220

  
221
                    // after the command
229 222
                    extra = parseTrailing(resource, RESOURCE_IS_AUTHORIZED);
230
                    
223

  
231 224
                    // authorized?
232 225
                    if (httpVerb == GET) {
233
                    	isAuthorized(extra);
234
                    	status = true;
235
                    }    
226
                        isAuthorized(extra);
227
                        status = true;
228
                    }
236 229
                } else if (resource.startsWith(RESOURCE_OBJECTS)) {
237 230
                    logMetacat.debug("Using resource 'object'");
238
                    logMetacat.debug("D1 Rest: Starting resource processing...");
239
                    
231
                    logMetacat
232
                            .debug("D1 Rest: Starting resource processing...");
233

  
240 234
                    // after the command
241 235
                    extra = parseTrailing(resource, RESOURCE_OBJECTS);
242
                    
236

  
243 237
                    logMetacat.debug("objectId: " + extra);
244 238
                    logMetacat.debug("verb:" + httpVerb);
245 239

  
246 240
                    if (httpVerb == GET) {
247
                    	if (extra != null) {
248
                    		getObject(extra);
249
                    	} else {
250
                    		listObjects();
251
                    	}
241
                        if (extra != null) {
242
                            getObject(extra);
243
                        } else {
244
                            listObjects();
245
                        }
252 246
                        status = true;
253 247
                    } else if (httpVerb == POST) {
254 248
                        putObject(extra, FUNCTION_NAME_INSERT);
255 249
                        status = true;
256 250
                    }
257
                    
251

  
258 252
                } else if (resource.startsWith(RESOURCE_FORMATS)) {
259
                  logMetacat.debug("Using resource: " + RESOURCE_FORMATS);
260
                  
261
                  // after the command
262
                  extra = parseTrailing(resource, RESOURCE_FORMATS);
263
                  
264
                  // handle each verb
265
                  if (httpVerb == GET) {
266
                  	if (extra == null) {
267
                  		// list the formats collection
268
                  		listFormats();
269
                  	} else {
270
                  		// get the specified format
271
                  		getFormat(extra);
272
                  	}
273
                  	status = true;
274
                  }
275
                  
253
                    logMetacat.debug("Using resource: " + RESOURCE_FORMATS);
254

  
255
                    // after the command
256
                    extra = parseTrailing(resource, RESOURCE_FORMATS);
257

  
258
                    // handle each verb
259
                    if (httpVerb == GET) {
260
                        if (extra == null) {
261
                            // list the formats collection
262
                            listFormats();
263
                        } else {
264
                            // get the specified format
265
                            getFormat(extra);
266
                        }
267
                        status = true;
268
                    }
269

  
276 270
                } else if (resource.startsWith(RESOURCE_LOG)) {
277 271
                    logMetacat.debug("Using resource: " + RESOURCE_LOG);
278
                    //handle log events
272
                    // handle log events
279 273
                    if (httpVerb == GET) {
280 274
                        getLog();
281 275
                        status = true;
......
283 277

  
284 278
                } else if (resource.startsWith(RESOURCE_CHECKSUM)) {
285 279
                    logMetacat.debug("Using resource: " + RESOURCE_CHECKSUM);
286
                    
280

  
287 281
                    // after the command
288 282
                    extra = parseTrailing(resource, RESOURCE_CHECKSUM);
289
                    
290
                    //handle checksum requests
283

  
284
                    // handle checksum requests
291 285
                    if (httpVerb == GET) {
292
                    
286

  
293 287
                        checksum(extra);
294 288
                        status = true;
295
                        
289

  
296 290
                    }
297
                
298
                } else if ( resource.startsWith(RESOURCE_REPLICATION_POLICY) && 
299
                        httpVerb == PUT) {
300
                    
301
                    logMetacat.debug("Using resource: " + RESOURCE_REPLICATION_POLICY);
291

  
292
                } else if (resource.startsWith(RESOURCE_REPLICATION_POLICY)
293
                        && httpVerb == PUT) {
294

  
295
                    logMetacat.debug("Using resource: "
296
                            + RESOURCE_REPLICATION_POLICY);
302 297
                    // get the trailing pid
303 298
                    extra = parseTrailing(resource, RESOURCE_REPLICATION_POLICY);
304 299
                    setReplicationPolicy(extra);
305 300
                    status = true;
306 301

  
307
                } else if ( resource.startsWith(RESOURCE_REPLICATION_META) && 
308
                        httpVerb == PUT) {
309
                    
310
                    logMetacat.debug("Using resource: " + RESOURCE_REPLICATION_META);
302
                } else if (resource.startsWith(RESOURCE_REPLICATION_META)
303
                        && httpVerb == PUT) {
304

  
305
                    logMetacat.debug("Using resource: "
306
                            + RESOURCE_REPLICATION_META);
311 307
                    // get the trailing pid
312 308
                    extra = parseTrailing(resource, RESOURCE_REPLICATION_META);
313 309
                    updateReplicationMetadata(extra);
314 310
                    status = true;
315 311

  
316
                } else if ( resource.startsWith(RESOURCE_REPLICATION_NOTIFY) && 
317
                        httpVerb == PUT ) {
318
                    
319
                    logMetacat.debug("Using resource: " + RESOURCE_REPLICATION_NOTIFY);
312
                } else if (resource.startsWith(RESOURCE_REPLICATION_NOTIFY)
313
                        && httpVerb == PUT) {
314

  
315
                    logMetacat.debug("Using resource: "
316
                            + RESOURCE_REPLICATION_NOTIFY);
320 317
                    // get the trailing pid
321 318
                    extra = parseTrailing(resource, RESOURCE_REPLICATION_NOTIFY);
322 319
                    setReplicationStatus(extra);
323 320
                    status = true;
324
                    
325
                } else if ( resource.startsWith(RESOURCE_REPLICATION_AUTHORIZED) 
321

  
322
                } else if (resource.startsWith(RESOURCE_REPLICATION_AUTHORIZED)
326 323
                        && httpVerb == GET) {
327
                    
328
                    logMetacat.debug("Using resource: " + RESOURCE_REPLICATION_AUTHORIZED);
324

  
325
                    logMetacat.debug("Using resource: "
326
                            + RESOURCE_REPLICATION_AUTHORIZED);
329 327
                    // get the trailing pid
330
                    extra = parseTrailing(resource, RESOURCE_REPLICATION_AUTHORIZED);
328
                    extra = parseTrailing(resource,
329
                            RESOURCE_REPLICATION_AUTHORIZED);
331 330
                    isNodeAuthorized(extra);
332 331
                    status = true;
333
                    
334
                } 
335
                    
332

  
333
                }
334

  
336 335
                if (!status) {
337
                	throw new ServiceFailure("0000", "Unknown error, status = " + status);
336
                    throw new ServiceFailure("0000", "Unknown error, status = "
337
                            + status);
338 338
                }
339 339
            } else {
340
            	throw new InvalidRequest("0000", "No resource matched for " + resource);
340
                throw new InvalidRequest("0000", "No resource matched for "
341
                        + resource);
341 342
            }
342 343
        } catch (BaseException be) {
343
        	// report Exceptions as clearly and generically as possible
344
        	OutputStream out = null;
345
			try {
346
				out = response.getOutputStream();
347
			} catch (IOException ioe) {
348
				logMetacat.error("Could not get output stream from response", ioe);
349
			}
344
            // report Exceptions as clearly and generically as possible
345
            OutputStream out = null;
346
            try {
347
                out = response.getOutputStream();
348
            } catch (IOException ioe) {
349
                logMetacat.error("Could not get output stream from response",
350
                        ioe);
351
            }
350 352
            serializeException(be, out);
351 353
        } catch (Exception e) {
352 354
            // report Exceptions as clearly and generically as possible
353 355
            logMetacat.error(e.getClass() + ": " + e.getMessage(), e);
354
        	OutputStream out = null;
355
			try {
356
				out = response.getOutputStream();
357
			} catch (IOException ioe) {
358
				logMetacat.error("Could not get output stream from response", ioe);
359
			}
360
			ServiceFailure se = new ServiceFailure("0000", e.getMessage());
356
            OutputStream out = null;
357
            try {
358
                out = response.getOutputStream();
359
            } catch (IOException ioe) {
360
                logMetacat.error("Could not get output stream from response",
361
                        ioe);
362
            }
363
            ServiceFailure se = new ServiceFailure("0000", e.getMessage());
361 364
            serializeException(se, out);
362 365
        }
363 366
    }
364
    
365
    
367

  
366 368
    /**
367 369
     * Get the checksum for the given guid
368 370
     * 
369 371
     * @param guid
370
     * @throws NotImplemented 
371
     * @throws InvalidRequest 
372
     * @throws NotFound 
373
     * @throws NotAuthorized 
374
     * @throws ServiceFailure 
375
     * @throws InvalidToken 
376
     * @throws IOException 
377
     * @throws JiBXException 
372
     * @throws NotImplemented
373
     * @throws InvalidRequest
374
     * @throws NotFound
375
     * @throws NotAuthorized
376
     * @throws ServiceFailure
377
     * @throws InvalidToken
378
     * @throws IOException
379
     * @throws JiBXException
378 380
     */
379
    private void checksum(String guid) throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, InvalidRequest, NotImplemented, JiBXException, IOException {
380
    	Identifier guidid = new Identifier();
381
    private void checksum(String guid) throws InvalidToken, ServiceFailure,
382
            NotAuthorized, NotFound, InvalidRequest, NotImplemented,
383
            JiBXException, IOException {
384
        Identifier guidid = new Identifier();
381 385
        guidid.setValue(guid);
382 386
        logMetacat.debug("getting checksum for object " + guid);
383
        Checksum c = CNodeService.getInstance(request).getChecksum(session, guidid);
387
        Checksum c = CNodeService.getInstance(request).getChecksum(session,
388
                guidid);
384 389
        logMetacat.debug("got checksum " + c.getValue());
385 390
        response.setStatus(200);
386 391
        logMetacat.debug("serializing response");
387 392
        TypeMarshaller.marshalTypeToOutputStream(c, response.getOutputStream());
388 393
        logMetacat.debug("done serializing response.");
389
        
394

  
390 395
    }
391
    
392
	/**
393
     * get the logs based on passed params.  Available 
394
     * params are token, fromDate, toDate, event.  See 
395
     * http://mule1.dataone.org/ArchitectureDocs/mn_api_crud.html#MN_crud.getLogRecords
396
     * for more info
397
	 * @throws NotImplemented 
398
	 * @throws InvalidRequest 
399
	 * @throws NotAuthorized 
400
	 * @throws ServiceFailure 
401
	 * @throws InvalidToken 
402
	 * @throws IOException 
403
	 * @throws JiBXException 
396

  
397
    /**
398
     * get the logs based on passed params. Available params are token,
399
     * fromDate, toDate, event. See
400
     * http://mule1.dataone.org/ArchitectureDocs/mn_api_crud
401
     * .html#MN_crud.getLogRecords for more info
402
     * 
403
     * @throws NotImplemented
404
     * @throws InvalidRequest
405
     * @throws NotAuthorized
406
     * @throws ServiceFailure
407
     * @throws InvalidToken
408
     * @throws IOException
409
     * @throws JiBXException
404 410
     */
405
    private void getLog() throws InvalidToken, ServiceFailure, NotAuthorized, InvalidRequest, NotImplemented, IOException, JiBXException
406
    {
407
        
411
    private void getLog() throws InvalidToken, ServiceFailure, NotAuthorized,
412
            InvalidRequest, NotImplemented, IOException, JiBXException {
413

  
408 414
        Date fromDate = null;
409 415
        Date toDate = null;
410 416
        Event event = null;
411 417
        Integer start = null;
412 418
        Integer count = null;
413
        
419

  
414 420
        try {
415
        	String fromDateS = params.get("fromDate")[0];
421
            String fromDateS = params.get("fromDate")[0];
416 422
            logMetacat.debug("param fromDateS: " + fromDateS);
417 423
            fromDate = DateTimeMarshaller.deserializeDateToUTC(fromDateS);
418 424
        } catch (Exception e) {
419
        	logMetacat.warn("Could not parse fromDate: " + e.getMessage());
425
            logMetacat.warn("Could not parse fromDate: " + e.getMessage());
420 426
        }
421 427
        try {
422
        	String toDateS = params.get("toDate")[0];
428
            String toDateS = params.get("toDate")[0];
423 429
            logMetacat.debug("param toDateS: " + toDateS);
424 430
            toDate = DateTimeMarshaller.deserializeDateToUTC(toDateS);
425 431
        } catch (Exception e) {
426
        	logMetacat.warn("Could not parse toDate: " + e.getMessage());
427
		}
432
            logMetacat.warn("Could not parse toDate: " + e.getMessage());
433
        }
428 434
        try {
429
        	String eventS = params.get("event")[0];
435
            String eventS = params.get("event")[0];
430 436
            event = Event.convert(eventS);
431 437
        } catch (Exception e) {
432
        	logMetacat.warn("Could not parse event: " + e.getMessage());
433
		}
438
            logMetacat.warn("Could not parse event: " + e.getMessage());
439
        }
434 440
        logMetacat.debug("fromDate: " + fromDate + " toDate: " + toDate);
435
        
441

  
436 442
        try {
437
        	start =  Integer.parseInt(params.get("start")[0]);
443
            start = Integer.parseInt(params.get("start")[0]);
438 444
        } catch (Exception e) {
439
			logMetacat.warn("Could not parse start: " + e.getMessage());
440
		}
445
            logMetacat.warn("Could not parse start: " + e.getMessage());
446
        }
441 447
        try {
442
        	count =  Integer.parseInt(params.get("count")[0]);
448
            count = Integer.parseInt(params.get("count")[0]);
443 449
        } catch (Exception e) {
444
			logMetacat.warn("Could not parse count: " + e.getMessage());
445
		}
446
        
450
            logMetacat.warn("Could not parse count: " + e.getMessage());
451
        }
452

  
447 453
        logMetacat.debug("calling getLogRecords");
448
        Log log = CNodeService.getInstance(request).getLogRecords(session, fromDate, toDate, event, start, count);
449
        
454
        Log log = CNodeService.getInstance(request).getLogRecords(session,
455
                fromDate, toDate, event, start, count);
456

  
450 457
        OutputStream out = response.getOutputStream();
451 458
        response.setStatus(200);
452 459
        response.setContentType("text/xml");
453
        
460

  
454 461
        TypeMarshaller.marshalTypeToOutputStream(log, out);
455
  
462

  
456 463
    }
457 464

  
458 465
    /**
459 466
     * Implements REST version of DataONE CRUD API --> get
460
     * @param guid ID of data object to be read
461
     * @throws NotImplemented 
462
     * @throws InvalidRequest 
463
     * @throws NotFound 
464
     * @throws NotAuthorized 
465
     * @throws ServiceFailure 
466
     * @throws InvalidToken 
467
     * @throws IOException 
467
     * 
468
     * @param guid
469
     *            ID of data object to be read
470
     * @throws NotImplemented
471
     * @throws InvalidRequest
472
     * @throws NotFound
473
     * @throws NotAuthorized
474
     * @throws ServiceFailure
475
     * @throws InvalidToken
476
     * @throws IOException
468 477
     */
469
    protected void getObject(String guid) throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, InvalidRequest, NotImplemented, IOException {
478
    protected void getObject(String guid) throws InvalidToken, ServiceFailure,
479
            NotAuthorized, NotFound, InvalidRequest, NotImplemented,
480
            IOException {
470 481

  
471 482
        Identifier id = new Identifier();
472 483
        id.setValue(guid);
473
            
474
        SystemMetadata sm = CNodeService.getInstance(request).getSystemMetadata(session, id);
475
        
476
        //set the content type
477
        if(sm.getFormatId().getValue().trim().equals(
478
        		ObjectFormatCache.getInstance().getFormat("text/csv").getFormatId().getValue()))
479
        {
484

  
485
        SystemMetadata sm = CNodeService.getInstance(request)
486
                .getSystemMetadata(session, id);
487

  
488
        // set the content type
489
        if (sm.getFormatId()
490
                .getValue()
491
                .trim()
492
                .equals(ObjectFormatCache.getInstance().getFormat("text/csv")
493
                        .getFormatId().getValue())) {
480 494
            response.setContentType("text/csv");
481
            response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".csv");
482
        }
483
        else if(sm.getFormatId().getValue().trim().equals(
484
        		ObjectFormatCache.getInstance().getFormat("text/plain").getFormatId().getValue()))
485
        {
495
            response.setHeader("Content-Disposition",
496
                    "inline; filename=" + id.getValue() + ".csv");
497
        } else if (sm
498
                .getFormatId()
499
                .getValue()
500
                .trim()
501
                .equals(ObjectFormatCache.getInstance().getFormat("text/plain")
502
                        .getFormatId().getValue())) {
486 503
            response.setContentType("text/plain");
487
            response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".txt");
488
        } 
489
        else if(sm.getFormatId().getValue().trim().equals(
490
        		ObjectFormatCache.getInstance().getFormat("application/octet-stream").getFormatId().getValue()))
491
        {
504
            response.setHeader("Content-Disposition",
505
                    "inline; filename=" + id.getValue() + ".txt");
506
        } else if (sm
507
                .getFormatId()
508
                .getValue()
509
                .trim()
510
                .equals(ObjectFormatCache.getInstance()
511
                        .getFormat("application/octet-stream").getFormatId()
512
                        .getValue())) {
492 513
            response.setContentType("application/octet-stream");
493
        }
494
        else
495
        {
514
        } else {
496 515
            response.setContentType("text/xml");
497
            response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".xml");
516
            response.setHeader("Content-Disposition",
517
                    "inline; filename=" + id.getValue() + ".xml");
498 518
        }
499
        
519

  
500 520
        InputStream data = CNodeService.getInstance(request).get(session, id);
501
        
521

  
502 522
        OutputStream out = response.getOutputStream();
503 523
        response.setStatus(200);
504 524
        IOUtils.copyLarge(data, out);
505
            
525

  
506 526
    }
507
    
508 527

  
509 528
    /**
510 529
     * Implements REST version of DataONE CRUD API --> getSystemMetadata
511
     * @param guid ID of data object to be read
512
     * @throws NotImplemented 
513
     * @throws InvalidRequest 
514
     * @throws NotFound 
515
     * @throws NotAuthorized 
516
     * @throws ServiceFailure 
517
     * @throws InvalidToken 
518
     * @throws IOException 
519
     * @throws JiBXException 
530
     * 
531
     * @param guid
532
     *            ID of data object to be read
533
     * @throws NotImplemented
534
     * @throws InvalidRequest
535
     * @throws NotFound
536
     * @throws NotAuthorized
537
     * @throws ServiceFailure
538
     * @throws InvalidToken
539
     * @throws IOException
540
     * @throws JiBXException
520 541
     */
521
    protected void getSystemMetadataObject(String guid) throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, InvalidRequest, NotImplemented, IOException, JiBXException {
542
    protected void getSystemMetadataObject(String guid) throws InvalidToken,
543
            ServiceFailure, NotAuthorized, NotFound, InvalidRequest,
544
            NotImplemented, IOException, JiBXException {
522 545

  
523 546
        Identifier id = new Identifier();
524 547
        id.setValue(guid);
525
        SystemMetadata sysmeta = CNodeService.getInstance(request).getSystemMetadata(session, id);
526
        
548
        SystemMetadata sysmeta = CNodeService.getInstance(request)
549
                .getSystemMetadata(session, id);
550

  
527 551
        response.setContentType("text/xml");
528 552
        response.setStatus(200);
529 553
        OutputStream out = response.getOutputStream();
530
        
554

  
531 555
        // Serialize and write it to the output stream
532 556
        TypeMarshaller.marshalTypeToOutputStream(sysmeta, out);
533
   }
534
    
557
    }
558

  
535 559
    /**
536
     * Earthgrid API > Put Service >Put Function : calls MetacatHandler > handleInsertOrUpdateAction 
560
     * Earthgrid API > Put Service >Put Function : calls MetacatHandler >
561
     * handleInsertOrUpdateAction
537 562
     * 
538
     * @param guid - ID of data object to be inserted or updated.  If action is update, the pid
539
     *               is the existing pid.  If insert, the pid is the new one
540
     * @throws InvalidRequest 
541
     * @throws ServiceFailure 
542
     * @throws IdentifierNotUnique 
543
     * @throws JiBXException 
544
     * @throws NotImplemented 
545
     * @throws InvalidSystemMetadata 
546
     * @throws InsufficientResources 
547
     * @throws UnsupportedType 
548
     * @throws NotAuthorized 
549
     * @throws InvalidToken 
550
     * @throws IOException 
551
     * @throws IllegalAccessException 
552
     * @throws InstantiationException 
563
     * @param guid
564
     *            - ID of data object to be inserted or updated. If action is
565
     *            update, the pid is the existing pid. If insert, the pid is the
566
     *            new one
567
     * @throws InvalidRequest
568
     * @throws ServiceFailure
569
     * @throws IdentifierNotUnique
570
     * @throws JiBXException
571
     * @throws NotImplemented
572
     * @throws InvalidSystemMetadata
573
     * @throws InsufficientResources
574
     * @throws UnsupportedType
575
     * @throws NotAuthorized
576
     * @throws InvalidToken
577
     * @throws IOException
578
     * @throws IllegalAccessException
579
     * @throws InstantiationException
553 580
     */
554
    protected void putObject(String pid, String action) throws ServiceFailure, InvalidRequest, IdentifierNotUnique, JiBXException, InvalidToken, NotAuthorized, UnsupportedType, InsufficientResources, InvalidSystemMetadata, NotImplemented, IOException, InstantiationException, IllegalAccessException {
581
    protected void putObject(String pid, String action) throws ServiceFailure,
582
            InvalidRequest, IdentifierNotUnique, JiBXException, InvalidToken,
583
            NotAuthorized, UnsupportedType, InsufficientResources,
584
            InvalidSystemMetadata, NotImplemented, IOException,
585
            InstantiationException, IllegalAccessException {
555 586
        logMetacat.debug("Entering putObject: " + pid + "/" + action);
556
        
587

  
557 588
        // Read the incoming data from its Mime Multipart encoding
558
    	Map<String, File> files = collectMultipartFiles();
589
        Map<String, File> files = collectMultipartFiles();
559 590
        InputStream object = null;
560 591
        InputStream sysmeta = null;
561 592

  
......
563 594
        sysmeta = new FileInputStream(smFile);
564 595
        File objFile = files.get("object");
565 596
        object = new FileInputStream(objFile);
566
       
567
        if (action.equals(FUNCTION_NAME_INSERT)) { //handle inserts
568 597

  
598
        if (action.equals(FUNCTION_NAME_INSERT)) { // handle inserts
599

  
569 600
            logMetacat.debug("Commence creation...");
570
            SystemMetadata smd = TypeMarshaller.unmarshalTypeFromStream(SystemMetadata.class, sysmeta);
601
            SystemMetadata smd = TypeMarshaller.unmarshalTypeFromStream(
602
                    SystemMetadata.class, sysmeta);
571 603

  
572 604
            Identifier id = new Identifier();
573 605
            id.setValue(pid);
574 606
            logMetacat.debug("creating object with pid " + id.getValue());
575
            Identifier rId = CNodeService.getInstance(request).create(session, id, object, smd);
576
            
607
            Identifier rId = CNodeService.getInstance(request).create(session,
608
                    id, object, smd);
609

  
577 610
            OutputStream out = response.getOutputStream();
578 611
            response.setStatus(200);
579 612
            response.setContentType("text/xml");
580
            
613

  
581 614
            TypeMarshaller.marshalTypeToOutputStream(rId, out);
582
            
615

  
583 616
        } else {
584 617
            throw new InvalidRequest("1000", "Operation must be create.");
585 618
        }
......
587 620

  
588 621
    /**
589 622
     * List the object formats registered with the system
590
     * @throws NotImplemented 
591
     * @throws InsufficientResources 
592
     * @throws NotFound 
593
     * @throws ServiceFailure 
594
     * @throws InvalidRequest 
595
     * @throws IOException 
596
     * @throws JiBXException 
623
     * 
624
     * @throws NotImplemented
625
     * @throws InsufficientResources
626
     * @throws NotFound
627
     * @throws ServiceFailure
628
     * @throws InvalidRequest
629
     * @throws IOException
630
     * @throws JiBXException
597 631
     */
598
	private void listFormats() throws InvalidRequest, ServiceFailure, NotFound, InsufficientResources, NotImplemented, IOException, JiBXException {
599
      logMetacat.debug("Entering listFormats()");
632
    private void listFormats() throws InvalidRequest, ServiceFailure, NotFound,
633
            InsufficientResources, NotImplemented, IOException, JiBXException {
634
        logMetacat.debug("Entering listFormats()");
600 635

  
601
      ObjectFormatList objectFormatList = CNodeService.getInstance(request).listFormats();
602
      // get the response output stream
603
      OutputStream out = response.getOutputStream();
604
      response.setStatus(200);
605
      response.setContentType("text/xml");
606
      
607
      // style the object with a processing directive
608
      String stylesheet = null;
609
      try {
610
    	  stylesheet = PropertyService.getProperty("dataone.types.xsl");
611
      } catch (PropertyNotFoundException e) {
612
    	  logMetacat.warn("Could not locate DataONE types XSLT: " + e.getMessage());
613
      }
614
      
615
      TypeMarshaller.marshalTypeToOutputStream(objectFormatList, out, stylesheet);
616
            
636
        ObjectFormatList objectFormatList = CNodeService.getInstance(request)
637
                .listFormats();
638
        // get the response output stream
639
        OutputStream out = response.getOutputStream();
640
        response.setStatus(200);
641
        response.setContentType("text/xml");
642

  
643
        // style the object with a processing directive
644
        String stylesheet = null;
645
        try {
646
            stylesheet = PropertyService.getProperty("dataone.types.xsl");
647
        } catch (PropertyNotFoundException e) {
648
            logMetacat.warn("Could not locate DataONE types XSLT: "
649
                    + e.getMessage());
650
        }
651

  
652
        TypeMarshaller.marshalTypeToOutputStream(objectFormatList, out,
653
                stylesheet);
654

  
617 655
    }
618 656

  
619
		/**
657
    /**
620 658
     * Return the requested object format
621 659
     * 
622
     * @param fmtidStr the requested format identifier as a string
623
		 * @throws NotImplemented 
624
		 * @throws InsufficientResources 
625
		 * @throws NotFound 
626
		 * @throws ServiceFailure 
627
		 * @throws InvalidRequest 
628
		 * @throws IOException 
629
		 * @throws JiBXException 
660
     * @param fmtidStr
661
     *            the requested format identifier as a string
662
     * @throws NotImplemented
663
     * @throws InsufficientResources
664
     * @throws NotFound
665
     * @throws ServiceFailure
666
     * @throws InvalidRequest
667
     * @throws IOException
668
     * @throws JiBXException
630 669
     */
631
    private void getFormat(String fmtidStr) throws InvalidRequest, ServiceFailure, NotFound, InsufficientResources, NotImplemented, IOException, JiBXException {
632
      logMetacat.debug("Entering listFormats()");
633
      
634
      ObjectFormatIdentifier fmtid = new ObjectFormatIdentifier();
635
      fmtid.setValue(fmtidStr);
636
      
637
	  // get the specified object format
638
      ObjectFormat objectFormat = CNodeService.getInstance(request).getFormat(fmtid);
639
      
640
      OutputStream out = response.getOutputStream();
641
      response.setStatus(200);
642
      response.setContentType("text/xml");
643
      
644
      TypeMarshaller.marshalTypeToOutputStream(objectFormat, out);
645
      
670
    private void getFormat(String fmtidStr) throws InvalidRequest,
671
            ServiceFailure, NotFound, InsufficientResources, NotImplemented,
672
            IOException, JiBXException {
673
        logMetacat.debug("Entering listFormats()");
674

  
675
        ObjectFormatIdentifier fmtid = new ObjectFormatIdentifier();
676
        fmtid.setValue(fmtidStr);
677

  
678
        // get the specified object format
679
        ObjectFormat objectFormat = CNodeService.getInstance(request)
680
                .getFormat(fmtid);
681

  
682
        OutputStream out = response.getOutputStream();
683
        response.setStatus(200);
684
        response.setContentType("text/xml");
685

  
686
        TypeMarshaller.marshalTypeToOutputStream(objectFormat, out);
687

  
646 688
    }
647
    
689

  
648 690
    /**
649 691
     * Reserve the given Identifier
692
     * 
650 693
     * @throws InvalidToken
651 694
     * @throws ServiceFailure
652 695
     * @throws NotAuthorized
653 696
     * @throws IdentifierNotUnique
654 697
     * @throws NotImplemented
655 698
     * @throws InvalidRequest
656
     * @throws IOException 
657
     * @throws JiBXException 
699
     * @throws IOException
700
     * @throws JiBXException
658 701
     */
659
    private void reserve() throws InvalidToken, ServiceFailure, NotAuthorized, IdentifierNotUnique, NotImplemented, InvalidRequest, IOException, JiBXException {
660
		Identifier pid = null;
661
		String scope = null;
662
    	String format = null;
663
    	// gather the params
664
		try {
665
	    	String id = params.get("pid")[0];
666
			pid = new Identifier();
667
			pid.setValue(id);
668
		} catch (Exception e) {
669
			logMetacat.warn("pid not specified");
670
		}
671
		try {
672
			scope = params.get("scope")[0];
673
		} catch (Exception e) {
674
			logMetacat.warn("pid not specified");
675
		}
676
		try {
677
			format = params.get("format")[0];
678
		} catch (Exception e) {
679
			logMetacat.warn("pid not specified");
680
		} 
681
		// call the implementation
682
		Identifier resultPid = CNodeService.getInstance(request).reserveIdentifier(session, pid);
683
		OutputStream out = response.getOutputStream();
684
		response.setStatus(200);
685
		response.setContentType("text/xml");
686
		// send back the reserved pid
687
		TypeMarshaller.marshalTypeToOutputStream(resultPid, out);
702
    private void reserve() throws InvalidToken, ServiceFailure, NotAuthorized,
703
            IdentifierNotUnique, NotImplemented, InvalidRequest, IOException,
704
            JiBXException {
705
        Identifier pid = null;
706
        String scope = null;
707
        String format = null;
708
        // gather the params
709
        try {
710
            String id = params.get("pid")[0];
711
            pid = new Identifier();
712
            pid.setValue(id);
713
        } catch (Exception e) {
714
            logMetacat.warn("pid not specified");
715
        }
716
        try {
717
            scope = params.get("scope")[0];
718
        } catch (Exception e) {
719
            logMetacat.warn("pid not specified");
720
        }
721
        try {
722
            format = params.get("format")[0];
723
        } catch (Exception e) {
724
            logMetacat.warn("pid not specified");
725
        }
726
        // call the implementation
727
        Identifier resultPid = CNodeService.getInstance(request)
728
                .reserveIdentifier(session, pid);
729
        OutputStream out = response.getOutputStream();
730
        response.setStatus(200);
731
        response.setContentType("text/xml");
732
        // send back the reserved pid
733
        TypeMarshaller.marshalTypeToOutputStream(resultPid, out);
688 734
    }
689
    
735

  
690 736
    /**
691 737
     * 
692 738
     * @param id
......
697 743
     * @throws NotFound
698 744
     * @throws NotImplemented
699 745
     * @throws IOException
700
     * @throws JiBXException 
746
     * @throws JiBXException
701 747
     */
702
    private void resolve(String id) throws InvalidRequest, InvalidToken, ServiceFailure, NotAuthorized, NotFound, NotImplemented, IOException, JiBXException {
703
		Identifier pid = new Identifier();
704
		pid.setValue(id);
705
		ObjectLocationList locationList = CNodeService.getInstance(request).resolve(session, pid);
706
	    OutputStream out = response.getOutputStream();
707
		response.setStatus(200);
708
		response.setContentType("text/xml");
709
		TypeMarshaller.marshalTypeToOutputStream(locationList, out);
710
		
748
    private void resolve(String id) throws InvalidRequest, InvalidToken,
749
            ServiceFailure, NotAuthorized, NotFound, NotImplemented,
750
            IOException, JiBXException {
751
        Identifier pid = new Identifier();
752
        pid.setValue(id);
753
        ObjectLocationList locationList = CNodeService.getInstance(request)
754
                .resolve(session, pid);
755
        OutputStream out = response.getOutputStream();
756
        response.setStatus(200);
757
        response.setContentType("text/xml");
758
        TypeMarshaller.marshalTypeToOutputStream(locationList, out);
759

  
711 760
    }
712 761

  
713 762
    /**
714 763
     * Assert that a relationship exists between two resources
764
     * 
715 765
     * @param id
716 766
     * @return
717 767
     * @throws InvalidToken
......
721 771
     * @throws InvalidRequest
722 772
     * @throws NotImplemented
723 773
     */
724
    private boolean assertRelation(String id) throws InvalidToken, ServiceFailure, NotAuthorized, NotFound, InvalidRequest, NotImplemented {
725
		Identifier pidOfSubject = new Identifier();
726
		pidOfSubject.setValue(id);
727
		String relationship = null;
728
		try {
729
			relationship = params.get("relationship")[0];
730
		} catch (Exception e) {
731
			logMetacat.warn("relationship not specified");
732
		}
733
		Identifier pidOfObject = new Identifier();
734
		try {
735
			String objPid = params.get("pidOfObject")[0];
736
			pidOfObject.setValue(objPid);
737
		} catch (Exception e) {
738
			logMetacat.warn("pidOfObject not specified");
739
		}
740
		boolean result = CNodeService.getInstance(request).assertRelation(session, pidOfSubject, relationship, pidOfObject);
741
		response.setStatus(200);
742
		response.setContentType("text/xml");
743
		return result;
774
    private boolean assertRelation(String id) throws InvalidToken,
775
            ServiceFailure, NotAuthorized, NotFound, InvalidRequest,
776
            NotImplemented {
777
        Identifier pidOfSubject = new Identifier();
778
        pidOfSubject.setValue(id);
779
        String relationship = null;
780
        try {
781
            relationship = params.get("relationship")[0];
782
        } catch (Exception e) {
783
            logMetacat.warn("relationship not specified");
784
        }
785
        Identifier pidOfObject = new Identifier();
786
        try {
787
            String objPid = params.get("pidOfObject")[0];
788
            pidOfObject.setValue(objPid);
789
        } catch (Exception e) {
790
            logMetacat.warn("pidOfObject not specified");
791
        }
792
        boolean result = CNodeService.getInstance(request).assertRelation(
793
                session, pidOfSubject, relationship, pidOfObject);
794
        response.setStatus(200);
795
        response.setContentType("text/xml");
796
        return result;
744 797
    }
745
    
798

  
746 799
    /**
747 800
     * Set the owner of a resource
801
     * 
748 802
     * @param id
749 803
     * @throws JiBXException
750 804
     * @throws InvalidToken
......
754 808
     * @throws NotImplemented
755 809
     * @throws InvalidRequest
756 810
     * @throws IOException
757
     * @throws IllegalAccessException 
758
     * @throws InstantiationException 
811
     * @throws IllegalAccessException
812
     * @throws InstantiationException
759 813
     */
760
    private void owner(String id) 
761
        throws JiBXException, InvalidToken, ServiceFailure, 
762
        NotFound, NotAuthorized, NotImplemented, InvalidRequest, IOException, 
763
        InstantiationException, IllegalAccessException {
764
		
814
    private void owner(String id) throws JiBXException, InvalidToken,
815
            ServiceFailure, NotFound, NotAuthorized, NotImplemented,
816
            InvalidRequest, IOException, InstantiationException,
817
            IllegalAccessException {
818

  
765 819
        Identifier pid = new Identifier();
766
		    pid.setValue(id);
820
        pid.setValue(id);
767 821

  
768 822
        long serialVersion = 0L;
769 823
        String serialVersionStr = null;
770
        
824

  
771 825
        // get the serialVersion
772 826
        try {
773 827
            serialVersionStr = params.get("serialVersion")[0];
774 828
            serialVersion = new Long(serialVersionStr).longValue();
775
            
829

  
776 830
        } catch (NullPointerException e) {
777 831
            String msg = "The 'serialVersion' must be provided as a parameter and was not.";
778 832
            logMetacat.error(msg);
779 833
            throw new InvalidRequest("4442", msg);
780
            
781
        }		    
782
		    
783
		    // get the subject
784
		    String subjectStr = params.get("subject")[0];
785
		    Subject subject = TypeMarshaller.unmarshalTypeFromStream(Subject.class, new ByteArrayInputStream(subjectStr.getBytes("UTF-8")));
786
		    
787
		    Identifier retPid = CNodeService.getInstance(request).setOwner(session, pid, subject, serialVersion);
788
		    OutputStream out = response.getOutputStream();
789
		    response.setStatus(200);
790
		    response.setContentType("text/xml");
791
		    TypeMarshaller.marshalTypeToOutputStream(retPid, out);		
834

  
835
        }
836

  
837
        // get the subject
838
        String subjectStr = params.get("subject")[0];
839
        Subject subject = TypeMarshaller.unmarshalTypeFromStream(Subject.class,
840
                new ByteArrayInputStream(subjectStr.getBytes("UTF-8")));
841

  
842
        Identifier retPid = CNodeService.getInstance(request).setOwner(session,
843
                pid, subject, serialVersion);
844
        OutputStream out = response.getOutputStream();
845
        response.setStatus(200);
846
        response.setContentType("text/xml");
847
        TypeMarshaller.marshalTypeToOutputStream(retPid, out);
792 848
    }
793
    
849

  
794 850
    /**
795 851
     * Processes the authorization check for given id
852
     * 
796 853
     * @param id
797 854
     * @return
798 855
     * @throws ServiceFailure
......
802 859
     * @throws NotImplemented
803 860
     * @throws InvalidRequest
804 861
     */
805
    private boolean isAuthorized(String id) throws ServiceFailure, InvalidToken, NotFound, NotAuthorized, NotImplemented, InvalidRequest {
806
		Identifier pid = new Identifier();
807
		pid.setValue(id);
808
		String permission = params.get("action")[0];
809
		boolean result = CNodeService.getInstance(request).isAuthorized(session, pid, Permission.convert(permission));
810
		response.setStatus(200);
811
		response.setContentType("text/xml");
812
		return result;
862
    private boolean isAuthorized(String id) throws ServiceFailure,
863
            InvalidToken, NotFound, NotAuthorized, NotImplemented,
864
            InvalidRequest {
865
        Identifier pid = new Identifier();
866
        pid.setValue(id);
867
        String permission = params.get("action")[0];
868
        boolean result = CNodeService.getInstance(request).isAuthorized(
869
                session, pid, Permission.convert(permission));
870
        response.setStatus(200);
871
        response.setContentType("text/xml");
872
        return result;
813 873
    }
814
    
874

  
815 875
    /**
816 876
     * Register System Metadata without data or metadata object
817
     * @param pid identifier for System Metadata entry
818
     * @throws JiBXException 
819
     * @throws FileUploadException 
820
     * @throws IOException 
821
     * @throws InvalidRequest 
822
     * @throws ServiceFailure 
823
     * @throws InvalidSystemMetadata 
824
     * @throws NotAuthorized 
825
     * @throws NotImplemented 
826
     * @throws IllegalAccessException 
827
     * @throws InstantiationException 
877
     * 
878
     * @param pid
879
     *            identifier for System Metadata entry
880
     * @throws JiBXException
881
     * @throws FileUploadException
882
     * @throws IOException
883
     * @throws InvalidRequest
884
     * @throws ServiceFailure
885
     * @throws InvalidSystemMetadata
886
     * @throws NotAuthorized
887
     * @throws NotImplemented
888
     * @throws IllegalAccessException
889
     * @throws InstantiationException
828 890
     */
829
    protected Identifier registerSystemMetadata(String pid) throws ServiceFailure, InvalidRequest, IOException, FileUploadException, JiBXException, NotImplemented, NotAuthorized, InvalidSystemMetadata, InstantiationException, IllegalAccessException {
830
		logMetacat.debug("Entering registerSystemMetadata: " + pid);
891
    protected Identifier registerSystemMetadata(String pid)
892
            throws ServiceFailure, InvalidRequest, IOException,
893
            FileUploadException, JiBXException, NotImplemented, NotAuthorized,
894
            InvalidSystemMetadata, InstantiationException,
895
            IllegalAccessException {
896
        logMetacat.debug("Entering registerSystemMetadata: " + pid);
831 897

  
832
		// get the system metadata from the request
833
		SystemMetadata systemMetadata = collectSystemMetadata();
898
        // get the system metadata from the request
899
        SystemMetadata systemMetadata = collectSystemMetadata();
834 900

  
835
		Identifier guid = new Identifier();
836
		guid.setValue(pid);
837
		logMetacat.debug("registering system metadata with pid " + guid.getValue());
838
		Identifier retGuid = CNodeService.getInstance(request).registerSystemMetadata(session, guid, systemMetadata);
839
		
840
		response.setStatus(200);
841
		response.setContentType("text/xml");
842
		return retGuid;
843
			
844
	}
845
    
901
        Identifier guid = new Identifier();
902
        guid.setValue(pid);
903
        logMetacat.debug("registering system metadata with pid "
904
                + guid.getValue());
905
        Identifier retGuid = CNodeService.getInstance(request)
906
                .registerSystemMetadata(session, guid, systemMetadata);
907

  
908
        response.setStatus(200);
909
        response.setContentType("text/xml");
910
        return retGuid;
911

  
912
    }
913

  
846 914
    /**
847 915
     * set the access perms on a document
848
     * @throws JiBXException 
849
     * @throws InvalidRequest 
850
     * @throws NotImplemented 
851
     * @throws NotAuthorized 
852
     * @throws NotFound 
853
     * @throws ServiceFailure 
854
     * @throws InvalidToken 
855
     * @throws IllegalAccessException 
856
     * @throws InstantiationException 
857
     * @throws IOException 
858
     * @throws SAXException 
859
     * @throws ParserConfigurationException 
916
     * 
917
     * @throws JiBXException
918
     * @throws InvalidRequest
919
     * @throws NotImplemented
920
     * @throws NotAuthorized
921
     * @throws NotFound
922
     * @throws ServiceFailure
923
     * @throws InvalidToken
924
     * @throws IllegalAccessException
925
     * @throws InstantiationException
926
     * @throws IOException
927
     * @throws SAXException
928
     * @throws ParserConfigurationException
860 929
     */
861
    protected void setAccess(String pid) 
862
        throws JiBXException, InvalidToken, ServiceFailure, NotFound, 
863
        NotAuthorized, NotImplemented, InvalidRequest, IOException, 
864
        InstantiationException, IllegalAccessException, ParserConfigurationException, 
865
        SAXException {
930
    protected void setAccess(String pid) throws JiBXException, InvalidToken,
931
            ServiceFailure, NotFound, NotAuthorized, NotImplemented,
932
            InvalidRequest, IOException, InstantiationException,
933
            IllegalAccessException, ParserConfigurationException, SAXException {
866 934

  
867 935
        long serialVersion = 0L;
868 936
        String serialVersionStr = null;
869
        
937

  
870 938
        // get the serialVersion
871 939
        try {
872 940
            serialVersionStr = params.get("serialVersion")[0];
873 941
            serialVersion = new Long(serialVersionStr).longValue();
874
            
942

  
875 943
        } catch (NullPointerException e) {
876 944
            String msg = "The 'serialVersion' must be provided as a parameter and was not.";
877 945
            logMetacat.error(msg);
878 946
            throw new InvalidRequest("4402", msg);
879
            
947

  
880 948
        }
881
        
949

  
882 950
        Identifier id = new Identifier();
883 951
        id.setValue(pid);
884
        
952

  
885 953
        AccessPolicy accessPolicy = collectAccessPolicy();
886
        CNodeService.getInstance(request).setAccessPolicy(session, id, accessPolicy, serialVersion);
954
        CNodeService.getInstance(request).setAccessPolicy(session, id,
955
                accessPolicy, serialVersion);
887 956

  
888 957
    }
889
    
958

  
890 959
    /**
891
     *	List the objects
892
     *
893
     * @throws NotImplemented 
894
     * @throws InvalidRequest 
895
     * @throws NotAuthorized 
896
     * @throws ServiceFailure 
897
     * @throws InvalidToken 
898
     * @throws NotFound 
899
     * @throws IOException 
960
     * List the objects
961
     * 
962
     * @throws NotImplemented
963
     * @throws InvalidRequest
964
     * @throws NotAuthorized
965
     * @throws ServiceFailure
966
     * @throws InvalidToken
967
     * @throws NotFound
968
     * @throws IOException
900 969
     * @throws JiBXException
901 970
     * @throws Exception
902 971
     */
903
    private void listObjects() throws InvalidToken, ServiceFailure, NotAuthorized,
904
			InvalidRequest, NotImplemented, NotFound, IOException,
905
			JiBXException {
972
    private void listObjects() throws InvalidToken, ServiceFailure,
973
            NotAuthorized, InvalidRequest, NotImplemented, NotFound,
974
            IOException, JiBXException {
906 975

  
907
		Date startTime = null;
908
		Date endTime = null;
909
		ObjectFormat objectFormat = null;
910
		boolean replicaStatus = false;
911
		int start = 0;
912
		int count = -1;
913
		Enumeration<String> paramlist = request.getParameterNames();
914
		while (paramlist.hasMoreElements()) {
915
			// parse the params and make the call
916
			String name = paramlist.nextElement();
917
			String[] value = request.getParameterValues(name);
976
        Date startTime = null;
977
        Date endTime = null;
978
        ObjectFormat objectFormat = null;
979
        boolean replicaStatus = false;
980
        int start = 0;
981
        int count = -1;
982
        Enumeration<String> paramlist = request.getParameterNames();
983
        while (paramlist.hasMoreElements()) {
984
            // parse the params and make the call
985
            String name = paramlist.nextElement();
986
            String[] value = request.getParameterValues(name);
918 987

  
919
			if (name.equals("startTime") && value != null) {
920
				try {
921
					startTime = DateTimeMarshaller.deserializeDateToUTC(value[0]);
922
				} catch (Exception e) { 
923
					// if we can't parse it, just don't use the startTime param
924
					logMetacat.warn("Could not parse startTime: " + value[0]);
925
					startTime = null;
926
				}
927
			} else if (name.equals("endTime") && value != null) {
928
				try {
929
					endTime = DateTimeMarshaller.deserializeDateToUTC(value[0]);
930
				} catch (Exception e) { 
931
					// if we can't parse it, just don't use the endTime param
932
					logMetacat.warn("Could not parse endTime: " + value[0]);
933
					endTime = null;
934
				}
935
			} else if (name.equals("objectFormat") && value != null) {
936
				objectFormat = ObjectFormatCache.getInstance().getFormat(value[0]);
937
			} else if (name.equals("replicaStatus") && value != null) {
938
				replicaStatus = Boolean.parseBoolean(value[0]);
939
			} else if (name.equals("start") && value != null) {
940
				start = Integer.valueOf(value[0]);
941
			} else if (name.equals("count") && value != null) {
942
				count = Integer.valueOf(value[0]);
943
			}
944
		}
945
		// make the call
946
		logMetacat.debug("session: " + session + " startTime: " + startTime
947
				+ " endtime: " + endTime + " objectFormat: " + objectFormat
948
				+ " replicaStatus: " + replicaStatus + " start: " + start
949
				+ " count: " + count);
988
            if (name.equals("startTime") && value != null) {
989
                try {
990
                    startTime = DateTimeMarshaller
991
                            .deserializeDateToUTC(value[0]);
992
                } catch (Exception e) {
993
                    // if we can't parse it, just don't use the startTime param
994
                    logMetacat.warn("Could not parse startTime: " + value[0]);
995
                    startTime = null;
996
                }
997
            } else if (name.equals("endTime") && value != null) {
998
                try {
999
                    endTime = DateTimeMarshaller.deserializeDateToUTC(value[0]);
1000
                } catch (Exception e) {
1001
                    // if we can't parse it, just don't use the endTime param
1002
                    logMetacat.warn("Could not parse endTime: " + value[0]);
1003
                    endTime = null;
1004
                }
1005
            } else if (name.equals("objectFormat") && value != null) {
1006
                objectFormat = ObjectFormatCache.getInstance().getFormat(
1007
                        value[0]);
1008
            } else if (name.equals("replicaStatus") && value != null) {
1009
                replicaStatus = Boolean.parseBoolean(value[0]);
1010
            } else if (name.equals("start") && value != null) {
1011
                start = Integer.valueOf(value[0]);
1012
            } else if (name.equals("count") && value != null) {
1013
                count = Integer.valueOf(value[0]);
1014
            }
1015
        }
1016
        // make the call
1017
        logMetacat.debug("session: " + session + " startTime: " + startTime
1018
                + " endtime: " + endTime + " objectFormat: " + objectFormat
1019
                + " replicaStatus: " + replicaStatus + " start: " + start
1020
                + " count: " + count);
950 1021

  
951
		ObjectFormatIdentifier fmtid = null;
952
		if (objectFormat != null) {
953
			fmtid = objectFormat.getFormatId();
954
		}
955
		
956
		// get the list
957
		ObjectList ol = 
958
			CNodeService.getInstance(request).listObjects(session,
959
				startTime, endTime, fmtid, replicaStatus, start, count);
1022
        ObjectFormatIdentifier fmtid = null;
1023
        if (objectFormat != null) {
1024
            fmtid = objectFormat.getFormatId();
1025
        }
960 1026

  
961
		// send it
962
		OutputStream out = response.getOutputStream();
963
		response.setStatus(200);
964
		response.setContentType("text/xml");
965
		
966
		// style the object with a processing directive
967
		String stylesheet = null;
968
		try {
969
			stylesheet = PropertyService.getProperty("dataone.types.xsl");
970
		} catch (PropertyNotFoundException e) {
971
			logMetacat.warn("Could not locate DataONE types XSLT: " + e.getMessage());
972
		}
973
	      
974
		// Serialize and write it to the output stream
975
		TypeMarshaller.marshalTypeToOutputStream(ol, out, stylesheet);
976
	}
977
    
1027
        // get the list
1028
        ObjectList ol = CNodeService.getInstance(request).listObjects(session,
1029
                startTime, endTime, fmtid, replicaStatus, start, count);
1030

  
1031
        // send it
1032
        OutputStream out = response.getOutputStream();
1033
        response.setStatus(200);
1034
        response.setContentType("text/xml");
1035

  
1036
        // style the object with a processing directive
1037
        String stylesheet = null;
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff