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