From 091720a1c45088618b7ac4746d99f93bfcba1b90 Mon Sep 17 00:00:00 2001 From: Yves Langisch Date: Thu, 28 Nov 2024 11:42:51 +0100 Subject: [PATCH] Fix naming. --- .../core/deepbox/DeepboxIdProvider.java | 41 ++++++++++++++++--- .../core/deepbox/DeepboxListService.java | 4 +- .../deepbox/DeepboxDirectoryFeatureTest.java | 4 +- .../core/deepbox/DeepboxIdProviderTest.java | 8 ++-- .../core/deepbox/DeepboxListServiceTest.java | 2 +- 5 files changed, 45 insertions(+), 14 deletions(-) diff --git a/deepbox/src/main/java/ch/cyberduck/core/deepbox/DeepboxIdProvider.java b/deepbox/src/main/java/ch/cyberduck/core/deepbox/DeepboxIdProvider.java index d2247fa2c4d..298dcacc36c 100644 --- a/deepbox/src/main/java/ch/cyberduck/core/deepbox/DeepboxIdProvider.java +++ b/deepbox/src/main/java/ch/cyberduck/core/deepbox/DeepboxIdProvider.java @@ -113,18 +113,32 @@ protected Path normalize(final Path file) { while(!segments.isEmpty()) { Path segment = segments.pop(); if(containerService.isSharedWithMe(segment)) { - final String combined = segments.pop().getName(); - final Matcher matcher = SHARED.matcher(combined); + final Path combined = segments.pop(); + final String name = combined.getName(); + final Matcher matcher = SHARED.matcher(name); if(matcher.matches()) { - final String deepboxName = matcher.group(1); + final String companyName = matcher.group(1); final String boxName = matcher.group(2); final EnumSet type = EnumSet.copyOf(segment.getType()); type.add(AbstractPath.Type.shared); - final Path deepbox = new Path(result, deepboxName, type, new PathAttributes(segment.attributes()).withFileId(null)); + String deepboxName; + if(combined.attributes().getCustom().containsKey("deepboxName")) { + deepboxName = combined.attributes().getCustom().get("deepboxName"); + } + else { + try { + deepboxName = this.lookupDeepboxName(this.getCompanyNodeId(file), companyName, boxName); + } + catch(BackgroundException e) { + log.warn("Cannot find Deepbox for company {} and box {}", companyName, boxName); + return file; + } + } + final Path deepbox = new Path(result, deepboxName, type, new PathAttributes(combined.attributes()).withFileId(null)); result = new Path(deepbox, boxName, type, segment.attributes()); } else { - log.warn("Folder {} does not match pattern {}", combined, SHARED.pattern()); + log.warn("Folder {} does not match pattern {}", name, SHARED.pattern()); return file; } } @@ -139,6 +153,23 @@ protected Path normalize(final Path file) { return result; } + private String lookupDeepboxName(final String companyId, final String companyName, final String boxName) throws BackgroundException { + final OverviewRestControllerApi rest = new OverviewRestControllerApi(session.getClient()); + try { + final Overview overview = rest.getOverview(companyId, chunksize, null); + for(final BoxEntry box : overview.getSharedWithMe().getBoxes()) { + if(StringUtils.equals(companyName, DeepboxPathNormalizer.name(box.getCompany().getDisplayName())) && + StringUtils.equals(boxName, DeepboxPathNormalizer.name(box.getBoxName()))) { + return box.getDeepBoxName(); + } + } + } + catch(ApiException e) { + throw new DeepboxExceptionMappingService(this).map(String.format("Failure finding Deepbox for company %s and box %s", companyName, boxName), e); + } + throw new NotfoundException(String.format("Cannot find Deepbox for company %s and box %s", companyName, boxName)); + } + private Deque decompose(final Path path) { final Deque walk = new ArrayDeque<>(); Path next = path; diff --git a/deepbox/src/main/java/ch/cyberduck/core/deepbox/DeepboxListService.java b/deepbox/src/main/java/ch/cyberduck/core/deepbox/DeepboxListService.java index a932a46cd66..95eca587b19 100644 --- a/deepbox/src/main/java/ch/cyberduck/core/deepbox/DeepboxListService.java +++ b/deepbox/src/main/java/ch/cyberduck/core/deepbox/DeepboxListService.java @@ -350,9 +350,9 @@ public AttributedList list(final Path directory, final ListProgressListene final Overview overview = rest.getOverview(companyId, chunksize, null); for(final BoxEntry box : overview.getSharedWithMe().getBoxes()) { list.add(new Path(directory, - String.format("%s (%s)", DeepboxPathNormalizer.name(box.getDeepBoxName()), DeepboxPathNormalizer.name(box.getBoxName())), + String.format("%s (%s)", DeepboxPathNormalizer.name(box.getCompany().getDisplayName()), DeepboxPathNormalizer.name(box.getBoxName())), EnumSet.of(Path.Type.directory, Path.Type.volume), - new PathAttributes().withFileId(box.getBoxNodeId())) + new PathAttributes().withFileId(box.getBoxNodeId()).withCustom("deepboxName", box.getDeepBoxName())) ); } listener.chunk(directory, list); diff --git a/deepbox/src/test/java/ch/cyberduck/core/deepbox/DeepboxDirectoryFeatureTest.java b/deepbox/src/test/java/ch/cyberduck/core/deepbox/DeepboxDirectoryFeatureTest.java index cd1890357ed..be32b3ef4be 100644 --- a/deepbox/src/test/java/ch/cyberduck/core/deepbox/DeepboxDirectoryFeatureTest.java +++ b/deepbox/src/test/java/ch/cyberduck/core/deepbox/DeepboxDirectoryFeatureTest.java @@ -83,7 +83,7 @@ public void testBox() { public void testSharedWithMe_Box() { final DeepboxIdProvider nodeid = new DeepboxIdProvider(session); final DeepboxDirectoryFeature directory = new DeepboxDirectoryFeature(session, nodeid); - final Path parent = new Path(String.format("/ORG 1 - DeepBox Desktop App/%s/Testing (1 Christian Gruber)", DeepboxListService.SHARED), EnumSet.of(Path.Type.directory)); + final Path parent = new Path(String.format("/ORG 1 - DeepBox Desktop App/%s/Demo 1 (1 Christian Gruber)", DeepboxListService.SHARED), EnumSet.of(Path.Type.directory)); final Path folder = new Path(parent, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); assertThrows(AccessDeniedException.class, () -> directory.preflight(parent, folder.getName())); assertThrows(AccessDeniedException.class, () -> directory.mkdir(folder, new TransferStatus())); @@ -103,7 +103,7 @@ public void testInbox() { public void testSharedWithMe_Inbox() { final DeepboxIdProvider nodeid = new DeepboxIdProvider(session); final DeepboxDirectoryFeature directory = new DeepboxDirectoryFeature(session, nodeid); - final Path parent = new Path(String.format("/ORG 1 - DeepBox Desktop App/%s/Testing (1 Christian Gruber)/Inbox", DeepboxListService.SHARED), EnumSet.of(Path.Type.directory)); + final Path parent = new Path(String.format("/ORG 1 - DeepBox Desktop App/%s/Demo 1 (1 Christian Gruber)/Inbox", DeepboxListService.SHARED), EnumSet.of(Path.Type.directory)); final Path folder = new Path(parent, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory)); assertThrows(AccessDeniedException.class, () -> directory.preflight(parent, folder.getName())); assertThrows(InteroperabilityException.class, () -> directory.mkdir(folder, new TransferStatus())); diff --git a/deepbox/src/test/java/ch/cyberduck/core/deepbox/DeepboxIdProviderTest.java b/deepbox/src/test/java/ch/cyberduck/core/deepbox/DeepboxIdProviderTest.java index 2076b5210ac..159485cd2f1 100644 --- a/deepbox/src/test/java/ch/cyberduck/core/deepbox/DeepboxIdProviderTest.java +++ b/deepbox/src/test/java/ch/cyberduck/core/deepbox/DeepboxIdProviderTest.java @@ -86,7 +86,7 @@ public void testBox() throws Exception { @Test public void testSharedWithMe_Box() throws Exception { final DeepboxIdProvider nodeid = new DeepboxIdProvider(session); - final Path directory = new Path(String.format("/ORG 1 - DeepBox Desktop App/%s/Testing (1 Christian Gruber)", DeepboxListService.SHARED), EnumSet.of(Path.Type.directory, Path.Type.volume, AbstractPath.Type.shared)); + final Path directory = new Path(String.format("/ORG 1 - DeepBox Desktop App/%s/Demo 1 (1 Christian Gruber)", DeepboxListService.SHARED), EnumSet.of(Path.Type.directory, Path.Type.volume, AbstractPath.Type.shared)); assertEquals(SHARED_DEEPBOX_BOX, nodeid.getFileId(directory)); assertEquals(SHARED_DEEPBOX, nodeid.getDeepBoxNodeId(directory)); assertEquals(SHARED_DEEPBOX_BOX, nodeid.getBoxNodeId(directory)); @@ -107,7 +107,7 @@ public void testInbox() throws Exception { @Test public void testSharedWithMe_Inbox() throws Exception { final DeepboxIdProvider nodeid = new DeepboxIdProvider(session); - final Path directory = new Path(String.format("/ORG 1 - DeepBox Desktop App/%s/Testing (1 Christian Gruber)/Inbox", DeepboxListService.SHARED), EnumSet.of(Path.Type.directory, Path.Type.volume, AbstractPath.Type.shared)); + final Path directory = new Path(String.format("/ORG 1 - DeepBox Desktop App/%s/Demo 1 (1 Christian Gruber)/Inbox", DeepboxListService.SHARED), EnumSet.of(Path.Type.directory, Path.Type.volume, AbstractPath.Type.shared)); assertEquals("b13b6754-2b9a-4867-888c-cbd72fe353c3", nodeid.getFileId(directory)); assertEquals(ORG1, nodeid.getCompanyNodeId(directory)); assertEquals(SHARED_DEEPBOX, nodeid.getDeepBoxNodeId(directory)); @@ -162,7 +162,7 @@ public void testFile() throws Exception { @Test public void testSharedWithMe_File() throws Exception { final DeepboxIdProvider nodeid = new DeepboxIdProvider(session); - final Path file = new Path(String.format("/ORG 1 - DeepBox Desktop App/%s/Testing (1 Christian Gruber)/Documents/Bookkeeping/screenshot.png", DeepboxListService.SHARED), EnumSet.of(Path.Type.directory, Path.Type.volume, AbstractPath.Type.shared)); + final Path file = new Path(String.format("/ORG 1 - DeepBox Desktop App/%s/Demo 1 (1 Christian Gruber)/Documents/Bookkeeping/screenshot.png", DeepboxListService.SHARED), EnumSet.of(Path.Type.directory, Path.Type.volume, AbstractPath.Type.shared)); assertEquals("0fb9536b-391c-4d07-bcff-0d6d0e7cd2d7", nodeid.getFileId(file)); assertEquals(ORG1, nodeid.getCompanyNodeId(file)); assertEquals(SHARED_DEEPBOX, nodeid.getDeepBoxNodeId(file)); @@ -173,7 +173,7 @@ public void testSharedWithMe_File() throws Exception { @Test public void testNormalizeInboxInSharedWithMe() { final DeepboxIdProvider nodeid = new DeepboxIdProvider(session); - final Path directory = new Path(String.format("/ORG 1 - DeepBox Desktop App/%s/Testing (1 Christian Gruber)/Inbox/", DeepboxListService.SHARED), EnumSet.of(Path.Type.directory, Path.Type.volume)); + final Path directory = new Path(String.format("/ORG 1 - DeepBox Desktop App/%s/Demo 1 (1 Christian Gruber)/Inbox/", DeepboxListService.SHARED), EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path normalized = new Path("/ORG 1 - DeepBox Desktop App/Testing/1 Christian Gruber/Inbox/", EnumSet.of(Path.Type.directory, Path.Type.volume, AbstractPath.Type.shared)); assertEquals(new SimplePathPredicate(normalized), new SimplePathPredicate(nodeid.normalize(directory))); Path p = nodeid.normalize(directory); diff --git a/deepbox/src/test/java/ch/cyberduck/core/deepbox/DeepboxListServiceTest.java b/deepbox/src/test/java/ch/cyberduck/core/deepbox/DeepboxListServiceTest.java index 21b42d95a9f..9f84029bdf0 100644 --- a/deepbox/src/test/java/ch/cyberduck/core/deepbox/DeepboxListServiceTest.java +++ b/deepbox/src/test/java/ch/cyberduck/core/deepbox/DeepboxListServiceTest.java @@ -144,7 +144,7 @@ public void testListSharedBoxes() throws Exception { final AttributedList list = new DeepboxListService(session, nodeid).list(shared, new DisabledListProgressListener()); assertNotSame(AttributedList.emptyList(), list); assertFalse(list.isEmpty()); - assertNotNull(list.find(new SimplePathPredicate(new Path(String.format("/ORG 1 - DeepBox Desktop App/%s/Testing (1 Christian Gruber)", DeepboxListService.SHARED), EnumSet.of(Path.Type.directory, Path.Type.volume))))); + assertNotNull(list.find(new SimplePathPredicate(new Path(String.format("/ORG 1 - DeepBox Desktop App/%s/Demo 1 (1 Christian Gruber)", DeepboxListService.SHARED), EnumSet.of(Path.Type.directory, Path.Type.volume))))); assertEquals(1, list.size()); for(final Path f : list) { assertSame(shared, f.getParent());