f1985e9fcf17fc231dae89dbbb321fb16fe88576
[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
26 import org.onap.so.apihandler.common.CommonConstants;
27 import org.onap.so.exceptions.ValidationException;
28 import org.onap.so.serviceinstancebeans.ServiceInstancesRequest;
29 import org.onap.so.utils.UUIDChecker;
30
31 public class InstanceIdMapValidation implements ValidationRule{
32
33         @Override
34         public ValidationInformation validate(ValidationInformation info) throws ValidationException{
35                 HashMap<String, String> instanceIdMap = info.getInstanceIdMap();
36                 ServiceInstancesRequest sir = info.getSir();
37                 if(instanceIdMap != null){
38                 if(instanceIdMap.get("serviceInstanceId") != null){
39                         if (!UUIDChecker.isValidUUID (instanceIdMap.get ("serviceInstanceId"))) {
40                                 throw new ValidationException ("serviceInstanceId");
41                         }
42                         sir.setServiceInstanceId(instanceIdMap.get("serviceInstanceId"));
43                 }
44
45                 if(instanceIdMap.get("vnfInstanceId") != null){
46                         if (!UUIDChecker.isValidUUID (instanceIdMap.get ("vnfInstanceId"))) {
47                                 throw new ValidationException ("vnfInstanceId");
48                         }
49                         sir.setVnfInstanceId(instanceIdMap.get("vnfInstanceId"));
50                 }
51
52                 if(instanceIdMap.get("vfModuleInstanceId") != null){
53                         if (!UUIDChecker.isValidUUID (instanceIdMap.get ("vfModuleInstanceId"))) {
54                                 throw new ValidationException ("vfModuleInstanceId");
55                         }
56                         sir.setVfModuleInstanceId(instanceIdMap.get("vfModuleInstanceId"));
57                 }
58
59                 if(instanceIdMap.get("volumeGroupInstanceId") != null){
60                         if (!UUIDChecker.isValidUUID (instanceIdMap.get ("volumeGroupInstanceId"))) {
61                                 throw new ValidationException ("volumeGroupInstanceId");
62                         }
63                         sir.setVolumeGroupInstanceId(instanceIdMap.get("volumeGroupInstanceId"));
64                 }
65
66                 if(instanceIdMap.get("networkInstanceId") != null){
67                         if (!UUIDChecker.isValidUUID (instanceIdMap.get ("networkInstanceId"))) {
68                                 throw new ValidationException ("networkInstanceId");
69                         }
70                         sir.setNetworkInstanceId(instanceIdMap.get("networkInstanceId"));
71                 }
72                 
73                 if(instanceIdMap.get("configurationInstanceId") != null){
74                         if (!UUIDChecker.isValidUUID (instanceIdMap.get ("configurationInstanceId"))) {
75                                 throw new ValidationException ("configurationInstanceId");
76                         }
77                         sir.setConfigurationId(instanceIdMap.get("configurationInstanceId"));
78                 }
79                 
80                 if(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_ID) != null){
81                         if (!UUIDChecker.isValidUUID (instanceIdMap.get (CommonConstants.INSTANCE_GROUP_ID))) {
82                                 throw new ValidationException (CommonConstants.INSTANCE_GROUP_ID, true);
83                         }
84                         sir.setInstanceGroupId(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_ID));
85                 }
86         }
87         return info;
88         }
89 }