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 public class MaintDocDDCreator {
28
29 public static void main( String[] args ) throws Exception {
30 String className = args[0];
31 Class boClass = Class.forName( className );
32 PropertyDescriptor[] props = PropertyUtils.getPropertyDescriptors( boClass );
33
34 StringBuffer sb = new StringBuffer( 4000 );
35 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 sb.append( boClass.getSimpleName() );
43 sb.append( "MaintenanceDocument\" parent=\"" );
44 sb.append( boClass.getSimpleName() );
45 sb.append( "MaintenanceDocument-parentBean\" />\r\n" +
46 "\r\n" +
47 " <bean id=\"" );
48 sb.append( boClass.getSimpleName() );
49 sb.append( "MaintenanceDocument-parentBean\" abstract=\"true\" parent=\"MaintenanceDocumentEntry\"\r\n" +
50 " p:businessObjectClass=\"" );
51 sb.append( boClass.getName() );
52 sb.append( "\"\r\n" );
53 sb.append( " p:maintainableClass=\"" );
54 sb.append( "org.kuali.core.maintenance.KualiMaintainableImpl" );
55 sb.append( "\"\r\n" );
56 sb.append( " p:label=\"" );
57 sb.append( BeanDDCreator.camelCaseToString( boClass.getSimpleName() ) );
58 sb.append( " Maintenance Document\"\r\n" );
59 sb.append( " p:shortLabel=\"" );
60 sb.append( BeanDDCreator.camelCaseToString( boClass.getSimpleName() ) );
61 sb.append( " Maint. Doc.\"\r\n" );
62 sb.append( " p:documentTypeName=\"" );
63 sb.append( boClass.getSimpleName() + "MaintenanceDocument" );
64 sb.append( "\"\r\n" );
65 sb.append( " p:documentTypeCode=\"" );
66 sb.append( "FILLMEIN" );
67 sb.append( "\"\r\n" );
68 sb.append( " p:businessRulesClass=\"" );
69 sb.append( "org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase" );
70 sb.append( "\"\r\n" );
71 sb.append( " p:preRulesCheckClass=\"" );
72 sb.append( "FILLMEIN" );
73 sb.append( "\"\r\n" );
74 sb.append( " p:documentAuthorizerClass=\"" );
75 sb.append( "org.kuali.kfs.sys.document.authorization.FinancialSystemMaintenanceDocumentAuthorizerBase" );
76 sb.append( "\"\r\n" );
77 sb.append( " p:workflowProperties-ref=\"" );
78 sb.append( boClass.getSimpleName() );
79 sb.append( "MaintenanceDocument-workflowProperties\" >\r\n" );
80 sb.append( "\r\n" );
81
82 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 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 sb.append( " <property name=\"helpDefinition\" >\r\n" +
102 " <bean parent=\"HelpDefinition\" p:parameterClass=\"" );
103 sb.append( boClass.getName() );
104 sb.append( "\" p:parameterName=\"" );
105 sb.append( camelCaseToHelpParm( boClass.getSimpleName() ) );
106 sb.append( "\" />\r\n" +
107 " </property>\r\n" +
108 "" );
109 sb.append( " <property name=\"defaultExistenceChecks\" >\r\n" +
110 " <list>\r\n" +
111 "" );
112 for ( PropertyDescriptor pd : props ) {
113 if ( isReferenceBoProperty(pd)) {
114 sb.append( " <bean parent=\"ReferenceDefinition\"\r\n" +
115 " p:attributeName=\"" );
116 sb.append( pd.getName() );
117 sb.append( "\"\r\n" +
118 " p:activeIndicatorAttributeName=\"active\"\r\n" +
119 " p:attributeToHighlightOnFail=\"FILLMEIN\" />\r\n" +
120 "" );
121 }
122 }
123 sb.append( " </list>\r\n" +
124 " </property>\r\n" +
125 "" );
126
127 sb.append( " <property name=\"maintainableSections\" >\r\n" +
128 " <list>\r\n" +
129 " <ref bean=\"" );
130 sb.append( boClass.getSimpleName() );
131 sb.append( "MaintenanceDocument-MainSection\" />\r\n" +
132 " </list>\r\n" +
133 " </property>\r\n" +
134 " </bean>\r\n\r\n");
135
136 sb.append( " <bean id=\"" );
137 sb.append( boClass.getSimpleName() );
138 sb.append( "MaintenanceDocument-MainSection\" parent=\"" );
139 sb.append( boClass.getSimpleName() );
140 sb.append( "MaintenanceDocument-MainSection-parentBean\" />\r\n" +
141 "\r\n" +
142 " <bean id=\"" );
143 sb.append( boClass.getSimpleName() );
144 sb.append( "MaintenanceDocument-MainSection-parentBean\" abstract=\"true\" parent=\"MaintainableSectionDefinition\"\r\n" +
145 " p:title=\"" );
146 sb.append( BeanDDCreator.camelCaseToString( boClass.getSimpleName() ) );
147 sb.append( " Maintenance\" >\r\n" +
148 " <property name=\"maintainableItems\" >\r\n" +
149 " <list>\r\n" +
150 "" );
151 for ( PropertyDescriptor pd : props ) {
152 if ( BeanDDCreator.isNormalProperty(pd) && !pd.getName().endsWith("codeAndDescription" ) ) {
153
154 sb.append( " <bean parent=\"MaintainableFieldDefinition\"\r\n" +
155 " p:name=\"" );
156 sb.append( pd.getName() );
157 if ( pd.getName().endsWith("active" ) ) {
158 sb.append( "\"\r\n" +
159 " p:defaultValue=\"true\" />\r\n" );
160 } else if ( pd.getName().equals("versionNumber" ) ) {
161 sb.append( "\" />\r\n" );
162 } else {
163 sb.append( "\"\r\n" +
164 " p:required=\"true\" />\r\n" );
165 }
166 }
167 }
168 sb.append( " </list>\r\n" +
169 " </property>\r\n" +
170 " </bean>\r\n" +
171 "" );
172 sb.append( " <bean id=\"" );
173 sb.append( boClass.getSimpleName() );
174 sb.append( "MaintenanceDocument-workflowProperties\" parent=\"" );
175 sb.append( boClass.getSimpleName() );
176 sb.append( "MaintenanceDocument-workflowProperties-parentBean\" />\r\n" +
177 "\r\n" +
178 " <bean id=\"" );
179 sb.append( boClass.getSimpleName() );
180 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 System.out.println( sb.toString() );
196 }
197
198 public static String camelCaseToHelpParm( String className ) {
199 StringBuffer newName = new StringBuffer( className );
200
201 newName.replace(0, 1, newName.substring(0, 1).toLowerCase());
202
203 for ( int i = 0; i < newName.length(); i++ ) {
204 if ( Character.isUpperCase(newName.charAt(i)) ) {
205 newName.insert(i, '_');
206 i++;
207 }
208 }
209 return newName.toString().toUpperCase().trim();
210 }
211
212 public static boolean isReferenceBoProperty( PropertyDescriptor p ) {
213 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 }