[DS-4390] fixed test failure and cleaned up ScriptRestRepository from DSpaceRunnable logic, moved to ScriptService instead

This commit is contained in:
Raf Ponsaerts
2019-11-22 14:15:26 +01:00
parent 02d98b2760
commit e87dd5a8b7
3 changed files with 21 additions and 7 deletions

View File

@@ -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());
}
}

View File

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

View File

@@ -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