RelatedTopics { public List makeModel(TopicIF topic) { if (excltopics != null && !excltopics.isEmpty() && incltopics != null && !incltopics.isEmpty()) throw new OntopiaRuntimeException("Configuration fields includeTopicTypes and excludeTopicTypes cannot both be specified."); if (exclassocs != null && !exclassocs.isEmpty() && inclassocs != null && !inclassocs.isEmpty()) throw new OntopiaRuntimeException("Configuration fields includeAssociationTypes and excludeAssociationTypes cannot both be specified."); updateCache(topic.getTopicMap()); ParsedQueryIF pquery = null; if (filterquery != null) pquery = parse(topic.getTopicMap(), filterquery); ParsedQueryIF headingOrderQuery = null; if (headingOrderQueryString != null) headingOrderQuery = parse(topic.getTopicMap(), headingOrderQueryString); ParsedQueryIF childOrderQuery = null; if (childOrderQueryString != null) childOrderQuery = parse(topic.getTopicMap(), childOrderQueryString); Map typemap = new HashMap(); Iterator it = getRoles(topic).iterator(); while (it.hasNext()) { AssociationRoleIF role = (AssociationRoleIF) it.next(); if (isRoleHidden(role, pquery)) continue; AssociationIF assoc = role.getAssociation(); if (getWeakTypes().contains(getObjectId(assoc.getType()))) { if (assoc.getRoles().size() != 2) throw new OntopiaRuntimeException("Weak associations cannot be " + "n-ary or unary"); AssociationRoleIF other = getOtherRole(assoc, role); TopicIF player = other.getPlayer(); TopicIF ttype = null; if (player.getTypes().size() > 0) ttype = (TopicIF) player.getTypes().iterator().next(); String key = getObjectId(ttype); Heading heading = (Heading) typemap.get(key); if (heading == null) { heading = new Heading(ttype); if (headingOrderQuery != null) heading.setSortKey(getSortKey(ttype, headingOrderQuery)); typemap.put(key, heading); } Association child = new Association(role, false); if (childOrderQuery != null) child.setSortKey(getSortKey(child.getPlayer(), childOrderQuery)); heading.addChild(child); } else { String key = getObjectId(assoc.getType()) + "." + getObjectId(role.getType()); Heading heading = (Heading) typemap.get(key); if (heading == null) { heading = new Heading(assoc.getType(), role.getType()); if (headingOrderQuery != null) heading.setSortKey(getSortKey(assoc.getType(), headingOrderQuery)); typemap.put(key, heading); } Association child = new Association(role, true); if (childOrderQuery != null) child.setSortKey(getSortKey(child.getPlayer(), childOrderQuery)); heading.addChild(child); } } List headings = new ArrayList(typemap.values()); Collections.sort(headings); for (int i=0; i < headings.size(); i++) { Heading heading = (Heading)headings.get(i); Collections.sort(heading.children); } return headings; }  void setWeakAssociationTypes(Set weaktypes); void setExcludeAssociationTypes(Set types); void setExcludeRoleTypes(Set types); void setExcludeTopicTypes(Set types); void setIncludeAssociationTypes(Set types); void setIncludeTopicTypes(Set types); void setFilterQuery(String query); void setMaxChildren(int maxchildren); void setHeadingOrderQuery(String headingOrderQueryString); void setHeadingOrdering(int headingOrdering); void setChildOrderQuery(String childOrderQueryString); void setChildOrdering(int childOrdering); void setAggregateHierarchy(boolean aggregateHierarchy); void setAggregateAssociations(Set aggregateAssociations); void setTologContext(DeclarationContextIF tologctx); List makeModel(TopicIF topic); void setUseOntopolyNames(boolean useOntopolyNames); static final int ORDERING_ASC; static final int ORDERING_DESC; }
@Test public void testNoAssociations() throws IOException { TopicMapIF tm = load("screwed-up.ltm"); TopicIF topic = getTopicById(tm, "no-name"); List headings = portlet.makeModel(topic); Assert.assertTrue("topic with no associations had headings", headings.isEmpty()); }