use of edu.stanford.protege.widgetmap.server.node.JsonNodeSerializer in project webprotege by protegeproject.
the class PerspectiveLayoutStoreImpl method setPerspectiveLayout.
@Override
public void setPerspectiveLayout(@Nonnull ProjectId projectId, @Nonnull UserId userId, @Nonnull PerspectiveLayout layout) {
File file = perspectiveFileManager.getPerspectiveLayoutForUser(projectId, layout.getPerspectiveId(), userId);
if (layout.getRootNode().isPresent()) {
try {
file.getParentFile().mkdirs();
JsonNodeSerializer serializer = new JsonNodeSerializer();
String serialization = serializer.serialize(layout.getRootNode().get());
Files.write(serialization.getBytes(Charsets.UTF_8), file);
} catch (IOException e) {
logger.error("An error occurred whilst writing the perspective: {} {} {}", projectId, userId, projectId, e);
}
} else {
file.delete();
}
}
use of edu.stanford.protege.widgetmap.server.node.JsonNodeSerializer in project webprotege by protegeproject.
the class PerspectiveLayoutStoreImpl method getPerspectiveLayoutFromFile.
private PerspectiveLayout getPerspectiveLayoutFromFile(PerspectiveId perspectiveId, File layoutFile) {
try {
if (layoutFile.exists()) {
String serialization = Files.toString(layoutFile, Charset.forName("utf-8"));
Node node = new JsonNodeSerializer().deserialize(serialization);
return new PerspectiveLayout(perspectiveId, Optional.of(node));
} else {
return new PerspectiveLayout(perspectiveId, Optional.empty());
}
} catch (IOException e) {
return new PerspectiveLayout(perspectiveId, Optional.empty());
}
}
Aggregations