use of org.eclipse.winery.repository.converter.validator.ObjectValidator in project winery by eclipse.
the class YamlReader method readServiceTemplate.
/**
* Reads a file and converts it to a ServiceTemplate
*
* @return ServiceTemplate
* @throws MultiException the ServiceTemplate or the file is invalid.
*/
private YTServiceTemplate readServiceTemplate(InputStream inputStream, String namespace) throws MultiException {
Object object = null;
// pre parse checking
try {
object = readObjectFromInputStream(inputStream);
ObjectValidator objectValidator = new ObjectValidator();
objectValidator.validateObject(object);
} 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 (InvalidToscaSyntax invalidToscaSyntax) {
invalidToscaSyntax.printStackTrace();
}
// parse checking
return buildServiceTemplate(object, namespace);
}
use of org.eclipse.winery.repository.converter.validator.ObjectValidator 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());
}
}
Aggregations