mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-17 15:03:18 +00:00
[CST-12752] refactoring and added a new method into ServiceManager
This commit is contained in:
@@ -8,7 +8,6 @@
|
|||||||
package org.dspace.content;
|
package org.dspace.content;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import org.dspace.app.ldn.ItemFilter;
|
import org.dspace.app.ldn.ItemFilter;
|
||||||
@@ -38,16 +37,12 @@ public class ItemFilterServiceImpl implements ItemFilterService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ItemFilter> findAll() {
|
public List<ItemFilter> findAll() {
|
||||||
return serviceManager.getServicesNames()
|
return serviceManager.getServicesWithNamesByType(LogicalStatement.class)
|
||||||
|
.keySet()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(id -> isLogicalStatement(id))
|
.sorted()
|
||||||
.map(id -> new ItemFilter(id))
|
.map(ItemFilter::new)
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isLogicalStatement(String id) {
|
|
||||||
return Objects.nonNull(
|
|
||||||
serviceManager.getServiceByName(id, LogicalStatement.class)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
@@ -76,6 +76,15 @@ public interface ServiceManager {
|
|||||||
*/
|
*/
|
||||||
public List<String> getServicesNames();
|
public List<String> getServicesNames();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the names of all registered service singletons. By
|
||||||
|
* convention, the name typically matches the fully qualified class
|
||||||
|
* name).
|
||||||
|
*
|
||||||
|
* @return the list of all current registered services
|
||||||
|
*/
|
||||||
|
public <T> Map<String, T> getServicesWithNamesByType(Class<T> type);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows adding singleton services and providers in at runtime or
|
* Allows adding singleton services and providers in at runtime or
|
||||||
* after the service manager has started up.
|
* after the service manager has started up.
|
||||||
|
@@ -504,6 +504,21 @@ public final class DSpaceServiceManager implements ServiceManagerSystem {
|
|||||||
return beanNames;
|
return beanNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> Map<String, T> getServicesWithNamesByType(Class<T> type) {
|
||||||
|
checkRunning();
|
||||||
|
|
||||||
|
if (type == null) {
|
||||||
|
throw new IllegalArgumentException("type cannot be null");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
return applicationContext.getBeansOfType(type, true, true);
|
||||||
|
} catch (BeansException e) {
|
||||||
|
throw new RuntimeException("Failed to get beans of type (" + type + "): " + e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isServiceExists(String name) {
|
public boolean isServiceExists(String name) {
|
||||||
checkRunning();
|
checkRunning();
|
||||||
|
@@ -80,6 +80,11 @@ public class MockServiceManagerSystem implements ServiceManagerSystem {
|
|||||||
return this.sms.getServicesNames();
|
return this.sms.getServicesNames();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <T> Map<String, T> getServicesWithNamesByType(Class<T> type) {
|
||||||
|
return this.sms.getServicesWithNamesByType(type);
|
||||||
|
}
|
||||||
|
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.dspace.kernel.ServiceManager#isServiceExists(java.lang.String)
|
* @see org.dspace.kernel.ServiceManager#isServiceExists(java.lang.String)
|
||||||
*/
|
*/
|
||||||
|
@@ -13,6 +13,7 @@ import static org.junit.Assert.assertNotNull;
|
|||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -84,6 +85,10 @@ public class ProviderStackTest {
|
|||||||
return new ArrayList<String>();
|
return new ArrayList<String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> Map<String, T> getServicesWithNamesByType(Class<T> type) {
|
||||||
|
return new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isServiceExists(String name) {
|
public boolean isServiceExists(String name) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user