[java-metadata-aggregator] branch main updated: MDA-257 - Refactor ItemMetadataSelection group of classes
Ian Young
ian at iay.org.uk
Mon Sep 28 13:21:29 UTC 2020
This is an automated email from the git hooks/post-receive script.
iay pushed a commit to branch main
in repository java-metadata-aggregator.
View the commit online:
http://git.shibboleth.net/view/?p=java-metadata-aggregator.git;a=commit;h=39ca7cecd9da9ed5d788f9998ea758dcb2ac67ea
The following commit(s) were added to refs/heads/main by this push:
new 39ca7ce MDA-257 - Refactor ItemMetadataSelection group of classes
39ca7ce is described below
commit 39ca7cecd9da9ed5d788f9998ea758dcb2ac67ea
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Mon Sep 28 14:21:25 2020 +0100
MDA-257 - Refactor ItemMetadataSelection group of classes
https://issues.shibboleth.net/jira/browse/MDA-257
---
.../AbstractItemMetadataSelectionStage.java | 22 ++++++++--------
.../metadata/pipeline/ItemMetadataFilterStage.java | 10 ++++----
.../pipeline/ItemMetadataTerminationStage.java | 12 ++++-----
.../pipeline/StatusMetadataLoggingStage.java | 30 +++++++++-------------
4 files changed, 33 insertions(+), 41 deletions(-)
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/AbstractItemMetadataSelectionStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/AbstractItemMetadataSelectionStage.java
index 489e933..633592b 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/AbstractItemMetadataSelectionStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/AbstractItemMetadataSelectionStage.java
@@ -19,9 +19,7 @@ package net.shibboleth.metadata.pipeline;
import java.util.ArrayList;
import java.util.Collection;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
import java.util.Set;
import javax.annotation.Nonnull;
@@ -34,6 +32,7 @@ import net.shibboleth.metadata.ItemIdentificationStrategy;
import net.shibboleth.metadata.ItemMetadata;
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
import net.shibboleth.utilities.java.support.annotation.constraint.Unmodifiable;
+import net.shibboleth.utilities.java.support.collection.ClassToInstanceMultiMap;
import net.shibboleth.utilities.java.support.logic.Constraint;
/**
@@ -41,15 +40,16 @@ import net.shibboleth.utilities.java.support.logic.Constraint;
* type of {@link ItemMetadata} attached to them.
*
* @param <T> the type of data included in the items being processed
+ * @param <B> the type bound for the selection requirements set
*/
@ThreadSafe
-public abstract class AbstractItemMetadataSelectionStage<T> extends AbstractStage<T> {
+public abstract class AbstractItemMetadataSelectionStage<T, B> extends AbstractStage<T> {
/**
* {@link ItemMetadata} classes that, if an item contains them, will cause the {@link Item} to be selected.
*/
@Nonnull @NonnullElements @Unmodifiable @GuardedBy("this")
- private Set<Class<? extends ItemMetadata>> selectionRequirements = Set.of();
+ private Set<Class<? extends B>> selectionRequirements = Set.of();
/** Strategy used to generate item identifiers for logging purposes. */
@Nonnull @GuardedBy("this")
@@ -63,7 +63,7 @@ public abstract class AbstractItemMetadataSelectionStage<T> extends AbstractStag
* selected, never null nor containing null elements
*/
@Nonnull @NonnullElements @Unmodifiable
- public final synchronized Collection<Class<? extends ItemMetadata>> getSelectionRequirements() {
+ public final synchronized Collection<Class<? extends B>> getSelectionRequirements() {
return selectionRequirements;
}
@@ -75,7 +75,7 @@ public abstract class AbstractItemMetadataSelectionStage<T> extends AbstractStag
* {@link Item} to be selected
*/
public synchronized void setSelectionRequirements(
- @Nonnull @NonnullElements @Unmodifiable final Collection<Class<? extends ItemMetadata>> requirements) {
+ @Nonnull @NonnullElements @Unmodifiable final Collection<Class<? extends B>> requirements) {
throwSetterPreconditionExceptions();
selectionRequirements = Set.copyOf(requirements);
}
@@ -106,12 +106,11 @@ public abstract class AbstractItemMetadataSelectionStage<T> extends AbstractStag
final var collectionCopy = new ArrayList<>(items);
for (final Item<T> item : collectionCopy) {
- final HashMap<Class<? extends ItemMetadata>, List<? extends ItemMetadata>> matchingMetadata =
- new HashMap<>();
+ final var matchingMetadata = new ClassToInstanceMultiMap<B>();
- for (final Class<? extends ItemMetadata> infoClass : getSelectionRequirements()) {
+ for (final Class<? extends B> infoClass : getSelectionRequirements()) {
if (item.getItemMetadata().containsKey(infoClass)) {
- matchingMetadata.put(infoClass, item.getItemMetadata().get(infoClass));
+ matchingMetadata.putAll(item.getItemMetadata().get(infoClass));
}
}
@@ -141,8 +140,7 @@ public abstract class AbstractItemMetadataSelectionStage<T> extends AbstractStag
protected abstract void doExecute(
@Nonnull @NonnullElements final List<Item<T>> items,
@Nonnull final Item<T> matchingItem,
- @Nonnull @NonnullElements
- final Map<Class<? extends ItemMetadata>, List<? extends ItemMetadata>> matchingMetadata)
+ @Nonnull @NonnullElements final ClassToInstanceMultiMap<B> matchingMetadata)
throws StageProcessingException;
}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/ItemMetadataFilterStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/ItemMetadataFilterStage.java
index 66ac26a..b62336c 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/ItemMetadataFilterStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/ItemMetadataFilterStage.java
@@ -18,7 +18,6 @@
package net.shibboleth.metadata.pipeline;
import java.util.List;
-import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.ThreadSafe;
@@ -29,6 +28,7 @@ import org.slf4j.LoggerFactory;
import net.shibboleth.metadata.Item;
import net.shibboleth.metadata.ItemMetadata;
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
+import net.shibboleth.utilities.java.support.collection.ClassToInstanceMultiMap;
/**
* A {@link Stage} that filters out {@link Item} if they have a specific type of {@link ItemMetadata} attached to them.
@@ -39,19 +39,19 @@ import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElemen
* @param <T> type of items the stage operates on
*/
@ThreadSafe
-public class ItemMetadataFilterStage<T> extends AbstractItemMetadataSelectionStage<T> {
+public class ItemMetadataFilterStage<T> extends AbstractItemMetadataSelectionStage<T, ItemMetadata> {
/** Class logger. */
private final Logger log = LoggerFactory.getLogger(ItemMetadataFilterStage.class);
@Override
protected void doExecute(@Nonnull @NonnullElements final List<Item<T>> items,
- final Item<T> matchingItem,
- final Map<Class<? extends ItemMetadata>, List<? extends ItemMetadata>> matchingMetadata)
+ @Nonnull final Item<T> matchingItem,
+ @Nonnull @NonnullElements final ClassToInstanceMultiMap<ItemMetadata> matchingMetadata)
throws StageProcessingException {
final String itemId = getItemIdentificationStrategy().getItemIdentifier(matchingItem);
- log.debug("Item {} was removed because it was marked with {}", itemId, matchingMetadata.keySet());
+ log.debug("Item {} was removed because it was marked with {}", itemId, matchingMetadata.keys());
items.remove(matchingItem);
}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/ItemMetadataTerminationStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/ItemMetadataTerminationStage.java
index a157d4d..e9e7821 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/ItemMetadataTerminationStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/ItemMetadataTerminationStage.java
@@ -18,7 +18,6 @@
package net.shibboleth.metadata.pipeline;
import java.util.List;
-import java.util.Map;
import javax.annotation.Nonnull;
import javax.annotation.concurrent.ThreadSafe;
@@ -29,6 +28,7 @@ import org.slf4j.LoggerFactory;
import net.shibboleth.metadata.Item;
import net.shibboleth.metadata.ItemMetadata;
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
+import net.shibboleth.utilities.java.support.collection.ClassToInstanceMultiMap;
/**
* A {@link Stage} that terminates pipeline processing if an {@link Item} has a specific type of {@link ItemMetadata}
@@ -37,22 +37,22 @@ import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElemen
* @param <T> type of items the stage operates on
*/
@ThreadSafe
-public class ItemMetadataTerminationStage<T> extends AbstractItemMetadataSelectionStage<T> {
+public class ItemMetadataTerminationStage<T> extends AbstractItemMetadataSelectionStage<T, ItemMetadata> {
/** Class logger. */
private final Logger log = LoggerFactory.getLogger(ItemMetadataTerminationStage.class);
@Override
protected void doExecute(@Nonnull @NonnullElements final List<Item<T>> items,
- final Item<T> matchingItem,
- final Map<Class<? extends ItemMetadata>, List<? extends ItemMetadata>> matchingMetadata)
+ @Nonnull final Item<T> matchingItem,
+ @Nonnull @NonnullElements final ClassToInstanceMultiMap<ItemMetadata> matchingMetadata)
throws TerminationException {
final String itemId = getItemIdentificationStrategy().getItemIdentifier(matchingItem);
log.error("Item {} caused processing to terminate because it was marked with a {}", itemId,
- matchingMetadata.keySet());
+ matchingMetadata.keys());
throw new TerminationException("Item " + itemId + " marked with metadata of type "
- + matchingMetadata.keySet());
+ + matchingMetadata.keys());
}
}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/StatusMetadataLoggingStage.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/StatusMetadataLoggingStage.java
index 49e519c..4061928 100644
--- a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/StatusMetadataLoggingStage.java
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/pipeline/StatusMetadataLoggingStage.java
@@ -18,10 +18,8 @@
package net.shibboleth.metadata.pipeline;
import java.util.List;
-import java.util.Map;
import javax.annotation.Nonnull;
-import javax.annotation.Nullable;
import javax.annotation.concurrent.ThreadSafe;
import org.slf4j.Logger;
@@ -30,10 +28,10 @@ import org.slf4j.LoggerFactory;
import net.shibboleth.metadata.ErrorStatus;
import net.shibboleth.metadata.InfoStatus;
import net.shibboleth.metadata.Item;
-import net.shibboleth.metadata.ItemMetadata;
import net.shibboleth.metadata.StatusMetadata;
import net.shibboleth.metadata.WarningStatus;
import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElements;
+import net.shibboleth.utilities.java.support.collection.ClassToInstanceMultiMap;
/**
* A {@link Stage} that logs {@link StatusMetadata} associated with an {@link Item}.
@@ -41,7 +39,7 @@ import net.shibboleth.utilities.java.support.annotation.constraint.NonnullElemen
* @param <T> type of item which this stage processes
*/
@ThreadSafe
-public class StatusMetadataLoggingStage<T> extends AbstractItemMetadataSelectionStage<T> {
+public class StatusMetadataLoggingStage<T> extends AbstractItemMetadataSelectionStage<T, StatusMetadata> {
/** Class logger. */
private final Logger log = LoggerFactory.getLogger(StatusMetadataLoggingStage.class);
@@ -50,8 +48,7 @@ public class StatusMetadataLoggingStage<T> extends AbstractItemMetadataSelection
protected void doExecute(
@Nonnull @NonnullElements final List<Item<T>> items,
@Nonnull final Item<T> matchingItem,
- @Nonnull @NonnullElements final Map<Class<? extends ItemMetadata>,
- List<? extends ItemMetadata>> matchingMetadata)
+ @Nonnull @NonnullElements final ClassToInstanceMultiMap<StatusMetadata> matchingMetadata)
throws StageProcessingException {
final String itemId = getItemIdentificationStrategy().getItemIdentifier(matchingItem);
@@ -68,11 +65,10 @@ public class StatusMetadataLoggingStage<T> extends AbstractItemMetadataSelection
* @param statuses status messages to log
*/
private void logInfos(@Nonnull final String itemId,
- @Nullable @NonnullElements final List<? extends ItemMetadata> statuses) {
- if (statuses != null && !statuses.isEmpty() && log.isInfoEnabled()) {
+ @Nonnull @NonnullElements final List<InfoStatus> statuses) {
+ if (!statuses.isEmpty() && log.isInfoEnabled()) {
log.info("Item {} was marked with the following Info status messages", itemId);
- for (final ItemMetadata info : statuses) {
- final StatusMetadata status = (StatusMetadata) info;
+ for (final var status : statuses) {
log.info(" {}: {}", status.getComponentId(), status.getStatusMessage());
}
}
@@ -85,11 +81,10 @@ public class StatusMetadataLoggingStage<T> extends AbstractItemMetadataSelection
* @param statuses status messages to log
*/
private void logWarnings(@Nonnull final String itemId,
- @Nullable @NonnullElements final List<? extends ItemMetadata> statuses) {
- if (statuses != null && !statuses.isEmpty() && log.isWarnEnabled()) {
+ @Nonnull @NonnullElements final List<WarningStatus> statuses) {
+ if (!statuses.isEmpty() && log.isWarnEnabled()) {
log.warn("Item {} was marked with the following Warning status messages", itemId);
- for (final ItemMetadata info : statuses) {
- final StatusMetadata status = (StatusMetadata) info;
+ for (final var status : statuses) {
log.warn(" {}: {}", status.getComponentId(), status.getStatusMessage());
}
}
@@ -102,11 +97,10 @@ public class StatusMetadataLoggingStage<T> extends AbstractItemMetadataSelection
* @param statuses status messages to log
*/
private void logErrors(@Nonnull final String itemId,
- @Nullable @NonnullElements final List<? extends ItemMetadata> statuses) {
- if (statuses != null && !statuses.isEmpty() && log.isErrorEnabled()) {
+ @Nonnull @NonnullElements final List<ErrorStatus> statuses) {
+ if (!statuses.isEmpty() && log.isErrorEnabled()) {
log.error("Item {} was marked with the following Error status messages", itemId);
- for (final ItemMetadata info : statuses) {
- final StatusMetadata status = (StatusMetadata) info;
+ for (final var status : statuses) {
log.error(" {}: {}", status.getComponentId(), status.getStatusMessage());
}
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list