55a68ff7df1bec4110f8784f187733321144ff10
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright (C) 2017 Huawei Technologies Co., Ltd. All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  * 
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  * 
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.so.apihandlerinfra.validation;
23
24 import java.util.Map;
25 import org.onap.so.apihandler.common.CommonConstants;
26 import org.onap.so.exceptions.ValidationException;
27 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
28 import org.onap.so.utils.UUIDChecker;
29
30 public class InstanceIdMapValidation implements ValidationRule {
31
32     private static final String Service_InstanceId = "serviceInstanceId";
33     private static final String Vnf_InstanceId = "vnfInstanceId";
34     private static final String PNF_NAME = "pnfName";
35     private static final String vfModule_InstanceId = "vfModuleInstanceId";
36
37     private static final String volume_Group_InstanceId = "volumeGroupInstanceId";
38     private static final String Network_Instance_Id = "networkInstanceId";
39     private static final String Configuration_Instance_Id = "configurationInstanceId";
40
41     @Override
42     public ValidationInformation validate(ValidationInformation info) throws ValidationException {
43         Map<String, String> instanceIdMap = info.getInstanceIdMap();
44         ServiceInstancesRequest sir = info.getSir();
45         if (instanceIdMap != null) {
46             if (instanceIdMap.get(Service_InstanceId) != null) {
47                 if (!UUIDChecker.isValidUUID(instanceIdMap.get(Service_InstanceId))) {
48                     throw new ValidationException(Service_InstanceId);
49                 }
50                 sir.setServiceInstanceId(instanceIdMap.get(Service_InstanceId));
51             }
52
53             if (instanceIdMap.get(Vnf_InstanceId) != null) {
54                 if (!UUIDChecker.isValidUUID(instanceIdMap.get(Vnf_InstanceId))) {
55                     throw new ValidationException(Vnf_InstanceId);
56                 }
57                 sir.setVnfInstanceId(instanceIdMap.get(Vnf_InstanceId));
58             }
59
60             if (instanceIdMap.get(vfModule_InstanceId) != null) {
61                 if (!UUIDChecker.isValidUUID(instanceIdMap.get(vfModule_InstanceId))) {
62                     throw new ValidationException(vfModule_InstanceId);
63                 }
64                 sir.setVfModuleInstanceId(instanceIdMap.get(vfModule_InstanceId));
65             }
66
67             if (instanceIdMap.get(volume_Group_InstanceId) != null) {
68                 if (!UUIDChecker.isValidUUID(instanceIdMap.get(volume_Group_InstanceId))) {
69                     throw new ValidationException(volume_Group_InstanceId);
70                 }
71                 sir.setVolumeGroupInstanceId(instanceIdMap.get(volume_Group_InstanceId));
72             }
73
74             if (instanceIdMap.get(Network_Instance_Id) != null) {
75                 if (!UUIDChecker.isValidUUID(instanceIdMap.get(Network_Instance_Id))) {
76                     throw new ValidationException(Network_Instance_Id);
77                 }
78                 sir.setNetworkInstanceId(instanceIdMap.get(Network_Instance_Id));
79             }
80
81             if (instanceIdMap.get(Configuration_Instance_Id) != null) {
82                 if (!UUIDChecker.isValidUUID(instanceIdMap.get(Configuration_Instance_Id))) {
83                     throw new ValidationException(Configuration_Instance_Id);
84                 }
85                 sir.setConfigurationId(instanceIdMap.get(Configuration_Instance_Id));
86             }
87
88             if (instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID) != null) {
89                 if (!UUIDChecker.isValidUUID(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID))) {
90                     throw new ValidationException(CommonConstants.INSTANCE_GROUP_INSTANCE_ID, true);
91                 }
92                 sir.setInstanceGroupId(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID));
93             }
94
95             if (instanceIdMap.get(PNF_NAME) != null) {
96                 sir.setPnfName(instanceIdMap.get(PNF_NAME));
97             }
98         }
99         return info;
100     }
101 }