private void addRule(Map<String, Integer> mapOfRelations, Entity e, Entity i) { if (e.getModule() != null && i.getModule() != null && e.getModule() != i.getModule()) { String rule = "\"" + e.getModule().getName() + "\"->\"" + i.getModule().getName() + "\""; if (!mapOfRelations.containsKey(rule)) mapOfRelations.put(rule, 0); mapOfRelations.put(rule, mapOfRelations.get(rule) + 1); logger.info(rule); } }
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); }