Skip to content

Commit

Permalink
review:
Browse files Browse the repository at this point in the history
* did some code formatting
* fixed OpenAPI documentation by adding "Namespace" parameter
* adjusted some working in OpenAPI docs as well
* fixed non-related typo in wot-thingDescription.yml

Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch.io>
  • Loading branch information
thjaeckle committed Jul 4, 2022
1 parent 94500d4 commit 1fc3ec4
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 35 deletions.
18 changes: 10 additions & 8 deletions documentation/src/main/resources/openapi/ditto-api-2.yml
Expand Up @@ -106,13 +106,7 @@ paths:
- $ref: '#/components/parameters/TimeoutParam'
- $ref: '#/components/parameters/ResponseRequiredParam'
- $ref: '#/components/parameters/AllowPolicyLockoutParam'
- name: namespace
in: query
description: Defines custom namespace for the thing while generating thing ID.
required: false
schema:
type: string
example: my.cool.namespace
- $ref: '#/components/parameters/Namespace'
responses:
'201':
description: The thing was successfully created.
Expand Down Expand Up @@ -6942,6 +6936,14 @@ components:
required: false
schema:
type: integer
Namespace:
name: namespace
in: query
description: Defines a custom namespace for the thing while generating a new thing ID.
required: false
schema:
type: string
example: com.example.namespace
NamespacesFilter:
name: namespaces
in: query
Expand Down Expand Up @@ -7554,7 +7556,7 @@ components:
description: An auth subject that can be used to provide access for a caller (e.g. in subject entries of policies).
WotThingDescription:
type: object
desciption: A WoT Thing Description version 1.1
description: A WoT Thing Description version 1.1
properties:
'@context':
oneOf:
Expand Down
Expand Up @@ -210,6 +210,8 @@ components:
$ref: "./parameters/messageSubjectPathParam.yml"
MessageTimeoutParam:
$ref: "./parameters/messageTimeoutParam.yml"
Namespace:
$ref: "./parameters/namespaceParameter.yml"
NamespacesFilter:
$ref: "./parameters/namespacesFilter.yml"
PolicyIdPathParam:
Expand Down
Expand Up @@ -11,8 +11,8 @@
name: namespace
in: query
description: |-
Defines custom namespace for the thing while generating thing ID.
Defines a custom namespace for the thing while generating a new thing ID.
required: false
schema:
type: string
example: my.cool.namespace
example: com.example.namespace
Expand Up @@ -9,7 +9,7 @@
#
# SPDX-License-Identifier: EPL-2.0
type: object
desciption: A WoT Thing Description version 1.1
description: A WoT Thing Description version 1.1
properties:
'@context':
oneOf:
Expand Down
Expand Up @@ -16,7 +16,6 @@

import java.util.EnumMap;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Predicate;
Expand Down Expand Up @@ -92,6 +91,7 @@ public final class ThingsRoute extends AbstractRoute {
private static final String PATH_POLICY_ID = "policyId";
private static final String PATH_ATTRIBUTES = "attributes";
private static final String PATH_THING_DEFINITION = "definition";
private static final String NAMESPACE_PARAMETER = "namespace";

private final FeaturesRoute featuresRoute;
private final MessagesRoute messagesRoute;
Expand Down Expand Up @@ -289,18 +289,17 @@ private Route buildPostThingsRoute(final RequestContext ctx, final DittoHeaders
return parameterOptional(DittoHeaderDefinition.CHANNEL.getKey(), channelOpt -> {
if (isLiveChannel(channelOpt, dittoHeaders)) {
throw ThingNotCreatableException.forLiveChannel(dittoHeaders);
} return parameterOptional("namespace", namespaceOpt -> {


return ensureMediaTypeJsonWithFallbacksThenExtractDataBytes(ctx, dittoHeaders,
payloadSource ->
handlePerRequest(ctx, dittoHeaders, payloadSource,
thingJson -> CreateThing.of(createThingForPost(thingJson, namespaceOpt.orElse(null)),
createInlinePolicyJson(thingJson),
getCopyPolicyFrom(thingJson),
dittoHeaders)));
});

}
return parameterOptional(NAMESPACE_PARAMETER, namespaceOpt ->
ensureMediaTypeJsonWithFallbacksThenExtractDataBytes(ctx, dittoHeaders,
payloadSource ->
handlePerRequest(ctx, dittoHeaders, payloadSource,
thingJson -> CreateThing.of(
createThingForPost(thingJson, namespaceOpt.orElse(null)),
createInlinePolicyJson(thingJson),
getCopyPolicyFrom(thingJson),
dittoHeaders)))
);
});
}

Expand All @@ -318,7 +317,6 @@ private static Thing createThingForPost(final String jsonString, @Nullable final
throw ThingIdNotExplicitlySettableException.forPostMethod().build();
}


return ThingsModelFactory.newThingBuilder(inputJson)
.setId(ThingBuilder.generateRandomTypedThingId(namespace))
.build();
Expand Down
Expand Up @@ -13,16 +13,15 @@
package org.eclipse.ditto.things.model;

import java.time.Instant;
import java.util.Optional;
import java.util.function.Predicate;

import javax.annotation.Nullable;
import javax.annotation.concurrent.NotThreadSafe;

import org.eclipse.ditto.base.model.entity.metadata.Metadata;
import org.eclipse.ditto.json.JsonObject;
import org.eclipse.ditto.json.JsonPointer;
import org.eclipse.ditto.json.JsonValue;
import org.eclipse.ditto.base.model.entity.metadata.Metadata;
import org.eclipse.ditto.policies.model.PolicyId;

/**
Expand All @@ -46,8 +45,8 @@ static ThingId generateRandomTypedThingId() {
* @param namespace the specified namespace
* @return the ID
*/
static ThingId generateRandomTypedThingId(@Nullable final String namespace){
return ThingId.generateRandom(namespace);
static ThingId generateRandomTypedThingId(@Nullable final String namespace) {
return ThingId.generateRandom(namespace);
}

/**
Expand Down
Expand Up @@ -12,7 +12,6 @@
*/
package org.eclipse.ditto.things.model;

import java.util.Optional;
import java.util.UUID;
import java.util.function.Supplier;

Expand All @@ -33,7 +32,6 @@ public final class ThingId extends AbstractNamespacedEntityId {

private static final String DEFAULT_NAMESPACE = "";


private ThingId(final CharSequence thingId) {
super(ThingConstants.ENTITY_TYPE, thingId);
}
Expand Down
Expand Up @@ -22,7 +22,6 @@
import org.assertj.core.api.JUnitSoftAssertions;
import org.eclipse.ditto.base.model.entity.id.EntityId;
import org.eclipse.ditto.base.model.entity.id.NamespacedEntityId;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;

Expand Down Expand Up @@ -53,9 +52,10 @@ public void testEqualsAndHashcode() {
.verify();
}
@Test
public void generateNamespaceTest(){
final ThingId randomThingId = ThingId.generateRandom("my.cool.namespace");
assertEquals(randomThingId.getNamespace(),"my.cool.namespace");
public void generateNamespaceTest() {
final String namespace = "my.cool.namespace";
final ThingId randomThingId = ThingId.generateRandom(namespace);
assertEquals(randomThingId.getNamespace(), namespace);
}
@Test
public void instantiationFromEntityTypeCreatesThingId() {
Expand Down

0 comments on commit 1fc3ec4

Please sign in to comment.