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 2020/02/21 01:14:36 UTC

[isis] 01/02: ISIS-2062: updates examples

This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 4365fd4bddbe04e5411bc041b4f5a1f8da20ecbc
Author: danhaywood <da...@haywood-associates.co.uk>
AuthorDate: Fri Feb 21 01:08:53 2020 +0000

    ISIS-2062: updates examples
---
 .../metamodel/Object_downloadMetaModelXml.java     |   3 +-
 .../examples/services/command/CommandContext.java  |   9 +
 .../services/confview/ConfigurationMenu.java       |   4 +-
 .../examples/services/jaxb/JaxbServiceDefault.java |  13 +-
 ...ServicesMenu.java => MetaModelServiceMenu.java} |  10 +-
 .../QueryResultsCacheDefault.java                  | 229 ---------------------
 .../services/tablecol/TableColumnOrderService.java |  28 +--
 .../UrlEncodingServiceWithCompression.java         |  52 -----
 8 files changed, 28 insertions(+), 320 deletions(-)

diff --git a/api/applib/src/main/adoc/modules/applib-cm/examples/mixins/metamodel/Object_downloadMetaModelXml.java b/api/applib/src/main/adoc/modules/applib-cm/examples/mixins/metamodel/Object_downloadMetaModelXml.java
index c07bca4..0cdc78f 100644
--- a/api/applib/src/main/adoc/modules/applib-cm/examples/mixins/metamodel/Object_downloadMetaModelXml.java
+++ b/api/applib/src/main/adoc/modules/applib-cm/examples/mixins/metamodel/Object_downloadMetaModelXml.java
@@ -100,7 +100,8 @@ public class Object_downloadMetaModelXml {
 
     @Inject MetaModelService metaModelService;
     @Inject JaxbService jaxbService;
-    @Inject MetaModelServicesMenu metaModelServicesMenu;
+    @Inject
+    MetaModelServiceMenu metaModelServiceMenu;
 
 
 
diff --git a/api/applib/src/main/adoc/modules/applib-svc/examples/services/command/CommandContext.java b/api/applib/src/main/adoc/modules/applib-svc/examples/services/command/CommandContext.java
index 2ae2f23..e3a24fc 100644
--- a/api/applib/src/main/adoc/modules/applib-svc/examples/services/command/CommandContext.java
+++ b/api/applib/src/main/adoc/modules/applib-svc/examples/services/command/CommandContext.java
@@ -18,6 +18,8 @@
  */
 package org.apache.isis.applib.services.command;
 
+import java.util.Optional;
+
 import javax.enterprise.context.RequestScoped;
 import javax.inject.Named;
 
@@ -27,6 +29,7 @@ import org.springframework.core.annotation.Order;
 import org.springframework.stereotype.Service;
 
 import org.apache.isis.applib.annotation.OrderPrecedence;
+import org.apache.isis.applib.services.command.Command.Executor;
 
 import lombok.Getter;
 
@@ -56,6 +59,12 @@ public class CommandContext {
     public void setCommand(final Command command) {
         this.command = command;
     }
+    
+    public Optional<Executor> getCurrentExecutor() {
+        return Optional.ofNullable(getCommand())
+                .map(Command::getExecutor); 
+    }
+    
 
 // tag::refguide[]
 }
diff --git a/api/applib/src/main/adoc/modules/applib-svc/examples/services/confview/ConfigurationMenu.java b/api/applib/src/main/adoc/modules/applib-svc/examples/services/confview/ConfigurationMenu.java
index fc79ee7..a400a9f 100644
--- a/api/applib/src/main/adoc/modules/applib-svc/examples/services/confview/ConfigurationMenu.java
+++ b/api/applib/src/main/adoc/modules/applib-svc/examples/services/confview/ConfigurationMenu.java
@@ -48,11 +48,11 @@ public class ConfigurationMenu {
         this.configurationService = configurationService;
     }
 
-    public static class AllConfigurationPropertiesDomainEvent
+    public static class ConfigurationDomainEvent
         extends ActionDomainEvent {}
 
     @Action(
-            domainEvent = AllConfigurationPropertiesDomainEvent.class,
+            domainEvent = ConfigurationDomainEvent.class,
             semantics = SemanticsOf.SAFE
             )
     @ActionLayout(
diff --git a/api/applib/src/main/adoc/modules/applib-svc/examples/services/jaxb/JaxbServiceDefault.java b/api/applib/src/main/adoc/modules/applib-svc/examples/services/jaxb/JaxbServiceDefault.java
index 9a70e93..e76bece 100644
--- a/api/applib/src/main/adoc/modules/applib-svc/examples/services/jaxb/JaxbServiceDefault.java
+++ b/api/applib/src/main/adoc/modules/applib-svc/examples/services/jaxb/JaxbServiceDefault.java
@@ -40,7 +40,6 @@ import org.apache.isis.applib.jaxbadapters.PersistentEntitiesAdapter;
 import org.apache.isis.applib.jaxbadapters.PersistentEntityAdapter;
 import org.apache.isis.applib.services.inject.ServiceInjector;
 import org.apache.isis.applib.services.metamodel.MetaModelService;
-import org.apache.isis.applib.services.registry.ServiceRegistry;
 
 @Service
 @Named("isisApplib.JaxbServiceDefault")
@@ -49,6 +48,15 @@ import org.apache.isis.applib.services.registry.ServiceRegistry;
 @Qualifier("Default")
 public class JaxbServiceDefault extends JaxbService.Simple {
 
+    private final ServiceInjector serviceInjector;
+    private final MetaModelService metaModelService;
+
+    @Inject
+    public JaxbServiceDefault(ServiceInjector serviceInjector, MetaModelService metaModelService) {
+        this.serviceInjector = serviceInjector;
+        this.metaModelService = metaModelService;
+    }
+
     @Override
     public Object fromXml(final JAXBContext jaxbContext, final String xml, final Map<String, Object> unmarshallerProperties) {
         try {
@@ -110,8 +118,5 @@ public class JaxbServiceDefault extends JaxbService.Simple {
     }
 
 
-    @Inject ServiceRegistry serviceRegistry;
-    @Inject ServiceInjector serviceInjector;
-    @Inject MetaModelService metaModelService;
 }
 
diff --git a/api/applib/src/main/adoc/modules/applib-svc/examples/services/metamodel/MetaModelServicesMenu.java b/api/applib/src/main/adoc/modules/applib-svc/examples/services/metamodel/MetaModelServiceMenu.java
similarity index 97%
rename from api/applib/src/main/adoc/modules/applib-svc/examples/services/metamodel/MetaModelServicesMenu.java
rename to api/applib/src/main/adoc/modules/applib-svc/examples/services/metamodel/MetaModelServiceMenu.java
index 86dbb92..0b76f27 100644
--- a/api/applib/src/main/adoc/modules/applib-svc/examples/services/metamodel/MetaModelServicesMenu.java
+++ b/api/applib/src/main/adoc/modules/applib-svc/examples/services/metamodel/MetaModelServiceMenu.java
@@ -47,20 +47,20 @@ import org.apache.isis.core.commons.internal.collections._Lists;
 import org.apache.isis.core.commons.internal.collections._Sets;
 import org.apache.isis.schema.metamodel.v2.MetamodelDto;
 
-@Named("isisApplib.MetaModelServicesMenu")
-@DomainService(objectType = "isisApplib.MetaModelServicesMenu")
+@Named("isisApplib.MetaModelServiceMenu")
+@DomainService(objectType = "isisApplib.MetaModelServiceMenu")
 @DomainServiceLayout(
         named = "Prototyping",
         menuBar = DomainServiceLayout.MenuBar.SECONDARY
 )
-public class MetaModelServicesMenu {
+public class MetaModelServiceMenu {
 
-    public static abstract class ActionDomainEvent extends IsisModuleApplib.ActionDomainEvent<MetaModelServicesMenu> { }
+    public static abstract class ActionDomainEvent extends IsisModuleApplib.ActionDomainEvent<MetaModelServiceMenu> { }
 
     final MimeType mimeTypeTextCsv;
     final MimeType mimeTypeTextXml;
 
-    public MetaModelServicesMenu() {
+    public MetaModelServiceMenu() {
         try {
             mimeTypeTextCsv = new MimeType("text", "csv");
             mimeTypeTextXml = new MimeType("application", "xml");
diff --git a/api/applib/src/main/adoc/modules/applib-svc/examples/services/queryresultscache/QueryResultsCacheDefault.java b/api/applib/src/main/adoc/modules/applib-svc/examples/services/queryresultscache/QueryResultsCacheDefault.java
deleted file mode 100644
index 5ddf15c..0000000
--- a/api/applib/src/main/adoc/modules/applib-svc/examples/services/queryresultscache/QueryResultsCacheDefault.java
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- *  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.queryresultscache;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.Callable;
-
-import javax.enterprise.context.RequestScoped;
-import javax.inject.Named;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.context.annotation.Primary;
-import org.springframework.core.annotation.Order;
-import org.springframework.stereotype.Service;
-
-import org.apache.isis.applib.annotation.OrderPrecedence;
-import org.apache.isis.applib.services.WithTransactionScope;
-import org.apache.isis.core.commons.handler.MethodReferences.Call0;
-import org.apache.isis.core.commons.handler.MethodReferences.Call1;
-import org.apache.isis.core.commons.handler.MethodReferences.Call2;
-import org.apache.isis.core.commons.handler.MethodReferences.Call3;
-import org.apache.isis.core.commons.handler.MethodReferences.Call4;
-import org.apache.isis.core.commons.handler.MethodReferences.Call5;
-import org.apache.isis.core.commons.internal.base._Casts;
-import org.apache.isis.core.commons.internal.base._NullSafe;
-import org.apache.isis.core.commons.internal.collections._Maps;
-
-import lombok.extern.log4j.Log4j2;
-
-/**
- * This service (API and implementation) provides a mechanism by which idempotent query results can be cached for the duration of an interaction.
- * Most commonly this allows otherwise &quot;naive&quot; - eg that makes a repository call many times within a loop - to
- * be performance tuned.  The benefit is that the algorithm of the business logic can remain easy to understand.
- *
- * <p>
- * This implementation has no UI and there is only one implementation (this class) in applib, it is annotated with
- * {@link org.apache.isis.applib.annotation.DomainService}.  This means that it is automatically registered and
- * available for use; no further configuration is required.
- */
-@Service
-@Named("isisApplib.QueryResultsCacheInternal")
-@Order(OrderPrecedence.EARLY)
-@Primary
-@RequestScoped
-@Qualifier("Default")
-@Log4j2
-public class QueryResultsCacheDefault implements QueryResultsCache, WithTransactionScope {
-
-    private final Map<Key, Value<?>> cache = _Maps.newHashMap();
-    
-    @Override
-    public <R> R execute(Call0<? extends R> action, Class<?> callingClass, String methodName) {
-        if(isIgnoreCache()) {
-            return action.call();
-        }
-        final Key cacheKey = new Key(callingClass, methodName);
-        return executeWithCaching(()->action.call(), cacheKey);
-    }
-
-    @Override
-    public <R, A0> R execute(Call1<? extends R, A0> action, Class<?> callingClass, String methodName, A0 arg0) {
-        if(isIgnoreCache()) {
-            return action.call(arg0);
-        }
-        final Key cacheKey = new Key(callingClass, methodName, arg0);
-        return executeWithCaching(()->action.call(arg0), cacheKey);
-    }
-
-    @Override
-    public <R, A0, A1> R execute(Call2<? extends R, A0, A1> action, Class<?> callingClass, String methodName, A0 arg0,
-            A1 arg1) {
-        if(isIgnoreCache()) {
-            return action.call(arg0, arg1);
-        }
-        final Key cacheKey = new Key(callingClass, methodName, arg0, arg1);
-        return executeWithCaching(()->action.call(arg0, arg1), cacheKey);
-    }
-
-    @Override
-    public <R, A0, A1, A2> R execute(Call3<? extends R, A0, A1, A2> action, Class<?> callingClass, String methodName,
-            A0 arg0, A1 arg1, A2 arg2) {
-        if(isIgnoreCache()) {
-            return action.call(arg0, arg1, arg2);
-        }
-        final Key cacheKey = new Key(callingClass, methodName, arg0, arg1, arg2);
-        return executeWithCaching(()->action.call(arg0, arg1, arg2), cacheKey);
-    }
-
-    @Override
-    public <R, A0, A1, A2, A3> R execute(Call4<? extends R, A0, A1, A2, A3> action, Class<?> callingClass,
-            String methodName, A0 arg0, A1 arg1, A2 arg2, A3 arg3) {
-        if(isIgnoreCache()) {
-            return action.call(arg0, arg1, arg2, arg3);
-        }
-        final Key cacheKey = new Key(callingClass, methodName, arg0, arg1, arg2, arg3);
-        return executeWithCaching(()->action.call(arg0, arg1, arg2, arg3), cacheKey);
-    }
-
-    @Override
-    public <R, A0, A1, A2, A3, A4> R execute(Call5<? extends R, A0, A1, A2, A3, A4> action, Class<?> callingClass,
-            String methodName, A0 arg0, A1 arg1, A2 arg2, A3 arg3, A4 arg4) {
-        if(isIgnoreCache()) {
-            return action.call(arg0, arg1, arg2, arg3, arg4);
-        }
-        final Key cacheKey = new Key(callingClass, methodName, arg0, arg1, arg2, arg3, arg4);
-        return executeWithCaching(()->action.call(arg0, arg1, arg2, arg3, arg4), cacheKey);
-    }
-
-    @Override
-    public <T> T execute(
-            final Callable<T> callable,
-            final Class<?> callingClass,
-            final String methodName,
-            final Object... keys) {
-        if(isIgnoreCache()) {
-            try {
-                return callable.call();
-            } catch (Exception e) {
-                throw new RuntimeException(e);
-            }
-        }
-        final Key cacheKey = new Key(callingClass, methodName, keys);
-        return executeWithCaching(callable, cacheKey);
-    }
-
-    private <T> T executeWithCaching(final Callable<T> callable, final Key cacheKey) {
-        try {
-            final Value<?> cacheValue = cache.get(cacheKey);
-            logHitOrMiss(cacheKey, cacheValue);
-            if(cacheValue != null) {
-                return _Casts.uncheckedCast(cacheValue.getResult());
-            }
-
-            // cache miss, so get the result...
-            T result = callable.call();
-
-            // ... and cache
-            //
-            // (it is possible that the callable just invoked might also have updated the cache, eg if there was
-            // some sort of recursion.  However, Map#put(...) is idempotent, so valid to call more than once.
-            //
-            // note: there's no need for thread-safety synchronization... remember that QueryResultsCache is @RequestScoped
-            put(cacheKey, result);
-
-            return result;
-        } catch (Exception e) {
-            throw new RuntimeException(e);
-        }
-    }
-
-    private <T> void put(final Key cacheKey, final T result) {
-        log.debug("PUT: {}", cacheKey);
-        cache.put(cacheKey, new Value<T>(result));
-    }
-
-    private static void logHitOrMiss(final Key cacheKey, final Value<?> cacheValue) {
-        if(!log.isDebugEnabled()) {
-            return;
-        }
-        log.debug("{}: {}", (cacheValue != null ? "HIT" : "MISS"), cacheKey.toString());
-    }
-
-    /**
-     * Not API: for framework to call at end of transaction, to clear out the cache.
-     *
-     * <p>
-     * (This service really ought to be considered
-     * a transaction-scoped service; since that isn't yet supported by the framework, we have to manually reset).
-     * </p>
-     */
-    @Override
-    public void resetForNextTransaction() {
-        cache.clear();
-    }
-
-    // -- HELPER
-
-    @Autowired(required = false)
-    protected List<QueryResultCacheControl> cacheControl;
-
-    private boolean isIgnoreCache() {
-        return _NullSafe.stream(cacheControl)
-                .anyMatch(c->c.isIgnoreCache());
-    }
-    
-    // -- REMOVED
-    
-  //XXX not used    
-//  private <T> Value<T> get(final Class<?> callingClass, final String methodName, final Object... keys) {
-//      return get(new Key(callingClass, methodName, keys));
-//  }
-//
-//  @SuppressWarnings("unchecked")
-//  private <T> Value<T> get(final Key cacheKey) {
-//      Value<T> value = (Value<T>) cache.get(cacheKey);
-//      logHitOrMiss(cacheKey, value);
-//      return value;
-//  }
-    
-  //XXX not used    
-//  private <T> T execute(final Callable<T> callable, final Key cacheKey) {
-//      if(isIgnoreCache()) {
-//          try {
-//              return callable.call();
-//          } catch (Exception e) {
-//              throw new RuntimeException(e);
-//          }
-//      }
-//      return executeWithCaching(callable, cacheKey);
-//  }
-
-}
\ No newline at end of file
diff --git a/api/applib/src/main/adoc/modules/applib-svc/examples/services/tablecol/TableColumnOrderService.java b/api/applib/src/main/adoc/modules/applib-svc/examples/services/tablecol/TableColumnOrderService.java
index dd2b60b..e2586d3 100644
--- a/api/applib/src/main/adoc/modules/applib-svc/examples/services/tablecol/TableColumnOrderService.java
+++ b/api/applib/src/main/adoc/modules/applib-svc/examples/services/tablecol/TableColumnOrderService.java
@@ -43,33 +43,7 @@ public interface TableColumnOrderService {
             final List<String> propertyIds);
 
 // end::refguide[]
-    /**
-     * Used as a fallback.
-     */
-    @Service
-    @Named("isisApplib.TableColumnOrderService.Default")
-    @Order(OrderPrecedence.LATE)
-    @Primary
-    @Qualifier("Default")
-    public static class Default implements TableColumnOrderService {
-
-        @Override
-        public List<String> orderParented(
-                final Object parent,
-                final String collectionId,
-                final Class<?> collectionType,
-                final List<String> propertyIds) {
-            return propertyIds;
-        }
-
-        @Override
-        public List<String> orderStandalone(
-                final Class<?> collectionType,
-                final List<String> propertyIds) {
-            return propertyIds;
-        }
-    }
-// tag::refguide[]
+    // tag::refguide[]
 
 }
 // end::refguide[]
diff --git a/api/applib/src/main/adoc/modules/applib-svc/examples/services/urlencoding/UrlEncodingServiceWithCompression.java b/api/applib/src/main/adoc/modules/applib-svc/examples/services/urlencoding/UrlEncodingServiceWithCompression.java
deleted file mode 100644
index 1554e6b..0000000
--- a/api/applib/src/main/adoc/modules/applib-svc/examples/services/urlencoding/UrlEncodingServiceWithCompression.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- *  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.urlencoding;
-
-import java.nio.charset.StandardCharsets;
-
-import javax.inject.Named;
-
-import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.context.annotation.Primary;
-import org.springframework.core.annotation.Order;
-import org.springframework.stereotype.Service;
-
-import org.apache.isis.applib.annotation.OrderPrecedence;
-import org.apache.isis.core.commons.internal.base._Bytes;
-import org.apache.isis.core.commons.internal.base._Strings;
-
-@Service
-@Named("isisApplib.UrlEncodingServiceWithCompression")
-@Order(OrderPrecedence.MIDPOINT)
-@Primary
-@Qualifier("Compression")
-public class UrlEncodingServiceWithCompression implements UrlEncodingService {
-
-    @Override
-    public String encode(final byte[] bytes) {
-        return _Strings.ofBytes(_Bytes.asCompressedUrlBase64.apply(bytes), StandardCharsets.UTF_8);
-    }
-
-    @Override
-    public byte[] decode(final String str) {
-        return _Bytes.ofCompressedUrlBase64.apply(_Strings.toBytes(str, StandardCharsets.UTF_8));
-    }
-
-
-}