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 2015/12/22 14:30:07 UTC

[2/3] isis git commit: ISIS-666: new HomePageProviderService and RoutingService; updated wicket viewer to use the RoutingService when an action is invoked.

ISIS-666: new HomePageProviderService and RoutingService; updated wicket viewer to use the RoutingService when an action is invoked.


Project: http://git-wip-us.apache.org/repos/asf/isis/repo
Commit: http://git-wip-us.apache.org/repos/asf/isis/commit/9885ce97
Tree: http://git-wip-us.apache.org/repos/asf/isis/tree/9885ce97
Diff: http://git-wip-us.apache.org/repos/asf/isis/diff/9885ce97

Branch: refs/heads/master
Commit: 9885ce9752312a18af2a37708b5f9c73a5069390
Parents: 6c165d7
Author: Dan Haywood <da...@haywood-associates.co.uk>
Authored: Tue Dec 22 12:49:39 2015 +0000
Committer: Dan Haywood <da...@haywood-associates.co.uk>
Committed: Tue Dec 22 12:49:39 2015 +0000

----------------------------------------------------------------------
 .../homepage/HomePageProviderService.java       |  34 ++++++
 .../applib/services/routing/RoutingService.java |  31 ++++++
 .../services/routing/RoutingServiceDefault.java |  58 ++++++++++
 .../HomePageProviderServiceDefault.java         | 108 +++++++++++++++++++
 .../viewer/wicket/model/models/ActionModel.java |  17 +++
 .../java/domainapp/dom/simple/SimpleObject.java |  10 ++
 6 files changed, 258 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/isis/blob/9885ce97/core/applib/src/main/java/org/apache/isis/applib/services/homepage/HomePageProviderService.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/homepage/HomePageProviderService.java b/core/applib/src/main/java/org/apache/isis/applib/services/homepage/HomePageProviderService.java
