Search in sources :

Example 11 with YTServiceTemplate

use of org.eclipse.winery.model.tosca.yaml.YTServiceTemplate in project winery by eclipse.

the class YamlRepository method deleteArtifact.

/**
 * Deletes artifacts from there referenced type
 *
 * @param id Artifact Template id
 */
private void deleteArtifact(ArtifactTemplateId id) {
    if (getNameOfTypeFromArtifactName(id.getQName().getLocalPart()).equalsIgnoreCase("Cache")) {
        super.forceDelete(id);
    } else {
        Path targetPath = id2AbsolutePath(id);
        GenericId convertedId = convertGenericId(id);
        if (convertedId != null) {
            if (convertedId instanceof DefinitionsChildId) {
                String convertedFilename = BackendUtils.getFileNameOfDefinitions((DefinitionsChildId) convertedId);
                targetPath = targetPath.resolve(convertedFilename);
            }
        }
        if (Files.exists(targetPath)) {
            try {
                YTServiceTemplate nodeType = readServiceTemplate(targetPath);
                String targetArtifactName = getNameOfArtifactFromArtifactName(id.getQName().getLocalPart());
                if (getTypeFromArtifactName(id.getQName().getLocalPart()).equalsIgnoreCase("nodetypes")) {
                    Map<String, YTArtifactDefinition> artifacts = nodeType.getNodeTypes().entrySet().iterator().next().getValue().getArtifacts();
                    nodeType.getNodeTypes().entrySet().iterator().next().setValue(removeImplementation(nodeType.getNodeTypes().entrySet().iterator().next().getValue(), targetArtifactName));
                    artifacts.remove(targetArtifactName);
                    nodeType.getNodeTypes().entrySet().iterator().next().getValue().setArtifacts(artifacts);
                } else {
                    nodeType.getRelationshipTypes().entrySet().iterator().next().setValue(removeRelationshipArtifact(nodeType.getRelationshipTypes().entrySet().iterator().next().getValue(), targetArtifactName));
                }
                YamlWriter writer = new YamlWriter();
                InputStream output = writer.writeToInputStream(nodeType);
                writeInputStreamToPath(targetPath, output);
            } catch (Exception e) {
                LOGGER.error("Error deleting file: {}", e.getMessage(), e);
            }
        }
    }
}
Also used : Path(java.nio.file.Path) GenericId(org.eclipse.winery.model.ids.GenericId) YTArtifactDefinition(org.eclipse.winery.model.tosca.yaml.YTArtifactDefinition) DefinitionsChildId(org.eclipse.winery.model.ids.definitions.DefinitionsChildId) InputStream(java.io.InputStream) YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) JAXBException(javax.xml.bind.JAXBException) InvocationTargetException(java.lang.reflect.InvocationTargetException) MultiException(org.eclipse.winery.model.converter.support.exception.MultiException) IOException(java.io.IOException) YamlWriter(org.eclipse.winery.repository.converter.writer.YamlWriter)

Example 12 with YTServiceTemplate

use of org.eclipse.winery.model.tosca.yaml.YTServiceTemplate 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)

Example 13 with YTServiceTemplate

use of org.eclipse.winery.model.tosca.yaml.YTServiceTemplate in project winery by eclipse.

the class SchemaVisitor method visit.

public Map<QName, Map<String, QName>> visit(YTServiceTemplate node, Path path, Path outpath, String namespace) {
    for (YTMapImportDefinition map : node.getImports()) {
        for (Map.Entry<String, YTImportDefinition> entry : map.entrySet()) {
            YamlReader reader = new YamlReader();
            try {
                YTServiceTemplate serviceTemplate = reader.parse(entry.getValue(), path, entry.getValue().getNamespaceUri());
                visit(serviceTemplate, new Parameter(outpath, entry.getValue().getNamespaceUri()).setBuildSchema(false));
            } catch (MultiException e) {
                setException(e);
            }
        }
    }
    this.visit(node, new Parameter(outpath, namespace));
    return propertyDefinition;
}
Also used : YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) YTMapImportDefinition(org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition) YTImportDefinition(org.eclipse.winery.model.tosca.yaml.YTImportDefinition) YamlReader(org.eclipse.winery.repository.converter.reader.YamlReader) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap) MultiException(org.eclipse.winery.model.converter.support.exception.MultiException)

Example 14 with YTServiceTemplate

use of org.eclipse.winery.model.tosca.yaml.YTServiceTemplate in project winery by eclipse.

the class SchemaVisitor method visit.

