Fix checkstyle violations in sdc/jtosca
[sdc/sdc-tosca.git] / src / main / java / org / onap / sdc / toscaparser / api / UnsupportedType.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 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  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.sdc.toscaparser.api;
22
23 import org.onap.sdc.toscaparser.api.common.JToscaValidationIssue;
24 import org.onap.sdc.toscaparser.api.utils.ThreadLocalsHolder;
25
26 public class UnsupportedType {
27
28     // Note: TOSCA spec version related
29
30         /*
31     The tosca.nodes.Storage.ObjectStorage and tosca.nodes.Storage.BlockStorage
32     used here as un_supported_types are part of the name changes in TOSCA spec
33     version 1.1. The original name as specified in version 1.0 are,
34     tosca.nodes.BlockStorage and tosca.nodes.ObjectStorage which are supported
35     by the tosca-parser. Since there are little overlapping in version support
36     currently in the tosca-parser, the names tosca.nodes.Storage.ObjectStorage
37     and tosca.nodes.Storage.BlockStorage are used here to demonstrate the usage
38     of un_supported_types. As tosca-parser move to provide support for version
39     1.1 and higher, they will be removed.
40     */
41
42     private UnsupportedType() {
43     }
44
45     private static final String[] UNSUPPORTED_TYPES = {
46             "tosca.test.invalidtype",
47             "tosca.nodes.Storage.ObjectStorage",
48             "tosca.nodes.Storage.BlockStorage"};
49
50     public static boolean validateType(String entityType) {
51         for (String ust : UNSUPPORTED_TYPES) {
52             if (ust.equals(entityType)) {
53                 ThreadLocalsHolder.getCollector().appendValidationIssue(new JToscaValidationIssue("JE251", String.format(
54                         "UnsupportedTypeError: Entity type \"%s\" is not supported", entityType)));
55                 return true;
56             }
57         }
58         return false;
59     }
60 }
61
62 /*python
63
64 from toscaparser.common.exception import ValidationIssueCollector
65 from toscaparser.common.exception import UnsupportedTypeError
66 from toscaparser.utils.gettextutils import _
67
68 log = logging.getLogger('tosca')
69
70
71 class UnsupportedType(object):
72
73     """Note: TOSCA spec version related
74
75     The tosca.nodes.Storage.ObjectStorage and tosca.nodes.Storage.BlockStorage
76     used here as un_supported_types are part of the name changes in TOSCA spec
77     version 1.1. The original name as specified in version 1.0 are,
78     tosca.nodes.BlockStorage and tosca.nodes.ObjectStorage which are supported
79     by the tosca-parser. Since there are little overlapping in version support
80     currently in the tosca-parser, the names tosca.nodes.Storage.ObjectStorage
81     and tosca.nodes.Storage.BlockStorage are used here to demonstrate the usage
82     of un_supported_types. As tosca-parser move to provide support for version
83     1.1 and higher, they will be removed.
84     """
85     un_supported_types = ['tosca.test.invalidtype',
86                           'tosca.nodes.Storage.ObjectStorage',
87                           'tosca.nodes.Storage.BlockStorage']
88
89     def __init__(self):
90         pass
91
92     @staticmethod
93     def validate_type(entitytype):
94         if entitytype in UnsupportedType.un_supported_types:
95             ValidationIssueCollector.appendException(UnsupportedTypeError(
96                                                what=_('%s')
97                                                % entitytype))
98             return True
99         else:
100             return False
101 */