Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add basic level policy support to Ditto Java Client #46

Merged
merged 43 commits into from Mar 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
bab3f28
Add PolicyHandle Interface
VadimGue Nov 28, 2019
f625897
Add policies structure
VadimGue Dec 3, 2019
8353f8b
Implement policy handle
VadimGue Dec 4, 2019
3b1d935
Add PolicyHandle for things
VadimGue Dec 10, 2019
ced609b
Add Unit-Test for policies
VadimGue Dec 10, 2019
447219b
Add inline policy and unit tests
VadimGue Dec 16, 2019
7fc8293
Add initial policy via options
VadimGue Jan 8, 2020
1532ad2
Add inline policy for put and update
VadimGue Jan 9, 2020
10c00f0
Add Unit-Tests
VadimGue Jan 9, 2020
4f8ce1b
Remove processing of options at thing modify
VadimGue Jan 29, 2020
f491391
Fix mapping of create thing command with inline policy
VadimGue Feb 3, 2020
115ee4f
add missing license header
dguggemos Feb 5, 2020
b4b3d52
Merge branch 'master' into 'feature/policy-protocol'
VadimGue Feb 11, 2020
afa0875
fix incorrect call to Thing instead of Policy implementation
ffendt Feb 17, 2020
2529108
Add policy path
VadimGue Feb 18, 2020
f39b639
Merge branch 'feature/policy-protocol' of https://products.bosch-si.c…
VadimGue Feb 18, 2020
feb960a
Fix test
VadimGue Feb 18, 2020
325cd90
Include ditto-signals-commands-policies to assembly.xlm for OSGi comp…
VadimGue Feb 18, 2020
ef89c0e
remove possibility to add initialPolicy in the "update"-methods of a …
ffendt Feb 20, 2020
844f365
restructure the code to create a Thing with an inline Policy or a cop…
ffendt Feb 20, 2020
13420cd
remove unused methods and provide the correct return types in Outgoin…
ffendt Feb 20, 2020
7ec1d70
fix wrongly set allowExists parameter
ffendt Feb 20, 2020
7da9ccf
use the existing Option visitor pattern to process the copyPolicy opt…
ffendt Feb 20, 2020
45185f1
Add ModifyPolicyId to the protocol adapter
ffendt Feb 21, 2020
c470695
Fix some warnings e.g. using specific command instead of unspecific T…
ffendt Feb 21, 2020
2909392
Default to schemaVersion V2 for outgoing Policy commands
ffendt Feb 21, 2020
159437b
Implement response handling for Policy commands
VadimGue Feb 21, 2020
17bf51d
Merge branch 'feature/policy-protocol' of https://products.bosch-si.c…
VadimGue Feb 21, 2020
2cdf5c8
Remove unsupported Policy features
VadimGue Feb 21, 2020
983c709
Fix failing ClientShutdownTest when running after RunOSGiContainerInt…
ffendt Feb 24, 2020
4f246ba
Try to simply some parts and get rid of most raw uses of parameterize…
ffendt Feb 24, 2020
a48c6fe
Increase code coverage for new policies code by verifying correct res…
ffendt Feb 24, 2020
4480f04
Add possibility do define a MessagingProvider for policy features.
ffendt Feb 25, 2020
41d8057
add @since 1.1.0 annotations where missing
ffendt Feb 25, 2020
a33ae6a
Add policy example
VadimGue Feb 25, 2020
2df3748
make policy example more fluent
dguggemos Feb 27, 2020
84b3c3b
Merge branch 'master' into 'feature/policy-protocol'
VadimGue Feb 27, 2020
5f177f7
Add additional possibility to create thing with Policy object
VadimGue Mar 4, 2020
446e072
Fix some findings
VadimGue Mar 5, 2020
5217b27
Fix version annotation
VadimGue Mar 5, 2020
6e1996d
add missing argument not null assertions and update binary compatibil…
ffendt Mar 16, 2020
4e6ecdc
revert updating binary compatibility check version to 1.1.0-M2 as the…
ffendt Mar 16, 2020
7cc1b8b
use github action checkout@v2 to fix bug "fatal: reference is not a t…
ffendt Mar 17, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/maven.yml
Expand Up @@ -23,7 +23,7 @@ jobs:
java: [ '1.8' ]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- name: set up JDK ${{ matrix.java }}
uses: actions/setup-java@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Expand Up @@ -24,7 +24,7 @@ jobs:
node-version: [10.x, 12.x]

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
Expand Down
13 changes: 13 additions & 0 deletions java/README.md
Expand Up @@ -98,6 +98,19 @@ client.twin().create("org.eclipse.ditto:new-thing").handle((createdThing, throwa
}).get(); // this will block the thread! work asynchronously whenever possible!
```

#### Manage policies

```java
client.policies().create(newPolicy)
.thenAccept(createdPolicy -> System.out.println("Created new Policy: " + createdPolicy)).get();

client.twin()
.forId(ThingId.of("org.eclipse.ditto:new-thing"))
.setPolicyId(newPolicy.getEntityId().get())
.thenAccept(_void -> System.out.println("PolicyId was adapted"))
.get();
```

#### Subscribe for change notifications

```java
Expand Down
1 change: 1 addition & 0 deletions java/src/main/assembly/assembly.xml
Expand Up @@ -41,6 +41,7 @@
<include>org.eclipse.ditto:ditto-signals-base</include>
<include>org.eclipse.ditto:ditto-signals-commands-base</include>
<include>org.eclipse.ditto:ditto-signals-commands-things</include>
<include>org.eclipse.ditto:ditto-signals-commands-policies</include>
<include>org.eclipse.ditto:ditto-signals-commands-messages</include>
<include>org.eclipse.ditto:ditto-signals-commands-live</include>
<include>org.eclipse.ditto:ditto-signals-events-base</include>
Expand Down
9 changes: 9 additions & 0 deletions java/src/main/java/org/eclipse/ditto/client/DittoClient.java
Expand Up @@ -15,6 +15,7 @@
import java.util.concurrent.CompletableFuture;

