You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2013/03/13 00:32:22 UTC
[9/38] git commit: ISIS-208: service Ids cannot be unique
ISIS-208: service Ids cannot be unique
Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/2782ee86
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/2782ee86
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/2782ee86
Branch: refs/heads/dan/ISIS-233-ro
Commit: 2782ee8653d6064e00df0b5e54511f76ec380e17
Parents: 23c80d3
Author: Dan Haywood <da...@apache.org>
Authored: Mon Mar 11 19:21:13 2013 +0000
Committer: Dan Haywood <da...@apache.org>
Committed: Mon Mar 11 20:48:27 2013 +0000
----------------------------------------------------------------------
.../system/session/IsisSessionFactoryAbstract.java | 33 +++++++++++++++
...ssionFactoryAbstractTest_init_and_shutdown.java | 15 +++++++
2 files changed, 48 insertions(+), 0 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/isis/blob/2782ee86/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryAbstract.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryAbstract.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryAbstract.java
index b63ebcf..d1daa8b 100644
--- a/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryAbstract.java
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryAbstract.java
@@ -25,8 +25,10 @@ import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.CoreMatchers.nullValue;
import java.lang.reflect.Method;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Properties;
import javax.annotation.PostConstruct;
@@ -38,6 +40,7 @@ import org.apache.isis.core.commons.config.IsisConfiguration;
import org.apache.isis.core.commons.lang.JavaClassUtils;
import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller;
import org.apache.isis.core.metamodel.adapter.util.InvokeUtils;
+import org.apache.isis.core.metamodel.services.ServiceUtil;
import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
import org.apache.isis.core.runtime.authentication.AuthenticationManager;
import org.apache.isis.core.runtime.authorization.AuthorizationManager;
@@ -50,6 +53,12 @@ import org.apache.isis.core.runtime.userprofile.UserProfile;
import org.apache.isis.core.runtime.userprofile.UserProfileLoader;
import org.apache.log4j.Logger;
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ListMultimap;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import com.google.common.collect.Multimaps;
+
/**
* Creates an implementation of
* {@link IsisSessionFactory#openSession(AuthenticationSession)} to create an
@@ -126,6 +135,30 @@ public abstract class IsisSessionFactoryAbstract implements IsisSessionFactory {
validatePreDestroyMethods(service, method);
}
}
+
+ ListMultimap<String, Object> servicesById = ArrayListMultimap.create();
+ for (Object service : serviceList) {
+ String id = ServiceUtil.id(service);
+ servicesById.put(id, service);
+ }
+ for (Entry<String, Collection<Object>> servicesForId : servicesById.asMap().entrySet()) {
+ String serviceId = servicesForId.getKey();
+ Collection<Object> services = servicesForId.getValue();
+ if(services.size() > 1) {
+ throw new IllegalStateException("Service ids must be unique; serviceId '" + serviceId + "' is declared by domain services " + classNamesFor(services));
+ }
+ }
+ }
+
+ private static String classNamesFor(Collection<Object> services) {
+ StringBuilder buf = new StringBuilder();
+ for (Object service : services) {
+ if(buf.length() > 0) {
+ buf.append(", ");
+ }
+ buf.append(service.getClass().getName());
+ }
+ return buf.toString();
}
private void validatePostConstructMethods(Object service, Method method) {
http://git-wip-us.apache.org/repos/asf/isis/blob/2782ee86/core/runtime/src/test/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryAbstractTest_init_and_shutdown.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/test/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryAbstractTest_init_and_shutdown.java b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryAbstractTest_init_and_shutdown.java
index bf8a186..67ccb9e 100644
--- a/core/runtime/src/test/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryAbstractTest_init_and_shutdown.java
+++ b/core/runtime/src/test/java/org/apache/isis/core/runtime/system/session/IsisSessionFactoryAbstractTest_init_and_shutdown.java
@@ -86,6 +86,14 @@ public class IsisSessionFactoryAbstractTest_init_and_shutdown {
public void postConstruct(int i) {}
}
+ public static class DomainServiceWithSomeId {
+ public String getId() { return "someId"; }
+ }
+
+ public static class DomainServiceWithDuplicateId {
+ public String getId() { return "someId"; }
+ }
+
@Rule
@@ -197,6 +205,13 @@ public class IsisSessionFactoryAbstractTest_init_and_shutdown {
isfa = createIsisSessionFactoryAbstract(serviceList);
}
+ @Test(expected=IllegalStateException.class)
+ public void validate_DomainServicesWithDuplicateIds() {
+ serviceList.add(new DomainServiceWithSomeId());
+ serviceList.add(new DomainServiceWithDuplicateId());
+ isfa = createIsisSessionFactoryAbstract(serviceList);
+ }
+
private IsisSessionFactoryAbstract createIsisSessionFactoryAbstract(List<Object> serviceList) {
return new IsisSessionFactoryAbstract(deploymentType, configuration, specificationLoader, templateImageLoader, authenticationManager, authorizationManager, userProfileLoader, persistenceSessionFactory, serviceList, oidMarshaller) {