ServiceTemplateResource extends AbstractComponentInstanceResourceContainingATopology implements IHasName { @POST @Path("injector/replace") @Consumes( {MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON}) @Produces( {MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON}) public Response injectNodeTemplates(InjectorReplaceData injectorReplaceData, @Context UriInfo uriInfo) throws Exception { if (injectorReplaceData.hostInjections != null) { Collection<TTopologyTemplate> hostInjectorTopologyTemplates = injectorReplaceData.hostInjections.values(); hostInjectorTopologyTemplates.forEach(t -> { try { ModelUtilities.patchAnyAttributes(t.getNodeTemplates()); } catch (IOException e) { LOGGER.error("XML was invalid", e); } }); } if (injectorReplaceData.connectionInjections != null) { Collection<TTopologyTemplate> connectionInjectorTopologyTemplates = injectorReplaceData.connectionInjections.values(); connectionInjectorTopologyTemplates.forEach(t -> { try { ModelUtilities.patchAnyAttributes(t.getNodeTemplates()); } catch (IOException e) { LOGGER.error("XML was invalid", e); } }); } Splitting splitting = new Splitting(); TTopologyTemplate matchedHostsTopologyTemplate; TTopologyTemplate matchedConnectedTopologyTemplate; Map<TRequirement, String> requirementsAndMatchingBasisCapabilityTypes = splitting.getOpenRequirementsAndMatchingBasisCapabilityTypeNames(this.getServiceTemplate().getTopologyTemplate()); for (TRequirement req : requirementsAndMatchingBasisCapabilityTypes.keySet()) { System.out.println("open Requirement: " + req.getId()); System.out.println("matchingbasisType: " + requirementsAndMatchingBasisCapabilityTypes.get(req)); } if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Container")) { matchedHostsTopologyTemplate = splitting.injectNodeTemplates(this.getServiceTemplate().getTopologyTemplate(), injectorReplaceData.hostInjections, InjectRemoval.REMOVE_REPLACED_AND_SUCCESSORS); if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Endpoint")) { matchedConnectedTopologyTemplate = splitting.injectConnectionNodeTemplates(matchedHostsTopologyTemplate, injectorReplaceData.connectionInjections); } else { matchedConnectedTopologyTemplate = matchedHostsTopologyTemplate; } } else if (requirementsAndMatchingBasisCapabilityTypes.containsValue("Endpoint")) { matchedConnectedTopologyTemplate = splitting.injectConnectionNodeTemplates(this.getServiceTemplate().getTopologyTemplate(), injectorReplaceData.connectionInjections); } else { throw new SplittingException("No open Requirements which can be matched"); } TTopologyTemplate daSpecifiedTopology = matchedConnectedTopologyTemplate; if (!DASpecification.getNodeTemplatesWithAbstractDAs(matchedConnectedTopologyTemplate).isEmpty() && DASpecification.getNodeTemplatesWithAbstractDAs(matchedConnectedTopologyTemplate) != null) { daSpecifiedTopology = DriverInjection.injectDriver(matchedConnectedTopologyTemplate); } this.getServiceTemplate().setTopologyTemplate(daSpecifiedTopology); LOGGER.debug("Persisting..."); RestUtils.persist(this); LOGGER.debug("Persisted."); URI url = uriInfo.getBaseUri().resolve(RestUtils.getAbsoluteURL(id)); LOGGER.debug("URI of the old and new service template {}", url.toString()); return Response.created(url).build(); } ServiceTemplateResource(ServiceTemplateId id); TServiceTemplate getServiceTemplate(); @Override void setTopology(TTopologyTemplate topologyTemplate, String type); @Path("topologytemplate/") TopologyTemplateResource getTopologyTemplateResource(); @Path("plans/") PlansResource getPlansResource(); @Path("selfserviceportal/") SelfServicePortalResource getSelfServicePortalResource(); @Path("boundarydefinitions/") BoundaryDefinitionsResource getBoundaryDefinitionsResource(); @Override String getName(); @Override Response setName(String name); @GET @ApiOperation(value = "Returns the associated node type, which can be substituted by this service template.") @ApiResponses(value = { @ApiResponse(code = 200, response = QName.class, message = "QName of the form {namespace}localName") }) @Path("substitutableNodeType") @Produces(MediaType.TEXT_PLAIN) Response getSubstitutableNodeTypeAsResponse(); QName getSubstitutableNodeType(); @DELETE @ApiOperation(value = "Removes the association to substitutable node type") @Path("substitutableNodeType") Response deleteSubstitutableNodeType(); @GET @Path("injector/options") @Produces( {MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON}) Response getInjectorOptions(); @POST @Path("injector/replace") @Consumes( {MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON}) @Produces( {MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON}) Response injectNodeTemplates(InjectorReplaceData injectorReplaceData, @Context UriInfo uriInfo); @Path("constraintchecking") @Produces(MediaType.APPLICATION_XML) @POST Response complianceChecking(@Context UriInfo uriInfo); @Path("substitute") @Produces(MediaType.APPLICATION_JSON) @GET ServiceTemplateId substitute(); @POST() @Path("createnewstatefulversion") @Produces( {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) Response createNewStatefulVersion(); @Path("threatmodeling") @Produces(MediaType.APPLICATION_JSON) @GET ThreatAssessment threatModeling(); @Override void synchronizeReferences(); @Path("parameters") ParameterResource getParameterResource(); @Path("toscalight") @Produces(MediaType.APPLICATION_JSON) @GET Map<String, Object> getToscaLightCompatibility();  }
@Test public void injectNodeTemplates() throws Exception { this.setRevisionTo("d535f69bf50b2c4eda437be46b7ba1f85c4ff3bc"); this.assertPost("servicetemplates/http%253A%252F%252Fwinery.opentosca.org%252Ftest%252Fservicetemplates%252Fponyuniverse%252Finjector/FoodandHouseInjectionTest/injector/replace", "servicetemplates/ServiceTemplateResource-injectNodeTemplates-input2.json"); }