mirror of
https://github.com/dbeaver/cloudbeaver.git
synced 2026-09-24 16:04:36 +08:00
CB-3686 remove rm resource path from events (#1824)
Co-authored-by: Daria Marutkina <125263541+dariamarutkina@users.noreply.github.com>
This commit is contained in:
+2
-2
@@ -19,7 +19,7 @@ public abstract class DBNAbstractResourceManagerNode extends DBNNode implements
|
||||
super(parentNode);
|
||||
}
|
||||
|
||||
public void removeChildResourceNode(@NotNull Queue<RMResource> resourcePath) {
|
||||
public void removeChildResourceNode(@NotNull Queue<String> resourcePath) {
|
||||
if (children == null || resourcePath.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
@@ -49,7 +49,7 @@ public abstract class DBNAbstractResourceManagerNode extends DBNNode implements
|
||||
return;
|
||||
}
|
||||
var expectedResource = resourcePath.poll();
|
||||
var node = RMNavigatorUtils.findResourceNode(children, expectedResource);
|
||||
var node = RMNavigatorUtils.findResourceNode(children, expectedResource.getName());
|
||||
if (node == null) { // we are in expected parent node
|
||||
DBNResourceManagerResource newResourceNode = new DBNResourceManagerResource(this, expectedResource);
|
||||
children = ArrayUtils.add(DBNResourceManagerResource.class, children, newResourceNode);
|
||||
|
||||
+1
-1
@@ -101,7 +101,7 @@ public class DBNResourceManagerProject extends DBNAbstractResourceManagerNode {
|
||||
return children;
|
||||
}
|
||||
|
||||
public RMController getResourceController() {
|
||||
protected RMController getResourceController() {
|
||||
return ((DBNResourceManagerRoot) getParentNode()).getResourceController();
|
||||
}
|
||||
|
||||
|
||||
+21
-6
@@ -20,6 +20,7 @@ package io.cloudbeaver.model.rm;
|
||||
import io.cloudbeaver.model.session.WebSession;
|
||||
import org.jkiss.code.NotNull;
|
||||
import org.jkiss.dbeaver.DBException;
|
||||
import org.jkiss.dbeaver.Log;
|
||||
import org.jkiss.dbeaver.model.DBPHiddenObject;
|
||||
import org.jkiss.dbeaver.model.DBPImage;
|
||||
import org.jkiss.dbeaver.model.app.DBPProject;
|
||||
@@ -34,6 +35,8 @@ import java.util.*;
|
||||
|
||||
public class DBNResourceManagerRoot extends DBNNode implements DBPHiddenObject, RMEventListener {
|
||||
|
||||
private static final Log log = Log.getLog(DBNResourceManagerRoot.class);
|
||||
|
||||
private DBNResourceManagerProject[] projects;
|
||||
private RMController resourceController;
|
||||
|
||||
@@ -123,10 +126,10 @@ public class DBNResourceManagerRoot extends DBNNode implements DBPHiddenObject,
|
||||
var action = event.getAction();
|
||||
switch (action) {
|
||||
case RESOURCE_DELETE:
|
||||
deleteResourceNode(event.getProject(), event.getResourceTree());
|
||||
deleteResourceNode(event.getProject(), event.getResourcePath());
|
||||
break;
|
||||
case RESOURCE_ADD:
|
||||
addResourceNode(event.getProject(), event.getResourceTree());
|
||||
addResourceNode(event.getProject(), event.getResourcePath());
|
||||
break;
|
||||
case PROJECT_ADD:
|
||||
addProjectNode(event.getProject());
|
||||
@@ -134,9 +137,13 @@ public class DBNResourceManagerRoot extends DBNNode implements DBPHiddenObject,
|
||||
}
|
||||
}
|
||||
|
||||
private void deleteResourceNode(RMProject project, List<RMResource> resourcePath) {
|
||||
private void deleteResourceNode(RMProject project, String resourcePath) {
|
||||
if (resourcePath == null) {
|
||||
return;
|
||||
}
|
||||
var projectNode = getProjectNode(project);
|
||||
projectNode.ifPresent(dbnResourceManagerProject -> dbnResourceManagerProject.removeChildResourceNode(new ArrayDeque<>(resourcePath)));
|
||||
var rmResourcePath = Arrays.asList(resourcePath.split("/"));
|
||||
projectNode.ifPresent(dbnResourceManagerProject -> dbnResourceManagerProject.removeChildResourceNode(new ArrayDeque<>(rmResourcePath)));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -146,9 +153,17 @@ public class DBNResourceManagerRoot extends DBNNode implements DBPHiddenObject,
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
private void addResourceNode(RMProject project, List<RMResource> resourcePath) {
|
||||
private void addResourceNode(RMProject project, String resourcePath) {
|
||||
if (resourcePath == null) {
|
||||
return;
|
||||
}
|
||||
var projectNode = getProjectNode(project);
|
||||
projectNode.ifPresent(dbnResourceManagerProject -> dbnResourceManagerProject.addChildResourceNode(new ArrayDeque<>(resourcePath)));
|
||||
try {
|
||||
var rmResourcePath = Arrays.asList(getResourceController().getResourcePath(project.getId(), resourcePath));
|
||||
projectNode.ifPresent(dbnResourceManagerProject -> dbnResourceManagerProject.addChildResourceNode(new ArrayDeque<>(rmResourcePath)));
|
||||
} catch (DBException e) {
|
||||
log.error("Cannot add new node to resource manager tree", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void addProjectNode(RMProject project) {
|
||||
|
||||
+2
-2
@@ -3,11 +3,11 @@ package io.cloudbeaver.model.rm;
|
||||
import org.jkiss.dbeaver.model.rm.RMResource;
|
||||
|
||||
class RMNavigatorUtils {
|
||||
public static DBNResourceManagerResource findResourceNode(DBNResourceManagerResource[] resourceNodes, RMResource expectedResource) {
|
||||
public static DBNResourceManagerResource findResourceNode(DBNResourceManagerResource[] resourceNodes, String expectedResource) {
|
||||
DBNResourceManagerResource node = null;
|
||||
for (DBNResourceManagerResource resourceNode : resourceNodes) {
|
||||
var nodeResource = resourceNode.getResource();
|
||||
if (nodeResource.getName().equals(expectedResource.getName()) && nodeResource.isFolder() == expectedResource.isFolder()) {
|
||||
if (nodeResource.getName().equals(expectedResource)) {
|
||||
node = resourceNode;
|
||||
break;
|
||||
}
|
||||
|
||||
+4
-6
@@ -608,7 +608,6 @@ public class LocalResourceController implements RMController {
|
||||
"' in project '" + projectId + "'") ;
|
||||
}
|
||||
Path oldTargetPath = getTargetPath(projectId, normalizedOldResourcePath);
|
||||
List<RMResource> rmOldResourcePath = makeResourcePath(projectId, oldTargetPath, false);
|
||||
|
||||
doFileWriteOperation(projectId, oldTargetPath, () -> {
|
||||
if (!Files.exists(oldTargetPath)) {
|
||||
@@ -631,7 +630,7 @@ public class LocalResourceController implements RMController {
|
||||
return null;
|
||||
});
|
||||
|
||||
fireRmResourceDeleteEvent(projectId, rmOldResourcePath);
|
||||
fireRmResourceDeleteEvent(projectId, normalizedOldResourcePath);
|
||||
fireRmResourceAddEvent(projectId, normalizedNewResourcePath);
|
||||
}
|
||||
|
||||
@@ -673,7 +672,6 @@ public class LocalResourceController implements RMController {
|
||||
}
|
||||
validateResourcePath(resourcePath);
|
||||
Path targetPath = getTargetPath(projectId, resourcePath);
|
||||
List<RMResource> rmResourcePath = makeResourcePath(projectId, targetPath, recursive);
|
||||
doFileWriteOperation(projectId, targetPath, () -> {
|
||||
if (!Files.exists(targetPath)) {
|
||||
throw new DBException("Resource '" + resourcePath + "' doesn't exists");
|
||||
@@ -706,7 +704,7 @@ public class LocalResourceController implements RMController {
|
||||
});
|
||||
|
||||
log.debug("Fire resource delete event");
|
||||
fireRmResourceDeleteEvent(projectId, rmResourcePath);
|
||||
fireRmResourceDeleteEvent(projectId, resourcePath);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1068,11 +1066,11 @@ public class LocalResourceController implements RMController {
|
||||
RMEventManager.fireEvent(
|
||||
new RMEvent(RMEvent.Action.RESOURCE_ADD,
|
||||
getProject(projectId, false, false),
|
||||
Arrays.asList(getResourcePath(projectId, resourcePath)))
|
||||
resourcePath)
|
||||
);
|
||||
}
|
||||
|
||||
private void fireRmResourceDeleteEvent(@NotNull String projectId, @NotNull List<RMResource> resourcePath) throws DBException {
|
||||
private void fireRmResourceDeleteEvent(@NotNull String projectId, @NotNull String resourcePath) throws DBException {
|
||||
RMEventManager.fireEvent(
|
||||
new RMEvent(RMEvent.Action.RESOURCE_DELETE,
|
||||
makeProjectFromId(projectId, false),
|
||||
|
||||
@@ -130,18 +130,16 @@ public class WebEventUtils {
|
||||
String projectId,
|
||||
WebSession session,
|
||||
String resourcePath,
|
||||
RMResource[] resourceParsedPath,
|
||||
WSConstants.EventAction eventAction,
|
||||
WSResourceProperty property
|
||||
) {
|
||||
addRmResourceUpdatedEvent(projectId, session, resourcePath, resourceParsedPath, eventAction, property, null);
|
||||
addRmResourceUpdatedEvent(projectId, session, resourcePath, eventAction, property, null);
|
||||
}
|
||||
|
||||
public static void addRmResourceUpdatedEvent(
|
||||
String projectId,
|
||||
WebSession session,
|
||||
String resourcePath,
|
||||
RMResource[] resourceParsedPath,
|
||||
WSConstants.EventAction eventAction,
|
||||
WSResourceProperty property,
|
||||
String details
|
||||
@@ -154,7 +152,6 @@ public class WebEventUtils {
|
||||
session.getUserId(),
|
||||
projectId,
|
||||
resourcePath,
|
||||
resourceParsedPath,
|
||||
property,
|
||||
details
|
||||
);
|
||||
@@ -165,7 +162,6 @@ public class WebEventUtils {
|
||||
session.getUserId(),
|
||||
projectId,
|
||||
resourcePath,
|
||||
resourceParsedPath,
|
||||
property,
|
||||
details
|
||||
);
|
||||
@@ -176,7 +172,6 @@ public class WebEventUtils {
|
||||
session.getUserId(),
|
||||
projectId,
|
||||
resourcePath,
|
||||
resourceParsedPath,
|
||||
property,
|
||||
details
|
||||
);
|
||||
|
||||
+4
-11
@@ -43,35 +43,28 @@ public class WSRmResourceUpdatedEventHandlerImpl extends WSAbstractProjectEventH
|
||||
@Override
|
||||
protected void updateSessionData(@NotNull BaseWebSession activeUserSession, @NotNull WSResourceUpdatedEvent event) {
|
||||
if (activeUserSession instanceof WebSession) {
|
||||
var parsedResourcePath = event.getResourceParsedPath();
|
||||
var resourceParsedPath = parsedResourcePath instanceof RMResource[]
|
||||
? (RMResource[]) parsedResourcePath
|
||||
: gson.fromJson(gson.toJson(parsedResourcePath), RMResource[].class);
|
||||
var webSession = (WebSession) activeUserSession;
|
||||
acceptChangesInNavigatorTree(
|
||||
WSEventType.valueById(event.getId()),
|
||||
resourceParsedPath,
|
||||
event.getResourcePath(),
|
||||
webSession.getProjectById(event.getProjectId())
|
||||
);
|
||||
}
|
||||
activeUserSession.addSessionEvent(event);
|
||||
}
|
||||
|
||||
private void acceptChangesInNavigatorTree(WSEventType eventType,
|
||||
RMResource[] resourceParsedPath,
|
||||
WebProjectImpl project) {
|
||||
List<RMResource> rmResourcePath = Arrays.asList(resourceParsedPath);
|
||||
private void acceptChangesInNavigatorTree(WSEventType eventType, String resourcePath, WebProjectImpl project) {
|
||||
if (eventType == WSEventType.RM_RESOURCE_CREATED) {
|
||||
RMEventManager.fireEvent(
|
||||
new RMEvent(RMEvent.Action.RESOURCE_ADD,
|
||||
project.getRmProject(),
|
||||
rmResourcePath)
|
||||
resourcePath)
|
||||
);
|
||||
} else if (eventType == WSEventType.RM_RESOURCE_DELETED) {
|
||||
RMEventManager.fireEvent(
|
||||
new RMEvent(RMEvent.Action.RESOURCE_DELETE,
|
||||
project.getRmProject(),
|
||||
rmResourcePath)
|
||||
resourcePath)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-16
@@ -425,12 +425,9 @@ public class WebServiceNavigator implements DBWServiceNavigator {
|
||||
String projectId = rmNode.getResourceProject().getId();
|
||||
// Get paths from nodes
|
||||
String resourcePath = rmNode.getResourceFolder();
|
||||
RMController rmController = session.getRmController();
|
||||
var oldRmResourcePath = rmController.getResourcePath(projectId, resourcePath);
|
||||
node.rename(session.getProgressMonitor(), newName);
|
||||
var newPath = rmNode.getResourceFolder();
|
||||
var newRmResourcePath = rmController.getResourcePath(projectId, newPath);
|
||||
addRmMoveEvent(session, projectId, resourcePath, newPath, oldRmResourcePath, newRmResourcePath);
|
||||
addRmMoveEvent(session, projectId, resourcePath, newPath);
|
||||
return node.getName();
|
||||
}
|
||||
|
||||
@@ -438,22 +435,18 @@ public class WebServiceNavigator implements DBWServiceNavigator {
|
||||
@NotNull WebSession session,
|
||||
String projectId,
|
||||
String oldResourcePath,
|
||||
String newResourcePath,
|
||||
RMResource[] oldRmResourcePath,
|
||||
RMResource[] newRmResourcePath
|
||||
String newResourcePath
|
||||
) {
|
||||
WebEventUtils.addRmResourceUpdatedEvent(
|
||||
projectId,
|
||||
session,
|
||||
oldResourcePath,
|
||||
oldRmResourcePath,
|
||||
WSConstants.EventAction.DELETE,
|
||||
WSResourceProperty.NAME);
|
||||
WebEventUtils.addRmResourceUpdatedEvent(
|
||||
projectId,
|
||||
session,
|
||||
newResourcePath,
|
||||
newRmResourcePath,
|
||||
WSConstants.EventAction.CREATE,
|
||||
WSResourceProperty.NAME);
|
||||
}
|
||||
@@ -515,13 +508,11 @@ public class WebServiceNavigator implements DBWServiceNavigator {
|
||||
DBNResourceManagerResource rmResource = ((DBNResourceManagerResource) node);
|
||||
String resourceProjectId = rmResource.getResourceProject().getId();
|
||||
String resourcePath = rmResource.getResourceFolder();
|
||||
var rmResourcePath = session.getRmController().getResourcePath(resourceProjectId, resourcePath);
|
||||
session.getRmController().deleteResource(resourceProjectId, resourcePath, true);
|
||||
WebEventUtils.addRmResourceUpdatedEvent(
|
||||
resourceProjectId,
|
||||
session,
|
||||
resourcePath,
|
||||
rmResourcePath,
|
||||
WSConstants.EventAction.DELETE,
|
||||
WSResourceProperty.NAME);
|
||||
}
|
||||
@@ -614,11 +605,8 @@ public class WebServiceNavigator implements DBWServiceNavigator {
|
||||
newPath = ((DBNResourceManagerResource) folderNode).getResourceFolder() + "/" + newPath;
|
||||
}
|
||||
String resourcePath = rmOldNode.getResourceFolder();
|
||||
RMController rmController = session.getRmController();
|
||||
var oldRmResourcePath = rmController.getResourcePath(projectId, resourcePath);
|
||||
rmController.moveResource(projectId, resourcePath, newPath);
|
||||
var newRmResourcePath = rmController.getResourcePath(projectId, newPath);
|
||||
addRmMoveEvent(session, projectId, resourcePath, newPath, oldRmResourcePath, newRmResourcePath);
|
||||
session.getRmController().moveResource(projectId, resourcePath, newPath);
|
||||
addRmMoveEvent(session, projectId, resourcePath, newPath);
|
||||
} else {
|
||||
throw new DBWebException("Navigator node '" + path + "' is not a data source node");
|
||||
}
|
||||
|
||||
+1
-10
@@ -118,7 +118,6 @@ public class WebServiceRM implements DBWServiceRM {
|
||||
projectId,
|
||||
webSession,
|
||||
resourcePath,
|
||||
getResourceController(webSession).getResourcePath(projectId, resourcePath),
|
||||
WSConstants.EventAction.UPDATE,
|
||||
WSResourceProperty.PROPERTY,
|
||||
propertyName);
|
||||
@@ -156,7 +155,6 @@ public class WebServiceRM implements DBWServiceRM {
|
||||
projectId,
|
||||
webSession,
|
||||
resourcePath,
|
||||
getResourceController(webSession).getResourcePath(projectId, resourcePath),
|
||||
WSConstants.EventAction.CREATE,
|
||||
WSResourceProperty.NAME);
|
||||
return result;
|
||||
@@ -172,13 +170,11 @@ public class WebServiceRM implements DBWServiceRM {
|
||||
) throws DBException {
|
||||
checkIsRmEnabled(webSession);
|
||||
try {
|
||||
var rmResourcePath = getResourceController(webSession).getResourcePath(projectId, resourcePath);
|
||||
getResourceController(webSession).deleteResource(projectId, resourcePath, false);
|
||||
WebEventUtils.addRmResourceUpdatedEvent(
|
||||
projectId,
|
||||
webSession,
|
||||
resourcePath,
|
||||
rmResourcePath,
|
||||
WSConstants.EventAction.DELETE,
|
||||
WSResourceProperty.NAME);
|
||||
return true;
|
||||
@@ -196,22 +192,18 @@ public class WebServiceRM implements DBWServiceRM {
|
||||
checkIsRmEnabled(webSession);
|
||||
try {
|
||||
var resourceController = getResourceController(webSession);
|
||||
var oldRmResourcePath = resourceController.getResourcePath(projectId, oldResourcePath);
|
||||
resourceController.moveResource(projectId, oldResourcePath, newResourcePath);;
|
||||
var newRmResourcePath = resourceController.getResourcePath(projectId, newResourcePath);
|
||||
resourceController.moveResource(projectId, oldResourcePath, newResourcePath);
|
||||
|
||||
WebEventUtils.addRmResourceUpdatedEvent(
|
||||
projectId,
|
||||
webSession,
|
||||
oldResourcePath,
|
||||
oldRmResourcePath,
|
||||
WSConstants.EventAction.DELETE,
|
||||
WSResourceProperty.NAME);
|
||||
WebEventUtils.addRmResourceUpdatedEvent(
|
||||
projectId,
|
||||
webSession,
|
||||
newResourcePath,
|
||||
newRmResourcePath,
|
||||
WSConstants.EventAction.CREATE,
|
||||
WSResourceProperty.NAME);
|
||||
return true;
|
||||
@@ -241,7 +233,6 @@ public class WebServiceRM implements DBWServiceRM {
|
||||
projectId,
|
||||
webSession,
|
||||
resourcePath,
|
||||
getResourceController(webSession).getResourcePath(projectId, resourcePath),
|
||||
eventType,
|
||||
WSResourceProperty.CONTENT);
|
||||
return content;
|
||||
|
||||
Reference in New Issue
Block a user