Search in sources :

Example 1 with ToCanonical

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

the class YamlRepository method convertToDefinitions.

/**
 * Reads service template from target path and converts it to XML Definition
 *
 * @param targetPath      target path of service template
 * @param id              id of requested Definition
 * @param targetNamespace targetNamespace of requested Definition
 * @return xml definitions
 */
private TDefinitions convertToDefinitions(Path targetPath, String id, String targetNamespace) throws IOException, MultiException {
    YTServiceTemplate serviceTemplate = readServiceTemplate(targetPath);
    ToCanonical converter = new ToCanonical(this);
    return converter.convert(serviceTemplate, id, targetNamespace, targetPath.endsWith("ServiceTemplate.tosca"));
}
Also used : YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) ToCanonical(org.eclipse.winery.repository.yaml.converter.ToCanonical)

Example 2 with ToCanonical

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

the class YamlCsarImporter method parseDefinitionsElement.

@Override
protected Optional<TDefinitions> parseDefinitionsElement(Path entryDefinitionsPath, final List<String> errors) {
    YamlReader reader = new YamlReader();
    YTServiceTemplate serviceTemplate;
    try {
        serviceTemplate = reader.parse(new FileInputStream(entryDefinitionsPath.toFile()));
        String name = serviceTemplate.getMetadata().get("name");
        if (name == null) {
            // fallback to filename
            name = entryDefinitionsPath.toString().substring(entryDefinitionsPath.toString().indexOf("__") + 2, entryDefinitionsPath.toString().indexOf(".tosca"));
        }
        ToCanonical converter = new ToCanonical(targetRepository);
        return Optional.of(converter.convert(serviceTemplate, name, serviceTemplate.getMetadata().get("targetNamespace"), true));
    } catch (MultiException | FileNotFoundException e) {
        e.printStackTrace();
        LOGGER.error("Could not read the given entry definition " + e.getMessage());
    }
    return Optional.empty();
}
Also used : YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) FileNotFoundException(java.io.FileNotFoundException) YamlReader(org.eclipse.winery.repository.converter.reader.YamlReader) ToCanonical(org.eclipse.winery.repository.yaml.converter.ToCanonical) MultiException(org.eclipse.winery.model.converter.support.exception.MultiException) FileInputStream(java.io.FileInputStream)

Aggregations

YTServiceTemplate (org.eclipse.winery.model.tosca.yaml.YTServiceTemplate)2 ToCanonical (org.eclipse.winery.repository.yaml.converter.ToCanonical)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 MultiException (org.eclipse.winery.model.converter.support.exception.MultiException)1 YamlReader (org.eclipse.winery.repository.converter.reader.YamlReader)1