Skip to content

Commit

Permalink
Move userIdTrans and userListAllowImport into MergeConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
csev committed Feb 25, 2025
1 parent 92385a0 commit e321930
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,7 @@ private void addSupplementaryItemAttachments(Document doc, Element item, List<St

@Override
@Transactional
public String merge(String siteId, Element root, String archivePath, String fromSiteId,
MergeConfig mcx, Map<String, String> userIdTrans, Set<String> userListAllowImport) {
public String merge(String siteId, Element root, String archivePath, String fromSiteId, MergeConfig mcx) {


final StringBuilder results = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> userIdTrans, Set<String> userListAllowImport)
public String merge(String siteId, Element root, String archivePath, String fromSiteId, MergeConfig mcx)
{

// prepare the buffer for the results log
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> usersListAllowImport = new HashSet<String>();

/**
* 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.
Expand Down Expand Up @@ -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)+")");
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<String, String> userIdTrans, Set<String> 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);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions kernel/api/src/main/java/org/sakaiproject/util/MergeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Long, Map<String, Object>> ltiContentItems = new HashMap();
public Map<String, String> attachmentNames = new HashMap();
public Map<String, String> userIdTrans = new HashMap();
public Set<String> userListAllowImport = new HashSet();

public MergeConfig() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> userIdTrans, Set<String> 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<String, String> 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<String, String> entityMap)
public String mergeInternal(String siteId, Element root, String archivePath, String fromSiteId, MergeConfig mcx,
Map<String, String> entityMap)
{

log.debug("Lessons Merge siteId={} fromSiteId={} creatorId={} archiveContext={} archiveServerUrl={}",
Expand Down Expand Up @@ -1542,7 +1542,7 @@ public Map<String,String> 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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> userIdTrans, Set<String> 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: <service> node
Expand All @@ -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();

Expand Down Expand Up @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,7 @@ public Map<String, String> transferCopyEntities(String fromContext, String toCon
return transversalMap;
}

public String merge(String siteId, Element root, String archivePath, String fromSiteId,
MergeConfig mcx, Map<String, String> userIdTrans, Set<String> userListAllowImport) {
public String merge(String siteId, Element root, String archivePath, String fromSiteId, MergeConfig mcx) {

log.debug("merge archiveContext={} archiveServerUrl={}", mcx.archiveContext, mcx.archiveServerUrl);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ public String archive(String siteId, Document doc, Stack<Element> stack, String
}

public String merge(String siteId, Element root, String archivePath, String fromSiteId,
MergeConfig mcx, Map<String, String> userIdTrans, Set<String> userListAllowImport) {
MergeConfig mcx) {

log.debug("merge archiveContext={} archiveServerUrl={}", mcx.archiveContext, mcx.archiveServerUrl);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, String> userIdTrans, Set<String> userListAllowImport)
public String merge(String siteId, Element root, String archivePath, String fromSiteId, MergeConfig mcx)
{

log.debug("merge archiveContext={} archiveServerUrl={}", mcx.archiveContext, mcx.archiveServerUrl);
Expand Down

0 comments on commit e321930

Please sign in to comment.