Skip to content

Commit

Permalink
[eclipse-ditto#926] remove raw types from preEnforcer.
Browse files Browse the repository at this point in the history
Signed-off-by: Yufei Cai <yufei.cai@bosch.io>
  • Loading branch information
yufei-cai committed Jan 1, 2021
1 parent 097d6c6 commit 6dc7cd7
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
Expand Up @@ -45,7 +45,7 @@ public interface PreEnforcer {
* @param signal the signal.
* @return future result of the pre-enforcement.
*/
CompletionStage<WithDittoHeaders> apply(WithDittoHeaders signal);
CompletionStage<WithDittoHeaders<?>> apply(WithDittoHeaders<?> signal);

/**
* Perform pre-enforcement with error handling.
Expand Down
Expand Up @@ -34,7 +34,9 @@
* its {@link DittoHeaders}.
*/
@Immutable
public final class PlaceholderSubstitution implements Function<WithDittoHeaders, CompletionStage<WithDittoHeaders>> {
public final class PlaceholderSubstitution
implements Function<WithDittoHeaders<?>, CompletionStage<WithDittoHeaders<?>>> {

private final HeaderBasedPlaceholderSubstitutionAlgorithm substitutionAlgorithm;
private final SubstitutionStrategyRegistry substitutionStrategyRegistry;

Expand Down Expand Up @@ -90,8 +92,7 @@ public CompletionStage<WithDittoHeaders> apply(final WithDittoHeaders withDittoH
if (firstMatchingStrategyOpt.isPresent()) {
final SubstitutionStrategy firstMatchingStrategy = firstMatchingStrategyOpt.get();
return CompletableFuture.supplyAsync(() -> {
@SuppressWarnings("unchecked")
final WithDittoHeaders maybeSubstituted =
@SuppressWarnings("unchecked") final WithDittoHeaders maybeSubstituted =
firstMatchingStrategy.apply(withDittoHeaders, substitutionAlgorithm);

return maybeSubstituted;
Expand All @@ -103,7 +104,8 @@ public CompletionStage<WithDittoHeaders> apply(final WithDittoHeaders withDittoH

private static Map<String, Function<DittoHeaders, String>> createDefaultReplacementDefinitions() {
final Map<String, Function<DittoHeaders, String>> defaultReplacementDefinitions = new LinkedHashMap<>();
defaultReplacementDefinitions.put(SubjectIdReplacementDefinition.REPLACER_NAME, SubjectIdReplacementDefinition.getInstance());
defaultReplacementDefinitions.put(SubjectIdReplacementDefinition.REPLACER_NAME,
SubjectIdReplacementDefinition.getInstance());
defaultReplacementDefinitions.put(SubjectIdReplacementDefinition.LEGACY_REPLACER_NAME,
SubjectIdReplacementDefinition.getInstance());
return Collections.unmodifiableMap(defaultReplacementDefinitions);
Expand Down
Expand Up @@ -28,7 +28,7 @@
* Checks that commands that modify entities cause no harm downstream.
*/
public final class CommandWithOptionalEntityValidator implements
Function<WithDittoHeaders, WithDittoHeaders> {
Function<WithDittoHeaders<?>, WithDittoHeaders<?>> {

private static final CommandWithOptionalEntityValidator INSTANCE = new CommandWithOptionalEntityValidator();

Expand All @@ -37,11 +37,11 @@ public static CommandWithOptionalEntityValidator getInstance() {
}

@Override
public WithDittoHeaders apply(final WithDittoHeaders withDittoHeaders) {
public WithDittoHeaders<?> apply(final WithDittoHeaders<?> withDittoHeaders) {
return checkForHarmfulEntity(withDittoHeaders);
}

private static WithDittoHeaders checkForHarmfulEntity(final WithDittoHeaders withDittoHeaders) {
private static WithDittoHeaders<?> checkForHarmfulEntity(final WithDittoHeaders<?> withDittoHeaders) {
if (withDittoHeaders instanceof Command && withDittoHeaders instanceof WithOptionalEntity) {
final Optional<JsonValue> optionalEntity = ((WithOptionalEntity) withDittoHeaders).getEntity();
if (optionalEntity.isPresent() && isJsonValueIllegal(optionalEntity.get())) {
Expand Down Expand Up @@ -78,7 +78,7 @@ private static boolean isStringIllegal(final String string) {
return false;
}

private static DittoRuntimeException buildError(final WithDittoHeaders withDittoHeaders) {
private static DittoRuntimeException buildError(final WithDittoHeaders<?> withDittoHeaders) {
final JsonParseException jsonException = JsonParseException.newBuilder()
.message("JSON contains a string with the forbidden character '\\u0000'")
.description("We do not accept any JSON strings containing the null character.")
Expand Down
Expand Up @@ -170,15 +170,15 @@ public ActorRef startEnforcerActor(final ActorContext context, final ConciergeCo
* @param originalSignal A signal with authorization context.
* @return A copy of the signal with the header "ditto-originator" set.
*/
public static <T extends WithDittoHeaders<T>> WithDittoHeaders<T> setOriginatorHeader(final T originalSignal) {
public static WithDittoHeaders<?> setOriginatorHeader(final WithDittoHeaders<?> originalSignal) {
final DittoHeaders dittoHeaders = originalSignal.getDittoHeaders();
final AuthorizationContext authorizationContext = dittoHeaders.getAuthorizationContext();
return authorizationContext.getFirstAuthorizationSubject()
.map(AuthorizationSubject::getId)
.map(originatorSubjectId -> DittoHeaders.newBuilder(dittoHeaders)
.putHeader(DittoHeaderDefinition.ORIGINATOR.getKey(), originatorSubjectId)
.build())
.map(originalSignal::setDittoHeaders)
.<WithDittoHeaders<?>>map(originalSignal::setDittoHeaders)
.orElse(originalSignal);
}

Expand All @@ -194,7 +194,7 @@ private static PreEnforcer newPreEnforcer(final BlockedNamespaces blockedNamespa
.thenCompose(placeholderSubstitution);
}

private static WithDittoHeaders prependDefaultNamespaceToCreateThing(final WithDittoHeaders<?> signal) {
private static WithDittoHeaders<?> prependDefaultNamespaceToCreateThing(final WithDittoHeaders<?> signal) {
if (signal instanceof CreateThing) {
final CreateThing createThing = (CreateThing) signal;
final Thing thing = createThing.getThing();
Expand Down
Expand Up @@ -52,7 +52,7 @@ public static BlockNamespaceBehavior of(final BlockedNamespaces blockedNamespace
* @return a completion stage which either completes successfully with the given {@code signal} or exceptionally
* with a {@code NamespaceBlockedException}.
*/
public CompletionStage<WithDittoHeaders> block(final WithDittoHeaders signal) {
public CompletionStage<WithDittoHeaders<?>> block(final WithDittoHeaders<?> signal) {
if (signal instanceof WithId) {
final Optional<String> namespaceOptional = NamespaceReader.fromEntityId(((WithId) signal).getEntityId());
if (namespaceOptional.isPresent()) {
Expand Down

0 comments on commit 6dc7cd7

Please sign in to comment.