Search in sources :

Example 1 with YamlWriter

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

the class YamlRepository method convertToServiceTemplate.

/**
 * Reads xml definition input stream converts it to yaml service template and writes it to input stream
 *
 * @param ref         Repository File Reference
 * @param inputStream Input Stream
 * @return yaml service template input stream
 */
@Deprecated
private InputStream convertToServiceTemplate(RepositoryFileReference ref, InputStream inputStream, MediaType mediaType) {
    if (!mediaType.equals(MediaTypes.MEDIATYPE_TOSCA_DEFINITIONS)) {
        // do not modify content that's not a TOSCA_DEFINITIONS file
        return inputStream;
    }
    // ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    try {
        // IOUtils.copy(inputStream, outputStream);
        // Definitions definitions = readInputStream(new ByteArrayInputStream(outputStream.toByteArray()));
        TDefinitions definitions = (TDefinitions) JAXBSupport.createUnmarshaller().unmarshal(inputStream);
        YTServiceTemplate serviceTemplate = convertToYamlModel(ref, definitions);
        YamlWriter writer = new YamlWriter();
        return writer.writeToInputStream(serviceTemplate);
    } catch (Exception e) {
        LOGGER.error("Error converting service template. Reason: {}", e.getMessage(), e);
    }
    return null;
}
Also used : YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) TDefinitions(org.eclipse.winery.model.tosca.TDefinitions) 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 2 with YamlWriter

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

the class YamlRepository method putDefinition.

@Override
public void putDefinition(RepositoryFileReference ref, TDefinitions content) {
    try {
        YTServiceTemplate yaml = convertToYamlModel(ref, content);
        YamlWriter writer = new YamlWriter();
        writer.write(yaml, ref2AbsolutePath(ref));
    } catch (Exception e) {
        LOGGER.error("Error converting service template. Reason: {}", e.getMessage(), e);
    }
}
Also used : 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 3 with YamlWriter

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

the class YAMLDefinitionsBasedCsarEntry method writeToOutputStream.

@Override
public void writeToOutputStream(OutputStream outputStream) throws IOException {
    YamlWriter writer = new YamlWriter();
    outputStream.write(writer.visit(definitions, new YamlWriter.Parameter(0)).toString().getBytes());
}
Also used : YamlWriter(org.eclipse.winery.repository.converter.writer.YamlWriter)

Example 4 with YamlWriter

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

the class YamlRepository method serialize.

private void serialize(YTServiceTemplate definitions, OutputStream target) throws IOException {
    YamlWriter writer = new YamlWriter();
    target.write(writer.visit(definitions, new YamlWriter.Parameter(0)).toString().getBytes());
}
Also used : YamlWriter(org.eclipse.winery.repository.converter.writer.YamlWriter)

Example 5 with YamlWriter

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

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