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