Search in sources :

Example 1 with FromCanonical

use of org.eclipse.winery.repository.yaml.converter.FromCanonical 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;
}
Also used : Path(java.nio.file.Path) NodeTypeImplementationId(org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId) RelationshipTypeId(org.eclipse.winery.model.ids.definitions.RelationshipTypeId) YTArtifactDefinition(org.eclipse.winery.model.tosca.yaml.YTArtifactDefinition) FromCanonical(org.eclipse.winery.repository.yaml.converter.FromCanonical) CapabilityTypeId(org.eclipse.winery.model.ids.definitions.CapabilityTypeId) TArtifactTemplate(org.eclipse.winery.model.tosca.TArtifactTemplate) YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) YTMapImportDefinition(org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition) RelationshipTypeImplementationId(org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId) ArtifactTemplateId(org.eclipse.winery.model.ids.definitions.ArtifactTemplateId) PolicyTypeId(org.eclipse.winery.model.ids.definitions.PolicyTypeId) NodeTypeId(org.eclipse.winery.model.ids.definitions.NodeTypeId) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) YTNodeType(org.eclipse.winery.model.tosca.yaml.YTNodeType)

Example 2 with FromCanonical

use of org.eclipse.winery.repository.yaml.converter.FromCanonical in project winery by eclipse.

the class YamlCsarImporter method storeDefs.

private void storeDefs(DefinitionsChildId id, TDefinitions defs) {
    RepositoryFileReference ref = BackendUtils.getRefOfDefinitions(id);
    IRepository repo = RepositoryFactory.getRepository();
    FromCanonical converter = null;
    if (repo instanceof GitBasedRepository) {
        GitBasedRepository wrapper = (GitBasedRepository) RepositoryFactory.getRepository();
        converter = new FromCanonical((YamlRepository) wrapper.getRepository());
    } else if (repo instanceof YamlRepository) {
        converter = new FromCanonical((YamlRepository) repo);
    }
    if (Objects.nonNull(converter)) {
        YamlWriter writer = new YamlWriter();
        writer.write(converter.convert((TDefinitions) defs), repo.ref2AbsolutePath(ref));
    }
}
Also used : RepositoryFileReference(org.eclipse.winery.repository.common.RepositoryFileReference) FromCanonical(org.eclipse.winery.repository.yaml.converter.FromCanonical) YamlRepository(org.eclipse.winery.repository.yaml.YamlRepository) IRepository(org.eclipse.winery.repository.backend.IRepository) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository) YamlWriter(org.eclipse.winery.repository.converter.writer.YamlWriter)

Example 3 with FromCanonical

use of org.eclipse.winery.repository.yaml.converter.FromCanonical in project winery by eclipse.

the class YamlRepository method serialize.

@Override
public void serialize(TDefinitions definitions, OutputStream target) throws IOException {
    FromCanonical converter = new FromCanonical(this);
    YTServiceTemplate implementedStandard = converter.convert(definitions);
    serialize(implementedStandard, target);
}
Also used : FromCanonical(org.eclipse.winery.repository.yaml.converter.FromCanonical) YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate)

Aggregations

FromCanonical (org.eclipse.winery.repository.yaml.converter.FromCanonical)3 YTServiceTemplate (org.eclipse.winery.model.tosca.yaml.YTServiceTemplate)2 Path (java.nio.file.Path)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)1 CapabilityTypeId (org.eclipse.winery.model.ids.definitions.CapabilityTypeId)1 NodeTypeId (org.eclipse.winery.model.ids.definitions.NodeTypeId)1 NodeTypeImplementationId (org.eclipse.winery.model.ids.definitions.NodeTypeImplementationId)1 PolicyTypeId (org.eclipse.winery.model.ids.definitions.PolicyTypeId)1 RelationshipTypeId (org.eclipse.winery.model.ids.definitions.RelationshipTypeId)1 RelationshipTypeImplementationId (org.eclipse.winery.model.ids.definitions.RelationshipTypeImplementationId)1 TArtifactTemplate (org.eclipse.winery.model.tosca.TArtifactTemplate)1 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)1 YTArtifactDefinition (org.eclipse.winery.model.tosca.yaml.YTArtifactDefinition)1 YTNodeType (org.eclipse.winery.model.tosca.yaml.YTNodeType)1 YTMapImportDefinition (org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition)1 IRepository (org.eclipse.winery.repository.backend.IRepository)1 GitBasedRepository (org.eclipse.winery.repository.backend.filebased.GitBasedRepository)1 RepositoryFileReference (org.eclipse.winery.repository.common.RepositoryFileReference)1