View Javadoc
1   package org.kuali.ole.describe.keyvalue;
2   
3   import org.kuali.ole.describe.form.BoundwithForm;
4   import org.kuali.ole.describe.form.GlobalEditForm;
5   import org.kuali.ole.describe.form.OLESearchForm;
6   import org.kuali.ole.docstore.common.constants.DocstoreConstants;
7   import org.kuali.ole.docstore.common.document.config.DocFieldConfig;
8   import org.kuali.ole.docstore.common.document.config.DocFormatConfig;
9   import org.kuali.ole.docstore.common.document.config.DocTypeConfig;
10  import org.kuali.ole.docstore.common.document.config.DocumentSearchConfig;
11  import org.kuali.ole.docstore.model.enums.DocType;
12  import org.kuali.rice.core.api.util.ConcreteKeyValue;
13  import org.kuali.rice.core.api.util.KeyValue;
14  import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
15  import org.kuali.rice.krad.uif.view.ViewModel;
16  
17  import java.util.ArrayList;
18  import java.util.List;
19  import java.util.Map;
20  import java.util.TreeMap;
21  
22  /**
23   * Created by jayabharathreddy on 2/16/15.
24   */
25  public class EHoldingsSearchFieldKeyValuefinder extends UifKeyValuesFinderBase implements DocstoreConstants{
26  
27      DocumentSearchConfig documentSearchConfig = DocumentSearchConfig.getDocumentSearchConfig();
28  
29      @Override
30      public List<KeyValue> getKeyValues(ViewModel viewModel) {
31          setAddBlankOption(false);
32          OLESearchForm oleSearchForm = null;
33          GlobalEditForm globalEditForm = null;
34          BoundwithForm boundwithForm = null;
35          String docType = DocType.EHOLDINGS.getCode();
36          if (viewModel instanceof OLESearchForm) {
37              oleSearchForm = (OLESearchForm)  viewModel;
38          }
39          else if (viewModel instanceof GlobalEditForm) {
40              globalEditForm = (GlobalEditForm) viewModel;
41          }
42          else if (viewModel instanceof BoundwithForm) {
43              boundwithForm = (BoundwithForm) viewModel;
44          }
45          List<KeyValue> options = new ArrayList<KeyValue>();
46          Map<String, String> sortedMap = new TreeMap<>();
47          for (DocTypeConfig docTypeConfig : documentSearchConfig.getDocTypeConfigs()) {
48              if (docTypeConfig.getName().equals(docType)) {
49                  for (DocFormatConfig docFormatConfig : docTypeConfig.getDocFormatConfigList()) {
50                      if (docFormatConfig.getName().equals("oleml") && DocType.EHOLDINGS.getCode().equals(docType)) {
51                          for (DocFieldConfig docFieldConfig : docFormatConfig.getDocFieldConfigList()) {
52                              if((oleSearchForm != null && docType.equalsIgnoreCase(docFieldConfig.getDocType().getName())) ||
53                                      (globalEditForm != null && globalEditForm.getDocType().equalsIgnoreCase(docFieldConfig.getDocType().getName())) ||
54                                      (boundwithForm!=null && boundwithForm.getDocType().equalsIgnoreCase(docFieldConfig.getDocType().getName()))){
55                                  if(docFieldConfig.isSearchable()){
56                                      if(docFieldConfig.getName().endsWith("_search")){
57                                          sortedMap.put(docFieldConfig.getLabel(), docFieldConfig.getName());
58                                      }if(docFieldConfig.getName().equalsIgnoreCase(BIB_IDENTIFIER)){
59                                          sortedMap.put(docFieldConfig.getLabel(), docFieldConfig.getName());
60                                      }
61                                  }
62                              }
63                          }
64                      }
65                  }
66              }
67          }
68  
69          for (String searchField : sortedMap.keySet()) {
70              options.add(new ConcreteKeyValue(sortedMap.get(searchField), searchField));
71          }
72          options.add(0,new ConcreteKeyValue("any","ANY"));
73          return options;
74      }
75  }