Skip to content

Commit

Permalink
Added visual appearances
Browse files Browse the repository at this point in the history
Signed-off-by: Thommy Zelenik <t.zelenik@live.de>
Also-by: Josip Ledic <ledicjp@gmail.com>
  • Loading branch information
zelenikty committed Jan 30, 2018
1 parent 253c1a1 commit be8a8d8
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ public class UrlConfiguration {
private String repositoryApiUrl = "http://localhost:8080/winery";

private String repositoryUiUrl = "http://localhost:8080/#/";
private String bpmn4ToscaModelerUrl = "http://localhost:8080/winery-topoloymodeler";
private String topologyModelerUrl = "http://localhost:8080/winery-workflowmodeler";
private String topologyModelerUrl = "http://localhost:8080/winery-topologymodeler";
private String bpmn4ToscaModelerUrl = "http://localhost:8080/winery-workflowmodeler";

public UrlConfiguration() {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
package org.eclipse.winery.repository.rest.resources._support;

import java.io.InputStream;
import java.net.URI;
import java.util.Map;

import javax.ws.rs.Consumes;
Expand All @@ -25,8 +26,10 @@
import javax.xml.namespace.QName;

import org.eclipse.winery.common.RepositoryFileReference;
import org.eclipse.winery.common.Util;
import org.eclipse.winery.common.ids.elements.ToscaElementId;
import org.eclipse.winery.repository.backend.constants.Filename;
import org.eclipse.winery.repository.configuration.Environment;
import org.eclipse.winery.repository.datatypes.ids.elements.VisualAppearanceId;
import org.eclipse.winery.repository.rest.RestUtils;
import org.eclipse.winery.repository.rest.resources.entitytypes.TopologyGraphElementEntityTypeResource;
Expand Down Expand Up @@ -65,6 +68,17 @@ public Response onDelete() {
return RestUtils.delete(this.id);
}

/**
* Used for GUI when accessing the resource as data E.g., for topology
* template
*/
//@JsonIgnore
public URI getAbsoluteURL() {
String URI = Environment.getUrlConfiguration().getRepositoryApiUrl();
URI = URI + "/" + Util.getUrlPath(this.id);
return RestUtils.createURI(URI);
}

public ToscaElementId getId() {
return this.id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,39 @@
*******************************************************************************/
package org.eclipse.winery.repository.rest.resources.apiData;

import javax.xml.namespace.QName;

import org.eclipse.winery.common.RepositoryFileReference;
import org.eclipse.winery.common.ids.definitions.NodeTypeId;
import org.eclipse.winery.repository.backend.RepositoryFactory;
import org.eclipse.winery.repository.backend.constants.Filename;
import org.eclipse.winery.repository.rest.resources.entitytypes.nodetypes.VisualAppearanceResource;

import com.fasterxml.jackson.annotation.JsonInclude;

@JsonInclude(JsonInclude.Include.NON_NULL)
public class NodeTypesVisualsApiData {

public String iconUrl;
public String imageUrl;
public String color;
public QName nodeTypeId;

public NodeTypesVisualsApiData(VisualAppearanceResource visuals) {
this.color = visuals.getBorderColor();
this.nodeTypeId = ((NodeTypeId) visuals.getId().getParent()).getQName();

RepositoryFileReference iconRef = new RepositoryFileReference(visuals.getId(), Filename.FILENAME_SMALL_ICON);
if (RepositoryFactory.getRepository().exists(iconRef)) {
iconUrl = visuals.getAbsoluteURL() + "16x16";
}

RepositoryFileReference imageRef = new RepositoryFileReference(visuals.getId(), Filename.FILENAME_BIG_ICON);
if (RepositoryFactory.getRepository().exists(imageRef)) {
imageUrl = visuals.getAbsoluteURL() + "50x50";
}
}

public NodeTypesVisualsApiData () {
public NodeTypesVisualsApiData() {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,21 @@
*******************************************************************************/
package org.eclipse.winery.repository.rest.resources.entitytypes.nodetypes;

import java.util.List;
import java.util.SortedSet;
import java.util.stream.Collectors;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.eclipse.winery.common.ids.definitions.NodeTypeId;
import org.eclipse.winery.repository.backend.RepositoryFactory;
import org.eclipse.winery.repository.rest.resources._support.AbstractComponentsResource;
import org.eclipse.winery.repository.rest.resources._support.AbstractComponentsWithoutTypeReferenceResource;
import org.eclipse.winery.repository.rest.resources.apiData.NodeTypesVisualsApiData;

import io.swagger.annotations.Api;

Expand All @@ -26,4 +37,16 @@ public NodeTypeResource getComponentInstaceResource(@PathParam("namespace") Stri
return this.getComponentInstaceResource(namespace, id, true);
}

@GET
@Path("allvisualappearancedata")
@Produces(MediaType.APPLICATION_JSON)
public List<NodeTypesVisualsApiData> getVisualAppearanceList() {
SortedSet<NodeTypeId> allNodeTypeIds = RepositoryFactory.getRepository().getAllDefinitionsChildIds(NodeTypeId.class);
return allNodeTypeIds.stream()
.map(id -> {
NodeTypeResource res = (NodeTypeResource) AbstractComponentsResource.getComponentInstaceResource(id);
return res.getVisualAppearanceResource().getJsonData();
})
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ public void baobabGetCsar() throws Exception {
this.assertGet("nodetypes/http%253A%252F%252Fwinery.opentosca.org%252Ftest%252Fnodetypes%252Ffruits/baobab/?csar", "entitytypes/nodetypes/baobab.csar");
}

@Test
public void getAllVisualAppearances() throws Exception {
this.setRevisionTo("8cf0ce80c2c40c6ec178ef8e5bdc4e2fcdecc7f9");
this.assertGet("nodetypes/allvisualappearancedata", "entitytypes/nodetypes/test.visualappearances.json");
}


@Test
public void nodeTypeWithTwoKVPropertiesCorrectJson() throws Exception {
this.setRevisionTo("origin/plain");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"color": "#89ee01"
}
"color": "#89ee01",
"nodeTypeId": "{http://winery.opentosca.org/test/nodetypes/fruits}baobab"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[
{
"imageUrl": "http://localhost:8080/winery/nodetypes/http%253A%252F%252Fwinery.opentosca.org%252Ftest%252Fnodetypes%252Ffruits/baobab/appearance/50x50",
"color": "#89ee01",
"nodeTypeId": "{http://winery.opentosca.org/test/nodetypes/fruits}baobab"
},
{
"color": "#89ee01",
"nodeTypeId": "{http://winery.opentosca.org/test/nodetypes/fruits}grape"
},
{
"color": "#89ee01",
"nodeTypeId": "{http://winery.opentosca.org/test/nodetypes/fruits}lemon"
},
{
"color": "#89ee01",
"nodeTypeId": "{http://winery.opentosca.org/test/nodetypes/fruits}mango"
},
{
"color": "#89ee01",
"nodeTypeId": "{http://winery.opentosca.org/test/nodetypes/fruits}orange"
},
{
"color": "#6f02b4",
"nodeTypeId": "{http://winery.opentosca.org/test/nodetypes/fruits}plantage"
},
{
"color": "#36739e",
"nodeTypeId": "{http://winery.opentosca.org/test/nodetypes/fruits}tree"
},
{
"color": "#01ace2",
"nodeTypeId": "{http://winery.opentosca.org/test/ponyuniverse}oat"
},
{
"color": "#cb1016",
"nodeTypeId": "{http://winery.opentosca.org/test/ponyuniverse}pasture"
},
{
"color": "#bb1c9a",
"nodeTypeId": "{http://winery.opentosca.org/test/ponyuniverse}shetland_pony"
},
{
"color": "#8ac3a0",
"nodeTypeId": "{http://winery.opentosca.org/test/ponyuniverse}stall"
},
{
"color": "#8b0227",
"nodeTypeId": "{http://winery.opentosca.org/test/ponyuniverse}straw"
},
{
"color": "#458ac5",
"nodeTypeId": "{http://winery.opentosca.org/test/ponyuniverse}trough"
},
{
"color": "#e47c98",
"nodeTypeId": "{http://winery.opentosca.org/test/ponyuniverse}unicorn"
}
]

0 comments on commit be8a8d8

Please sign in to comment.