Skip to content

Commit

Permalink
Merge pull request eclipse-ditto#9 from bosch-iot-things/feature/remo…
Browse files Browse the repository at this point in the history
…ve-api-1

Feature/remove api 1
  • Loading branch information
Bartelheimer Joel authored and GitHub Enterprise committed Mar 8, 2021
2 parents 22ebcbf + a42d34b commit 3b5a011
Show file tree
Hide file tree
Showing 15 changed files with 29 additions and 291 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@

package org.eclipse.ditto.client.internal;

import static org.eclipse.ditto.client.internal.BusAddressPatterns.ACL_ENTRY_PATTERN;
import static org.eclipse.ditto.client.internal.BusAddressPatterns.ACL_PATTERN;
import static org.eclipse.ditto.client.internal.BusAddressPatterns.ATTRIBUTES_PATTERN;
import static org.eclipse.ditto.client.internal.BusAddressPatterns.ATTRIBUTE_PATTERN;
import static org.eclipse.ditto.client.internal.BusAddressPatterns.DEFINITION_PATTERN;
Expand Down Expand Up @@ -48,26 +46,6 @@ static String forThing(final ThingId thingId) {
return THING_PATTERN.format(thingId);
}

/**
* @param thingId the thingId that is part of the pattern
* @return bus pattern for the acl resource
* @deprecated Permissions belong to deprecated API version 1. Use API version 2 with policies instead.
*/
@Deprecated
static String forAcl(final ThingId thingId) {
return ACL_PATTERN.format(thingId);
}

/**
* @param thingId the thingId that is part of the pattern
* @return bus pattern for the acl entry resource
* @deprecated Permissions belong to deprecated API version 1. Use API version 2 with policies instead.
*/
@Deprecated
static String forAclEntry(final ThingId thingId, final String subjectId) {
return ACL_ENTRY_PATTERN.format(thingId, subjectId);
}

/**
* @param thingId the thingId that is part of the pattern
* @return bus pattern for the thing definition resource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
enum BusAddressPatterns {

THING_PATTERN("/things/{0}"),
ACL_PATTERN("/things/{0}/acl"),
ACL_ENTRY_PATTERN("/things/{0}/acl/{1}"),
ATTRIBUTES_PATTERN("/things/{0}/attributes"),
ATTRIBUTE_PATTERN("/things/{0}/attributes{1}"),
DEFINITION_PATTERN("/things/{0}/definition"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,6 @@
import org.eclipse.ditto.signals.acks.base.Acknowledgement;
import org.eclipse.ditto.signals.base.Signal;
import org.eclipse.ditto.signals.commands.base.ErrorResponse;
import org.eclipse.ditto.signals.events.things.AclEntryCreated;
import org.eclipse.ditto.signals.events.things.AclEntryDeleted;
import org.eclipse.ditto.signals.events.things.AclEntryModified;
import org.eclipse.ditto.signals.events.things.AclModified;
import org.eclipse.ditto.signals.events.things.AttributeCreated;
import org.eclipse.ditto.signals.events.things.AttributeDeleted;
import org.eclipse.ditto.signals.events.things.AttributeModified;
Expand Down Expand Up @@ -230,13 +226,6 @@ private static PoliciesImpl configurePolicyClient(final MessagingProvider messag
private static OutgoingMessageFactory getOutgoingMessageFactoryForPolicies(
final MessagingProvider messagingProvider) {
final JsonSchemaVersion schemaVersion = messagingProvider.getMessagingConfiguration().getJsonSchemaVersion();
if (JsonSchemaVersion.V_1.equals(schemaVersion)) {
LOGGER.warn("The MessagingProvider was configured with JsonSchemaVersion V_1 which is invalid for policy" +
" commands. Therefore defaulting to V_2 for all policy commands." +
" Please consider upgrading to JsonSchemaVersion V_2 as V_1 is deprecated and will be removed" +
" in an upcoming release.");
return OutgoingMessageFactory.newInstance(JsonSchemaVersion.V_2);
}
return OutgoingMessageFactory.newInstance(schemaVersion);
}

Expand Down Expand Up @@ -331,48 +320,6 @@ private static void registerKeyBasedHandlersForIncomingEvents(final PointerBus b
emitAcknowledgement)
);

/*
* ACL - v1 only
* @deprecated as part of deprecated API 1
*/
SelectorUtil.addHandlerForThingEvent(LOGGER, bus, AclModified.TYPE, AclModified.class,
e -> BusAddressFactory.forAcl(e.getThingEntityId()),
(e, extra) -> new ImmutableChange(e.getThingEntityId(), ChangeAction.UPDATED,
JsonPointer.empty(),
e.getAccessControlList().toJson(e.getImplementedSchemaVersion()),
e.getRevision(), e.getTimestamp().orElse(null), extra, e.getDittoHeaders(),
emitAcknowledgement)
);

