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.document.config.DocFieldConfig;
7   import org.kuali.ole.docstore.common.document.config.DocFormatConfig;
8   import org.kuali.ole.docstore.common.document.config.DocTypeConfig;
9   import org.kuali.ole.docstore.common.document.config.DocumentSearchConfig;
10  import org.kuali.ole.docstore.engine.service.index.solr.ItemConstants;
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.service.KRADServiceLocator;
15  import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
16  import org.kuali.rice.krad.uif.view.ViewModel;
17  
18  import java.util.*;
19  
20  /**
21   * Created with IntelliJ IDEA.
22   * User: srirams
23   * Date: 3/12/14
24   * Time: 6:02 PM
25   * To change this template use File | Settings | File Templates.
26   */
27  public class SearchFieldKeyValuefinder extends UifKeyValuesFinderBase {
28  
29      DocumentSearchConfig documentSearchConfig = DocumentSearchConfig.getDocumentSearchConfig();
30  
31      @Override
32      public List<KeyValue> getKeyValues(ViewModel viewModel) {
33          setAddBlankOption(false);
34          OLESearchForm oleSearchForm = null;
35          GlobalEditForm globalEditForm = null;
36          BoundwithForm boundwithForm = null;
37          String docType = null;
38          if (viewModel instanceof OLESearchForm) {
39              oleSearchForm = (OLESearchForm)  viewModel;
40              docType = oleSearchForm.getDocType();
41          }
42          else if (viewModel instanceof GlobalEditForm) {
43              globalEditForm = (GlobalEditForm) viewModel;
44              docType = globalEditForm.getDocType();
45          }
46          else if (viewModel instanceof BoundwithForm) {
47              boundwithForm = (BoundwithForm) viewModel;
48              docType = boundwithForm.getDocType();
49          }
50          List<KeyValue> options = new ArrayList<KeyValue>();
51          Map<String, String> sortedMap = new TreeMap<>();
52          for (DocTypeConfig docTypeConfig : documentSearchConfig.getDocTypeConfigs()) {
53              if (docTypeConfig.getName().equals(docType)) {
54                  for (DocFormatConfig docFormatConfig : docTypeConfig.getDocFormatConfigList()) {
55                      if (docFormatConfig.getName().equals("marc") && DocType.BIB.getCode().equals(docType)){
56                          for (DocFieldConfig docFieldConfig : docFormatConfig.getDocFieldConfigList()) {
57                              if((oleSearchForm != null && docType.equalsIgnoreCase(docFieldConfig.getDocType().getName())) ||
58                                      (globalEditForm != null && globalEditForm.getDocType().equalsIgnoreCase(docFieldConfig.getDocType().getName())) ||
59                                      (boundwithForm != null && boundwithForm.getDocType().equalsIgnoreCase(docFieldConfig.getDocType().getName()))){
60                                  if(docFieldConfig.isSearchable()){
61                                      if (docFieldConfig.getName().endsWith("_search")) {
62                                          sortedMap.put(docFieldConfig.getLabel(), docFieldConfig.getName());
63                                      } else if (docFieldConfig.getName().equalsIgnoreCase("mdf_035a")) {
64                                          sortedMap.put(docFieldConfig.getLabel(), docFieldConfig.getName());
65                                      }
66                                  }
67                              }
68  
69                          }
70                      } else if (docFormatConfig.getName().equals("oleml") && !DocType.BIB.getCode().equals(docType)) {
71                          for (DocFieldConfig docFieldConfig : docFormatConfig.getDocFieldConfigList()) {
72                              if((oleSearchForm != null && docType.equalsIgnoreCase(docFieldConfig.getDocType().getName())) ||
73                                      (globalEditForm != null && globalEditForm.getDocType().equalsIgnoreCase(docFieldConfig.getDocType().getName())) ||
74                                      (boundwithForm!=null && boundwithForm.getDocType().equalsIgnoreCase(docFieldConfig.getDocType().getName()))){
75                                          if(docFieldConfig.isSearchable()){
76                                              if(docFieldConfig.getName().endsWith("_search")){
77                                                  sortedMap.put(docFieldConfig.getLabel(), docFieldConfig.getName());
78                                              }if(docFieldConfig.getName().equalsIgnoreCase(ItemConstants.BIB_IDENTIFIER)){
79                                                  sortedMap.put(docFieldConfig.getLabel(), docFieldConfig.getName());
80                                              }
81                                          }
82                              }
83                          }
84                      }
85                  }
86              }
87          }
88  
89          for (String searchField : sortedMap.keySet()) {
90              options.add(new ConcreteKeyValue(sortedMap.get(searchField), searchField));
91          }
92          options.add(0,new ConcreteKeyValue("any","ANY"));
93          return options;
94      }
95  }