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;
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 PNF_NAME = "pnfName";
35 private static final String vfModule_InstanceId = "vfModuleInstanceId";
37 private static final String volume_Group_InstanceId = "volumeGroupInstanceId";
38 private static final String Network_Instance_Id = "networkInstanceId";
39 private static final String Configuration_Instance_Id = "configurationInstanceId";
42 public ValidationInformation validate(ValidationInformation info) throws ValidationException {
43 Map<String, String> instanceIdMap = info.getInstanceIdMap();
44 ServiceInstancesRequest sir = info.getSir();
45 if (instanceIdMap != null) {
46 if (instanceIdMap.get(Service_InstanceId) != null) {
47 if (!UUIDChecker.isValidUUID(instanceIdMap.get(Service_InstanceId))) {
48 throw new ValidationException(Service_InstanceId);
50 sir.setServiceInstanceId(instanceIdMap.get(Service_InstanceId));
53 if (instanceIdMap.get(Vnf_InstanceId) != null) {
54 if (!UUIDChecker.isValidUUID(instanceIdMap.get(Vnf_InstanceId))) {
55 throw new ValidationException(Vnf_InstanceId);
57 sir.setVnfInstanceId(instanceIdMap.get(Vnf_InstanceId));
60 if (instanceIdMap.get(vfModule_InstanceId) != null) {
61 if (!UUIDChecker.isValidUUID(instanceIdMap.get(vfModule_InstanceId))) {
62 throw new ValidationException(vfModule_InstanceId);
64 sir.setVfModuleInstanceId(instanceIdMap.get(vfModule_InstanceId));
67 if (instanceIdMap.get(volume_Group_InstanceId) != null) {
68 if (!UUIDChecker.isValidUUID(instanceIdMap.get(volume_Group_InstanceId))) {
69 throw new ValidationException(volume_Group_InstanceId);
71 sir.setVolumeGroupInstanceId(instanceIdMap.get(volume_Group_InstanceId));
74 if (instanceIdMap.get(Network_Instance_Id) != null) {
75 if (!UUIDChecker.isValidUUID(instanceIdMap.get(Network_Instance_Id))) {
76 throw new ValidationException(Network_Instance_Id);
78 sir.setNetworkInstanceId(instanceIdMap.get(Network_Instance_Id));
81 if (instanceIdMap.get(Configuration_Instance_Id) != null) {
82 if (!UUIDChecker.isValidUUID(instanceIdMap.get(Configuration_Instance_Id))) {
83 throw new ValidationException(Configuration_Instance_Id);
85 sir.setConfigurationId(instanceIdMap.get(Configuration_Instance_Id));
88 if (instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID) != null) {
89 if (!UUIDChecker.isValidUUID(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID))) {
90 throw new ValidationException(CommonConstants.INSTANCE_GROUP_INSTANCE_ID, true);
92 sir.setInstanceGroupId(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID));
95 if (instanceIdMap.get(PNF_NAME) != null) {
96 sir.setPnfName(instanceIdMap.get(PNF_NAME));