use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class BackendUtils method createWrapperDefinitionsAndInitialEmptyElement.
public static Definitions createWrapperDefinitionsAndInitialEmptyElement(IRepository repository, DefinitionsChildId id) {
final Definitions definitions = createWrapperDefinitions(id);
HasIdInIdOrNameField element;
if (id instanceof RelationshipTypeImplementationId) {
element = new TRelationshipTypeImplementation();
} else if (id instanceof NodeTypeImplementationId) {
element = new TNodeTypeImplementation();
} else if (id instanceof RequirementTypeId) {
element = new TRequirementType();
} else if (id instanceof NodeTypeId) {
element = new TNodeType();
} else if (id instanceof RelationshipTypeId) {
element = new TRelationshipType();
} else if (id instanceof CapabilityTypeId) {
element = new TCapabilityType();
} else if (id instanceof ArtifactTypeId) {
element = new TArtifactType();
} else if (id instanceof PolicyTypeId) {
element = new TPolicyType();
} else if (id instanceof PolicyTemplateId) {
element = new TPolicyTemplate();
} else if (id instanceof ServiceTemplateId) {
element = new TServiceTemplate();
} else if (id instanceof ArtifactTemplateId) {
element = new TArtifactTemplate();
} else if (id instanceof XSDImportId) {
// TImport has no id; thus directly generating it without setting an id
TImport tImport = new TImport();
definitions.setElement(tImport);
return definitions;
} else {
throw new IllegalStateException("Unhandled id branch. Could happen for XSDImportId");
}
copyIdToFields(element, id);
definitions.setElement((TExtensibleElements) element);
return definitions;
}
use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class BackendUtils method mergeServiceTemplateAinServiceTemplateB.
public static void mergeServiceTemplateAinServiceTemplateB(ServiceTemplateId serviceTemplateIdA, ServiceTemplateId serviceTemplateIdB) throws IOException {
IRepository repository = RepositoryFactory.getRepository();
TTopologyTemplate topologyTemplateA = repository.getElement(serviceTemplateIdA).getTopologyTemplate();
TServiceTemplate serviceTemplateB = repository.getElement(serviceTemplateIdB);
TTopologyTemplate topologyTemplateB = serviceTemplateB.getTopologyTemplate();
Optional<Integer> shiftLeft = topologyTemplateB.getNodeTemplateOrRelationshipTemplate().stream().filter(x -> x instanceof TNodeTemplate).map(x -> (TNodeTemplate) x).max(Comparator.comparingInt(n -> ModelUtilities.getLeft(n).orElse(0))).map(n -> ModelUtilities.getLeft(n).orElse(0));
if (shiftLeft.isPresent()) {
Map<String, String> idMapping = new HashMap<>();
// collect existing node template ids
topologyTemplateB.getNodeTemplateOrRelationshipTemplate().stream().filter(x -> x instanceof TNodeTemplate).map(x -> (TNodeTemplate) x).forEach(x -> idMapping.put(x.getId(), x.getId()));
// collect existing relationship template ids
topologyTemplateB.getNodeTemplateOrRelationshipTemplate().stream().filter(x -> x instanceof TRelationshipTemplate).map(x -> (TRelationshipTemplate) x).forEach(x -> idMapping.put(x.getId(), x.getId()));
if (topologyTemplateB.getNodeTemplates() != null) {
// collect existing requirement ids
topologyTemplateB.getNodeTemplates().stream().filter(nt -> nt.getRequirements() != null).forEach(nt -> nt.getRequirements().getRequirement().stream().forEach(x -> idMapping.put(x.getId(), x.getId())));
// collect existing capability ids
topologyTemplateB.getNodeTemplates().stream().filter(nt -> nt.getCapabilities() != null).forEach(nt -> nt.getCapabilities().getCapability().stream().forEach(x -> idMapping.put(x.getId(), x.getId())));
}
if (topologyTemplateA.getNodeTemplates() != null) {
// patch ids of reqs change them if required
topologyTemplateA.getNodeTemplates().stream().filter(nt -> nt.getRequirements() != null).forEach(nt -> nt.getRequirements().getRequirement().forEach(req -> {
String oldId = req.getId();
String newId = req.getId();
while (idMapping.containsKey(newId)) {
newId = newId + "-new";
}
idMapping.put(req.getId(), newId);
req.setId(newId);
topologyTemplateA.getRelationshipTemplates().stream().filter(rt -> rt.getSourceElement().getRef() instanceof TRequirement).forEach(rt -> {
TRequirement sourceElement = (TRequirement) rt.getSourceElement().getRef();
if (sourceElement.getId().equalsIgnoreCase(oldId)) {
sourceElement.setId(req.getId());
}
});
}));
// patch ids of caps change them if required
topologyTemplateA.getNodeTemplates().stream().filter(nt -> nt.getCapabilities() != null).forEach(nt -> nt.getCapabilities().getCapability().forEach(cap -> {
String oldId = cap.getId();
String newId = cap.getId();
while (idMapping.containsKey(newId)) {
newId = newId + "-new";
}
idMapping.put(cap.getId(), newId);
cap.setId(newId);
topologyTemplateA.getRelationshipTemplates().stream().filter(rt -> rt.getTargetElement().getRef() instanceof TCapability).forEach(rt -> {
TCapability targetElement = (TCapability) rt.getTargetElement().getRef();
if (targetElement.getId().equalsIgnoreCase(oldId)) {
targetElement.setId(cap.getId());
}
});
}));
}
// patch the ids of node templates and add them
topologyTemplateA.getNodeTemplateOrRelationshipTemplate().stream().filter(x -> x instanceof TNodeTemplate).map(x -> (TNodeTemplate) x).forEach(nt -> {
String newId = nt.getId();
while (idMapping.containsKey(newId)) {
newId = newId + "-new";
}
idMapping.put(nt.getId(), newId);
nt.setId(newId);
int newLeft = ModelUtilities.getLeft((TNodeTemplate) nt).orElse(0) + shiftLeft.get();
((TNodeTemplate) nt).setX(Integer.toString(newLeft));
topologyTemplateB.getNodeTemplateOrRelationshipTemplate().add(nt);
});
// patch the ids of relationship templates and add them
topologyTemplateA.getNodeTemplateOrRelationshipTemplate().stream().filter(x -> x instanceof TRelationshipTemplate).map(x -> (TRelationshipTemplate) x).forEach(rt -> {
String newId = rt.getId();
while (idMapping.containsKey(newId)) {
newId = newId + "-new";
}
idMapping.put(rt.getId(), newId);
rt.setId(newId);
topologyTemplateB.getNodeTemplateOrRelationshipTemplate().add(rt);
});
} else {
topologyTemplateB.getNodeTemplateOrRelationshipTemplate().addAll(topologyTemplateA.getNodeTemplateOrRelationshipTemplate());
}
repository.setElement(serviceTemplateIdB, serviceTemplateB);
}
use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class TopologyTemplateResource method getHTML.
@GET
@ApiOperation(value = "?edit is used in the URL to get the jsPlumb-based editor")
@Produces(MediaType.TEXT_HTML)
public // @formatter:off
Response getHTML(@QueryParam(value = "edit") String edit, @QueryParam(value = "script") @ApiParam(value = "the script to include in a <script> tag. The function wineryViewExternalScriptOnLoad if it is defined. Only available if 'view' is also set") String script, @QueryParam(value = "view") String view, @QueryParam(value = "autoLayoutOnLoad") String autoLayoutOnLoad, @Context UriInfo uriInfo) {
// @formatter:on
Response res;
String JSPName;
String location = Environment.getUrlConfiguration().getTopologyModelerUrl();
location = uriInfo.getBaseUri().resolve(location).toString();
// at the topology modeler, jersey needs to have an absolute path
URI repositoryURI = uriInfo.getBaseUri();
location = location + "/?repositoryURL=";
location = location + Util.URLencode(repositoryURI.toString());
ServiceTemplateId serviceTemplate = (ServiceTemplateId) this.serviceTemplateRes.getId();
location = location + "&ns=";
location = location + serviceTemplate.getNamespace().getEncoded();
location = location + "&id=";
location = location + serviceTemplate.getXmlId().getEncoded();
if (edit == null) {
// TODO: Render-only mode
// currently also the edit mode
URI uri = RestUtils.createURI(location);
res = Response.seeOther(uri).build();
} else {
// edit mode
URI uri = RestUtils.createURI(location);
res = Response.seeOther(uri).build();
}
return res;
}
use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class TopologyTemplateResource method match.
@Path("match/")
@Produces(MediaType.TEXT_PLAIN)
@POST
public Response match(@Context UriInfo uriInfo) {
Splitting splitting = new Splitting();
ServiceTemplateId matchedServiceTemplateId;
try {
matchedServiceTemplateId = splitting.matchTopologyOfServiceTemplate((ServiceTemplateId) this.serviceTemplateRes.getId());
} catch (Exception e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Could not match. " + e.getMessage()).build();
}
URI url = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(matchedServiceTemplateId));
return Response.created(url).build();
}
use of org.eclipse.winery.common.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class TopologyTemplateResource method split.
@Path("split/")
@Produces(MediaType.TEXT_PLAIN)
@POST
public Response split(@Context UriInfo uriInfo) {
Splitting splitting = new Splitting();
ServiceTemplateId splitServiceTemplateId;
try {
splitServiceTemplateId = splitting.splitTopologyOfServiceTemplate((ServiceTemplateId) this.serviceTemplateRes.getId());
} catch (Exception e) {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Could not split. " + e.getMessage()).build();
}
URI url = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(splitServiceTemplateId));
return Response.created(url).build();
}
Aggregations