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;
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;
30 public class InstanceIdMapValidation implements ValidationRule {
32 private static final String Service_InstanceId = "serviceInstanceId";
33 private static final String Vnf_InstanceId = "vnfInstanceId";
34 private static final String vfModule_InstanceId = "vfModuleInstanceId";
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";
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);
49 sir.setServiceInstanceId(instanceIdMap.get(Service_InstanceId));
52 if (instanceIdMap.get(Vnf_InstanceId) != null) {
53 if (!UUIDChecker.isValidUUID(instanceIdMap.get(Vnf_InstanceId))) {
54 throw new ValidationException(Vnf_InstanceId);
56 sir.setVnfInstanceId(instanceIdMap.get(Vnf_InstanceId));
59 if (instanceIdMap.get(vfModule_InstanceId) != null) {
60 if (!UUIDChecker.isValidUUID(instanceIdMap.get(vfModule_InstanceId))) {
61 throw new ValidationException(vfModule_InstanceId);
63 sir.setVfModuleInstanceId(instanceIdMap.get(vfModule_InstanceId));
66 if (instanceIdMap.get(volume_Group_InstanceId) != null) {
67 if (!UUIDChecker.isValidUUID(instanceIdMap.get(volume_Group_InstanceId))) {
68 throw new ValidationException(volume_Group_InstanceId);
70 sir.setVolumeGroupInstanceId(instanceIdMap.get(volume_Group_InstanceId));
73 if (instanceIdMap.get(Network_Instance_Id) != null) {
74 if (!UUIDChecker.isValidUUID(instanceIdMap.get(Network_Instance_Id))) {
75 throw new ValidationException(Network_Instance_Id);
77 sir.setNetworkInstanceId(instanceIdMap.get(Network_Instance_Id));
80 if (instanceIdMap.get(Configuration_Instance_Id) != null) {
81 if (!UUIDChecker.isValidUUID(instanceIdMap.get(Configuration_Instance_Id))) {
82 throw new ValidationException(Configuration_Instance_Id);
84 sir.setConfigurationId(instanceIdMap.get(Configuration_Instance_Id));
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);
91 sir.setInstanceGroupId(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID));