1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kns.maintenance;
17
18 import org.kuali.rice.kns.service.KNSServiceLocator;
19 import org.kuali.rice.kns.bo.GlobalBusinessObject;
20 import org.kuali.rice.kns.bo.GlobalBusinessObjectDetail;
21 import org.kuali.rice.krad.bo.PersistableBusinessObject;
22 import org.kuali.rice.krad.data.KradDataServiceLocator;
23 import org.kuali.rice.krad.data.MaterializeOption;
24 import org.kuali.rice.krad.maintenance.MaintenanceLock;
25 import org.kuali.rice.krad.service.BusinessObjectService;
26 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
27 import org.kuali.rice.krad.util.KRADPropertyConstants;
28 import org.kuali.rice.krad.util.ObjectUtils;
29
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33
34
35
36
37 @Deprecated
38 public abstract class KualiGlobalMaintainableImpl extends KualiMaintainableImpl {
39 private static final long serialVersionUID = 4814145799502207182L;
40
41 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(KualiGlobalMaintainableImpl.class);
42
43
44
45
46 @Override
47 public void prepareForSave() {
48 if (businessObject != null) {
49 prepareGlobalsForSave();
50 }
51 }
52
53
54
55
56 @Override
57 public void processAfterRetrieve() {
58 if (businessObject != null) {
59 processGlobalsAfterRetrieve();
60 }
61 }
62
63
64
65
66
67 protected void processGlobalsAfterRetrieve() {
68
69
70
71
72
73
74
75 GlobalBusinessObject gbo = (GlobalBusinessObject) businessObject;
76 Class gboClass = businessObject.getClass();
77 String finDocNumber = gbo.getDocumentNumber();
78
79
80
81
82
83
84 boolean assumptionIsWrong = false;
85
86
87 List primaryKeys = KRADServiceLocatorWeb.getLegacyDataAdapter().listPrimaryKeyFieldNames(gboClass);
88 if (primaryKeys == null) {
89 assumptionIsWrong = true;
90 }
91 else if (primaryKeys.isEmpty()) {
92 assumptionIsWrong = true;
93 }
94 else if (primaryKeys.size() != 1) {
95 assumptionIsWrong = true;
96 }
97 else if (!primaryKeys.get(0).getClass().equals(String.class)) {
98 assumptionIsWrong = true;
99 }
100 else if (!KRADPropertyConstants.DOCUMENT_NUMBER.equalsIgnoreCase((String) primaryKeys.get(0))) {
101 assumptionIsWrong = true;
102 }
103 if (assumptionIsWrong) {
104 throw new RuntimeException("An assertion about the nature of the primary keys for this GBO has " + "failed, and processing cannot continue.");
105 }
106
107
108
109
110
111
112 Map pkMap = new HashMap();
113 pkMap.put(KRADPropertyConstants.DOCUMENT_NUMBER, finDocNumber);
114 Object newBo = KNSServiceLocator.getBusinessObjectService().findByPrimaryKey(gboClass, pkMap);
115 if (newBo == null) {
116 throw new RuntimeException("The Global Business Object could not be retrieved from the DB. " + "This should never happen under normal circumstances. If this is a legitimate case " + "Then this exception should be removed.");
117 }
118
119
120 try {
121
122
123
124
125 KradDataServiceLocator.getDataObjectService().wrap(businessObject).materializeReferencedObjectsToDepth(2
126 , MaterializeOption.COLLECTIONS, MaterializeOption.UPDATE_UPDATABLE_REFS);
127
128 KRADServiceLocatorWeb.getLegacyDataAdapter().setObjectPropertyDeep(businessObject, KRADPropertyConstants.NEW_COLLECTION_RECORD,
129 boolean.class, true);
130
131 }
132 catch (Exception e) {
133 LOG.error("unable to set newCollectionRecord property: " + e.getMessage());
134 throw new RuntimeException("unable to set newCollectionRecord property: " + e.getMessage());
135 }
136
137
138 setDataObject(newBo);
139 }
140
141
142
143
144 protected void prepareGlobalsForSave() {
145 GlobalBusinessObject gbo = (GlobalBusinessObject) businessObject;
146
147
148 gbo.setDocumentNumber(getDocumentNumber());
149
150 List<? extends GlobalBusinessObjectDetail> details = gbo.getAllDetailObjects();
151 for ( GlobalBusinessObjectDetail detail : details ) {
152 detail.setDocumentNumber(getDocumentNumber());
153 }
154 }
155
156
157
158
159
160
161 @Override
162 public abstract List<MaintenanceLock> generateMaintenanceLocks();
163
164
165
166
167 @SuppressWarnings({ "rawtypes", "unchecked" })
168 @Override
169 public void saveBusinessObject() {
170 BusinessObjectService boService = KNSServiceLocator.getBusinessObjectService();
171 GlobalBusinessObject gbo = (GlobalBusinessObject) businessObject;
172
173
174 List bosToDeactivate = gbo.generateDeactivationsToPersist();
175 if (bosToDeactivate != null) {
176 if (!bosToDeactivate.isEmpty()) {
177 boService.save(bosToDeactivate);
178 }
179 }
180
181
182 List bosToPersist = gbo.generateGlobalChangesToPersist();
183 if (bosToPersist != null) {
184 if (!bosToPersist.isEmpty()) {
185 boService.save(bosToPersist);
186 }
187 }
188
189 }
190
191 public abstract Class<? extends PersistableBusinessObject> getPrimaryEditedBusinessObjectClass();
192 }