1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krms.impl.ui;
17
18 import org.apache.commons.collections.CollectionUtils;
19 import org.kuali.rice.core.api.uif.DataType;
20 import org.kuali.rice.core.api.uif.RemotableAttributeField;
21 import org.kuali.rice.core.api.uif.RemotableTextInput;
22 import org.kuali.rice.krad.document.MaintenanceDocument;
23 import org.kuali.rice.krad.maintenance.MaintainableImpl;
24 import org.kuali.rice.krad.service.BusinessObjectService;
25 import org.kuali.rice.krad.service.KRADServiceLocator;
26 import org.kuali.rice.krad.uif.container.CollectionGroup;
27 import org.kuali.rice.krad.uif.container.Container;
28 import org.kuali.rice.krad.uif.view.View;
29 import org.kuali.rice.krad.web.form.MaintenanceForm;
30 import org.kuali.rice.krms.impl.repository.ActionBo;
31 import org.kuali.rice.krms.impl.repository.CategoryBo;
32 import org.kuali.rice.krms.impl.repository.TermBo;
33 import org.kuali.rice.krms.impl.repository.TermResolverBo;
34 import org.kuali.rice.krms.impl.repository.TermResolverParameterSpecificationBo;
35
36 import java.util.ArrayList;
37 import java.util.Collection;
38 import java.util.Collections;
39 import java.util.Comparator;
40 import java.util.List;
41 import java.util.Map;
42
43
44
45
46
47
48
49 public class TermMaintainable extends MaintainableImpl {
50
51 private static final long serialVersionUID = 1L;
52
53 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(TermMaintainable.class);
54
55
56
57
58 public BusinessObjectService getBoService() {
59 return KRADServiceLocator.getBusinessObjectService();
60 }
61
62
63
64 public List<RemotableAttributeField> retrieveCustomAttributes(View view, Object model, Container container) {
65
66 List<RemotableAttributeField> results = new ArrayList<RemotableAttributeField>();
67
68 String termSpecId = ((TermBo)((MaintenanceForm)model).getDocument().getNewMaintainableObject().getDataObject()).getSpecificationId();
69
70 Collection<TermResolverBo> termResolvers = getBoService().findMatching(TermResolverBo.class,
71 Collections.singletonMap("outputId", termSpecId)
72 );
73
74 TermResolverBo termResolver = null;
75
76 if (termResolvers != null && termResolvers.size() == 1) {
77 termResolver = termResolvers.iterator().next();
78 }
79
80 if (termResolver != null && !CollectionUtils.isEmpty(termResolver.getParameterSpecifications())) {
81 List<TermResolverParameterSpecificationBo> params = new ArrayList<TermResolverParameterSpecificationBo>(termResolver.getParameterSpecifications());
82
83 Collections.sort(params, new Comparator<TermResolverParameterSpecificationBo>() {
84 @Override
85 public int compare(TermResolverParameterSpecificationBo o1, TermResolverParameterSpecificationBo o2) {
86 return o1.getName().compareTo(o2.getName());
87 }
88 });
89
90 for (TermResolverParameterSpecificationBo param : params) {
91 RemotableAttributeField.Builder builder = RemotableAttributeField.Builder.create(param.getName());
92 RemotableTextInput.Builder inputBuilder = RemotableTextInput.Builder.create();
93 inputBuilder.setSize(80);
94 builder.setControl(inputBuilder);
95 builder.setDataType(DataType.STRING);
96 builder.setLongLabel(param.getName());
97 builder.setShortLabel(param.getName());
98
99 results.add(builder.build());
100 }
101 }
102
103 return results;
104 }
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130 @Override
131 public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) {
132
133 TermBo termBo = (TermBo)document.getNewMaintainableObject().getDataObject();
134 termBo.exportToParametersMap();
135
136 return super.retrieveObjectForEditOrCopy(document,
137 dataObjectKeys);
138 }
139
140
141
142
143 @Override
144 public void processAfterNew(MaintenanceDocument document,
145 Map<String, String[]> requestParameters) {
146
147 super.processAfterNew(document, requestParameters);
148 document.getDocumentHeader().setDocumentDescription("New Term Document");
149
150 }
151
152 @Override
153 public void saveDataObject() {
154 TermBo term = (TermBo) getDataObject();
155 term.importFromParametersMap();
156
157 super.saveDataObject();
158 }
159
160 @Override
161 public Class getDataObjectClass() {
162 return TermBo.class;
163 }
164
165 @Override
166 protected void processBeforeAddLine(View view, CollectionGroup collectionGroup, Object model, Object addLine) {
167 super.processBeforeAddLine(view, collectionGroup, model, addLine);
168 }
169
170
171 }