mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-14 05:23:14 +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;
|
package org.dspace.scripts;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.dspace.core.Context;
|
||||||
import org.dspace.scripts.service.ScriptService;
|
import org.dspace.scripts.service.ScriptService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
@@ -28,4 +30,10 @@ public class ScriptServiceImpl implements ScriptService {
|
|||||||
.findFirst()
|
.findFirst()
|
||||||
.orElse(null);
|
.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;
|
package org.dspace.scripts.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.dspace.core.Context;
|
||||||
import org.dspace.scripts.DSpaceRunnable;
|
import org.dspace.scripts.DSpaceRunnable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,4 +23,11 @@ public interface ScriptService {
|
|||||||
* @return The matching DSpaceRunnable script
|
* @return The matching DSpaceRunnable script
|
||||||
*/
|
*/
|
||||||
DSpaceRunnable getScriptForName(String name);
|
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();
|
private static final Logger log = LogManager.getLogger();
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private List<DSpaceRunnable> dspaceRunnables;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ScriptConverter scriptConverter;
|
private ScriptConverter scriptConverter;
|
||||||
|
|
||||||
@@ -73,7 +70,7 @@ public class ScriptRestRepository extends DSpaceRestRepository<ScriptRest, Strin
|
|||||||
public ScriptRest findOne(Context context, String name) {
|
public ScriptRest findOne(Context context, String name) {
|
||||||
|
|
||||||
DSpaceRunnable dSpaceRunnable = scriptService.getScriptForName(name);
|
DSpaceRunnable dSpaceRunnable = scriptService.getScriptForName(name);
|
||||||
if (dspaceRunnables != null) {
|
if (dSpaceRunnable != null) {
|
||||||
if (dSpaceRunnable.isAllowedToExecute(context)) {
|
if (dSpaceRunnable.isAllowedToExecute(context)) {
|
||||||
return scriptConverter.fromModel(dSpaceRunnable);
|
return scriptConverter.fromModel(dSpaceRunnable);
|
||||||
} else {
|
} else {
|
||||||
@@ -85,9 +82,8 @@ public class ScriptRestRepository extends DSpaceRestRepository<ScriptRest, Strin
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Page<ScriptRest> findAll(Context context, Pageable pageable) {
|
public Page<ScriptRest> findAll(Context context, Pageable pageable) {
|
||||||
return utils.getPage(dspaceRunnables.stream().filter(
|
List<DSpaceRunnable> dSpaceRunnables = scriptService.getDSpaceRunnables(context);
|
||||||
dSpaceRunnable -> dSpaceRunnable.isAllowedToExecute(context)).collect(Collectors.toList()), pageable)
|
return utils.getPage(dSpaceRunnables, pageable).map(scriptConverter);
|
||||||
.map(scriptConverter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user