Skip to content

Commit

Permalink
Addition of access rights on AFS nodes (#827)
Browse files Browse the repository at this point in the history
Signed-off-by: NOIR Nicolas ext <[email protected]>
  • Loading branch information
NOIR Nicolas ext authored and niconoir committed Nov 6, 2019
1 parent 409ea3e commit 3e601c5
Show file tree
Hide file tree
Showing 38 changed files with 358 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
7 changes: 4 additions & 3 deletions afs/afs-core/src/main/java/com/powsybl/afs/Folder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -87,7 +88,7 @@ public Optional<Folder> 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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -108,7 +109,7 @@ public Optional<ProjectFolder> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
}
Expand Down Expand Up @@ -112,7 +113,7 @@ class TacBuilder implements ProjectFileBuilder<Tac> {

@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()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -78,9 +79,8 @@ protected List<ServiceExtension> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -65,6 +66,11 @@ public NodeGenericMetadata getGenericMetadata() {
return new NodeGenericMetadata().setString("format", importer.getFormat());
}

@Override
public NodeAccessRights getAccessRights() {
return new NodeAccessRights();
}

@Override
public Optional<InputStream> readBinaryData(String name) {
DataSource dataSource = Importers.createDataSource(file);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;

Expand All @@ -27,6 +28,8 @@ public interface LocalFile extends LocalNode {

NodeGenericMetadata getGenericMetadata();

NodeAccessRights getAccessRights();

Optional<InputStream> readBinaryData(String name);

boolean dataExists(String name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand All @@ -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<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,6 +16,7 @@
import java.io.IOException;
import java.io.Serializable;
import java.util.Map;
import java.util.Objects;

/**
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
Expand Down Expand Up @@ -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<String, Short> e : nodeInfo.getAccessRights().getUsersRights().entrySet()) {
out.writeUTF(e.getKey());
out.writeShort(e.getValue());
}
out.writeInt(nodeInfo.getAccessRights().getGroupsRights().size());
for (Map.Entry<String, Short> 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
Expand Down Expand Up @@ -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);
}
}
Loading

0 comments on commit 3e601c5

Please sign in to comment.