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 2018/01/18 10:42:22 UTC

[isis] branch ISIS-1569-replay-commands updated (64ef3a2 -> a649b8f)

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

danhaywood pushed a change to branch ISIS-1569-replay-commands
in repository https://gitbox.apache.org/repos/asf/isis.git.


    from 64ef3a2  ISIS-1569: by way of tidy-up, just removes unused injected ClockService from CommandServiceDefault
     new 47e0e91  ISIS-1831: adds a guard in exception handler of a RuntimeException (REST API) to avoid throwing an NPE there.
     new 51ab60a  ISIS-1569: removes CommandService2, not required after all.
     new 75977f6  ISIS-1569: extends cmd-1.3.xsd to introduce a new CommandsDto (note the plural) as a sequence of CommandDto's
     new 306fa40  ISIS-1569: adds a convenience Util class for ContentMappingService to remove boilerplate in subclass implementations (parsing the acceptable media types).
     new a649b8f  ISIS-1569: defines CommandWithDto as an optional interface for Command SPI implementations to have their Command's implement (translatable into a CommandDto) along with out-of-the-box ContentMapingService to convert these into CommandsDto structure.

The 5 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../isis/applib/conmap/ContentMappingService.java  | 27 ++++++++
 .../ContentMappingServiceForCommandDto.java}       | 52 +++++++--------
 .../ContentMappingServiceForCommandsDto.java       | 78 ++++++++++++++++++++++
 .../CommandWithDto.java}                           | 11 ++-
 .../services/command/spi/CommandService2.java      | 55 ---------------
 .../org/apache/isis/schema/cmd/cmd-1.3.xsd         | 11 +++
 .../ExceptionMapperForRuntimeException.java        | 13 ++--
 7 files changed, 154 insertions(+), 93 deletions(-)
 copy core/{viewer-wicket-impl/src/main/java/org/apache/isis/viewer/wicket/viewer/services/LocaleProviderWicket.java => applib/src/main/java/org/apache/isis/applib/conmap/ContentMappingServiceForCommandDto.java} (54%)
 create mode 100644 core/applib/src/main/java/org/apache/isis/applib/conmap/ContentMappingServiceForCommandsDto.java
 copy core/applib/src/main/java/org/apache/isis/applib/services/{urlencoding/UrlEncodingService.java => command/CommandWithDto.java} (82%)
 delete mode 100644 core/applib/src/main/java/org/apache/isis/applib/services/command/spi/CommandService2.java

-- 
To stop receiving notification emails like this one, please contact
['"commits@isis.apache.org" <co...@isis.apache.org>'].

[isis] 05/05: ISIS-1569: defines CommandWithDto as an optional interface for Command SPI implementations to have their Command's implement (translatable into a CommandDto) along with out-of-the-box ContentMapingService to convert these into CommandsDto structure.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch ISIS-1569-replay-commands
in repository https://gitbox.apache.org/repos/asf/isis.git

commit a649b8f0a2eb4f972d1981e8df6438113ad7613e
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Thu Jan 18 10:33:07 2018 +0000

    ISIS-1569: defines CommandWithDto as an optional interface for Command SPI implementations to have their Command's implement (translatable into a CommandDto) along with out-of-the-box ContentMapingService to convert these into CommandsDto structure.
---
 .../conmap/ContentMappingServiceForCommandDto.java | 60 +++++++++++++++++
 .../ContentMappingServiceForCommandsDto.java       | 78 ++++++++++++++++++++++
 .../applib/services/command/CommandWithDto.java    | 26 ++++++++
 3 files changed, 164 insertions(+)

