add support to generate docker image for artifactbroker
[multicloud/framework.git] / artifactbroker / plugins / reception-plugins / src / main / java / org / onap / policy / distribution / reception / handling / sdc / FileSystemReceptionHandlerConfigurationParameterGroup.java
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.distribution.reception.handling.sdc;
22
23 import java.io.File;
24
25 import org.onap.policy.common.parameters.GroupValidationResult;
26 import org.onap.policy.common.parameters.ValidationStatus;
27 import org.onap.policy.distribution.reception.parameters.ReceptionHandlerConfigurationParameterGroup;
28
29 /**
30  * This class handles reading, parsing and validating of the Policy SDC Service Distribution parameters from Json
31  * format, which strictly adheres to the interface:IConfiguration, defined by SDC SDK.
32  */
33 public class FileSystemReceptionHandlerConfigurationParameterGroup extends ReceptionHandlerConfigurationParameterGroup {
34
35     private String watchPath;
36
37     /**
38      * The constructor for instantiating {@link FileSystemReceptionHandlerConfigurationParameterGroup} class.
39      *
40      * @param builder the SDC configuration builder
41      */
42     public FileSystemReceptionHandlerConfigurationParameterGroup(
43             final FileSystemReceptionHandlerConfigurationParameterBuilder builder) {
44         watchPath = builder.getWatchPath();
45     }
46
47     public String getWatchPath() {
48         return watchPath;
49     }
50
51     /**
52      * {@inheritDoc}.
53      */
54     @Override
55     public GroupValidationResult validate() {
56         final GroupValidationResult validationResult = new GroupValidationResult(this);
57         validatePathElement(validationResult, watchPath, "watchPath");
58         return validationResult;
59     }
60
61
62     /**
63      * Validate the string element.
64      *
65      * @param validationResult the result object
66      * @param element the element to validate
67      * @param elementName the element name for error message
68      */
69     private void validatePathElement(final GroupValidationResult validationResult, final String element,
70             final String elementName) {
71         boolean valid = false;
72         if (element != null) {
73             File file = new File(element);
74             if (file.exists() && file.isDirectory()) {
75                 valid = true;
76             }
77         }
78         if (!valid) {
79             validationResult.setResult(elementName, ValidationStatus.INVALID,
80                     elementName + " must be a valid directory");
81         }
82     }
83 }
84