Search in sources :

Example 11 with MultiException

use of org.eclipse.winery.model.converter.support.exception.MultiException in project winery by eclipse.

the class YamlReader method readServiceTemplate.

private YTServiceTemplate readServiceTemplate(Path path, Path file, String namespace) throws MultiException {
    Path filePath;
    if (Objects.isNull(path)) {
        filePath = file;
    } else {
        filePath = path.resolve(file);
    }
    if (!fileChanged(filePath)) {
        if (exceptionBuffer.containsKey(filePath)) {
            throw exceptionBuffer.get(filePath);
        }
        if (serviceTemplateBuffer.containsKey(filePath)) {
            return serviceTemplateBuffer.get(filePath);
        }
    }
    logger.debug("Read Service Template: {}", filePath);
    try {
        // pre parse checking
        try {
            ObjectValidator objectValidator = new ObjectValidator();
            objectValidator.validateObject(readObject(filePath));
        } catch (ConstructorException e) {
            ExceptionInterpreter interpreter = new ExceptionInterpreter();
            throw new MultiException().add(interpreter.interpret(e));
        } catch (ScannerException e) {
            ExceptionInterpreter interpreter = new ExceptionInterpreter();
            throw new MultiException().add(interpreter.interpret(e));
        } catch (YAMLParserException e) {
            throw new MultiException().add(e);
        }
        // parse checking
        YTServiceTemplate result = buildServiceTemplate(readObject(filePath), namespace);
        // post parse checking
        Validator validator = new Validator(path);
        validator.validate(result, namespace);
        serviceTemplateBuffer.put(filePath, result);
        return result;
    } catch (MultiException e) {
        exceptionBuffer.put(filePath, e);
        throw e.add(file.toString());
    }
}
Also used : Path(java.nio.file.Path) ScannerException(org.yaml.snakeyaml.scanner.ScannerException) ExceptionInterpreter(org.eclipse.winery.repository.converter.validator.support.ExceptionInterpreter) YAMLParserException(org.eclipse.winery.model.converter.support.exception.YAMLParserException) YTServiceTemplate(org.eclipse.winery.model.tosca.yaml.YTServiceTemplate) ObjectValidator(org.eclipse.winery.repository.converter.validator.ObjectValidator) ConstructorException(org.yaml.snakeyaml.constructor.ConstructorException) MultiException(org.eclipse.winery.model.converter.support.exception.MultiException) Validator(org.eclipse.winery.repository.converter.validator.Validator) ObjectValidator(org.eclipse.winery.repository.converter.validator.ObjectValidator)

Aggregations

MultiException (org.eclipse.winery.model.converter.support.exception.MultiException)11 YTServiceTemplate (org.eclipse.winery.model.tosca.yaml.YTServiceTemplate)6 YamlReader (org.eclipse.winery.repository.converter.reader.YamlReader)5 IOException (java.io.IOException)3 Path (java.nio.file.Path)3 TDefinitions (org.eclipse.winery.model.tosca.TDefinitions)3 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2 InputStream (java.io.InputStream)2 AbstractMap (java.util.AbstractMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Map (java.util.Map)2 QName (javax.xml.namespace.QName)2 TArtifactTemplate (org.eclipse.winery.model.tosca.TArtifactTemplate)2 YTImportDefinition (org.eclipse.winery.model.tosca.yaml.YTImportDefinition)2 ObjectValidator (org.eclipse.winery.repository.converter.validator.ObjectValidator)2 ExceptionInterpreter (org.eclipse.winery.repository.converter.validator.support.ExceptionInterpreter)2 Parameter (org.eclipse.winery.repository.converter.validator.support.Parameter)2 ConstructorException (org.yaml.snakeyaml.constructor.ConstructorException)2 ScannerException (org.yaml.snakeyaml.scanner.ScannerException)2