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