Search in sources :

Example 1 with InvalidToscaSyntax

use of org.eclipse.winery.model.converter.support.exception.InvalidToscaSyntax 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);
}
Also used : ScannerException(org.yaml.snakeyaml.scanner.ScannerException) ExceptionInterpreter(org.eclipse.winery.repository.converter.validator.support.ExceptionInterpreter) InvalidToscaSyntax(org.eclipse.winery.model.converter.support.exception.InvalidToscaSyntax) ObjectValidator(org.eclipse.winery.repository.converter.validator.ObjectValidator) ConstructorException(org.yaml.snakeyaml.constructor.ConstructorException) MultiException(org.eclipse.winery.model.converter.support.exception.MultiException)

Example 2 with InvalidToscaSyntax

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

the class ObjectValidator method validateObject.

public void validateObject(Object object) throws InvalidToscaSyntax {
    if (object instanceof LinkedHashMap) {
        LinkedHashMap map = (LinkedHashMap) object;
        Set<Map.Entry> entries = map.entrySet();
        if (entries.size() == 0 || !entries.iterator().next().getKey().equals("tosca_definitions_version")) {
            for (Map.Entry entry : entries) {
                if (entry.getKey().equals("tosca_definitions_version")) {
                    throw new InvalidToscaSyntax("The field tosca_definitions_version MUST be defined before all other YAML elements");
                }
            }
        }
    }
}
Also used : InvalidToscaSyntax(org.eclipse.winery.model.converter.support.exception.InvalidToscaSyntax) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

InvalidToscaSyntax (org.eclipse.winery.model.converter.support.exception.InvalidToscaSyntax)2 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 MultiException (org.eclipse.winery.model.converter.support.exception.MultiException)1 ObjectValidator (org.eclipse.winery.repository.converter.validator.ObjectValidator)1 ExceptionInterpreter (org.eclipse.winery.repository.converter.validator.support.ExceptionInterpreter)1 ConstructorException (org.yaml.snakeyaml.constructor.ConstructorException)1 ScannerException (org.yaml.snakeyaml.scanner.ScannerException)1