From b79eeaf11313dcb95fe7fa71aeeb53b4b646f4f0 Mon Sep 17 00:00:00 2001 From: NOIR Nicolas ext Date: Tue, 11 Jun 2019 10:43:41 +0200 Subject: [PATCH] Addition of access rights on AFS nodes (#827) Signed-off-by: NOIR Nicolas ext --- .../action/dsl/afs/ActionScriptBuilder.java | 3 +- .../src/main/java/com/powsybl/afs/Folder.java | 7 +- .../java/com/powsybl/afs/ProjectFolder.java | 3 +- .../powsybl/afs/AppFileSystemToolTest.java | 4 +- .../com/powsybl/afs/DependencyCacheTest.java | 5 +- .../java/com/powsybl/afs/FooFileBuilder.java | 3 +- .../afs/ext/base/ImportedCaseBuilder.java | 3 +- .../ext/base/ModificationScriptBuilder.java | 3 +- .../afs/ext/base/VirtualCaseBuilder.java | 3 +- .../afs/ext/base/ImportedCaseTest.java | 4 +- .../powsybl/afs/ext/base/VirtualCaseTest.java | 3 +- .../afs/local/storage/LocalAppStorage.java | 16 ++-- .../powsybl/afs/local/storage/LocalCase.java | 6 ++ .../powsybl/afs/local/storage/LocalFile.java | 3 + .../afs/mapdb/storage/MapDbAppStorage.java | 6 +- .../afs/mapdb/storage/NodeInfoSerializer.java | 32 +++++++- .../com/powsybl/afs/storage/AppStorage.java | 2 +- .../afs/storage/AppStorageArchive.java | 2 +- .../storage/DefaultListenableAppStorage.java | 4 +- .../afs/storage/ForwardingAppStorage.java | 4 +- .../powsybl/afs/storage/NodeAccessRights.java | 82 +++++++++++++++++++ .../com/powsybl/afs/storage/NodeInfo.java | 15 +++- .../storage/json/AppStorageJsonModule.java | 3 + .../NodeAccessRightsJsonDeserializer.java | 74 +++++++++++++++++ .../json/NodeAccessRightsJsonSerializer.java | 52 ++++++++++++ .../json/NodeInfoJsonDeserializer.java | 10 ++- .../storage/json/NodeInfoJsonSerializer.java | 3 + .../AbstractAppStorageArchiveTest.java | 8 +- .../afs/storage/AbstractAppStorageTest.java | 30 +++---- .../DefaultListenableAppStorageTest.java | 6 +- .../afs/storage/NodeDependencyTest.java | 4 +- .../com/powsybl/afs/storage/NodeInfoTest.java | 3 +- .../afs/ws/server/AppStorageServer.java | 7 +- .../afs/ws/storage/RemoteAppStorage.java | 8 +- .../afs/ContingencyStoreBuilder.java | 3 +- .../groovy/AbstractGroovyScriptTest.java | 2 +- .../afs/SecurityAnalysisRunnerBuilder.java | 3 +- .../afs/SecurityAnalysisRunnerTest.java | 5 +- 38 files changed, 358 insertions(+), 76 deletions(-) create mode 100644 afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/NodeAccessRights.java create mode 100644 afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/json/NodeAccessRightsJsonDeserializer.java create mode 100644 afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/json/NodeAccessRightsJsonSerializer.java diff --git a/action/action-dsl/src/main/java/com/powsybl/action/dsl/afs/ActionScriptBuilder.java b/action/action-dsl/src/main/java/com/powsybl/action/dsl/afs/ActionScriptBuilder.java index b029596a876..915865f2714 100644 --- a/action/action-dsl/src/main/java/com/powsybl/action/dsl/afs/ActionScriptBuilder.java +++ b/action/action-dsl/src/main/java/com/powsybl/action/dsl/afs/ActionScriptBuilder.java @@ -11,6 +11,7 @@ import com.powsybl.afs.ProjectFileBuildContext; import com.powsybl.afs.ProjectFileBuilder; import com.powsybl.afs.ProjectFileCreationContext; +import com.powsybl.afs.storage.NodeAccessRights; import com.powsybl.afs.storage.NodeGenericMetadata; import com.powsybl.afs.storage.NodeInfo; @@ -59,7 +60,7 @@ public ActionScript build() { // create project file NodeInfo info = context.getStorage().createNode(context.getFolderInfo().getId(), name, ActionScript.PSEUDO_CLASS, "", ActionScript.VERSION, - new NodeGenericMetadata()); + new NodeGenericMetadata(), new NodeAccessRights()); // store script try (Reader reader = new StringReader(content); diff --git a/afs/afs-core/src/main/java/com/powsybl/afs/Folder.java b/afs/afs-core/src/main/java/com/powsybl/afs/Folder.java index da7449b17a0..b800d6d855f 100644 --- a/afs/afs-core/src/main/java/com/powsybl/afs/Folder.java +++ b/afs/afs-core/src/main/java/com/powsybl/afs/Folder.java @@ -7,6 +7,7 @@ package com.powsybl.afs; import com.powsybl.afs.storage.AppStorageArchive; +import com.powsybl.afs.storage.NodeAccessRights; import com.powsybl.afs.storage.NodeGenericMetadata; import com.powsybl.afs.storage.NodeInfo; @@ -87,7 +88,7 @@ public Optional getFolder(String name, String... more) { public Folder createFolder(String name) { NodeInfo folderInfo = storage.getChildNode(info.getId(), name) .orElseGet(() -> { - NodeInfo newFolderInfo = storage.createNode(info.getId(), name, PSEUDO_CLASS, "", VERSION, new NodeGenericMetadata()); + NodeInfo newFolderInfo = storage.createNode(info.getId(), name, PSEUDO_CLASS, "", VERSION, new NodeGenericMetadata(), new NodeAccessRights()); storage.setConsistent(newFolderInfo.getId()); storage.flush(); return newFolderInfo; @@ -102,10 +103,10 @@ public Folder createFolder(String name) { public Project createProject(String name) { NodeInfo projectInfo = storage.getChildNode(info.getId(), name) .orElseGet(() -> { - NodeInfo newProjectInfo = storage.createNode(info.getId(), name, Project.PSEUDO_CLASS, "", Project.VERSION, new NodeGenericMetadata()); + NodeInfo newProjectInfo = storage.createNode(info.getId(), name, Project.PSEUDO_CLASS, "", Project.VERSION, new NodeGenericMetadata(), new NodeAccessRights()); storage.setConsistent(newProjectInfo.getId()); // create root project folder - NodeInfo newProjectInfoRootFolder = storage.createNode(newProjectInfo.getId(), Project.ROOT_FOLDER_NAME, ProjectFolder.PSEUDO_CLASS, "", ProjectFolder.VERSION, new NodeGenericMetadata()); + NodeInfo newProjectInfoRootFolder = storage.createNode(newProjectInfo.getId(), Project.ROOT_FOLDER_NAME, ProjectFolder.PSEUDO_CLASS, "", ProjectFolder.VERSION, new NodeGenericMetadata(), new NodeAccessRights()); storage.setConsistent(newProjectInfoRootFolder.getId()); storage.flush(); return newProjectInfo; diff --git a/afs/afs-core/src/main/java/com/powsybl/afs/ProjectFolder.java b/afs/afs-core/src/main/java/com/powsybl/afs/ProjectFolder.java index 0bcb2e98b6d..6cd0c87999e 100644 --- a/afs/afs-core/src/main/java/com/powsybl/afs/ProjectFolder.java +++ b/afs/afs-core/src/main/java/com/powsybl/afs/ProjectFolder.java @@ -6,6 +6,7 @@ */ package com.powsybl.afs; +import com.powsybl.afs.storage.NodeAccessRights; import com.powsybl.afs.storage.NodeGenericMetadata; import com.powsybl.afs.storage.NodeInfo; import com.powsybl.afs.storage.events.AppStorageListener; @@ -108,7 +109,7 @@ public Optional getFolder(String name, String... more) { public ProjectFolder createFolder(String name) { NodeInfo folderInfo = storage.getChildNode(info.getId(), name) .orElseGet(() -> { - NodeInfo newFolderInfo = storage.createNode(ProjectFolder.this.info.getId(), name, PSEUDO_CLASS, "", VERSION, new NodeGenericMetadata()); + NodeInfo newFolderInfo = storage.createNode(ProjectFolder.this.info.getId(), name, PSEUDO_CLASS, "", VERSION, new NodeGenericMetadata(), new NodeAccessRights()); storage.setConsistent(newFolderInfo.getId()); storage.flush(); return newFolderInfo; diff --git a/afs/afs-core/src/test/java/com/powsybl/afs/AppFileSystemToolTest.java b/afs/afs-core/src/test/java/com/powsybl/afs/AppFileSystemToolTest.java index 8aeabf58d4e..954153a3fb7 100644 --- a/afs/afs-core/src/test/java/com/powsybl/afs/AppFileSystemToolTest.java +++ b/afs/afs-core/src/test/java/com/powsybl/afs/AppFileSystemToolTest.java @@ -8,6 +8,7 @@ import com.powsybl.afs.mapdb.storage.MapDbAppStorage; import com.powsybl.afs.storage.AppStorage; +import com.powsybl.afs.storage.NodeAccessRights; import com.powsybl.afs.storage.NodeGenericMetadata; import com.powsybl.computation.ComputationManager; import com.powsybl.tools.AbstractToolTest; @@ -44,7 +45,8 @@ protected AppData createAppData(ToolRunningContext context) { afs.getRootFolder().createProject("test_project1"); afs.getRootFolder().createProject("test_project2"); storage.createNode(afs.getRootFolder().getId(), "test", FOLDER_PSEUDO_CLASS, "", 0, - new NodeGenericMetadata().setString("k", "v")); + new NodeGenericMetadata().setString("k", "v"), + new NodeAccessRights()); storage.flush(); return appData; } diff --git a/afs/afs-core/src/test/java/com/powsybl/afs/DependencyCacheTest.java b/afs/afs-core/src/test/java/com/powsybl/afs/DependencyCacheTest.java index df878516aa2..b6b76bdfdaf 100644 --- a/afs/afs-core/src/test/java/com/powsybl/afs/DependencyCacheTest.java +++ b/afs/afs-core/src/test/java/com/powsybl/afs/DependencyCacheTest.java @@ -9,6 +9,7 @@ import com.google.common.collect.ImmutableList; import com.powsybl.afs.mapdb.storage.MapDbAppStorage; import com.powsybl.afs.storage.AppStorage; +import com.powsybl.afs.storage.NodeAccessRights; import com.powsybl.afs.storage.NodeGenericMetadata; import com.powsybl.afs.storage.NodeInfo; import org.junit.Test; @@ -48,7 +49,7 @@ public TicBuilder setName(String name) { @Override public Tic build() { - NodeInfo info = context.getStorage().createNode(context.getFolderInfo().getId(), name, "TIC", "", 0, new NodeGenericMetadata()); + NodeInfo info = context.getStorage().createNode(context.getFolderInfo().getId(), name, "TIC", "", 0, new NodeGenericMetadata(), new NodeAccessRights()); context.getStorage().setConsistent(info.getId()); return new Tic(new ProjectFileCreationContext(info, context.getStorage(), context.getProject())); } @@ -112,7 +113,7 @@ class TacBuilder implements ProjectFileBuilder { @Override public Tac build() { - NodeInfo info = context.getStorage().createNode(context.getFolderInfo().getId(), "tac", "TAC", "", 0, new NodeGenericMetadata()); + NodeInfo info = context.getStorage().createNode(context.getFolderInfo().getId(), "tac", "TAC", "", 0, new NodeGenericMetadata(), new NodeAccessRights()); context.getStorage().setConsistent(info.getId()); return new Tac(new ProjectFileCreationContext(info, context.getStorage(), context.getProject())); } diff --git a/afs/afs-core/src/test/java/com/powsybl/afs/FooFileBuilder.java b/afs/afs-core/src/test/java/com/powsybl/afs/FooFileBuilder.java index edfece395a9..52a7eb3a119 100644 --- a/afs/afs-core/src/test/java/com/powsybl/afs/FooFileBuilder.java +++ b/afs/afs-core/src/test/java/com/powsybl/afs/FooFileBuilder.java @@ -6,6 +6,7 @@ */ package com.powsybl.afs; +import com.powsybl.afs.storage.NodeAccessRights; import com.powsybl.afs.storage.NodeInfo; import com.powsybl.afs.storage.NodeGenericMetadata; @@ -43,7 +44,7 @@ public FooFile build() { throw new IllegalStateException("name is not set"); } String pseudoClass = "foo"; - NodeInfo info = context.getStorage().createNode(context.getFolderInfo().getId(), name, pseudoClass, "", 0, new NodeGenericMetadata()); + NodeInfo info = context.getStorage().createNode(context.getFolderInfo().getId(), name, pseudoClass, "", 0, new NodeGenericMetadata(), new NodeAccessRights()); context.getStorage().setConsistent(info.getId()); return new FooFile(new ProjectFileCreationContext(info, context.getStorage(), diff --git a/afs/afs-ext-base/src/main/java/com/powsybl/afs/ext/base/ImportedCaseBuilder.java b/afs/afs-ext-base/src/main/java/com/powsybl/afs/ext/base/ImportedCaseBuilder.java index dfcba8a9196..1469eb7d39a 100644 --- a/afs/afs-ext-base/src/main/java/com/powsybl/afs/ext/base/ImportedCaseBuilder.java +++ b/afs/afs-ext-base/src/main/java/com/powsybl/afs/ext/base/ImportedCaseBuilder.java @@ -11,6 +11,7 @@ import com.powsybl.afs.ProjectFileBuilder; import com.powsybl.afs.ProjectFileCreationContext; import com.powsybl.afs.storage.AppStorageDataSource; +import com.powsybl.afs.storage.NodeAccessRights; import com.powsybl.afs.storage.NodeGenericMetadata; import com.powsybl.afs.storage.NodeInfo; import com.powsybl.commons.datasource.DataSource; @@ -138,7 +139,7 @@ public ImportedCase build() { // create project file NodeInfo info = context.getStorage().createNode(context.getFolderInfo().getId(), name, ImportedCase.PSEUDO_CLASS, "", ImportedCase.VERSION, - new NodeGenericMetadata().setString(ImportedCase.FORMAT, importer.getFormat())); + new NodeGenericMetadata().setString(ImportedCase.FORMAT, importer.getFormat()), new NodeAccessRights()); // store case data importer.copy(dataSource, new AppStorageDataSource(context.getStorage(), info.getId(), info.getName())); diff --git a/afs/afs-ext-base/src/main/java/com/powsybl/afs/ext/base/ModificationScriptBuilder.java b/afs/afs-ext-base/src/main/java/com/powsybl/afs/ext/base/ModificationScriptBuilder.java index ff7c8e9eeb7..a2654299c17 100644 --- a/afs/afs-ext-base/src/main/java/com/powsybl/afs/ext/base/ModificationScriptBuilder.java +++ b/afs/afs-ext-base/src/main/java/com/powsybl/afs/ext/base/ModificationScriptBuilder.java @@ -11,6 +11,7 @@ import com.powsybl.afs.ProjectFileBuildContext; import com.powsybl.afs.ProjectFileBuilder; import com.powsybl.afs.ProjectFileCreationContext; +import com.powsybl.afs.storage.NodeAccessRights; import com.powsybl.afs.storage.NodeGenericMetadata; import com.powsybl.afs.storage.NodeInfo; @@ -69,7 +70,7 @@ public ModificationScript build() { // create project file NodeInfo info = context.getStorage().createNode(context.getFolderInfo().getId(), name, ModificationScript.PSEUDO_CLASS, "", ModificationScript.VERSION, - new NodeGenericMetadata().setString(ModificationScript.SCRIPT_TYPE, type.name())); + new NodeGenericMetadata().setString(ModificationScript.SCRIPT_TYPE, type.name()), new NodeAccessRights()); // store script try (Reader reader = new StringReader(content); diff --git a/afs/afs-ext-base/src/main/java/com/powsybl/afs/ext/base/VirtualCaseBuilder.java b/afs/afs-ext-base/src/main/java/com/powsybl/afs/ext/base/VirtualCaseBuilder.java index 592a685d78b..6af8625ae9c 100644 --- a/afs/afs-ext-base/src/main/java/com/powsybl/afs/ext/base/VirtualCaseBuilder.java +++ b/afs/afs-ext-base/src/main/java/com/powsybl/afs/ext/base/VirtualCaseBuilder.java @@ -7,6 +7,7 @@ package com.powsybl.afs.ext.base; import com.powsybl.afs.*; +import com.powsybl.afs.storage.NodeAccessRights; import com.powsybl.afs.storage.NodeGenericMetadata; import com.powsybl.afs.storage.NodeInfo; @@ -78,7 +79,7 @@ public VirtualCase build() { } // create project file - NodeInfo info = context.getStorage().createNode(context.getFolderInfo().getId(), name, VirtualCase.PSEUDO_CLASS, "", VirtualCase.VERSION, new NodeGenericMetadata()); + NodeInfo info = context.getStorage().createNode(context.getFolderInfo().getId(), name, VirtualCase.PSEUDO_CLASS, "", VirtualCase.VERSION, new NodeGenericMetadata(), new NodeAccessRights()); // create case link context.getStorage().addDependency(info.getId(), VirtualCase.CASE_DEPENDENCY_NAME, aCase.getId()); diff --git a/afs/afs-ext-base/src/test/java/com/powsybl/afs/ext/base/ImportedCaseTest.java b/afs/afs-ext-base/src/test/java/com/powsybl/afs/ext/base/ImportedCaseTest.java index f517201c53f..0635b80a0bb 100644 --- a/afs/afs-ext-base/src/test/java/com/powsybl/afs/ext/base/ImportedCaseTest.java +++ b/afs/afs-ext-base/src/test/java/com/powsybl/afs/ext/base/ImportedCaseTest.java @@ -13,6 +13,7 @@ import com.powsybl.afs.*; import com.powsybl.afs.mapdb.storage.MapDbAppStorage; import com.powsybl.afs.storage.AppStorage; +import com.powsybl.afs.storage.NodeAccessRights; import com.powsybl.afs.storage.NodeGenericMetadata; import com.powsybl.afs.storage.NodeInfo; import com.powsybl.commons.config.PlatformConfig; @@ -78,9 +79,8 @@ protected List getServiceExtensions() { public void setup() throws IOException { super.setup(); NodeInfo rootFolderInfo = storage.createRootNodeIfNotExists("root", Folder.PSEUDO_CLASS); - NodeInfo nodeInfo = storage.createNode(rootFolderInfo.getId(), "network", Case.PSEUDO_CLASS, "Test format", Case.VERSION, - new NodeGenericMetadata().setString("format", TestImporter.FORMAT)); + new NodeGenericMetadata().setString("format", TestImporter.FORMAT), new NodeAccessRights()); storage.setConsistent(nodeInfo.getId()); fileSystem = Jimfs.newFileSystem(Configuration.unix()); diff --git a/afs/afs-ext-base/src/test/java/com/powsybl/afs/ext/base/VirtualCaseTest.java b/afs/afs-ext-base/src/test/java/com/powsybl/afs/ext/base/VirtualCaseTest.java index 042a63a8369..317f297a3b9 100644 --- a/afs/afs-ext-base/src/test/java/com/powsybl/afs/ext/base/VirtualCaseTest.java +++ b/afs/afs-ext-base/src/test/java/com/powsybl/afs/ext/base/VirtualCaseTest.java @@ -10,6 +10,7 @@ import com.powsybl.afs.*; import com.powsybl.afs.mapdb.storage.MapDbAppStorage; import com.powsybl.afs.storage.AppStorage; +import com.powsybl.afs.storage.NodeAccessRights; import com.powsybl.afs.storage.NodeGenericMetadata; import com.powsybl.afs.storage.NodeInfo; import com.powsybl.iidm.import_.ImportConfig; @@ -59,7 +60,7 @@ public void setup() throws IOException { super.setup(); NodeInfo rootFolderInfo = storage.createRootNodeIfNotExists("root", Folder.PSEUDO_CLASS); NodeInfo nodeInfo = storage.createNode(rootFolderInfo.getId(), "network", Case.PSEUDO_CLASS, "", Case.VERSION, - new NodeGenericMetadata().setString(Case.FORMAT, TestImporter.FORMAT)); + new NodeGenericMetadata().setString(Case.FORMAT, TestImporter.FORMAT), new NodeAccessRights()); storage.setConsistent(nodeInfo.getId()); } diff --git a/afs/afs-local/src/main/java/com/powsybl/afs/local/storage/LocalAppStorage.java b/afs/afs-local/src/main/java/com/powsybl/afs/local/storage/LocalAppStorage.java index 47c12ccd71d..a435e7d2f4a 100644 --- a/afs/afs-local/src/main/java/com/powsybl/afs/local/storage/LocalAppStorage.java +++ b/afs/afs-local/src/main/java/com/powsybl/afs/local/storage/LocalAppStorage.java @@ -8,10 +8,7 @@ import com.google.common.collect.ImmutableList; import com.powsybl.afs.Folder; -import com.powsybl.afs.storage.AppStorage; -import com.powsybl.afs.storage.NodeDependency; -import com.powsybl.afs.storage.NodeGenericMetadata; -import com.powsybl.afs.storage.NodeInfo; +import com.powsybl.afs.storage.*; import com.powsybl.commons.exceptions.UncheckedUnsupportedEncodingException; import com.powsybl.computation.ComputationManager; import com.powsybl.timeseries.DoubleDataChunk; @@ -145,7 +142,8 @@ public NodeInfo createRootNodeIfNotExists(String name, String nodePseudoClass) { attr.creationTime().toMillis(), attr.lastModifiedTime().toMillis(), DEFAULT_VERSION, - new NodeGenericMetadata()); + new NodeGenericMetadata(), + new NodeAccessRights()); } @Override @@ -170,7 +168,8 @@ private NodeInfo getNodeInfo(Path path) { attr.creationTime().toMillis(), attr.lastModifiedTime().toMillis(), DEFAULT_VERSION, - file.getGenericMetadata()); + file.getGenericMetadata(), + file.getAccessRights()); } else { LocalFolder folder = scanFolder(path, true); if (folder != null) { @@ -181,7 +180,8 @@ private NodeInfo getNodeInfo(Path path) { attr.creationTime().toMillis(), attr.lastModifiedTime().toMillis(), DEFAULT_VERSION, - new NodeGenericMetadata()); + new NodeGenericMetadata(), + new NodeAccessRights()); } else { throw new AssertionError(); } @@ -274,7 +274,7 @@ public boolean isConsistent(String nodeId) { } @Override - public NodeInfo createNode(String parentString, String name, String nodePseudoClass, String description, int version, NodeGenericMetadata genericMetadata) { + public NodeInfo createNode(String parentString, String name, String nodePseudoClass, String description, int version, NodeGenericMetadata genericMetadata, NodeAccessRights accessRights) { throw new AssertionError(); } diff --git a/afs/afs-local/src/main/java/com/powsybl/afs/local/storage/LocalCase.java b/afs/afs-local/src/main/java/com/powsybl/afs/local/storage/LocalCase.java index 6d883e27322..d17a5280acc 100644 --- a/afs/afs-local/src/main/java/com/powsybl/afs/local/storage/LocalCase.java +++ b/afs/afs-local/src/main/java/com/powsybl/afs/local/storage/LocalCase.java @@ -8,6 +8,7 @@ import com.powsybl.afs.ext.base.Case; import com.powsybl.afs.storage.AppStorageDataSource; +import com.powsybl.afs.storage.NodeAccessRights; import com.powsybl.afs.storage.NodeGenericMetadata; import com.powsybl.commons.datasource.DataSource; import com.powsybl.commons.datasource.DataSourceUtil; @@ -65,6 +66,11 @@ public NodeGenericMetadata getGenericMetadata() { return new NodeGenericMetadata().setString("format", importer.getFormat()); } + @Override + public NodeAccessRights getAccessRights() { + return new NodeAccessRights(); + } + @Override public Optional readBinaryData(String name) { DataSource dataSource = Importers.createDataSource(file); diff --git a/afs/afs-local/src/main/java/com/powsybl/afs/local/storage/LocalFile.java b/afs/afs-local/src/main/java/com/powsybl/afs/local/storage/LocalFile.java index 8f672fe4d07..e5e9fac215b 100644 --- a/afs/afs-local/src/main/java/com/powsybl/afs/local/storage/LocalFile.java +++ b/afs/afs-local/src/main/java/com/powsybl/afs/local/storage/LocalFile.java @@ -6,6 +6,7 @@ */ package com.powsybl.afs.local.storage; +import com.powsybl.afs.storage.NodeAccessRights; import com.powsybl.afs.storage.NodeGenericMetadata; import com.powsybl.timeseries.*; @@ -27,6 +28,8 @@ public interface LocalFile extends LocalNode { NodeGenericMetadata getGenericMetadata(); + NodeAccessRights getAccessRights(); + Optional readBinaryData(String name); boolean dataExists(String name); diff --git a/afs/afs-mapdb-storage/src/main/java/com/powsybl/afs/mapdb/storage/MapDbAppStorage.java b/afs/afs-mapdb-storage/src/main/java/com/powsybl/afs/mapdb/storage/MapDbAppStorage.java index ecdb467a4df..d5677a5a22c 100644 --- a/afs/afs-mapdb-storage/src/main/java/com/powsybl/afs/mapdb/storage/MapDbAppStorage.java +++ b/afs/afs-mapdb-storage/src/main/java/com/powsybl/afs/mapdb/storage/MapDbAppStorage.java @@ -277,7 +277,7 @@ private static UUID checkNullableNodeId(String nodeId) { public NodeInfo createRootNodeIfNotExists(String name, String nodePseudoClass) { NodeInfo rootNodeInfo = rootNodeVar.get(); if (rootNodeInfo == null) { - rootNodeInfo = createNode(null, name, nodePseudoClass, "", 0, new NodeGenericMetadata()); + rootNodeInfo = createNode(null, name, nodePseudoClass, "", 0, new NodeGenericMetadata(), new NodeAccessRights()); rootNodeVar.set(rootNodeInfo); } UUID nodeUuid = checkNodeId(rootNodeInfo.getId()); @@ -419,7 +419,7 @@ public void setParentNode(String nodeId, String newParentNodeId) { } @Override - public NodeInfo createNode(String parentNodeId, String name, String nodePseudoClass, String description, int version, NodeGenericMetadata genericMetadata) { + public NodeInfo createNode(String parentNodeId, String name, String nodePseudoClass, String description, int version, NodeGenericMetadata genericMetadata, NodeAccessRights accessRights) { UUID parentNodeUuid = checkNullableNodeId(parentNodeId); Objects.requireNonNull(name); Objects.requireNonNull(nodePseudoClass); @@ -433,7 +433,7 @@ public NodeInfo createNode(String parentNodeId, String name, String nodePseudoCl } UUID nodeUuid = UUID.randomUUID(); long creationTime = ZonedDateTime.now().toInstant().toEpochMilli(); - NodeInfo nodeInfo = new NodeInfo(nodeUuid.toString(), name, nodePseudoClass, description, creationTime, creationTime, version, genericMetadata); + NodeInfo nodeInfo = new NodeInfo(nodeUuid.toString(), name, nodePseudoClass, description, creationTime, creationTime, version, genericMetadata, accessRights); nodeInfoMap.put(nodeUuid, nodeInfo); dataNamesMap.put(nodeUuid, Collections.emptySet()); childNodesMap.put(nodeUuid, new ArrayList<>()); diff --git a/afs/afs-mapdb-storage/src/main/java/com/powsybl/afs/mapdb/storage/NodeInfoSerializer.java b/afs/afs-mapdb-storage/src/main/java/com/powsybl/afs/mapdb/storage/NodeInfoSerializer.java index 75aed678d34..e4e742a5f86 100644 --- a/afs/afs-mapdb-storage/src/main/java/com/powsybl/afs/mapdb/storage/NodeInfoSerializer.java +++ b/afs/afs-mapdb-storage/src/main/java/com/powsybl/afs/mapdb/storage/NodeInfoSerializer.java @@ -6,6 +6,7 @@ */ package com.powsybl.afs.mapdb.storage; +import com.powsybl.afs.storage.NodeAccessRights; import com.powsybl.afs.storage.NodeGenericMetadata; import com.powsybl.afs.storage.NodeInfo; import org.mapdb.DataInput2; @@ -15,6 +16,7 @@ import java.io.IOException; import java.io.Serializable; import java.util.Map; +import java.util.Objects; /** * @author Geoffroy Jamgotchian @@ -52,6 +54,20 @@ public void serialize(DataOutput2 out, NodeInfo nodeInfo) throws IOException { out.writeUTF(e.getKey()); out.writeBoolean(e.getValue()); } + out.writeInt(nodeInfo.getAccessRights().getUsersRights().size()); + for (Map.Entry e : nodeInfo.getAccessRights().getUsersRights().entrySet()) { + out.writeUTF(e.getKey()); + out.writeShort(e.getValue()); + } + out.writeInt(nodeInfo.getAccessRights().getGroupsRights().size()); + for (Map.Entry e : nodeInfo.getAccessRights().getGroupsRights().entrySet()) { + out.writeUTF(e.getKey()); + out.writeShort(e.getValue()); + } + out.writeInt(Objects.isNull(nodeInfo.getAccessRights().getOthersRights()) ? 0 : 1); + if (!Objects.isNull(nodeInfo.getAccessRights().getOthersRights())) { + out.writeShort(nodeInfo.getAccessRights().getOthersRights()); + } } @Override @@ -80,6 +96,20 @@ public NodeInfo deserialize(DataInput2 input, int available) throws IOException for (int i = 0; i < booleanMetadataSize; i++) { metadata.setBoolean(input.readUTF(), input.readBoolean()); } - return new NodeInfo(nodeId, name, pseudoClass, description, creationTime, modificationTime, version, metadata); + NodeAccessRights accessRights = new NodeAccessRights(); + int usersRightsSize = input.readInt(); + for (int i = 0; i < usersRightsSize; i++) { + accessRights.setUserRights(input.readUTF(), input.readShort()); + } + int groupsRightsSize = input.readInt(); + for (int i = 0; i < groupsRightsSize; i++) { + accessRights.setGroupRights(input.readUTF(), input.readShort()); + } + int othersRightsSize = input.readInt(); + for (int i = 0; i < othersRightsSize; i++) { + accessRights.setOthersRights(input.readShort()); + } + + return new NodeInfo(nodeId, name, pseudoClass, description, creationTime, modificationTime, version, metadata, accessRights); } } diff --git a/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/AppStorage.java b/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/AppStorage.java index b695157e9db..c90780163f4 100644 --- a/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/AppStorage.java +++ b/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/AppStorage.java @@ -41,7 +41,7 @@ public interface AppStorage extends AutoCloseable { * Creates a new node in the tree under a parent node. Returns {@code NodeInfo} corresponding to the newly created node. * The new node is by default inconsistent, {@link #setConsistent(String nodeId)} method should explicitly be called to set it consistent. */ - NodeInfo createNode(String parentNodeId, String name, String nodePseudoClass, String description, int version, NodeGenericMetadata genericMetadata); + NodeInfo createNode(String parentNodeId, String name, String nodePseudoClass, String description, int version, NodeGenericMetadata genericMetadata, NodeAccessRights accessRights); boolean isWritable(String nodeId); diff --git a/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/AppStorageArchive.java b/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/AppStorageArchive.java index 33d809715ea..f29b093118f 100644 --- a/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/AppStorageArchive.java +++ b/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/AppStorageArchive.java @@ -243,7 +243,7 @@ private NodeInfo readNodeInfo(NodeInfo parentNodeInfo, Path nodeDir, UnarchiveCo try (Reader reader = Files.newBufferedReader(nodeDir.resolve("info.json"), StandardCharsets.UTF_8)) { nodeInfo = mapper.readerFor(NodeInfo.class).readValue(reader); newNodeInfo = storage.createNode(context.getIdMapping(parentNodeInfo.getId()), nodeInfo.getName(), nodeInfo.getPseudoClass(), nodeInfo.getDescription(), - nodeInfo.getVersion(), nodeInfo.getGenericMetadata()); + nodeInfo.getVersion(), nodeInfo.getGenericMetadata(), nodeInfo.getAccessRights()); context.getIdMapping().put(nodeInfo.getId(), newNodeInfo.getId()); } diff --git a/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/DefaultListenableAppStorage.java b/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/DefaultListenableAppStorage.java index 01b7148a5cc..1bd5ecc3abf 100644 --- a/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/DefaultListenableAppStorage.java +++ b/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/DefaultListenableAppStorage.java @@ -53,8 +53,8 @@ public NodeInfo createRootNodeIfNotExists(String name, String nodePseudoClass) { } @Override - public NodeInfo createNode(String parentNodeId, String name, String nodePseudoClass, String description, int version, NodeGenericMetadata genericMetadata) { - NodeInfo nodeInfo = super.createNode(parentNodeId, name, nodePseudoClass, description, version, genericMetadata); + public NodeInfo createNode(String parentNodeId, String name, String nodePseudoClass, String description, int version, NodeGenericMetadata genericMetadata, NodeAccessRights accessRights) { + NodeInfo nodeInfo = super.createNode(parentNodeId, name, nodePseudoClass, description, version, genericMetadata, accessRights); addEvent(new NodeCreated(nodeInfo.getId(), parentNodeId)); return nodeInfo; } diff --git a/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/ForwardingAppStorage.java b/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/ForwardingAppStorage.java index 866db5821e5..4b81aebb3cc 100644 --- a/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/ForwardingAppStorage.java +++ b/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/ForwardingAppStorage.java @@ -43,8 +43,8 @@ public NodeInfo createRootNodeIfNotExists(String name, String nodePseudoClass) { } @Override - public NodeInfo createNode(String parentNodeId, String name, String nodePseudoClass, String description, int version, NodeGenericMetadata genericMetadata) { - return storage.createNode(parentNodeId, name, nodePseudoClass, description, version, genericMetadata); + public NodeInfo createNode(String parentNodeId, String name, String nodePseudoClass, String description, int version, NodeGenericMetadata genericMetadata, NodeAccessRights accessRights) { + return storage.createNode(parentNodeId, name, nodePseudoClass, description, version, genericMetadata, accessRights); } @Override diff --git a/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/NodeAccessRights.java b/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/NodeAccessRights.java new file mode 100644 index 00000000000..fb5166ce122 --- /dev/null +++ b/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/NodeAccessRights.java @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2019, RTE (http://www.rte-france.com) + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ +package com.powsybl.afs.storage; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +public class NodeAccessRights { + + private final Map usersRights; + + private final Map groupsRights; + + private Short othersRights; + + public NodeAccessRights() { + this(new HashMap<>(), new HashMap<>(), null); + } + + public NodeAccessRights(Map usersRights, Map groupsRights, Short othersRights) { + this.usersRights = Objects.requireNonNull(usersRights); + this.groupsRights = Objects.requireNonNull(groupsRights); + this.othersRights = othersRights; + } + + public Map getUsersRights() { + return usersRights; + } + + public NodeAccessRights setUserRights(String user, Short rights) { + Objects.requireNonNull(user); + usersRights.put(user, rights); + return this; + } + + public Map getGroupsRights() { + return groupsRights; + } + + public NodeAccessRights setGroupRights(String group, Short rights) { + Objects.requireNonNull(group); + groupsRights.put(group, rights); + return this; + } + + public Short getOthersRights() { + return othersRights; + } + + public NodeAccessRights setOthersRights(Short rights) { + othersRights = rights; + return this; + } + + @Override + public int hashCode() { + return Objects.hash(usersRights, groupsRights, othersRights); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof NodeAccessRights) { + NodeAccessRights other = (NodeAccessRights) obj; + return usersRights.equals(other.usersRights) && groupsRights.equals(other.groupsRights) && + (Objects.isNull(othersRights) ? (Objects.isNull(other.othersRights)) : (othersRights.equals(other.othersRights))); + } + return false; + } + + @Override + public String toString() { + return "NodeAccessRights(usersRights=" + usersRights + ", groupsRights=" + groupsRights + + ", othersRights=" + othersRights + ")"; + + } + +} diff --git a/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/NodeInfo.java b/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/NodeInfo.java index 887f79339e0..1657bdb28a3 100644 --- a/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/NodeInfo.java +++ b/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/NodeInfo.java @@ -31,8 +31,10 @@ public class NodeInfo { private final NodeGenericMetadata genericMetadata; + private final NodeAccessRights accessRights; + public NodeInfo(String id, String name, String pseudoClass, String description, long creationTime, long modificationTime, - int version, NodeGenericMetadata genericMetadata) { + int version, NodeGenericMetadata genericMetadata, NodeAccessRights accessRights) { this.id = Objects.requireNonNull(id); this.name = checkName(name); this.pseudoClass = Objects.requireNonNull(pseudoClass); @@ -41,6 +43,7 @@ public NodeInfo(String id, String name, String pseudoClass, String description, this.modificationTime = modificationTime; this.version = version; this.genericMetadata = Objects.requireNonNull(genericMetadata); + this.accessRights = accessRights; } /** @@ -105,9 +108,13 @@ public NodeGenericMetadata getGenericMetadata() { return genericMetadata; } + public NodeAccessRights getAccessRights() { + return accessRights; + } + @Override public int hashCode() { - return Objects.hash(id, name, pseudoClass, description, creationTime, modificationTime, version, genericMetadata); + return Objects.hash(id, name, pseudoClass, description, creationTime, modificationTime, version, genericMetadata, accessRights); } @Override @@ -117,7 +124,7 @@ public boolean equals(Object obj) { return id.equals(other.id) && name.equals(other.name) && pseudoClass.equals(other.pseudoClass) && description.equals(other.description) && creationTime == other.creationTime && modificationTime == other.modificationTime && version == other.version && - genericMetadata.equals(other.genericMetadata); + genericMetadata.equals(other.genericMetadata) && accessRights.equals(other.accessRights); } return false; } @@ -127,6 +134,6 @@ public String toString() { return "NodeInfo(id=" + id + ", name=" + name + ", pseudoClass=" + pseudoClass + ", description=" + description + ", creationTime=" + creationTime + ", modificationTime=" + modificationTime + ", version=" + version + - ", genericMetadata=" + genericMetadata + ")"; + ", genericMetadata=" + genericMetadata + ", accessRights=" + accessRights + ")"; } } diff --git a/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/json/AppStorageJsonModule.java b/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/json/AppStorageJsonModule.java index 765853ab5bc..f7846f30c75 100644 --- a/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/json/AppStorageJsonModule.java +++ b/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/json/AppStorageJsonModule.java @@ -6,6 +6,7 @@ */ package com.powsybl.afs.storage.json; +import com.powsybl.afs.storage.NodeAccessRights; import com.powsybl.afs.storage.NodeDependency; import com.powsybl.afs.storage.NodeGenericMetadata; import com.powsybl.afs.storage.NodeInfo; @@ -18,10 +19,12 @@ public class AppStorageJsonModule extends TimeSeriesJsonModule { public AppStorageJsonModule() { addSerializer(NodeGenericMetadata.class, new NodeGenericMetadataJsonSerializer()); + addSerializer(NodeAccessRights.class, new NodeAccessRightsJsonSerializer()); addSerializer(NodeInfo.class, new NodeInfoJsonSerializer()); addSerializer(NodeDependency.class, new NodeDependencySerializer()); addDeserializer(NodeGenericMetadata.class, new NodeGenericMetadataJsonDeserializer()); + addDeserializer(NodeAccessRights.class, new NodeAccessRightsJsonDeserializer()); addDeserializer(NodeInfo.class, new NodeInfoJsonDeserializer()); addDeserializer(NodeDependency.class, new NodeDependencyDeserializer()); } diff --git a/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/json/NodeAccessRightsJsonDeserializer.java b/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/json/NodeAccessRightsJsonDeserializer.java new file mode 100644 index 00000000000..6e6ef684748 --- /dev/null +++ b/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/json/NodeAccessRightsJsonDeserializer.java @@ -0,0 +1,74 @@ +package com.powsybl.afs.storage.json; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.powsybl.afs.storage.NodeAccessRights; + +import java.io.IOException; +import java.util.Objects; + +public class NodeAccessRightsJsonDeserializer extends StdDeserializer { + + private static class JsonParsingContext { + final NodeAccessRights accessRights = new NodeAccessRights(); + String type = null; + String name = null; + } + + public NodeAccessRightsJsonDeserializer() { + super(NodeAccessRights.class); + } + + private static void parseFieldName(JsonParser jsonParser, NodeAccessRightsJsonDeserializer.JsonParsingContext parsingContext) throws IOException { + switch (jsonParser.getCurrentName()) { + case NodeAccessRightsJsonSerializer.TYPE: + jsonParser.nextToken(); + parsingContext.type = jsonParser.getValueAsString(); + break; + + case NodeAccessRightsJsonSerializer.NAME: + jsonParser.nextToken(); + parsingContext.name = jsonParser.getValueAsString(); + break; + + case NodeAccessRightsJsonSerializer.VALUE: + Objects.requireNonNull(parsingContext.type); + Objects.requireNonNull(parsingContext.name); + jsonParser.nextToken(); + switch (parsingContext.type) { + case NodeAccessRightsJsonSerializer.USER: + parsingContext.accessRights.setUserRights(parsingContext.name, (short) jsonParser.getValueAsInt()); + break; + case NodeAccessRightsJsonSerializer.GROUP: + parsingContext.accessRights.setGroupRights(parsingContext.name, (short) jsonParser.getValueAsInt()); + break; + case NodeAccessRightsJsonSerializer.OTHERS: + parsingContext.accessRights.setOthersRights((short) jsonParser.getValueAsInt()); + break; + default: + throw new AssertionError("Unexpected access right type " + parsingContext.type); + } + break; + + default: + throw new AssertionError("Unexpected field: " + jsonParser.getCurrentName()); + + } + } + + @Override + public NodeAccessRights deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException { + NodeAccessRightsJsonDeserializer.JsonParsingContext parsingContext = new NodeAccessRightsJsonDeserializer.JsonParsingContext(); + JsonToken token; + while ((token = jsonParser.nextToken()) != null) { + if (token == JsonToken.END_ARRAY) { + break; + } else if (token == JsonToken.FIELD_NAME) { + parseFieldName(jsonParser, parsingContext); + } + } + return parsingContext.accessRights; + } +} diff --git a/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/json/NodeAccessRightsJsonSerializer.java b/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/json/NodeAccessRightsJsonSerializer.java new file mode 100644 index 00000000000..87482acd3ea --- /dev/null +++ b/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/json/NodeAccessRightsJsonSerializer.java @@ -0,0 +1,52 @@ +package com.powsybl.afs.storage.json; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import com.powsybl.afs.storage.NodeAccessRights; + +import java.io.IOException; +import java.util.Map; + +public class NodeAccessRightsJsonSerializer extends StdSerializer { + + static final String VALUE = "value"; + static final String NAME = "name"; + static final String TYPE = "type"; + static final String USER = "user"; + static final String GROUP = "group"; + static final String OTHERS = "others"; + + public NodeAccessRightsJsonSerializer() { + super(NodeAccessRights.class); + } + + @Override + public void serialize(NodeAccessRights nodeAccessRights, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException { + jsonGenerator.writeStartArray(); + for (Map.Entry e : nodeAccessRights.getUsersRights().entrySet()) { + jsonGenerator.writeStartObject(); + jsonGenerator.writeStringField(TYPE, USER); + jsonGenerator.writeStringField(NAME, e.getKey()); + jsonGenerator.writeNumberField(VALUE, e.getValue()); + jsonGenerator.writeEndObject(); + } + for (Map.Entry e : nodeAccessRights.getGroupsRights().entrySet()) { + jsonGenerator.writeStartObject(); + jsonGenerator.writeStringField(TYPE, GROUP); + jsonGenerator.writeStringField(NAME, e.getKey()); + jsonGenerator.writeNumberField(VALUE, e.getValue()); + jsonGenerator.writeEndObject(); + } + + if (nodeAccessRights.getOthersRights() != null) { + jsonGenerator.writeStartObject(); + jsonGenerator.writeStringField(TYPE, OTHERS); + jsonGenerator.writeStringField(NAME, OTHERS); + jsonGenerator.writeNumberField(VALUE, nodeAccessRights.getOthersRights()); + jsonGenerator.writeEndObject(); + } + + jsonGenerator.writeEndArray(); + } +} diff --git a/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/json/NodeInfoJsonDeserializer.java b/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/json/NodeInfoJsonDeserializer.java index 72e4ab697d7..5fc6ca77610 100644 --- a/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/json/NodeInfoJsonDeserializer.java +++ b/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/json/NodeInfoJsonDeserializer.java @@ -10,6 +10,7 @@ import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.databind.DeserializationContext; import com.fasterxml.jackson.databind.deser.std.StdDeserializer; +import com.powsybl.afs.storage.NodeAccessRights; import com.powsybl.afs.storage.NodeGenericMetadata; import com.powsybl.afs.storage.NodeInfo; @@ -28,6 +29,7 @@ private static class JsonParsingContext { long creationTime = -1; long modificationTime = -1; int version = -1; + NodeAccessRights accessRights; NodeGenericMetadata metadata; } @@ -78,6 +80,11 @@ private static void parseFieldName(JsonParser jsonParser, DeserializationContext parsingContext.metadata = new NodeGenericMetadataJsonDeserializer().deserialize(jsonParser, deserializationContext); break; + case NodeInfoJsonSerializer.ACCESS_RIGHTS: + jsonParser.nextToken(); + parsingContext.accessRights = new NodeAccessRightsJsonDeserializer().deserialize(jsonParser, deserializationContext); + break; + default: throw new AssertionError("Unexpected field: " + jsonParser.getCurrentName()); @@ -96,6 +103,7 @@ public NodeInfo deserialize(JsonParser jsonParser, DeserializationContext deseri } } return new NodeInfo(parsingContext.id, parsingContext.name, parsingContext.pseudoClass, parsingContext.description, - parsingContext.creationTime, parsingContext.modificationTime, parsingContext.version, parsingContext.metadata); + parsingContext.creationTime, parsingContext.modificationTime, parsingContext.version, + parsingContext.metadata, parsingContext.accessRights); } } diff --git a/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/json/NodeInfoJsonSerializer.java b/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/json/NodeInfoJsonSerializer.java index 84479e85708..98baaa1016a 100644 --- a/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/json/NodeInfoJsonSerializer.java +++ b/afs/afs-storage-api/src/main/java/com/powsybl/afs/storage/json/NodeInfoJsonSerializer.java @@ -26,6 +26,7 @@ public class NodeInfoJsonSerializer extends StdSerializer { static final String MODIFICATION_TIME = "modificationTime"; static final String VERSION = "version"; static final String METADATA = "metadata"; + static final String ACCESS_RIGHTS = "accessRights"; public NodeInfoJsonSerializer() { super(NodeInfo.class); @@ -43,6 +44,8 @@ public void serialize(NodeInfo nodeInfo, JsonGenerator jsonGenerator, Serializer jsonGenerator.writeNumberField(VERSION, nodeInfo.getVersion()); jsonGenerator.writeFieldName(METADATA); new NodeGenericMetadataJsonSerializer().serialize(nodeInfo.getGenericMetadata(), jsonGenerator, serializerProvider); + jsonGenerator.writeFieldName(ACCESS_RIGHTS); + new NodeAccessRightsJsonSerializer().serialize(nodeInfo.getAccessRights(), jsonGenerator, serializerProvider); jsonGenerator.writeEndObject(); } } diff --git a/afs/afs-storage-api/src/test/java/com/powsybl/afs/storage/AbstractAppStorageArchiveTest.java b/afs/afs-storage-api/src/test/java/com/powsybl/afs/storage/AbstractAppStorageArchiveTest.java index 661beedb524..751b1f5f040 100644 --- a/afs/afs-storage-api/src/test/java/com/powsybl/afs/storage/AbstractAppStorageArchiveTest.java +++ b/afs/afs-storage-api/src/test/java/com/powsybl/afs/storage/AbstractAppStorageArchiveTest.java @@ -64,9 +64,9 @@ public void archive() throws IOException { NodeInfo rootFolderInfo = storage.createRootNodeIfNotExists(storage.getFileSystemName(), AbstractAppStorageTest.FOLDER_PSEUDO_CLASS); storage.setConsistent(rootFolderInfo.getId()); - NodeInfo folder1Info = storage.createNode(rootFolderInfo.getId(), "folder1", AbstractAppStorageTest.FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata()); + NodeInfo folder1Info = storage.createNode(rootFolderInfo.getId(), "folder1", AbstractAppStorageTest.FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata(), new NodeAccessRights()); storage.setConsistent(folder1Info.getId()); - NodeInfo file1Info = storage.createNode(folder1Info.getId(), "file1", AbstractAppStorageTest.DATA_FILE_CLASS, "", 0, new NodeGenericMetadata().setInt("i1", 1)); + NodeInfo file1Info = storage.createNode(folder1Info.getId(), "file1", AbstractAppStorageTest.DATA_FILE_CLASS, "", 0, new NodeGenericMetadata().setInt("i1", 1), new NodeAccessRights().setUserRights("user1", (short) 7)); storage.setConsistent(file1Info.getId()); try (OutputStream os = storage.writeBinaryData(file1Info.getId(), "data1")) { @@ -83,10 +83,10 @@ public void archive() throws IOException { new UncompressedDoubleDataChunk(5, new double[]{3d})); storage.addDoubleTimeSeriesData(file1Info.getId(), 0, "ts1 hello", chunks); - NodeInfo folder2Info = storage.createNode(rootFolderInfo.getId(), "folder2", AbstractAppStorageTest.FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata()); + NodeInfo folder2Info = storage.createNode(rootFolderInfo.getId(), "folder2", AbstractAppStorageTest.FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata(), new NodeAccessRights()); storage.setConsistent(folder2Info.getId()); NodeInfo file2Info = storage.createNode(folder2Info.getId(), "file2", AbstractAppStorageTest.DATA_FILE_CLASS, "", 0, new NodeGenericMetadata() - .setString("s1", "a")); + .setString("s1", "a"), new NodeAccessRights().setGroupRights("group1", (short) 5)); storage.setConsistent(file2Info.getId()); storage.addDependency(file1Info.getId(), "dependency1", file2Info.getId()); diff --git a/afs/afs-storage-api/src/test/java/com/powsybl/afs/storage/AbstractAppStorageTest.java b/afs/afs-storage-api/src/test/java/com/powsybl/afs/storage/AbstractAppStorageTest.java index ea7242fb47f..6cb0e95333c 100644 --- a/afs/afs-storage-api/src/test/java/com/powsybl/afs/storage/AbstractAppStorageTest.java +++ b/afs/afs-storage-api/src/test/java/com/powsybl/afs/storage/AbstractAppStorageTest.java @@ -109,7 +109,7 @@ public void test() throws IOException, InterruptedException { // 2) create a test folder NodeInfo testFolderInfo = storage.createNode(rootFolderInfo.getId(), "test", FOLDER_PSEUDO_CLASS, "", 0, - new NodeGenericMetadata().setString("k", "v")); + new NodeGenericMetadata().setString("k", "v"), new NodeAccessRights().setUserRights("user1", (short) 6)); storage.flush(); assertFalse(storage.isConsistent(testFolderInfo.getId())); @@ -170,14 +170,14 @@ public void test() throws IOException, InterruptedException { assertTrue(storage.getNodeInfo(testFolderInfo.getId()).getModificationTime() >= oldModificationTime); // 5) create 2 data nodes in test folder - NodeInfo testDataInfo = storage.createNode(testFolderInfo.getId(), "data", DATA_FILE_CLASS, "", 0, new NodeGenericMetadata()); + NodeInfo testDataInfo = storage.createNode(testFolderInfo.getId(), "data", DATA_FILE_CLASS, "", 0, new NodeGenericMetadata(), new NodeAccessRights()); NodeInfo testData2Info = storage.createNode(testFolderInfo.getId(), "data2", DATA_FILE_CLASS, "", 0, new NodeGenericMetadata().setString("s1", "v1") .setDouble("d1", 1d) .setInt("i1", 2) - .setBoolean("b1", false)); - NodeInfo testData3Info = storage.createNode(testFolderInfo.getId(), "data3", DATA_FILE_CLASS, "", 0, new NodeGenericMetadata()); - + .setBoolean("b1", false), + new NodeAccessRights().setUserRights("user1", (short) 2).setUserRights("user2", (short) 4).setGroupRights("group1", (short) 6)); + NodeInfo testData3Info = storage.createNode(testFolderInfo.getId(), "data3", DATA_FILE_CLASS, "", 0, new NodeGenericMetadata(), new NodeAccessRights()); storage.setConsistent(testDataInfo.getId()); storage.setConsistent(testData2Info.getId()); storage.setConsistent(testData3Info.getId()); @@ -449,8 +449,8 @@ public void test() throws IOException, InterruptedException { assertTrue(storage.getTimeSeriesNames(testData2Info.getId()).isEmpty()); // 18) change parent test - NodeInfo folder1Info = storage.createNode(rootFolderInfo.getId(), "test1", FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata()); - NodeInfo folder2Info = storage.createNode(rootFolderInfo.getId(), "test2", FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata()); + NodeInfo folder1Info = storage.createNode(rootFolderInfo.getId(), "test1", FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata(), new NodeAccessRights()); + NodeInfo folder2Info = storage.createNode(rootFolderInfo.getId(), "test2", FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata(), new NodeAccessRights()); storage.setConsistent(folder1Info.getId()); storage.setConsistent(folder2Info.getId()); storage.flush(); @@ -458,7 +458,7 @@ public void test() throws IOException, InterruptedException { discardEvents(4); // create a file in folder 1 - NodeInfo fileInfo = storage.createNode(folder1Info.getId(), "file", "file-type", "", 0, new NodeGenericMetadata()); + NodeInfo fileInfo = storage.createNode(folder1Info.getId(), "file", "file-type", "", 0, new NodeGenericMetadata(), new NodeAccessRights()); storage.setConsistent(fileInfo.getId()); storage.flush(); @@ -480,8 +480,8 @@ public void test() throws IOException, InterruptedException { // 18) delete node test // create root node and 2 folders - NodeInfo folder3Info = storage.createNode(rootFolderInfo.getId(), "test3", FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata()); - NodeInfo folder4Info = storage.createNode(rootFolderInfo.getId(), "test4", FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata()); + NodeInfo folder3Info = storage.createNode(rootFolderInfo.getId(), "test3", FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata(), new NodeAccessRights()); + NodeInfo folder4Info = storage.createNode(rootFolderInfo.getId(), "test4", FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata(), new NodeAccessRights()); storage.setConsistent(folder3Info.getId()); storage.setConsistent(folder4Info.getId()); storage.flush(); @@ -503,10 +503,10 @@ public void test() throws IOException, InterruptedException { assertTrue(storage.getDependencies(folder3Info.getId(), "dep2").isEmpty()); // 19) rename node test - NodeInfo folder5Info = storage.createNode(rootFolderInfo.getId(), "test5", FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata()); + NodeInfo folder5Info = storage.createNode(rootFolderInfo.getId(), "test5", FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata(), new NodeAccessRights()); storage.setConsistent(folder5Info.getId()); - NodeInfo folder51Info = storage.createNode(folder5Info.getId(), "child_of_test5", FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata()); - NodeInfo folder52Info = storage.createNode(folder5Info.getId(), "another_child_of_test5", FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata()); + NodeInfo folder51Info = storage.createNode(folder5Info.getId(), "child_of_test5", FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata(), new NodeAccessRights()); + NodeInfo folder52Info = storage.createNode(folder5Info.getId(), "another_child_of_test5", FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata(), new NodeAccessRights()); storage.setConsistent(folder51Info.getId()); storage.setConsistent(folder52Info.getId()); storage.flush(); @@ -521,7 +521,7 @@ public void test() throws IOException, InterruptedException { assertTrue(storage.getChildNode(folder5Info.getId(), "child_of_test5").isPresent()); assertTrue(storage.getChildNode(folder5Info.getId(), "another_child_of_test5").isPresent()); - NodeInfo folder6Info = storage.createNode(rootFolderInfo.getId(), "test6", FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata()); + NodeInfo folder6Info = storage.createNode(rootFolderInfo.getId(), "test6", FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata(), new NodeAccessRights()); storage.setConsistent(folder6Info.getId()); try { storage.renameNode(folder6Info.getId(), null); @@ -529,7 +529,7 @@ public void test() throws IOException, InterruptedException { } catch (Exception ignored) { } - NodeInfo folder7Info = storage.createNode(rootFolderInfo.getId(), "test7", FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata()); + NodeInfo folder7Info = storage.createNode(rootFolderInfo.getId(), "test7", FOLDER_PSEUDO_CLASS, "", 0, new NodeGenericMetadata(), new NodeAccessRights()); storage.setConsistent(folder7Info.getId()); try { storage.renameNode(folder7Info.getId(), ""); diff --git a/afs/afs-storage-api/src/test/java/com/powsybl/afs/storage/DefaultListenableAppStorageTest.java b/afs/afs-storage-api/src/test/java/com/powsybl/afs/storage/DefaultListenableAppStorageTest.java index caa96ed3d6a..54687b0a27d 100644 --- a/afs/afs-storage-api/src/test/java/com/powsybl/afs/storage/DefaultListenableAppStorageTest.java +++ b/afs/afs-storage-api/src/test/java/com/powsybl/afs/storage/DefaultListenableAppStorageTest.java @@ -44,8 +44,8 @@ public class DefaultListenableAppStorageTest { @Before public void setUp() { AppStorage storage = Mockito.mock(AppStorage.class); - Mockito.when(storage.createNode(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyInt(), Mockito.any(NodeGenericMetadata.class))) - .thenReturn(new NodeInfo("node2", "nodeName", "", "", 0, 0, 0, new NodeGenericMetadata())); + Mockito.when(storage.createNode(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), Mockito.anyInt(), Mockito.any(NodeGenericMetadata.class), Mockito.any(NodeAccessRights.class))) + .thenReturn(new NodeInfo("node2", "nodeName", "", "", 0, 0, 0, new NodeGenericMetadata(), new NodeAccessRights())); Mockito.when(storage.deleteNode("node2")).thenReturn("node1"); Mockito.when(storage.writeBinaryData(Mockito.anyString(), Mockito.anyString())) .thenReturn(new ByteArrayOutputStream() { @@ -73,7 +73,7 @@ public void tearDown() { @Test public void test() throws IOException { - listenableStorage.createNode("node1", "node2", "file", "", 0, new NodeGenericMetadata()); + listenableStorage.createNode("node1", "node2", "file", "", 0, new NodeGenericMetadata(), new NodeAccessRights()); listenableStorage.flush(); assertEquals(new NodeEventList(new NodeCreated("node2", "node1")), lastEventList); diff --git a/afs/afs-storage-api/src/test/java/com/powsybl/afs/storage/NodeDependencyTest.java b/afs/afs-storage-api/src/test/java/com/powsybl/afs/storage/NodeDependencyTest.java index 588ec06ab11..1f94d71142f 100644 --- a/afs/afs-storage-api/src/test/java/com/powsybl/afs/storage/NodeDependencyTest.java +++ b/afs/afs-storage-api/src/test/java/com/powsybl/afs/storage/NodeDependencyTest.java @@ -22,11 +22,11 @@ public class NodeDependencyTest { @Test public void test() throws IOException { - NodeInfo info = new NodeInfo("a", "b", "c", "d", 1000000, 1000001, 0, new NodeGenericMetadata()); + NodeInfo info = new NodeInfo("a", "b", "c", "d", 1000000, 1000001, 0, new NodeGenericMetadata(), new NodeAccessRights()); NodeDependency dependency = new NodeDependency("l", info); assertEquals("l", dependency.getName()); assertEquals(info, dependency.getNodeInfo()); - assertEquals("NodeDependency(name=l, nodeInfo=NodeInfo(id=a, name=b, pseudoClass=c, description=d, creationTime=1000000, modificationTime=1000001, version=0, genericMetadata=NodeGenericMetadata(stringMetadata={}, doubleMetadata={}, intMetadata={}, booleanMetadata={})))", dependency.toString()); + assertEquals("NodeDependency(name=l, nodeInfo=NodeInfo(id=a, name=b, pseudoClass=c, description=d, creationTime=1000000, modificationTime=1000001, version=0, genericMetadata=NodeGenericMetadata(stringMetadata={}, doubleMetadata={}, intMetadata={}, booleanMetadata={}), accessRights=NodeAccessRights(usersRights={}, groupsRights={}, othersRights=null)))", dependency.toString()); ObjectMapper objectMapper = JsonUtil.createObjectMapper() .registerModule(new AppStorageJsonModule()); diff --git a/afs/afs-storage-api/src/test/java/com/powsybl/afs/storage/NodeInfoTest.java b/afs/afs-storage-api/src/test/java/com/powsybl/afs/storage/NodeInfoTest.java index f24867c9ec0..e203648ceb2 100644 --- a/afs/afs-storage-api/src/test/java/com/powsybl/afs/storage/NodeInfoTest.java +++ b/afs/afs-storage-api/src/test/java/com/powsybl/afs/storage/NodeInfoTest.java @@ -35,7 +35,8 @@ public void nodeInfoTest() throws IOException { new NodeGenericMetadata().setString("s1", "s1") .setDouble("d1", 1d) .setInt("i1", 2) - .setBoolean("b1", true)); + .setBoolean("b1", true), + new NodeAccessRights().setGroupRights("group1", (short) 2).setGroupRights("group2", (short) 4).setUserRights("user1", (short) 6)); NodeInfo info2 = objectMapper.readValue(objectMapper.writeValueAsString(info), NodeInfo.class); assertEquals(info, info2); info.setVersion(1); diff --git a/afs/afs-ws/afs-ws-server/src/main/java/com/powsybl/afs/ws/server/AppStorageServer.java b/afs/afs-ws/afs-ws-server/src/main/java/com/powsybl/afs/ws/server/AppStorageServer.java index d4eadd3230b..509f0aa521b 100644 --- a/afs/afs-ws/afs-ws-server/src/main/java/com/powsybl/afs/ws/server/AppStorageServer.java +++ b/afs/afs-ws/afs-ws-server/src/main/java/com/powsybl/afs/ws/server/AppStorageServer.java @@ -11,10 +11,7 @@ import com.powsybl.afs.AppFileSystem; import com.powsybl.afs.ProjectFile; import com.powsybl.afs.TaskMonitor; -import com.powsybl.afs.storage.AppStorage; -import com.powsybl.afs.storage.NodeDependency; -import com.powsybl.afs.storage.NodeGenericMetadata; -import com.powsybl.afs.storage.NodeInfo; +import com.powsybl.afs.storage.*; import com.powsybl.afs.storage.buffer.*; import com.powsybl.afs.ws.server.utils.JwtTokenNeeded; import com.powsybl.afs.ws.server.utils.AppDataBean; @@ -112,7 +109,7 @@ public Response createNode(@ApiParam(value = "File system name") @PathParam("fil @ApiParam(value = "Version") @QueryParam("version") int version, @ApiParam(value = "Node Meta Data") NodeGenericMetadata nodeMetadata) { AppStorage storage = appDataBean.getStorage(fileSystemName); - NodeInfo newNodeInfo = storage.createNode(nodeId, childName, nodePseudoClass, description, version, nodeMetadata); + NodeInfo newNodeInfo = storage.createNode(nodeId, childName, nodePseudoClass, description, version, nodeMetadata, new NodeAccessRights()); return Response.ok().entity(newNodeInfo).build(); } diff --git a/afs/afs-ws/afs-ws-storage/src/main/java/com/powsybl/afs/ws/storage/RemoteAppStorage.java b/afs/afs-ws/afs-ws-storage/src/main/java/com/powsybl/afs/ws/storage/RemoteAppStorage.java index 64f96a15eec..79fbae45079 100644 --- a/afs/afs-ws/afs-ws-storage/src/main/java/com/powsybl/afs/ws/storage/RemoteAppStorage.java +++ b/afs/afs-ws/afs-ws-storage/src/main/java/com/powsybl/afs/ws/storage/RemoteAppStorage.java @@ -11,6 +11,7 @@ import com.powsybl.afs.storage.AppStorage; import com.powsybl.afs.storage.NodeDependency; import com.powsybl.afs.storage.NodeGenericMetadata; +import com.powsybl.afs.storage.NodeAccessRights; import com.powsybl.afs.storage.NodeInfo; import com.powsybl.afs.storage.buffer.StorageChangeBuffer; import com.powsybl.afs.ws.client.utils.ClientUtils; @@ -302,18 +303,19 @@ public void updateModificationTime(String nodeId) { @Override public NodeInfo createNode(String parentNodeId, String name, String nodePseudoClass, String description, int version, - NodeGenericMetadata genericMetadata) { + NodeGenericMetadata genericMetadata, NodeAccessRights accessRights) { Objects.requireNonNull(parentNodeId); Objects.requireNonNull(name); Objects.requireNonNull(nodePseudoClass); Objects.requireNonNull(description); Objects.requireNonNull(genericMetadata); + Objects.requireNonNull(accessRights); // flush buffer to keep change order changeBuffer.flush(); - LOGGER.debug("createNode(fileSystemName={}, parentNodeId={}, name={}, nodePseudoClass={}, description={}, version={}, genericMetadata={})", - fileSystemName, parentNodeId, name, nodePseudoClass, description, version, genericMetadata); + LOGGER.debug("createNode(fileSystemName={}, parentNodeId={}, name={}, nodePseudoClass={}, description={}, version={}, genericMetadata={}, accessRights={})", + fileSystemName, parentNodeId, name, nodePseudoClass, description, version, genericMetadata, accessRights); Response response = webTarget.path("fileSystems/{fileSystemName}/nodes/{nodeId}/children/{childName}") .resolveTemplate(FILE_SYSTEM_NAME, fileSystemName) diff --git a/contingency/contingency-api/src/main/java/com/powsybl/contingency/afs/ContingencyStoreBuilder.java b/contingency/contingency-api/src/main/java/com/powsybl/contingency/afs/ContingencyStoreBuilder.java index 8e57ae98342..ff9ed26c6ea 100644 --- a/contingency/contingency-api/src/main/java/com/powsybl/contingency/afs/ContingencyStoreBuilder.java +++ b/contingency/contingency-api/src/main/java/com/powsybl/contingency/afs/ContingencyStoreBuilder.java @@ -10,6 +10,7 @@ import com.powsybl.afs.ProjectFileBuildContext; import com.powsybl.afs.ProjectFileBuilder; import com.powsybl.afs.ProjectFileCreationContext; +import com.powsybl.afs.storage.NodeAccessRights; import com.powsybl.afs.storage.NodeGenericMetadata; import com.powsybl.afs.storage.NodeInfo; @@ -45,7 +46,7 @@ public ContingencyStore build() { // create project file NodeInfo info = context.getStorage().createNode(context.getFolderInfo().getId(), name, ContingencyStore.PSEUDO_CLASS, - "", ContingencyStore.VERSION, new NodeGenericMetadata()); + "", ContingencyStore.VERSION, new NodeGenericMetadata(), new NodeAccessRights()); context.getStorage().setConsistent(info.getId()); diff --git a/scripting/src/test/java/com/powsybl/scripting/groovy/AbstractGroovyScriptTest.java b/scripting/src/test/java/com/powsybl/scripting/groovy/AbstractGroovyScriptTest.java index 79674b20abb..9965e670854 100644 --- a/scripting/src/test/java/com/powsybl/scripting/groovy/AbstractGroovyScriptTest.java +++ b/scripting/src/test/java/com/powsybl/scripting/groovy/AbstractGroovyScriptTest.java @@ -64,7 +64,7 @@ protected AppStorage createStorage() { .thenAnswer(invocationOnMock -> new NodeInfo("id", (String) invocationOnMock.getArguments()[0], (String) invocationOnMock.getArguments()[1], - "", 0L, 0L, 0, new NodeGenericMetadata())); + "", 0L, 0L, 0, new NodeGenericMetadata(), new NodeAccessRights())); return storage; } diff --git a/security-analysis/security-analysis-afs/src/main/java/com/powsybl/security/afs/SecurityAnalysisRunnerBuilder.java b/security-analysis/security-analysis-afs/src/main/java/com/powsybl/security/afs/SecurityAnalysisRunnerBuilder.java index 1ec96fca3e5..e0605e0d268 100644 --- a/security-analysis/security-analysis-afs/src/main/java/com/powsybl/security/afs/SecurityAnalysisRunnerBuilder.java +++ b/security-analysis/security-analysis-afs/src/main/java/com/powsybl/security/afs/SecurityAnalysisRunnerBuilder.java @@ -8,6 +8,7 @@ import com.powsybl.afs.*; import com.powsybl.afs.ext.base.ProjectCase; +import com.powsybl.afs.storage.NodeAccessRights; import com.powsybl.afs.storage.NodeGenericMetadata; import com.powsybl.afs.storage.NodeInfo; import com.powsybl.security.SecurityAnalysisParameters; @@ -80,7 +81,7 @@ public SecurityAnalysisRunner build() { // create project file NodeInfo info = context.getStorage().createNode(context.getFolderInfo().getId(), name, SecurityAnalysisRunner.PSEUDO_CLASS, - "", SecurityAnalysisRunner.VERSION, new NodeGenericMetadata()); + "", SecurityAnalysisRunner.VERSION, new NodeGenericMetadata(), new NodeAccessRights()); // create case link context.getStorage().addDependency(info.getId(), SecurityAnalysisRunner.CASE_DEPENDENCY_NAME, aCase.getId()); diff --git a/security-analysis/security-analysis-afs/src/test/java/com/powsybl/security/afs/SecurityAnalysisRunnerTest.java b/security-analysis/security-analysis-afs/src/test/java/com/powsybl/security/afs/SecurityAnalysisRunnerTest.java index 67c1f81fe41..125406ca1e1 100644 --- a/security-analysis/security-analysis-afs/src/test/java/com/powsybl/security/afs/SecurityAnalysisRunnerTest.java +++ b/security-analysis/security-analysis-afs/src/test/java/com/powsybl/security/afs/SecurityAnalysisRunnerTest.java @@ -12,6 +12,7 @@ import com.powsybl.afs.ext.base.*; import com.powsybl.afs.mapdb.storage.MapDbAppStorage; import com.powsybl.afs.storage.AppStorage; +import com.powsybl.afs.storage.NodeAccessRights; import com.powsybl.afs.storage.NodeGenericMetadata; import com.powsybl.afs.storage.NodeInfo; import com.powsybl.commons.datasource.DataSource; @@ -137,11 +138,11 @@ public void setup() throws IOException { // create network.net NodeInfo caseNode = storage.createNode(rootFolderInfo.getId(), "network", Case.PSEUDO_CLASS, "", Case.VERSION, - new NodeGenericMetadata().setString(Case.FORMAT, ImporterMock.FORMAT)); + new NodeGenericMetadata().setString(Case.FORMAT, ImporterMock.FORMAT), new NodeAccessRights()); // create network2.net NodeInfo caseNode2 = storage.createNode(rootFolderInfo.getId(), "network2", Case.PSEUDO_CLASS, "", Case.VERSION, - new NodeGenericMetadata().setString(Case.FORMAT, ImporterMock.FORMAT)); + new NodeGenericMetadata().setString(Case.FORMAT, ImporterMock.FORMAT), new NodeAccessRights()); storage.setConsistent(caseNode.getId()); storage.setConsistent(caseNode2.getId()); }