1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.maintenance;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.criteria.QueryByCriteria;
20 import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
21
22 import java.util.ArrayList;
23 import java.util.List;
24 import java.util.Map;
25
26
27
28
29
30
31 public class BulkUpdateMaintainableImpl extends MaintainableImpl implements BulkUpdateMaintainable {
32 private static final long serialVersionUID = 6656390440709425848L;
33
34
35
36
37
38
39
40 @Override
41 public boolean isPersistable() {
42 if (StringUtils.isBlank(getDocumentNumber())) {
43 return false;
44 }
45
46 BulkUpdateMaintenanceDataObject dataObject = (BulkUpdateMaintenanceDataObject) getDataObject();
47 List<?> targetUpdateDataObjects = dataObject.getTargetUpdateDataObjects();
48
49 for (Object targetUpdateDataObject : targetUpdateDataObjects) {
50 if (!getLegacyDataAdapter().hasPrimaryKeyFieldValues(targetUpdateDataObject)) {
51 return false;
52 }
53 }
54
55 return true;
56 }
57
58
59
60
61 @Override
62 public List<Object> generateUpdatableObjects() {
63 List<Object> updatableObjects = new ArrayList<Object>();
64
65 BulkUpdateMaintenanceDataObject bulkUpdateMaintenanceDataObject = (BulkUpdateMaintenanceDataObject) getDataObject();
66 List<?> targetUpdateDataObjects = bulkUpdateMaintenanceDataObject.getTargetUpdateDataObjects();
67
68 for (Object targetUpdateDataObject : targetUpdateDataObjects) {
69 Map<String, Object> primaryKeys = getDataObjectService().wrap(targetUpdateDataObject).getPrimaryKeyValues();
70 Object updatableObject = getDataObjectService().findUnique(targetUpdateDataObject.getClass(),
71 QueryByCriteria.Builder.andAttributes(primaryKeys).build());
72
73 for (Map.Entry<String, ?> updateFieldValue : bulkUpdateMaintenanceDataObject.getUpdateFieldValues().entrySet()) {
74 String propertyName = updateFieldValue.getKey();
75 Object propertyValue = updateFieldValue.getValue();
76
77 if (ObjectPropertyUtils.isWritableProperty(updatableObject, propertyName)) {
78 ObjectPropertyUtils.setPropertyValue(updatableObject, propertyName, propertyValue);
79 updatableObjects.add(updatableObject);
80 }
81 }
82 }
83
84 return updatableObjects;
85 }
86
87
88
89
90 @Override
91 public List<MaintenanceLock> generateMaintenanceLocks() {
92 List<MaintenanceLock> maintenanceLocks = super.generateMaintenanceLocks();
93
94 BulkUpdateMaintenanceDataObject dataObject = (BulkUpdateMaintenanceDataObject) getDataObject();
95
96 for (Object targetUpdateDataObjects : dataObject.getTargetUpdateDataObjects()) {
97 String documentTypeName = getDocumentDictionaryService().getMaintenanceDocumentTypeName(targetUpdateDataObjects.getClass());
98 maintenanceLocks.addAll(generateMaintenanceLocks(getDocumentNumber(), documentTypeName, targetUpdateDataObjects.getClass(), targetUpdateDataObjects));
99 }
100
101 return maintenanceLocks;
102 }
103
104
105
106
107 @Override
108 public void saveDataObject() {
109 for (Object updateableObject : generateUpdatableObjects()) {
110 getLegacyDataAdapter().linkAndSave(updateableObject);
111 }
112 }
113
114 }