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.constants.DocstoreConstants;
8 import org.kuali.ole.docstore.common.document.config.DocFieldConfig;
9 import org.kuali.ole.docstore.common.document.config.DocFormatConfig;
10 import org.kuali.ole.docstore.common.document.config.DocTypeConfig;
11 import org.kuali.ole.docstore.common.document.config.DocumentSearchConfig;
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.*;
19
20
21
22
23
24
25
26
27 public class SearchFieldKeyValuefinder extends UifKeyValuesFinderBase implements DocstoreConstants{
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 if(StringUtils .isEmpty(docType)){
41 docType = oleSearchForm.getDocType();
42 }
43
44 }
45 else if (viewModel instanceof GlobalEditForm) {
46 globalEditForm = (GlobalEditForm) viewModel;
47 if(StringUtils .isEmpty(docType)){
48 docType = globalEditForm.getDocType();
49 }
50 }
51 else if (viewModel instanceof BoundwithForm) {
52 boundwithForm = (BoundwithForm) viewModel;
53 if(StringUtils .isEmpty(docType)){
54 docType = boundwithForm.getDocType();
55 }
56
57 }
58 List<KeyValue> options = new ArrayList<KeyValue>();
59 Map<String, String> sortedMap = new TreeMap<>();
60 for (DocTypeConfig docTypeConfig : documentSearchConfig.getDocTypeConfigs()) {
61 if (docTypeConfig.getName().equals(docType)) {
62 for (DocFormatConfig docFormatConfig : docTypeConfig.getDocFormatConfigList()) {
63 if (docFormatConfig.getName().equals("marc") && DocType.BIB.getCode().equals(docType)){
64 for (DocFieldConfig docFieldConfig : docFormatConfig.getDocFieldConfigList()) {
65 if((oleSearchForm != null && docType.equalsIgnoreCase(docFieldConfig.getDocType().getName())) ||
66 (globalEditForm != null && globalEditForm.getDocType().equalsIgnoreCase(docFieldConfig.getDocType().getName())) ||
67 (boundwithForm != null && boundwithForm.getDocType().equalsIgnoreCase(docFieldConfig.getDocType().getName()))){
68 if(docFieldConfig.isSearchable()){
69 if (docFieldConfig.getName().endsWith("_search")) {
70 sortedMap.put(docFieldConfig.getLabel(), docFieldConfig.getName());
71 } else if (docFieldConfig.getName().equalsIgnoreCase("mdf_035a")) {
72 sortedMap.put(docFieldConfig.getLabel(), docFieldConfig.getName());
73 }
74 }
75 }
76
77 }
78 } else if (docFormatConfig.getName().equals("oleml") && !DocType.BIB.getCode().equals(docType)) {
79 for (DocFieldConfig docFieldConfig : docFormatConfig.getDocFieldConfigList()) {
80 if((oleSearchForm != null && docType.equalsIgnoreCase(docFieldConfig.getDocType().getName())) ||
81 (globalEditForm != null && globalEditForm.getDocType().equalsIgnoreCase(docFieldConfig.getDocType().getName())) ||
82 (boundwithForm!=null && boundwithForm.getDocType().equalsIgnoreCase(docFieldConfig.getDocType().getName()))){
83 if(docFieldConfig.isSearchable()){
84 if(docFieldConfig.getName().endsWith("_search")){
85 sortedMap.put(docFieldConfig.getLabel(), docFieldConfig.getName());
86 }if(docFieldConfig.getName().equalsIgnoreCase(BIB_IDENTIFIER)){
87 sortedMap.put(docFieldConfig.getLabel(), docFieldConfig.getName());
88 }
89 }
90 }
91 }
92 }
93 }
94 }
95 }
96
97 for (String searchField : sortedMap.keySet()) {
98 options.add(new ConcreteKeyValue(sortedMap.get(searchField), searchField));
99 }
100 options.add(0,new ConcreteKeyValue("any","ANY"));
101 return options;
102 }
103 }