Search in sources :

Example 6 with YamlWriter

use of org.eclipse.winery.repository.converter.writer.YamlWriter in project winery by eclipse.

the class YamlWriterTests method testPropertyAssignmentSerialization.

@ParameterizedTest
@ArgumentsSource(PropertyAssignmentArgumentsProvider.class)
public void testPropertyAssignmentSerialization(YTPropertyAssignment prop, String expected) {
    YamlWriter writer = new YamlWriter();
    YamlPrinter p = writer.visit(prop, new YamlWriter.Parameter(0).addContext("root"));
    assertEquals(expected, p.toString());
}
Also used : YamlPrinter(org.eclipse.winery.repository.converter.writer.YamlPrinter) YamlWriter(org.eclipse.winery.repository.converter.writer.YamlWriter) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 7 with YamlWriter

use of org.eclipse.winery.repository.converter.writer.YamlWriter in project winery by eclipse.

the class YamlWriterTests method testConstraintClauses.

@ParameterizedTest
@ArgumentsSource(ConstraintClausesArgumentsProvider.class)
public void testConstraintClauses(YTConstraintClause constraint, String expected) {
    YamlWriter writer = new YamlWriter();
    YamlPrinter p = writer.visit(constraint, new YamlWriter.Parameter(0).addContext("root"));
    assertEquals(expected, p.toString());
}
Also used : YamlPrinter(org.eclipse.winery.repository.converter.writer.YamlPrinter) YamlWriter(org.eclipse.winery.repository.converter.writer.YamlWriter) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 8 with YamlWriter

use of org.eclipse.winery.repository.converter.writer.YamlWriter in project winery by eclipse.

the class YamlWriterTests method testTopologyTemplateContent.

@ParameterizedTest
@ArgumentsSource(ServiceTmpltTopologyTmpltProvider.class)
public void testTopologyTemplateContent(YTServiceTemplate serv, String expected) {
    YamlWriter writer = new YamlWriter();
    YamlPrinter p = writer.visit(serv, new YamlWriter.Parameter(0).addContext("root"));
    assertEquals(expected, p.toString());
}
Also used : YamlPrinter(org.eclipse.winery.repository.converter.writer.YamlPrinter) YamlWriter(org.eclipse.winery.repository.converter.writer.YamlWriter) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) ArgumentsSource(org.junit.jupiter.params.provider.ArgumentsSource)

Example 9 with YamlWriter

use of org.eclipse.winery.repository.converter.writer.YamlWriter 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 10 with YamlWriter

use of org.eclipse.winery.repository.converter.writer.YamlWriter in project winery by eclipse.

the class YAMLDefinitionsBasedCsarEntry method getInputStream.

@Override
public InputStream getInputStream() throws IOException {
    YamlWriter writer = new YamlWriter();
    InputStream is = writer.writeToInputStream(definitions);
    if (Objects.nonNull(is)) {
        return is;
    }
    throw new IOException("Failed to convert XML to YAML");
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) YamlWriter(org.eclipse.winery.repository.converter.writer.YamlWriter)

Aggregations

YamlWriter (org.eclipse.winery.repository.converter.writer.YamlWriter)14 YamlPrinter (org.eclipse.winery.repository.converter.writer.YamlPrinter)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 ArgumentsSource (org.junit.jupiter.params.provider.ArgumentsSource)7 IOException (java.io.IOException)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 JAXBException (javax.xml.bind.JAXBException)3 MultiException (org.eclipse.winery.model.converter.support.exception.MultiException)3 YTServiceTemplate (org.eclipse.winery.model.tosca.yaml.YTServiceTemplate)3 InputStream (java.io.InputStream)2 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)2 Path (java.nio.file.Path)1 GenericId (org.eclipse.winery.model.ids.GenericId)1 DefinitionsChildId (org.eclipse.winery.model.ids.definitions.DefinitionsChildId)1 YTArtifactDefinition (org.eclipse.winery.model.tosca.yaml.YTArtifactDefinition)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 YamlRepository (org.eclipse.winery.repository.yaml.YamlRepository)1 FromCanonical (org.eclipse.winery.repository.yaml.converter.FromCanonical)1