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 | 0 | public class TermMaintainable extends MaintainableImpl { |
50 | |
|
51 | |
private static final long serialVersionUID = 1L; |
52 | |
|
53 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(TermMaintainable.class); |
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
public BusinessObjectService getBoService() { |
59 | 0 | return KRADServiceLocator.getBusinessObjectService(); |
60 | |
} |
61 | |
|
62 | |
|
63 | |
|
64 | |
public List<RemotableAttributeField> retrieveCustomAttributes(View view, Object model, Container container) { |
65 | |
|
66 | 0 | List<RemotableAttributeField> results = new ArrayList<RemotableAttributeField>(); |
67 | |
|
68 | 0 | String termSpecId = ((TermBo)((MaintenanceForm)model).getDocument().getNewMaintainableObject().getDataObject()).getSpecificationId(); |
69 | |
|
70 | 0 | Collection<TermResolverBo> termResolvers = getBoService().findMatching(TermResolverBo.class, |
71 | |
Collections.singletonMap("outputId", termSpecId) |
72 | |
); |
73 | |
|
74 | 0 | TermResolverBo termResolver = null; |
75 | |
|
76 | 0 | if (termResolvers != null && termResolvers.size() == 1) { |
77 | 0 | termResolver = termResolvers.iterator().next(); |
78 | |
} |
79 | |
|
80 | 0 | if (termResolver != null && !CollectionUtils.isEmpty(termResolver.getParameterSpecifications())) { |
81 | 0 | List<TermResolverParameterSpecificationBo> params = new ArrayList<TermResolverParameterSpecificationBo>(termResolver.getParameterSpecifications()); |
82 | |
|
83 | 0 | Collections.sort(params, new Comparator<TermResolverParameterSpecificationBo>() { |
84 | |
@Override |
85 | |
public int compare(TermResolverParameterSpecificationBo o1, TermResolverParameterSpecificationBo o2) { |
86 | 0 | return o1.getName().compareTo(o2.getName()); |
87 | |
} |
88 | |
}); |
89 | |
|
90 | 0 | for (TermResolverParameterSpecificationBo param : params) { |
91 | 0 | RemotableAttributeField.Builder builder = RemotableAttributeField.Builder.create(param.getName()); |
92 | 0 | RemotableTextInput.Builder inputBuilder = RemotableTextInput.Builder.create(); |
93 | 0 | inputBuilder.setSize(80); |
94 | 0 | builder.setControl(inputBuilder); |
95 | 0 | builder.setDataType(DataType.STRING); |
96 | 0 | builder.setLongLabel(param.getName()); |
97 | 0 | builder.setShortLabel(param.getName()); |
98 | |
|
99 | 0 | results.add(builder.build()); |
100 | 0 | } |
101 | |
} |
102 | |
|
103 | 0 | 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 | 0 | TermBo termBo = (TermBo)document.getNewMaintainableObject().getDataObject(); |
134 | 0 | termBo.exportToParametersMap(); |
135 | |
|
136 | 0 | 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 | 0 | super.processAfterNew(document, requestParameters); |
148 | 0 | document.getDocumentHeader().setDocumentDescription("New Term Document"); |
149 | |
|
150 | 0 | } |
151 | |
|
152 | |
@Override |
153 | |
public void saveDataObject() { |
154 | 0 | TermBo term = (TermBo) getDataObject(); |
155 | 0 | term.importFromParametersMap(); |
156 | |
|
157 | 0 | super.saveDataObject(); |
158 | 0 | } |
159 | |
|
160 | |
@Override |
161 | |
public Class getDataObjectClass() { |
162 | 0 | return TermBo.class; |
163 | |
} |
164 | |
|
165 | |
@Override |
166 | |
protected void processBeforeAddLine(View view, CollectionGroup collectionGroup, Object model, Object addLine) { |
167 | 0 | super.processBeforeAddLine(view, collectionGroup, model, addLine); |
168 | 0 | } |
169 | |
|
170 | |
|
171 | |
} |