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
25
26 public class HoldingsSearchFieldKeyValuefinder 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.HOLDINGS.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
47 List<KeyValue> options = new ArrayList<KeyValue>();
48 Map<String, String> sortedMap = new TreeMap<>();
49 for (DocTypeConfig docTypeConfig : documentSearchConfig.getDocTypeConfigs()) {
50 if (docTypeConfig.getName().equals(docType)) {
51 for (DocFormatConfig docFormatConfig : docTypeConfig.getDocFormatConfigList()) {
52 if (docFormatConfig.getName().equals("oleml") && DocType.HOLDINGS.getCode().equals(docType)) {
53 for (DocFieldConfig docFieldConfig : docFormatConfig.getDocFieldConfigList()) {
54 if((oleSearchForm != null && docType.equalsIgnoreCase(docFieldConfig.getDocType().getName())) ||
55 (globalEditForm != null && globalEditForm.getDocType().equalsIgnoreCase(docFieldConfig.getDocType().getName())) ||
56 (boundwithForm!=null && boundwithForm.getDocType().equalsIgnoreCase(docFieldConfig.getDocType().getName()))){
57 if(docFieldConfig.isSearchable()){
58 if(docFieldConfig.getName().endsWith("_search")){
59 sortedMap.put(docFieldConfig.getLabel(), docFieldConfig.getName());
60 }if(docFieldConfig.getName().equalsIgnoreCase(ItemConstants.BIB_IDENTIFIER)){
61 sortedMap.put(docFieldConfig.getLabel(), docFieldConfig.getName());
62 }
63 }
64 }
65 }
66 }
67 }
68 }
69 }
70
71 for (String searchField : sortedMap.keySet()) {
72 options.add(new ConcreteKeyValue(sortedMap.get(searchField), searchField));
73 }
74 options.add(0,new ConcreteKeyValue("any","ANY"));
75 return options;
76 }
77 }