@Override public void generate(Model model, MolgenisOptions options) throws Exception { if (options.generate_tests) { } else { Template template = this.createTemplate(this.getClass().getSimpleName() + getExtension() + ".ftl"); Map<String, Object> templateArgs = createTemplateArguments(options); // apply generator to each entity for (Entity entity : model.getEntities()) { // calculate package from its own package String packageName = entity.getNamespace().toLowerCase() + this.getClass() .getPackage() .toString() .substring(Generator.class.getPackage().toString().length()); File targetDir = new File( (this.getSourcePath(options).endsWith("/") ? this.getSourcePath(options) : this.getSourcePath(options) + "/") + packageName.replace(".", "/").replace("/cpp", "")); try { File targetFile = new File( targetDir + "/" + GeneratorHelper.getJavaName(entity.getName()) + getExtension()); boolean created = targetDir.mkdirs(); if (!created && !targetDir.exists()) { throw new IOException("could not create " + targetDir); } // logger.debug("trying to generated "+targetFile); templateArgs.put("entity", entity); templateArgs.put("model", model); templateArgs.put("db_driver", options.db_driver); templateArgs.put("template", template.getName()); templateArgs.put( "file", targetDir.getCanonicalPath().replace("\\", "/") + "/" + GeneratorHelper.firstToUpper(entity.getName()) + getType() + getExtension()); templateArgs.put("package", packageName); OutputStream targetOut = new FileOutputStream(targetFile); template.process( templateArgs, new OutputStreamWriter(targetOut, Charset.forName("UTF-8"))); targetOut.close(); logger.info("generated " + targetFile); } catch (Exception e) { logger.error("problem generating for " + entity.getName()); throw e; } } } }
@Override public void generate(Model model, MolgenisOptions options) throws Exception { Template template = createTemplate("/" + this.getClass().getSimpleName() + ".java.ftl"); Map<String, Object> templateArgs = createTemplateArguments(options); List<Entity> entityList = model.getEntities(); entityList = MolgenisModel.sortEntitiesByDependency(entityList, model); // side // effect? File target = new File(this.getSourcePath(options) + "/test/TestDataSet.java"); boolean created = target.getParentFile().mkdirs(); if (!created && !target.getParentFile().exists()) { throw new IOException("could not create " + target.getParentFile()); } String packageName = "test"; templateArgs.put( "databaseImp", options.mapper_implementation.equals(MolgenisOptions.MapperImplementation.JPA) ? "jpa" : "jdbc"); templateArgs.put("model", model); templateArgs.put("entities", entityList); templateArgs.put("package", packageName); OutputStream targetOut = new FileOutputStream(target); template.process(templateArgs, new OutputStreamWriter(targetOut, Charset.forName("UTF-8"))); targetOut.close(); logger.info("generated " + target); }
public void generate(Model model, MolgenisOptions options, boolean wait) throws Exception { Template template = createTemplate("/" + getClass().getSimpleName() + ".java.ftl"); Map<String, Object> templateArgs = createTemplateArguments(options); File target = new File(this.getDocumentationPath(options) + "/module-dependency-diagram.dot"); boolean created = target.getParentFile().mkdirs(); if (!created && !target.getParentFile().exists()) { throw new IOException("could not create " + target.getParentFile()); } // count the relationships Map<String, Integer> mapOfRelations = new LinkedHashMap<String, Integer>(); for (Entity e : model.getEntities()) { if (e.getModel() != null) { // interface if (e.hasImplements()) { for (Entity i : e.getImplements()) { if (i.getModule() != null) { addRule(mapOfRelations, e, i); } } } // superclass if (e.hasAncestor()) { addRule(mapOfRelations, e, e.getAncestor()); } // xrefs/mrefs for (Field f : e.getFields()) { if (f.getType() instanceof XrefField || f.getType() instanceof MrefField) { addRule(mapOfRelations, e, f.getXrefEntity()); } } } } templateArgs.put("rules", mapOfRelations); apply(templateArgs, template, target); logger.info("generated " + target); executeDot(target, "png", wait); }
@Override public void generate(Model model, MolgenisOptions options) throws Exception { Template template = createTemplate("/" + getClass().getSimpleName() + ".java.ftl"); Map<String, Object> templateArgs = createTemplateArguments(options); File target = new File(this.getDocumentationPath(options) + "/entitymodel.html"); target.getParentFile().mkdirs(); List<Entity> entityList = model.getEntities(); List<Module> moduleList = model.getModules(); entityList = MolgenisModel.sortEntitiesByDependency(entityList, model); // side effect? templateArgs.put("model", model); templateArgs.put("entities", entityList); templateArgs.put("modules", moduleList); OutputStream targetOut = new FileOutputStream(target); template.process(templateArgs, new OutputStreamWriter(targetOut)); targetOut.close(); logger.info("generated " + target); }
@Override public void generate(Model model, MolgenisOptions options) throws Exception { Template template = createTemplate("/" + this.getClass().getSimpleName() + ".java.ftl"); Map<String, Object> templateArgs = createTemplateArguments(options); List<Entity> entityList = model.getEntities(); entityList = MolgenisModel.sortEntitiesByDependency(entityList, model); // side effect? // String packageName = // this.getClass().getPackage().toString().substring(Generator.class.getPackage().toString().length()); File target = new File(this.getSourcePath(options) + APP_DIR + "/ExcelImport.java"); target.getParentFile().mkdirs(); templateArgs.put("model", model); templateArgs.put("entities", entityList); templateArgs.put("package", APP_DIR); OutputStream targetOut = new FileOutputStream(target); template.process(templateArgs, new OutputStreamWriter(targetOut)); targetOut.close(); logger.info("generated " + target); }
@Override public void generate(Model model, MolgenisOptions options) throws Exception { Template template = createTemplate("/" + this.getClass().getSimpleName() + ".java.ftl"); Map<String, Object> templateArgs = createTemplateArguments(options); List<Entity> entityList = model.getEntities(); entityList = MolgenisModel.sortEntitiesByDependency(entityList, model); // side // effect? File target = new File(this.getSourcePath(options) + APP_DIR + "/CsvEntityExporter.java"); boolean created = target.getParentFile().mkdirs(); if (!created && !target.getParentFile().exists()) { throw new IOException("could not create " + target.getParentFile()); } templateArgs.put("model", model); templateArgs.put("entities", entityList); templateArgs.put("package", APP_DIR); OutputStream targetOut = new FileOutputStream(target); template.process(templateArgs, new OutputStreamWriter(targetOut, Charset.forName("UTF-8"))); targetOut.close(); logger.info("generated " + target); }