View Javadoc

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