use of org.eclipse.winery.model.tosca.TCapabilityRef in project winery by eclipse.
the class CapabilitiesResource method addNewElement.
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response addNewElement(@FormParam("name") String name, @FormParam("ref") String reference) {
if (reference == null) {
return Response.status(Status.BAD_REQUEST).entity("A reference has to be provided").build();
}
TCapabilityRef ref = new TCapabilityRef();
// may also be null
ref.setName(name);
// The XML model fordces us to put a reference to the object and not just the string
ServiceTemplateResource rs = (ServiceTemplateResource) this.res;
TCapability resolved = ModelUtilities.resolveCapability(rs.getServiceTemplate(), reference);
// In case nothing was found: report back to the user
if (resolved == null) {
return Response.status(Status.BAD_REQUEST).entity("Reference could not be resolved").build();
}
ref.setRef(resolved);
// "this.alreadyContains(ref)" cannot be called as this leads to a mappable exception: The data does not contain an id where the given ref attribute may point to
this.list.add(ref);
return CollectionsHelper.persist(this.res, this, ref, true);
}
use of org.eclipse.winery.model.tosca.TCapabilityRef in project winery by eclipse.
the class Substitution method replaceNodeTemplateWithServiceTemplate.
private void replaceNodeTemplateWithServiceTemplate(TTopologyTemplate topologyTemplate, Map<TNodeTemplate, TServiceTemplate> nodeTemplateToBeSubstitutedWithTopology) {
nodeTemplateToBeSubstitutedWithTopology.forEach((substitutableNodeTemplate, stSubstitutingTheNodeTemplate) -> {
if (Objects.nonNull(stSubstitutingTheNodeTemplate.getBoundaryDefinitions())) {
TTopologyTemplate topologyToImport = stSubstitutingTheNodeTemplate.getTopologyTemplate();
// 1. get all references of the Node Template
// 1.1 Relationships
// TODO 1.2 Boundary definitions
List<TRelationshipTemplate> ingoingRelations = new ArrayList<>();
List<TRelationshipTemplate> outgoingRelations = new ArrayList<>();
topologyTemplate.getRelationshipTemplates().forEach(tRelationshipTemplate -> {
if (substitutableNodeTemplate.getId().equals(tRelationshipTemplate.getSourceElement().getRef().getId())) {
outgoingRelations.add(tRelationshipTemplate);
}
if (substitutableNodeTemplate.getId().equals(tRelationshipTemplate.getTargetElement().getRef().getId())) {
ingoingRelations.add(tRelationshipTemplate);
}
});
// 2. import the topology in the Service Template
BackendUtils.mergeTopologyTemplateAinTopologyTemplateB(topologyToImport, topologyTemplate);
// 3. update the references accordingly
if (topologyToImport != null && ingoingRelations.size() > 0) {
if (Objects.nonNull(stSubstitutingTheNodeTemplate.getBoundaryDefinitions().getCapabilities())) {
List<TCapabilityRef> capabilities = stSubstitutingTheNodeTemplate.getBoundaryDefinitions().getCapabilities();
ingoingRelations.forEach(ingoing -> capabilities.forEach(tCapabilityRef -> topologyToImport.getNodeTemplates().stream().filter(tNodeTemplate -> Objects.nonNull(tNodeTemplate.getCapabilities())).filter(tNodeTemplate -> tNodeTemplate.getCapabilities().stream().anyMatch(tCapability -> tCapability.equals(tCapabilityRef.getRef()))).findFirst().ifPresent(tNodeTemplate -> ingoing.getTargetElement().setRef(tNodeTemplate))));
} else {
throw new UnsupportedOperationException("Mapping without Reqs/Caps is currently not supported");
}
}
if (topologyToImport != null && outgoingRelations.size() > 0) {
if (Objects.nonNull(stSubstitutingTheNodeTemplate.getBoundaryDefinitions().getRequirements())) {
List<TRequirementRef> requirements = stSubstitutingTheNodeTemplate.getBoundaryDefinitions().getRequirements();
outgoingRelations.forEach(outgoing -> requirements.forEach(requirementRef -> topologyToImport.getNodeTemplates().stream().filter(tNodeTemplate -> Objects.nonNull(tNodeTemplate.getRequirements()) && tNodeTemplate.getRequirements().stream().anyMatch(tRequirement -> tRequirement.equals(requirementRef.getRef()))).findFirst().ifPresent(tNodeTemplate -> outgoing.getSourceElement().setRef(tNodeTemplate))));
} else {
throw new UnsupportedOperationException("Mapping without Reqs/Caps is currently not supported");
}
}
// TODO: propagate property mappings
topologyTemplate.getNodeTemplateOrRelationshipTemplate().remove(substitutableNodeTemplate);
}
});
}
use of org.eclipse.winery.model.tosca.TCapabilityRef in project winery by eclipse.
the class ServiceTemplateResource method cullElementReferences.
private void cullElementReferences() {
final TTopologyTemplate topology = this.getServiceTemplate().getTopologyTemplate();
TBoundaryDefinitions boundaryDefs = this.getServiceTemplate().getBoundaryDefinitions();
if (topology == null || boundaryDefs == null) {
return;
}
if (boundaryDefs.getProperties() != null && boundaryDefs.getProperties().getPropertyMappings() != null) {
for (Iterator<TPropertyMapping> it = boundaryDefs.getProperties().getPropertyMappings().iterator(); it.hasNext(); ) {
TPropertyMapping propMapping = it.next();
HasId targetObject = propMapping.getTargetObjectRef();
if (!containsTarget(topology, targetObject)) {
// cull the property mapping pointing towards a no-longer existing element
it.remove();
}
}
}
if (boundaryDefs.getCapabilities() != null) {
for (Iterator<TCapabilityRef> it = boundaryDefs.getCapabilities().iterator(); it.hasNext(); ) {
TCapabilityRef ref = it.next();
TCapability target = ref.getRef();
if (!containsCapability(topology, target)) {
// cull the capability referencing a no longer existing capability in the topology
it.remove();
}
}
}
if (boundaryDefs.getRequirements() != null) {
for (Iterator<TRequirementRef> it = boundaryDefs.getRequirements().iterator(); it.hasNext(); ) {
TRequirementRef ref = it.next();
TRequirement target = ref.getRef();
if (!containsRequirement(topology, target)) {
// cull the requirement referencing a no longer existing requirement in the topology
it.remove();
}
}
}
}
use of org.eclipse.winery.model.tosca.TCapabilityRef in project winery by eclipse.
the class CapabilitiesResource method addNewElementJSON.
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response addNewElementJSON(RequirementsOrCapabilityApiData reqOrCap) {
if (reqOrCap.ref == null) {
return Response.status(Status.BAD_REQUEST).entity("A reference has to be provided").build();
}
TCapabilityRef ref = new TCapabilityRef();
// may also be null
ref.setName(reqOrCap.name);
// The XML model fordces us to put a reference to the object and not just the string
ServiceTemplateResource rs = (ServiceTemplateResource) this.res;
TCapability resolved = ModelUtilities.resolveCapability(rs.getServiceTemplate(), reqOrCap.ref);
// In case nothing was found: report back to the user
if (resolved == null) {
return Response.status(Status.BAD_REQUEST).entity("Reference could not be resolved").build();
}
ref.setRef(resolved);
// "this.alreadyContains(ref)" cannot be called as this leads to a mappable exception: The data does not contain an id where the given ref attribute may point to
this.list.add(ref);
return CollectionsHelper.persist(this.res, this, ref, true);
}
Aggregations