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
24
25 public class ItemSearchFieldKeyValuefinder 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.ITEM.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
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.ITEM.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(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 }