use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class ServiceTemplateResource method createParticipantsVersion.
@POST()
@Path("createparticipantsversion")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public List<Response> createParticipantsVersion() throws IOException {
IRepository repo = RepositoryFactory.getRepository();
// create list of responses because we create multiple resources at once
List<Response> listOfResponses = new ArrayList<>();
LOGGER.debug("Creating new participants version of Service Template {}...", this.getId());
ServiceTemplateId id = (ServiceTemplateId) this.getId();
WineryVersion version = VersionUtils.getVersion(id.getXmlId().getDecoded());
TTopologyTemplate topologyTemplate = this.getTopology();
List<TTag> tags = new ArrayList<>();
Splitting splitting = new Splitting();
if (topologyTemplate.getParticipants() != null) {
for (OTParticipant participant : topologyTemplate.getParticipants()) {
// check if tag with partner in service template
WineryVersion newVersion = new WineryVersion(participant.getName() + "-" + version.toString().replace("gdm", "ldm"), 1, 1);
List<OTParticipant> newParticipantList = new ArrayList<>(topologyTemplate.getParticipants());
// new tag to define participant of service template
tags.add(new TTag.Builder("participant", participant.getName()).build());
String choreoValue = splitting.calculateChoreographyTag(this.getServiceTemplate().getTopologyTemplate().getNodeTemplates(), participant.getName());
tags.add(new TTag.Builder("choreography", choreoValue).build());
ServiceTemplateId newId = new ServiceTemplateId(id.getNamespace().getDecoded(), VersionUtils.getNameWithoutVersion(id.getXmlId().getDecoded()) + WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + newVersion.toString(), false);
if (repo.exists(newId)) {
repo.forceDelete(newId);
}
ResourceResult response = RestUtils.duplicate(id, newId);
if (response.getStatus() == Status.CREATED) {
response.setUri(null);
response.setMessage(new QNameApiData(newId));
}
TServiceTemplate tempServiceTempl = repo.getElement(newId);
tempServiceTempl.setTags(tags);
tempServiceTempl.getTopologyTemplate().setParticipants(newParticipantList);
listOfResponses.add(response.getResponse());
// set element to propagate changed tags
repo.setElement(newId, tempServiceTempl);
}
}
return listOfResponses;
}
use of org.eclipse.winery.model.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.parent.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();
}
use of org.eclipse.winery.model.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.parent.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.model.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 = Environments.getInstance().getUiConfig().getEndpoints().get("topologymodeler");
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 + EncodingUtil.URLencode(repositoryURI.toString());
ServiceTemplateId serviceTemplate = (ServiceTemplateId) this.parent.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 = URI.create(location);
res = Response.seeOther(uri).build();
} else {
// edit mode
URI uri = URI.create(location);
res = Response.seeOther(uri).build();
}
return res;
}
use of org.eclipse.winery.model.ids.definitions.ServiceTemplateId in project winery by eclipse.
the class TopologyTemplateResource method applyGroupingAndPlacement.
@POST
@Path("applyplacement")
@Produces(MediaType.APPLICATION_JSON)
public Response applyGroupingAndPlacement(@Context UriInfo uriInfo) {
try {
TTopologyTemplate topology = PlacementUtils.groupAndPlaceComponents((ServiceTemplateId) this.parent.getId(), this.topologyTemplate);
this.parent.setTopology(topology, this.type);
RestUtils.persist(this.parent);
ServiceTemplateId thisServiceTemplateId = (ServiceTemplateId) this.parent.getId();
URI url = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(thisServiceTemplateId));
return Response.created(url).build();
} catch (InvalidParameterException e) {
LOGGER.debug("Error while grouping and placing: {}", e.getMessage());
return Response.serverError().entity(e.getMessage()).build();
}
}
Aggregations