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;
}
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);
}
}
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());
}
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());
}
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));
}
}
Aggregations