View Javadoc

1   package org.kuali.ole.serviceimpl;
2   
3   import org.kuali.ole.OleSRUConstants;
4   import org.kuali.ole.service.OleValidateInputRequestService;
5   
6   import java.util.Map;
7   
8   /**
9    * Created with IntelliJ IDEA.
10   * User: ?
11   * Date: 7/9/12
12   * Time: 7:57 PM
13   * To change this template use File | Settings | File Templates.
14   */
15  public class OleValidateInputRequestServiceImpl implements OleValidateInputRequestService {
16  
17      /**
18       * to validate whether the required parameters of corresponding operation is present or not.
19       *
20       * @param reqParamMap
21       * @return boolean
22       */
23      public String inputRequestValidation(Map reqParamMap) {
24  
25          String operationType = (String) reqParamMap.get(OleSRUConstants.OPERATION_TYPE);
26          String version = (String) reqParamMap.get(OleSRUConstants.VERSION);
27          String query = (String) reqParamMap.get(OleSRUConstants.QUERY);
28          String recordPacking = (String) reqParamMap.get(OleSRUConstants.RECORD_PACKING);
29          String recordSchema = (String) reqParamMap.get(OleSRUConstants.RECORD_SCHEMA);
30  
31          if (operationType == null || "".equals(operationType))
32              return OleSRUConstants.OPERATION_REQUIRED_FIELD_DIAGNOSTIC_MSG;
33  
34          if (OleSRUConstants.SEARCH_RETRIEVE.equalsIgnoreCase(operationType)) {
35              if (version == null || "".equals(version))
36                  return OleSRUConstants.VERSION_REQUIRED_FIELD_DIAGNOSTIC_MSG;
37              else if (query == null || "".equals(query))
38                  return OleSRUConstants.QUERY_REQUIRED_FIELD_DIAGNOSTIC_MSG;
39  
40          } else if (OleSRUConstants.EXPLAIN.equalsIgnoreCase(operationType)) {
41              if (version == null || "".equals(version))
42                  return OleSRUConstants.VERSION_REQUIRED_FIELD_DIAGNOSTIC_MSG;
43  
44          } else
45              return OleSRUConstants.INVALID_OPERATION_TYPE;
46  
47          if (!(OleSRUConstants.RECORD_PACK_XML.equalsIgnoreCase(recordPacking) || OleSRUConstants.RECORD_PACK_STRING.equalsIgnoreCase(recordPacking)))
48              return OleSRUConstants.INVALID_RECORD_PACKING;
49  
50          if (recordSchema != null && OleSRUConstants.SEARCH_RETRIEVE.equalsIgnoreCase(operationType)) {
51              if (!(OleSRUConstants.DC_RECORD_SCHEMA.equalsIgnoreCase(recordSchema)) && !(OleSRUConstants.MARC_RECORD_SCHEMA.equalsIgnoreCase(recordSchema)) && !(OleSRUConstants.OPAC_RECORD.equalsIgnoreCase(recordSchema))) {
52                  return OleSRUConstants.INVALID_RECORD_SCHEMA;
53              }
54          }
55          if (recordSchema.equals(OleSRUConstants.MARC_RECORD_SCHEMA)) {
56              reqParamMap.put(OleSRUConstants.RECORD_SCHEMA, OleSRUConstants.MARC);
57          }
58          if (recordSchema.equals(OleSRUConstants.DC_RECORD_SCHEMA)) {
59              reqParamMap.put(OleSRUConstants.RECORD_SCHEMA, OleSRUConstants.DUBLIN_RECORD_SCHEMA);
60          }
61          return null;
62      }
63  }