public Publication rejectPublication()

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


    public Publication rejectPublication(ResourceDescriptor resource, RejectPublicationRequest request) {
        if (resource.isFolder() || resource.isPublic() || resource.getParentPath() != null) {
            throw new IllegalArgumentException("Bad publication url: " + resource.getUrl());
        }

        MutableObject<Publication> reference = new MutableObject<>();
        resourceService.computeResource(publications(resource), body -> {
            Map<String, Publication> publications = decodePublications(body);
            Publication publication = publications.get(resource.getUrl());

            if (publication == null) {
                throw new ResourceNotFoundException("No publication: " + resource.getUrl());
            }

            if (publication.getStatus() != Publication.Status.PENDING) {
                throw new ResourceNotFoundException("Publication is already finalized: " + resource.getUrl());
            }

            reference.setValue(publication);
            publication.setStatus(Publication.Status.REJECTED);
            return encodePublications(publications);
        });

        resourceService.computeResource(PUBLIC_PUBLICATIONS, body -> {
            Map<String, Publication> publications = decodePublications(body);
            Publication publication = publications.remove(resource.getUrl());
            return (publication == null) ? body : encodePublications(publications);
        });

        Publication publication = reference.getValue();
        List<Publication.Resource> resourcesToAdd = publication.getResources().stream()
                .filter(i -> i.getAction() == Publication.ResourceAction.ADD || i.getAction() == Publication.ResourceAction.ADD_IF_ABSENT)
                .toList();
        deleteReviewResources(resourcesToAdd);

        String rejectReason = request.comment();
        String notificationMessage = "Your request has been rejected by admin";
        notificationMessage = rejectReason != null ? notificationMessage + ": " + rejectReason : notificationMessage;
        Notification notification = Notification.getPublicationNotification(resource.getUrl(), notificationMessage);
        notificationService.createNotification(resource.getBucketName(), resource.getBucketLocation(), notification);

        return publication;
    }