1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.service.impl; |
17 | |
|
18 | |
import java.util.Iterator; |
19 | |
import java.util.List; |
20 | |
import java.util.Map.Entry; |
21 | |
|
22 | |
import org.apache.commons.lang.StringUtils; |
23 | |
import org.apache.log4j.Logger; |
24 | |
import org.kuali.rice.kim.bo.role.impl.KimResponsibilityImpl; |
25 | |
import org.kuali.rice.kim.bo.role.impl.ResponsibilityAttributeDataImpl; |
26 | |
import org.kuali.rice.kim.bo.types.dto.AttributeSet; |
27 | |
import org.kuali.rice.kim.bo.types.dto.KimTypeAttributeInfo; |
28 | |
import org.kuali.rice.kim.service.KIMServiceLocator; |
29 | |
import org.kuali.rice.kim.service.ResponsibilityUpdateService; |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | 0 | public class ResponsibilityUpdateServiceImpl extends ResponsibilityServiceBase implements ResponsibilityUpdateService { |
38 | 0 | private static final Logger LOG = Logger.getLogger( ResponsibilityUpdateServiceImpl.class ); |
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
public void saveResponsibility(String responsibilityId, |
44 | |
String responsibilityTemplateId, String namespaceCode, String name, |
45 | |
String description, boolean active, AttributeSet responsibilityDetails ) { |
46 | |
|
47 | |
try { |
48 | 0 | KimResponsibilityImpl resp = getBusinessObjectService().findBySinglePrimaryKey(KimResponsibilityImpl.class, responsibilityId); |
49 | 0 | if ( resp == null ) { |
50 | 0 | resp = new KimResponsibilityImpl(); |
51 | 0 | resp.setResponsibilityId(responsibilityId); |
52 | |
} |
53 | 0 | resp.setTemplateId(responsibilityTemplateId); |
54 | 0 | resp.refreshReferenceObject( "template" ); |
55 | 0 | resp.setNamespaceCode(namespaceCode); |
56 | 0 | resp.setName(name); |
57 | 0 | resp.setDescription(description); |
58 | 0 | resp.setActive(active); |
59 | 0 | AttributeSet attributesToAdd = new AttributeSet( responsibilityDetails ); |
60 | 0 | List<ResponsibilityAttributeDataImpl> details = resp.getDetailObjects(); |
61 | 0 | Iterator<ResponsibilityAttributeDataImpl> detailIter = details.iterator(); |
62 | 0 | while ( detailIter.hasNext() ) { |
63 | 0 | ResponsibilityAttributeDataImpl detail = detailIter.next(); |
64 | 0 | String attrName = detail.getKimAttribute().getAttributeName(); |
65 | 0 | String attrValue = attributesToAdd.get(attrName); |
66 | |
|
67 | 0 | if ( StringUtils.isBlank(attrValue) ) { |
68 | 0 | detailIter.remove(); |
69 | |
} else { |
70 | 0 | detail.setAttributeValue(attrValue); |
71 | |
} |
72 | |
|
73 | 0 | attributesToAdd.remove(attrName); |
74 | 0 | } |
75 | 0 | for ( Entry<String,String> attrEntry : attributesToAdd.entrySet() ) { |
76 | 0 | KimTypeAttributeInfo attr = resp.getTemplate().getKimType().getAttributeDefinitionByName(attrEntry.getKey()); |
77 | 0 | if (attr != null && StringUtils.isNotBlank(attrEntry.getValue()) ) { |
78 | 0 | ResponsibilityAttributeDataImpl newDetail = new ResponsibilityAttributeDataImpl(); |
79 | 0 | newDetail.setAttributeDataId(getNewAttributeDataId()); |
80 | 0 | newDetail.setKimAttributeId(attr.getKimAttributeId()); |
81 | 0 | newDetail.setKimTypeId(resp.getTemplate().getKimTypeId()); |
82 | 0 | newDetail.setResponsibilityId(responsibilityId); |
83 | 0 | newDetail.setAttributeValue(attrEntry.getValue()); |
84 | 0 | details.add(newDetail); |
85 | |
} |
86 | 0 | } |
87 | 0 | getBusinessObjectService().save(resp); |
88 | |
|
89 | 0 | KIMServiceLocator.getIdentityManagementService().flushResponsibilityCaches(); |
90 | |
|
91 | 0 | flushResponsibilityImplCache(); |
92 | 0 | } catch ( RuntimeException ex ) { |
93 | 0 | LOG.error( "Exception in saveResponsibility: ", ex ); |
94 | 0 | throw ex; |
95 | 0 | } |
96 | 0 | } |
97 | |
|
98 | |
} |