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 2022/04/13 18:47:27 UTC
[isis] branch master updated: ISIS-3003: simplifies and fixes the fetcher
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new b86ec7f7f2 ISIS-3003: simplifies and fixes the fetcher
b86ec7f7f2 is described below
commit b86ec7f7f2167cbf1c3db7ffdd9b7bb63d461f3b
Author: Andi Huber <ah...@apache.org>
AuthorDate: Wed Apr 13 20:47:20 2022 +0200
ISIS-3003: simplifies and fixes the fetcher
---
.../commandlog/model/command/CommandModel.java | 5 +++
.../jdo/ui/CommandReplayOnPrimaryService.java | 4 +-
.../ui/rest/CommandRetrievalOnPrimaryService.java | 34 ++++++++++----
.../secondary/fetch/CommandFetcher.java | 52 ++++++----------------
.../secondary/fetch/CommandFetcher_Test.java | 12 ++---
5 files changed, 53 insertions(+), 54 deletions(-)
diff --git a/extensions/core/command-log/applib/src/main/java/org/apache/isis/extensions/commandlog/model/command/CommandModel.java b/extensions/core/command-log/applib/src/main/java/org/apache/isis/extensions/commandlog/model/command/CommandModel.java
index 225b2f3b57..0011f1e078 100644
--- a/extensions/core/command-log/applib/src/main/java/org/apache/isis/extensions/commandlog/model/command/CommandModel.java
+++ b/extensions/core/command-log/applib/src/main/java/org/apache/isis/extensions/commandlog/model/command/CommandModel.java
@@ -27,6 +27,7 @@ import org.apache.isis.applib.services.commanddto.HasCommandDto;
import org.apache.isis.applib.util.ObjectContracts;
import org.apache.isis.applib.util.ToString;
import org.apache.isis.extensions.commandlog.model.IsisModuleExtCommandLogApplib;
+import org.apache.isis.schema.cmd.v2.CommandsDto;
public interface CommandModel
extends
@@ -85,4 +86,8 @@ extends
return this.getTimestamp().compareTo(other.getTimestamp());
}
+ static CommandsDto toDto(final CommandModel commandModel) {
+ return null;
+ }
+
}
diff --git a/extensions/core/command-log/jdo/src/main/java/org/apache/isis/extensions/commandlog/jdo/ui/CommandReplayOnPrimaryService.java b/extensions/core/command-log/jdo/src/main/java/org/apache/isis/extensions/commandlog/jdo/ui/CommandReplayOnPrimaryService.java
index fa5cae3d49..06c5d3e55c 100644
--- a/extensions/core/command-log/jdo/src/main/java/org/apache/isis/extensions/commandlog/jdo/ui/CommandReplayOnPrimaryService.java
+++ b/extensions/core/command-log/jdo/src/main/java/org/apache/isis/extensions/commandlog/jdo/ui/CommandReplayOnPrimaryService.java
@@ -111,10 +111,10 @@ public class CommandReplayOnPrimaryService {
@ParameterLayout(named="Batch size")
final Integer batchSize)
throws NotFoundException {
- return commandRetrievalOnPrimaryService.findCommandsOnPrimaryFrom(interactionId, batchSize);
+ return commandRetrievalOnPrimaryService.findCommandsOnPrimary(interactionId, batchSize);
}
@MemberSupport public Integer default1Act() {
- return commandRetrievalOnPrimaryService.default1FindCommandsOnPrimaryFrom();
+ return commandRetrievalOnPrimaryService.default1FindCommandsOnPrimaryAsDto();
}
}
diff --git a/extensions/core/command-log/jdo/src/main/java/org/apache/isis/extensions/commandlog/jdo/ui/rest/CommandRetrievalOnPrimaryService.java b/extensions/core/command-log/jdo/src/main/java/org/apache/isis/extensions/commandlog/jdo/ui/rest/CommandRetrievalOnPrimaryService.java
index 1f6593195f..54c8bb1092 100644
--- a/extensions/core/command-log/jdo/src/main/java/org/apache/isis/extensions/commandlog/jdo/ui/rest/CommandRetrievalOnPrimaryService.java
+++ b/extensions/core/command-log/jdo/src/main/java/org/apache/isis/extensions/commandlog/jdo/ui/rest/CommandRetrievalOnPrimaryService.java
@@ -20,6 +20,7 @@ package org.apache.isis.extensions.commandlog.jdo.ui.rest;
import java.util.List;
import java.util.UUID;
+import java.util.stream.Collectors;
import javax.inject.Inject;
import javax.inject.Named;
@@ -31,6 +32,8 @@ import org.apache.isis.applib.annotation.Action;
import org.apache.isis.applib.annotation.DomainService;
import org.apache.isis.applib.annotation.MemberSupport;
import org.apache.isis.applib.annotation.NatureOfService;
+import org.apache.isis.applib.annotation.Optionality;
+import org.apache.isis.applib.annotation.Parameter;
import org.apache.isis.applib.annotation.ParameterLayout;
import org.apache.isis.applib.annotation.PriorityPrecedence;
import org.apache.isis.applib.annotation.SemanticsOf;
@@ -38,6 +41,7 @@ import org.apache.isis.applib.exceptions.RecoverableException;
import org.apache.isis.extensions.commandlog.jdo.entities.CommandJdo;
import org.apache.isis.extensions.commandlog.model.IsisModuleExtCommandLogApplib;
import org.apache.isis.extensions.commandlog.model.command.CommandModelRepository;
+import org.apache.isis.schema.cmd.v2.CommandDto;
import lombok.Getter;
@@ -67,6 +71,7 @@ public class CommandRetrievalOnPrimaryService {
}
/**
+ * TODO: outdated info ...
* These actions should be called with HTTP Accept Header set to:
* <code>application/xml;profile="urn:org.restfulobjects:repr-types/action-result";x-ro-domain-type="org.apache.isis.schema.cmd.v1.CommandsDto"</code>
*
@@ -77,24 +82,35 @@ public class CommandRetrievalOnPrimaryService {
@Action(
domainEvent = FindCommandsOnPrimaryFromDomainEvent.class,
semantics = SemanticsOf.SAFE,
- typeOf = CommandJdo.class)
- public List<CommandJdo> findCommandsOnPrimaryFrom(
- @Nullable
+ typeOf = CommandDto.class)
+ public List<CommandDto> findCommandsOnPrimaryAsDto(
+
+ @Parameter(optionality = Optionality.OPTIONAL)
@ParameterLayout(named="Interaction Id")
final UUID interactionId,
- @Nullable
+
+ @Parameter(optionality = Optionality.OPTIONAL)
@ParameterLayout(named="Batch size")
- final Integer batchSize)
- throws NotFoundException {
+ final Integer batchSize) throws NotFoundException {
+
+ return findCommandsOnPrimary(interactionId, batchSize).stream()
+ .map(CommandJdo::getCommandDto)
+ .collect(Collectors.toList());
+ }
+ @MemberSupport public Integer default1FindCommandsOnPrimaryAsDto() {
+ return 25;
+ }
+
+ public List<CommandJdo> findCommandsOnPrimary(
+ final @Nullable UUID interactionId,
+ final @Nullable Integer batchSize) throws NotFoundException {
+
final List<CommandJdo> commands = commandModelRepository.findSince(interactionId, batchSize);
if(commands == null) {
throw new NotFoundException(interactionId);
}
return commands;
}
- @MemberSupport public Integer default1FindCommandsOnPrimaryFrom() {
- return 25;
- }
@Inject CommandModelRepository<CommandJdo> commandModelRepository;
}
diff --git a/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/fetch/CommandFetcher.java b/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/fetch/CommandFetcher.java
index 0cfa56d7f3..3fe2b9c010 100644
--- a/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/fetch/CommandFetcher.java
+++ b/extensions/core/command-replay/secondary/src/main/java/org/apache/isis/extensions/commandreplay/secondary/fetch/CommandFetcher.java
@@ -18,7 +18,6 @@
*/
package org.apache.isis.extensions.commandreplay.secondary.fetch;
-import java.util.Collections;
import java.util.List;
import java.util.UUID;
@@ -32,15 +31,13 @@ import org.springframework.stereotype.Service;
import org.apache.isis.applib.annotation.PriorityPrecedence;
import org.apache.isis.applib.client.SuppressionType;
-import org.apache.isis.applib.services.jaxb.JaxbService;
-import org.apache.isis.applib.services.jaxb.JaxbService.Simple;
+import org.apache.isis.commons.collections.Can;
import org.apache.isis.extensions.commandlog.model.IsisModuleExtCommandLogApplib;
import org.apache.isis.extensions.commandlog.model.command.CommandModel;
import org.apache.isis.extensions.commandreplay.secondary.config.SecondaryConfig;
import org.apache.isis.extensions.commandreplay.secondary.status.SecondaryStatus;
import org.apache.isis.extensions.commandreplay.secondary.status.StatusException;
import org.apache.isis.schema.cmd.v2.CommandDto;
-import org.apache.isis.schema.cmd.v2.CommandsDto;
import org.apache.isis.viewer.restfulobjects.client.RestfulClient;
import org.apache.isis.viewer.restfulobjects.client.RestfulClientConfig;
@@ -63,7 +60,7 @@ public class CommandFetcher {
static final String URL_SUFFIX =
"services/"
+ IsisModuleExtCommandLogApplib.SERVICE_REPLAY_PRIMARY_COMMAND_RETRIEVAL
- + "/actions/findCommandsOnPrimaryFrom/invoke";
+ + "/actions/findCommandsOnPrimaryAsDto/invoke";
private final SecondaryConfig secondaryConfig;
private final boolean useRequestDebugLogging;
@@ -79,16 +76,13 @@ public class CommandFetcher {
* @param previousHwmIfAny
* @throws StatusException
*/
- public List<CommandDto> fetchCommand(
+ public Can<CommandDto> fetchCommand(
final @Nullable CommandModel previousHwmIfAny)
throws StatusException {
log.debug("finding command on primary ...");
- final CommandsDto commandsDto = fetchCommands(previousHwmIfAny);
- return commandsDto != null
- ? commandsDto.getCommandDto()
- : Collections.emptyList();
+ return fetchCommands(previousHwmIfAny);
}
/**
@@ -96,26 +90,23 @@ public class CommandFetcher {
* @param previousHwmIfAny
* @throws StatusException
*/
- private CommandsDto fetchCommands(final CommandModel previousHwmIfAny)
+ private Can<CommandDto> fetchCommands(final CommandModel previousHwmIfAny)
throws StatusException {
- final UUID transactionId = previousHwmIfAny != null ? previousHwmIfAny.getInteractionId() : null;
+ final UUID transactionId = previousHwmIfAny != null
+ ? previousHwmIfAny.getInteractionId()
+ : null;
log.debug("finding commands on primary ...");
- final CommandsDto commandsDto = callPrimary(transactionId);
-
- final int size = commandsDto.getCommandDto().size();
- if(size == 0) {
- return null;
- }
- return commandsDto;
+ val commands = callPrimary(transactionId);
+ return commands;
}
// package private in support of JUnit
- CommandsDto callPrimary(final @Nullable UUID interactionId) throws StatusException {
+ Can<CommandDto> callPrimary(final @Nullable UUID interactionId) throws StatusException {
- val client = newClient(secondaryConfig, useRequestDebugLogging );
+ val client = newClient(secondaryConfig, useRequestDebugLogging);
val request = client.request(
URL_SUFFIX,
SuppressionType.RO);
@@ -126,29 +117,14 @@ public class CommandFetcher {
.build();
final Response response = request.post(args);
- val digest = client.digestList(response, CommandModel.class, new GenericType<List<CommandModel>>(){})
+ val digest = client.digestList(response, CommandDto.class, new GenericType<List<CommandDto>>(){})
.mapFailure(failure->{
log.warn("rest call failed", failure);
return new StatusException(SecondaryStatus.REST_CALL_FAILING);
})
.ifFailureFail();
- System.err.printf("%s%n", digest.getValue());
-
- return null;//unmarshal(digest.getValue().orElse("<unable to read from response entity>"), endpointUri);
- }
-
- private CommandsDto unmarshal(final String rawValue, final String endpointUri) throws StatusException {
- CommandsDto commandsDto;
- try {
- final JaxbService jaxbService = new Simple();
- commandsDto = jaxbService.fromXml(CommandsDto.class, rawValue);
- log.debug("commands:\n{}", rawValue);
- } catch(Exception ex) {
- log.warn("unable to unmarshal entity from {} to CommandsDto.class; was:\n{}", endpointUri, rawValue);
- throw new StatusException(SecondaryStatus.FAILED_TO_UNMARSHALL_RESPONSE, ex);
- }
- return commandsDto;
+ return digest.getValue().orElseThrow();
}
private static RestfulClient newClient(
diff --git a/extensions/core/command-replay/secondary/src/test/java/org/apache/isis/extensions/commandreplay/secondary/fetch/CommandFetcher_Test.java b/extensions/core/command-replay/secondary/src/test/java/org/apache/isis/extensions/commandreplay/secondary/fetch/CommandFetcher_Test.java
index b6ae1c3472..f5a5c82e87 100644
--- a/extensions/core/command-replay/secondary/src/test/java/org/apache/isis/extensions/commandreplay/secondary/fetch/CommandFetcher_Test.java
+++ b/extensions/core/command-replay/secondary/src/test/java/org/apache/isis/extensions/commandreplay/secondary/fetch/CommandFetcher_Test.java
@@ -26,12 +26,12 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.TestPropertySource;
-import org.apache.isis.applib.util.JaxbUtil;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
import org.apache.isis.core.config.presets.IsisPresets;
import org.apache.isis.core.metamodel._testing.MetaModelContext_forTesting;
import org.apache.isis.extensions.commandreplay.secondary.config.SecondaryConfig;
import org.apache.isis.extensions.commandreplay.secondary.status.StatusException;
-import org.apache.isis.schema.cmd.v2.CommandsDto;
import lombok.val;
import lombok.extern.log4j.Log4j2;
@@ -77,8 +77,10 @@ class CommandFetcher_Test {
// when
log.info("about to call REST endpoint ...");
- final CommandsDto entity = fetcher.callPrimary(null);
-
- System.out.println(JaxbUtil.toXml(entity));
+ val commands = fetcher.callPrimary(null);
+ assertNotNull(commands);
+ System.out.println(commands);
}
+
+
}