use of org.eclipse.winery.model.tosca.TRequirement in project winery by eclipse.
the class RequirementsResource 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();
}
TRequirementRef ref = new TRequirementRef();
// may also be null
ref.setName(reqOrCap.name);
// The XML model forces us to put a reference to the object and not just the string
ServiceTemplateResource rs = (ServiceTemplateResource) this.res;
TRequirement resolved = ModelUtilities.resolveRequirement(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);
}
use of org.eclipse.winery.model.tosca.TRequirement in project winery by eclipse.
the class IGenericRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(ServiceTemplateId id) {
// We have to use a HashSet to ensure that no duplicate ids are added
// E.g., there may be multiple relationship templates having the same type
Collection<DefinitionsChildId> ids = new HashSet<>();
TServiceTemplate serviceTemplate = this.getElement(id);
// add included things to export queue
TBoundaryDefinitions boundaryDefs;
if ((boundaryDefs = serviceTemplate.getBoundaryDefinitions()) != null) {
TBoundaryDefinitions.Policies policies = boundaryDefs.getPolicies();
if (policies != null) {
for (TPolicy policy : policies.getPolicy()) {
PolicyTypeId policyTypeId = new PolicyTypeId(policy.getPolicyType());
ids.add(policyTypeId);
PolicyTemplateId policyTemplateId = new PolicyTemplateId(policy.getPolicyRef());
ids.add(policyTemplateId);
}
}
// reqs and caps don't have to be exported here as they are references to existing reqs/caps (of nested node templates)
}
if (serviceTemplate.getTopologyTemplate() != null) {
for (TEntityTemplate entityTemplate : serviceTemplate.getTopologyTemplate().getNodeTemplateOrRelationshipTemplate()) {
QName qname = entityTemplate.getType();
if (entityTemplate instanceof TNodeTemplate) {
ids.add(new NodeTypeId(qname));
TNodeTemplate n = (TNodeTemplate) entityTemplate;
// crawl through deployment artifacts
TDeploymentArtifacts deploymentArtifacts = n.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
List<TDeploymentArtifact> das = deploymentArtifacts.getDeploymentArtifact();
for (TDeploymentArtifact da : das) {
ids.add(new ArtifactTypeId(da.getArtifactType()));
if ((qname = da.getArtifactRef()) != null) {
ids.add(new ArtifactTemplateId(qname));
}
}
}
// crawl through reqs/caps
TNodeTemplate.Requirements requirements = n.getRequirements();
if (requirements != null) {
for (TRequirement req : requirements.getRequirement()) {
QName type = req.getType();
RequirementTypeId rtId = new RequirementTypeId(type);
ids.add(rtId);
}
}
TNodeTemplate.Capabilities capabilities = n.getCapabilities();
if (capabilities != null) {
for (TCapability cap : capabilities.getCapability()) {
QName type = cap.getType();
CapabilityTypeId ctId = new CapabilityTypeId(type);
ids.add(ctId);
}
}
// crawl through policies
org.eclipse.winery.model.tosca.TNodeTemplate.Policies policies = n.getPolicies();
if (policies != null) {
for (TPolicy pol : policies.getPolicy()) {
QName type = pol.getPolicyType();
PolicyTypeId ctId = new PolicyTypeId(type);
ids.add(ctId);
QName template = pol.getPolicyRef();
if (template != null) {
PolicyTemplateId policyTemplateId = new PolicyTemplateId(template);
ids.add(policyTemplateId);
}
}
}
} else {
assert (entityTemplate instanceof TRelationshipTemplate);
ids.add(new RelationshipTypeId(qname));
}
}
}
return ids;
}
use of org.eclipse.winery.model.tosca.TRequirement in project winery by eclipse.
the class ProviderRepository method getAllTopologyFragmentsForLocationAndOfferingCapability.
/**
* Pointing to a concrete node template has to be done by putting this node template into a separeate namespace <p>
* The given targetLocation is appended to {@see NS_NAME_START} to gain the namespace. All NodeTemplates in this
* namespace and all "lower" namespaces (e.g., starting with that string) are returned.
*
* @return All node templates available for the given targetLocation.
*/
public List<TTopologyTemplate> getAllTopologyFragmentsForLocationAndOfferingCapability(String targetLocation, TRequirement requirement) {
QName reqTypeQName = requirement.getType();
RequirementTypeId reqTypeId = new RequirementTypeId(reqTypeQName);
QName requiredCapabilityType = RepositoryFactory.getRepository().getElement(reqTypeId).getRequiredCapabilityType();
return getAllTopologyFragmentsForLocation(targetLocation).stream().filter(tf -> {
Optional<TNodeTemplate> nodeTemplate = ModelUtilities.getAllNodeTemplates(tf).stream().filter(nt -> nt.getCapabilities() != null).filter(nt -> nt.getCapabilities().getCapability().stream().anyMatch(cap -> cap.getType().equals(requiredCapabilityType))).findAny();
if (nodeTemplate.isPresent()) {
return true;
} else {
return false;
}
}).collect(Collectors.toList());
}
Aggregations