1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kim.impl.responsibility; |
17 | |
|
18 | |
import org.apache.commons.lang.StringUtils; |
19 | |
import org.apache.log4j.Logger; |
20 | |
import org.kuali.rice.core.api.mo.common.Attributes; |
21 | |
import org.kuali.rice.core.util.AttributeSet; |
22 | |
import org.kuali.rice.kew.util.KEWConstants; |
23 | |
import org.kuali.rice.kim.api.common.template.Template; |
24 | |
import org.kuali.rice.kim.api.responsibility.Responsibility; |
25 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
26 | |
import org.kuali.rice.kim.util.KimConstants; |
27 | |
import org.kuali.rice.kns.bo.BusinessObject; |
28 | |
import org.kuali.rice.kns.bo.PersistableBusinessObject; |
29 | |
import org.kuali.rice.kns.document.MaintenanceDocument; |
30 | |
import org.kuali.rice.kns.maintenance.KualiMaintainableImpl; |
31 | |
import org.kuali.rice.kns.maintenance.Maintainable; |
32 | |
import org.kuali.rice.kns.web.ui.Field; |
33 | |
import org.kuali.rice.kns.web.ui.Row; |
34 | |
import org.kuali.rice.kns.web.ui.Section; |
35 | |
|
36 | |
import java.util.List; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | 0 | public class ReviewResponsibilityMaintainable extends KualiMaintainableImpl { |
45 | |
|
46 | 0 | private static final Logger LOG = Logger.getLogger( ReviewResponsibilityMaintainable.class ); |
47 | |
private static final long serialVersionUID = -8102504656976243468L; |
48 | |
|
49 | |
|
50 | 0 | protected static Template reviewTemplate = null; |
51 | |
|
52 | |
public List getSections(MaintenanceDocument document, Maintainable oldMaintainable) { |
53 | 0 | List<Section> sections = super.getSections(document, oldMaintainable); |
54 | 0 | if(document.isEdit()){ |
55 | 0 | for (Section section : sections) { |
56 | 0 | for (Row row : section.getRows()) { |
57 | 0 | for (Field field : row.getFields()) { |
58 | 0 | if(ReviewResponsibilityBo.ACTION_DETAILS_AT_ROLE_MEMBER_LEVEL_FIELD_NAME.equals(field.getPropertyName())){ |
59 | 0 | field.setReadOnly(true); |
60 | |
} |
61 | |
} |
62 | |
} |
63 | |
} |
64 | |
} |
65 | 0 | return sections; |
66 | |
} |
67 | |
|
68 | |
|
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
@Override |
74 | |
public void saveBusinessObject() { |
75 | 0 | if ( LOG.isInfoEnabled() ) { |
76 | 0 | LOG.info( "Attempting to save ReviewResponsibilityBo BO via ResponsibilityService:" + getBusinessObject() ); |
77 | |
} |
78 | |
|
79 | 0 | if ( reviewTemplate == null ) { |
80 | 0 | populateReviewTemplateInfo(); |
81 | |
} |
82 | 0 | ReviewResponsibilityBo resp = (ReviewResponsibilityBo)getBusinessObject(); |
83 | |
|
84 | 0 | AttributeSet details = new AttributeSet(); |
85 | 0 | details.put( KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME, resp.getDocumentTypeName() ); |
86 | 0 | details.put( KimConstants.AttributeConstants.ROUTE_NODE_NAME, resp.getRouteNodeName() ); |
87 | 0 | details.put( KimConstants.AttributeConstants.REQUIRED, resp.isRequired()?"true":"false" ); |
88 | 0 | details.put( KimConstants.AttributeConstants.ACTION_DETAILS_AT_ROLE_MEMBER_LEVEL, resp.isActionDetailsAtRoleMemberLevel()?"true":"false" ); |
89 | 0 | if ( StringUtils.isNotBlank(resp.getQualifierResolverProvidedIdentifier()) ) { |
90 | 0 | details.put( KimConstants.AttributeConstants.QUALIFIER_RESOLVER_PROVIDED_IDENTIFIER, resp.getQualifierResolverProvidedIdentifier() ); |
91 | |
} |
92 | |
|
93 | 0 | Responsibility.Builder b = Responsibility.Builder.create(resp.getResponsibilityId(), resp.getNamespaceCode(), resp.getName(), Template.Builder.create(reviewTemplate)); |
94 | 0 | b.setActive(resp.isActive()); |
95 | 0 | b.setDescription(resp.getDescription()); |
96 | 0 | b.setAttributes(Attributes.fromMap(details)); |
97 | |
|
98 | 0 | KimApiServiceLocator.getResponsibilityService().updateResponsibility(b.build()); |
99 | 0 | } |
100 | |
|
101 | |
protected void populateReviewTemplateInfo() { |
102 | 0 | List<Template> template = KimApiServiceLocator.getResponsibilityService().findRespTemplatesByNamespaceCodeAndName(KEWConstants.KEW_NAMESPACE, KEWConstants.DEFAULT_RESPONSIBILITY_TEMPLATE_NAME); |
103 | |
|
104 | 0 | reviewTemplate = template.get(0); |
105 | 0 | } |
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | |
|
111 | |
|
112 | |
@Override |
113 | |
public Class<? extends BusinessObject> getBoClass() { |
114 | 0 | return ReviewResponsibilityBo.class; |
115 | |
} |
116 | |
|
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
@Override |
123 | |
public boolean isExternalBusinessObject() { |
124 | 0 | return true; |
125 | |
} |
126 | |
|
127 | |
|
128 | |
|
129 | |
|
130 | |
|
131 | |
|
132 | |
@Override |
133 | |
public void prepareBusinessObject(BusinessObject businessObject) { |
134 | |
try { |
135 | 0 | if ( businessObject == null ) { |
136 | 0 | throw new RuntimeException( "Configuration ERROR: ReviewResponsibilityBoMaintainable.prepareBusinessObject passed a null object." ); |
137 | |
} |
138 | 0 | if ( businessObject instanceof ResponsibilityBo ) { |
139 | 0 | ResponsibilityBo resp = getBusinessObjectService().findBySinglePrimaryKey(ResponsibilityBo.class, ((ResponsibilityBo)businessObject).getId() ); |
140 | 0 | businessObject = new ReviewResponsibilityBo( resp ); |
141 | 0 | } else if ( businessObject instanceof ReviewResponsibilityBo ) { |
142 | |
|
143 | 0 | ResponsibilityBo resp = getBusinessObjectService().findBySinglePrimaryKey(ResponsibilityBo.class, ((ReviewResponsibilityBo)businessObject).getResponsibilityId() ); |
144 | 0 | ((ReviewResponsibilityBo)businessObject).loadFromKimResponsibility(resp); |
145 | 0 | } else { |
146 | 0 | throw new RuntimeException( "Configuration ERROR: ReviewResponsibilityBoMaintainable passed an unsupported object type: " + businessObject.getClass() ); |
147 | |
} |
148 | 0 | if ( businessObject instanceof PersistableBusinessObject ) { |
149 | 0 | setBusinessObject( (PersistableBusinessObject)businessObject ); |
150 | |
} |
151 | 0 | super.prepareBusinessObject(businessObject); |
152 | 0 | } catch ( RuntimeException ex ) { |
153 | 0 | LOG.error( "Exception in prepareBusinessObject()", ex ); |
154 | 0 | throw ex; |
155 | 0 | } |
156 | 0 | } |
157 | |
|
158 | |
} |