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