You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2019/10/05 07:24:20 UTC

[isis] branch v2 updated: ISIS-2158: adds 'fileAccept' for @Action

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

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


The following commit(s) were added to refs/heads/v2 by this push:
     new 7a38263  ISIS-2158: adds 'fileAccept' for @Action
7a38263 is described below

commit 7a382632ac73246c8a23d0b76c5acbd6097ac7c1
Author: Andi Huber <ah...@apache.org>
AuthorDate: Sat Oct 5 09:24:12 2019 +0200

    ISIS-2158: adds 'fileAccept' for @Action
    
    unrelated: there is still an issue with @Action annotation processing, hence the quickfix code in ActionAnnotationFacetFactory
---
 .../org/apache/isis/applib/annotation/Action.java  | 13 +++++-
 .../action/ActionAnnotationFacetFactory.java       | 27 ++++++++++---
 .../FileAcceptFacetForActionAnnotation.java        | 47 ++++++++++++++++++++++
 .../standard/AuthenticationManagerStandard.java    | 30 +++++++-------
 4 files changed, 95 insertions(+), 22 deletions(-)

diff --git a/core/applib/src/main/java/org/apache/isis/applib/annotation/Action.java b/core/applib/src/main/java/org/apache/isis/applib/annotation/Action.java
index 5685491..9cabe5f 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/annotation/Action.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/annotation/Action.java
@@ -31,6 +31,8 @@ import org.apache.isis.applib.events.domain.ActionDomainEvent;
 import org.apache.isis.applib.services.command.CommandDtoProcessor;
 import org.apache.isis.applib.services.command.CommandWithDto;
 import org.apache.isis.applib.services.command.spi.CommandService;
+import org.apache.isis.applib.value.Blob;
+import org.apache.isis.applib.value.Clob;
 
 /**
  * Domain semantics for domain object collection.
@@ -208,5 +210,14 @@ public @interface Action {
      */
     String associateWithSequence() default "1";
 
-
+    /**
+     * For uploading {@link Blob} or {@link Clob}, optionally restrict the files accepted (eg <tt>.xslx</tt>).
+     *
+     * <p>
+     * The value should be of the form "file_extension|audio/*|video/*|image/*|media_type".
+     * </p>
+     *
+     * @see <a href="http://www.w3schools.com/tags/att_input_accept.asp">http://www.w3schools.com</a>
+     */
+    String fileAccept() default "";
 }
\ No newline at end of file
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/actions/action/ActionAnnotationFacetFactory.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/actions/action/ActionAnnotationFacetFactory.java
index d79b181..d03898b 100644
--- a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/actions/action/ActionAnnotationFacetFactory.java
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/actions/action/ActionAnnotationFacetFactory.java
@@ -42,6 +42,7 @@ import org.apache.isis.metamodel.facets.actions.action.prototype.PrototypeFacetF
 import org.apache.isis.metamodel.facets.actions.action.publishing.PublishedActionFacetForActionAnnotation;
 import org.apache.isis.metamodel.facets.actions.action.semantics.ActionSemanticsFacetForActionAnnotation;
 import org.apache.isis.metamodel.facets.actions.action.typeof.TypeOfFacetForActionAnnotation;
+import org.apache.isis.metamodel.facets.actions.fileaccept.FileAcceptFacetForActionAnnotation;
 import org.apache.isis.metamodel.facets.members.order.annotprop.MemberOrderFacetForActionAnnotation;
 import org.apache.isis.metamodel.facets.object.domainobject.domainevents.ActionDomainEventDefaultFacetForDomainObjectAnnotation;
 import org.apache.isis.metamodel.spec.ObjectSpecification;
