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.kew.api.KewApiConstants;
21 import org.kuali.rice.kim.api.KimConstants;
22 import org.kuali.rice.kim.api.common.template.Template;
23 import org.kuali.rice.kim.api.responsibility.Responsibility;
24 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
25 import org.kuali.rice.kim.impl.common.attribute.KimAttributeDataBo;
26 import org.kuali.rice.kim.impl.permission.PermissionTemplateBo;
27 import org.kuali.rice.kns.document.MaintenanceDocument;
28 import org.kuali.rice.kns.maintenance.KualiMaintainableImpl;
29 import org.kuali.rice.kns.maintenance.Maintainable;
30 import org.kuali.rice.kns.service.KNSServiceLocator;
31 import org.kuali.rice.kns.web.ui.Field;
32 import org.kuali.rice.kns.web.ui.Row;
33 import org.kuali.rice.kns.web.ui.Section;
34 import org.kuali.rice.krad.bo.BusinessObject;
35 import org.kuali.rice.krad.bo.PersistableBusinessObject;
36 import org.kuali.rice.krad.util.KRADConstants;
37
38 import java.util.HashMap;
39 import java.util.List;
40 import java.util.Map;
41
42 public class ReviewResponsibilityMaintainable extends KualiMaintainableImpl {
43
44 private static final Logger LOG = Logger.getLogger( ReviewResponsibilityMaintainable.class );
45 private static final long serialVersionUID = -8102504656976243468L;
46
47 private static Template REVIEW_TEMPLATE;
48
49 public List getSections(MaintenanceDocument document, Maintainable oldMaintainable) {
50 List<Section> sections = super.getSections(document, oldMaintainable);
51 if(document.isEdit()){
52 for (Section section : sections) {
53 for (Row row : section.getRows()) {
54 for (Field field : row.getFields()) {
55 if(ReviewResponsibilityBo.ACTION_DETAILS_AT_ROLE_MEMBER_LEVEL_FIELD_NAME.equals(field.getPropertyName())){
56 field.setReadOnly(true);
57 }
58 }
59 }
60 }
61 }
62 return sections;
63 }
64
65
66
67
68
69
70 @Override
71 public void saveDataObject() {
72 if ( LOG.isInfoEnabled() ) {
73 LOG.info( "Attempting to save ReviewResponsibilityBo BO via ResponsibilityService:" + getBusinessObject() );
74 }
75 populateReviewTemplateInfo();
76
77 ReviewResponsibilityBo resp = (ReviewResponsibilityBo)getDataObject();
78
79 Map<String, String> details = new HashMap<String, String>();
80 details.put( KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME, resp.getDocumentTypeName() );
81 details.put( KimConstants.AttributeConstants.ROUTE_NODE_NAME, resp.getRouteNodeName() );
82 details.put( KimConstants.AttributeConstants.REQUIRED, resp.isRequired()?"true":"false" );
83 details.put( KimConstants.AttributeConstants.ACTION_DETAILS_AT_ROLE_MEMBER_LEVEL, resp.isActionDetailsAtRoleMemberLevel()?"true":"false" );
84 if ( StringUtils.isNotBlank(resp.getQualifierResolverProvidedIdentifier()) ) {
85 details.put( KimConstants.AttributeConstants.QUALIFIER_RESOLVER_PROVIDED_IDENTIFIER, resp.getQualifierResolverProvidedIdentifier() );
86 }
87
88
89 if (resp.getTemplateId() == null) {
90 resp.setTemplateId(REVIEW_TEMPLATE.getId());
91 resp.setTemplate(ResponsibilityTemplateBo.from(REVIEW_TEMPLATE));
92 }
93
94 else {
95 resp.setTemplate(
96 ResponsibilityTemplateBo.from(KimApiServiceLocator.getResponsibilityService().getResponsibilityTemplate(
97 resp.getTemplateId())));
98 }
99
100 resp.setAttributes(details);
101 resp.setAttributeDetails(KimAttributeDataBo.createFrom(ResponsibilityAttributeBo.class, details, resp.getTemplate().getKimTypeId()));
102
103 boolean responsibilityExists = false;
104 if (resp.getId() != null) {
105 responsibilityExists = KimApiServiceLocator.getResponsibilityService().getResponsibility(resp.getId()) != null;
106 }
107
108 if (responsibilityExists) {
109 KimApiServiceLocator.getResponsibilityService().updateResponsibility(ResponsibilityBo.to(resp));
110 } else {
111
112 if(getMaintenanceAction().equals(KRADConstants.MAINTENANCE_COPY_ACTION)){
113 if(org.apache.commons.lang.StringUtils.isNotBlank(resp.getObjectId())){
114 resp.setObjectId("");
115 }
116 if(null!= resp.getVersionNumber()){
117 resp.setVersionNumber(null);
118 }
119 }
120 KimApiServiceLocator.getResponsibilityService().createResponsibility(ResponsibilityBo.to(resp));
121 }
122 }
123
124 private static synchronized void populateReviewTemplateInfo() {
125 if ( REVIEW_TEMPLATE == null ) {
126 REVIEW_TEMPLATE = KimApiServiceLocator.getResponsibilityService().findRespTemplateByNamespaceCodeAndName(KewApiConstants.KEW_NAMESPACE, KewApiConstants.DEFAULT_RESPONSIBILITY_TEMPLATE_NAME);
127 }
128 }
129
130 @Override
131 public Class<? extends BusinessObject> getBoClass() {
132 return ReviewResponsibilityBo.class;
133 }
134
135 @Override
136 public void prepareBusinessObject(BusinessObject businessObject) {
137 if ( businessObject == null ) {
138 throw new RuntimeException( "Configuration ERROR: ReviewResponsibilityBoMaintainable.prepareBusinessObject passed a null object." );
139 }
140 if ( businessObject instanceof ResponsibilityBo ) {
141 ResponsibilityBo resp = KNSServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(ResponsibilityBo.class, ((ResponsibilityBo)businessObject).getId() );
142 businessObject = new ReviewResponsibilityBo( resp );
143 setBusinessObject( (PersistableBusinessObject)businessObject );
144 } else {
145 throw new RuntimeException( "Configuration ERROR: ReviewResponsibilityBoMaintainable passed an unsupported object type: " + businessObject.getClass() );
146 }
147 super.prepareBusinessObject(businessObject);
148 }
149
150
151
152
153
154
155 @Override
156 public boolean isExternalBusinessObject() {
157 return true;
158 }
159
160 }