Daniel Keir Haywood created CAUSEWAY-4066:
---------------------------------------------

             Summary: Allow a 'primer' to be called when invoking an action or 
rendering an object.
                 Key: CAUSEWAY-4066
                 URL: https://issues.apache.org/jira/browse/CAUSEWAY-4066
             Project: Causeway
          Issue Type: New Feature
          Components: Applib (programming model), Core
    Affects Versions: 4.0.0-M2, v2 maintenance-branch
            Reporter: Daniel Keir Haywood
            Assignee: Daniel Keir Haywood
             Fix For: 4.0.0, v2 maintenance-branch


```java
   public interface PrimingRegistry {

       <T> void action(
               Class<T> domainType,
               String actionLogicalName,
               ActionPrimer<? super T> primer);

       <T> void actions(
               Class<T> domainType,
               Collection<String> actionLogicalNames,
               ActionPrimer<? super T> primer);

       <T> void view(
               Class<T> domainType,
               ViewPrimer<? super T> primer);

   }
 ```

 Example:

 ```java
   registry.actions(
           Invoice.class,
           Set.of("approve", "recalculate"),
           (invoice, arguments) ->
                   invoiceRepository.primeForCalculation(invoice));

   registry.view(
           Invoice.class,
           invoiceRepository::primeForRendering);
 ```

 Internally, registration resolves:

 ```text
   Invoice.class
       → ObjectSpecification
       → logical type "estatio.Invoice"
 ```

 The resulting lookup keys are:

 ```text
   action: "estatio.Invoice#approve"
   view:   "estatio.Invoice"
 ```

 Fail-fast validation

 Registration must happen after metamodel initialization so that it can 
validate:

 - the supplied class has an exact metamodel specification;
 - that specification has a logical type;
 - each supplied action logical name exists on that specification;
 - an action name is nonblank and is a local name rather than a full type#member
   identifier;
 - the registered target class is compatible with the resolved specification.

 If the supplied class is an unregistered superclass or other type without its 
own
 logical type, startup fails.

 There should initially be no:

 - search through subclasses;
 - search up the superclass hierarchy;
 - inherited view-primer matching;
 - wildcard or assignability-based registry lookup.

 Both registration and runtime lookup therefore remain exact and predictable.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to