Containerization feature of SO
[so.git] / mso-api-handlers / mso-api-handler-infra / src / main / java / org / onap / so / apihandlerinfra / validation / UserParamsValidation.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.ArrayList;
25 import java.util.List;
26
27 import org.onap.so.apihandlerinfra.Action;
28 import org.onap.so.apihandlerinfra.Actions;
29 import org.onap.so.exceptions.ValidationException;
30 import org.onap.so.serviceinstancebeans.Networks;
31 import org.onap.so.serviceinstancebeans.Service;
32 import org.onap.so.serviceinstancebeans.VfModules;
33 import org.onap.so.serviceinstancebeans.Vnfs;
34
35 public class UserParamsValidation implements ValidationRule{
36     private static boolean empty(String s) {
37           return (s == null || s.trim().isEmpty());
38     }
39         @Override
40         public ValidationInformation validate(ValidationInformation info) throws ValidationException{
41                 Service validate = info.getUserParams();
42                 Actions action = info.getAction();
43                 
44                 if(validate.getModelInfo() == null){
45                         throw new ValidationException ("model-info in userParams");
46                 }else if(validate.getModelInfo().getModelVersionId() == null){
47                         throw new ValidationException("modelVersionId in userParams");
48                 }
49                 for(Vnfs vnf : validate.getResources().getVnfs()){
50                         if(vnf.getModelInfo() == null){
51                                 throw new ValidationException ("model-info in userParams vnf resources");
52                         }else if(vnf.getModelInfo().getModelCustomizationId() == null){
53                                 throw new ValidationException ("modelCustomizationId in userParams vnf resources");
54                         }else if(vnf.getModelInfo().getModelVersionId() == null){
55                                 throw new ValidationException("modelVersionId in userParams vnf resources");
56                         }
57                         if(vnf.getCloudConfiguration() == null){
58                                 throw new ValidationException ("cloudConfiguration in userParams vnf resources");
59                         }
60                         if(action == Action.createInstance || action == Action.assignInstance){
61                                 if(vnf.getPlatform() == null){
62                                         throw new ValidationException ("platform in userParams vnf resources");
63                                 }if(vnf.getProductFamilyId() == null){
64                                         throw new ValidationException ("productFamilyId in userParams vnf resources");
65                                 }
66                         }
67                         if (vnf.getPlatform() != null && vnf.getPlatform().getPlatformName() == null){
68                                 throw new ValidationException ("platformName in userParams vnf resources");
69                         }
70                         if(vnf.getVfModules().isEmpty()){
71                                 throw new ValidationException ("vfModules in userParams vnf resources");
72                         }
73                         for(VfModules vfModules : vnf.getVfModules()){
74                                 if(vfModules.getModelInfo() == null){
75                                         throw new ValidationException ("model-info in userParams vfModules resources");
76                                 }else if(vfModules.getModelInfo().getModelCustomizationId() == null){
77                                         throw new ValidationException ("modelCustomizationId in userParams vfModule resources");
78                                 }else if(vfModules.getModelInfo().getModelVersionId() == null){
79                                         throw new ValidationException("modelVersionId in userParams vfModule resources");
80                                 }
81                         }
82                 }
83                 
84                 List<Networks> validateNetworks = new ArrayList<>();
85                 validateNetworks = validate.getResources().getNetworks();
86                 if(validateNetworks != null){
87                         for(Networks networks : validateNetworks){
88                                 if(networks.getModelInfo() == null){
89                                         throw new ValidationException ("model-info in userParams network resources");
90                                 }else if(networks.getModelInfo().getModelCustomizationId() == null){
91                                         throw new ValidationException ("modelCustomizationId in userParams network resources");
92                                 }else if(networks.getModelInfo().getModelVersionId() == null){
93                                         throw new ValidationException("modelVersionId in userParams network resources");
94                                 }
95                                 if(networks.getCloudConfiguration() == null){
96                                         throw new ValidationException ("cloudConfiguration in userParams network resources");
97                                 }
98                         }
99                 } 
100                 return info;
101         }
102 }