From e32193028a533d69e98890800f4f72ae69d421f5 Mon Sep 17 00:00:00 2001 From: Charles Severance Date: Tue, 25 Feb 2025 10:33:46 -0500 Subject: [PATCH] Move userIdTrans and userListAllowImport into MergeConfig --- .../assignment/impl/AssignmentServiceImpl.java | 3 +-- .../calendar/impl/BaseCalendarService.java | 3 +-- .../org/sakaiproject/archive/impl/SiteMerger.java | 12 +++++------- .../org/sakaiproject/entity/api/EntityProducer.java | 12 +++--------- .../main/java/org/sakaiproject/util/MergeConfig.java | 12 ++++++++++++ .../service/LessonBuilderEntityProducer.java | 12 ++++++------ .../org/sakaiproject/message/util/BaseMessage.java | 11 +++++------ .../messageforums/DiscussionForumServiceImpl.java | 3 +-- .../poll/service/impl/PollListManagerImpl.java | 2 +- .../component/app/syllabus/SyllabusServiceImpl.java | 3 +-- 10 files changed, 36 insertions(+), 37 deletions(-) diff --git a/assignment/impl/src/java/org/sakaiproject/assignment/impl/AssignmentServiceImpl.java b/assignment/impl/src/java/org/sakaiproject/assignment/impl/AssignmentServiceImpl.java index 42df1e4b2c1a..f4f42aa7155b 100644 --- a/assignment/impl/src/java/org/sakaiproject/assignment/impl/AssignmentServiceImpl.java +++ b/assignment/impl/src/java/org/sakaiproject/assignment/impl/AssignmentServiceImpl.java @@ -436,8 +436,7 @@ private void addSupplementaryItemAttachments(Document doc, Element item, List userIdTrans, Set userListAllowImport) { + public String merge(String siteId, Element root, String archivePath, String fromSiteId, MergeConfig mcx) { final StringBuilder results = new StringBuilder(); diff --git a/calendar/calendar-impl/impl/src/java/org/sakaiproject/calendar/impl/BaseCalendarService.java b/calendar/calendar-impl/impl/src/java/org/sakaiproject/calendar/impl/BaseCalendarService.java index ada98254f909..e942f6014310 100644 --- a/calendar/calendar-impl/impl/src/java/org/sakaiproject/calendar/impl/BaseCalendarService.java +++ b/calendar/calendar-impl/impl/src/java/org/sakaiproject/calendar/impl/BaseCalendarService.java @@ -1491,8 +1491,7 @@ public String archive(String siteId, Document doc, Stack stack, String archivePa } @Override - public String merge(String siteId, Element root, String archivePath, String fromSiteId, - MergeConfig mcx, Map userIdTrans, Set userListAllowImport) + public String merge(String siteId, Element root, String archivePath, String fromSiteId, MergeConfig mcx) { // prepare the buffer for the results log diff --git a/common/archive-impl/impl2/src/java/org/sakaiproject/archive/impl/SiteMerger.java b/common/archive-impl/impl2/src/java/org/sakaiproject/archive/impl/SiteMerger.java index c030f89f2f3f..1426f0851acf 100644 --- a/common/archive-impl/impl2/src/java/org/sakaiproject/archive/impl/SiteMerger.java +++ b/common/archive-impl/impl2/src/java/org/sakaiproject/archive/impl/SiteMerger.java @@ -92,9 +92,7 @@ public class SiteMerger { private String DEV_MERGE_KEEP_ATTACHMENTS = "dev.merge.keep.attachments"; private Boolean DEV_MERGE_KEEP_ATTACHMENTS_DEFAULT = false; - - //SWG TODO I have a feeling this is a bug - protected HashSet usersListAllowImport = new HashSet(); + /** * Process a merge for the file, or if it's a directory, for all contained files (one level deep). * @param fileName The site name (for the archive file) to read from. @@ -366,7 +364,7 @@ else if (element.getTagName().equals(UserDirectoryService.APPLICATION_ID)) mcx.archiveServerUrl = parentEl.getAttribute("serverurl"); } log.debug("Merging archive data for {} ({}) to site {} archive from context {} and server {}", serviceName, fileName, siteId, mcx.archiveContext, mcx.archiveServerUrl); - msg = service.merge(siteId, element, fileName, fromSite, mcx, new HashMap() /* empty userIdTran map */, usersListAllowImport); + msg = service.merge(siteId, element, fileName, fromSite, mcx); } else { log.warn("Skipping merge archive data for "+serviceName+" ("+fileName+") to site "+siteId+", checked filter failed (filtersOn="+filterSakaiService+", filters="+Arrays.toString(filteredSakaiService)+")"); } @@ -565,7 +563,7 @@ protected void mergeSite(String siteId, String fromSiteId, Element element, Hash if (!element3.getTagName().equals("roles")) continue; try { - mergeSiteRoles(element3, siteId, useIdTrans, filterSakaiRoles, filteredSakaiRoles); + mergeSiteRoles(element3, siteId, mcx, filterSakaiRoles, filteredSakaiRoles); } catch (PermissionException e1) { log.warn(e1.getMessage(), e1); @@ -632,7 +630,7 @@ else if (b == (byte) -106) * @param element The XML DOM tree of messages to merge. * @param siteId The id of the site getting imported into. */ - protected void mergeSiteRoles(Element el, String siteId, HashMap useIdTrans, boolean filterSakaiRoles, String[] filteredSakaiRoles) throws PermissionException + protected void mergeSiteRoles(Element el, String siteId, MergeConfig mcx, boolean filterSakaiRoles, String[] filteredSakaiRoles) throws PermissionException { // heck security (throws if not permitted) unlock(SiteService.SECURE_UPDATE_SITE, siteService.siteReference(siteId)); @@ -696,7 +694,7 @@ protected void mergeSiteRoles(Element el, String siteId, HashMap useIdTrans, boo String userId = element3.getAttribute("userId"); // this user has a qualified role, his/her resource will be imported - usersListAllowImport.add(userId); + mcx.userListAllowImport.add(userId); } } // for } diff --git a/kernel/api/src/main/java/org/sakaiproject/entity/api/EntityProducer.java b/kernel/api/src/main/java/org/sakaiproject/entity/api/EntityProducer.java index 4b1f348aeb25..29f833c962a8 100644 --- a/kernel/api/src/main/java/org/sakaiproject/entity/api/EntityProducer.java +++ b/kernel/api/src/main/java/org/sakaiproject/entity/api/EntityProducer.java @@ -102,7 +102,7 @@ default String merge(String siteId, Element root, String archivePath, String fro } /** - * Merge the resources from the archive into the given site (adding creatorId) + * Merge the resources from the archive into the given site with MergeConfig * * @param siteId * The id of the site getting imported into. @@ -114,17 +114,11 @@ default String merge(String siteId, Element root, String archivePath, String fro * The site id from which these items were archived. * @param mcx * MergeConfig for this import - * @param userIdTrans - * A map supplied by the called containing keys of old user IDs and values of new user IDs that the content should be attributed to. - * @param userListAllowImport - * A list of user IDs for which the content should be imported. An importer should ignore content if the user ID of the creator isn't in this - * set. * @return A log of status messages from the merge. */ - default String merge(String siteId, Element root, String archivePath, String fromSiteId, - MergeConfig mcx, Map userIdTrans, Set userListAllowImport) { + default String merge(String siteId, Element root, String archivePath, String fromSiteId, MergeConfig mcx) { // By default call the old merge without creatorId for those impls that don't need the creatorId - return merge(siteId, root, archivePath, fromSiteId, mcx.attachmentNames, userIdTrans, userListAllowImport); + return merge(siteId, root, archivePath, fromSiteId, mcx.attachmentNames, mcx.userIdTrans, mcx.userListAllowImport); } /** diff --git a/kernel/api/src/main/java/org/sakaiproject/util/MergeConfig.java b/kernel/api/src/main/java/org/sakaiproject/util/MergeConfig.java index 6c0842944e4e..f525c894b1be 100644 --- a/kernel/api/src/main/java/org/sakaiproject/util/MergeConfig.java +++ b/kernel/api/src/main/java/org/sakaiproject/util/MergeConfig.java @@ -2,13 +2,25 @@ import java.util.HashMap; import java.util.Map; +import java.util.Set; +import java.util.HashSet; +/** + * MergeConfig is a configuration container for merge operations across services. + * It acts as a shared context between different services during merge operations, + * eliminating the need to pass data through multiple service layers. + * + * The merge() operations are executed in a specific order, allowing later services + * to access data populated by earlier services through this shared configuration. + */ public class MergeConfig { public String creatorId; public String archiveContext = ""; public String archiveServerUrl = ""; public Map> ltiContentItems = new HashMap(); public Map attachmentNames = new HashMap(); + public Map userIdTrans = new HashMap(); + public Set userListAllowImport = new HashSet(); public MergeConfig() {} } diff --git a/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/service/LessonBuilderEntityProducer.java b/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/service/LessonBuilderEntityProducer.java index fd5423b28db2..6855c9be714e 100644 --- a/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/service/LessonBuilderEntityProducer.java +++ b/lessonbuilder/tool/src/java/org/sakaiproject/lessonbuildertool/service/LessonBuilderEntityProducer.java @@ -1131,14 +1131,14 @@ public String fixUrls(String s, String oldServer, String siteId, String fromSite // Externally used for zip import @Override - public String merge(String siteId, Element root, String archivePath, String fromSiteId, - MergeConfig mcx, Map userIdTrans, Set userListAllowImport) { - return mergeInternal(siteId, root, archivePath, fromSiteId, mcx, userIdTrans, userListAllowImport, null); + public String merge(String siteId, Element root, String archivePath, String fromSiteId, MergeConfig mcx) { + Map entityMap = null; + return mergeInternal(siteId, root, archivePath, fromSiteId, mcx, entityMap); } // Internally used for both site copy and zip import - public String mergeInternal(String siteId, Element root, String archivePath, String fromSiteId, - MergeConfig mcx, Map userIdTrans, Set userListAllowImport, Map entityMap) + public String mergeInternal(String siteId, Element root, String archivePath, String fromSiteId, MergeConfig mcx, + Map entityMap) { log.debug("Lessons Merge siteId={} fromSiteId={} creatorId={} archiveContext={} archiveServerUrl={}", @@ -1542,7 +1542,7 @@ public Map transferCopyEntitiesImpl(String fromContext, String to MergeConfig mcx = new MergeConfig(); mcx.creatorId = sessionManager.getCurrentSessionUserId(); - mergeInternal(toContext, (Element)doc.getFirstChild().getFirstChild(), "/tmp/archive", fromContext, mcx, null, null, entityMap); + mergeInternal(toContext, (Element)doc.getFirstChild().getFirstChild(), "/tmp/archive", fromContext, mcx, entityMap); ToolSession session = sessionManager.getCurrentToolSession(); diff --git a/message/message-util/util/src/java/org/sakaiproject/message/util/BaseMessage.java b/message/message-util/util/src/java/org/sakaiproject/message/util/BaseMessage.java index 8bf7c75bd5fb..2dbac5400705 100644 --- a/message/message-util/util/src/java/org/sakaiproject/message/util/BaseMessage.java +++ b/message/message-util/util/src/java/org/sakaiproject/message/util/BaseMessage.java @@ -1680,8 +1680,7 @@ public void archiveSynopticOptions(String siteId, Document doc, Element element) * {@inheritDoc} */ @Override - public String merge(String siteId, Element root, String archivePath, String fromSiteId, - MergeConfig mcx, Map userIdTrans, Set userListAllowImport) + public String merge(String siteId, Element root, String archivePath, String fromSiteId, MergeConfig mcx) { // get the system name: FROM_WT, FROM_CT, FROM_SAKAI // root: node @@ -1690,7 +1689,7 @@ public String merge(String siteId, Element root, String archivePath, String from log.debug("merge ltiService={} contentHostingService={} class={} archiveContext={} archiveServerUrl={}", ltiService, contentHostingService, this.getClass().getName(), mcx.archiveContext, mcx.archiveServerUrl); - HashSet userSet = (HashSet) userListAllowImport; + HashSet userSet = (HashSet) mcx.userListAllowImport; Map ids = new HashMap(); @@ -1776,11 +1775,11 @@ public String merge(String siteId, Element root, String archivePath, String from String oldUserId = element4.getAttribute("from"); // userIdTrans is not empty only when from WT - if (!userIdTrans.isEmpty()) + if (!mcx.userIdTrans.isEmpty()) { - if (userIdTrans.containsKey(oldUserId)) + if (mcx.userIdTrans.containsKey(oldUserId)) { - element4.setAttribute("from", (String) userIdTrans.get(oldUserId)); + element4.setAttribute("from", (String) mcx.userIdTrans.get(oldUserId)); } } diff --git a/msgcntr/messageforums-component-impl/src/java/org/sakaiproject/component/app/messageforums/DiscussionForumServiceImpl.java b/msgcntr/messageforums-component-impl/src/java/org/sakaiproject/component/app/messageforums/DiscussionForumServiceImpl.java index add930a42e5a..336663d0a355 100644 --- a/msgcntr/messageforums-component-impl/src/java/org/sakaiproject/component/app/messageforums/DiscussionForumServiceImpl.java +++ b/msgcntr/messageforums-component-impl/src/java/org/sakaiproject/component/app/messageforums/DiscussionForumServiceImpl.java @@ -732,8 +732,7 @@ public Map transferCopyEntities(String fromContext, String toCon return transversalMap; } - public String merge(String siteId, Element root, String archivePath, String fromSiteId, - MergeConfig mcx, Map userIdTrans, Set userListAllowImport) { + public String merge(String siteId, Element root, String archivePath, String fromSiteId, MergeConfig mcx) { log.debug("merge archiveContext={} archiveServerUrl={}", mcx.archiveContext, mcx.archiveServerUrl); diff --git a/polls/impl/src/java/org/sakaiproject/poll/service/impl/PollListManagerImpl.java b/polls/impl/src/java/org/sakaiproject/poll/service/impl/PollListManagerImpl.java index 5f09c0798f36..ab8735e43f69 100644 --- a/polls/impl/src/java/org/sakaiproject/poll/service/impl/PollListManagerImpl.java +++ b/polls/impl/src/java/org/sakaiproject/poll/service/impl/PollListManagerImpl.java @@ -461,7 +461,7 @@ public String archive(String siteId, Document doc, Stack stack, String } public String merge(String siteId, Element root, String archivePath, String fromSiteId, - MergeConfig mcx, Map userIdTrans, Set userListAllowImport) { + MergeConfig mcx) { log.debug("merge archiveContext={} archiveServerUrl={}", mcx.archiveContext, mcx.archiveServerUrl); diff --git a/syllabus/syllabus-impl/src/java/org/sakaiproject/component/app/syllabus/SyllabusServiceImpl.java b/syllabus/syllabus-impl/src/java/org/sakaiproject/component/app/syllabus/SyllabusServiceImpl.java index 83ee71afbf17..7565409fbfe1 100644 --- a/syllabus/syllabus-impl/src/java/org/sakaiproject/component/app/syllabus/SyllabusServiceImpl.java +++ b/syllabus/syllabus-impl/src/java/org/sakaiproject/component/app/syllabus/SyllabusServiceImpl.java @@ -453,8 +453,7 @@ public String archive(String siteId, Document doc, Stack stack, String arg3, * java.util.Set) */ @Transactional - public String merge(String siteId, Element root, String archivePath, String fromSiteId, MergeConfig mcx, - Map userIdTrans, Set userListAllowImport) + public String merge(String siteId, Element root, String archivePath, String fromSiteId, MergeConfig mcx) { log.debug("merge archiveContext={} archiveServerUrl={}", mcx.archiveContext, mcx.archiveServerUrl);