Skip to content

Commit

Permalink
Allow to override filesystem project node search
Browse files Browse the repository at this point in the history
Signed-off-by: GONCALVES Bruno <[email protected]>
(cherry picked from commit 08358ab)
  • Loading branch information
BrunoRte committed Jun 30, 2023
1 parent 608ac95 commit 5b88cf4
Showing 1 changed file with 23 additions and 23 deletions.
46 changes: 23 additions & 23 deletions afs-core/src/main/java/com/powsybl/afs/AppFileSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public <T extends ProjectFile> T findProjectFile(String projectFileId, Class<T>

// get file info
NodeInfo projectFileInfo = storage.getNodeInfo(projectFileId);
Project project = createProject(projectFileId, projectFileInfo);
Project project = createProject(projectFileInfo);

// then create the file
ProjectFile projectFile = project.createProjectFile(projectFileInfo);
Expand All @@ -140,21 +140,12 @@ public AbstractNodeBase fetchNode(String nodeId, boolean connected) {
Objects.requireNonNull(nodeId);

NodeInfo projectFileInfo = storage.getNodeInfo(nodeId);
NodeInfo parentInfo = storage.getParentNode(projectFileInfo.getId()).orElse(null);
while (parentInfo != null && !Project.PSEUDO_CLASS.equals(parentInfo.getPseudoClass())) {
parentInfo = storage.getParentNode(parentInfo.getId()).orElse(null);
}

NodeInfo projectInfo = parentInfo;
while (projectInfo != null && !Project.PSEUDO_CLASS.equals(projectInfo.getPseudoClass())) {
projectInfo = storage.getParentNode(projectInfo.getId()).orElse(null);
}
Project project = projectInfo != null && Project.PSEUDO_CLASS.equals(projectInfo.getPseudoClass()) ?
new Project(new FileCreationContext(projectInfo, storage, this)) : null;
NodeInfo projectInfo = searchProject(projectFileInfo.getId());

if (parentInfo == null || project == null) {
if (projectInfo == null) {
return createNode(projectFileInfo);
}
Project project = new Project(new FileCreationContext(projectInfo, storage, this));

ProjectFileCreationContext context = new ProjectFileCreationContext(projectFileInfo, storage, project, connected);

Expand Down Expand Up @@ -204,28 +195,37 @@ public ProjectFolder findProjectFolder(String projectFolderId) {
// get file info
NodeInfo projectFolderInfo = storage.getNodeInfo(projectFolderId);

// walk the node hierarchy until finding a project
Project project = createProject(projectFolderId, projectFolderInfo);
Project project = createProject(projectFolderInfo);

// then create and return the projectFolder

return project.createProjectFolder(projectFolderInfo);
}

private Project createProject(String projectNodeId, NodeInfo projectNodeInfo) {
// walk the node hierarchy until finding a project
NodeInfo parentInfo = storage.getParentNode(projectNodeInfo.getId()).orElse(null);
while (parentInfo != null && !Project.PSEUDO_CLASS.equals(parentInfo.getPseudoClass())) {
parentInfo = storage.getParentNode(parentInfo.getId()).orElse(null);
}
private Project createProject(NodeInfo projectNodeInfo) {
NodeInfo parentInfo = searchProject(projectNodeInfo.getId());

if (parentInfo == null) {
throw new AfsException("Node '" + projectNodeId + " parent project cannot be found.");
throw new AfsException("Node '" + projectNodeInfo.getId() + " parent project cannot be found.");
}

// create the project
return new Project(new FileCreationContext(parentInfo, storage, this));
}

/**
* Find the project of the node
* @param nodeId The node id
* @return Project info or null if not found
*/
protected NodeInfo searchProject(String nodeId) {
// walk the node hierarchy until finding a project
NodeInfo parentInfo = storage.getParentNode(nodeId).orElse(null);
while (parentInfo != null && !Project.PSEUDO_CLASS.equals(parentInfo.getPseudoClass())) {
parentInfo = storage.getParentNode(parentInfo.getId()).orElse(null);
}
return parentInfo;
}

public TaskMonitor getTaskMonitor() {
return taskMonitor;
}
Expand Down

0 comments on commit 5b88cf4

Please sign in to comment.