Skip to content

Commit

Permalink
SAK-42362 Make sure toolOptions is always supplied ... (sakaiproject#…
Browse files Browse the repository at this point in the history
…7255)

... during import from sites and reuse material.

https://jira.sakaiproject.org/browse/SAK-42362
  • Loading branch information
adrianfish authored Aug 19, 2019
1 parent 660bfbb commit 72b5230
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,11 @@ private Map<String, String> transferCopyEntities(String toolId, String fromConte
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {

List<String> options = (toolOptions != null) ? toolOptions.get(toolId) : null;

Map<String, String> entityMap
= et.transferCopyEntities(
fromContext, toContext, new ArrayList<>(), toolOptions.get(toolId), cleanup);
fromContext, toContext, new ArrayList<>(), options, cleanup);
if (entityMap != null) {
transversalMap.putAll(entityMap);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,8 @@ public class SiteAction extends PagedResourceActionII {

private static final String STATE_IMPORT_SITE_TOOL = "state_import_site_tool";

private static final String STATE_IMPORT_SITE_TOOL_OPTIONS = "state_import_site_tool_options";

/** for navigating between sites in site list */
private static final String STATE_SITES = "state_sites";

Expand Down Expand Up @@ -2845,7 +2847,7 @@ public int compare(JoinableGroup g1, JoinableGroup g2){
*
*/
boolean existingSite = site != null;

// define the tools available for import. defaults to those tools in the 'destination' site
List<String> importableToolsIdsInDestinationSite = (List) state.getAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST);
if (existingSite) {
Expand Down Expand Up @@ -5338,12 +5340,28 @@ private boolean select_import_tools(ParameterParser params, SessionState state)
}
}
}

log.debug("tools to import: " + importTools);

if (log.isDebugEnabled()) {
log.debug("tools to import: " + importTools);
}
state.setAttribute(STATE_IMPORT_SITE_TOOL, importTools);

return anyToolSelected;
Map<String, List<String>> toolOptions = new HashMap<>();
for (Iterator<String> iter = params.getNames(); iter.hasNext();) {
String name = iter.next();
if (name.startsWith("import-option-")) {
String option = name.substring(14, name.indexOf("-tool-"));
String toolId = name.substring(name.indexOf("-tool-") + 6);
if (toolOptions.get(toolId) == null) {
toolOptions.put(toolId, new ArrayList<>());
}
toolOptions.get(toolId).add(option);
}
}

state.setAttribute(STATE_IMPORT_SITE_TOOL_OPTIONS, toolOptions);

return anyToolSelected;
} // select_import_tools

/**
Expand Down Expand Up @@ -9622,12 +9640,11 @@ private void actionForTemplate(String direction, int index,
if (select_import_tools(params, state)) {
// list of tools that were selected for import
Map<String, List<String>> importTools = (Map<String, List<String>>) state.getAttribute(STATE_IMPORT_SITE_TOOL);
Map<String, List<String>> toolOptions = (Map<String, List<String>>) state.getAttribute(STATE_IMPORT_SITE_TOOL_OPTIONS);

//list of existing tools in the destination site
List<String> existingTools = getOriginalToolIds((List<String>) state.getAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST), state);

Map<String, List<String>> toolOptions = getToolOptionsFromParams(params);

boolean importTaskStarted = siteManageService.importToolsIntoSiteThread(existingSite, existingTools, importTools, toolOptions, false);
if (importTaskStarted) {
// ***** import tools here
Expand Down Expand Up @@ -9665,12 +9682,11 @@ private void actionForTemplate(String direction, int index,
if (select_import_tools(params, state)) {
// list of tools that were selected for import
Map<String, List<String>> importTools = (Map<String, List<String>>) state.getAttribute(STATE_IMPORT_SITE_TOOL);
Map<String, List<String>> toolOptions = (Map<String, List<String>>) state.getAttribute(STATE_IMPORT_SITE_TOOL_OPTIONS);

//list of existing tools in the destination site
List<String> existingTools = getOriginalToolIds((List<String>) state.getAttribute(STATE_TOOL_REGISTRATION_SELECTED_LIST), state);

Map<String, List<String>> toolOptions = getToolOptionsFromParams(params);

boolean importTaskStarted = siteManageService.importToolsIntoSiteThread(existingSite, existingTools, importTools, toolOptions, true);

if (importTaskStarted) {
Expand Down Expand Up @@ -11583,8 +11599,10 @@ else if (multiAllowed && toolId.startsWith(toolRegId))

site = refreshSiteObject(site);

Map<String, List<String>> toolOptions = (Map<String, List<String>>) state.getAttribute(STATE_IMPORT_SITE_TOOL_OPTIONS);

// import
siteManageService.importToolsIntoSite(site, chosenList, importTools, null, false);
siteManageService.importToolsIntoSite(site, chosenList, importTools, toolOptions, false);

// SAK-22384 add LaTeX (MathJax) support
if (MathJaxEnabler.prepareMathJaxToolSettingsForSave(site, state))
Expand Down Expand Up @@ -16184,22 +16202,4 @@ public void doRemove_widget(RunData data)

state.setAttribute("tools", tools);
}

private Map<String, List<String>> getToolOptionsFromParams(ParameterParser params) {

Map<String, List<String>> toolOptions = new HashMap<>();
for (Iterator<String> iter = params.getNames(); iter.hasNext();) {
String name = iter.next();
if (name.startsWith("import-option-")) {
String option = name.substring(14, name.indexOf("-tool-"));
String toolId = name.substring(name.indexOf("-tool-") + 6);
if (toolOptions.get(toolId) == null) {
toolOptions.put(toolId, new ArrayList<>());
}
toolOptions.get(toolId).add(option);
}
}

return toolOptions;
}
}

0 comments on commit 72b5230

Please sign in to comment.