| 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.util.KEWConstants; | 
  | 21 |  |  import org.kuali.rice.kim.api.common.template.Template; | 
  | 22 |  |  import org.kuali.rice.kim.api.responsibility.Responsibility; | 
  | 23 |  |  import org.kuali.rice.kim.api.services.KimApiServiceLocator; | 
  | 24 |  |  import org.kuali.rice.kim.util.KimConstants; | 
  | 25 |  |  import org.kuali.rice.kns.document.MaintenanceDocument; | 
  | 26 |  |  import org.kuali.rice.kns.maintenance.KualiMaintainableImpl; | 
  | 27 |  |  import org.kuali.rice.kns.maintenance.Maintainable; | 
  | 28 |  |  import org.kuali.rice.kns.web.ui.Field; | 
  | 29 |  |  import org.kuali.rice.kns.web.ui.Row; | 
  | 30 |  |  import org.kuali.rice.kns.web.ui.Section; | 
  | 31 |  |  import org.kuali.rice.krad.bo.BusinessObject; | 
  | 32 |  |  import org.kuali.rice.krad.bo.PersistableBusinessObject; | 
  | 33 |  |   | 
  | 34 |  |  import java.util.HashMap; | 
  | 35 |  |  import java.util.List; | 
  | 36 |  |  import java.util.Map; | 
  | 37 |  |   | 
  | 38 | 0 |  public class ReviewResponsibilityMaintainable extends KualiMaintainableImpl { | 
  | 39 |  |   | 
  | 40 | 0 |          private static final Logger LOG = Logger.getLogger( ReviewResponsibilityMaintainable.class ); | 
  | 41 |  |          private static final long serialVersionUID = -8102504656976243468L; | 
  | 42 |  |   | 
  | 43 |  |          private static Template REVIEW_TEMPLATE; | 
  | 44 |  |   | 
  | 45 |  |      public List getSections(MaintenanceDocument document, Maintainable oldMaintainable) { | 
  | 46 | 0 |          List<Section> sections = super.getSections(document, oldMaintainable); | 
  | 47 | 0 |          if(document.isEdit()){ | 
  | 48 | 0 |                  for (Section section : sections) { | 
  | 49 | 0 |                  for (Row row : section.getRows()) { | 
  | 50 | 0 |                      for (Field field : row.getFields()) { | 
  | 51 | 0 |                              if(ReviewResponsibilityBo.ACTION_DETAILS_AT_ROLE_MEMBER_LEVEL_FIELD_NAME.equals(field.getPropertyName())){ | 
  | 52 | 0 |                                      field.setReadOnly(true); | 
  | 53 |  |                              } | 
  | 54 |  |                      } | 
  | 55 |  |                  } | 
  | 56 |  |                  } | 
  | 57 |  |          } | 
  | 58 | 0 |          return sections; | 
  | 59 |  |      } | 
  | 60 |  |                   | 
  | 61 |  |           | 
  | 62 |  |   | 
  | 63 |  |   | 
  | 64 |  |   | 
  | 65 |  |   | 
  | 66 |  |          @Override | 
  | 67 |  |          public void saveBusinessObject() { | 
  | 68 | 0 |          if ( LOG.isInfoEnabled() ) { | 
  | 69 | 0 |              LOG.info( "Attempting to save ReviewResponsibilityBo BO via ResponsibilityService:" + getBusinessObject() ); | 
  | 70 |  |          } | 
  | 71 | 0 |          populateReviewTemplateInfo(); | 
  | 72 |  |   | 
  | 73 | 0 |          ReviewResponsibilityBo resp = (ReviewResponsibilityBo)getBusinessObject(); | 
  | 74 |  |           | 
  | 75 | 0 |          Map<String, String> details = new HashMap<String, String>(); | 
  | 76 | 0 |          details.put( KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME, resp.getDocumentTypeName() ); | 
  | 77 | 0 |          details.put( KimConstants.AttributeConstants.ROUTE_NODE_NAME, resp.getRouteNodeName() ); | 
  | 78 | 0 |          details.put( KimConstants.AttributeConstants.REQUIRED, resp.isRequired()?"true":"false" ); | 
  | 79 | 0 |          details.put( KimConstants.AttributeConstants.ACTION_DETAILS_AT_ROLE_MEMBER_LEVEL, resp.isActionDetailsAtRoleMemberLevel()?"true":"false" ); | 
  | 80 | 0 |          if ( StringUtils.isNotBlank(resp.getQualifierResolverProvidedIdentifier()) ) { | 
  | 81 | 0 |              details.put( KimConstants.AttributeConstants.QUALIFIER_RESOLVER_PROVIDED_IDENTIFIER, resp.getQualifierResolverProvidedIdentifier() ); | 
  | 82 |  |          } | 
  | 83 |  |   | 
  | 84 | 0 |          Responsibility.Builder b = Responsibility.Builder.create(resp.getNamespaceCode(), resp.getName(), Template.Builder.create(REVIEW_TEMPLATE)); | 
  | 85 | 0 |          b.setDescription(resp.getDescription()); | 
  | 86 | 0 |          b.setAttributes(details); | 
  | 87 | 0 |          b.setActive(resp.isActive()); | 
  | 88 |  |   | 
  | 89 | 0 |          KimApiServiceLocator.getResponsibilityService().createResponsibility(b.build()); | 
  | 90 | 0 |          } | 
  | 91 |  |           | 
  | 92 |  |          private static synchronized void populateReviewTemplateInfo() { | 
  | 93 | 0 |                  if ( REVIEW_TEMPLATE == null ) { | 
  | 94 | 0 |                      REVIEW_TEMPLATE = KimApiServiceLocator.getResponsibilityService().findRespTemplateByNamespaceCodeAndName(KEWConstants.KEW_NAMESPACE, KEWConstants.DEFAULT_RESPONSIBILITY_TEMPLATE_NAME); | 
  | 95 |  |          } | 
  | 96 | 0 |          } | 
  | 97 |  |   | 
  | 98 |  |          @Override | 
  | 99 |  |          public Class<? extends BusinessObject> getBoClass() { | 
  | 100 | 0 |                  return ReviewResponsibilityBo.class; | 
  | 101 |  |          } | 
  | 102 |  |   | 
  | 103 |  |          @Override | 
  | 104 |  |          public void prepareBusinessObject(BusinessObject businessObject) { | 
  | 105 | 0 |          if ( businessObject == null ) { | 
  | 106 | 0 |              throw new RuntimeException( "Configuration ERROR: ReviewResponsibilityBoMaintainable.prepareBusinessObject passed a null object." ); | 
  | 107 |  |          } | 
  | 108 | 0 |          if ( businessObject instanceof ResponsibilityBo ) { | 
  | 109 | 0 |              ResponsibilityBo resp = getBusinessObjectService().findBySinglePrimaryKey(ResponsibilityBo.class, ((ResponsibilityBo)businessObject).getId() ); | 
  | 110 | 0 |              businessObject = new ReviewResponsibilityBo( resp ); | 
  | 111 | 0 |              setBusinessObject( (PersistableBusinessObject)businessObject ); | 
  | 112 | 0 |          } else { | 
  | 113 | 0 |              throw new RuntimeException( "Configuration ERROR: ReviewResponsibilityBoMaintainable passed an unsupported object type: " + businessObject.getClass() ); | 
  | 114 |  |          } | 
  | 115 | 0 |          super.prepareBusinessObject(businessObject); | 
  | 116 | 0 |          } | 
  | 117 |  |           | 
  | 118 |  |  } |