Replaced all tabs with spaces in java and pom.xml
[so.git] / mso-api-handlers / mso-api-handler-infra / src / main / java / org / onap / so / apihandlerinfra / validation / InstanceIdMapValidation.java
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     @Override
33     public ValidationInformation validate(ValidationInformation info) throws ValidationException {
34         HashMap<String, String> instanceIdMap = info.getInstanceIdMap();
35         ServiceInstancesRequest sir = info.getSir();
36         if (instanceIdMap != null) {
37             if (instanceIdMap.get("serviceInstanceId") != null) {
38                 if (!UUIDChecker.isValidUUID(instanceIdMap.get("serviceInstanceId"))) {
39                     throw new ValidationException("serviceInstanceId");
40                 }
41                 sir.setServiceInstanceId(instanceIdMap.get("serviceInstanceId"));
42             }
43
44             if (instanceIdMap.get("vnfInstanceId") != null) {
45                 if (!UUIDChecker.isValidUUID(instanceIdMap.get("vnfInstanceId"))) {
46                     throw new ValidationException("vnfInstanceId");
47                 }
48                 sir.setVnfInstanceId(instanceIdMap.get("vnfInstanceId"));
49             }
50
51             if (instanceIdMap.get("vfModuleInstanceId") != null) {
52                 if (!UUIDChecker.isValidUUID(instanceIdMap.get("vfModuleInstanceId"))) {
53                     throw new ValidationException("vfModuleInstanceId");
54                 }
55                 sir.setVfModuleInstanceId(instanceIdMap.get("vfModuleInstanceId"));
56             }
57
58             if (instanceIdMap.get("volumeGroupInstanceId") != null) {
59                 if (!UUIDChecker.isValidUUID(instanceIdMap.get("volumeGroupInstanceId"))) {
60                     throw new ValidationException("volumeGroupInstanceId");
61                 }
62                 sir.setVolumeGroupInstanceId(instanceIdMap.get("volumeGroupInstanceId"));
63             }
64
65             if (instanceIdMap.get("networkInstanceId") != null) {
66                 if (!UUIDChecker.isValidUUID(instanceIdMap.get("networkInstanceId"))) {
67                     throw new ValidationException("networkInstanceId");
68                 }
69                 sir.setNetworkInstanceId(instanceIdMap.get("networkInstanceId"));
70             }
71
72             if (instanceIdMap.get("configurationInstanceId") != null) {
73                 if (!UUIDChecker.isValidUUID(instanceIdMap.get("configurationInstanceId"))) {
74                     throw new ValidationException("configurationInstanceId");
75                 }
76                 sir.setConfigurationId(instanceIdMap.get("configurationInstanceId"));
77             }
78
79             if (instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID) != null) {
80                 if (!UUIDChecker.isValidUUID(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID))) {
81                     throw new ValidationException(CommonConstants.INSTANCE_GROUP_INSTANCE_ID, true);
82                 }
83                 sir.setInstanceGroupId(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID));
84             }
85         }
86         return info;
87     }
88 }