use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId 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.DefinitionsChildId in project winery by eclipse.
the class IRepository method getReferencedDefinitionsChildIds.
/**
* Determines the referenced definition children Ids. Does NOT return the included files.
*
* @return a collection of referenced definition child Ids
*/
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(ArtifactTemplateId id) throws RepositoryCorruptException {
Collection<DefinitionsChildId> ids = new ArrayList<>();
final TArtifactTemplate artifactTemplate = this.getElement(id);
// "Export" type
QName type = artifactTemplate.getType();
if (type == null) {
throw new RepositoryCorruptException("Type is null for " + id.toReadableString());
} else {
ids.add(new ArtifactTypeId(type));
}
return ids;
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class IRepository method getDefinitionsChildIdOfParent.
/**
* Determines the id of the parent in the inheritance hierarchy (if exists).
*
* @return the id of the parent class
*/
default Optional<DefinitionsChildId> getDefinitionsChildIdOfParent(HasInheritanceId id) {
final HasInheritance element = (HasInheritance) this.getDefinitions(id).getElement();
final HasType derivedFrom = element.getDerivedFrom();
QName derivedFromType = null;
if (derivedFrom != null) {
derivedFromType = derivedFrom.getTypeAsQName();
}
if (derivedFromType == null) {
return Optional.empty();
} else {
// Instantiate an id with the same class as the current id
DefinitionsChildId parentId;
Constructor<? extends DefinitionsChildId> constructor;
try {
constructor = id.getClass().getConstructor(QName.class);
} catch (NoSuchMethodException | SecurityException e1) {
throw new IllegalStateException("Could get constructor to instantiate parent id", e1);
}
try {
parentId = constructor.newInstance(derivedFromType);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
throw new IllegalStateException("Could not instantiate id for parent", e);
}
return Optional.of(parentId);
}
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class IRepository method getReferencedDefinitionsChildIds.
default Collection<DefinitionsChildId> getReferencedDefinitionsChildIds(DataTypeId id) {
Set<DefinitionsChildId> ids = new HashSet<>();
TDataType definition = this.getElement(id);
// cast is safe because TDataType can only use YamlPropertiesDefinitions
getReferencedDefinitionsOfProperties(ids, definition.getProperties());
return ids;
}
use of org.eclipse.winery.model.ids.definitions.DefinitionsChildId in project winery by eclipse.
the class IRepository 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) {
List<TPolicy> policies = boundaryDefs.getPolicies();
if (policies != null) {
for (TPolicy policy : policies) {
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)
}
final TTopologyTemplate topology = serviceTemplate.getTopologyTemplate();
if (topology != null) {
if (Objects.nonNull(topology.getPolicies())) {
topology.getPolicies().stream().filter(Objects::nonNull).forEach(p -> {
QName type = p.getPolicyType();
PolicyTypeId policyTypeIdId = new PolicyTypeId(type);
ids.add(policyTypeIdId);
});
}
for (TEntityTemplate entityTemplate : topology.getNodeTemplateOrRelationshipTemplate()) {
QName qname = entityTemplate.getType();
if (entityTemplate instanceof TNodeTemplate) {
ids.add(new NodeTypeId(qname));
TNodeTemplate n = (TNodeTemplate) entityTemplate;
// crawl through policies
List<TPolicy> policies = n.getPolicies();
if (policies != null) {
for (TPolicy pol : policies) {
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);
}
}
}
// Crawl RequirementTypes and Capabilities for their references
getReferencedRequirementTypeIds(ids, n);
getCapabilitiesReferences(ids, n);
// TODO: this information is collected differently for YAML and XML modes
// crawl through deployment artifacts
List<TDeploymentArtifact> deploymentArtifacts = n.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
for (TDeploymentArtifact da : deploymentArtifacts) {
if (da.getArtifactType() != null) {
// This is considered Nullable, because the test case ConsistencyCheckerTest#hasError
// expects an empty artifactType and thus it may be null.
ids.add(new ArtifactTypeId(da.getArtifactType()));
}
if (da.getArtifactRef() != null) {
ids.add(new ArtifactTemplateId(da.getArtifactRef()));
}
}
}
// Store all referenced artifact types
List<TArtifact> artifacts = n.getArtifacts();
if (Objects.nonNull(artifacts)) {
artifacts.forEach(a -> ids.add(new ArtifactTypeId(a.getType())));
}
TNodeType nodeType = this.getElement(new NodeTypeId(qname));
if (Objects.nonNull(nodeType.getInterfaceDefinitions())) {
nodeType.getInterfaceDefinitions().stream().filter(Objects::nonNull).forEach(iDef -> {
if (Objects.nonNull(iDef.getType())) {
ids.add(new InterfaceTypeId(iDef.getType()));
}
});
}
} else {
assert (entityTemplate instanceof TRelationshipTemplate);
ids.add(new RelationshipTypeId(qname));
}
}
}
return ids;
}
Aggregations