0b438a1b17ee3ed9db9295fded12584419f50802
[so.git] /
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.Map;
25
26 import org.onap.so.apihandlerinfra.Action;
27 import org.onap.so.apihandlerinfra.Actions;
28 import org.onap.so.exceptions.ValidationException;
29 import org.onap.so.serviceinstancebeans.ModelType;
30 import org.onap.so.serviceinstancebeans.RequestParameters;
31
32 public class RequestParametersValidation implements ValidationRule{
33         private static boolean empty(String s) {
34           return (s == null || s.trim().isEmpty());
35     }
36         @Override
37         public ValidationInformation validate(ValidationInformation info) throws ValidationException{
38                 int reqVersion = info.getReqVersion();
39                 String requestScope = info.getRequestScope();
40                 Actions action = info.getAction();
41                 RequestParameters requestParameters = info.getReqParameters(); 
42               
43                 if (requestScope.equalsIgnoreCase(ModelType.service.name()) && (action == Action.createInstance || action == Action.assignInstance)) {
44                 if (requestParameters == null) {
45                         throw new ValidationException ("requestParameters");
46                 }
47                 if (empty (requestParameters.getSubscriptionServiceType())) {
48                         throw new ValidationException ("subscriptionServiceType");
49                 }
50         }
51                 if(reqVersion >= 4){
52                 if(Action.addRelationships.equals(action) || Action.removeRelationships.equals(action)) {
53                         if(requestParameters == null || requestParameters.getALaCarte() == null) {
54                                 throw new ValidationException ("aLaCarte in requestParameters");
55                         }
56                 }
57         }
58                 if(requestParameters == null && !requestScope.equalsIgnoreCase(ModelType.service.name())){
59                         info.setALaCarteFlag(true);
60                 }
61         if(requestParameters != null){
62                 if(requestScope.equalsIgnoreCase(ModelType.vnf.name())){
63                         if(action == Action.updateInstance){
64                                 if(requestParameters.isUsePreload() == null){
65                                         requestParameters.setUsePreload(true);
66                                 }
67                         }
68                         if(action == Action.replaceInstance){
69                                 if(requestParameters.getRebuildVolumeGroups() == null){
70                                         requestParameters.setRebuildVolumeGroups(false);
71                                 }
72                         }
73                 }
74                 if(requestScope.equalsIgnoreCase(ModelType.vfModule.name())){
75                         if(action == Action.createInstance || action == Action.updateInstance){                         
76                                 if(requestParameters.isUsePreload() == null){                                   
77                                         if(reqVersion >= 4){                                            
78                                                 if (requestParameters.getALaCarte() == false) {                                                 
79                                                         requestParameters.setUsePreload(false);
80                                                 }
81                                                 else {                                                  
82                                                         requestParameters.setUsePreload(true);
83                                                 }
84                                         }
85                                         else {                                  
86                                                 requestParameters.setUsePreload(true);
87                                         }
88                                 }
89                         }
90                 }
91                 if(reqVersion >= 4){
92                        if(requestParameters.getALaCarte() != null){
93                                 info.setALaCarteFlag(requestParameters.getALaCarte());
94                        }else if(requestScope.equalsIgnoreCase(ModelType.service.name())){
95                            if(action == Action.createInstance || action == Action.deleteInstance || action == Action.activateInstance || action == Action.deactivateInstance){
96                                    if(requestParameters.getALaCarte() == null){
97                                            requestParameters.setaLaCarte(false);
98                                            info.setALaCarteFlag(requestParameters.getALaCarte());
99                                    }
100                            }
101                        }else{
102                            info.setALaCarteFlag(true);
103                        }
104                 }else{
105                         info.setALaCarteFlag(true);
106                 }
107         }
108                 return info;
109         }
110 }