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;
}
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");
}
}
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();
}
}
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();
}
}
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();
}
}
Aggregations