Project

General

Profile

« Previous | Next » 

Revision 6140

Added support in ResourceHandler for the /formats collection. Added listFormats() and getFormat() method, both of which call CNCoreImpl methods to handle the call.

View differences:

ResourceHandler.java
78 78
import org.dataone.service.types.NodeReference;
79 79
import org.dataone.service.types.NodeType;
80 80
import org.dataone.service.types.ObjectFormat;
81
import org.dataone.service.types.ObjectFormatIdentifier;
82
import org.dataone.service.types.ObjectFormatList;
81 83
import org.dataone.service.types.ObjectList;
82 84
import org.dataone.service.types.Service;
83 85
import org.dataone.service.types.ServiceMethod;
......
404 406
                    
405 407
                } else if (resource.equals(RESOURCE_FORMATS)) {
406 408
                  System.out.println("Using resource 'formats'");
409
                  
410
                  // check for a format identifier
411
                  String fmtid = request.getPathInfo();
412
                  
413
                  if ( fmtid != null && fmtid.length() > 1 ) {
414
                  	fmtid = request.getPathInfo().substring(1);
415
                  	
416
                  } else {
417
                  	fmtid = null;
418
                  	
419
                  }
420
                  
421
                  // handle each verb
422
                  if ( httpVerb == GET ) {
423
                  	if ( fmtid == null ) {
424
                      // list the formats collection
425
                  		listFormats();
426
                  		
427
                  	} else {
428
                  		// get the specified format
429
                  		getFormat(fmtid);
407 430

  
431
                  	}
432
                  	status = true;
433
                  
434
                  } else if ( httpVerb == PUT ) {
435
                  	status = true;
436
                  	
437
                  } else if ( httpVerb == POST ) {
438
                  	status = true;
439
                  	
440
                  } else if ( httpVerb == DELETE ) {
441
                  	status = true;
442
                  	
443
                  } else if ( httpVerb == HEAD ) {
444
                  	status = true;
445
                  	
446
                  }
447
                  
408 448
                } else if (resource.equals(RESOURCE_IDENTIFIER)) {
409 449
                    System.out.println("Using resource 'identifier'");
410 450
                    String identifierId = request.getPathInfo();
......
554 594
                            if(params.containsKey("format"))
555 595
                            {
556 596
                                String format = params.get("format")[0];
557
                                of = ObjectFormatCache.getFormat(format);
597
                                of = ObjectFormatCache.getInstance().getFormat(format);
558 598
                            }
559 599
                            if(params.containsKey("time"))
560 600
                            {
......
591 631
                            if(params.containsKey("format"))
592 632
                            {
593 633
                                String format = params.get("format")[0];
594
                                of = ObjectFormatCache.getFormat(format);
634
                                of = ObjectFormatCache.getInstance().getFormat(format);
595 635
                            }
596 636
                            if(params.containsKey("eventtime"))
597 637
                            {
......
633 673
        }
634 674
    }
635 675
    
636
    /**
676
		/**
637 677
     * handle the /replicate action
638 678
     * @param httpVerb
639 679
     * @param request
......
723 763
            AuthToken token = new AuthToken(sessionId);
724 764
            MNode mnode = new MNode(nodeUrl);
725 765
            //get the doc from the remote host
726
            InputStream docStream = mnode.get(new AuthToken("public"), sm.getIdentifier());
766
            InputStream docStream = mnode.get(new Session(), sm.getIdentifier());
727 767
            File outputTmpFile = getTempFile();
728 768
            System.out.println("wrote xml file to " + outputTmpFile.getAbsolutePath());
729 769
            FileOutputStream outputTmpFileStream = new FileOutputStream(outputTmpFile);
......
1181 1221
                    
1182 1222
                    //set the content type
1183 1223
                    if(sm.getObjectFormat().getFmtid().getValue().trim().equals(
1184
                    		ObjectFormatCache.getFormat("text/csv").getFmtid().getValue()))
1224
                    		ObjectFormatCache.getInstance().getFormat("text/csv").getFmtid().getValue()))
1185 1225
                    {
1186 1226
                        response.setContentType("text/csv");
1187 1227
                        response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".csv");
1188 1228
                    }
1189 1229
                    else if(sm.getObjectFormat().getFmtid().getValue().trim().equals(
1190
                    		ObjectFormatCache.getFormat("text/plain").getFmtid().getValue()))
1230
                    		ObjectFormatCache.getInstance().getFormat("text/plain").getFmtid().getValue()))
1191 1231
                    {
1192 1232
                        response.setContentType("text/plain");
1193 1233
                        response.setHeader("Content-Disposition", "inline; filename=" + id.getValue() + ".txt");
1194 1234
                    } 
1195 1235
                    else if(sm.getObjectFormat().getFmtid().getValue().trim().equals(
1196
                    		ObjectFormatCache.getFormat("application/octet-stream").getFmtid().getValue()))
1236
                    		ObjectFormatCache.getInstance().getFormat("application/octet-stream").getFmtid().getValue()))
1197 1237
                    {
1198 1238
                        response.setContentType("application/octet-stream");
1199 1239
                    }
......
1290 1330
                    }
1291 1331
                    else if(name.equals("objectFormat") && value != null) 
1292 1332
                    {
1293
                        objectFormat = ObjectFormatCache.getFormat(value[0]);
1333
                        objectFormat = ObjectFormatCache.getInstance().getFormat(value[0]);
1294 1334
                    }
1295 1335
                    else if(name.equals("replicaStatus") && value != null)
1296 1336
                    {
......
2017 2057
    }
2018 2058

  
2019 2059
    /**
2060
     * List the object formats registered with the system
2061
     */
2062
		private void listFormats() {
2063
      logMetacat.debug("Entering listFormats()");
2064
      // get the response output stream
2065
      OutputStream out = null;
2066
      
2067
      try {
2068
	      out = response.getOutputStream();
2069
	      response.setStatus(200);
2070
	      response.setContentType("text/xml");
2071
	      
2072
      } catch (IOException ioe) {
2073
      	logMetacat.error("Could not get the output stream for writing" +
2074
      	  "in ResourceHandler.listFormats()");
2075
      
2076
      }
2077

  
2078
      // get the object format list
2079
      try {
2080
	      ObjectFormatList objectFormatList = CNCoreImpl.getInstance().listFormats();
2081
	      serializeServiceType(ObjectFormatList.class, objectFormatList, out);
2082
      
2083
      } catch (InvalidRequest e) {
2084
      	response.setStatus(200);
2085
      	serializeException(e, out);
2086
      	
2087
      } catch (ServiceFailure e) {
2088
      	response.setStatus(501);
2089
      	serializeException(e, out);
2090
      
2091
      } catch (NotFound e) {
2092
      	response.setStatus(200);
2093
      	serializeException(e, out);
2094
      
2095
      } catch (InsufficientResources e) {
2096
      	response.setStatus(200);
2097
      	serializeException(e, out);
2098
      
2099
      } catch (NotImplemented e) {
2100
      	response.setStatus(200);
2101
      	serializeException(e, out);
2102
      
2103
      } catch (JiBXException jibxe) {
2104
      	response.setStatus(501);
2105
      	ServiceFailure e = 
2106
      		new ServiceFailure("4841", "Unexpected exception from the service - " + 
2107
        	                   jibxe.getClass() + ": " + jibxe.getMessage());
2108
      	serializeException(e, out);
2109
      	
2110
      }
2111
      
2112
    }
2113

  
2114
		/**
2115
     * Return the requested object format
2116
     * 
2117
     * @param fmtidStr the requested format identifier as a string
2118
     */
2119
    private void getFormat(String fmtidStr) {
2120
      logMetacat.debug("Entering listFormats()");
2121
      
2122
      // get the response output stream
2123
      OutputStream out = null;
2124
      try {
2125
	      out = response.getOutputStream();
2126
	      response.setStatus(200);
2127
	      response.setContentType("text/xml");
2128
	      
2129
      } catch (IOException ioe) {
2130
      	logMetacat.error("Could not get the output stream for writing" +
2131
      	  "in ResourceHandler.listFormats()");
2132
      
2133
      }
2134
      
2135
      ObjectFormatIdentifier fmtid = new ObjectFormatIdentifier();
2136
      fmtid.setValue(fmtidStr);
2137
      
2138
      try {
2139
      	// get the specified object format
2140
	      ObjectFormat objectFormat = CNCoreImpl.getInstance().getFormat(fmtid);
2141
	      serializeServiceType(ObjectFormat.class, objectFormat, out);
2142

  
2143
      } catch (InvalidRequest e) {
2144
      	response.setStatus(200);
2145
      	serializeException(e, out);
2146
      
2147
      } catch (ServiceFailure e) {
2148
      	response.setStatus(501);
2149
      	serializeException(e, out);
2150
      
2151
      } catch (NotFound e) {
2152
      	response.setStatus(200);
2153
      	serializeException(e, out);
2154
      
2155
      } catch (InsufficientResources e) {
2156
      	response.setStatus(200);
2157
      	serializeException(e, out);
2158
      
2159
      } catch (NotImplemented e) {
2160
      	response.setStatus(200);
2161
      	serializeException(e, out);
2162
      
2163
      } catch (JiBXException jibxe) {
2164
      	ServiceFailure e = 
2165
      		new ServiceFailure("4841", "Unexpected exception from the service - " + 
2166
        	                   jibxe.getClass() + ": " + jibxe.getMessage());
2167
      	serializeException(e, out);
2168

  
2169
      }
2170
	    
2171
    }
2172

  
2173
    /**
2020 2174
     * Register System Metadata without data or metadata object
2021 2175
     * @param pid identifier for System Metadata entry
2022 2176
     */
......
2131 2285
			guid.setValue(pid);
2132 2286
			logMetacat.debug("registering system metadata with pid "
2133 2287
					+ guid.getValue());
2134
			boolean result = CNCoreImpl.getInstance().registerSystemMetaData(
2288
			boolean result = CNCoreImpl.getInstance().registerSystemMetadata(
2135 2289
					session, guid, systemMetadata);
2136 2290
			serializeServiceType(Boolean.class, result, out);
2137 2291

  
......
2156 2310
			InvalidSystemMetadata ism = new InvalidSystemMetadata("1080", e
2157 2311
					.getMessage());
2158 2312
			serializeException(ism, out);
2159
		}
2313
		} catch (InvalidSystemMetadata e) {
2314
			serializeException(e, out);
2315
    }
2160 2316
	}
2161 2317

  
2162 2318
}

Also available in: Unified diff