Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxim-Gadalov committed Mar 12, 2024
1 parent 8f700e4 commit e6cc1f6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,23 @@ public class ResourceOperationService {
private final InvitationService invitationService;
private final ShareService shareService;

public void moveResource(String bucket, String location, ResourceDescription source, ResourceDescription description, boolean overwriteIfExists) {
if (source.isFolder() || description.isFolder()) {
public void moveResource(String bucket, String location, ResourceDescription source, ResourceDescription destination, boolean overwriteIfExists) {
if (source.isFolder() || destination.isFolder()) {
throw new IllegalArgumentException("Moving folders is not supported");
}

String sourceResourcePath = source.getAbsoluteFilePath();
String sourceResourceUrl = source.getUrl();
String destinationResourcePath = description.getAbsoluteFilePath();
String destinationResourceUrl = description.getUrl();
String destinationResourcePath = destination.getAbsoluteFilePath();
String destinationResourceUrl = destination.getUrl();

if (!storage.exists(sourceResourcePath)) {
throw new IllegalArgumentException("Can't find resource %s".formatted(sourceResourceUrl));
}

if (!overwriteIfExists) {
if (storage.exists(destinationResourcePath)) {
throw new IllegalArgumentException("Can't move resource %s to %s, because destination resource already exists"
.formatted(sourceResourceUrl, destinationResourceUrl));
}
if (!overwriteIfExists && storage.exists(destinationResourcePath)) {
throw new IllegalArgumentException("Can't move resource %s to %s, because destination resource already exists"
.formatted(sourceResourceUrl, destinationResourceUrl));
}

ResourceType resourceType = source.getType();
Expand All @@ -41,15 +39,15 @@ public void moveResource(String bucket, String location, ResourceDescription sou
storage.delete(sourceResourcePath);
}
case CONVERSATION, PROMPT -> {
resourceService.copyResource(source, description);
resourceService.copyResource(source, destination);
resourceService.deleteResource(source);
}
default -> throw new IllegalArgumentException("Unsupported resource type " + resourceType);
}
// move source links to destination if any
invitationService.moveResource(bucket, location, source, description);
invitationService.moveResource(bucket, location, source, destination);
// move shared access if any
shareService.moveSharedAccess(bucket, location, source, description);
shareService.moveSharedAccess(bucket, location, source, destination);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public void copySharedAccess(String bucket, String location, ResourceDescription
// source and destination resource type might be different
sharedByMeResource = getShareResource(ResourceType.SHARED_BY_ME, destinationResourceType, bucket, location);

// copy user locations form source to destination
// copy user locations from source to destination
resourceService.computeResource(sharedByMeResource, state -> {
SharedByMeDto dto = ProxyUtil.convertToObject(state, SharedByMeDto.class);
if (dto == null) {
Expand Down

0 comments on commit e6cc1f6

Please sign in to comment.