2  * ============LICENSE_START=======================================================
 
   3  *  Copyright (C) 2018 Intel. All rights reserved.
 
   4  * ================================================================================
 
   5  * Licensed under the Apache License, Version 2.0 (the "License");
 
   6  * you may not use this file except in compliance with the License.
 
   7  * You may obtain a copy of the License at
 
   9  *      http://www.apache.org/licenses/LICENSE-2.0
 
  11  * Unless required by applicable law or agreed to in writing, software
 
  12  * distributed under the License is distributed on an "AS IS" BASIS,
 
  13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  14  * See the License for the specific language governing permissions and
 
  15  * limitations under the License.
 
  17  * SPDX-License-Identifier: Apache-2.0
 
  18  * ============LICENSE_END=========================================================
 
  21 package org.onap.policy.distribution.reception.handling.file;
 
  25 import org.onap.policy.common.parameters.GroupValidationResult;
 
  26 import org.onap.policy.common.parameters.ValidationStatus;
 
  27 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
 
  28 import org.onap.policy.distribution.reception.parameters.ReceptionHandlerConfigurationParameterGroup;
 
  31  * This class handles reading, parsing and validating of the Policy SDC Service Distribution parameters from Json
 
  32  * format, which strictly adheres to the interface:IConfiguration, defined by SDC SDK.
 
  34 public class FileSystemReceptionHandlerConfigurationParameterGroup extends ReceptionHandlerConfigurationParameterGroup {
 
  36     private String watchPath;
 
  37     private int maxThread;
 
  40      * The constructor for instantiating {@link FileSystemReceptionHandlerConfigurationParameterGroup} class.
 
  42      * @param builder the SDC configuration builder
 
  44     public FileSystemReceptionHandlerConfigurationParameterGroup(
 
  45             final FileSystemReceptionHandlerConfigurationParameterBuilder builder) {
 
  46         watchPath = builder.getWatchPath();
 
  47         maxThread = builder.getMaxThread();
 
  50     public String getWatchPath() {
 
  54     public int getMaxThread() {
 
  62     public GroupValidationResult validate() {
 
  63         final GroupValidationResult validationResult = new GroupValidationResult(this);
 
  64         validatePathElement(validationResult, watchPath, "watchPath");
 
  65         if (!ParameterValidationUtils.validateIntParameter(maxThread)) {
 
  66             validationResult.setResult("maxThread", ValidationStatus.INVALID, "must be a positive integer");
 
  68         return validationResult;
 
  73      * Validate the string element.
 
  75      * @param validationResult the result object
 
  76      * @param element the element to validate
 
  77      * @param elementName the element name for error message
 
  79     private void validatePathElement(final GroupValidationResult validationResult, final String element,
 
  80             final String elementName) {
 
  81         boolean valid = false;
 
  82         if (element != null) {
 
  83             File file = new File(element);
 
  84             if (file.exists() && file.isDirectory()) {
 
  89             validationResult.setResult(elementName, ValidationStatus.INVALID,
 
  90                     elementName + " must be a valid directory");