001    /**
002     * Copyright 2005-2014 The Kuali Foundation
003     *
004     * Licensed under the Educational Community License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     * http://www.opensource.org/licenses/ecl2.php
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package org.kuali.rice.devtools.generators.dd;
017    
018    import org.apache.commons.beanutils.PropertyUtils;
019    import org.kuali.rice.krad.bo.BusinessObject;
020    
021    import java.beans.PropertyDescriptor;
022    
023    /**
024     * @deprecated this is for the legacy kns.
025     */
026    @Deprecated
027    public class MaintDocDDCreator {
028    
029        public static void main( String[] args ) throws Exception {
030            String className = args[0];
031            Class boClass = Class.forName( className );
032            PropertyDescriptor[] props = PropertyUtils.getPropertyDescriptors( boClass );
033    
034            StringBuffer sb = new StringBuffer( 4000 );
035            sb.append( "<beans xmlns=\"http://www.springframework.org/schema/beans\"\r\n" + 
036                    "    xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\r\n" + 
037                    "    xmlns:p=\"http://www.springframework.org/schema/p\"\r\n" + 
038                    "    xsi:schemaLocation=\"http://www.springframework.org/schema/beans\r\n" + 
039                    "        http://www.springframework.org/schema/beans/spring-beans-2.0.xsd\">\r\n" + 
040                    "\r\n" + 
041                    "  <bean id=\"" );
042            sb.append( boClass.getSimpleName() );
043            sb.append( "MaintenanceDocument\" parent=\"" );
044            sb.append( boClass.getSimpleName() );
045            sb.append( "MaintenanceDocument-parentBean\" />\r\n" + 
046                    "\r\n" + 
047                    "  <bean id=\"" );
048            sb.append( boClass.getSimpleName() );
049            sb.append( "MaintenanceDocument-parentBean\" abstract=\"true\" parent=\"MaintenanceDocumentEntry\"\r\n" + 
050                    "        p:businessObjectClass=\"" );
051            sb.append( boClass.getName() );
052            sb.append( "\"\r\n" );
053            sb.append( "        p:maintainableClass=\"" ); 
054            sb.append( "org.kuali.core.maintenance.KualiMaintainableImpl" );
055            sb.append( "\"\r\n" );
056            sb.append( "        p:label=\"" ); 
057            sb.append( BeanDDCreator.camelCaseToString( boClass.getSimpleName() ) );
058            sb.append( " Maintenance Document\"\r\n" );
059            sb.append( "        p:shortLabel=\"" ); 
060            sb.append( BeanDDCreator.camelCaseToString( boClass.getSimpleName() ) );
061            sb.append( " Maint. Doc.\"\r\n" );
062            sb.append( "        p:documentTypeName=\"" ); 
063            sb.append( boClass.getSimpleName() + "MaintenanceDocument" );
064            sb.append( "\"\r\n" );
065            sb.append( "        p:documentTypeCode=\"" ); 
066            sb.append( "FILLMEIN" );
067            sb.append( "\"\r\n" );
068            sb.append( "        p:businessRulesClass=\"" ); 
069            sb.append( "org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase" );
070            sb.append( "\"\r\n" );
071            sb.append( "        p:preRulesCheckClass=\"" ); 
072            sb.append( "FILLMEIN" );
073            sb.append( "\"\r\n" );
074            sb.append( "        p:documentAuthorizerClass=\"" ); 
075            sb.append( "org.kuali.kfs.sys.document.authorization.FinancialSystemMaintenanceDocumentAuthorizerBase" );
076            sb.append( "\"\r\n" );
077            sb.append( "        p:workflowProperties-ref=\"" ); 
078            sb.append( boClass.getSimpleName() );
079            sb.append( "MaintenanceDocument-workflowProperties\" >\r\n" );
080            sb.append( "\r\n" );
081    
082            sb.append( "    <property name=\"authorizations\" >\r\n" + 
083                            "      <list>\r\n" + 
084                            "        <bean parent=\"AuthorizationDefinition\">\r\n" + 
085                            "          <property name=\"action\" value=\"initiate\" />\r\n" + 
086                            "          <property name=\"authorizedGroups\" >\r\n" + 
087                            "            <set>\r\n" + 
088                            "              <value>SY_MAINTENANCE_USERS</value>\r\n" + 
089                            "            </set>\r\n" + 
090                            "          </property>\r\n" + 
091                            "        </bean>\r\n" + 
092                            "      </list>\r\n" + 
093                            "    </property>\r\n" + 
094                            "" );
095            sb.append( "    <property name=\"lockingKeys\" >\r\n" + 
096                            "      <list>\r\n" + 
097                            "        <value>FILLMEIN</value>\r\n" + 
098                            "      </list>\r\n" + 
099                            "    </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    //                      "    <property name=\"workflowPropertyGroups\" >\r\n" + 
182    //                      "      <list>\r\n" + 
183    //                      "        <bean parent=\"WorkflowPropertyGroup\">\r\n" + 
184    //                      "          <property name=\"workflowProperties\" >\r\n" + 
185    //                      "            <list>\r\n" + 
186    //                      "              <bean parent=\"WorkflowProperty\" p:path=\"newMaintainableObject.businessObject\" />\r\n" + 
187    //                      "              <bean parent=\"WorkflowProperty\" p:path=\"oldMaintainableObject.businessObject\" />\r\n" + 
188    //                      "            </list>\r\n" + 
189    //                      "          </property>\r\n" + 
190    //                      "        </bean>\r\n" + 
191    //                      "      </list>\r\n" + 
192    //                      "    </property>\r\n" + 
193    //                      "  </bean>\r\n" + 
194                            "</beans>" );
195            System.out.println( sb.toString() );
196        }
197        
198        public static String camelCaseToHelpParm( String className ) {
199            StringBuffer newName = new StringBuffer( className );
200            // lower case the 1st letter
201            newName.replace(0, 1, newName.substring(0, 1).toLowerCase());
202            // loop through, inserting spaces when cap
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    }