Search in sources :

Example 1 with Parameter

use of org.eclipse.winery.repository.converter.validator.support.Parameter in project winery by eclipse.

the class DefinitionValidator method validate.

public void validate(YTServiceTemplate serviceTemplate) throws MultiException {
    serviceTemplate.accept(definitionsVisitor, new Parameter());
    serviceTemplate.accept(this, new Parameter());
    if (hasExceptions()) {
        throw getException();
    }
}
Also used : Parameter(org.eclipse.winery.repository.converter.validator.support.Parameter)

Example 2 with Parameter

use of org.eclipse.winery.repository.converter.validator.support.Parameter in project winery by eclipse.

the class ImportVisitor method visit.

@Override
public Result visit(YTServiceTemplate node, Parameter parameter) {
    YamlReader reader = new YamlReader();
    if (!this.namespace.equals(Namespaces.TOSCA_YAML_NS)) {
        Set<String> typeDefinitions = new HashSet<>(Arrays.asList(Defaults.TOSCA_NORMATIVE_TYPES, Defaults.TOSCA_NONNORMATIVE_TYPES));
        String tmpNamespace = this.namespace;
        this.namespace = Namespaces.TOSCA_YAML_NS;
        Path tmpDir = Utils.getTmpDir(Paths.get("types"));
        for (String typeDefinition : typeDefinitions) {
            try {
                Path outFilePath = tmpDir.resolve(typeDefinition);
                InputStream inputStream = this.getClass().getResourceAsStream(// Do not use File.separator here (https://stackoverflow.com/a/41677152/8235252)
                "/".concat(typeDefinition));
                Files.copy(inputStream, outFilePath, StandardCopyOption.REPLACE_EXISTING);
                YTServiceTemplate serviceTemplate = reader.parseSkipTest(outFilePath, Namespaces.TOSCA_YAML_NS);
                if (Objects.nonNull(serviceTemplate)) {
                    serviceTemplate.accept(this, new Parameter());
                }
            } catch (MultiException e) {
                setException(e);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        this.namespace = tmpNamespace;
    }
    super.visit(node, parameter);
    return null;
}
Also used : Path(java.nio.file.Path) InputStream(java.io.InputStream) YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) Parameter(org.eclipse.winery.repository.converter.validator.support.Parameter) YamlReader(org.eclipse.winery.repository.converter.reader.YamlReader) MultiException(org.eclipse.winery.model.converter.support.exception.MultiException) MultiException(org.eclipse.winery.model.converter.support.exception.MultiException) HashSet(java.util.HashSet)

Example 3 with Parameter

use of org.eclipse.winery.repository.converter.validator.support.Parameter in project winery by eclipse.

the class TypeValidator method validate.

public void validate(YTServiceTemplate serviceTemplate) throws MultiException {
    serviceTemplate.accept(typeVisitor, new Parameter());
    if (typeVisitor.hasExceptions()) {
        this.setException(this.typeVisitor.getException());
    }
    serviceTemplate.accept(this, new Parameter());
    if (this.hasExceptions()) {
        throw this.getException();
    }
}
Also used : Parameter(org.eclipse.winery.repository.converter.validator.support.Parameter)

Example 4 with Parameter

use of org.eclipse.winery.repository.converter.validator.support.Parameter in project winery by eclipse.

the class Validator method validate.

public void validate(YTServiceTemplate serviceTemplate, String namespace) throws MultiException {
    if (Objects.isNull(serviceTemplate))
        return;
    TypeValidator typeValidator = new TypeValidator(path, namespace);
    typeValidator.validate(serviceTemplate);
    DefinitionValidator definitionValidator = new DefinitionValidator(path);
    definitionValidator.validate(serviceTemplate);
    serviceTemplate.accept(this, new Parameter());
    if (this.hasExceptions())
        throw this.getException();
}
Also used : Parameter(org.eclipse.winery.repository.converter.validator.support.Parameter)

Example 5 with Parameter

use of org.eclipse.winery.repository.converter.validator.support.Parameter in project winery by eclipse.

the class ImportVisitor method visit.

@Override
public Result visit(YTImportDefinition node, Parameter parameter) {
    YamlReader reader = new YamlReader();
    String importNamespace = node.getNamespaceUri() == null ? this.namespace : node.getNamespaceUri();
    try {
        YTServiceTemplate serviceTemplate = reader.parse(node, path, importNamespace);
        if (serviceTemplate != null) {
            String tmpNamespace = this.namespace;
            this.namespace = importNamespace;
            this.visit(serviceTemplate, new Parameter());
            this.namespace = tmpNamespace;
        }
        super.visit(node, parameter);
    } catch (MultiException e) {
        this.setException(e);
    }
    return null;
}
Also used : YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) Parameter(org.eclipse.winery.repository.converter.validator.support.Parameter) YamlReader(org.eclipse.winery.repository.converter.reader.YamlReader) MultiException(org.eclipse.winery.model.converter.support.exception.MultiException)

Aggregations

Parameter (org.eclipse.winery.repository.converter.validator.support.Parameter)5 MultiException (org.eclipse.winery.model.converter.support.exception.MultiException)2 YTServiceTemplate (org.eclipse.winery.model.tosca.yaml.YTServiceTemplate)2 YamlReader (org.eclipse.winery.repository.converter.reader.YamlReader)2 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1