@@ -71,6 +72,8 @@ public class ActionAnnotationFacetFactory extends FacetFactoryAbstract {
 
         processTypeOf(processMethodContext);
         processAssociateWith(processMethodContext);
+        
+        processFileAccept(processMethodContext);
     }
 
     void processInvocation(final ProcessMethodContext processMethodContext) {
@@ -99,18 +102,19 @@ public class ActionAnnotationFacetFactory extends FacetFactoryAbstract {
                     .map(Action::domainEvent)
                     .filter(domainEvent -> domainEvent != ActionDomainEvent.Default.class)
                     .filter(domainEvent -> {
-                        
-                        
+
+
                         if(!ActionDomainEvent.class.isAssignableFrom(domainEvent)) {
                             System.out.println("#### " + actionMethod + " -> " + domainEvent);
                             return false;
                         }
-                        
+
                         return true;
                     })
                     .map(domainEvent ->
-                    (ActionDomainEventFacetAbstract) new ActionDomainEventFacetForActionAnnotation(
-                            defaultFromDomainObjectIfRequired(typeSpec, domainEvent), holder))
+                            (ActionDomainEventFacetAbstract) 
+                            new ActionDomainEventFacetForActionAnnotation(
+                                    defaultFromDomainObjectIfRequired(typeSpec, domainEvent), holder))
                     .orElse(
                             new ActionDomainEventFacetDefault(
                                     defaultFromDomainObjectIfRequired(typeSpec, ActionDomainEvent.Default.class), holder)
@@ -282,6 +286,19 @@ public class ActionAnnotationFacetFactory extends FacetFactoryAbstract {
         
 
     }
+    
+    void processFileAccept(final ProcessMethodContext processMethodContext) {
+
+        val holder = processMethodContext.getFacetHolder();
+
+        // check for @Action(fileAccept=...)
+
+        val actionIfAny = processMethodContext.synthesizeOnMethod(Action.class);
+        
+        val facet = FileAcceptFacetForActionAnnotation.create(actionIfAny, holder);
+        FacetUtil.addFacet(facet);
+
+    }
 
 
 }
diff --git a/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/actions/fileaccept/FileAcceptFacetForActionAnnotation.java b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/actions/fileaccept/FileAcceptFacetForActionAnnotation.java
new file mode 100644
index 0000000..6d67fc9
--- /dev/null
+++ b/core/metamodel/src/main/java/org/apache/isis/metamodel/facets/actions/fileaccept/FileAcceptFacetForActionAnnotation.java
@@ -0,0 +1,47 @@
+/*
+ *  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.metamodel.facets.actions.fileaccept;
+
+import java.util.Optional;
+
+import org.apache.isis.applib.annotation.Action;
+import org.apache.isis.commons.internal.base._Strings;
+import org.apache.isis.metamodel.facetapi.FacetHolder;
+import org.apache.isis.metamodel.facets.objectvalue.fileaccept.FileAcceptFacet;
+import org.apache.isis.metamodel.facets.objectvalue.fileaccept.FileAcceptFacetAbstract;
+
+public class FileAcceptFacetForActionAnnotation extends FileAcceptFacetAbstract {
+
+    public static FileAcceptFacet create(
+            final Optional<Action> actionIfAny,
+            final FacetHolder holder) {
+
+        return actionIfAny
+                .map(Action::fileAccept)
+                .filter(_Strings::isNotEmpty)
+                .map(fileAccept -> new FileAcceptFacetForActionAnnotation(fileAccept, holder))
+                .orElse(null);
+    }
+
+    private FileAcceptFacetForActionAnnotation(final String value, final FacetHolder holder) {
+        super(value, holder);
+    }
+
+}
diff --git a/core/security/api/src/main/java/org/apache/isis/security/authentication/standard/AuthenticationManagerStandard.java b/core/security/api/src/main/java/org/apache/isis/security/authentication/standard/AuthenticationManagerStandard.java
index b7de778..9c21c52 100644
--- a/core/security/api/src/main/java/org/apache/isis/security/authentication/standard/AuthenticationManagerStandard.java
+++ b/core/security/api/src/main/java/org/apache/isis/security/authentication/standard/AuthenticationManagerStandard.java
@@ -30,6 +30,7 @@ import javax.inject.Inject;
 import org.apache.isis.applib.services.registry.ServiceRegistry;
 import org.apache.isis.applib.util.ToString;
 import org.apache.isis.commons.exceptions.IsisException;
+import org.apache.isis.commons.internal.base._Lazy;
 import org.apache.isis.commons.internal.base._NullSafe;
 import org.apache.isis.commons.internal.collections._Lists;
 import org.apache.isis.commons.internal.collections._Maps;
@@ -39,16 +40,23 @@ import org.apache.isis.security.authentication.manager.AuthenticationManager;
 import org.apache.isis.security.authentication.manager.RegistrationDetails;
 
 import static org.apache.isis.commons.internal.base._NullSafe.stream;
+import static org.apache.isis.commons.internal.base._With.requires;
 
+import lombok.Getter;
 import lombok.val;
 
 public class AuthenticationManagerStandard implements AuthenticationManager {
 
     private final Map<String, String> userByValidationCode = _Maps.newHashMap();
     private final List<Authenticator> authenticators = _Lists.newArrayList();
-    private RandomCodeGenerator randomCodeGenerator;
+    private _Lazy<RandomCodeGenerator> randomCodeGenerator =
+            _Lazy.threadSafe(this::getDefaultRandomCodeGenerator);
+    
+    @Getter
+    private RandomCodeGenerator defaultRandomCodeGenerator = new RandomCodeGenerator10Chars();
 
-    private @Inject ServiceRegistry serviceRegistry;
+    @Inject
+    private ServiceRegistry serviceRegistry;
 
     @PostConstruct
     public void preInit() {
@@ -68,7 +76,6 @@ public class AuthenticationManagerStandard implements AuthenticationManager {
      */
     @Override
     public final void init() {
-        defaultRandomCodeGeneratorIfNecessary();
         addDefaultAuthenticators();
         if (authenticators.size() == 0) {
             throw new IsisException("No authenticators specified");
@@ -78,11 +85,6 @@ public class AuthenticationManagerStandard implements AuthenticationManager {
         }
     }
 
-    private void defaultRandomCodeGeneratorIfNecessary() {
-        if (randomCodeGenerator == null) {
-            randomCodeGenerator = new RandomCodeGenerator10Chars();
-        }
-    }
 
     /**
      * optional hook method
@@ -131,7 +133,7 @@ public class AuthenticationManagerStandard implements AuthenticationManager {
     private String getUnusedRandomCode() {
         String code;
         do {
-            code = randomCodeGenerator.generateRandomCode();
+            code = randomCodeGenerator.get().generateRandomCode();
         } while (userByValidationCode.containsKey(code));
 
         return code;
@@ -212,14 +214,10 @@ public class AuthenticationManagerStandard implements AuthenticationManager {
     // RandomCodeGenerator
     // //////////////////////////////////////////////////////////
 
-
-    /**
-     * For injection; will {@link #defaultRandomCodeGeneratorIfNecessary()
-     * default} otherwise.
-     */
     public void setRandomCodeGenerator(final RandomCodeGenerator randomCodeGenerator) {
-        assert randomCodeGenerator != null;
-        this.randomCodeGenerator = randomCodeGenerator;
+        requires(randomCodeGenerator, "randomCodeGenerator");
+        this.defaultRandomCodeGenerator = randomCodeGenerator;
+        this.randomCodeGenerator.clear(); // invalidate
     }
 
     // //////////////////////////////////////////////////////////