Search in sources :

Example 16 with ReadException

use of com.developmentontheedge.be5.metadata.exception.ReadException in project be5 by DevelopmentOnTheEdge.

the class Templates method getTemplatesProject.

public static Project getTemplatesProject() throws ReadException {
    Project prj = new Project(TEMPLATES_PROJECT_NAME, true);
    LoadContext lc = new LoadContext();
    for (String template : TEMPLATES) {
        URL url = Templates.class.getResource("templates/" + template + ".yaml");
        Node content;
        try (InputStream is = url.openStream()) {
            content = new Yaml().compose(new InputStreamReader(is, StandardCharsets.UTF_8));
        } catch (MarkedYAMLException e) {
            throw new ReadException(new Exception((e.getProblemMark().getLine() + 1) + ":" + (e.getProblemMark().getColumn() + 1) + ": " + e.getMessage()), getPath(url), ReadException.LEE_INVALID_STRUCTURE);
        } catch (YAMLException | IOException e) {
            throw new ReadException(new Exception(e.getMessage()), getPath(url), ReadException.LEE_INVALID_STRUCTURE);
        }
        try {
            Object obj = Serialization.derepresent(content);
            @SuppressWarnings("unchecked") Map<String, Object> root = (Map<String, Object>) obj;
            @SuppressWarnings("unchecked") Map<String, Object> entityContent = (Map<String, Object>) root.get(template);
            DataElementUtils.saveQuiet(YamlDeserializer.readEntity(lc, template, entityContent, prj.getApplication()));
        } catch (RuntimeException e) {
            throw new ReadException(e, getPath(url), ReadException.LEE_INTERNAL_ERROR);
        }
        lc.check();
    }
    return prj;
}
Also used : InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) Node(org.yaml.snakeyaml.nodes.Node) MarkedYAMLException(org.yaml.snakeyaml.error.MarkedYAMLException) YAMLException(org.yaml.snakeyaml.error.YAMLException) MarkedYAMLException(org.yaml.snakeyaml.error.MarkedYAMLException) IOException(java.io.IOException) URL(java.net.URL) Yaml(org.yaml.snakeyaml.Yaml) FileSystemNotFoundException(java.nio.file.FileSystemNotFoundException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ReadException(com.developmentontheedge.be5.metadata.exception.ReadException) MarkedYAMLException(org.yaml.snakeyaml.error.MarkedYAMLException) YAMLException(org.yaml.snakeyaml.error.YAMLException) ReadException(com.developmentontheedge.be5.metadata.exception.ReadException) LoadContext(com.developmentontheedge.be5.metadata.serialization.LoadContext) Map(java.util.Map)

Example 17 with ReadException

use of com.developmentontheedge.be5.metadata.exception.ReadException in project be5 by DevelopmentOnTheEdge.

the class Icon method load.

public void load() throws ReadException {
    Path iconsFile = null;
    try {
        switch(source) {
            case SOURCE_PROJECT:
                iconsFile = getProjectFileSystem().getIconsFile(name);
                data = Files.readAllBytes(iconsFile);
                break;
            case SOURCE_BE:
                data = getBeIcon();
                break;
            default:
                data = null;
        }
    } catch (IOException e) {
        throw new ReadException(e, getOwner(), iconsFile, "Unable to load icon");
    }
}
Also used : Path(java.nio.file.Path) ReadException(com.developmentontheedge.be5.metadata.exception.ReadException) IOException(java.io.IOException)

Example 18 with ReadException

use of com.developmentontheedge.be5.metadata.exception.ReadException in project be5 by DevelopmentOnTheEdge.

the class Serialization method reloadEntity.

public static Entity reloadEntity(final Entity oldEntity) throws ReadException {
    checkProject(oldEntity.getProject());
    turnOffAutomaticSerialization();
    try {
        return new YamlDeserializer(new LoadContext()).reloadEntity(oldEntity);
    } finally {
        turnOnAutomaticSerialization();
    }
}
Also used : YamlDeserializer(com.developmentontheedge.be5.metadata.serialization.yaml.YamlDeserializer)

Example 19 with ReadException

use of com.developmentontheedge.be5.metadata.exception.ReadException in project be5 by DevelopmentOnTheEdge.

the class Serialization method reloadDaemons.

public static Daemons reloadDaemons(final Path file, final Module target) throws ReadException {
    checkProject(target.getProject());
    turnOffAutomaticSerialization();
    try {
        return new YamlDeserializer(new LoadContext()).reloadDaemons(file, target);
    } finally {
        turnOnAutomaticSerialization();
    }
}
Also used : YamlDeserializer(com.developmentontheedge.be5.metadata.serialization.yaml.YamlDeserializer)

Example 20 with ReadException

use of com.developmentontheedge.be5.metadata.exception.ReadException in project be5 by DevelopmentOnTheEdge.

the class Serialization method load.

/**
 * @param root
 * @param fuseTemplates whether to fuse templates into entities (useful for modules loading)
 * @param loadContext
 * @return
 * @throws ProjectLoadException
 * @see Serialization#canBeLoaded(Path)
 */
public static Project load(final Path root, final boolean fuseTemplates, final LoadContext loadContext) throws ProjectLoadException {
    Objects.requireNonNull(root);
    turnOffAutomaticSerialization();
    try {
        return new YamlDeserializer(loadContext == null ? new LoadContext() : loadContext, fuseTemplates).readProject(root);
    } catch (final ReadException e) {
        throw new ProjectLoadException(root, e);
    } finally {
        turnOnAutomaticSerialization();
    }
}
Also used : ReadException(com.developmentontheedge.be5.metadata.exception.ReadException) ProjectLoadException(com.developmentontheedge.be5.metadata.exception.ProjectLoadException) YamlDeserializer(com.developmentontheedge.be5.metadata.serialization.yaml.YamlDeserializer)

Aggregations

YamlDeserializer (com.developmentontheedge.be5.metadata.serialization.yaml.YamlDeserializer)10 ReadException (com.developmentontheedge.be5.metadata.exception.ReadException)9 Map (java.util.Map)5 IOException (java.io.IOException)4 Entity (com.developmentontheedge.be5.metadata.model.Entity)3 Path (java.nio.file.Path)3 BeConnectionProfile (com.developmentontheedge.be5.metadata.model.BeConnectionProfile)2 BeModelElement (com.developmentontheedge.be5.metadata.model.base.BeModelElement)2 DataElementPath (com.developmentontheedge.be5.metadata.model.base.DataElementPath)2 LinkedHashMap (java.util.LinkedHashMap)2 MarkedYAMLException (org.yaml.snakeyaml.error.MarkedYAMLException)2 YAMLException (org.yaml.snakeyaml.error.YAMLException)2 FreemarkerSqlException (com.developmentontheedge.be5.metadata.exception.FreemarkerSqlException)1 ProcessInterruptedException (com.developmentontheedge.be5.metadata.exception.ProcessInterruptedException)1 ProjectLoadException (com.developmentontheedge.be5.metadata.exception.ProjectLoadException)1 BeConnectionProfiles (com.developmentontheedge.be5.metadata.model.BeConnectionProfiles)1 ColumnDef (com.developmentontheedge.be5.metadata.model.ColumnDef)1 Daemons (com.developmentontheedge.be5.metadata.model.Daemons)1 DataElementUtils (com.developmentontheedge.be5.metadata.model.DataElementUtils)1 DdlElement (com.developmentontheedge.be5.metadata.model.DdlElement)1