1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.impl.peopleflow;
17
18 import org.apache.commons.lang.StringUtils;
19 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
20 import org.kuali.rice.core.api.uif.RemotableAttributeField;
21 import org.kuali.rice.kew.api.KewApiServiceLocator;
22 import org.kuali.rice.kew.api.peopleflow.PeopleFlowDefinition;
23 import org.kuali.rice.kew.api.repository.type.KewTypeDefinition;
24 import org.kuali.rice.kew.framework.peopleflow.PeopleFlowTypeService;
25 import org.kuali.rice.krad.maintenance.MaintainableImpl;
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.util.ObjectPropertyUtils;
29 import org.kuali.rice.krad.uif.view.View;
30 import org.kuali.rice.krad.web.form.MaintenanceForm;
31
32 import java.util.ArrayList;
33 import java.util.Collection;
34 import java.util.Collections;
35 import java.util.Comparator;
36 import java.util.List;
37
38
39
40
41
42
43 public class PeopleFlowMaintainableImpl extends MaintainableImpl {
44
45
46
47
48
49
50
51
52
53
54 public List<RemotableAttributeField> retrieveTypeAttributes(View view, Object model, Container container) {
55 List<RemotableAttributeField> remoteFields = new ArrayList<RemotableAttributeField>();
56
57 PeopleFlowBo peopleFlow =
58 (PeopleFlowBo) ((MaintenanceForm) model).getDocument().getNewMaintainableObject().getDataObject();
59
60
61 String typeId = peopleFlow.getTypeId();
62 if (StringUtils.isNotBlank(typeId)) {
63 KewTypeDefinition typeDefinition = KewApiServiceLocator.getKewTypeRepositoryService().getTypeById(typeId);
64 PeopleFlowTypeService peopleFlowTypeService = GlobalResourceLoader.<PeopleFlowTypeService>getService(
65 typeDefinition.getServiceName());
66 remoteFields = peopleFlowTypeService.getAttributeFields(typeId);
67 }
68
69 return remoteFields;
70 }
71
72
73
74
75
76 @Override
77 public void saveDataObject() {
78 ((PeopleFlowBo) getDataObject()).updateAttributeBoValues();
79
80 PeopleFlowDefinition peopleFlowDefinition = PeopleFlowBo.to(((PeopleFlowBo) getDataObject()));
81 if (StringUtils.isNotBlank(peopleFlowDefinition.getId())) {
82 KewApiServiceLocator.getPeopleFlowService().updatePeopleFlow(peopleFlowDefinition);
83 } else {
84 KewApiServiceLocator.getPeopleFlowService().createPeopleFlow(peopleFlowDefinition);
85 }
86 }
87
88 @Override
89 public void processCollectionAddLine(View view, Object model, String collectionPath) {
90
91
92
93
94 CollectionGroup collectionGroup = view.getViewIndex().getCollectionGroupByPath(collectionPath);
95 if (collectionGroup == null) {
96 logAndThrowRuntime("Unable to get collection group component for path: " + collectionPath);
97 }
98
99
100 Collection<Object> collection = ObjectPropertyUtils.getPropertyValue(model, collectionPath);
101 if (collection == null) {
102 logAndThrowRuntime("Unable to get collection property from model for path: " + collectionPath);
103 }
104
105
106 String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
107 Object addLine = ObjectPropertyUtils.getPropertyValue(model, addLinePath);
108 if (addLine == null) {
109 logAndThrowRuntime("Add line instance not found for path: " + addLinePath);
110 }
111
112 processBeforeAddLine(view, collectionGroup, model, addLine);
113
114
115 boolean isValidLine = performAddLineValidation(view, collectionGroup, model, addLine);
116 if (isValidLine) {
117
118
119
120 if (collection instanceof List) {
121 ((List) collection).add(0, addLine);
122
123 if (addLine instanceof PeopleFlowMemberBo) {
124 Collections.sort((List) collection, new Comparator<Object>() {
125 public int compare(Object o1, Object o2) {
126 if ((o1 instanceof PeopleFlowMemberBo) && (o1 instanceof PeopleFlowMemberBo)) {
127 return ((PeopleFlowMemberBo)o1).getPriority() - ((PeopleFlowMemberBo)o2).getPriority();
128 }
129 return 0;
130 }
131 });
132 }
133 } else {
134 collection.add(addLine);
135 }
136
137
138 collectionGroup.initializeNewCollectionLine(view, model, collectionGroup, true);
139 }
140
141 processAfterAddLine(view, collectionGroup, model, addLine);
142 }
143 }