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 public class TermSpecificationMaintainable extends MaintainableImpl {
51
52 private static final long serialVersionUID = 1L;
53
54 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(TermSpecificationMaintainable.class);
55
56
57
58
59 public BusinessObjectService getBoService() {
60 return KRADServiceLocator.getBusinessObjectService();
61 }
62
63 @Override
64 public Object retrieveObjectForEditOrCopy(MaintenanceDocument document, Map<String, String> dataObjectKeys) {
65
66 TermSpecificationBo termSpecificationBo = (TermSpecificationBo) super.retrieveObjectForEditOrCopy(document,
67 dataObjectKeys);
68
69
70 Collection<ContextValidTermBo> validContextMappings =
71 getBoService().findMatching(ContextValidTermBo.class,
72 Collections.singletonMap("termSpecificationId", termSpecificationBo.getId()));
73
74 if (!CollectionUtils.isEmpty(validContextMappings)) for (ContextValidTermBo validContextMapping : validContextMappings) {
75 ContextBo context = getBoService().findBySinglePrimaryKey(ContextBo.class, validContextMapping.getContextId());
76 termSpecificationBo.getContexts().add(context);
77 }
78
79 return termSpecificationBo;
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 @Override
95 public void saveDataObject() {
96 TermSpecificationBo termSpec = (TermSpecificationBo) getDataObject();
97
98 super.saveDataObject();
99
100 if (termSpec.getId() != null) {
101
102 getBoService().deleteMatching(ContextValidTermBo.class,
103 Collections.singletonMap("termSpecificationId", termSpec.getId()));
104
105
106 if (!CollectionUtils.isEmpty(termSpec.getContexts())) for (ContextBo context : termSpec.getContexts()) {
107 ContextValidTermBo contextValidTerm = new ContextValidTermBo();
108 contextValidTerm.setContextId(context.getId());
109 contextValidTerm.setTermSpecificationId(termSpec.getId());
110 getBoService().save(contextValidTerm);
111 }
112 }
113
114 }
115
116 @Override
117 public Class getDataObjectClass() {
118 return TermSpecificationBo.class;
119 }
120
121 @Override
122 protected void processBeforeAddLine(View view, CollectionGroup collectionGroup, Object model, Object addLine) {
123 super.processBeforeAddLine(view, collectionGroup, model, addLine);
124 }
125
126
127 }