public Future copySharedAccess()

in server/src/main/java/com/epam/aidial/core/server/controller/ShareController.java [154:199]


    public Future<?> copySharedAccess() {
        return context.getRequest()
                .body()
                .compose(buffer -> {
                    CopySharedAccessRequest request;
                    try {
                        request = ProxyUtil.convertToObject(buffer, CopySharedAccessRequest.class);
                    } catch (Exception e) {
                        log.error("Invalid request body provided", e);
                        throw new IllegalArgumentException("Can't initiate copy shared access request. Incorrect body provided");
                    }

                    String sourceUrl = request.sourceUrl();
                    if (sourceUrl == null) {
                        throw new IllegalArgumentException("sourceUrl must be provided");
                    }
                    String destinationUrl = request.destinationUrl();
                    if (destinationUrl == null) {
                        throw new IllegalArgumentException("destinationUrl must be provided");
                    }

                    String bucketLocation = BucketBuilder.buildInitiatorBucket(context);
                    String bucket = encryptionService.encrypt(bucketLocation);

                    ResourceDescriptor source = ResourceDescriptorFactory.fromPrivateUrl(sourceUrl, encryptionService);
                    if (!bucket.equals(source.getBucketName())) {
                        throw new IllegalArgumentException("sourceUrl does not belong to the user");
                    }
                    ResourceDescriptor destination = ResourceDescriptorFactory.fromPrivateUrl(destinationUrl, encryptionService);
                    if (!bucket.equals(destination.getBucketName())) {
                        throw new IllegalArgumentException("destinationUrl does not belong to the user");
                    }

                    if (source.getUrl().equals(destination.getUrl())) {
                        throw new IllegalArgumentException("source and destination cannot be the same");
                    }

                    return proxy.getVertx().executeBlocking(() ->
                            lockService.underBucketLock(bucketLocation, () -> {
                                shareService.copySharedAccess(bucket, bucketLocation, source, destination);
                                return null;
                            }), false);
                })
                .onSuccess(ignore -> context.respond(HttpStatus.OK))
                .onFailure(this::handleServiceError);
    }