Skip to content

Commit

Permalink
Fix naming.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylangisc committed Nov 28, 2024
1 parent 49482b2 commit 091720a
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<AbstractPath.Type> 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;
}
}
Expand All @@ -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<Path> decompose(final Path path) {
final Deque<Path> walk = new ArrayDeque<>();
Path next = path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,9 @@ public AttributedList<Path> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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));
Expand Down Expand Up @@ -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));
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public void testListSharedBoxes() throws Exception {
final AttributedList<Path> 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());
Expand Down

0 comments on commit 091720a

Please sign in to comment.