Esempio n. 1
0
  @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);
  }
  @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);
  }
Esempio n. 5
0
  /**
   * Construct a MOLGENIS generator
   *
   * @param options with generator settings
   * @param generatorsToUse optional list of generator classes to include
   * @throws Exception
   */
  public <E extends Generator> Molgenis(
      MolgenisOptions options, String outputPath, Class<? extends Generator>... generatorsToUse)
      throws Exception {
    BasicConfigurator.configure();

    this.loadFieldTypes();

    this.options = options;

    Logger.getLogger("freemarker.cache").setLevel(Level.INFO);
    logger.info("\nMOLGENIS version " + org.molgenis.Version.convertToString());
    logger.info("working dir: " + System.getProperty("user.dir"));

    // clean options
    if (outputPath != null) {
      // workaround for java string escaping bug in freemarker (see
      // UsedMolgenisOptionsGen.ftl)
      outputPath = outputPath.replace('\\', '/');
      if (!outputPath.endsWith("/")) outputPath = outputPath + "/";
    }

    options.output_src = outputPath != null ? outputPath + options.output_src : options.output_src;
    if (!options.output_src.endsWith("/"))
      options.output_src = options.output_src.endsWith("/") + "/";
    options.output_hand =
        outputPath != null ? outputPath + options.output_hand : options.output_hand;
    if (!options.output_hand.endsWith("/")) options.output_hand = options.output_hand + "/";
    options.output_web = outputPath != null ? outputPath + options.output_web : options.output_web;
    if (!options.output_web.endsWith("/")) options.output_web = options.output_web + "/";
    options.output_doc = outputPath != null ? outputPath + options.output_doc : options.output_doc;
    if (!options.output_doc.endsWith("/")) options.output_doc = options.output_doc + "/";

    // DOCUMENTATION
    if (options.generate_doc) {
      generators.add(new FileFormatDocGen());
      // check if dot is available to prevent error lists in the build logs
      try {
        Runtime.getRuntime().exec("dot -?");
        generators.add(new DotDocGen());
        generators.add(new DotDocMinimalGen());
      } catch (Exception e) {
        // dot not available
      }
      generators.add(new ObjectModelDocGen());
      generators.add(new DotDocModuleDependencyGen());
    } else {
      logger.info("Skipping documentation ....");
    }

    if (options.generate_jpa) {
      if (options.generate_db) {
        generators.add(new DatabaseConfigGen());
      }

      generators.add(new DataTypeGen());
      generators.add(new EntityMetaDataGen());
      generators.add(new JpaRepositoryGen());
      generators.add(new JDBCMetaDatabaseGen());

      if (options.generate_persistence) {
        generators.add(new PersistenceGen());
      }

      if (options.generate_jpa_repository_source) {
        generators.add(new JpaRepositorySourceGen());
      }
    } else {
      logger.info("SEVERE: Skipping ALL SQL ....");
    }

    if (options.generate_entityio) {
      generators.add(new EntitiesImporterGen());
      generators.add(new EntitiesValidatorGen());
    }

    // clean out generators
    List<Generator> use = new ArrayList<Generator>();
    if (!ArrayUtils.isEmpty(generatorsToUse)) {
      for (Class<? extends Generator> c : generatorsToUse) {
        use.add(c.newInstance());
      }
      generators = use;
    }

    logger.debug("\nUsing generators:\n" + toString());

    // parsing model
    model = MolgenisModel.parse(options);
  }