Skip to content

Commit

Permalink
refactor duplicate message template;
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Maute <stefan.maute@bosch.io>
  • Loading branch information
Stefan Maute committed Oct 21, 2021
1 parent 6d0e231 commit 76e988a
Showing 1 changed file with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ private static Optional<MessageSendingFailedException> validateTypesMatch(final
final var semanticCommandResponseType = SemanticSignalType.parseSemanticSignalType(commandResponseType);
final var semanticCommandType = SemanticSignalType.parseSemanticSignalType(command.getType());
if (!isSameSignalDomain(semanticCommandType, semanticCommandResponseType)) {
final var pattern = "Type of live response <{0}> is not related to type of command <{1}>.";
detailMessage = MessageFormat.format(pattern, commandResponseType, command.getType());
detailMessage = messageFormatForLiveResponseNotRelatedToTypeOfCommand(commandResponseType, command);
}
else if (isMessagesSignalDomain(semanticCommandResponseType)) {
if (!areCorrespondingMessageSignals(command.getName(), commandResponse.getName())) {
Expand All @@ -148,13 +147,19 @@ else if (isMessagesSignalDomain(semanticCommandResponseType)) {
detailMessage = MessageFormat.format(pattern, commandResponse.getType(), command.getType());
}
} else if (!isEqualNames(command, commandResponse)) {
final var pattern = "Type of live response <{0}> is not related to type of command <{1}>.";
detailMessage = MessageFormat.format(pattern, commandResponseType, command.getType());
detailMessage = messageFormatForLiveResponseNotRelatedToTypeOfCommand(commandResponseType, command);
}

return Optional.ofNullable(detailMessage).map(toMessageSendingFailedException(command.getDittoHeaders()));
}

private static String messageFormatForLiveResponseNotRelatedToTypeOfCommand(final String commandResponseType,
final SignalWithEntityId<?> command) {
final var pattern = "Type of live response <{0}> is not related to type of command <{1}>.";

return MessageFormat.format(pattern, commandResponseType, command.getType());
}

private static boolean isAcknowledgement(final CommandResponse<?> commandResponse) {
return Acknowledgement.TYPE.equals(commandResponse.getType());
}
Expand Down

0 comments on commit 76e988a

Please sign in to comment.