Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor validation of connectivity commands to be extensible
Signed-off-by: Dominik Guggemos <dominik.guggemos@bosch-si.com>
- Loading branch information
Showing
10 changed files
with
277 additions
and
52 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
37 changes: 37 additions & 0 deletions
37
...to/services/connectivity/messaging/validation/CompoundConnectivityCommandInterceptor.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,37 @@ | ||
/* | ||
* Copyright (c) 2017 Bosch Software Innovations GmbH. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/org/documents/epl-2.0/index.php | ||
* Contributors: | ||
* Bosch Software Innovations GmbH - initial contribution | ||
* | ||
*/ | ||
package org.eclipse.ditto.services.connectivity.messaging.validation; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.function.Consumer; | ||
|
||
import org.eclipse.ditto.signals.commands.connectivity.ConnectivityCommand; | ||
import org.eclipse.ditto.signals.commands.connectivity.ConnectivityCommandInterceptor; | ||
|
||
/** | ||
* Accepts multiple {@link ConnectivityCommandInterceptor}s and simply executes all of them. | ||
*/ | ||
public class CompoundConnectivityCommandInterceptor implements ConnectivityCommandInterceptor { | ||
|
||
private final Collection<Consumer<ConnectivityCommand<?>>> validators; | ||
|
||
@SafeVarargs | ||
public CompoundConnectivityCommandInterceptor(final Consumer<ConnectivityCommand<?>>... validators) { | ||
this.validators = Arrays.asList(validators); | ||
} | ||
|
||
@Override | ||
public void accept(final ConnectivityCommand<?> command) { | ||
validators.forEach(c -> c.accept(command)); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...e/ditto/services/connectivity/messaging/validation/DittoConnectivityCommandValidator.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,52 @@ | ||
/* | ||
* Copyright (c) 2017 Bosch Software Innovations GmbH. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v2.0 | ||
* which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/org/documents/epl-2.0/index.php | ||
* Contributors: | ||
* Bosch Software Innovations GmbH - initial contribution | ||
* | ||
*/ | ||
package org.eclipse.ditto.services.connectivity.messaging.validation; | ||
|
||
import org.eclipse.ditto.model.connectivity.Connection; | ||
import org.eclipse.ditto.services.connectivity.messaging.ConnectionActorPropsFactory; | ||
import org.eclipse.ditto.signals.commands.connectivity.ConnectivityCommand; | ||
import org.eclipse.ditto.signals.commands.connectivity.ConnectivityCommandInterceptor; | ||
import org.eclipse.ditto.signals.commands.connectivity.modify.CreateConnection; | ||
import org.eclipse.ditto.signals.commands.connectivity.modify.ModifyConnection; | ||
import org.eclipse.ditto.signals.commands.connectivity.modify.TestConnection; | ||
|
||
import akka.actor.ActorRef; | ||
|
||
/** | ||
* Checks if the given {@link ConnectivityCommand} is valid by trying to create the client actor props. | ||
*/ | ||
public class DittoConnectivityCommandValidator implements ConnectivityCommandInterceptor { | ||
|
||
private final ConnectionActorPropsFactory propsFactory; | ||
private final ActorRef conciergeForwarder; | ||
|
||
public DittoConnectivityCommandValidator( | ||
final ConnectionActorPropsFactory propsFactory, final ActorRef conciergeForwarder) { | ||
this.propsFactory = propsFactory; | ||
this.conciergeForwarder = conciergeForwarder; | ||
} | ||
|
||
@Override | ||
public void accept(final ConnectivityCommand<?> command) { | ||
switch (command.getType()) { | ||
case CreateConnection.TYPE: | ||
case TestConnection.TYPE: | ||
case ModifyConnection.TYPE: | ||
final Connection connection = getConnectionFromCommand(command); | ||
if (connection != null) { | ||
propsFactory.getActorPropsForType(connection, conciergeForwarder); | ||
} | ||
break; | ||
default: //nothing to validate for other commands | ||
} | ||
} | ||
} |
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
Oops, something went wrong.