diff --git a/core/applib/src/main/java/org/apache/isis/applib/conmap/ContentMappingServiceForCommandDto.java b/core/applib/src/main/java/org/apache/isis/applib/conmap/ContentMappingServiceForCommandDto.java
new file mode 100644
index 0000000..0eb1235
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/conmap/ContentMappingServiceForCommandDto.java
@@ -0,0 +1,60 @@
+/*
+ *  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.conmap;
+
+import java.util.List;
+
+import javax.ws.rs.core.MediaType;
+
+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.services.command.CommandWithDto;
+import org.apache.isis.schema.cmd.v1.CommandDto;
+
+@DomainService(
+        nature = NatureOfService.DOMAIN,
+        menuOrder = "" + Integer.MAX_VALUE
+)
+public class ContentMappingServiceForCommandDto implements ContentMappingService {
+
+    @Programmatic
+    public Object map(Object object, final List<MediaType> acceptableMediaTypes) {
+        final boolean supported = Util.isSupported(CommandDto.class, acceptableMediaTypes);
+        if(!supported) {
+            return null;
+        }
+
+        return asDto(object);
+    }
+
+
+    static CommandDto asDto(final Object object) {
+        CommandDto commandDto = null;
+        if(object instanceof CommandWithDto) {
+            final CommandWithDto commandWithDto = (CommandWithDto) object;
+            commandDto = commandWithDto.asDto();
+        }
+        if(object instanceof CommandDto) {
+            commandDto = (CommandDto) object;
+        }
+        return commandDto;
+    }
+
+}
diff --git a/core/applib/src/main/java/org/apache/isis/applib/conmap/ContentMappingServiceForCommandsDto.java b/core/applib/src/main/java/org/apache/isis/applib/conmap/ContentMappingServiceForCommandsDto.java
new file mode 100644
index 0000000..4f886a9
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/conmap/ContentMappingServiceForCommandsDto.java
@@ -0,0 +1,78 @@
+/*
+ *  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.conmap;
+
+import java.util.List;
+
+import javax.ws.rs.core.MediaType;
+
+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.schema.cmd.v1.CommandDto;
+import org.apache.isis.schema.cmd.v1.CommandsDto;
+
+@DomainService(
+        nature = NatureOfService.DOMAIN,
+        menuOrder = "" + Integer.MAX_VALUE
+)
+public class ContentMappingServiceForCommandsDto implements ContentMappingService {
+
+    @Programmatic
+    public Object map(Object object, final List<MediaType> acceptableMediaTypes) {
+        final boolean supported = Util.isSupported(CommandsDto.class, acceptableMediaTypes);
+        if(!supported) {
+            return null;
+        }
+
+        if(object instanceof CommandsDto) {
+            return object;
+        }
+
+        CommandDto commandDto = asDto(object);
+        if(commandDto != null) {
+            final CommandsDto commandsDto = new CommandsDto();
+            commandsDto.getCommandDto().add(commandDto);
+            return commandsDto;
+        }
+
+        if (object instanceof List) {
+            final List list = (List) object;
+            final CommandsDto commandsDto = new CommandsDto();
+            for (final Object o : list) {
+                final CommandDto objAsCommandDto = asDto(o);
+                if(objAsCommandDto != null) {
+                    commandsDto.getCommandDto().add(objAsCommandDto);
+                } else {
+                    // ignore entire list because found something that is not convertible.
+                    return null;
+                }
+            }
+            return commandsDto;
+        }
+
+        // else
+        return null;
+    }
+
+    private static CommandDto asDto(final Object object) {
+        return ContentMappingServiceForCommandDto.asDto(object);
+    }
+
+}
diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/command/CommandWithDto.java b/core/applib/src/main/java/org/apache/isis/applib/services/command/CommandWithDto.java
new file mode 100644
index 0000000..e0e1b60
--- /dev/null
+++ b/core/applib/src/main/java/org/apache/isis/applib/services/command/CommandWithDto.java
@@ -0,0 +1,26 @@
+/**
+ *  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.command;
+
+import org.apache.isis.applib.annotation.Programmatic;
+import org.apache.isis.schema.cmd.v1.CommandDto;
+
+public interface CommandWithDto extends Command {
+
+    @Programmatic
+    CommandDto asDto();
+}

-- 
To stop receiving notification emails like this one, please contact
"commits@isis.apache.org" <co...@isis.apache.org>.

[isis] 02/05: ISIS-1569: removes CommandService2, not required after all.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch ISIS-1569-replay-commands
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 51ab60a8c0ff7ec4c5cf65e604fbc5d6067bca43
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Thu Jan 18 10:29:32 2018 +0000

    ISIS-1569: removes CommandService2, not required after all.
---
 .../services/command/spi/CommandService2.java      | 55 ----------------------
 1 file changed, 55 deletions(-)

diff --git a/core/applib/src/main/java/org/apache/isis/applib/services/command/spi/CommandService2.java b/core/applib/src/main/java/org/apache/isis/applib/services/command/spi/CommandService2.java
deleted file mode 100644
index c745bdd..0000000
--- a/core/applib/src/main/java/org/apache/isis/applib/services/command/spi/CommandService2.java
+++ /dev/null
@@ -1,55 +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.command.spi;
-
-import java.util.List;
-import java.util.UUID;
-
-import org.apache.isis.applib.annotation.Programmatic;
-import org.apache.isis.applib.services.command.Command;
-
-public interface CommandService2 extends CommandService {
-
-    public static class NotFoundException extends RuntimeException {
-
-        private static final long serialVersionUID = 1L;
-
-        private final String transactionId;
-
-        public NotFoundException(final String transactionId) {
-            this.transactionId = transactionId;
-        }
-
-        public String getTransactionId() {
-            return transactionId;
-        }
-    }
-
-    /**
-     * Finds all {@link Command}s created since the specified command (identified by its transaction Id).
-     *
-     * @param transactionId
-     * @param maxNumber
-     * @return
-     */
-    @Programmatic
-    List<Command> findSince(
-            final UUID transactionId,
-            int maxNumber)
-            throws NotFoundException;
-
-}