new file mode 100644
index 0000000..c9a56a7
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/homepage/HomePageProviderService.java
@@ -0,0 +1,34 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.applib.services.homepage;
+
+import org.apache.isis.applib.annotation.DomainService;
+import org.apache.isis.applib.annotation.HomePage;
+import org.apache.isis.applib.annotation.Programmatic;
+
+public interface HomePageProviderService {
+
+    /**
+     * Returns the object returned by invoking the home page action (an action of a {@link DomainService} annotated
+     * with {@link HomePage}.
+     */
+    @Programmatic
+    Object homePage();
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/9885ce97/core/applib/src/main/java/org/apache/isis/applib/services/routing/RoutingService.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/routing/RoutingService.java b/core/applib/src/main/java/org/apache/isis/applib/services/routing/RoutingService.java
new file mode 100644
index 0000000..fc0d46f
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/routing/RoutingService.java
@@ -0,0 +1,31 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.applib.services.routing;
+
+import org.apache.isis.applib.annotation.Programmatic;
+
+public interface RoutingService {
+
+    @Programmatic
+    boolean canRoute(Object original);
+
+    @Programmatic
+    Object route(Object original);
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/9885ce97/core/applib/src/main/java/org/apache/isis/applib/services/routing/RoutingServiceDefault.java
----------------------------------------------------------------------
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/routing/RoutingServiceDefault.java b/core/applib/src/main/java/org/apache/isis/applib/services/routing/RoutingServiceDefault.java
new file mode 100644
index 0000000..d351e90
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/routing/RoutingServiceDefault.java
@@ -0,0 +1,58 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.applib.services.routing;
+
+import javax.inject.Inject;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.isis.applib.annotation.DomainService;
+import org.apache.isis.applib.annotation.DomainServiceLayout;
+import org.apache.isis.applib.annotation.NatureOfService;
+import org.apache.isis.applib.annotation.Programmatic;
+import org.apache.isis.applib.services.homepage.HomePageProviderService;
+
+@DomainService(
+        nature = NatureOfService.DOMAIN
+)
+@DomainServiceLayout(
+        menuOrder = "" + Integer.MAX_VALUE // choose any lower number to override.
+)
+public class RoutingServiceDefault implements RoutingService {
+
+    @SuppressWarnings("unused")
+    private final static Logger LOG = LoggerFactory.getLogger(RoutingServiceDefault.class);
+
+    @Programmatic
+    @Override
+    public boolean canRoute(final Object original) {
+        return true;
+    }
+
+    @Programmatic
+    @Override
+    public Object route(final Object original) {
+        return original != null? original: homePageProviderService.homePage();
+    }
+
+    @Inject
+    HomePageProviderService homePageProviderService;
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/9885ce97/core/runtime/src/main/java/org/apache/isis/core/runtime/services/homepage/HomePageProviderServiceDefault.java
----------------------------------------------------------------------
diff --git a/core/runtime/src/main/java/org/apache/isis/core/runtime/services/homepage/HomePageProviderServiceDefault.java b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/homepage/HomePageProviderServiceDefault.java
new file mode 100644
index 0000000..5a4d9d5
--- /dev/null
+++ b/core/runtime/src/main/java/org/apache/isis/core/runtime/services/homepage/HomePageProviderServiceDefault.java
@@ -0,0 +1,108 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.isis.core.runtime.services.homepage;
+
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import org.apache.isis.applib.annotation.DomainService;
+import org.apache.isis.applib.annotation.NatureOfService;
+import org.apache.isis.applib.annotation.Programmatic;
+import org.apache.isis.applib.annotation.Where;
+import org.apache.isis.applib.services.homepage.HomePageProviderService;
+import org.apache.isis.core.metamodel.adapter.ObjectAdapter;
+import org.apache.isis.core.metamodel.consent.Consent;
+import org.apache.isis.core.metamodel.consent.InteractionInitiatedBy;
+import org.apache.isis.core.metamodel.facets.actions.homepage.HomePageFacet;
+import org.apache.isis.core.metamodel.spec.ObjectSpecification;
+import org.apache.isis.core.metamodel.spec.feature.Contributed;
+import org.apache.isis.core.metamodel.spec.feature.ObjectAction;
+import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.runtime.system.persistence.PersistenceSession;
+
+@DomainService(
+        nature = NatureOfService.DOMAIN
+)
+public class HomePageProviderServiceDefault implements HomePageProviderService {
+
+    @SuppressWarnings("unused")
+    private final static Logger LOG = LoggerFactory.getLogger(HomePageProviderServiceDefault.class);
+
+    @Programmatic
+    @Override
+    public Object homePage() {
+        final List<ObjectAdapter> serviceAdapters = getPersistenceSession().getServices();
+        for (final ObjectAdapter serviceAdapter : serviceAdapters) {
+            final ObjectSpecification serviceSpec = serviceAdapter.getSpecification();
+            final List<ObjectAction> objectActions = serviceSpec.getObjectActions(Contributed.EXCLUDED);
+            for (final ObjectAction objectAction : objectActions) {
+                final Object homePage = homePageIfUsable(serviceAdapter, objectAction);
+                if(homePage != null) {
+                    return homePage;
+                }
+            }
+        }
+        return null;
+    }
+
+    protected Object homePageIfUsable(ObjectAdapter serviceAdapter, ObjectAction objectAction) {
+        if (!objectAction.containsDoOpFacet(HomePageFacet.class)) {
+            return null;
+        }
+
+        final Consent visibility =
+                objectAction.isVisible(
+                        serviceAdapter,
+                        InteractionInitiatedBy.USER,
+                        Where.ANYWHERE);
+        if (visibility.isVetoed()) {
+            return null;
+        }
+
+        final Consent usability =
+                objectAction.isUsable(
+                        serviceAdapter,
+                        InteractionInitiatedBy.USER,
+                        Where.ANYWHERE
+                );
+        if (usability.isVetoed()) {
+            return  null;
+        }
+
+        final ObjectAdapter objectAdapter = objectAction.executeWithRuleChecking(
+                serviceAdapter, new ObjectAdapter[] {},
+                InteractionInitiatedBy.USER,
+                WHERE_FOR_ACTION_INVOCATION);
+        return objectAdapter != null ? objectAdapter.getObject(): null;
+    }
+
+    // REVIEW: should provide this rendering context, rather than hardcoding.
+    // the net effect currently is that class members annotated with
+    // @Hidden(where=Where.ANYWHERE) or @Disabled(where=Where.ANYWHERE) will indeed
+    // be hidden/disabled, but will be visible/enabled (perhaps incorrectly)
+    // for any other value for Where
+    protected static final Where WHERE_FOR_ACTION_INVOCATION = Where.ANYWHERE;
+
+    protected PersistenceSession getPersistenceSession() {
+        return IsisContext.getPersistenceSession();
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/isis/blob/9885ce97/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/ActionModel.java
----------------------------------------------------------------------
diff --git a/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/ActionModel.java b/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/ActionModel.java
index 96f61ed..1dffbe8 100644
--- a/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/ActionModel.java
+++ b/core/viewer-wicket-model/src/main/java/org/apache/isis/viewer/wicket/model/models/ActionModel.java
@@ -48,6 +48,7 @@ import org.apache.isis.applib.Identifier;
 import org.apache.isis.applib.RecoverableException;
 import org.apache.isis.applib.annotation.BookmarkPolicy;
 import org.apache.isis.applib.annotation.Where;
+import org.apache.isis.applib.services.routing.RoutingService;
 import org.apache.isis.applib.value.Blob;
 import org.apache.isis.applib.value.Clob;
 import org.apache.isis.applib.value.NamedWithMimeType;
@@ -59,6 +60,7 @@ import org.apache.isis.core.metamodel.consent.Consent;
 import org.apache.isis.core.metamodel.consent.InteractionInitiatedBy;
 import org.apache.isis.core.metamodel.facets.object.bookmarkpolicy.BookmarkPolicyFacet;
 import org.apache.isis.core.metamodel.facets.object.encodeable.EncodableFacet;
+import org.apache.isis.core.metamodel.services.ServicesInjectorSpi;
 import org.apache.isis.core.metamodel.spec.ActionType;
 import org.apache.isis.core.metamodel.spec.ObjectSpecId;
 import org.apache.isis.core.metamodel.spec.ObjectSpecification;
@@ -467,6 +469,17 @@ public class ActionModel extends BookmarkableModel<ObjectAdapter> {
                         targetAdapter, arguments,
                         InteractionInitiatedBy.USER,
                         WHERE_FOR_ACTION_INVOCATION);
+
+        final List<RoutingService> routingServices = getServicesInjector().lookupServices(RoutingService.class);
+        final Object result = resultAdapter != null ? resultAdapter.getObject() : null;
+        for (RoutingService routingService : routingServices) {
+            final boolean canRoute = routingService.canRoute(result);
+            if(canRoute) {
+                final Object routeTo = routingService.route(result);
+                return routeTo != null? getPersistenceSession().adapterFor(routeTo): null;
+            }
+        }
+
         return resultAdapter;
     }
 
@@ -664,6 +677,10 @@ public class ActionModel extends BookmarkableModel<ObjectAdapter> {
         return new ActionModel(this);
     }
 
+    protected ServicesInjectorSpi getServicesInjector() {
+        return getPersistenceSession().getServicesInjector();
+    }
+
 
 
 }

http://git-wip-us.apache.org/repos/asf/isis/blob/9885ce97/example/application/simpleapp/dom/src/main/java/domainapp/dom/simple/SimpleObject.java
----------------------------------------------------------------------
diff --git a/example/application/simpleapp/dom/src/main/java/domainapp/dom/simple/SimpleObject.java b/example/application/simpleapp/dom/src/main/java/domainapp/dom/simple/SimpleObject.java
index 3057180..1410351 100644
--- a/example/application/simpleapp/dom/src/main/java/domainapp/dom/simple/SimpleObject.java
+++ b/example/application/simpleapp/dom/src/main/java/domainapp/dom/simple/SimpleObject.java
@@ -113,6 +113,16 @@ public class SimpleObject implements Comparable<SimpleObject> {
 
 
 
+    public static class DeleteDomainEvent extends ActionDomainEvent<SimpleObject> {}
+    @Action(
+            domainEvent = DeleteDomainEvent.class,
+            semantics = SemanticsOf.NON_IDEMPOTENT_ARE_YOU_SURE
+    )
+    public void delete() {
+        container.removeIfNotAlready(this);
+    }
+
+
     /**
      * version (derived property)
      */