From 8f0ef84eeb4d50923fca824fecee0fb1b288591f Mon Sep 17 00:00:00 2001 From: Torsten Simon Date: Mon, 2 Dec 2024 09:42:32 +0100 Subject: [PATCH] fix:add custom class for thumb import --- .../server/jobs/helper/NodeCustomClasses.java | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Backend/services/core/src/main/java/org/edu_sharing/repository/server/jobs/helper/NodeCustomClasses.java diff --git a/Backend/services/core/src/main/java/org/edu_sharing/repository/server/jobs/helper/NodeCustomClasses.java b/Backend/services/core/src/main/java/org/edu_sharing/repository/server/jobs/helper/NodeCustomClasses.java new file mode 100644 index 0000000000..f177d52c2c --- /dev/null +++ b/Backend/services/core/src/main/java/org/edu_sharing/repository/server/jobs/helper/NodeCustomClasses.java @@ -0,0 +1,51 @@ +package org.edu_sharing.repository.server.jobs.helper; + +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.cmr.repository.StoreRef; +import org.apache.log4j.Logger; +import org.edu_sharing.repository.client.tools.CCConstants; +import org.edu_sharing.repository.server.jobs.quartz.BulkEditNodesJob; +import org.edu_sharing.repository.server.tools.HttpQueryTool; +import org.edu_sharing.service.nodeservice.NodeServiceFactory; +import org.edu_sharing.service.nodeservice.NodeServiceHelper; + +import java.io.InputStream; +import java.util.function.Consumer; + +/** + * to be used with @BulkEditNodesJob + */ +public class NodeCustomClasses { + public static class ImportExternalThumbnail implements Consumer { + @Override + public void accept(NodeRef nodeRef) { + String thumbUrl = NodeServiceHelper.getProperty(nodeRef, CCConstants.CCM_PROP_IO_THUMBNAILURL); + if (thumbUrl == null) { + Logger.getLogger(BulkEditNodesJob.class).info(nodeRef + " has no " + CCConstants.CCM_PROP_IO_THUMBNAILURL + ", skipping..."); + return; + } + try { + HttpQueryTool.Callback callback = new HttpQueryTool.Callback() { + @Override + public void handle(InputStream is) { + try { + NodeServiceFactory.getLocalService().writeContent(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE, nodeRef.getId(), is, + "image/jpeg", null, CCConstants.CCM_PROP_IO_USERDEFINED_PREVIEW); + } catch (Exception e) { + Logger.getLogger(BulkEditNodesJob.class).warn("Thumb fetching failed for " + nodeRef + " " + thumbUrl); + } + } + }; + new HttpQueryTool().queryStream(thumbUrl, callback); + if (callback.getResult() != null) { + Logger.getLogger(BulkEditNodesJob.class).warn("Thumb fetching failed for " + nodeRef + " " + thumbUrl + ": " + callback.getResult()); + } else { + NodeServiceHelper.removeProperty(nodeRef, CCConstants.CCM_PROP_IO_THUMBNAILURL); + Logger.getLogger(BulkEditNodesJob.class).info(nodeRef + " thumb imported: " + thumbUrl); + } + } catch (Throwable t) { + Logger.getLogger(BulkEditNodesJob.class).warn("Thumb fetching failed for " + nodeRef + " " + thumbUrl); + } + } + } +}