Merge "Added support for using oauth token for Kafka"
[nonrtric/plt/ranpm.git] / datafilecollector / src / main / java / org / onap / dcaegen2 / collectors / datafile / commons / Scheme.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * Copyright (C) 2019 Nordix Foundation. All rights reserved.
4  * Copyright (C) 2020-2021 Nokia. All rights reserved.
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  * ============LICENSE_END=========================================================
18  */
19
20 package org.onap.dcaegen2.collectors.datafile.commons;
21
22 import org.onap.dcaegen2.collectors.datafile.exceptions.DatafileTaskException;
23
24 /**
25  * Enum specifying the schemes that DFC support for downloading files.
26  *
27  * @author <a href="mailto:henrik.b.andersson@est.tech">Henrik Andersson</a>
28  *
29  */
30 public enum Scheme {
31     FTPES, SFTP, HTTP, HTTPS;
32
33     public static final String DFC_DOES_NOT_SUPPORT_PROTOCOL_ERROR_MSG = "DFC does not support protocol ";
34     public static final String SUPPORTED_PROTOCOLS_ERROR_MESSAGE =
35         ". Supported protocols are FTPeS, sFTP, HTTP and HTTPS";
36
37     /**
38      * Get a <code>Scheme</code> from a string.
39      *
40      * @param schemeString the string to convert to <code>Scheme</code>.
41      * @return The corresponding <code>Scheme</code>
42      * @throws DatafileTaskException if the value of the string doesn't match any defined scheme.
43      */
44     public static Scheme getSchemeFromString(String schemeString) throws DatafileTaskException {
45         Scheme result;
46         if ("FTPES".equalsIgnoreCase(schemeString)) {
47             result = Scheme.FTPES;
48         } else if ("SFTP".equalsIgnoreCase(schemeString)) {
49             result = Scheme.SFTP;
50         } else if ("HTTP".equalsIgnoreCase(schemeString)) {
51             result = Scheme.HTTP;
52         } else if ("HTTPS".equalsIgnoreCase(schemeString)) {
53             result = Scheme.HTTPS;
54         } else {
55             throw new DatafileTaskException(
56                 DFC_DOES_NOT_SUPPORT_PROTOCOL_ERROR_MSG + schemeString + SUPPORTED_PROTOCOLS_ERROR_MESSAGE);
57         }
58         return result;
59     }
60
61     /**
62      * Check if <code>Scheme</code> is FTP type or HTTP type.
63      *
64      * @param scheme the <code>Scheme</code> which has to be checked.
65      * @return true if <code>Scheme</code> is FTP type or false if it is HTTP type
66      */
67     public static boolean isFtpScheme(Scheme scheme) {
68         return scheme == SFTP || scheme == FTPES;
69     }
70 }