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.criteria.QueryByCriteria;
20 import org.kuali.rice.core.api.criteria.QueryResults;
21 import org.kuali.rice.core.api.data.DataType;
22 import org.kuali.rice.core.api.uif.RemotableAttributeField;
23 import org.kuali.rice.core.api.uif.RemotableTextInput;
24 import org.kuali.rice.krad.maintenance.MaintainableImpl;
25 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
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.uif.view.ViewModel;
30 import org.kuali.rice.krad.util.KRADConstants;
31 import org.kuali.rice.krad.web.form.MaintenanceDocumentForm;
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.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 public List<RemotableAttributeField> retrieveCustomAttributes(View view, Object model, Container container) {
56
57 List<RemotableAttributeField> results = new ArrayList<RemotableAttributeField>();
58 String termSpecId = ((TermBo)((MaintenanceDocumentForm)model).getDocument().getNewMaintainableObject().getDataObject()).getSpecificationId();
59
60 QueryResults<TermResolverBo> termResolvers = getDataObjectService().findMatching(TermResolverBo.class,
61 QueryByCriteria.Builder.forAttribute("outputId", termSpecId).build()
62 );
63
64 TermResolverBo termResolver = null;
65
66 if (termResolvers.getResults() != null && termResolvers.getResults().size() == 1) {
67 termResolver = termResolvers.getResults().get(0);
68 }
69
70 if (termResolver != null && !CollectionUtils.isEmpty(termResolver.getParameterSpecifications())) {
71 List<TermResolverParameterSpecificationBo> params = new ArrayList<TermResolverParameterSpecificationBo>(termResolver.getParameterSpecifications());
72
73 Collections.sort(params, new Comparator<TermResolverParameterSpecificationBo>() {
74 @Override
75 public int compare(TermResolverParameterSpecificationBo o1, TermResolverParameterSpecificationBo o2) {
76 return o1.getName().compareTo(o2.getName());
77 }
78 });
79
80 for (TermResolverParameterSpecificationBo param : params) {
81 RemotableAttributeField.Builder builder = RemotableAttributeField.Builder.create(param.getName());
82 RemotableTextInput.Builder inputBuilder = RemotableTextInput.Builder.create();
83 inputBuilder.setSize(80);
84 builder.setControl(inputBuilder);
85 builder.setDataType(DataType.STRING);
86 builder.setLongLabel(param.getName());
87 builder.setShortLabel(param.getName());
88
89 results.add(builder.build());
90 }
91 }
92
93 return results;
94 }
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120 @Override
121 public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) {
122
123 TermBo termBo = (TermBo) super.retrieveObjectForEditOrCopy(document, dataObjectKeys);
124 termBo.exportToParametersMap();
125
126 if (KRADConstants.MAINTENANCE_COPY_ACTION.equals(getMaintenanceAction())) {
127 document.getDocumentHeader().setDocumentDescription("New Term Document");
128 }
129
130 return termBo;
131 }
132
133
134
135
136 @Override
137 public void processAfterNew(MaintenanceDocument document,
138 Map<String, String[]> requestParameters) {
139
140 super.processAfterNew(document, requestParameters);
141 document.getDocumentHeader().setDocumentDescription("New Term Document");
142
143 }
144
145
146
147
148 @Override
149 public void processAfterEdit(MaintenanceDocument document, Map<String, String[]> requestParameters) {
150
151
152 super.processAfterEdit(document,
153 requestParameters);
154
155 document.getDocumentHeader().setDocumentDescription("Edited Term Document");
156 }
157
158 @Override
159 public void saveDataObject() {
160 TermBo term = (TermBo) getDataObject();
161 term.importFromParametersMap();
162
163 super.saveDataObject();
164 }
165
166 @Override
167 public Class getDataObjectClass() {
168 return TermBo.class;
169 }
170
171 @Override
172 public void processBeforeAddLine(ViewModel model, Object addLine, String collectionId, String collectionPath) {
173 super.processBeforeAddLine(model, addLine, collectionId, collectionPath);
174 }
175
176
177 }