summaryrefslogtreecommitdiffstats
path: root/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/FileCarrierTechnologyParameters.java
diff options
context:
space:
mode:
Diffstat (limited to 'services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/FileCarrierTechnologyParameters.java')
-rw-r--r--services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/FileCarrierTechnologyParameters.java170
1 files changed, 47 insertions, 123 deletions
diff --git a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/FileCarrierTechnologyParameters.java b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/FileCarrierTechnologyParameters.java
index 5071824ce..eceb0b4f9 100644
--- a/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/FileCarrierTechnologyParameters.java
+++ b/services/services-engine/src/main/java/org/onap/policy/apex/service/engine/event/impl/filecarrierplugin/FileCarrierTechnologyParameters.java
@@ -1,19 +1,20 @@
/*-
* ============LICENSE_START=======================================================
* Copyright (C) 2016-2018 Ericsson. All rights reserved.
+ * Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed 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.
- *
+ *
* SPDX-License-Identifier: Apache-2.0
* ============LICENSE_END=========================================================
*/
@@ -21,12 +22,18 @@
package org.onap.policy.apex.service.engine.event.impl.filecarrierplugin;
import java.io.File;
+import lombok.Getter;
+import lombok.Setter;
import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.consumer.ApexFileEventConsumer;
import org.onap.policy.apex.service.engine.event.impl.filecarrierplugin.producer.ApexFileEventProducer;
import org.onap.policy.apex.service.parameters.carriertechnology.CarrierTechnologyParameters;
-import org.onap.policy.common.parameters.GroupValidationResult;
+import org.onap.policy.common.parameters.BeanValidationResult;
+import org.onap.policy.common.parameters.ObjectValidationResult;
+import org.onap.policy.common.parameters.ValidationResult;
import org.onap.policy.common.parameters.ValidationStatus;
+import org.onap.policy.common.parameters.annotations.Min;
import org.onap.policy.common.utils.validation.ParameterValidationUtils;
+import org.onap.policy.models.base.Validated;
/**
* This class holds the parameters that allows transport of events into and out of Apex using files and standard input
@@ -42,6 +49,8 @@ import org.onap.policy.common.utils.validation.ParameterValidationUtils;
*
* @author Liam Fallon (liam.fallon@ericsson.com)
*/
+@Getter
+@Setter
public class FileCarrierTechnologyParameters extends CarrierTechnologyParameters {
// @formatter:off
/** The label of this carrier technology. */
@@ -60,7 +69,7 @@ public class FileCarrierTechnologyParameters extends CarrierTechnologyParameters
private boolean standardIo = false;
private boolean standardError = false;
private boolean streamingMode = false;
- private long startDelay = 0;
+ private @Min(0) long startDelay = 0;
// @formatter:on
/**
@@ -77,96 +86,6 @@ public class FileCarrierTechnologyParameters extends CarrierTechnologyParameters
}
/**
- * Gets the file name from which to read or to which to write events.
- *
- * @return the file name from which to read or to which to write events
- */
- public String getFileName() {
- return fileName;
- }
-
- /**
- * Checks if is standard IO should be used for input or output.
- *
- * @return true, if standard IO should be used for input or output
- */
- public boolean isStandardIo() {
- return standardIo;
- }
-
- /**
- * Checks if is standard error should be used for output.
- *
- * @return true, if standard error should be used for output
- */
- public boolean isStandardError() {
- return standardError;
- }
-
- /**
- * Checks if is streaming mode is on.
- *
- * @return true, if streaming mode is on
- */
- public boolean isStreamingMode() {
- return streamingMode;
- }
-
- /**
- * Sets the file name from which to read or to which to write events.
- *
- * @param fileName the file name from which to read or to which to write events
- */
- public void setFileName(final String fileName) {
- this.fileName = fileName;
- }
-
- /**
- * Sets if standard IO should be used for event input or output.
- *
- * @param standardIo if standard IO should be used for event input or output
- */
- public void setStandardIo(final boolean standardIo) {
- this.standardIo = standardIo;
- }
-
- /**
- * Sets if standard error should be used for event output.
- *
- * @param standardError if standard error should be used for event output
- */
- public void setStandardError(final boolean standardError) {
- this.standardError = standardError;
- }
-
- /**
- * Sets streaming mode.
- *
- * @param streamingMode the streaming mode value
- */
- public void setStreamingMode(final boolean streamingMode) {
- this.streamingMode = streamingMode;
- }
-
- /**
- * Gets the delay in milliseconds before the plugin starts processing.
- *
- * @return the delay
- */
- public long getStartDelay() {
- return startDelay;
- }
-
- /**
- * Sets the delay in milliseconds before the plugin starts processing.
- *
- * @param startDelay the delay
- */
- public void setStartDelay(final long startDelay) {
- this.startDelay = startDelay;
- }
-
- /**
* {@inheritDoc}.
*/
@Override
@@ -188,36 +107,29 @@ public class FileCarrierTechnologyParameters extends CarrierTechnologyParameters
* {@inheritDoc}.
*/
@Override
- public GroupValidationResult validate() {
- final GroupValidationResult result = super.validate();
+ public BeanValidationResult validate() {
+ final BeanValidationResult result = super.validate();
if (!standardIo && !standardError) {
- validateFileName(result);
+ result.addResult(validateFileName());
}
if (standardIo || standardError) {
streamingMode = true;
}
- if (startDelay < 0) {
- result.setResult("startDelay", ValidationStatus.INVALID,
- "startDelay must be zero or a positive number of milliseconds");
- }
-
return result;
}
-
+
/**
* Validate the file name parameter.
- *
- * @param result the variable in which to store the result of the validation
+ *
+ * @return the result of the validation
*/
- private void validateFileName(final GroupValidationResult result) {
+ private ValidationResult validateFileName() {
if (!ParameterValidationUtils.validateStringParameter(fileName)) {
- result.setResult(FILE_NAME_TOKEN, ValidationStatus.INVALID,
- "\"" + fileName + "\" invalid, must be specified as a non-empty string");
- return;
+ return new ObjectValidationResult(FILE_NAME_TOKEN, fileName, ValidationStatus.INVALID, Validated.IS_BLANK);
}
String absoluteFileName = null;
@@ -233,53 +145,65 @@ public class FileCarrierTechnologyParameters extends CarrierTechnologyParameters
// Check if the file exists, the file should be a regular file and should be readable
if (theFile.exists()) {
- validateExistingFile(result, absoluteFileName, theFile);
+ return validateExistingFile(absoluteFileName, theFile);
} else {
// The path to the file should exist and should be writable
- validateNewFileParent(result, absoluteFileName, theFile);
+ return validateNewFileParent(absoluteFileName, theFile);
}
}
/**
* Validate an existing file is OK.
- *
- * @param result the result of the validation
+ *
* @param absoluteFileName the absolute file name of the file
* @param theFile the file that exists
+ * @return the result of the validation
*/
- private void validateExistingFile(final GroupValidationResult result, String absoluteFileName, File theFile) {
+ private ValidationResult validateExistingFile(String absoluteFileName, File theFile) {
// Check that the file is a regular file
if (!theFile.isFile()) {
- result.setResult(FILE_NAME_TOKEN, ValidationStatus.INVALID, "is not a plain file");
+ return new ObjectValidationResult(FILE_NAME_TOKEN, absoluteFileName, ValidationStatus.INVALID,
+ "is not a plain file");
+
} else {
fileName = absoluteFileName;
if (!theFile.canRead()) {
- result.setResult(FILE_NAME_TOKEN, ValidationStatus.INVALID, "is not readable");
+ return new ObjectValidationResult(FILE_NAME_TOKEN, absoluteFileName, ValidationStatus.INVALID,
+ "is not readable");
}
+
+ return null;
}
}
/**
* Validate the parent of a new file is OK.
- *
- * @param result the result of the validation
+ *
* @param absoluteFileName the absolute file name of the file
* @param theFile the file that exists
+ * @return the result of the validation
*/
- private void validateNewFileParent(final GroupValidationResult result, String absoluteFileName, File theFile) {
+ private ValidationResult validateNewFileParent(String absoluteFileName, File theFile) {
// Check that the parent of the file is a directory
if (!theFile.getParentFile().exists()) {
- result.setResult(FILE_NAME_TOKEN, ValidationStatus.INVALID, "parent of file does not exist");
+ return new ObjectValidationResult(FILE_NAME_TOKEN, absoluteFileName, ValidationStatus.INVALID,
+ "parent of file does not exist");
+
} else if (!theFile.getParentFile().isDirectory()) {
// Check that the parent of the file is a directory
- result.setResult(FILE_NAME_TOKEN, ValidationStatus.INVALID, "parent of file is not directory");
+ return new ObjectValidationResult(FILE_NAME_TOKEN, absoluteFileName, ValidationStatus.INVALID,
+ "parent of file is not directory");
+
} else {
fileName = absoluteFileName;
if (!theFile.getParentFile().canRead()) {
- result.setResult(FILE_NAME_TOKEN, ValidationStatus.INVALID, "is not readable");
+ return new ObjectValidationResult(FILE_NAME_TOKEN, absoluteFileName, ValidationStatus.INVALID,
+ "is not readable");
}
+
+ return null;
}
}
}