use of org.eclipse.winery.model.ids.definitions.RequirementTypeId in project winery by eclipse.
the class IRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(RelationshipTypeId id) {
// add all implementations
Collection<DefinitionsChildId> ids = new ArrayList<>(this.getAllElementsReferencingGivenType(RelationshipTypeImplementationId.class, id.getQName()));
final TRelationshipType relationshipType = this.getElement(id);
TRelationshipType.ValidSource validSource = relationshipType.getValidSource();
if (validSource != null) {
QName typeRef = validSource.getTypeRef();
// can be a node type or a requirement type
// similar code as for valid target (difference: req/cap)
NodeTypeId ntId = new NodeTypeId(typeRef);
if (this.exists(ntId)) {
ids.add(ntId);
} else {
RequirementTypeId rtId = new RequirementTypeId(typeRef);
ids.add(rtId);
}
}
TRelationshipType.ValidTarget validTarget = relationshipType.getValidTarget();
if (validTarget != null) {
QName typeRef = validTarget.getTypeRef();
// can be a node type or a capability type
// similar code as for valid target (difference: req/cap)
NodeTypeId ntId = new NodeTypeId(typeRef);
if (this.exists(ntId)) {
ids.add(ntId);
} else {
CapabilityTypeId capId = new CapabilityTypeId(typeRef);
ids.add(capId);
}
}
List<QName> validTargetList = relationshipType.getValidTargetList();
if (validTargetList != null) {
for (QName typeRef : validTargetList) {
CapabilityTypeId capId = new CapabilityTypeId(typeRef);
if (this.exists(capId)) {
ids.add(capId);
}
}
}
getReferencedDefinitionsOfProperties(ids, relationshipType.getProperties());
return ids;
}
use of org.eclipse.winery.model.ids.definitions.RequirementTypeId in project winery by eclipse.
the class VersionSupport method getDefinitionInTheGivenVersion.
public static DefinitionsChildId getDefinitionInTheGivenVersion(DefinitionsChildId childId, WineryVersion otherVersion) {
if (childId.getVersion().compareTo(otherVersion) == 0) {
return childId;
}
String localPart = childId.getNameWithoutVersion() + (otherVersion.toString().length() > 0 ? WineryVersion.WINERY_NAME_FROM_VERSION_SEPARATOR + otherVersion.toString() : "");
QName qName = new QName(childId.getNamespace().getDecoded(), localPart);
if (childId instanceof RelationshipTypeImplementationId) {
return new RelationshipTypeImplementationId(qName);
} else if (childId instanceof NodeTypeImplementationId) {
return new NodeTypeImplementationId(qName);
} else if (childId instanceof RequirementTypeId) {
return new RequirementTypeId(qName);
} else if (childId instanceof NodeTypeId) {
return new NodeTypeId(qName);
} else if (childId instanceof RelationshipTypeId) {
return new RelationshipTypeId(qName);
} else if (childId instanceof CapabilityTypeId) {
return new CapabilityTypeId(qName);
} else if (childId instanceof ArtifactTypeId) {
return new ArtifactTypeId(qName);
} else if (childId instanceof PolicyTypeId) {
return new PolicyTypeId(qName);
} else if (childId instanceof PolicyTemplateId) {
return new PolicyTemplateId(qName);
} else if (childId instanceof ServiceTemplateId) {
return new ServiceTemplateId(qName);
} else if (childId instanceof ArtifactTemplateId) {
return new ArtifactTemplateId(qName);
} else {
throw new IllegalStateException("Unhandled id branch. Could happen for XSDImportId");
}
}
use of org.eclipse.winery.model.ids.definitions.RequirementTypeId in project winery by eclipse.
the class YamlRepository method getRequestedDefinition.
/**
* Parses only requested Definition from converted yaml service template
*
* @param id Definitions Child id
* @param definitions converted definitions
* @return requested definitions
*/
private TDefinitions getRequestedDefinition(DefinitionsChildId id, TDefinitions definitions) {
if (id instanceof ArtifactTemplateId) {
String artifactName = getNameOfArtifactFromArtifactName(id.getQName().getLocalPart());
List<TArtifactTemplate> artifactTemplates = definitions.getArtifactTemplates();
List<TArtifactTemplate> requestedArtifactTemplates = new ArrayList<>();
for (TArtifactTemplate artifactTemplate : artifactTemplates) {
if (artifactTemplate.getId().equalsIgnoreCase(artifactName)) {
requestedArtifactTemplates.add(artifactTemplate);
TDefinitions.Builder requestedDefinitions = getEmptyDefinition(definitions);
requestedDefinitions.addArtifactTemplates(requestedArtifactTemplates);
return requestedDefinitions.build();
}
}
// we did not find the artifact template id (this should not happen!)
LOGGER.error("requested artifact template id (" + id.toReadableString() + ") cannot be extracted from definitions object!");
return definitions;
} else {
TDefinitions.Builder requestedDefinitions = getEmptyDefinition(definitions);
if (id instanceof NodeTypeId) {
requestedDefinitions.addNodeTypes(definitions.getNodeTypes());
} else if (id instanceof RelationshipTypeId) {
requestedDefinitions.addRelationshipTypes(definitions.getRelationshipTypes());
} else if (id instanceof NodeTypeImplementationId) {
requestedDefinitions.addNodeTypeImplementations(definitions.getNodeTypeImplementations());
} else if (id instanceof RelationshipTypeImplementationId) {
requestedDefinitions.addRelationshipTypeImplementations(definitions.getRelationshipTypeImplementations());
} else if (id instanceof ArtifactTypeId) {
requestedDefinitions.addArtifactTypes(definitions.getArtifactTypes());
} else if (id instanceof CapabilityTypeId) {
requestedDefinitions.addCapabilityTypes(definitions.getCapabilityTypes());
} else if (id instanceof DataTypeId) {
requestedDefinitions.addDataTypes(definitions.getDataTypes());
} else if (id instanceof RequirementTypeId) {
requestedDefinitions.addRequirementTypes(definitions.getRequirementTypes());
} else if (id instanceof PolicyTypeId) {
requestedDefinitions.addPolicyTypes(definitions.getPolicyTypes());
} else if (id instanceof InterfaceTypeId) {
requestedDefinitions.addInterfaceTypes(definitions.getInterfaceTypes());
} else {
// we do not need to filter anything
return definitions;
}
return requestedDefinitions.build();
}
}
use of org.eclipse.winery.model.ids.definitions.RequirementTypeId 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 separate 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 -> tf.getNodeTemplates().stream().filter(nt -> nt.getCapabilities() != null).anyMatch(nt -> nt.getCapabilities().stream().anyMatch(cap -> cap.getType().equals(requiredCapabilityType)))).collect(Collectors.toList());
}
Aggregations