-
Notifications
You must be signed in to change notification settings - Fork 215
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#1228] moved restoration from connectivity command headers from Ackn…
…owledgementAggregatorActor.restoreCommandConnectivityHeaders to own utility class CommandHeaderRestoration and also used in ThingCommandEnforcement Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch.io>
- Loading branch information
Showing
12 changed files
with
105 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...gnal/src/main/java/org/eclipse/ditto/internal/models/signal/CommandHeaderRestoration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (c) 2021 Contributors to the Eclipse Foundation | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information regarding copyright ownership. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.eclipse.ditto.internal.models.signal; | ||
|
||
import org.eclipse.ditto.base.model.headers.DittoHeaderDefinition; | ||
import org.eclipse.ditto.base.model.headers.DittoHeaders; | ||
import org.eclipse.ditto.base.model.headers.DittoHeadersSettable; | ||
|
||
/** | ||
* Helpers for restoring command headers, e.g. for connectivity. | ||
*/ | ||
public final class CommandHeaderRestoration { | ||
|
||
private CommandHeaderRestoration() { | ||
throw new AssertionError(); | ||
} | ||
|
||
/** | ||
* Restores the connectivity relevant headers for commands and/or command responses. | ||
* | ||
* @param signal the signal to adjust the headers in. | ||
* @param headersToRestoreFrom the original headers to restore connectivity headers from. | ||
* @return the potentially adjusted signal with restored connectivity headers. | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public static <T extends DittoHeadersSettable<?>> T restoreCommandConnectivityHeaders( | ||
final DittoHeadersSettable<?> signal, | ||
final DittoHeaders headersToRestoreFrom) { | ||
|
||
final var signalDittoHeaders = signal.getDittoHeaders(); | ||
final var enhancedHeadersBuilder = signalDittoHeaders.toBuilder() | ||
.removeHeader(DittoHeaderDefinition.EXPECTED_RESPONSE_TYPES.getKey()) | ||
.removeHeader(DittoHeaderDefinition.INBOUND_PAYLOAD_MAPPER.getKey()) | ||
.removeHeader(DittoHeaderDefinition.REPLY_TARGET.getKey()); | ||
if (headersToRestoreFrom.containsKey(DittoHeaderDefinition.EXPECTED_RESPONSE_TYPES.getKey())) { | ||
enhancedHeadersBuilder.expectedResponseTypes(headersToRestoreFrom.getExpectedResponseTypes()); | ||
} | ||
headersToRestoreFrom.getInboundPayloadMapper().ifPresent(enhancedHeadersBuilder::inboundPayloadMapper); | ||
headersToRestoreFrom.getReplyTarget().ifPresent(enhancedHeadersBuilder::replyTarget); | ||
|
||
return (T) signal.setDittoHeaders(enhancedHeadersBuilder.build()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.