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.maintenance.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.util.KRADConstants;
30 import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
31 import org.kuali.rice.krms.impl.repository.TermBo;
32 import org.kuali.rice.krms.impl.repository.TermResolverBo;
33 import org.kuali.rice.krms.impl.repository.TermResolverParameterSpecificationBo;
34
35 import java.util.ArrayList;
36 import java.util.Collection;
37 import java.util.Collections;
38 import java.util.Comparator;
39 import java.util.List;
40 import java.util.Map;
41
42
43
44
45
46
47
48 public class TermMaintainable extends MaintainableImpl {
49
50 private static final long serialVersionUID = 1L;
51
52 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(TermMaintainable.class);
53
54
55
56
57 public BusinessObjectService getBoService() {
58 return KRADServiceLocator.getBusinessObjectService();
59 }
60
61
62
63 public List<RemotableAttributeField> retrieveCustomAttributes(View view, Object model, Container container) {
64
65 List<RemotableAttributeField> results = new ArrayList<RemotableAttributeField>();
66
67 String termSpecId = ((TermBo)((MaintenanceDocumentForm)model).getDocument().getNewMaintainableObject().getDataObject()).getSpecificationId();
68
69 Collection<TermResolverBo> termResolvers = getBoService().findMatching(TermResolverBo.class,
70 Collections.singletonMap("outputId", termSpecId)
71 );
72
73 TermResolverBo termResolver = null;
74
75 if (termResolvers != null && termResolvers.size() == 1) {
76 termResolver = termResolvers.iterator().next();
77 }
78
79 if (termResolver != null && !CollectionUtils.isEmpty(termResolver.getParameterSpecifications())) {
80 List<TermResolverParameterSpecificationBo> params = new ArrayList<TermResolverParameterSpecificationBo>(termResolver.getParameterSpecifications());
81
82 Collections.sort(params, new Comparator<TermResolverParameterSpecificationBo>() {
83 @Override
84 public int compare(TermResolverParameterSpecificationBo o1, TermResolverParameterSpecificationBo o2) {
85 return o1.getName().compareTo(o2.getName());
86 }
87 });
88
89 for (TermResolverParameterSpecificationBo param : params) {
90 RemotableAttributeField.Builder builder = RemotableAttributeField.Builder.create(param.getName());
91 RemotableTextInput.Builder inputBuilder = RemotableTextInput.Builder.create();
92 inputBuilder.setSize(80);
93 builder.setControl(inputBuilder);
94 builder.setDataType(DataType.STRING);
95 builder.setLongLabel(param.getName());
96 builder.setShortLabel(param.getName());
97
98 results.add(builder.build());
99 }
100 }
101
102 return results;
103 }
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 @Override
130 public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) {
131
132 TermBo termBo = (TermBo) super.retrieveObjectForEditOrCopy(document, dataObjectKeys);
133 termBo.exportToParametersMap();
134
135 if (KRADConstants.MAINTENANCE_COPY_ACTION.equals(getMaintenanceAction())) {
136 document.getDocumentHeader().setDocumentDescription("New Term Document");
137 }
138
139 return termBo;
140 }
141
142
143
144
145 @Override
146 public void processAfterNew(MaintenanceDocument document,
147 Map<String, String[]> requestParameters) {
148
149 super.processAfterNew(document, requestParameters);
150 document.getDocumentHeader().setDocumentDescription("New Term Document");
151
152 }
153
154
155
156
157 @Override
158 public void processAfterEdit(MaintenanceDocument document, Map<String, String[]> requestParameters) {
159
160
161 super.processAfterEdit(document,
162 requestParameters);
163
164 document.getDocumentHeader().setDocumentDescription("Edited Term Document");
165 }
166
167 @Override
168 public void saveDataObject() {
169 TermBo term = (TermBo) getDataObject();
170 term.importFromParametersMap();
171
172 super.saveDataObject();
173 }
174
175 @Override
176 public Class getDataObjectClass() {
177 return TermBo.class;
178 }
179
180 @Override
181 protected void processBeforeAddLine(View view, CollectionGroup collectionGroup, Object model, Object addLine) {
182 super.processBeforeAddLine(view, collectionGroup, model, addLine);
183 }
184
185
186 }