mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-14 13:33:08 +00:00
[DS-4390] fixed test failure and cleaned up ScriptRestRepository from DSpaceRunnable logic, moved to ScriptService instead
This commit is contained in:
@@ -8,8 +8,10 @@
|
||||
package org.dspace.scripts;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.scripts.service.ScriptService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
@@ -28,4 +30,10 @@ public class ScriptServiceImpl implements ScriptService {
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<DSpaceRunnable> getDSpaceRunnables(Context context) {
|
||||
return dSpaceRunnables.stream().filter(
|
||||
dSpaceRunnable -> dSpaceRunnable.isAllowedToExecute(context)).collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
@@ -7,6 +7,9 @@
|
||||
*/
|
||||
package org.dspace.scripts.service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.scripts.DSpaceRunnable;
|
||||
|
||||
/**
|
||||
@@ -20,4 +23,11 @@ public interface ScriptService {
|
||||
* @return The matching DSpaceRunnable script
|
||||
*/
|
||||
DSpaceRunnable getScriptForName(String name);
|
||||
|
||||
/**
|
||||
* This method will return a list of DSpaceRunnable objects for which the given Context is authorized to use them
|
||||
* @param context The relevant DSpace context
|
||||
* @return The list of accessible DSpaceRunnable scripts for this context
|
||||
*/
|
||||
List<DSpaceRunnable> getDSpaceRunnables(Context context);
|
||||
}
|
||||
|
@@ -50,9 +50,6 @@ public class ScriptRestRepository extends DSpaceRestRepository<ScriptRest, Strin
|
||||
|
||||
private static final Logger log = LogManager.getLogger();
|
||||
|
||||
@Autowired
|
||||
private List<DSpaceRunnable> dspaceRunnables;
|
||||
|
||||
@Autowired
|
||||
private ScriptConverter scriptConverter;
|
||||
|
||||
@@ -73,7 +70,7 @@ public class ScriptRestRepository extends DSpaceRestRepository<ScriptRest, Strin
|
||||
public ScriptRest findOne(Context context, String name) {
|
||||
|
||||
DSpaceRunnable dSpaceRunnable = scriptService.getScriptForName(name);
|
||||
if (dspaceRunnables != null) {
|
||||
if (dSpaceRunnable != null) {
|
||||
if (dSpaceRunnable.isAllowedToExecute(context)) {
|
||||
return scriptConverter.fromModel(dSpaceRunnable);
|
||||
} else {
|
||||
@@ -85,9 +82,8 @@ public class ScriptRestRepository extends DSpaceRestRepository<ScriptRest, Strin
|
||||
|
||||
@Override
|
||||
public Page<ScriptRest> findAll(Context context, Pageable pageable) {
|
||||
return utils.getPage(dspaceRunnables.stream().filter(
|
||||
dSpaceRunnable -> dSpaceRunnable.isAllowedToExecute(context)).collect(Collectors.toList()), pageable)
|
||||
.map(scriptConverter);
|
||||
List<DSpaceRunnable> dSpaceRunnables = scriptService.getDSpaceRunnables(context);
|
||||
return utils.getPage(dSpaceRunnables, pageable).map(scriptConverter);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user