private static Set<String> getSubTagNamesGraph(GraphContext graphContext, String subSectorTagName) { TagGraphService tagService = new TagGraphService(graphContext); Set<TagModel> subTags = tagService.getDescendantTags(tagService.getTagByName(subSectorTagName)); return subTags.stream().map(TagModel::getName).collect(Collectors.toSet()); }
/** * @return true if the subTag is contained directly or indirectly in the superTag. */ public static boolean isTagUnderTagOrSame(TagModel subTag, TagModel superTag) { return isTagUnderTag(subTag, superTag, true); }
@Override public void perform(GraphRewrite event, EvaluationContext context) { new TagGraphService(event.getGraphContext()).feedTheWholeTagStructureToGraph(tagServiceHolder.getTagService()); } }).withId("feedTagsToGraph")
@Override public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException { if (arguments.size() != 1) throw new TemplateModelException("Expected one String argument - the name of the tag."); SimpleScalar stringModel = (SimpleScalar) arguments.get(0); String tagName = stringModel.getAsString(); return new TagGraphService(graphContext).getTagByName(tagName); }
/** * Creates and returns the TagModel in a graph as per given Tag; * recursively creates the designated ("contained") tags. * <p> * If the Tag was already processed exists, returns the corresponding TagModel. * Doesn't check if the TagModel for given tag name already exists, assuming this method is only called once. */ private TagModel feedTagStructureToGraph(Tag tag, Set<Tag> visited, int level) { if (visited.contains(tag)) return this.getUniqueByProperty(TagModel.PROP_NAME, tag.getName(), true); visited.add(tag); LOG.fine(String.format("Creating TagModel for Tag: %s%s(%d) '%s' traits: %s", StringUtils.repeat(' ', level*2), tag.getName(), tag.getContainedTags().size(), tag.getTitle(), tag.getTraits())); TagModel tagModel = this.create(); tagModel.setName(tag.getName()); tagModel.setTitle(tag.getTitle()); tagModel.setColor(tag.getColor()); tagModel.setRoot(tag.isPrime()); tagModel.setPseudo(tag.isPseudo()); if (null != tag.getTraits()) tagModel.putAllTraits(tag.getTraits()); tag.getContainedTags().forEach(tag2 -> { TagModel tag2model = feedTagStructureToGraph(tag2, visited, level+1); tagModel.addDesignatedTag(tag2model); }); return tagModel; }
boolean isUnder = new TagGraphService(this.graphContext).isTagUnderTag(subTag, maybeSuperTag, countIfSame);
TagGraphService tagService = new TagGraphService(graphContext); final TagModel placeSectorsTag = tagService.getTagByName("techReport:placeSectors"); final TagModel placeBoxesTag = tagService.getTagByName("techReport:placeBoxes"); final TagModel placeRowsTag = tagService.getTagByName("techReport:placeRows"); final TagModel tag = tagService.getTagByName(name); if (null == tag) continue; if (TagGraphService.isTagUnderTagOrSame(tag, placeSectorsTag)) else if (TagGraphService.isTagUnderTagOrSame(tag, placeBoxesTag)) else if (TagGraphService.isTagUnderTagOrSame(tag, placeRowsTag))
/** * Returns all tags that are designated by this tag. E.g., for "vehicle", this would return "ship", "car", "tesla-model3", "bike", etc. */ public Set<TagModel> getDescendantTags(TagModel tag) { Set<TagModel> ancestors = new HashSet<>(); getDescendantTags(tag, ancestors); return ancestors; }
private static TagModel getNonPlaceParent(TagGraphService tagService, TagModel tag) { if (tag == null) return null; final TagModel placeRoot = tagService.getTagByName(MAPPING_OF_PLACEMENT_NAMES); final Iterator<TagModel> parents = tag.getDesignatedByTags().iterator(); if (!parents.hasNext()) throw new WindupException("Tag is not designated by any tags: " + tag); TagModel nonPlaceParent = null; while (parents.hasNext()) { TagModel parentTag = parents.next(); if (TagGraphService.isTagUnderTagOrSame(parentTag, placeRoot)) continue; if (nonPlaceParent != null) throw new WindupException( String.format("Tag %s has more than one non-placement parent: %s, %s", tag.getName(), nonPlaceParent, parentTag)); nonPlaceParent = parentTag; } return nonPlaceParent; }
/** * Traverses the graph structure and stores all tags to the graph. * <p> * There may be several isolated tag structures so we need to iterate through the root tags. */ public void feedTheWholeTagStructureToGraph(org.jboss.windup.config.tags.TagService tagLoaderService) { Set<Tag> visited = new HashSet<>(); for (Tag tag : tagLoaderService.getRootTags()) { // Sanity check TagModel existing = this.getUniqueByProperty(TagModel.PROP_NAME, tag.getName()); if (null != existing) { LOG.warning("TagModel already exists in graph, skipping root Tag: " + tag.getName()); return; } int level = 0; this.feedTagStructureToGraph(tag, visited, level); } }
public TagModel getTagByName(String name) { if (null == name) throw new IllegalArgumentException("Looking for a null tag name."); return getUniqueByProperty(TagModel.PROP_NAME, name.toLowerCase()); }
/** * This relies on the tag structure in the XML when the place:* mapping tags have exactly one parent outside the place: group, which is the tag * they are mapped to. */ private static TechReportPlacement normalizePlacement(GraphContext graphContext, TechReportPlacement placement) { TagGraphService tagService = new TagGraphService(graphContext); final TechReportPlacement normalPlacement = new TechReportPlacement(); normalPlacement.sector = getNonPlaceParent(tagService, placement.sector); normalPlacement.box = getNonPlaceParent(tagService, placement.box); normalPlacement.row = getNonPlaceParent(tagService, placement.row); return normalPlacement; }
@Override public Object exec(@SuppressWarnings("rawtypes") List arguments) throws TemplateModelException { if (arguments.size() != 1) throw new TemplateModelException("Expected one String argument - the name of the tag."); SimpleScalar stringModel = (SimpleScalar) arguments.get(0); String tagName = stringModel.getAsString(); return new TagGraphService(graphContext).getTagByName(tagName); }
/** * Creates and returns the TagModel in a graph as per given Tag; * recursively creates the designated ("contained") tags. * <p> * If the Tag was already processed exists, returns the corresponding TagModel. * Doesn't check if the TagModel for given tag name already exists, assuming this method is only called once. */ private TagModel feedTagStructureToGraph(Tag tag, Set<Tag> visited, int level) { if (visited.contains(tag)) return this.getUniqueByProperty(TagModel.PROP_NAME, tag.getName(), true); visited.add(tag); LOG.fine(String.format("Creating TagModel for Tag: %s%s(%d) '%s' traits: %s", StringUtils.repeat(' ', level*2), tag.getName(), tag.getContainedTags().size(), tag.getTitle(), tag.getTraits())); TagModel tagModel = this.create(); tagModel.setName(tag.getName()); tagModel.setTitle(tag.getTitle()); tagModel.setColor(tag.getColor()); tagModel.setRoot(tag.isPrime()); tagModel.setPseudo(tag.isPseudo()); if (null != tag.getTraits()) tagModel.putAllTraits(tag.getTraits()); tag.getContainedTags().forEach(tag2 -> { TagModel tag2model = feedTagStructureToGraph(tag2, visited, level+1); tagModel.addDesignatedTag(tag2model); }); return tagModel; }
boolean isUnder = new TagGraphService(this.graphContext).isTagUnderTag(subTag, maybeSuperTag, countIfSame);
TagGraphService tagService = new TagGraphService(graphContext); final TagModel placeSectorsTag = tagService.getTagByName("techReport:placeSectors"); final TagModel placeBoxesTag = tagService.getTagByName("techReport:placeBoxes"); final TagModel placeRowsTag = tagService.getTagByName("techReport:placeRows"); final TagModel tag = tagService.getTagByName(name); if (null == tag) continue; if (TagGraphService.isTagUnderTagOrSame(tag, placeSectorsTag)) else if (TagGraphService.isTagUnderTagOrSame(tag, placeBoxesTag)) else if (TagGraphService.isTagUnderTagOrSame(tag, placeRowsTag))
/** * Returns all tags that are designated by this tag. E.g., for "vehicle", this would return "ship", "car", "tesla-model3", "bike", etc. */ public Set<TagModel> getDescendantTags(TagModel tag) { Set<TagModel> ancestors = new HashSet<>(); getDescendantTags(tag, ancestors); return ancestors; }
private static TagModel getNonPlaceParent(TagGraphService tagService, TagModel tag) { if (tag == null) return null; final TagModel placeRoot = tagService.getTagByName(MAPPING_OF_PLACEMENT_NAMES); final Iterator<TagModel> parents = tag.getDesignatedByTags().iterator(); if (!parents.hasNext()) throw new WindupException("Tag is not designated by any tags: " + tag); TagModel nonPlaceParent = null; while (parents.hasNext()) { TagModel parentTag = parents.next(); if (TagGraphService.isTagUnderTagOrSame(parentTag, placeRoot)) continue; if (nonPlaceParent != null) throw new WindupException( String.format("Tag %s has more than one non-placement parent: %s, %s", tag.getName(), nonPlaceParent, parentTag)); nonPlaceParent = parentTag; } return nonPlaceParent; }
/** * Traverses the graph structure and stores all tags to the graph. * <p> * There may be several isolated tag structures so we need to iterate through the root tags. */ public void feedTheWholeTagStructureToGraph(org.jboss.windup.config.tags.TagService tagLoaderService) { Set<Tag> visited = new HashSet<>(); for (Tag tag : tagLoaderService.getRootTags()) { // Sanity check TagModel existing = this.getUniqueByProperty(TagModel.PROP_NAME, tag.getName()); if (null != existing) { LOG.warning("TagModel already exists in graph, skipping root Tag: " + tag.getName()); return; } int level = 0; this.feedTagStructureToGraph(tag, visited, level); } }
public TagModel getTagByName(String name) { if (null == name) throw new IllegalArgumentException("Looking for a null tag name."); return getUniqueByProperty(TagModel.PROP_NAME, name.toLowerCase()); }