SelectorUtil.addHandlerForThingEvent(LOGGER, bus, AclEntryCreated.TYPE, AclEntryCreated.class,
e -> BusAddressFactory.forAclEntry(e.getThingEntityId(),
e.getAclEntry().getAuthorizationSubject().getId()),
(e, extra) -> new ImmutableChange(e.getThingEntityId(), ChangeAction.CREATED,
JsonPointer.empty(),
e.getAclEntry().toJson(e.getImplementedSchemaVersion()),
e.getRevision(), e.getTimestamp().orElse(null), extra, e.getDittoHeaders(),
emitAcknowledgement)
);

SelectorUtil.addHandlerForThingEvent(LOGGER, bus, AclEntryModified.TYPE, AclEntryModified.class,
e -> BusAddressFactory.forAclEntry(e.getThingEntityId(),
e.getAclEntry().getAuthorizationSubject().getId()),
(e, extra) -> new ImmutableChange(e.getThingEntityId(), ChangeAction.UPDATED,
JsonPointer.empty(),
e.getAclEntry().toJson(e.getImplementedSchemaVersion()),
e.getRevision(), e.getTimestamp().orElse(null), extra, e.getDittoHeaders(),
emitAcknowledgement)
);

SelectorUtil.addHandlerForThingEvent(LOGGER, bus, AclEntryDeleted.TYPE, AclEntryDeleted.class,
e -> BusAddressFactory.forAclEntry(e.getThingEntityId(), e.getAuthorizationSubject().getId()),
(e, extra) -> new ImmutableChange(e.getThingEntityId(), ChangeAction.DELETED,
JsonPointer.empty(),
null,
e.getRevision(), e.getTimestamp().orElse(null), extra, e.getDittoHeaders(),
emitAcknowledgement)
);

