2cf01f93908351cd16053014b7486bd08f6e92b8
[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.HashMap;
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 vfModule_InstanceId = "vfModuleInstanceId";
35
36     private static final String volume_Group_InstanceId = "volumeGroupInstanceId";
37     private static final String Network_Instance_Id = "networkInstanceId";
38     private static final String Configuration_Instance_Id = "configurationInstanceId";
39
40     @Override
41     public ValidationInformation validate(ValidationInformation info) throws ValidationException {
42         HashMap<String, String> instanceIdMap = info.getInstanceIdMap();
43         ServiceInstancesRequest sir = info.getSir();
44         if (instanceIdMap != null) {
45             if (instanceIdMap.get(Service_InstanceId) != null) {
46                 if (!UUIDChecker.isValidUUID(instanceIdMap.get(Service_InstanceId))) {
47                     throw new ValidationException(Service_InstanceId);
48                 }
49                 sir.setServiceInstanceId(instanceIdMap.get(Service_InstanceId));
50             }
51
52             if (instanceIdMap.get(Vnf_InstanceId) != null) {
53                 if (!UUIDChecker.isValidUUID(instanceIdMap.get(Vnf_InstanceId))) {
54                     throw new ValidationException(Vnf_InstanceId);
55                 }
56                 sir.setVnfInstanceId(instanceIdMap.get(Vnf_InstanceId));
57             }
58
59             if (instanceIdMap.get(vfModule_InstanceId) != null) {
60                 if (!UUIDChecker.isValidUUID(instanceIdMap.get(vfModule_InstanceId))) {
61                     throw new ValidationException(vfModule_InstanceId);
62                 }
63                 sir.setVfModuleInstanceId(instanceIdMap.get(vfModule_InstanceId));
64             }
65
66             if (instanceIdMap.get(volume_Group_InstanceId) != null) {
67                 if (!UUIDChecker.isValidUUID(instanceIdMap.get(volume_Group_InstanceId))) {
68                     throw new ValidationException(volume_Group_InstanceId);
69                 }
70                 sir.setVolumeGroupInstanceId(instanceIdMap.get(volume_Group_InstanceId));
71             }
72
73             if (instanceIdMap.get(Network_Instance_Id) != null) {
74                 if (!UUIDChecker.isValidUUID(instanceIdMap.get(Network_Instance_Id))) {
75                     throw new ValidationException(Network_Instance_Id);
76                 }
77                 sir.setNetworkInstanceId(instanceIdMap.get(Network_Instance_Id));
78             }
79
80             if (instanceIdMap.get(Configuration_Instance_Id) != null) {
81                 if (!UUIDChecker.isValidUUID(instanceIdMap.get(Configuration_Instance_Id))) {
82                     throw new ValidationException(Configuration_Instance_Id);
83                 }
84                 sir.setConfigurationId(instanceIdMap.get(Configuration_Instance_Id));
85             }
86
87             if (instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID) != null) {
88                 if (!UUIDChecker.isValidUUID(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID))) {
89                     throw new ValidationException(CommonConstants.INSTANCE_GROUP_INSTANCE_ID, true);
90                 }
91                 sir.setInstanceGroupId(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID));
92             }
93         }
94         return info;
95     }
96 }