private void copyReviewToTargetResources()

in server/src/main/java/com/epam/aidial/core/server/service/PublicationService.java [627:667]


    private void copyReviewToTargetResources(List<Publication.Resource> resources) {
        Map<String, String> replacementLinks = new HashMap<>();

        for (Publication.Resource resource : resources) {
            String reviewUrl = resource.getReviewUrl();
            String targetUrl = resource.getTargetUrl();

            ResourceDescriptor from = ResourceDescriptorFactory.fromPrivateUrl(reviewUrl, encryption);
            ResourceDescriptor to = ResourceDescriptorFactory.fromPublicUrl(targetUrl);

            verifyResourceType(from);

            if (from.getType() == ResourceTypes.FILE) {
                String decodedUrl = UrlUtil.decodePath(from.getUrl());
                replacementLinks.put(decodedUrl, to.getUrl());
            }
        }

        for (Publication.Resource resource : resources) {
            String reviewUrl = resource.getReviewUrl();
            String targetUrl = resource.getTargetUrl();

            ResourceDescriptor from = ResourceDescriptorFactory.fromPrivateUrl(reviewUrl, encryption);
            ResourceDescriptor to = ResourceDescriptorFactory.fromPublicUrl(targetUrl);

            if (from.getType() == ResourceTypes.APPLICATION) {
                applicationService.copyApplication(from, to, false, app -> {
                    replaceCustomAppFiles(app, replacementLinks);
                    app.setReference(ApplicationUtil.generateReference());
                    app.setIconUrl(replaceLink(replacementLinks, app.getIconUrl()));
                });
            } else if (!resourceService.copyResource(from, to, false)
                    && resource.getAction() != Publication.ResourceAction.ADD_IF_ABSENT) {
                throw new IllegalStateException("Can't copy source resource from: " + from.getUrl() + " to review: " + to.getUrl());
            }

            if (from.getType() == ResourceTypes.CONVERSATION) {
                resourceService.computeResource(to, body -> PublicationUtil.replaceConversationLinks(body, to, replacementLinks));
            }
        }
    }