-- 
To stop receiving notification emails like this one, please contact
"commits@isis.apache.org" <co...@isis.apache.org>.

[isis] 01/05: ISIS-1831: adds a guard in exception handler of a RuntimeException (REST API) to avoid throwing an NPE there.

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch ISIS-1569-replay-commands
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 47e0e91372df0619c1cb5dfceee02f8110d115da
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Thu Jan 18 09:30:01 2018 +0000

    ISIS-1831: adds a guard in exception handler of a RuntimeException (REST API) to avoid throwing an NPE there.
---
 .../server/mappers/ExceptionMapperForRuntimeException.java  | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/mappers/ExceptionMapperForRuntimeException.java b/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/mappers/ExceptionMapperForRuntimeException.java
index 2596c65..c83798b 100644
--- a/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/mappers/ExceptionMapperForRuntimeException.java
+++ b/core/viewer-restfulobjects-server/src/main/java/org/apache/isis/viewer/restfulobjects/server/mappers/ExceptionMapperForRuntimeException.java
@@ -26,6 +26,7 @@ import javax.ws.rs.ext.Provider;
 import com.google.common.base.Throwables;
 
 import org.apache.isis.core.runtime.system.context.IsisContext;
+import org.apache.isis.core.runtime.system.session.IsisSession;
 import org.apache.isis.core.runtime.system.session.IsisSessionFactory;
 import org.apache.isis.core.runtime.system.transaction.IsisTransaction;
 
