001    /**
002     * Copyright 2004-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.student.remote.impl.mojo;
017    
018    import java.util.ArrayList;
019    import java.util.HashMap;
020    import java.util.List;
021    import java.util.Map;
022    
023    import org.apache.maven.plugin.MojoExecutionException;
024    import org.apache.maven.plugin.MojoFailureException;
025    import org.apache.maven.project.MavenProject;
026    import org.kuali.student.common.mojo.AbstractKSMojo;
027    import org.kuali.student.contract.model.ServiceContractModel;
028    import org.kuali.student.contract.model.impl.ServiceContractModelPescXsdLoader;
029    import org.kuali.student.contract.model.util.ServicesFilterByKeys;
030    import org.slf4j.Logger;
031    import org.slf4j.LoggerFactory;
032    
033    /**
034     *
035     * @author nwright
036     *
037     * @goal kscreateremoteimpl
038     * @phase none
039     * @requiresProject true
040     */
041    public class KSCreateRemoteImplMojo extends AbstractKSMojo {
042        
043        private static Logger log = LoggerFactory.getLogger(KSCreateRemoteImplMojo.class);
044    
045        public KSCreateRemoteImplMojo() {
046        }
047        public String targetDir;
048    
049        public String getTargetDir() {
050            return targetDir;
051        }
052    
053        public void setTargetDir(String targetDir) {
054            this.targetDir = targetDir;
055        }
056    
057        @Override
058        public void execute() throws MojoExecutionException, MojoFailureException {
059    
060            ServiceContractModel model = getModel();
061            validate(model);
062            if (targetDir == null) {
063                String targetDir = "target/generated-sources/remote-impl";
064            }
065            List<String> servKeys = new ArrayList<String>();
066            servKeys.add("AcademicCalendar");
067    //        servKeys.add("AcademicRecord");
068            servKeys.add("Appointment");
069    //        servKeys.add("Atp");
070    //        servKeys.add("BatchJobResult");
071            servKeys.add("Clu");
072            servKeys.add("Comment");
073            servKeys.add("CourseOffering");
074            servKeys.add("CourseOfferingSet");
075    //        servKeys.add("CourseRegistration");
076            servKeys.add("Course");
077    //        servKeys.add("CourseWaitlist");
078    //        servKeys.add("DataDictionary");
079            servKeys.add("Document");
080            servKeys.add("EnumerationManagement");
081            servKeys.add("Exemption");
082    //        servKeys.add("Fee");
083    //        servKeys.add("Grading");
084            servKeys.add("Hold");
085    //        servKeys.add("LRC");
086            servKeys.add("LearningObjective");
087    //        servKeys.add("LearningResultRecord");
088    //        servKeys.add("LprRoster");
089            servKeys.add("Lpr");
090            servKeys.add("Lui");
091            servKeys.add("Message");
092            servKeys.add("Organization");
093            servKeys.add("Population");
094            servKeys.add("Process");
095            servKeys.add("Program");
096            servKeys.add("Proposal");
097            servKeys.add("Room");
098            servKeys.add("Scheduling");
099    //        servKeys.add("Search");
100    //        servKeys.add("State");
101    //        servKeys.add("Statement");
102    //        servKeys.add("Type");
103    //        servKeys.add("VersionManagement");
104    
105    //        servKeys.add("Atp");
106    //        servKeys.add("Type");
107    //        servKeys.add("State");
108    //        servKeys.add("LRC");
109    //        servKeys.add("RICE.Permission");
110    //        servKeys.add("RICE.Role");
111            ServicesFilterByKeys filter = new ServicesFilterByKeys(servKeys);
112            RemoteImplWriter instance =
113                    new RemoteImplWriter(model,
114                    targetDir,
115                    RemoteImplWriter.DEFAULT_ROOT_PACKAGE,
116                    // TODO: inject filters as part of the Mojo parameters
117                    filter);
118            instance.write();
119    
120        }
121        private static final String CORE_DIRECTORY = "D:/svn/ks/trunk/ks-api/ks-core-api/src/main";
122        // "C:/svn/maven-dictionary-generator/trunk/src/main/java/org/kuali/student/core";
123        private static final String COMMON_DIRECTORY = "D:/svn/ks/trunk/ks-api/ks-common-api/src/main/java";
124        private static final String ENROLL_DIRECTORY = "D:/svn/ks/trunk/ks-api/ks-enroll-api/src/main/java";
125        private static final String LUM_DIRECTORY = "D:/svn/ks/trunk/ks-api/ks-lum-api/src/main/java";
126        private static final String RICE_CORE_API_DIRECTORY = "D:/svn/rice/rice-2.2.0-M3/core/api/src/main/java";
127        private static final String RICE_KIM_API_DIRECTORY = "D:/svn/rice/rice-2.2.0-M3/kim/kim-api/src/main/java";
128        private static final String TEST_SOURCE_DIRECTORY =
129                "src/test/java/org/kuali/student/contract/model/test/source";
130        private static final String TARGET_GENERATED_SOURCES = "target/generated-sources";
131        private static final String STANDALONE_DIRECTORY = "D:/svn/ks/ks-standalone-admin-app/src";
132    
133        public static void main(String[] args) {
134            log.info("execute");
135            List<String> srcDirs = new ArrayList<String>();
136            srcDirs.add(COMMON_DIRECTORY);
137            srcDirs.add(CORE_DIRECTORY);
138            srcDirs.add(LUM_DIRECTORY);
139            srcDirs.add(ENROLL_DIRECTORY);
140            srcDirs.add(RICE_KIM_API_DIRECTORY);
141    //        srcDirs.add(RICE_CORE_API_DIRECTORY);
142            KSCreateRemoteImplMojo instance = new KSCreateRemoteImplMojo();
143            Map pluginContext = new HashMap();
144            MavenProject project = new MavenProject();
145            pluginContext.put("project", project);
146            instance.setPluginContext(pluginContext);
147            instance.setSourceDirs(srcDirs);
148            instance.setTargetDir(STANDALONE_DIRECTORY);
149            try {
150                instance.execute();
151            } catch (MojoExecutionException ex) {
152                throw new RuntimeException(ex);
153            } catch (MojoFailureException ex) {
154                throw new RuntimeException(ex);
155            }
156        }
157    }