use of org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId in project winery by eclipse.
the class IRepository method getReferenceCount.
default int getReferenceCount(ArtifactTemplateId id) {
// We do not use a database, therefore, we have to go through all possibilities pointing to the artifact template
// DAs and IAs point to an artifact template
// DAs are contained in Node Type Implementations and Node Templates
// IAs are contained in Node Type Implementations and Relationship Type Implementations
int count = 0;
Collection<TDeploymentArtifact> allDAs = new HashSet<>();
Collection<TImplementationArtifact> allIAs = new HashSet<>();
// handle Node Type Implementation, which contains DAs and IAs
SortedSet<NodeTypeImplementationId> nodeTypeImplementations = this.getAllDefinitionsChildIds(NodeTypeImplementationId.class);
for (NodeTypeImplementationId ntiId : nodeTypeImplementations) {
final TNodeTypeImplementation nodeTypeImplementation = this.getElement(ntiId);
List<TDeploymentArtifact> deploymentArtifacts = nodeTypeImplementation.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
allDAs.addAll(deploymentArtifacts);
}
List<TImplementationArtifact> implementationArtifacts = nodeTypeImplementation.getImplementationArtifacts();
if (implementationArtifacts != null) {
allIAs.addAll(implementationArtifacts);
}
}
// check all RelationshipTypeImplementations for IAs
SortedSet<RelationshipTypeImplementationId> relationshipTypeImplementations = this.getAllDefinitionsChildIds(RelationshipTypeImplementationId.class);
for (RelationshipTypeImplementationId rtiId : relationshipTypeImplementations) {
List<TImplementationArtifact> implementationArtifacts = this.getElement(rtiId).getImplementationArtifacts();
if (implementationArtifacts != null) {
allIAs.addAll(implementationArtifacts);
}
}
// check all node templates for DAs
SortedSet<ServiceTemplateId> serviceTemplates = this.getAllDefinitionsChildIds(ServiceTemplateId.class);
for (ServiceTemplateId sid : serviceTemplates) {
TTopologyTemplate topologyTemplate = this.getElement(sid).getTopologyTemplate();
if (topologyTemplate != null) {
List<TEntityTemplate> nodeTemplateOrRelationshipTemplate = topologyTemplate.getNodeTemplateOrRelationshipTemplate();
for (TEntityTemplate template : nodeTemplateOrRelationshipTemplate) {
if (template instanceof TNodeTemplate) {
TNodeTemplate nodeTemplate = (TNodeTemplate) template;
List<TDeploymentArtifact> deploymentArtifacts = nodeTemplate.getDeploymentArtifacts();
if (deploymentArtifacts != null) {
allDAs.addAll(deploymentArtifacts);
}
}
}
}
}
// now we have all DAs and IAs
QName ourQName = id.getQName();
// check DAs for artifact templates
for (TDeploymentArtifact da : allDAs) {
QName artifactRef = da.getArtifactRef();
if (ourQName.equals(artifactRef)) {
count++;
}
}
// check IAs for artifact templates
for (TImplementationArtifact ia : allIAs) {
QName artifactRef = ia.getArtifactRef();
if (ourQName.equals(artifactRef)) {
count++;
}
}
return count;
}
use of org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId in project winery by eclipse.
the class SelfContainmentPackager method createSelfContainedNodeTypeImplementation.
private void createSelfContainedNodeTypeImplementation(TNodeTypeImplementation impl) {
if (impl.getImplementationArtifacts() != null) {
List<SelfContainmentPlugin.GeneratedArtifacts> generatedArtifacts = impl.getImplementationArtifacts().stream().filter(ia -> Objects.nonNull(ia.getArtifactRef())).filter(ia -> !new ArtifactTemplateId(ia.getArtifactRef()).isSelfContained()).map(ia -> this.downloadArtifacts(ia.getArtifactRef(), ia.getArtifactType())).filter(Objects::nonNull).filter(SelfContainmentPlugin.GeneratedArtifacts::containsNewElements).collect(Collectors.toList());
if (!generatedArtifacts.isEmpty()) {
NodeTypeImplementationId nodeTypeImplementationId = getSelfContainedNodeTypeImplId(impl);
try {
this.repository.duplicate(new NodeTypeImplementationId(impl.getQName()), nodeTypeImplementationId);
TNodeTypeImplementation implementation = this.repository.getElement(nodeTypeImplementationId);
generatedArtifacts.forEach(generatedArtifact -> {
if (implementation.getImplementationArtifacts() != null) {
implementation.getImplementationArtifacts().forEach(ia -> {
if (generatedArtifact.artifactToReplaceQName.equals(ia.getArtifactRef())) {
ia.setArtifactRef(generatedArtifact.selfContainedArtifactQName);
TArtifactTemplate artifactTemplate = generatedArtifact.selfContainedArtifactTemplate;
if (artifactTemplate == null) {
artifactTemplate = repository.getElement(new ArtifactTemplateId(generatedArtifact.selfContainedArtifactQName));
}
if (artifactTemplate.getType() == null) {
logger.error("Artifact Template does not have a type assigned! {}", generatedArtifact.selfContainedArtifactQName);
}
ia.setArtifactType(artifactTemplate.getType());
}
});
List<TDeploymentArtifact> deploymentArtifacts = implementation.getDeploymentArtifacts();
if (deploymentArtifacts == null) {
deploymentArtifacts = new ArrayList<>();
implementation.setDeploymentArtifacts(deploymentArtifacts);
} else {
deploymentArtifacts.removeIf(da -> da.getArtifactRef() != null && generatedArtifact.deploymentArtifactsToRemove.contains(da.getArtifactRef()));
}
for (QName artifactTemplate : generatedArtifact.deploymentArtifactsToAdd) {
TArtifactTemplate generatedAT = repository.getElement(new ArtifactTemplateId(artifactTemplate));
deploymentArtifacts.add(new TDeploymentArtifact.Builder(artifactTemplate.getLocalPart(), generatedAT.getType()).setArtifactRef(artifactTemplate).build());
}
}
});
repository.setElement(nodeTypeImplementationId, implementation);
} catch (IOException e) {
logger.error("Error while creating new self-contained NodeTypeImplementation of {}", impl, e);
}
}
} else {
logger.info("No processable IAs found in Node Type Implementation {}", impl.getQName());
}
}
use of org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId 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.NodeTypeImplementationId in project winery by eclipse.
the class BackendUtils method getArtifactTemplatesOfReferencedImplementationArtifacts.
public static Collection<QName> getArtifactTemplatesOfReferencedImplementationArtifacts(TNodeTemplate nodeTemplate, IRepository repo) {
List<QName> l = new ArrayList<>();
// IAs may be assigned via node type implementations
QName nodeTypeQName = nodeTemplate.getType();
Collection<NodeTypeImplementationId> allNodeTypeImplementations = repo.getAllElementsReferencingGivenType(NodeTypeImplementationId.class, nodeTypeQName);
for (NodeTypeImplementationId nodeTypeImplementationId : allNodeTypeImplementations) {
List<TImplementationArtifact> implementationArtifacts = repo.getElement(nodeTypeImplementationId).getImplementationArtifacts();
Collection<QName> allReferencedArtifactTemplates = getAllReferencedArtifactTemplatesInIAs(implementationArtifacts);
l.addAll(allReferencedArtifactTemplates);
}
return l;
}
use of org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId 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();
}
}
Aggregations