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