Changeset 3976
- Timestamp:
- 03/06/08 14:00:00 (13 years ago)
- Location:
- TI01-discovery/branches/ws-Discovery2-upgrade/src/ndg/services/discovery
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
TI01-discovery/branches/ws-Discovery2-upgrade/src/ndg/services/discovery/DiscoveryServiceSkeleton.java
r3965 r3976 16 16 * @author Matt Pritchard 17 17 */ 18 public class DiscoveryServiceSkeleton {19 18 public class DiscoveryServiceSkeleton 19 { 20 20 // Obtain a suitable logger. 21 21 private static Logger logger = Logger.getLogger(DiscoveryServiceSkeleton.class.getName()); … … 33 33 34 34 public static final String DELIMITER = "-------------------------------------"; 35 36 public static final String ORIGINAL_FORMAT = "original"; 37 public static final String DC_FORMAT = "DC"; 38 public static final String DIF_FORMAT = "DIF"; 39 public static final String MDIP_FORMAT = "MDIP"; 40 public static final String ISO19115_FORMAT = "ISO19115"; 41 42 // to_tsvector ignores the '_' character; as a work around replace this with the following string 43 // - primarily for use in the scope field 44 public static final String UNDERSCORE_REPLACEMENT = "UNDERSCORE"; 45 46 public static final String INVALID_LIST_NAME_MESSAGE = 47 "Invalid list name: please use getListNames to get the valid list names"; 48 49 /** 50 * Helper method for checking validity of a format 51 * @param format 52 * @return true if format if valid, false otherwise 53 */ 54 public static boolean isValidFormat(String format) 55 { 56 String[] allFormats = {ORIGINAL_FORMAT, DC_FORMAT, DIF_FORMAT, MDIP_FORMAT, ISO19115_FORMAT}; 57 for (int i = 0; i < allFormats.length; i++) 58 { 59 if (allFormats[i].equals(format)) 60 return true; 61 } 62 return false; 63 } 35 64 /** 36 65 * Performs the doFullTextSearch operation … … 65 94 catch (Exception e) 66 95 { 67 String errorMessage = "Unable to retrieve result - reason : " + e. toString();96 String errorMessage = "Unable to retrieve result - reason : " + e.getMessage(); 68 97 logger.severe(errorMessage); 69 98 responseContent.setStatus( false ); 70 99 responseContent.setStatusMessage(errorMessage); 100 return response; 71 101 } 72 102 … … 203 233 } 204 234 205 if ( requestContent.isSetDateRange() ) 235 // Generated code is a little ropey atm; if a start date is not defined, this date range is automatically 236 // not set - however if it is it will be - i.e. the end date is not consulted when setting up this object 237 // - this makes it currently impossible to recognise the case where a start date is null and the end date 238 // is set 239 // - NB, would be better to tighten up WSDL definition so that you can/cannot set things up wrongly 240 if (requestContent.isSetDateRange()) 206 241 { 207 242 logger.info("Adding temporal range"); 208 agent.setDateRangeStart( requestContent.getDateRange().getDateRangeStart() ); 209 agent.setDateRangeEnd( requestContent.getDateRange().getDateRangeEnd() ); 210 } 243 // NB, need to check that both end and start dates are set; if these are accessed via the daterange object 244 // and are nulls, an exception is thrown 245 try 246 { 247 agent.setDateRangeStart( requestContent.getDateRange().getDateRangeStart() ); 248 agent.setDateRangeEnd( requestContent.getDateRange().getDateRangeEnd() ); 249 } 250 catch (Exception e) 251 { 252 String errorMessage = "Invalid time range specified - detail: " + e.getMessage(); 253 logger.warning(errorMessage); 254 throw new DiscoveryWSException(errorMessage); 255 } 256 } 257 211 258 logger.info("Search agent ready for searching"); 212 259 return agent; … … 218 265 * @param discoveryserviceapi.DoPresentDocument containing search request 219 266 * @return discoveryserviceapi.DoPresentReturnDocument containing search result 267 * @throws DiscoveryWSException 220 268 */ 221 269 public discoveryserviceapi.DoPresentReturnDocument doPresent 222 (discoveryserviceapi.DoPresentDocument request ) 270 (discoveryserviceapi.DoPresentDocument request ) throws DiscoveryWSException 223 271 { 224 logger.info("doPresent() invoked"); 225 discoveryserviceapi.DoPresentReturnDocument response = discoveryserviceapi.DoPresentReturnDocument.Factory.newInstance(); 272 logger.info(DELIMITER); 273 logger.info("doPresent() invoked"); 274 logger.info(DELIMITER); 275 276 discoveryserviceapi.DoPresentReturnDocument response = 277 discoveryserviceapi.DoPresentReturnDocument.Factory.newInstance(); 226 278 discoveryserviceapi.PresentReturnType responseContent = response.addNewDoPresentReturn(); 227 279 … … 239 291 discoveryserviceapi.DocumentsType documents = requestContent.getDocuments(); 240 292 String[] documentsString = documents.getDocumentArray(); 241 System.out.println("Building list of " + documentsString.length + " documents for present");242 Vector documentsVector = new Vector();293 logger.info("Building list of " + documentsString.length + " documents for present"); 294 Vector<String> documentsVector = new Vector<String>(); 243 295 for (int i=0; i<documentsString.length; i++ ) 244 296 { 245 documentsVector.add( documentsString[i]);297 documentsVector.add(documentsString[i]); 246 298 } 247 299 agent.setDocumentNames( documentsVector ); … … 249 301 try 250 302 { 303 logger.info("Running doPresent() to retrieve documents"); 251 304 PresentSummary summary = agent.doPresent(); 252 305 responseContent.setStatus( summary.getStatus() ); 253 306 responseContent.setStatusMessage( summary.getStatusMessage() ); 254 if ( summary.getStatus() ) 255 { 307 // NB, if no results are returned, the status is false 308 if (summary.getStatus()) 309 { 310 logger.info("doPresent completed successfully - preparing results for return"); 256 311 Vector resultDocuments = summary.getDocuments(); 257 312 Iterator it = resultDocuments.iterator(); … … 261 316 returnDocuments.addDocument( (String)it.next() ); 262 317 } 263 264 318 } 265 319 } … … 268 322 responseContent.setStatusMessage("Error creating doPresentReturnDocument : " + e.toString() ); 269 323 } 270 logger.info("doPresent() completed successfully");324 logger.info("doPresent() completed - returning response"); 271 325 272 326 return response; … … 298 352 * @param discoveryserviceapi.GetListDocument containing request 299 353 * @return discoveryserviceapi.GetListReturnDocument containing result 354 * @throws DiscoveryWSException 300 355 */ 301 356 public discoveryserviceapi.GetListReturnDocument getList 302 (discoveryserviceapi.GetListDocument request ) 357 (discoveryserviceapi.GetListDocument request ) throws DiscoveryWSException 303 358 { 304 359 logger.info("getList() invoked"); … … 314 369 if ( listName.equals("presentFormatList") ) 315 370 { 316 list.addListMember( "original");317 list.addListMember( "DC");318 list.addListMember( "DIF");319 list.addListMember( "MDIP");320 list.addListMember( "ISO19115");371 list.addListMember(ORIGINAL_FORMAT); 372 list.addListMember(DC_FORMAT); 373 list.addListMember(DIF_FORMAT); 374 list.addListMember(MDIP_FORMAT); 375 list.addListMember(ISO19115_FORMAT); 321 376 //list.addListMember("moles"); 322 377 } … … 347 402 else 348 403 { 349 String errorMessage = "Invalid list name: please use getListNames to get the valid list names"; 350 logger.warning(errorMessage); 351 throw new UnsupportedOperationException(errorMessage); 404 logger.warning(INVALID_LIST_NAME_MESSAGE); 405 throw new DiscoveryWSException(INVALID_LIST_NAME_MESSAGE); 352 406 } 353 407 -
TI01-discovery/branches/ws-Discovery2-upgrade/src/ndg/services/discovery/PostgresDBClient.java
r3957 r3976 159 159 private void handleSQLException(SQLException e) throws DiscoveryDBException 160 160 { 161 String errorMessage = 162 "SQLException thrown whilst interacting with postgres DB - detail: " + 163 e.getLocalizedMessage(); 164 logger.severe(errorMessage); 165 throw new DiscoveryDBException(errorMessage); 161 throw new DiscoveryDBException("SQLException thrown whilst interacting with postgres DB - detail: " + 162 e.getLocalizedMessage()); 166 163 } 167 164
Note: See TracChangeset
for help on using the changeset viewer.