2 * ============LICENSE_START=======================================================
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.so.apihandlerinfra.validation;
24 import java.util.HashMap;
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;
31 public class InstanceIdMapValidation implements ValidationRule{
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");
42 sir.setServiceInstanceId(instanceIdMap.get("serviceInstanceId"));
45 if(instanceIdMap.get("vnfInstanceId") != null){
46 if (!UUIDChecker.isValidUUID (instanceIdMap.get ("vnfInstanceId"))) {
47 throw new ValidationException ("vnfInstanceId");
49 sir.setVnfInstanceId(instanceIdMap.get("vnfInstanceId"));
52 if(instanceIdMap.get("vfModuleInstanceId") != null){
53 if (!UUIDChecker.isValidUUID (instanceIdMap.get ("vfModuleInstanceId"))) {
54 throw new ValidationException ("vfModuleInstanceId");
56 sir.setVfModuleInstanceId(instanceIdMap.get("vfModuleInstanceId"));
59 if(instanceIdMap.get("volumeGroupInstanceId") != null){
60 if (!UUIDChecker.isValidUUID (instanceIdMap.get ("volumeGroupInstanceId"))) {
61 throw new ValidationException ("volumeGroupInstanceId");
63 sir.setVolumeGroupInstanceId(instanceIdMap.get("volumeGroupInstanceId"));
66 if(instanceIdMap.get("networkInstanceId") != null){
67 if (!UUIDChecker.isValidUUID (instanceIdMap.get ("networkInstanceId"))) {
68 throw new ValidationException ("networkInstanceId");
70 sir.setNetworkInstanceId(instanceIdMap.get("networkInstanceId"));
73 if(instanceIdMap.get("configurationInstanceId") != null){
74 if (!UUIDChecker.isValidUUID (instanceIdMap.get ("configurationInstanceId"))) {
75 throw new ValidationException ("configurationInstanceId");
77 sir.setConfigurationId(instanceIdMap.get("configurationInstanceId"));
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);
84 sir.setInstanceGroupId(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_ID));