use of org.eclipse.winery.model.tosca.yaml.YTNodeType in project winery by eclipse.
the class YamlRepository method replaceOldWithNewData.
/**
* Replaces old data of yaml node type with new data from xml node type to prevent deletion of implementation
* artifacts
*
* @param newData new saved node type
* @param oldData already saved node type
* @return edited yaml service template
*/
private YTServiceTemplate replaceOldWithNewData(YTServiceTemplate newData, YTServiceTemplate oldData) {
YTNodeType oldNodeType = oldData.getNodeTypes().entrySet().iterator().next().getValue();
YTNodeType newNodeType = newData.getNodeTypes().entrySet().iterator().next().getValue();
oldNodeType.setMetadata(newNodeType.getMetadata());
oldNodeType.setProperties(newNodeType.getProperties());
oldNodeType.setDerivedFrom(newNodeType.getDerivedFrom());
oldNodeType.setDescription(newNodeType.getDescription());
oldNodeType.setRequirements(newNodeType.getRequirements());
oldNodeType.setCapabilities(newNodeType.getCapabilities());
oldNodeType.setArtifacts(newNodeType.getArtifacts());
oldNodeType.setInterfaces(newNodeType.getInterfaces());
oldNodeType.setAttributes(newNodeType.getAttributes());
oldData.getNodeTypes().entrySet().iterator().next().setValue(oldNodeType);
return oldData;
}
use of org.eclipse.winery.model.tosca.yaml.YTNodeType in project winery by eclipse.
the class YamlRepository method convertToYamlModel.
private YTServiceTemplate convertToYamlModel(RepositoryFileReference existing, TDefinitions definitions) throws IOException, MultiException {
FromCanonical converter = new FromCanonical(this);
YTServiceTemplate serviceTemplate;
if (existing.getParent() instanceof NodeTypeImplementationId) {
serviceTemplate = readServiceTemplate(existing);
serviceTemplate = converter.convertNodeTypeImplementation(serviceTemplate, definitions.getNodeTypeImplementations().get(0));
} else if (existing.getParent() instanceof RelationshipTypeImplementationId) {
serviceTemplate = readServiceTemplate(existing);
serviceTemplate = converter.convertRelationshipTypeImplementation(serviceTemplate, definitions.getRelationshipTypeImplementations().get(0));
} else if (existing.getParent() instanceof NodeTypeId) {
serviceTemplate = converter.convert(definitions);
if (exists(existing)) {
YTServiceTemplate oldServiceTemplate = readServiceTemplate(existing);
serviceTemplate = replaceOldWithNewData(serviceTemplate, oldServiceTemplate);
}
} else if (existing.getParent() instanceof RelationshipTypeId) {
serviceTemplate = converter.convert(definitions);
if (exists(existing)) {
YTServiceTemplate oldServiceTemplate = readServiceTemplate(existing);
serviceTemplate = replaceOldRelationshipTypeWithNewData(serviceTemplate, oldServiceTemplate);
}
} else if (existing.getParent() instanceof ArtifactTemplateId) {
ArtifactTemplateId id = (ArtifactTemplateId) existing.getParent();
TArtifactTemplate artifactTemplate = definitions.getArtifactTemplates().get(0);
YTArtifactDefinition artifact = converter.convertArtifactTemplate(artifactTemplate);
List<YTMapImportDefinition> imports = converter.convertImports();
Path targetPath = ref2AbsolutePath(existing);
if (Files.exists(targetPath)) {
serviceTemplate = readServiceTemplate(targetPath);
if (serviceTemplate == null) {
serviceTemplate = createNewCacheNodeTypeWithArtifact(existing, artifactTemplate, artifact, imports);
} else if (getTypeFromArtifactName(id.getQName().getLocalPart()).equalsIgnoreCase("nodetypes")) {
YTNodeType nodeType = serviceTemplate.getNodeTypes().entrySet().iterator().next().getValue();
Map<String, YTArtifactDefinition> artifacts = nodeType.getArtifacts();
if (artifacts.containsKey(artifactTemplate.getIdFromIdOrNameField())) {
artifacts.replace(artifactTemplate.getIdFromIdOrNameField(), artifact);
} else {
artifacts.put(artifactTemplate.getIdFromIdOrNameField(), artifact);
}
} else if (existing.getParent() instanceof PolicyTypeId || existing.getParent() instanceof CapabilityTypeId) {
// we simply take the new definition as is
serviceTemplate = converter.convert(definitions);
} else {
serviceTemplate = converter.convert(definitions);
if (exists(existing)) {
YTServiceTemplate existingServiceTemplate = readServiceTemplate(existing);
serviceTemplate = replaceTopologyTemplate(serviceTemplate, existingServiceTemplate);
}
}
} else {
serviceTemplate = createNewCacheNodeTypeWithArtifact(existing, artifactTemplate, artifact, imports);
}
} else {
serviceTemplate = converter.convert(definitions);
}
return serviceTemplate;
}
use of org.eclipse.winery.model.tosca.yaml.YTNodeType in project winery by eclipse.
the class FromCanonical method convertNodeTypeImplementation.
@Deprecated
public YTServiceTemplate convertNodeTypeImplementation(YTServiceTemplate type, TNodeTypeImplementation node) {
if (Objects.isNull(node)) {
return null;
}
YTNodeType nodeType = type.getNodeTypes().entrySet().iterator().next().getValue();
nodeType.setArtifacts(convert(node, nodeType.getArtifacts()));
nodeType.setInterfaces(convertInterfaces(nodeType.getInterfaces(), node.getImplementationArtifacts()));
type.getNodeTypes().entrySet().iterator().next().setValue(nodeType);
type.setImports(addNewImports(type.getImports()));
return type;
}
use of org.eclipse.winery.model.tosca.yaml.YTNodeType in project winery by eclipse.
the class YamlReaderTest method testSupportedInterfaceDefinitions.
@Test
public void testSupportedInterfaceDefinitions() throws Exception {
YamlReader reader = new YamlReader();
InputStream is = getClass().getClassLoader().getResourceAsStream("yaml/supported_interfaces.yml");
YTServiceTemplate template = reader.parse(is);
Assertions.assertNotNull(template);
YTNodeType server = template.getNodeTypes().get("server");
Assertions.assertEquals(2, server.getArtifacts().size());
YTInterfaceDefinition standard = server.getInterfaces().get("Standard");
Assertions.assertEquals(2, standard.getOperations().size());
Assertions.assertEquals(1, standard.getInputs().size());
}
Aggregations