-
Notifications
You must be signed in to change notification settings - Fork 216
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Extension to determine default namespace for entity creation
* Moved logic out of model. Handling of resolving the default namespace is only relevant in edge services and from then on the namespace counts as resolved Signed-off-by: Yannic Klem <Yannic.Klem@bosch.io>
- Loading branch information
Showing
13 changed files
with
194 additions
and
130 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
60 changes: 60 additions & 0 deletions
60
edge/api/src/main/java/org/eclipse/ditto/edge/api/dispatching/DefaultNamespaceProvider.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,60 @@ | ||
/* | ||
* Copyright (c) 2022 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.edge.api.dispatching; | ||
|
||
import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull; | ||
|
||
import org.eclipse.ditto.base.service.DittoExtensionPoint; | ||
import org.eclipse.ditto.policies.model.signals.commands.modify.CreatePolicy; | ||
import org.eclipse.ditto.things.model.signals.commands.modify.CreateThing; | ||
|
||
import akka.actor.ActorSystem; | ||
|
||
/** | ||
* Determines the default namespace based on the given signal. | ||
*/ | ||
public interface DefaultNamespaceProvider extends DittoExtensionPoint { | ||
|
||
/** | ||
* @param createThing The command that requires a default namespace. | ||
* @return The default namespace. | ||
*/ | ||
String getDefaultNamespace(CreateThing createThing); | ||
|
||
/** | ||
* @param createPolicy The command that requires a default namespace. | ||
* @return The default namespace. | ||
*/ | ||
String getDefaultNamespace(CreatePolicy createPolicy); | ||
|
||
static DefaultNamespaceProvider get(final ActorSystem actorSystem) { | ||
checkNotNull(actorSystem, "actorSystem"); | ||
return ExtensionId.INSTANCE.get(actorSystem); | ||
} | ||
|
||
final class ExtensionId extends DittoExtensionPoint.ExtensionId<DefaultNamespaceProvider> { | ||
|
||
private static final String CONFIG_PATH = "ditto.entity-creation.default-namespace-provider"; | ||
private static final ExtensionId INSTANCE = new ExtensionId(DefaultNamespaceProvider.class); | ||
|
||
private ExtensionId(final Class<DefaultNamespaceProvider> parentClass) { | ||
super(parentClass); | ||
} | ||
|
||
@Override | ||
protected String getConfigPath() { | ||
return CONFIG_PATH; | ||
} | ||
|
||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
.../src/main/java/org/eclipse/ditto/edge/api/dispatching/StaticDefaultNamespaceProvider.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,44 @@ | ||
/* | ||
* Copyright (c) 2022 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.edge.api.dispatching; | ||
|
||
import org.eclipse.ditto.internal.utils.config.DefaultScopedConfig; | ||
import org.eclipse.ditto.policies.enforcement.config.DefaultEntityCreationConfig; | ||
import org.eclipse.ditto.policies.enforcement.config.EntityCreationConfig; | ||
import org.eclipse.ditto.policies.model.signals.commands.modify.CreatePolicy; | ||
import org.eclipse.ditto.things.model.signals.commands.modify.CreateThing; | ||
|
||
import akka.actor.ActorSystem; | ||
|
||
public final class StaticDefaultNamespaceProvider implements DefaultNamespaceProvider { | ||
|
||
private final String defaultNamespace; | ||
|
||
public StaticDefaultNamespaceProvider(final ActorSystem actorSystem) { | ||
final EntityCreationConfig entityCreationConfig = DefaultEntityCreationConfig.of( | ||
DefaultScopedConfig.dittoScoped(actorSystem.settings().config()) | ||
); | ||
defaultNamespace = entityCreationConfig.getDefaultNamespace(); | ||
} | ||
|
||
@Override | ||
public String getDefaultNamespace(final CreateThing createThing) { | ||
return defaultNamespace; | ||
} | ||
|
||
@Override | ||
public String getDefaultNamespace(final CreatePolicy createPolicy) { | ||
return defaultNamespace; | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,2 +1,4 @@ | ||
ditto.entity-creation.default-namespace-provider = org.eclipse.ditto.edge.api.dispatching.StaticDefaultNamespaceProvider | ||
ditto.entity-creation.default-namespace-provider = ${?DITTO_DEFAULT_NAMESPACE_PROVIDER} | ||
ditto.edge-command-forwarder-extension = org.eclipse.ditto.edge.api.dispatching.NoOpEdgeCommandForwarderExtension | ||
ditto.edge-command-forwarder-extension = ${?DITTO_EDGE_COMMAND_FORWARDER_EXTENSION} |
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
Oops, something went wrong.