1 package org.simantics.district.network.profile;
3 import java.util.Collection;
5 import java.util.stream.Collectors;
7 import org.simantics.db.ReadGraph;
8 import org.simantics.db.Resource;
9 import org.simantics.db.common.request.ResourceRead;
10 import org.simantics.db.exception.DatabaseException;
11 import org.simantics.district.network.DistrictNetworkUtil;
12 import org.simantics.district.network.ontology.DistrictNetworkResource;
13 import org.simantics.district.network.visualisations.DynamicVisualisationsContributions;
14 import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicColoringObject;
15 import org.simantics.district.network.visualisations.DynamicVisualisationsContributions.DynamicSizingObject;
16 import org.simantics.district.network.visualisations.model.ColorBarOptions;
17 import org.simantics.district.network.visualisations.model.DynamicColorContribution;
18 import org.simantics.district.network.visualisations.model.DynamicSizeContribution;
19 import org.simantics.district.network.visualisations.model.DynamicVisualisation;
20 import org.simantics.district.network.visualisations.model.SizeBarOptions;
21 import org.simantics.layer0.Layer0;
24 * @author Jani Simomaa
26 public class ActiveDynamicVisualisationsRequest extends ResourceRead<DynamicVisualisation> {
28 public ActiveDynamicVisualisationsRequest(Resource parent) {
33 public DynamicVisualisation perform(ReadGraph graph) throws DatabaseException {
34 DistrictNetworkResource DN = DistrictNetworkResource.getInstance(graph);
35 Resource visualisationFolder = DistrictNetworkUtil.getVisualisationFolder(graph, resource);
36 if (visualisationFolder != null) {
37 Resource visualisationResource = graph.getPossibleObject(visualisationFolder, DN.Diagram_hasActiveVisualisation);
38 if (visualisationResource != null) {
39 String name = graph.getRelatedValue(visualisationResource, Layer0.getInstance(graph).HasName);
41 Collection<DynamicColoringObject> dynamicColoringObjects = DynamicVisualisationsContributions.dynamicColoringObjects(graph);
42 Map<String, DynamicColoringObject> defaultColoringObjects = dynamicColoringObjects.stream().collect(Collectors.toMap(dcc -> dcc.getColoringObject().getName(), dcc -> dcc));
44 Collection<DynamicSizingObject> dynamicSizingObjects = DynamicVisualisationsContributions.dynamicSizingObjects(graph);
45 Map<String, DynamicSizingObject> defaultSizingObjects = dynamicSizingObjects.stream().collect(Collectors.toMap(dcc -> dcc.getSizingObject().getName(), dcc -> dcc));
47 Map<String, DynamicColorContribution> colorContributions = DistrictNetworkUtil.colorContributions(graph, visualisationResource);
48 ColorBarOptions colorBarOptions = DistrictNetworkUtil.colorBarOptions(graph, visualisationResource);
49 Map<String, DynamicSizeContribution> sizeContributions = DistrictNetworkUtil.sizeContributions(graph, visualisationResource);
50 SizeBarOptions sizeBarOptions = DistrictNetworkUtil.sizeBarOptions(graph, visualisationResource);
51 DynamicVisualisation visualisation = new DynamicVisualisation(name, visualisationResource, colorContributions, defaultColoringObjects, colorBarOptions, sizeContributions, defaultSizingObjects, sizeBarOptions);