From 1e50bd74ca90504a659defd2a73e5276b60b7db6 Mon Sep 17 00:00:00 2001 From: "francesco.mangiacrapa" Date: Thu, 21 Mar 2024 15:53:09 +0100 Subject: [PATCH] ItemObserved updated --- .../cms/plugins/events/ItemObserved.java | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/events/ItemObserved.java b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/events/ItemObserved.java index 47e9869..f6a84e3 100644 --- a/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/events/ItemObserved.java +++ b/cms-plugin-framework/src/main/java/org/gcube/application/cms/plugins/events/ItemObserved.java @@ -1,5 +1,9 @@ package org.gcube.application.cms.plugins.events; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.Map.Entry; + import org.gcube.application.geoportal.common.model.document.Project; import org.gcube.application.geoportal.common.model.document.accounting.Context; import org.gcube.application.geoportal.common.model.document.accounting.User; @@ -23,14 +27,13 @@ public class ItemObserved implements ItemObservable { T project; EventManager.Event event; - public String getProjectId() { log.debug("Called getProjectId"); if (project == null) return null; return project.getId(); } - + @Override public String getUCD_Id() { log.debug("Called getUCD_Id"); @@ -39,4 +42,28 @@ public class ItemObserved implements ItemObservable { return useCaseDescriptor.getId(); } + public LinkedHashMap getDocumentEntries(int limit) { + + LinkedHashMap documentAsMap = new LinkedHashMap<>(); + + try { + + Iterator> entrySetsIt = project.getTheDocument().entrySet().iterator(); + int i = 0; + while (entrySetsIt.hasNext()) { + if (i + 1 > limit) + break; + + Entry entry = entrySetsIt.next(); + documentAsMap.put(entry.getKey(), entry.getValue() != null ? entry.getValue().toString() : null); + i++; + } + + } catch (Exception e) { + throw e; + } + + return documentAsMap; + } + }