[java-metadata-aggregator] 01/06: MDA-153 add generic validator framework
Ian Young
ian at iay.org.uk
Thu Dec 10 12:32:44 EST 2015
This is an automated email from the git hooks/post-receive script.
iay pushed a commit to branch master
in repository java-metadata-aggregator.
commit 7ed7e2432439c8a648f7c0f88026ead3b4b78617
Author: Ian Young <ian at iay.org.uk>
AuthorDate: Thu Dec 10 17:06:11 2015 +0000
MDA-153 add generic validator framework
Initial import from ukf-mda project.
---
.../metadata/validate/BaseValidator.java | 93 ++++++++++++++++++++++
.../shibboleth/metadata/validate/Validator.java | 50 ++++++++++++
.../shibboleth/metadata/validate/package-info.java | 21 +++++
3 files changed, 164 insertions(+)
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/BaseValidator.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/BaseValidator.java
new file mode 100644
index 0000000..8aff846
--- /dev/null
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/BaseValidator.java
@@ -0,0 +1,93 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.metadata.validate;
+
+import javax.annotation.Nonnull;
+
+import net.shibboleth.metadata.ErrorStatus;
+import net.shibboleth.metadata.Item;
+import net.shibboleth.metadata.WarningStatus;
+import net.shibboleth.utilities.java.support.component.AbstractIdentifiableInitializableComponent;
+
+/**
+ * Base class for validator implementations.
+ *
+ * Encapsulates the notion of an identifier for each validator class, and helper
+ * methods for constructing status metadata.
+ */
+public abstract class BaseValidator extends AbstractIdentifiableInitializableComponent {
+
+ /**
+ * Construct a modified component identifier from the stage identifier and the
+ * validator identifier.
+ *
+ * @param stageId identifier for the calling stage
+ *
+ * @return composite component identifier
+ */
+ private String makeComponentId(@Nonnull final String stageId) {
+ final String id = getId();
+ if (id == null) {
+ return stageId;
+ } else {
+ return stageId + "/" + getId();
+ }
+ }
+
+ /**
+ * Add an {@link ErrorStatus} to the given {@link Item}.
+ *
+ * @param message message to include in the status metadata
+ * @param item {@link Item} to add the status metadata to
+ * @param stageId component identifier for the calling stage
+ */
+ protected void addError(@Nonnull final String message, @Nonnull final Item<?> item,
+ @Nonnull final String stageId) {
+ item.getItemMetadata().put(new ErrorStatus(makeComponentId(stageId), message));
+ }
+
+ /**
+ * Add a {@link WarningStatus} to the given {@link Item}.
+ *
+ * @param message message to include in the status metadata
+ * @param item {@link Item} to add the status metadata to
+ * @param stageId component identifier for the calling stage
+ */
+ protected void addWarning(@Nonnull final String message, @Nonnull final Item<?> item,
+ @Nonnull final String stageId) {
+ item.getItemMetadata().put(new WarningStatus(makeComponentId(stageId), message));
+ }
+
+ /**
+ * Add a {@link WarningStatus} or {@link ErrorStatus} to the given {@link Item}.
+ *
+ * @param error <code>true</code> if an {@link ErrorStatus} should be added
+ * @param message message to include in the status metadata
+ * @param item {@link Item} to add the status metadata to
+ * @param stageId component identifier for the calling stage
+ */
+ protected void addStatus(final boolean error, @Nonnull final String message, @Nonnull final Item<?> item,
+ @Nonnull final String stageId) {
+ if (error) {
+ addError(message, item, stageId);
+ } else {
+ addWarning(message, item, stageId);
+ }
+ }
+
+}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/Validator.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/Validator.java
new file mode 100644
index 0000000..21d61cb
--- /dev/null
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/Validator.java
@@ -0,0 +1,50 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.shibboleth.metadata.validate;
+
+import javax.annotation.Nonnull;
+
+import net.shibboleth.metadata.Item;
+import net.shibboleth.metadata.pipeline.StageProcessingException;
+import net.shibboleth.utilities.java.support.component.DestructableComponent;
+import net.shibboleth.utilities.java.support.component.IdentifiableComponent;
+import net.shibboleth.utilities.java.support.component.InitializableComponent;
+
+/**
+ * Interface for a validator to be applied to an object in the context of a given {@link Item}.
+ *
+ * @param <V> type of the object to be validated
+ */
+public interface Validator<V> extends DestructableComponent, IdentifiableComponent,
+ InitializableComponent {
+
+ /**
+ * Apply the validator to the object in the given {@link Item} context.
+ *
+ * The validator influences future processing by adding item metadata to the {@link Item}.
+ *
+ * @param e the object to be validated
+ * @param item the {@link Item} context for the validation
+ * @param stageId the identifier for the stage that is requesting the validation, for
+ * inclusion in status metadata
+ * @throws StageProcessingException if an error occurs during validation
+ */
+ public void validate(@Nonnull V e, @Nonnull Item<?> item, @Nonnull String stageId)
+ throws StageProcessingException;
+
+}
diff --git a/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/package-info.java b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/package-info.java
new file mode 100644
index 0000000..02484dc
--- /dev/null
+++ b/aggregator-pipeline/src/main/java/net/shibboleth/metadata/validate/package-info.java
@@ -0,0 +1,21 @@
+/*
+ * Licensed to the University Corporation for Advanced Internet Development,
+ * Inc. (UCAID) under one or more contributor license agreements. See the
+ * NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The UCAID licenses this file to You under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file except in
+ * compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Classes for validation of specific object types.
+ */
+package net.shibboleth.metadata.validate;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the commits
mailing list