1 package org.kuali.ole.describe.keyvalue;
2
3 import org.apache.commons.lang3.StringUtils;
4 import org.kuali.ole.describe.form.BoundwithForm;
5 import org.kuali.ole.describe.form.GlobalEditForm;
6 import org.kuali.ole.describe.form.ImportBibForm;
7 import org.kuali.ole.describe.form.WorkbenchForm;
8 import org.kuali.ole.docstore.common.search.SearchParams;
9 import org.kuali.ole.docstore.model.enums.DocCategory;
10 import org.kuali.ole.docstore.model.enums.DocFormat;
11 import org.kuali.ole.docstore.model.enums.DocType;
12 import org.kuali.ole.docstore.model.xmlpojo.config.*;
13 import org.kuali.ole.describe.service.DocstoreHelperService;
14 import org.kuali.rice.core.api.util.ConcreteKeyValue;
15 import org.kuali.rice.core.api.util.KeyValue;
16 import org.kuali.rice.krad.uif.control.UifKeyValuesFinderBase;
17 import org.kuali.rice.krad.uif.view.ViewModel;
18 import org.slf4j.Logger;
19 import org.slf4j.LoggerFactory;
20
21 import java.util.ArrayList;
22 import java.util.List;
23
24
25
26
27
28
29
30
31 public class DocFieldKeyValueFinder
32 extends UifKeyValuesFinderBase {
33
34 public static final Logger LOG = LoggerFactory.getLogger(DocFieldKeyValueFinder.class);
35
36 @Override
37 public List<KeyValue> getKeyValues(ViewModel viewModel) {
38 List<KeyValue> options = new ArrayList<KeyValue>();
39 SearchParams searchParams = null;
40 if (viewModel instanceof WorkbenchForm) {
41 WorkbenchForm workbenchForm = (WorkbenchForm) viewModel;
42 searchParams = workbenchForm.getSearchParams();
43 getOptions(workbenchForm.getDocType(), options);
44 } else if (viewModel instanceof BoundwithForm) {
45 BoundwithForm boundwithForm = (BoundwithForm) viewModel;
46 searchParams = boundwithForm.getSearchParams();
47 getOptions(boundwithForm.getDocType(), options);
48 } else if (viewModel instanceof ImportBibForm) {
49 ImportBibForm importBibForm = (ImportBibForm) viewModel;
50 getOptionsImportBib(importBibForm, options);
51 } else if (viewModel instanceof GlobalEditForm) {
52 GlobalEditForm globalEditForm = (GlobalEditForm) viewModel;
53
54
55
56
57
58 getOptions(globalEditForm.getDocType(), options);
59 }
60 return options;
61 }
62
63 private void getOptionsImportBib(ImportBibForm importBibForm, List<KeyValue> options) {
64
65 options.add(new ConcreteKeyValue("Title", "Title"));
66 options.add(new ConcreteKeyValue("OCLCControlNumber", "OCLC Control Number"));
67 options.add(new ConcreteKeyValue("Author", "Author"));
68 options.add(new ConcreteKeyValue("ISBN", "ISBN"));
69 options.add(new ConcreteKeyValue("ISSN", "ISSN"));
70 options.add(new ConcreteKeyValue("LCCN", "LCCN"));
71 }
72
73 private void getOptions(String docType, List<KeyValue> options) {
74 DocstoreHelperService docstoreHelperService = new DocstoreHelperService();
75 DocumentConfig documentConfig = docstoreHelperService.getDocumentConfigObj();
76 try {
77 for (DocumentCategory documentCategory : documentConfig.getDocumentCategories()) {
78 if (DocCategory.WORK.getDescription().equalsIgnoreCase(documentCategory.getName())) {
79 for (DocumentType documentType : documentCategory.getDocumentTypes()) {
80 if (StringUtils.isNotEmpty(docType) && docType.equalsIgnoreCase(documentType.getId())) {
81 if (DocType.BIB.getDescription().equalsIgnoreCase(documentType.getId())) {
82 addFieldsToOptions(documentType, options, "all");
83 } else {
84 addFieldsToOptions(documentType, options, DocFormat.OLEML.getDescription());
85 }
86 }
87 }
88 }
89 }
90 } catch (Exception e) {
91 LOG.error(e.getMessage(), e);
92 }
93 }
94
95 private void addFieldsToOptions(DocumentType documentType, List<KeyValue> options, String docFormat) {
96 options.add(new ConcreteKeyValue("all", "ALL"));
97 for (DocumentFormat documentFormat : documentType.getDocumentFormats()) {
98 if (docFormat.equalsIgnoreCase(documentFormat.getId())) {
99 for (Field field : documentFormat.getFields()) {
100 if ((field.getId()).endsWith("_search")) {
101 options.add(new ConcreteKeyValue(field.getId(), field.getName()));
102 }
103 }
104 }
105 }
106 }
107
108
109 }