Fix NPE on service import
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / impl / aaf / AafPermission.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2020 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 package org.openecomp.sdc.be.components.impl.aaf;
21
22 import org.openecomp.sdc.be.components.impl.exceptions.ByActionStatusComponentException;
23 import org.openecomp.sdc.be.config.ConfigurationManager;
24 import org.openecomp.sdc.be.dao.api.ActionStatus;
25
26 public enum AafPermission {
27     READ(PermNames.READ_VALUE), WRITE(PermNames.WRITE_VALUE), DELETE(PermNames.DELETE_VALUE), INTERNAL_ALL(PermNames.INTERNAL_ALL_VALUE);
28     private String permission;
29     private String permissionSuffix;
30
31     AafPermission(String permissionSuffix) {
32         this.permissionSuffix = permissionSuffix;
33         this.permission = String
34             .format("%s.%s", ConfigurationManager.getConfigurationManager().getConfiguration().getAafNamespace(), permissionSuffix);
35     }
36
37     public static AafPermission getEnumByString(String perm) {
38         for (AafPermission e : AafPermission.values()) {
39             if (perm.equals(e.getPermissionSuffix())) {
40                 return e;
41             }
42         }
43         throw new ByActionStatusComponentException(ActionStatus.INVALID_PROPERTY, perm);
44     }
45
46     public String getFullPermission() {
47         return permission;
48     }
49
50     public String getPermissionSuffix() {
51         return this.permissionSuffix;
52     }
53
54     public static class PermNames {
55
56         public static final String READ_VALUE = "endpoint.api.access|*|read";
57         public static final String WRITE_VALUE = "endpoint.api.access|*|write";
58         public static final String DELETE_VALUE = "endpoint.api.access|*|delete";
59         public static final String INTERNAL_ALL_VALUE = "endpoint.api.internal.access|*|all";
60     }
61 }