Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change naming for shared boxes #16596

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -70,11 +70,10 @@ public boolean isContainer(final Path file) {
}

public boolean isCompany(final Path file) {
final Path normalized = fileid.normalize(file);
if(normalized.isRoot()) {
if(file.isRoot()) {
return false;
}
return normalized.isDirectory() && normalized.getParent().isRoot();
return file.isDirectory() && file.getParent().isRoot();
}

public boolean isSharedWithMe(final Path file) {
Expand Down Expand Up @@ -214,7 +213,7 @@ protected Path getDeepboxPath(final Path file) {
}

protected Path getCompanyPath(final Path file) {
Path company = fileid.normalize(file);
Path company = file;
while(!company.isRoot() && !this.isCompany(company)) {
company = company.getParent();
}
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