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