@Override
public Result visit(YTDataType node, Parameter parameter) {
    SchemaBuilder builder;
    if (this.schemaBuilders.containsKey(parameter.getNamespace())) {
        builder = this.schemaBuilders.get(parameter.getNamespace());
    } else {
        builder = new SchemaBuilder(parameter.getNamespace());
        this.schemaBuilders.put(parameter.getNamespace(), builder);
    }
    Map<String, QName> buildPlan = new LinkedHashMap<>();
    for (Map.Entry<String, YTPropertyDefinition> entry : node.getProperties().entrySet()) {
        QName type = entry.getValue().getType();
        buildPlan.put(entry.getKey(), entry.getValue().getType());
        // Add default YAML types
        if (type.getNamespaceURI().equals(Namespaces.YAML_NS)) {
            builder.addElements(entry.getKey(), entry.getValue());
        } else // if parameter.datatype is not defined and property type is defined in this schema -> add
        if (parameter.getDatatype() == null && type.getNamespaceURI().equals(parameter.getNamespace()) && this.localDatatypeNames.contains(type.getLocalPart())) {
            builder.addElements(entry.getKey(), entry.getValue());
        } else // if parameter.datatype is defined and property type is not in this service template
        if (!type.getNamespaceURI().equals(parameter.getNamespace()) || !this.localDatatypeNames.contains(type.getLocalPart())) {
            for (Map.Entry<String, YTImportDefinition> importDefinition : imports.get(type.getNamespaceURI())) {
                try {
                    YamlReader reader = new YamlReader();
                    YTServiceTemplate serviceTemplate = reader.parse(importDefinition.getValue(), parameter.getPath(), importDefinition.getValue().getNamespaceUri());
                    visit(serviceTemplate, new Parameter(parameter.getPath(), type.getNamespaceURI()).setDatatype(type).setBuildSchema(false));
                    // TODO getAbsoluteFilePath
                    builder.addImports(importDefinition.getValue().getNamespaceUri(), getRelativeFileName(importDefinition.getValue().getNamespaceUri()));
                    builder.addElements(entry.getKey(), entry.getValue());
                } catch (MultiException e) {
                    setException(e);
                }
            }
        } else // if parameter.datatype is defined and property type is in this service template but not read
        if (!(this.schemaTypes.containsKey(parameter.getNamespace()) && this.schemaTypes.get(parameter.getNamespace()).contains(type.getLocalPart()))) {
            this.data_types.get(type.getLocalPart()).accept(this, parameter.copy().addContext(type.getLocalPart()).setDatatype(type));
            builder.addElements(entry.getKey(), entry.getValue());
        }
    }
    this.addSchemaTypes(parameter.getNamespace(), parameter.getKey());
    this.propertyDefinition.put(new QName(parameter.getNamespace(), parameter.getKey()), buildPlan);
    if (parameter.getBuildComplexType()) {
        builder.buildComplexType(parameter.getKey(), false);
    }
    return null;
}
Also used : QName(javax.xml.namespace.QName) YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) YamlReader(org.eclipse.winery.repository.converter.reader.YamlReader) LinkedHashMap(java.util.LinkedHashMap) YTPropertyDefinition(org.eclipse.winery.model.tosca.yaml.YTPropertyDefinition) YTImportDefinition(org.eclipse.winery.model.tosca.yaml.YTImportDefinition) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap) MultiException(org.eclipse.winery.model.converter.support.exception.MultiException)

Example 15 with YTServiceTemplate

use of org.eclipse.winery.model.tosca.yaml.YTServiceTemplate in project winery by eclipse.

the class YamlReaderTest method testPolicyDefinitionsAsMap.

@Test
public void testPolicyDefinitionsAsMap() throws Exception {
    YamlReader reader = new YamlReader();
    InputStream is = getClass().getClassLoader().getResourceAsStream("yaml/simple-tests/wrong-policy-map-in-tt.yml");
    YTServiceTemplate template = reader.parse(is);
    Assertions.assertNotNull(template);
    YTTopologyTemplateDefinition topologyTemplate = template.getTopologyTemplate();
    Assertions.assertNotNull(topologyTemplate);
    Assertions.assertEquals(0, topologyTemplate.getPolicies().size());
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) YTTopologyTemplateDefinition(org.eclipse.winery.model.tosca.yaml.YTTopologyTemplateDefinition) YamlReader(org.eclipse.winery.repository.converter.reader.YamlReader) AbstractConverterTest(org.eclipse.winery.repository.converter.AbstractConverterTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

YTServiceTemplate (org.eclipse.winery.model.tosca.yaml.YTServiceTemplate)19 YamlReader (org.eclipse.winery.repository.converter.reader.YamlReader)10 MultiException (org.eclipse.winery.model.converter.support.exception.MultiException)9 InputStream (java.io.InputStream)7 FileInputStream (java.io.FileInputStream)6 AbstractConverterTest (org.eclipse.winery.repository.converter.AbstractConverterTest)5 Test (org.junit.jupiter.api.Test)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 Path (java.nio.file.Path)4 LinkedHashMap (java.util.LinkedHashMap)4 IOException (java.io.IOException)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 Map (java.util.Map)3 JAXBException (javax.xml.bind.JAXBException)3 YTArtifactDefinition (org.eclipse.winery.model.tosca.yaml.YTArtifactDefinition)3 YTTopologyTemplateDefinition (org.eclipse.winery.model.tosca.yaml.YTTopologyTemplateDefinition)3 YTMapImportDefinition (org.eclipse.winery.model.tosca.yaml.support.YTMapImportDefinition)3 YamlWriter (org.eclipse.winery.repository.converter.writer.YamlWriter)3 AbstractMap (java.util.AbstractMap)2 ArtifactTemplateId (org.eclipse.winery.model.ids.definitions.ArtifactTemplateId)2