a12130eadaf9b36aa89ff9e8f759194125522c5b
[policy/distribution.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2018 Intel. All rights reserved.
4  *  Modifications Copyright (C) 2019 Nordix Foundation.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.distribution.reception.handling.file;
23
24 import java.io.File;
25
26 import lombok.Getter;
27 import lombok.Setter;
28
29 import org.onap.policy.common.parameters.GroupValidationResult;
30 import org.onap.policy.common.parameters.ValidationStatus;
31 import org.onap.policy.common.parameters.annotations.NotBlank;
32 import org.onap.policy.common.parameters.annotations.NotNull;
33 import org.onap.policy.distribution.reception.parameters.ReceptionHandlerConfigurationParameterGroup;
34
35 /**
36  * This class handles reading, parsing and validating of the Policy SDC Service Distribution parameters from Json
37  * format, which strictly adheres to the interface:IConfiguration, defined by SDC SDK.
38  */
39 @Getter
40 @Setter
41 @NotNull
42 @NotBlank
43 public class FileSystemReceptionHandlerConfigurationParameterGroup extends ReceptionHandlerConfigurationParameterGroup {
44
45     private String watchPath;
46     private int maxThread;
47
48     public FileSystemReceptionHandlerConfigurationParameterGroup() {
49         super(FileSystemReceptionHandlerConfigurationParameterGroup.class.getSimpleName());
50     }
51
52     /**
53      * {@inheritDoc}.
54      */
55     @Override
56     public GroupValidationResult validate() {
57         final GroupValidationResult validationResult = new GroupValidationResult(this);
58         validatePathElement(validationResult, watchPath, "watchPath");
59         return validationResult;
60     }
61
62
63     /**
64      * Validate the string element.
65      *
66      * @param validationResult the result object
67      * @param element the element to validate
68      * @param elementName the element name for error message
69      */
70     private void validatePathElement(final GroupValidationResult validationResult, final String element,
71             final String elementName) {
72         boolean valid = false;
73         if (element != null) {
74             final File file = new File(element);
75             if (file.exists() && file.isDirectory()) {
76                 valid = true;
77             }
78         }
79         if (!valid) {
80             validationResult.setResult(elementName, ValidationStatus.INVALID,
81                     elementName + " must be a valid directory");
82         }
83     }
84 }
85