| 1 |  |   | 
  | 2 |  |   | 
  | 3 |  |   | 
  | 4 |  |   | 
  | 5 |  |   | 
  | 6 |  |   | 
  | 7 |  |   | 
  | 8 |  |   | 
  | 9 |  |   | 
  | 10 |  |   | 
  | 11 |  |   | 
  | 12 |  |   | 
  | 13 |  |   | 
  | 14 |  |   | 
  | 15 |  |   | 
  | 16 |  |  package org.kuali.rice.devtools.generators.dd; | 
  | 17 |  |   | 
  | 18 |  |  import org.apache.commons.beanutils.PropertyUtils; | 
  | 19 |  |  import org.kuali.rice.krad.bo.BusinessObject; | 
  | 20 |  |   | 
  | 21 |  |  import java.beans.PropertyDescriptor; | 
  | 22 |  |   | 
  | 23 |  |   | 
  | 24 |  |   | 
  | 25 |  |   | 
  | 26 |  |  @Deprecated | 
  | 27 | 0 |  public class MaintDocDDCreator { | 
  | 28 |  |   | 
  | 29 |  |      public static void main( String[] args ) throws Exception { | 
  | 30 | 0 |          String className = args[0]; | 
  | 31 | 0 |          Class boClass = Class.forName( className ); | 
  | 32 | 0 |          PropertyDescriptor[] props = PropertyUtils.getPropertyDescriptors( boClass ); | 
  | 33 |  |   | 
  | 34 | 0 |          StringBuffer sb = new StringBuffer( 4000 ); | 
  | 35 | 0 |          sb.append( "<beans xmlns=\"http://www.springframework.org/schema/beans\"\r\n" +  | 
  | 36 |  |                  "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" +  | 
  | 37 |  |                  "    xmlns:p=\"http://www.springframework.org/schema/p\"\r\n" +  | 
  | 38 |  |                  "    xsi:schemaLocation=\"http://www.springframework.org/schema/beans\r\n" +  | 
  | 39 |  |                  "        http://www.springframework.org/schema/beans/spring-beans-2.0.xsd\">\r\n" +  | 
  | 40 |  |                  "\r\n" +  | 
  | 41 |  |                  "  <bean id=\"" ); | 
  | 42 | 0 |          sb.append( boClass.getSimpleName() ); | 
  | 43 | 0 |          sb.append( "MaintenanceDocument\" parent=\"" ); | 
  | 44 | 0 |          sb.append( boClass.getSimpleName() ); | 
  | 45 | 0 |          sb.append( "MaintenanceDocument-parentBean\" />\r\n" +  | 
  | 46 |  |                  "\r\n" +  | 
  | 47 |  |                  "  <bean id=\"" ); | 
  | 48 | 0 |          sb.append( boClass.getSimpleName() ); | 
  | 49 | 0 |          sb.append( "MaintenanceDocument-parentBean\" abstract=\"true\" parent=\"MaintenanceDocumentEntry\"\r\n" +  | 
  | 50 |  |                  "        p:businessObjectClass=\"" ); | 
  | 51 | 0 |          sb.append( boClass.getName() ); | 
  | 52 | 0 |          sb.append( "\"\r\n" ); | 
  | 53 | 0 |          sb.append( "        p:maintainableClass=\"" );  | 
  | 54 | 0 |          sb.append( "org.kuali.core.maintenance.KualiMaintainableImpl" ); | 
  | 55 | 0 |          sb.append( "\"\r\n" ); | 
  | 56 | 0 |          sb.append( "        p:label=\"" );  | 
  | 57 | 0 |          sb.append( BeanDDCreator.camelCaseToString( boClass.getSimpleName() ) ); | 
  | 58 | 0 |          sb.append( " Maintenance Document\"\r\n" ); | 
  | 59 | 0 |          sb.append( "        p:shortLabel=\"" );  | 
  | 60 | 0 |          sb.append( BeanDDCreator.camelCaseToString( boClass.getSimpleName() ) ); | 
  | 61 | 0 |          sb.append( " Maint. Doc.\"\r\n" ); | 
  | 62 | 0 |          sb.append( "        p:documentTypeName=\"" );  | 
  | 63 | 0 |          sb.append( boClass.getSimpleName() + "MaintenanceDocument" ); | 
  | 64 | 0 |          sb.append( "\"\r\n" ); | 
  | 65 | 0 |          sb.append( "        p:documentTypeCode=\"" );  | 
  | 66 | 0 |          sb.append( "FILLMEIN" ); | 
  | 67 | 0 |          sb.append( "\"\r\n" ); | 
  | 68 | 0 |          sb.append( "        p:businessRulesClass=\"" );  | 
  | 69 | 0 |          sb.append( "org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase" ); | 
  | 70 | 0 |          sb.append( "\"\r\n" ); | 
  | 71 | 0 |          sb.append( "        p:preRulesCheckClass=\"" );  | 
  | 72 | 0 |          sb.append( "FILLMEIN" ); | 
  | 73 | 0 |          sb.append( "\"\r\n" ); | 
  | 74 | 0 |          sb.append( "        p:documentAuthorizerClass=\"" );  | 
  | 75 | 0 |          sb.append( "org.kuali.kfs.sys.document.authorization.FinancialSystemMaintenanceDocumentAuthorizerBase" ); | 
  | 76 | 0 |          sb.append( "\"\r\n" ); | 
  | 77 | 0 |          sb.append( "        p:workflowProperties-ref=\"" );  | 
  | 78 | 0 |          sb.append( boClass.getSimpleName() ); | 
  | 79 | 0 |          sb.append( "MaintenanceDocument-workflowProperties\" >\r\n" ); | 
  | 80 | 0 |          sb.append( "\r\n" ); | 
  | 81 |  |   | 
  | 82 | 0 |          sb.append( "    <property name=\"authorizations\" >\r\n" +  | 
  | 83 |  |                          "      <list>\r\n" +  | 
  | 84 |  |                          "        <bean parent=\"AuthorizationDefinition\">\r\n" +  | 
  | 85 |  |                          "          <property name=\"action\" value=\"initiate\" />\r\n" +  | 
  | 86 |  |                          "          <property name=\"authorizedGroups\" >\r\n" +  | 
  | 87 |  |                          "            <set>\r\n" +  | 
  | 88 |  |                          "              <value>SY_MAINTENANCE_USERS</value>\r\n" +  | 
  | 89 |  |                          "            </set>\r\n" +  | 
  | 90 |  |                          "          </property>\r\n" +  | 
  | 91 |  |                          "        </bean>\r\n" +  | 
  | 92 |  |                          "      </list>\r\n" +  | 
  | 93 |  |                          "    </property>\r\n" +  | 
  | 94 |  |                          "" ); | 
  | 95 | 0 |          sb.append( "    <property name=\"lockingKeys\" >\r\n" +  | 
  | 96 |  |                          "      <list>\r\n" +  | 
  | 97 |  |                          "        <value>FILLMEIN</value>\r\n" +  | 
  | 98 |  |                          "      </list>\r\n" +  | 
  | 99 |  |                          "    </property>\r\n" +  | 
  | 100 |  |                          ""); | 
  | 101 | 0 |          sb.append( "    <property name=\"helpDefinition\" >\r\n" +  | 
  | 102 |  |                          "      <bean parent=\"HelpDefinition\" p:parameterClass=\"" ); | 
  | 103 | 0 |          sb.append( boClass.getName() ); | 
  | 104 | 0 |          sb.append( "\" p:parameterName=\"" ); | 
  | 105 | 0 |          sb.append( camelCaseToHelpParm( boClass.getSimpleName() ) ); | 
  | 106 | 0 |          sb.append( "\" />\r\n" +  | 
  | 107 |  |                          "    </property>\r\n" +  | 
  | 108 |  |                          "" ); | 
  | 109 | 0 |          sb.append( "    <property name=\"defaultExistenceChecks\" >\r\n" +  | 
  | 110 |  |                          "      <list>\r\n" +  | 
  | 111 |  |                          "" ); | 
  | 112 | 0 |          for ( PropertyDescriptor pd : props ) { | 
  | 113 | 0 |              if ( isReferenceBoProperty(pd)) { | 
  | 114 | 0 |                  sb.append( "        <bean parent=\"ReferenceDefinition\"\r\n" +  | 
  | 115 |  |                                  "              p:attributeName=\"" ); | 
  | 116 | 0 |                  sb.append( pd.getName() ); | 
  | 117 | 0 |                  sb.append( "\"\r\n" +  | 
  | 118 |  |                                  "              p:activeIndicatorAttributeName=\"active\"\r\n" +  | 
  | 119 |  |                                  "              p:attributeToHighlightOnFail=\"FILLMEIN\" />\r\n" +  | 
  | 120 |  |                                  "" ); | 
  | 121 |  |              } | 
  | 122 |  |          } | 
  | 123 | 0 |          sb.append( "      </list>\r\n" +  | 
  | 124 |  |                          "    </property>\r\n" +  | 
  | 125 |  |                          "" ); | 
  | 126 |  |           | 
  | 127 | 0 |          sb.append( "    <property name=\"maintainableSections\" >\r\n" +  | 
  | 128 |  |                          "      <list>\r\n" +  | 
  | 129 |  |                          "        <ref bean=\"" ); | 
  | 130 | 0 |          sb.append( boClass.getSimpleName() ); | 
  | 131 | 0 |          sb.append( "MaintenanceDocument-MainSection\" />\r\n" +  | 
  | 132 |  |                          "      </list>\r\n" +  | 
  | 133 |  |                          "    </property>\r\n" +  | 
  | 134 |  |                          "  </bean>\r\n\r\n"); | 
  | 135 |  |           | 
  | 136 | 0 |          sb.append( "  <bean id=\"" ); | 
  | 137 | 0 |          sb.append( boClass.getSimpleName() ); | 
  | 138 | 0 |          sb.append( "MaintenanceDocument-MainSection\" parent=\"" ); | 
  | 139 | 0 |          sb.append( boClass.getSimpleName() ); | 
  | 140 | 0 |          sb.append( "MaintenanceDocument-MainSection-parentBean\" />\r\n" +  | 
  | 141 |  |                  "\r\n" +  | 
  | 142 |  |                  "  <bean id=\"" ); | 
  | 143 | 0 |          sb.append( boClass.getSimpleName() ); | 
  | 144 | 0 |          sb.append( "MaintenanceDocument-MainSection-parentBean\" abstract=\"true\" parent=\"MaintainableSectionDefinition\"\r\n" +  | 
  | 145 |  |                  "        p:title=\"" ); | 
  | 146 | 0 |          sb.append( BeanDDCreator.camelCaseToString( boClass.getSimpleName() ) ); | 
  | 147 | 0 |          sb.append( " Maintenance\" >\r\n" + | 
  | 148 |  |                          "    <property name=\"maintainableItems\" >\r\n" +  | 
  | 149 |  |                          "      <list>\r\n" +  | 
  | 150 |  |                          "" ); | 
  | 151 | 0 |          for ( PropertyDescriptor pd : props ) { | 
  | 152 | 0 |              if ( BeanDDCreator.isNormalProperty(pd) && !pd.getName().endsWith("codeAndDescription" ) ) { | 
  | 153 |  |                   | 
  | 154 | 0 |                  sb.append( "        <bean parent=\"MaintainableFieldDefinition\"\r\n" +  | 
  | 155 |  |                                  "              p:name=\"" ); | 
  | 156 | 0 |                  sb.append( pd.getName() ); | 
  | 157 | 0 |                  if ( pd.getName().endsWith("active" ) ) { | 
  | 158 | 0 |                      sb.append( "\"\r\n" +  | 
  | 159 |  |                              "              p:defaultValue=\"true\" />\r\n" ); | 
  | 160 | 0 |                  } else if ( pd.getName().equals("versionNumber" ) ) { | 
  | 161 | 0 |                      sb.append( "\" />\r\n" ); | 
  | 162 |  |                  } else { | 
  | 163 | 0 |                      sb.append( "\"\r\n" +  | 
  | 164 |  |                      "              p:required=\"true\" />\r\n" ); | 
  | 165 |  |                  } | 
  | 166 |  |              } | 
  | 167 |  |          } | 
  | 168 | 0 |          sb.append( "      </list>\r\n" +  | 
  | 169 |  |                          "    </property>\r\n" +  | 
  | 170 |  |                          "  </bean>\r\n" +  | 
  | 171 |  |                          "" ); | 
  | 172 | 0 |          sb.append( "  <bean id=\"" ); | 
  | 173 | 0 |          sb.append( boClass.getSimpleName() ); | 
  | 174 | 0 |          sb.append( "MaintenanceDocument-workflowProperties\" parent=\"" ); | 
  | 175 | 0 |          sb.append( boClass.getSimpleName() ); | 
  | 176 | 0 |          sb.append( "MaintenanceDocument-workflowProperties-parentBean\" />\r\n" +  | 
  | 177 |  |                          "\r\n" +  | 
  | 178 |  |                          "  <bean id=\"" ); | 
  | 179 | 0 |          sb.append( boClass.getSimpleName() ); | 
  | 180 | 0 |          sb.append( "MaintenanceDocument-workflowProperties-parentBean\" abstract=\"true\" parent=\"CommonWorkflow-MaintenanceDocument\" />\r\n" +  | 
  | 181 |  |   | 
  | 182 |  |   | 
  | 183 |  |   | 
  | 184 |  |   | 
  | 185 |  |   | 
  | 186 |  |   | 
  | 187 |  |   | 
  | 188 |  |   | 
  | 189 |  |   | 
  | 190 |  |   | 
  | 191 |  |   | 
  | 192 |  |   | 
  | 193 |  |   | 
  | 194 |  |                          "</beans>" ); | 
  | 195 | 0 |          System.out.println( sb.toString() ); | 
  | 196 | 0 |      } | 
  | 197 |  |       | 
  | 198 |  |      public static String camelCaseToHelpParm( String className ) { | 
  | 199 | 0 |          StringBuffer newName = new StringBuffer( className ); | 
  | 200 |  |           | 
  | 201 | 0 |          newName.replace(0, 1, newName.substring(0, 1).toLowerCase()); | 
  | 202 |  |           | 
  | 203 | 0 |          for ( int i = 0; i < newName.length(); i++ ) { | 
  | 204 | 0 |              if ( Character.isUpperCase(newName.charAt(i)) ) { | 
  | 205 | 0 |                  newName.insert(i, '_'); | 
  | 206 | 0 |                  i++; | 
  | 207 |  |              } | 
  | 208 |  |          } | 
  | 209 | 0 |          return newName.toString().toUpperCase().trim(); | 
  | 210 |  |      } | 
  | 211 |  |       | 
  | 212 |  |      public static boolean isReferenceBoProperty( PropertyDescriptor p ) { | 
  | 213 | 0 |          return p.getPropertyType()!= null  | 
  | 214 |  |                  && BusinessObject.class.isAssignableFrom( p.getPropertyType() ) | 
  | 215 |  |                  && !p.getName().startsWith( "boNote" ) | 
  | 216 |  |                  && !p.getName().startsWith( "extension" ) | 
  | 217 |  |                  && !p.getName().equals( "newCollectionRecord" ); | 
  | 218 |  |      } | 
  | 219 |  |       | 
  | 220 |  |  } |