@@ -35,15 +36,17 @@ public class ExceptionMapperForRuntimeException extends ExceptionMapperAbstract<
     @Override
     public Response toResponse(final RuntimeException ex) {
 
-        // since already rendered...
-        final IsisTransaction currentTransaction = getIsisSessionFactory().getCurrentSession()
-                .getPersistenceSession().getTransactionManager().getCurrentTransaction();
-
         final Throwable rootCause = Throwables.getRootCause(ex);
         final List<Throwable> causalChain = Throwables.getCausalChain(ex);
         for (Throwable throwable : causalChain) {
             if(throwable == rootCause) {
-                currentTransaction.clearAbortCause();
+                // since already rendered...
+                final IsisSession currentSession = getIsisSessionFactory().getCurrentSession();
+                if(currentSession != null) {
+                    final IsisTransaction currentTransaction = currentSession
+                            .getPersistenceSession().getTransactionManager().getCurrentTransaction();
+                    currentTransaction.clearAbortCause();
+                }
             }
         }
 

-- 
To stop receiving notification emails like this one, please contact
"commits@isis.apache.org" <co...@isis.apache.org>.

[isis] 04/05: ISIS-1569: adds a convenience Util class for ContentMappingService to remove boilerplate in subclass implementations (parsing the acceptable media types).

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch ISIS-1569-replay-commands
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 306fa403a926ac69cef1df2de8bf97e30aceff09
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Thu Jan 18 10:30:46 2018 +0000

    ISIS-1569: adds a convenience Util class for ContentMappingService to remove boilerplate in subclass implementations (parsing the acceptable media types).
---
 .../isis/applib/conmap/ContentMappingService.java  | 27 ++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/core/applib/src/main/java/org/apache/isis/applib/conmap/ContentMappingService.java b/core/applib/src/main/java/org/apache/isis/applib/conmap/ContentMappingService.java
index d577dfb..49b0eb5 100644
--- a/core/applib/src/main/java/org/apache/isis/applib/conmap/ContentMappingService.java
+++ b/core/applib/src/main/java/org/apache/isis/applib/conmap/ContentMappingService.java
@@ -19,9 +19,12 @@
 package org.apache.isis.applib.conmap;
 
 import java.util.List;
+import java.util.Map;
 
 import javax.ws.rs.core.MediaType;
 
+import com.google.common.base.Joiner;
+
 import org.apache.isis.applib.annotation.Programmatic;
 
 public interface ContentMappingService {
@@ -32,4 +35,28 @@ public interface ContentMappingService {
     @Programmatic
     Object map(Object object, final List<MediaType> acceptableMediaTypes);
 
+    /**
+     * Convenience utilities for implementations of {@link ContentMappingService}.
+     */
+    public static class Util {
+
+        public static String determineDomainType(final List<MediaType> acceptableMediaTypes) {
+            for (MediaType acceptableMediaType : acceptableMediaTypes) {
+                final Map<String, String> parameters = acceptableMediaType.getParameters();
+                final String domainType = parameters.get("x-ro-domain-type");
+                if(domainType != null) {
+                    return domainType;
+                }
+            }
+            throw new IllegalArgumentException(
+                    "Could not locate x-ro-domain-type parameter in any of the provided media types; got: " + Joiner.on(", ").join(acceptableMediaTypes));
+        }
+
+        public static boolean isSupported(
+                final Class<?> clazz,
+                final List<MediaType> acceptableMediaTypes) {
+            final String domainType = determineDomainType(acceptableMediaTypes);
+            return clazz.getName().equals(domainType);
+        }
+    }
 }

-- 
To stop receiving notification emails like this one, please contact
"commits@isis.apache.org" <co...@isis.apache.org>.

[isis] 03/05: ISIS-1569: extends cmd-1.3.xsd to introduce a new CommandsDto (note the plural) as a sequence of CommandDto's

Posted by da...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch ISIS-1569-replay-commands
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 75977f6168bec7433dfeac60be90fe4440cc29e4
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Thu Jan 18 10:30:03 2018 +0000

    ISIS-1569: extends cmd-1.3.xsd to introduce a new CommandsDto (note the plural) as a sequence of CommandDto's
---
 .../src/main/resources/org/apache/isis/schema/cmd/cmd-1.3.xsd | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/core/schema/src/main/resources/org/apache/isis/schema/cmd/cmd-1.3.xsd b/core/schema/src/main/resources/org/apache/isis/schema/cmd/cmd-1.3.xsd
index 8cb1830..630dbe2 100644
--- a/core/schema/src/main/resources/org/apache/isis/schema/cmd/cmd-1.3.xsd
+++ b/core/schema/src/main/resources/org/apache/isis/schema/cmd/cmd-1.3.xsd
@@ -25,6 +25,17 @@
 
     <xs:import namespace="http://isis.apache.org/schema/common" schemaLocation="../common/common-1.1.xsd"/>
 
+    <xs:element name="commandsDto">
+        <xs:annotation>
+            <xs:documentation>Collection of commandDto's</xs:documentation>
+        </xs:annotation>
+        <xs:complexType>
+            <xs:sequence minOccurs="1" maxOccurs="unbounded">
+                <xs:element ref="commandDto"/>
+            </xs:sequence>
+        </xs:complexType>
+    </xs:element>
+
     <xs:element name="commandDto">
         <xs:annotation>
             <xs:documentation>Represents v1.3 of this schema, adding in 'logicalMemberIdentifier'

-- 
To stop receiving notification emails like this one, please contact
"commits@isis.apache.org" <co...@isis.apache.org>.