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.ContextBo; |
31 | |
import org.kuali.rice.krms.impl.repository.ContextValidTermBo; |
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 | |
import org.kuali.rice.krms.impl.repository.TermSpecificationBo; |
36 | |
|
37 | |
import java.util.ArrayList; |
38 | |
import java.util.Collection; |
39 | |
import java.util.Collections; |
40 | |
import java.util.Comparator; |
41 | |
import java.util.List; |
42 | |
import java.util.Map; |
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | 0 | public class TermSpecificationMaintainable extends MaintainableImpl { |
51 | |
|
52 | |
private static final long serialVersionUID = 1L; |
53 | |
|
54 | 0 | private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(TermSpecificationMaintainable.class); |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
public BusinessObjectService getBoService() { |
60 | 0 | return KRADServiceLocator.getBusinessObjectService(); |
61 | |
} |
62 | |
|
63 | |
@Override |
64 | |
public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) { |
65 | |
|
66 | 0 | TermSpecificationBo termSpecificationBo = (TermSpecificationBo) super.retrieveObjectForEditOrCopy(document, |
67 | |
dataObjectKeys); |
68 | |
|
69 | |
|
70 | 0 | Collection<ContextValidTermBo> validContextMappings = |
71 | |
getBoService().findMatching(ContextValidTermBo.class, |
72 | |
Collections.singletonMap("termSpecificationId", termSpecificationBo.getId())); |
73 | |
|
74 | 0 | if (!CollectionUtils.isEmpty(validContextMappings)) for (ContextValidTermBo validContextMapping : validContextMappings) { |
75 | 0 | ContextBo context = getBoService().findBySinglePrimaryKey(ContextBo.class, validContextMapping.getContextId()); |
76 | 0 | termSpecificationBo.getContexts().add(context); |
77 | 0 | } |
78 | |
|
79 | 0 | return termSpecificationBo; |
80 | |
} |
81 | |
|
82 | |
|
83 | |
|
84 | |
|
85 | |
@Override |
86 | |
public void processAfterNew(MaintenanceDocument document, |
87 | |
Map<String, String[]> requestParameters) { |
88 | |
|
89 | 0 | super.processAfterNew(document, requestParameters); |
90 | 0 | document.getDocumentHeader().setDocumentDescription("New Term Specification Document"); |
91 | |
|
92 | 0 | } |
93 | |
|
94 | |
@Override |
95 | |
public void saveDataObject() { |
96 | 0 | TermSpecificationBo termSpec = (TermSpecificationBo) getDataObject(); |
97 | |
|
98 | 0 | super.saveDataObject(); |
99 | |
|
100 | 0 | if (termSpec.getId() != null) { |
101 | |
|
102 | 0 | getBoService().deleteMatching(ContextValidTermBo.class, |
103 | |
Collections.singletonMap("termSpecificationId", termSpec.getId())); |
104 | |
|
105 | |
|
106 | 0 | if (!CollectionUtils.isEmpty(termSpec.getContexts())) for (ContextBo context : termSpec.getContexts()) { |
107 | 0 | ContextValidTermBo contextValidTerm = new ContextValidTermBo(); |
108 | 0 | contextValidTerm.setContextId(context.getId()); |
109 | 0 | contextValidTerm.setTermSpecificationId(termSpec.getId()); |
110 | 0 | getBoService().save(contextValidTerm); |
111 | 0 | } |
112 | |
} |
113 | |
|
114 | 0 | } |
115 | |
|
116 | |
@Override |
117 | |
public Class getDataObjectClass() { |
118 | 0 | return TermSpecificationBo.class; |
119 | |
} |
120 | |
|
121 | |
@Override |
122 | |
protected void processBeforeAddLine(View view, CollectionGroup collectionGroup, Object model, Object addLine) { |
123 | 0 | super.processBeforeAddLine(view, collectionGroup, model, addLine); |
124 | 0 | } |
125 | |
|
126 | |
|
127 | |
} |