Search in sources :

Example 1 with JsonNodeSerializer

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();
    }
}
Also used : IOException(java.io.IOException) JsonNodeSerializer(edu.stanford.protege.widgetmap.server.node.JsonNodeSerializer) File(java.io.File)

Example 2 with JsonNodeSerializer

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());
    }
}
Also used : Node(edu.stanford.protege.widgetmap.shared.node.Node) IOException(java.io.IOException) JsonNodeSerializer(edu.stanford.protege.widgetmap.server.node.JsonNodeSerializer) PerspectiveLayout(edu.stanford.bmir.protege.web.shared.perspective.PerspectiveLayout)

Aggregations

JsonNodeSerializer (edu.stanford.protege.widgetmap.server.node.JsonNodeSerializer)2 IOException (java.io.IOException)2 PerspectiveLayout (edu.stanford.bmir.protege.web.shared.perspective.PerspectiveLayout)1 Node (edu.stanford.protege.widgetmap.shared.node.Node)1 File (java.io.File)1