import org.eclipse.ditto.client.live.Live;
import org.eclipse.ditto.client.policies.Policies;
import org.eclipse.ditto.client.twin.Twin;
import org.eclipse.ditto.protocoladapter.Adaptable;

Expand Down Expand Up @@ -56,4 +57,12 @@ public interface DittoClient {
*/
CompletableFuture<Adaptable> sendDittoProtocol(Adaptable dittoProtocolAdaptable);

/**
* Returns the client's {@link Policies} singleton which provides the necessary functionality to manage and monitor
* {@link org.eclipse.ditto.model.policies.Policy}s.
*
* @return the Policy handle
* @since 1.1.0
*/
Policies policies();
}
48 changes: 43 additions & 5 deletions java/src/main/java/org/eclipse/ditto/client/DittoClients.java
Expand Up @@ -66,11 +66,28 @@ public static DittoClient newInstance(final MessagingProvider messagingProvider)
public static DittoClient newInstance(final MessagingProvider twinMessagingProvider,
final MessagingProvider liveMessagingProvider) {

final ResponseForwarder responseForwarder = ResponseForwarder.getInstance();
return newInstance(twinMessagingProvider, liveMessagingProvider, twinMessagingProvider);
}

/**
* Creates a new {@link org.eclipse.ditto.client.DittoClient} with a specific {@code Twin} and {@code Live}
* {@link org.eclipse.ditto.client.messaging.MessagingProvider}.
*
* @param twinMessagingProvider the messaging provider for the {@code Twin} part of the client.
* @param liveMessagingProvider the messaging provider for the {@code Live} part of the client.
* @param policyMessagingProvider the messaging provider for the {@code Policy} part of the client.
* @return the client.
* @throws org.eclipse.ditto.client.messaging.AuthenticationException if authentication failed.
* @throws org.eclipse.ditto.client.messaging.MessagingException if a connection to the configured endpoint
* could not be established
* @since 1.1.0
*/
public static DittoClient newInstance(final MessagingProvider twinMessagingProvider,
final MessagingProvider liveMessagingProvider, final MessagingProvider policyMessagingProvider) {

final MessageSerializerRegistry messageSerializerRegistry =
MessageSerializerFactory.newInstance().getMessageSerializerRegistry();
return DefaultDittoClient.newInstance(twinMessagingProvider, liveMessagingProvider, responseForwarder,
messageSerializerRegistry);
return newInstance(twinMessagingProvider, liveMessagingProvider, policyMessagingProvider, messageSerializerRegistry);
}

/**
Expand All @@ -88,9 +105,30 @@ public static DittoClient newInstance(final MessagingProvider twinMessagingProvi
public static DittoClient newInstance(final MessagingProvider twinMessagingProvider,
final MessagingProvider liveMessagingProvider, final MessageSerializerRegistry messageSerializerRegistry) {

return newInstance(twinMessagingProvider, liveMessagingProvider, twinMessagingProvider, messageSerializerRegistry);
}

/**
* Creates a new {@link org.eclipse.ditto.client.DittoClient} with a specific {@code Twin}, {@code Live} and
* {@code Policy} {@link org.eclipse.ditto.client.messaging.MessagingProvider}.
*
* @param twinMessagingProvider the messaging provider for the {@code Twin} part of the client.
* @param liveMessagingProvider the messaging provider for the {@code Live} part of the client.
* @param policyMessagingProvider the messaging provider for the {@code Policy} part of the client.
* @param messageSerializerRegistry a registry of {@code MessageSerializer}s for the {@code Live} part of the client.
* @return the client.
* @throws org.eclipse.ditto.client.messaging.AuthenticationException if authentication failed.
* @throws org.eclipse.ditto.client.messaging.MessagingException if a connection to the configured endpoint
* could not be established
* @since 1.1.0
*/
public static DittoClient newInstance(final MessagingProvider twinMessagingProvider,
final MessagingProvider liveMessagingProvider, final MessagingProvider policyMessagingProvider,
final MessageSerializerRegistry messageSerializerRegistry) {

final ResponseForwarder responseForwarder = ResponseForwarder.getInstance();
return DefaultDittoClient.newInstance(twinMessagingProvider, liveMessagingProvider, responseForwarder,
messageSerializerRegistry);
return DefaultDittoClient.newInstance(twinMessagingProvider, liveMessagingProvider, policyMessagingProvider,
responseForwarder, messageSerializerRegistry);
}

}
Expand Up @@ -87,7 +87,7 @@ private static final class WebSocketMessagingConfigurationBuilder implements Mes
private boolean reconnectEnabled = true;
private ProxyConfiguration proxyConfiguration;
private TrustStoreConfiguration trustStoreConfiguration;

@Override
public MessagingConfiguration.Builder jsonSchemaVersion(final JsonSchemaVersion jsonSchemaVersion) {
this.jsonSchemaVersion = checkNotNull(jsonSchemaVersion, "jsonSchemaVersion");
Expand Down