/*
* Attributes
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,6 @@
*/
public final class OutgoingMessageFactory {

private static final Logger LOGGER = LoggerFactory.getLogger(OutgoingMessageFactory.class);

private static final EntityTagMatchers ASTERISK =
EntityTagMatchers.fromList(Collections.singletonList(EntityTagMatcher.asterisk()));

Expand Down Expand Up @@ -122,8 +120,6 @@ public static OutgoingMessageFactory newInstance(final JsonSchemaVersion jsonSch
*/
public CreateThing createThing(final Thing thing, @Nullable JsonObject initialPolicy,
final Option<?>... options) {
logWarningsForAclPolicyUsage(thing);

validateOptions(initialPolicy, options);

final DittoHeaders dittoHeaders = buildDittoHeaders(false, options);
Expand All @@ -150,8 +146,6 @@ public ModifyThing putThing(final Thing thing, @Nullable final JsonObject initia
checkNotNull(thing, "thing");
final ThingId thingId = thing.getEntityId().orElseThrow(() -> new IllegalArgumentException("Thing had no ID!"));

logWarningsForAclPolicyUsage(thing);

validateOptions(initialPolicy, options);

final DittoHeaders dittoHeaders = buildDittoHeaders(true, options);
Expand All @@ -176,8 +170,6 @@ public ModifyThing updateThing(final Thing thing, final Option<?>... options) {
checkNotNull(thing, "thing");
final ThingId thingId = thing.getEntityId().orElseThrow(() -> new IllegalArgumentException("Thing had no ID!"));

logWarningsForAclPolicyUsage(thing);

final DittoHeaders headersWithoutIfMatch = buildDittoHeaders(false, options);
final DittoHeaders headers = headersWithoutIfMatch.toBuilder()
.ifMatch(ASTERISK)
Expand All @@ -197,7 +189,6 @@ public ModifyThing updateThing(final Thing thing, final Option<?>... options) {
*/
MergeThing mergeThing(final ThingId thingId, final Thing thing, final Option<?>[] options) {
checkNotNull(thing, "thing");
logWarningsForAclPolicyUsage(thing);

final DittoHeaders headersWithoutIfMatch = buildDittoHeaders(false, options);
final DittoHeaders headers = headersWithoutIfMatch.toBuilder()
Expand All @@ -207,19 +198,6 @@ MergeThing mergeThing(final ThingId thingId, final Thing thing, final Option<?>[
return MergeThing.withThing(thingId, thing, headers);
}

private void logWarningsForAclPolicyUsage(final Thing thing) {
if (jsonSchemaVersion == JsonSchemaVersion.V_1 && thing.getPolicyEntityId().isPresent()) {
LOGGER.warn("Creating/modifying a Thing with a defined 'policyId' when client was configured to use " +
"Ditto Protocol in 'schemaVersion' 1 (which is ACL based). That will most likely result in " +
"unexpected behavior.");
}
if (jsonSchemaVersion == JsonSchemaVersion.V_2 && thing.getAccessControlList().isPresent()) {
LOGGER.warn("Creating/modifying a Thing with a defined 'acl' when client was configured to use " +
"Ditto Protocol in 'schemaVersion' 2 (which is policy based). That will most likely result in " +
"unexpected behavior.");
}
}

public RetrieveThing retrieveThing(final CharSequence thingId) {
return RetrieveThing.of(ThingId.of(thingId), buildDittoHeaders(false));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,6 @@ public String visitPolicyId(final JsonPointer path, @Nullable final ThingId thin
return BusAddressFactory.forPolicyId(checkNotNull(thingId));
}

@Override
public String visitAcl(final JsonPointer path, @Nullable final ThingId thingId) {
return BusAddressFactory.forAcl(checkNotNull(thingId));
}

@Override
public String visitAclEntry(final JsonPointer path, @Nullable final ThingId thingId) {
return BusAddressFactory.forAclEntry(checkNotNull(thingId), extractSubjectId(path));
}

@Override
public String visitAttributes(final JsonPointer path, @Nullable final ThingId thingId) {
return BusAddressFactory.forAttributes(checkNotNull(thingId));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import static org.eclipse.ditto.json.JsonFactory.emptyPointer;
import static org.eclipse.ditto.json.JsonFactory.newObjectBuilder;
import static org.eclipse.ditto.json.JsonFactory.newPointer;
import static org.eclipse.ditto.model.base.auth.AuthorizationModelFactory.newAuthSubject;
import static org.junit.Assert.assertEquals;

import java.util.UUID;
Expand All @@ -42,7 +41,6 @@
import org.eclipse.ditto.model.things.Attributes;
import org.eclipse.ditto.model.things.Feature;
import org.eclipse.ditto.model.things.FeatureProperties;
import org.eclipse.ditto.model.things.Permission;
import org.eclipse.ditto.model.things.Thing;
import org.eclipse.ditto.model.things.ThingId;
import org.eclipse.ditto.model.things.ThingsModelFactory;
Expand Down Expand Up @@ -122,23 +120,10 @@ public class ChangeUpwardsDownwardsPropagationTest extends AbstractDittoClientTe
public void before() {
super.before();
thingId1 = newThingId(UUID.randomUUID().toString());
thing1 = ThingsModelFactory.newThingBuilder().setId(thingId1)
.setPermissions(
ThingsModelFactory.newAclEntry(newAuthSubject(TEST_USER_SID), Permission.READ,
Permission.WRITE),
ThingsModelFactory.newAclEntry(newAuthSubject(TestConstants.CLIENT_ID),
Permission.READ, Permission.WRITE,
Permission.ADMINISTRATE))
.build();
thing1 = ThingsModelFactory.newThingBuilder().setId(thingId1).build();

thingId2 = newThingId(UUID.randomUUID().toString());
thing2withAttributes = ThingsModelFactory.newThingBuilder().setId(thingId2)
.setPermissions(
ThingsModelFactory.newAclEntry(newAuthSubject(TEST_USER_SID), Permission.READ,
Permission.WRITE),
ThingsModelFactory.newAclEntry(newAuthSubject(TestConstants.CLIENT_ID),
Permission.READ, Permission.WRITE,
Permission.ADMINISTRATE))
.setAttributes(ATTRIBUTES2)
.build();

Expand Down Expand Up @@ -177,8 +162,9 @@ public void testUpwardsRegisterForThingChangeWhenThingIsCreated() throws Excepti

final Message<ThingEvent> thingCreated =
MessagesModelFactory.<ThingEvent>newMessageBuilder(messageHeaders).payload(
ThingCreated.of(thing1, 1,
DittoHeaders.newBuilder().schemaVersion(JsonSchemaVersion.V_1).build()
ThingCreated.of(thing1, 1, null,
DittoHeaders.newBuilder().schemaVersion(JsonSchemaVersion.V_2).build(),
null
)).build();

messaging.receiveEvent(thingCreated);
Expand Down Expand Up @@ -208,8 +194,9 @@ public void testSignalEnrichment() throws Exception {
.build();
final Message<ThingEvent> thingCreated =
MessagesModelFactory.<ThingEvent>newMessageBuilder(messageHeaders)
.payload(ThingCreated.of(thing1, 1,
DittoHeaders.newBuilder().schemaVersion(JsonSchemaVersion.V_1).build()
.payload(ThingCreated.of(thing1, 1, null,
DittoHeaders.newBuilder().schemaVersion(JsonSchemaVersion.V_2).build(),
null
))
.extra(extra)
.build();
Expand Down Expand Up @@ -258,8 +245,9 @@ public void testMultipleChangeHandlersAreInvokedOnSingleChange() throws Exceptio

final Message<ThingEvent> thingCreated =
MessagesModelFactory.<ThingEvent>newMessageBuilder(messageHeaders).payload(
ThingCreated.of(thing1, 1,
DittoHeaders.newBuilder().schemaVersion(JsonSchemaVersion.V_1).build()
ThingCreated.of(thing1, 1, null,
DittoHeaders.newBuilder().schemaVersion(JsonSchemaVersion.V_2).build(),
null
)).build();

// only create the Thing once:
Expand Down Expand Up @@ -297,7 +285,7 @@ public void testUpwardsRegisterForThingChangeWhenThingIsDeleted() throws Excepti

final Message<ThingEvent> thingDeleted =
MessagesModelFactory.<ThingEvent>newMessageBuilder(messageHeaders).payload(
ThingDeleted.of(thingId1, 1, DittoHeaders.empty())).build();
ThingDeleted.of(thingId1, 1, null, DittoHeaders.empty(), null)).build();

messaging.receiveEvent(thingDeleted);

Expand Down Expand Up @@ -337,8 +325,8 @@ public void testUpwardsRegisterForThingChangeWhenAttributesAreModified() throws
// set the attributes
final Message<ThingEvent> attributesCreated =
MessagesModelFactory.<ThingEvent>newMessageBuilder(messageHeaders).payload(
AttributesCreated.of(thingId1, ThingsModelFactory.newAttributes(attributesToSet), 1,
DittoHeaders.empty())).build();
AttributesCreated.of(thingId1, ThingsModelFactory.newAttributes(attributesToSet), 1, null,
DittoHeaders.empty(), null)).build();

messaging.receiveEvent(attributesCreated);

Expand Down Expand Up @@ -385,7 +373,8 @@ public void testUpwardsRegisterForThingChangeWhenSingleAttributeIsModified() thr
// set the attributes
final Message<ThingEvent> attributeCreated =
MessagesModelFactory.<ThingEvent>newMessageBuilder(messageHeaders).payload(
AttributeCreated.of(thingId1, newAttribute, complex, 1, DittoHeaders.empty())).build();
AttributeCreated.of(thingId1, newAttribute, complex, 1, null, DittoHeaders.empty(), null))
.build();

messaging.receiveEvent(attributeCreated);

Expand Down Expand Up @@ -560,7 +549,7 @@ public void testDownwardsRegisterForSingleAttributeChangeWhenThingIsCreated() th
// create the thing with attributes
final Message<ThingEvent> thingCreated =
MessagesModelFactory.<ThingEvent>newMessageBuilder(messageHeaders).payload(
ThingCreated.of(thing2withAttributes, 1, DittoHeaders.empty())).build();
ThingCreated.of(thing2withAttributes, 1, null, DittoHeaders.empty(), null)).build();

messaging.receiveEvent(thingCreated);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,9 @@

import org.assertj.core.api.Assertions;
import org.eclipse.ditto.client.internal.AbstractDittoClientTest;
import org.eclipse.ditto.client.messaging.internal.MockMessagingProvider;
import org.eclipse.ditto.client.options.Options;
import org.eclipse.ditto.json.JsonFactory;
import org.eclipse.ditto.json.JsonMissingFieldException;
import org.eclipse.ditto.model.base.json.JsonSchemaVersion;
import org.eclipse.ditto.model.policies.Policy;
import org.eclipse.ditto.signals.commands.policies.PolicyCommand;
import org.eclipse.ditto.signals.commands.policies.PolicyCommandResponse;
Expand All @@ -53,19 +51,6 @@
*/
public final class DittoClientPoliciesTest extends AbstractDittoClientTest {

@Test
public void verifyClientDefaultsToSchemaVersion2ForPolicyCommands() {
messaging = new MockMessagingProvider(JsonSchemaVersion.V_1);
final DittoClient client = DittoClients.newInstance(messaging)
.connect()
.toCompletableFuture()
.join();
assertEventualCompletion(client.policies().retrieve(POLICY_ID).thenRun(client::destroy));
final RetrievePolicy command = expectMsgClass(RetrievePolicy.class);
reply(RetrievePolicyResponse.of(POLICY_ID, POLICY, command.getDittoHeaders()));
assertThat(command).hasSchemaVersion(JsonSchemaVersion.V_2);
}

@Test
public void testCreatePolicy() throws Exception {
final CompletableFuture<Policy> policyCompletableFuture =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,10 +377,8 @@ public void testUpdateThingWithMissingId() {
@Test
public void testCreateThingWithoutFeatures() {
final ThingId thingIdWithoutFeatures = ThingId.of("demo:mything1");
final AuthorizationSubject authorizationSubject = AuthorizationModelFactory.newAuthSubject("someSubject");
final Thing thing = ThingsModelFactory.newThingBuilder()
.setId(thingIdWithoutFeatures)
.setPermissions(authorizationSubject, ThingsModelFactory.allPermissions())
.build();
assertEventualCompletion(getManagement().create(thing));
final CreateThing command = expectMsgClass(CreateThing.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@
import org.eclipse.ditto.model.messages.Message;
import org.eclipse.ditto.model.messages.MessagesModelFactory;
import org.eclipse.ditto.model.policies.PoliciesModelFactory;
import org.eclipse.ditto.model.things.AccessControlListModelFactory;
import org.eclipse.ditto.model.things.AttributesModelFactory;
import org.eclipse.ditto.model.things.ThingsModelFactory;
import org.eclipse.ditto.protocoladapter.Adaptable;
Expand Down Expand Up @@ -224,7 +223,6 @@ public void shouldBeAbleToResolveBundlesOfUsedDependencies() {

// ditto-model-things:
LOG.info("Ensuring ditto-model-things is usable from OSGi..");
checkBundleIsPresentInstalledAndActive(FrameworkUtil.getBundle(AccessControlListModelFactory.class));
checkBundleIsPresentInstalledAndActive(FrameworkUtil.getBundle(AttributesModelFactory.class));
checkBundleIsPresentInstalledAndActive(FrameworkUtil.getBundle(ThingsModelFactory.class));

Expand Down
Loading

0 comments on commit 3b5a011

Please sign in to comment.