-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds the EventKey and EventKeyFactory. (#4627)
Adds the EventKey and EventKeyFactory. Resolves #1916. Signed-off-by: David Venable <dlv@amazon.com>
- Loading branch information
Showing
23 changed files
with
1,268 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
data-prepper-api/src/main/java/org/opensearch/dataprepper/model/event/EventKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.model.event; | ||
|
||
/** | ||
* Model class to represent a key into a Data Prepper {@link Event}. | ||
* | ||
* @since 2.9 | ||
*/ | ||
public interface EventKey { | ||
/** | ||
* The original key provided as a string. | ||
* | ||
* @return The key as a string | ||
* @since 2.9 | ||
*/ | ||
String getKey(); | ||
} |
71 changes: 71 additions & 0 deletions
71
data-prepper-api/src/main/java/org/opensearch/dataprepper/model/event/EventKeyFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.dataprepper.model.event; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.EnumSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
/** | ||
* A factory for producing {@link EventKey} objects. | ||
* | ||
* @since 2.9 | ||
*/ | ||
public interface EventKeyFactory { | ||
/** | ||
* Creates an {@link EventKey} with given actions. | ||
* | ||
* @param key The key | ||
* @param forActions Actions to support | ||
* @return The EventKey | ||
* @since 2.9 | ||
*/ | ||
EventKey createEventKey(String key, EventAction... forActions); | ||
|
||
/** | ||
* Creates an {@link EventKey} for the default actions, which are all. | ||
* | ||
* @param key The key | ||
* @return The EventKey | ||
* @since 2.9 | ||
*/ | ||
default EventKey createEventKey(final String key) { | ||
return createEventKey(key, EventAction.ALL); | ||
} | ||
|
||
/** | ||
* An action on an Event. | ||
* | ||
* @since 2.9 | ||
*/ | ||
enum EventAction { | ||
GET, | ||
DELETE, | ||
PUT, | ||
ALL(GET, DELETE, PUT); | ||
|
||
private final List<EventAction> includedActions; | ||
|
||
EventAction(EventAction... eventActions) { | ||
includedActions = Arrays.asList(eventActions); | ||
|
||
} | ||
|
||
boolean isMutableAction() { | ||
return this != GET; | ||
} | ||
|
||
Set<EventAction> getSupportedActions() { | ||
final EnumSet<EventAction> supportedActions = EnumSet.noneOf(EventAction.class); | ||
supportedActions.add(this); | ||
supportedActions.addAll(includedActions); | ||
|
||
return Collections.unmodifiableSet(supportedActions); | ||
} | ||
} | ||
} |
Oops, something went wrong.