public InvitationLink initializeShare(ProxyContext context, ShareResourcesRequest request) {
        validateShareResourcesRequest(request);
        String bucketLocation = BucketBuilder.buildInitiatorBucket(context);
        String bucket = encryptionService.encrypt(bucketLocation);
        // validate resources - owner must be current user
        addCustomApplicationRelatedFiles(bucket, request);
        Set<SharedResource> sharedResources = request.getResources();
        Set<String> uniqueLinks = new HashSet<>();
        List<SharedResource> normalizedResourceLinks = new ArrayList<>(sharedResources.size());
        Map<ResourceType, List<SharedResource>> resourceGroups = sharedResources.stream()
                .collect(Collectors.groupingBy(sharedResource -> getResourceFromLink(sharedResource.getUrl()).getType()));

        long invitationTtl = Long.MAX_VALUE;
        for (Map.Entry<ResourceType, List<SharedResource>> entry : resourceGroups.entrySet()) {
            ResourceType resourceType = entry.getKey();
            List<SharedResource> links = entry.getValue();
            ShareResourceLimit limit = getLimit(context, resourceType);
            invitationTtl = Math.min(invitationTtl, limit.getInvitationTtl());
            ResourceDescriptor sharedWithMe = getShareResource(ResourceTypes.SHARED_WITH_ME, resourceType, bucket, bucketLocation);
            String state = resourceService.getResource(sharedWithMe);
            SharedResources existingSharedResources = ProxyUtil.convertToObject(state, SharedResources.class);
            if (existingSharedResources == null) {
                existingSharedResources = new SharedResources(new ArrayList<>());
            }
            Set<String> resharedResourceUrls = new HashSet<>();
            for (SharedResource sharedResource : existingSharedResources.getResources()) {
                if (sharedResource.getPermissions().contains(ResourceAccessType.SHARE)) {
                    resharedResourceUrls.add(sharedResource.getUrl());
                }
            }
            List<SharedResource> ownerResources = new ArrayList<>();
            for (SharedResource sharedResource : links) {
                ResourceDescriptor resource = getResourceFromLink(sharedResource.getUrl());
                canShare(sharedResource, bucket, resource, resharedResourceUrls);
                if (!uniqueLinks.add(resource.getUrl())) {
                    throw new IllegalArgumentException("Duplicated resource: %s".formatted(resource.getUrl()));
                }
                if (resource.getBucketName().equals(bucket)) {
                    ownerResources.add(sharedResource);
                }
                normalizedResourceLinks.add(sharedResource.withUrl(resource.getUrl()));
                updateLimits(context, resourceType, limit, ownerResources);
            }
        }

        Invitation invitation = invitationService.createInvitation(bucket, bucketLocation, normalizedResourceLinks,
                context.getUserDisplayName(), request.getMaxAcceptedUsers(), invitationTtl);
        return new InvitationLink(InvitationService.INVITATION_PATH_BASE + ResourceDescriptor.PATH_SEPARATOR + invitation.getId());
    }
Initialize share request by creating invitation object

@param request  - request body
@return invitation link
server/src/main/java/com/epam/aidial/core/server/service/ShareService.java