1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.krad.service.impl;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.apache.commons.lang.StringUtils;
22 import org.kuali.rice.core.api.criteria.PredicateFactory;
23 import org.kuali.rice.core.api.criteria.QueryByCriteria;
24 import org.kuali.rice.core.api.criteria.QueryResults;
25 import org.kuali.rice.kim.api.group.Group;
26 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
27 import org.kuali.rice.krad.bo.AdHocRoutePerson;
28 import org.kuali.rice.krad.bo.AdHocRouteRecipient;
29 import org.kuali.rice.krad.bo.AdHocRouteWorkgroup;
30 import org.kuali.rice.krad.data.DataObjectService;
31 import org.kuali.rice.krad.document.Document;
32 import org.kuali.rice.krad.service.DocumentAdHocService;
33
34
35
36
37
38
39
40 public class DocumentAdHocServiceImpl implements DocumentAdHocService {
41
42 protected DataObjectService dataObjectService;
43
44
45
46
47 @Override
48 public void replaceAdHocsForDocument( String documentNumber, List<AdHocRouteRecipient> adHocRoutingRecipients ) {
49 if ( StringUtils.isBlank(documentNumber) ) {
50 return;
51 }
52 dataObjectService.deleteMatching( AdHocRoutePerson.class,
53 QueryByCriteria.Builder.forAttribute("documentNumber", documentNumber).build() );
54 dataObjectService.deleteMatching( AdHocRouteWorkgroup.class,
55 QueryByCriteria.Builder.forAttribute("documentNumber", documentNumber).build() );
56
57 if ( adHocRoutingRecipients != null ) {
58 for ( AdHocRouteRecipient recipient : adHocRoutingRecipients ) {
59 recipient.setdocumentNumber(documentNumber);
60 dataObjectService.save(recipient);
61 }
62 }
63 }
64
65
66
67
68 @Override
69 public void addAdHocs(Document document) {
70 if ( document == null ) {
71 return;
72 }
73
74
75
76
77 QueryResults<AdHocRoutePerson> adHocRoutePersons = dataObjectService.findMatching(AdHocRoutePerson.class,
78 QueryByCriteria.Builder.fromPredicates(
79 PredicateFactory.equal("documentNumber", document.getDocumentNumber()),
80 PredicateFactory.equal("type", AdHocRoutePerson.PERSON_TYPE) ) );
81
82 QueryResults<AdHocRouteWorkgroup> adHocRouteWorkgroups = dataObjectService.findMatching(AdHocRouteWorkgroup.class,
83 QueryByCriteria.Builder.fromPredicates(
84 PredicateFactory.equal("documentNumber", document.getDocumentNumber()),
85 PredicateFactory.equal("type", AdHocRoutePerson.WORKGROUP_TYPE) ) );
86
87
88 for (AdHocRouteWorkgroup adHocRouteWorkgroup : adHocRouteWorkgroups.getResults()) {
89 Group group = KimApiServiceLocator.getGroupService().getGroup(adHocRouteWorkgroup.getId());
90 adHocRouteWorkgroup.setRecipientName(group.getName());
91 adHocRouteWorkgroup.setRecipientNamespaceCode(group.getNamespaceCode());
92 }
93
94
95 document.setAdHocRoutePersons( new ArrayList<AdHocRoutePerson>( adHocRoutePersons.getResults() ) );
96 document.setAdHocRouteWorkgroups( new ArrayList<AdHocRouteWorkgroup>( adHocRouteWorkgroups.getResults() ) );
97 }
98
99 public void setDataObjectService(DataObjectService dataObjectService) {
100 this.dataObjectService = dataObjectService;
101 }
102
103 }