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