Skip to content

Commit

Permalink
HZN-786: Add support for specifying the default SZL in a GraphML topo…
Browse files Browse the repository at this point in the history
…logy.
  • Loading branch information
Jesse White committed Jun 7, 2016
1 parent 336822f commit 6568955
Show file tree
Hide file tree
Showing 14 changed files with 58 additions and 4 deletions.
Expand Up @@ -715,6 +715,11 @@ public Edge connectVertices(VertexRef sourceVertextId, VertexRef targetVertextId
return m_delegate.connectVertices(sourceVertextId, targetVertextId);
}

@Override
public int getDefaultSzl() {
return m_delegate.getDefaultSzl();
}

@Override
public List<Criteria> getDefaultCriteria() {
return m_delegate.getDefaultCriteria();
Expand Down
Expand Up @@ -45,6 +45,7 @@
import com.google.common.collect.Collections2;

public abstract class AbstractTopologyProvider extends DelegatingVertexEdgeProvider implements GraphProvider {
public static final int DEFAULT_SEMANTIC_ZOOM_LEVEL = 1;
protected static final String SIMPLE_VERTEX_ID_PREFIX = "v";
protected static final String SIMPLE_GROUP_ID_PREFIX = "g";
protected static final String SIMPLE_EDGE_ID_PREFIX = "e";
Expand Down Expand Up @@ -363,6 +364,11 @@ protected void clearCounters() {
edgeIdGenerator.reset();
}

@Override
public int getDefaultSzl() {
return DEFAULT_SEMANTIC_ZOOM_LEVEL;
}

@Override
public abstract void save();

Expand Down
Expand Up @@ -78,6 +78,8 @@ public interface GraphProvider extends VertexProvider, EdgeProvider, SelectionAw

Edge connectVertices(VertexRef sourceVertextId, VertexRef targetVertextId);

int getDefaultSzl();

List<Criteria> getDefaultCriteria();

TopologyProviderInfo getTopologyProviderInfo();
Expand Down
Expand Up @@ -32,6 +32,7 @@
import java.net.MalformedURLException;
import java.net.URI;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -205,7 +206,7 @@ public void refresh() {

@Override
public List<Criteria> getDefaultCriteria() {
return null; //To change body of implemented methods use File | Settings | File Templates.
return Collections.emptyList();
}

void load(URI url) throws JAXBException, MalformedURLException {
Expand Down
Expand Up @@ -389,6 +389,11 @@ public Edge connectVertices(VertexRef sourceVertextId, VertexRef targetVertextId
return m_baseGraphProvider.connectVertices(sourceVertextId, targetVertextId);
}

@Override
public int getDefaultSzl() {
return m_baseGraphProvider.getDefaultSzl();
}

@Override
public List<Criteria> getDefaultCriteria() {
return m_baseGraphProvider.getDefaultCriteria();
Expand Down Expand Up @@ -701,6 +706,11 @@ public Edge connectVertices(VertexRef sourceVertextId, VertexRef targetVertextId
return null;
}

@Override
public int getDefaultSzl() {
return 0;
}

@Override
public List<Criteria> getDefaultCriteria() {
return null;
Expand Down
Expand Up @@ -296,7 +296,7 @@ public void switchLayoutProvider(GraphContainer graphContainer, GraphProvider to
graphContainer.setBaseTopology(topologyProvider);
if (resetCriteriaAndSzl) {
graphContainer.clearCriteria(); // remove all criteria
graphContainer.setSemanticZoomLevel(1); // reset to 1
graphContainer.setSemanticZoomLevel(topologyProvider.getDefaultSzl()); // use the default SZL
List<Criteria> defaultCriteriaList = graphContainer.getBaseTopology().getDefaultCriteria();
if (defaultCriteriaList != null) {
defaultCriteriaList.forEach(eachCriteria -> graphContainer.addCriteria(eachCriteria));
Expand Down
Expand Up @@ -84,7 +84,8 @@ public void execute(List<VertexRef> targets, final OperationContext operationCon
// TODO: Consolidate that this is configurable and we can define a default SZL and default Focus per layer
// TODO: Use a default SZL per graph?
graphContainer.clearCriteria(); // Remove all criteria
graphContainer.setSemanticZoomLevel(1); // Reset the SZL to 1
// Use the default SZL
graphContainer.setSemanticZoomLevel(targetGraphProvider.getDefaultSzl());

// Add the target vertices to focus
targetVertices.stream().forEach(v -> graphContainer.addCriteria(new DefaultVertexHopCriteria(v)));
Expand Down
Expand Up @@ -45,4 +45,5 @@ public interface GraphMLProperties {
String PREFERRED_LAYOUT = "preferred-layout";
String FOCUS_STRATEGY = "focus-strategy";
String FOCUS_IDS = "focus-ids";
String SEMANTIC_ZOOM_LEVEL = "semantic-zoom-level";
}
Expand Up @@ -61,6 +61,7 @@ private static TopologyProviderInfo createTopologyProviderInfo(GraphMLGraph grap
return new DefaultTopologyProviderInfo(name, description);
}

private final int defaultSzl;
private final FocusStrategy focusStrategy;
private final List<String> focusIds;

Expand All @@ -81,6 +82,7 @@ public GraphMLTopologyProvider(GraphMLGraph graph) {
addEdges(newEdge);
}
setTopologyProviderInfo(createTopologyProviderInfo(graph));
defaultSzl = getDefaultSzl(graph);
focusStrategy = getFocusStrategy(graph);
focusIds = getFocusIds(graph);
if (focusStrategy != FocusStrategy.SPECIFIC && !focusIds.isEmpty()) {
Expand All @@ -105,6 +107,14 @@ private static List<String> getFocusIds(GraphMLGraph graph) {
return Lists.newArrayList();
}

private static int getDefaultSzl(GraphMLGraph graph) {
Integer szl = graph.getProperty(GraphMLProperties.SEMANTIC_ZOOM_LEVEL);
if (szl != null) {
return szl;
}
return AbstractTopologyProvider.DEFAULT_SEMANTIC_ZOOM_LEVEL;
}

@Override
public void refresh() {
// TODO: How to handle refresh()?
Expand All @@ -120,6 +130,11 @@ public void save() {
throw new UnsupportedOperationException();
}

@Override
public int getDefaultSzl() {
return defaultSzl;
}

@Override
public List<Criteria> getDefaultCriteria() {
List<VertexHopGraphProvider.VertexHopCriteria> focusCriteria = focusStrategy.getFocusCriteria(this, focusIds.toArray(new String[focusIds.size()]));
Expand Down
Expand Up @@ -39,6 +39,7 @@
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.opennms.features.topology.api.topo.AbstractTopologyProvider;
import org.opennms.features.topology.api.topo.GraphProvider;
import org.opennms.features.topology.api.topo.Vertex;

Expand Down Expand Up @@ -72,6 +73,7 @@ public void load() throws IOException {
assertEquals("regions", regionsGraphProvider.getTopologyProviderInfo().getName());
assertNull(metaTopoProvider.getPreferredLayout(regionsGraphProvider));
assertEquals(GraphMLTopologyProvider.DEFAULT_DESCRIPTION, regionsGraphProvider.getTopologyProviderInfo().getDescription());
assertEquals(AbstractTopologyProvider.DEFAULT_SEMANTIC_ZOOM_LEVEL, regionsGraphProvider.getDefaultSzl());
assertEquals(4, regionsGraphProvider.getVertexTotalCount());
for (String region : Lists.newArrayList("north", "south", "east", "west")) {
// Every vertex should link to 4 other vertices
Expand All @@ -85,6 +87,7 @@ public void load() throws IOException {
assertEquals("Markets", marketsGraphProvider.getTopologyProviderInfo().getName());
assertEquals("The Markets Layer", marketsGraphProvider.getTopologyProviderInfo().getDescription());
assertEquals("Some Layout", metaTopoProvider.getPreferredLayout(marketsGraphProvider));
assertEquals(0, marketsGraphProvider.getDefaultSzl());
assertEquals(16, marketsGraphProvider.getVertexTotalCount());
}
}
Expand Up @@ -7,6 +7,7 @@
<key id="description" for="graph" attr.name="description" attr.type="string"></key>
<key id="namespace" for="graph" attr.name="namespace" attr.type="string"></key>
<key id="preferred-layout" for="graph" attr.name="preferred-layout" attr.type="string"></key>
<key id="semantic-zoom-level" for="graph" attr.name="semantic-zoom-level" attr.type="int"/>
<graph id="regions" edgedefault="undirected">
<data key="namespace">acme:regions</data>
<node id="north">
Expand All @@ -27,6 +28,7 @@
<data key="description">The Markets Layer</data>
<data key="namespace">acme:markets</data>
<data key="preferred-layout">Some Layout</data>
<data key="semantic-zoom-level">0</data>
<node id="north.1">
<data key="label">North 1</data>
</node>
Expand Down
Expand Up @@ -144,6 +144,11 @@ public Edge connectVertices(VertexRef sourceVertextId, VertexRef targetVertextId
return m_delegate.connectVertices(sourceVertextId, targetVertextId);
}

@Override
public int getDefaultSzl() {
return m_delegate.getDefaultSzl();
}

@Override
public List<Criteria> getDefaultCriteria() {
return m_delegate.getDefaultCriteria();
Expand Down
Expand Up @@ -64,7 +64,6 @@ public class GraphMLTopologyIT extends OpenNMSSeleniumTestCase {

private static final String LABEL = "GraphML Topology Provider (test-graph)";


private TopologyIT.TopologyUIPage topologyUIPage;

@Before
Expand Down Expand Up @@ -92,6 +91,7 @@ public void canUseTopology() throws IOException {
List<TopologyIT.FocusedVertex> focusedVertices = topologyUIPage.getFocusedVertices();
assertEquals(4, focusedVertices.size());
assertEquals(4, topologyUIPage.getVisibleVertices().size());
assertEquals(1, topologyUIPage.getSzl());
focusedVertices.sort(Comparator.comparing(TopologyIT.FocusedVertex::getNamespace).thenComparing(TopologyIT.FocusedVertex::getLabel));
assertEquals(
Lists.newArrayList(
Expand All @@ -116,6 +116,7 @@ public void canUseTopology() throws IOException {

// Switch Layer
topologyUIPage.selectLayer("Markets");
assertEquals(0, topologyUIPage.getSzl());
assertEquals(1, topologyUIPage.getFocusedVertices().size());
assertEquals("North 4", topologyUIPage.getFocusedVertices().get(0).getLabel());
}
Expand Down
Expand Up @@ -9,6 +9,7 @@
<key id="focus-strategy" for="graph" attr.name="focus-strategy" attr.type="string"></key>
<key id="focus-ids" for="graph" attr.name="focus-ids" attr.type="string"></key>
<key id="preferred-layout" for="graph" attr.name="preferred-layout" attr.type="string"></key>
<key id="semantic-zoom-level" for="graph" attr.name="semantic-zoom-level" attr.type="int"/>
<data key="label">GraphML Topology Provider (test-graph)</data>
<graph id="regions" edgedefault="undirected">
<data key="namespace">acme:regions</data>
Expand All @@ -33,6 +34,7 @@
<data key="description">The Markets Layer</data>
<data key="namespace">acme:markets</data>
<data key="preferred-layout">Circle Layout</data>
<data key="semantic-zoom-level">0</data>
<node id="north.1">
<data key="label">North 1</data>
</node>
Expand Down

0 comments on commit 6568955

Please sign in to comment.