Skip to content

Commit

Permalink
fixed some module/dependency mess by e.g:
Browse files Browse the repository at this point in the history
* removing SignalInformationPoint from ditto-interna-models-signal (as it pulled in several entity modules); moved funtionality of that interface to Command, Signal, etc. interfaces
* moving HeaderTranslator from ditto-protocol to ditto-base-model
* moving LikeHelper from ditto-rql-query to ditto-base-model
* moved ConciergeForwarderActor and ShardRegions to ditto-edge-api
* moved PolicyEnforcer from ditto-internal-utils-cache-loaders to ditto-policies-enforcement
* created DittoSystemProperties inn ditto-base-model for commonly used system properties in order to avoid dependencies to models where not necessary
* moved ThingCommandEnforcement, LiveSignalEnforcement, etc. from ditto-policies-enforcement to ditto-things-service where they should be located in the end

Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch.io>
  • Loading branch information
thjaeckle committed Apr 26, 2022
1 parent b2ffb05 commit 1432c03
Show file tree
Hide file tree
Showing 177 changed files with 986 additions and 878 deletions.
@@ -0,0 +1,39 @@
/*
* 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.base.model.common;

/**
* TODO TJ add javadoc
* @since 3.0.0
*/
public final class DittoSystemProperties {

/**
* System property name of the property defining the max policy size in bytes.
*/
public static final String DITTO_LIMITS_POLICIES_MAX_SIZE_BYTES = "ditto.limits.policies.max-size";

/**
* System property name of the property defining the max Thing size in bytes.
*/
public static final String DITTO_LIMITS_THINGS_MAX_SIZE_BYTES = "ditto.limits.things.max-size";

/**
* System property name of the property defining the max Message payload size in bytes.
*/
public static final String DITTO_LIMITS_MESSAGES_MAX_SIZE_BYTES = "ditto.limits.messages.max-size";

private DittoSystemProperties() {
throw new AssertionError();
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Contributors to the Eclipse Foundation
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.rql.query;
package org.eclipse.ditto.base.model.common;

import java.util.regex.Pattern;

Expand Down
Expand Up @@ -16,6 +16,8 @@

import javax.annotation.Nullable;

import org.eclipse.ditto.base.model.signals.Signal;

/**
* Implementations of this interface are associated to an entity identified by the value
* returned from {@link #getEntityId()}.
Expand Down Expand Up @@ -48,4 +50,41 @@ static <I extends EntityId> Optional<I> getEntityIdOfType(final Class<I> theClas
.map(theClass::cast);
}

/**
* Indicates whether the specified signal argument provides an entity ID.
*
* @param signal the signal to be checked.
* @return {@code true} if {@code signal} provides an entity ID because it implements {@link WithEntityId}.
* {@code false} else.
* @since 3.0.0
*/
static boolean isWithEntityId(@Nullable final Signal<?> signal) {
final boolean result;
if (null != signal) {
result = WithEntityId.class.isAssignableFrom(signal.getClass());
} else {
result = false;
}

return result;
}

/**
* Returns the {@link EntityId} for the specified signal argument.
*
* @param signal the signal to get the entity ID from.
* @return an {@code Optional} containing the signal's entity ID if it provides one, an empty {@code Optional} else.
* @since 3.0.0
*/
static Optional<EntityId> getEntityId(@Nullable final Signal<?> signal) {
final Optional<EntityId> result;
if (null != signal && WithEntityId.isWithEntityId(signal)) {
result = Optional.of(((WithEntityId) signal).getEntityId());
} else {
result = Optional.empty();
}

return result;
}

}
Expand Up @@ -12,6 +12,10 @@
*/
package org.eclipse.ditto.base.model.headers;

import java.util.Optional;

import javax.annotation.Nullable;

/**
* Common interface for all classes which have {@link org.eclipse.ditto.base.model.headers.DittoHeaders} available.
*/
Expand All @@ -24,4 +28,22 @@ public interface WithDittoHeaders {
*/
DittoHeaders getDittoHeaders();

/**
* Returns the optional correlation ID of the specified argument's headers.
*
* @param signal the signal to get the optional correlation ID from.
* @return the optional correlation ID. The optional is empty if {@code signal} is {@code null}.
* @since 3.0.0
*/
static Optional<String> getCorrelationId(@Nullable final WithDittoHeaders signal) {
final Optional<String> result;
if (null != signal) {
final DittoHeaders signalDittoHeaders = signal.getDittoHeaders();
result = signalDittoHeaders.getCorrelationId();
} else {
result = Optional.empty();
}

return result;
}
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Contributors to the Eclipse Foundation
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.protocol;
package org.eclipse.ditto.base.model.headers.translator;

import javax.annotation.Nullable;

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Contributors to the Eclipse Foundation
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.protocol;
package org.eclipse.ditto.base.model.headers.translator;

import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Contributors to the Eclipse Foundation
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -10,20 +10,20 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.protocol;
package org.eclipse.ditto.base.model.headers.translator;

import java.util.Objects;

import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

import org.eclipse.ditto.base.model.acks.AcknowledgementLabel;
import org.eclipse.ditto.base.model.acks.DittoAcknowledgementLabel;
import org.eclipse.ditto.base.model.headers.DittoHeaderDefinition;
import org.eclipse.ditto.json.JsonArray;
import org.eclipse.ditto.json.JsonCollectors;
import org.eclipse.ditto.json.JsonParseException;
import org.eclipse.ditto.json.JsonValue;
import org.eclipse.ditto.base.model.acks.AcknowledgementLabel;
import org.eclipse.ditto.base.model.acks.DittoAcknowledgementLabel;
import org.eclipse.ditto.base.model.headers.DittoHeaderDefinition;

/**
* This {@link HeaderEntryFilter} checks if the given key references {@link DittoHeaderDefinition#REQUESTED_ACKS} and
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Contributors to the Eclipse Foundation
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.protocol;
package org.eclipse.ditto.base.model.headers.translator;

import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Contributors to the Eclipse Foundation
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.protocol;
package org.eclipse.ditto.base.model.headers.translator;

import java.util.Map;

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017 Contributors to the Eclipse Foundation
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.protocol;
package org.eclipse.ditto.base.model.headers.translator;

import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;

Expand All @@ -34,6 +34,8 @@
* <p>
* Does so by applying blocking based on {@link HeaderDefinition}s.
* </p>
* @since 3.0.0
* TODO TJ can we make HeaderTranslator internal??
*/
@Immutable
public final class HeaderTranslator {
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Contributors to the Eclipse Foundation
* Copyright (c) 2022 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
Expand All @@ -10,7 +10,7 @@
*
* SPDX-License-Identifier: EPL-2.0
*/
package org.eclipse.ditto.protocol;
package org.eclipse.ditto.base.model.headers.translator;

import static org.eclipse.ditto.base.model.common.ConditionChecker.checkNotNull;

Expand All @@ -22,14 +22,14 @@
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;

import org.eclipse.ditto.base.model.headers.HeaderDefinition;
import org.eclipse.ditto.json.JsonArray;
import org.eclipse.ditto.json.JsonCollectors;
import org.eclipse.ditto.json.JsonParseException;
import org.eclipse.ditto.json.JsonValue;
import org.eclipse.ditto.base.model.headers.HeaderDefinition;

/**
* This {@link org.eclipse.ditto.protocol.HeaderEntryFilter} reads headers which are of {@code serializationType}
* This {@link HeaderEntryFilter} reads headers which are of {@code serializationType}
* {@code JsonArray} as comma-separated list of values so that the read header entry does not need to be in the JSON
* representation of a JSON array (that would be: {@code "\"["foo","bar"]\""}), but instead simply: {@code "foo,bar"}.
*
Expand Down
Expand Up @@ -12,11 +12,15 @@
*/
package org.eclipse.ditto.base.model.signals;

import org.eclipse.ditto.json.JsonField;
import org.eclipse.ditto.json.JsonObject;
import javax.annotation.Nullable;

import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.base.model.headers.DittoHeadersSettable;
import org.eclipse.ditto.base.model.headers.WithDittoHeaders;
import org.eclipse.ditto.base.model.headers.WithManifest;
import org.eclipse.ditto.base.model.json.Jsonifiable;
import org.eclipse.ditto.json.JsonField;
import org.eclipse.ditto.json.JsonObject;

/**
* A service message that incites to action or conveys notice or warning.
Expand All @@ -26,6 +30,18 @@
public interface Signal<T extends Signal<T>> extends Jsonifiable.WithPredicate<JsonObject, JsonField>,
DittoHeadersSettable<T>, WithManifest, WithType, WithName, WithResource {

/**
* TODO TJ doc
* @since 3.0.0
*/
String CHANNEL_LIVE = "live";

/**
* TODO TJ doc
* @since 3.0.0
*/
String CHANNEL_TWIN = "twin";

/**
* Returns the name of the signal. This is gathered by the type of the signal by default.
*
Expand All @@ -36,4 +52,41 @@ default String getName() {
return getType().contains(":") ? getType().split(":")[1] : getType();
}

/**
* TODO TJ doc - moved from SignalInformationPoint
* @param signal
* @param typePrefix
* @return
* @since 3.0.0
*/
static boolean hasTypePrefix(@Nullable final WithType signal, final String typePrefix) {
final boolean result;
if (null != signal) {
final String signalType = signal.getType();
result = signalType.startsWith(typePrefix);
} else {
result = false;
}
return result;
}

/**
* Indicates whether the headers of the specified signal argument contain channel {@value CHANNEL_LIVE}.
*
* @param signal the signal to be checked.
* @return {@code true} if the headers of {@code signal} contain the channel {@value CHANNEL_LIVE}.
* @since 3.0.0
*/
static boolean isChannelLive(@Nullable final WithDittoHeaders signal) {
final boolean result;
if (null != signal) {
final DittoHeaders dittoHeaders = signal.getDittoHeaders();
result = dittoHeaders.getChannel().filter(CHANNEL_LIVE::equals).isPresent();
} else {
result = false;
}

return result;
}

}

0 comments on commit 1432c03

Please sign in to comment.