Merge "Fix resource looping if AAI response empty"
[so.git] / mso-api-handlers / mso-api-handler-infra / src / main / java / org / openecomp / mso / apihandlerinfra / MsoRequest.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.openecomp.mso.apihandlerinfra;
23
24 import java.io.IOException;
25 import java.io.StringWriter;
26 import java.sql.Timestamp;
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Map;
31 import java.util.Map.Entry;
32 import java.util.StringTokenizer;
33
34 import javax.ws.rs.core.MultivaluedMap;
35 import javax.ws.rs.core.Response;
36 import javax.xml.bind.JAXBContext;
37 import javax.xml.bind.JAXBException;
38 import javax.xml.bind.Marshaller;
39 import javax.xml.transform.OutputKeys;
40 import javax.xml.transform.Transformer;
41 import javax.xml.transform.TransformerFactory;
42 import javax.xml.transform.dom.DOMSource;
43 import javax.xml.transform.stream.StreamResult;
44
45 import org.hibernate.Session;
46 import org.openecomp.mso.apihandler.common.ValidationException;
47 import org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType;
48 import org.openecomp.mso.apihandlerinfra.vnfbeans.VnfInputs;
49 import org.openecomp.mso.apihandlerinfra.vnfbeans.VnfRequest;
50 import org.openecomp.mso.db.AbstractSessionFactoryManager;
51 import org.openecomp.mso.logger.MessageEnum;
52 import org.openecomp.mso.logger.MsoLogger;
53 import org.openecomp.mso.requestsdb.InfraActiveRequests;
54 import org.openecomp.mso.requestsdb.RequestsDatabase;
55 import org.openecomp.mso.requestsdb.RequestsDbSessionFactoryManager;
56 import org.openecomp.mso.serviceinstancebeans.CloudConfiguration;
57 import org.openecomp.mso.serviceinstancebeans.InstanceDirection;
58 import org.openecomp.mso.serviceinstancebeans.LineOfBusiness;
59 import org.openecomp.mso.serviceinstancebeans.ModelInfo;
60 import org.openecomp.mso.serviceinstancebeans.ModelType;
61 import org.openecomp.mso.serviceinstancebeans.OwningEntity;
62 import org.openecomp.mso.serviceinstancebeans.Platform;
63 import org.openecomp.mso.serviceinstancebeans.PolicyException;
64 import org.openecomp.mso.serviceinstancebeans.Project;
65 import org.openecomp.mso.serviceinstancebeans.RelatedInstance;
66 import org.openecomp.mso.serviceinstancebeans.RelatedInstanceList;
67 import org.openecomp.mso.serviceinstancebeans.RequestError;
68 import org.openecomp.mso.serviceinstancebeans.RequestInfo;
69 import org.openecomp.mso.serviceinstancebeans.RequestParameters;
70 import org.openecomp.mso.serviceinstancebeans.ServiceException;
71 import org.openecomp.mso.serviceinstancebeans.ServiceInstancesRequest;
72 import org.openecomp.mso.serviceinstancebeans.SubscriberInfo;
73 import org.openecomp.mso.utils.UUIDChecker;
74 import org.w3c.dom.Document;
75 import org.w3c.dom.Element;
76 import org.w3c.dom.Node;
77 import org.w3c.dom.NodeList;
78
79 import com.fasterxml.jackson.annotation.JsonInclude.Include;
80 import com.fasterxml.jackson.core.JsonGenerationException;
81 import com.fasterxml.jackson.databind.JsonMappingException;
82 import com.fasterxml.jackson.databind.ObjectMapper;
83
84 public class MsoRequest {
85
86     private String requestId;
87     private String requestXML;
88     private String requestUri;
89     private VnfRequest vnfReq;
90     private RequestInfo requestInfo;
91     private ModelInfo modelInfo;
92     private CloudConfiguration cloudConfiguration ;
93     private VnfInputs vnfInputs;
94     private String vnfParams;
95     private Action action;
96     private String errorMessage;
97     private String errorCode;
98     private String httpResponse;
99     private String responseBody;
100     private String originalRequestJSON;
101     private RequestStatusType status;
102     private ServiceInstancesRequest sir;
103     private long startTime;
104     private long progress = Constants.PROGRESS_REQUEST_RECEIVED;
105     private String serviceInstanceType;
106     private String vnfType;
107     private String vfModuleType;
108     private String vfModuleModelName;
109     private String networkType;
110     private String asdcServiceModelVersion;
111     private String requestScope;
112     private int reqVersion;
113     private boolean aLaCarteFlag;
114     private Platform platform;
115     private LineOfBusiness lineOfBusiness;
116     private Project project;
117     private OwningEntity owningEntity;
118
119     private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH);
120     protected AbstractSessionFactoryManager requestsDbSessionFactoryManager = new RequestsDbSessionFactoryManager ();
121
122     MsoRequest (String requestId) {
123         this.requestId = requestId;
124         this.startTime = System.currentTimeMillis();
125         MsoLogger.setLogContext (requestId, null);
126
127     }
128
129     MsoRequest () {
130
131         this.startTime = System.currentTimeMillis();
132         MsoLogger.setLogContext (requestId, null);
133
134     }
135
136
137     public Response buildServiceErrorResponse (int httpResponseCode,
138             MsoException exceptionType,
139             String text,
140             String messageId,
141             List<String> variables) {
142
143         this.errorCode = messageId;
144
145         if (text != null) {
146                 this.errorMessage = text;
147         }
148         else {
149                 this.errorMessage = "";
150         }
151         this.httpResponse = Integer.toString(httpResponseCode);
152         if(errorMessage.length() > 1999){
153             errorMessage = errorMessage.substring(0, 1999);
154         }
155
156         RequestError re = new RequestError();
157
158         if("PolicyException".equals(exceptionType.name())){
159
160                 PolicyException pe = new PolicyException();
161                 pe.setMessageId(messageId);
162                 pe.setText(text);
163                 if(variables != null){
164                         for(String variable: variables){
165                                 pe.getVariables().add(variable);
166                         }
167                 }
168                 re.setPolicyException(pe);
169
170         } else {
171
172                 ServiceException se = new ServiceException();
173                 se.setMessageId(messageId);
174                 se.setText(text);
175                 if(variables != null){
176                                 for(String variable: variables){
177                                         se.getVariables().add(variable);
178                                 }
179                         }
180                 re.setServiceException(se);
181         }
182
183         String requestErrorStr = null;
184
185         try{
186                 ObjectMapper mapper = new ObjectMapper();
187                 mapper.setSerializationInclusion(Include.NON_DEFAULT);
188                 requestErrorStr = mapper.writeValueAsString(re);
189         }catch(Exception e){
190                 msoLogger.error (MessageEnum.APIH_VALIDATION_ERROR, "", "", MsoLogger.ErrorCode.DataError, "Exception in buildServiceErrorResponse writing exceptionType to string ", e);
191         }
192
193
194         return Response.status (httpResponseCode).entity(requestErrorStr).build ();
195
196     }
197
198     private int reqVersionToInt(String version){
199         if(version!=null){
200                 return Integer.parseInt(version.substring(1));
201         }else{
202                 return 0;
203         }
204     }
205
206     // Parse request JSON
207     void parse (ServiceInstancesRequest sir, HashMap<String,String> instanceIdMap, Action action, String version, String originalRequestJSON) throws ValidationException {
208
209         msoLogger.debug ("Validating the Service Instance request");
210
211         this.sir = sir;
212         this.action = action;
213         this.reqVersion = reqVersionToInt(version);
214         this.originalRequestJSON = originalRequestJSON;
215         msoLogger.debug ("Incoming version is: " + version + " coverting to int: " + this.reqVersion);
216         
217         if(instanceIdMap != null){
218                 if(instanceIdMap.get("serviceInstanceId") != null){
219                         if (!UUIDChecker.isValidUUID (instanceIdMap.get ("serviceInstanceId"))) {
220                                 throw new ValidationException ("serviceInstanceId");
221                         }
222                         this.sir.setServiceInstanceId(instanceIdMap.get("serviceInstanceId"));
223                 }
224
225                 if(instanceIdMap.get("vnfInstanceId") != null){
226                         if (!UUIDChecker.isValidUUID (instanceIdMap.get ("vnfInstanceId"))) {
227                                 throw new ValidationException ("vnfInstanceId");
228                         }
229                         this.sir.setVnfInstanceId(instanceIdMap.get("vnfInstanceId"));
230                 }
231
232                 if(instanceIdMap.get("vfModuleInstanceId") != null){
233                         if (!UUIDChecker.isValidUUID (instanceIdMap.get ("vfModuleInstanceId"))) {
234                                 throw new ValidationException ("vfModuleInstanceId");
235                         }
236                         this.sir.setVfModuleInstanceId(instanceIdMap.get("vfModuleInstanceId"));
237                 }
238
239                 if(instanceIdMap.get("volumeGroupInstanceId") != null){
240                         if (!UUIDChecker.isValidUUID (instanceIdMap.get ("volumeGroupInstanceId"))) {
241                                 throw new ValidationException ("volumeGroupInstanceId");
242                         }
243                         this.sir.setVolumeGroupInstanceId(instanceIdMap.get("volumeGroupInstanceId"));
244                 }
245
246                 if(instanceIdMap.get("networkInstanceId") != null){
247                         if (!UUIDChecker.isValidUUID (instanceIdMap.get ("networkInstanceId"))) {
248                                 throw new ValidationException ("networkInstanceId");
249                         }
250                         this.sir.setNetworkInstanceId(instanceIdMap.get("networkInstanceId"));
251                 }
252                 
253                 if(instanceIdMap.get("configurationInstanceId") != null){
254                         if (!UUIDChecker.isValidUUID (instanceIdMap.get ("configurationInstanceId"))) {
255                                 throw new ValidationException ("configurationInstanceId");
256                         }
257                         this.sir.setConfigurationId(instanceIdMap.get("configurationInstanceId"));
258                 }
259         }
260         
261             if(reqVersion >= 6 && (action == Action.inPlaceSoftwareUpdate || action == Action.applyUpdatedConfig)){
262                 parsePayload(sir, action);
263         }
264         else{
265                 
266         RequestParameters requestParameters = sir.getRequestDetails().getRequestParameters();
267         
268         this.modelInfo = sir.getRequestDetails().getModelInfo();
269
270         if (this.modelInfo == null) {
271             throw new ValidationException ("model-info");
272         }
273
274         this.requestInfo = sir.getRequestDetails().getRequestInfo();
275
276         if (this.requestInfo == null) {
277             throw new ValidationException ("requestInfo");
278         }
279
280         if (modelInfo.getModelType () == null) {
281                 throw new ValidationException ("modelType");
282         }
283
284         this.requestScope = modelInfo.getModelType().name();
285         
286         if(this.reqVersion >= 4){
287                 if(Action.addRelationships.equals(action) || Action.removeRelationships.equals(action)) {
288                         if(requestParameters == null || requestParameters.getALaCarte() == null) {
289                                 throw new ValidationException ("aLaCarte in requestParameters");
290                         }
291                 }
292         }
293         
294         if(requestParameters != null){
295                 if(requestScope.equalsIgnoreCase(ModelType.vnf.name())){
296                         if(action == Action.createInstance){
297                                 if(requestParameters.getAutoBuildVfModules() == null){
298                                         requestParameters.setAutoBuildVfModules(false);
299                                 }
300                         }
301                         if(action == Action.deleteInstance){
302                                 if(requestParameters.getCascadeDelete() == null){
303                                         requestParameters.setCascadeDelete(false);
304                                 }
305                         }
306                         if(action == Action.updateInstance){
307                                 if(requestParameters.isUsePreload() == null){
308                                         requestParameters.setUsePreload(true);
309                                 }
310                         }
311                         if(action == Action.replaceInstance){
312                                 if(requestParameters.rebuildVolumeGroups() == null){
313                                         requestParameters.setRebuildVolumeGroups(false);
314                                 }
315                         }
316                 }
317                 if(requestScope.equalsIgnoreCase(ModelType.vfModule.name())){
318                         if(action == Action.createInstance || action == Action.updateInstance){
319                                 if(requestParameters.isUsePreload() == null){
320                                         requestParameters.setUsePreload(true);
321                                 }
322                         }
323                 }
324                 if(this.reqVersion >= 4){
325                        if(requestParameters.getALaCarte() != null){
326                                 this.aLaCarteFlag = requestParameters.getALaCarte();
327                        }
328                        if(requestScope.equalsIgnoreCase(ModelType.service.name())){
329                            if(action == Action.createInstance || action == Action.deleteInstance || action == Action.activateInstance || action == Action.deactivateInstance){
330                                    if(requestParameters.getALaCarte() == null){
331                                            requestParameters.setaLaCarte(false);
332                                            this.aLaCarteFlag = requestParameters.getALaCarte();
333                                    }
334                            }
335                        }
336                 }else{
337                         this.aLaCarteFlag = true;
338                 }
339         }
340         if(reqVersion >= 5 && requestScope.equalsIgnoreCase(ModelType.vnf.name()) && action == Action.createInstance){
341                 parsePlatformAndLineOfBusiness(sir);
342         }
343         // modelCustomizationId is required when usePreLoad is false for v4 and higher for VF Module Create
344         if(requestParameters != null && reqVersion >= 4 && requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && action == Action.createInstance && !requestParameters.isUsePreload()) {
345                 if(!UUIDChecker.isValidUUID(modelInfo.getModelCustomizationId())) {
346                         throw new ValidationException("modelCustomizationId");
347                 }
348         }
349         
350         // modelCustomizationId is required for v5 and higher for VF Module Replace
351         if(requestParameters != null && reqVersion > 4 && requestScope.equalsIgnoreCase(ModelType.vfModule.name()) && action == Action.replaceInstance) {
352                 if(!UUIDChecker.isValidUUID(modelInfo.getModelCustomizationId())) {
353                         throw new ValidationException("modelCustomizationId");
354                 }
355         }
356         
357         // modelCustomizationId or modelCustomizationName are required for VNF Replace
358         if(requestParameters != null && reqVersion > 4 && requestScope.equalsIgnoreCase(ModelType.vnf.name()) && action == Action.replaceInstance) {
359                 if(!UUIDChecker.isValidUUID(modelInfo.getModelCustomizationId()) && modelInfo.getModelCustomizationName() == null) {
360                         throw new ValidationException("modelCustomizationId or modelCustomizationName");
361                 }
362         }
363
364         //is required for serviceInstance delete macro when aLaCarte=false (v3)
365         //create and updates except for network (except v4)
366         if (empty (modelInfo.getModelInvariantId ()) && ((this.reqVersion >2 && !this.aLaCarteFlag && requestScope.equalsIgnoreCase(ModelType.service.name()) && action == Action.deleteInstance) ||
367                 !(this.reqVersion < 4 && requestScope.equalsIgnoreCase (ModelType.network.name ())) && 
368                 (action == Action.createInstance || action == Action.updateInstance || action == Action.enablePort || action == Action.disablePort || action == Action.addRelationships || action == Action.removeRelationships ||
369                 (requestScope.equalsIgnoreCase(ModelType.configuration.name()) && (action == Action.activateInstance || action == Action.deactivateInstance))))) {
370                 throw new ValidationException ("modelInvariantId");
371         }
372
373         if (!empty (modelInfo.getModelInvariantId ()) && !UUIDChecker.isValidUUID (modelInfo.getModelInvariantId ())) {
374                 throw new ValidationException ("modelInvariantId format");
375         }
376
377         if(this.reqVersion >= 4 && !(requestScope.equalsIgnoreCase(ModelType.configuration.name())) && empty (modelInfo.getModelName ()) && (action == Action.createInstance || action == Action.updateInstance || 
378                         action == Action.addRelationships || action == Action.removeRelationships || (action == Action.deleteInstance && (requestScope.equalsIgnoreCase (ModelType.vfModule.name ()))))){
379                 throw new ValidationException ("modelName");
380         }
381
382         if (empty (modelInfo.getModelVersion ()) && !(requestScope.equalsIgnoreCase(ModelType.configuration.name())) && 
383                         (!(this.reqVersion < 4 && requestScope.equalsIgnoreCase (ModelType.network.name ())) 
384                                         && (action == Action.createInstance || action == Action.updateInstance || action == Action.addRelationships || action == Action.removeRelationships))) {
385                 throw new ValidationException ("modelVersion");
386         }
387
388         // is required for serviceInstance delete macro when aLaCarte=false in v4
389         if (this.reqVersion >= 4 && empty (modelInfo.getModelVersionId()) && ((!this.aLaCarteFlag && requestScope.equalsIgnoreCase(ModelType.service.name()) && action == Action.deleteInstance) ||
390                         (action == Action.createInstance || action == Action.updateInstance || action == Action.enablePort || action == Action.disablePort || action == Action.addRelationships || action == Action.removeRelationships ||
391                         (requestScope.equalsIgnoreCase(ModelType.configuration.name()) && (action == Action.activateInstance || action == Action.deactivateInstance))))) {
392                 throw new ValidationException ("modelVersionId");
393          }
394         
395         if(requestScope.equalsIgnoreCase(ModelType.vnf.name()) && action != Action.deleteInstance && empty (modelInfo.getModelCustomizationName ())) {
396                 if (!UUIDChecker.isValidUUID (modelInfo.getModelCustomizationId())) {
397                         throw new ValidationException ("modelCustomizationId or modelCustomizationName");
398                 }
399         }
400
401         if(this.reqVersion >= 4 && (!UUIDChecker.isValidUUID (modelInfo.getModelCustomizationId())) && (requestScope.equalsIgnoreCase (ModelType.network.name ()) || requestScope.equalsIgnoreCase(ModelType.configuration.name()))
402                         && (action == Action.updateInstance || action == Action.createInstance)){
403                 throw new ValidationException ("modelCustomizationId");
404         }
405
406         if(!empty(modelInfo.getModelNameVersionId())){
407                 modelInfo.setModelVersionId(modelInfo.getModelNameVersionId());
408         }
409
410         this.cloudConfiguration = sir.getRequestDetails ().getCloudConfiguration ();
411         if ( (((!this.aLaCarteFlag && requestScope.equalsIgnoreCase (ModelType.service.name ()) && this.reqVersion < 5) || 
412                         (!requestScope.equalsIgnoreCase (ModelType.service.name ())) && action != Action.updateInstance)) 
413                         && cloudConfiguration == null) {
414                 throw new ValidationException ("cloudConfiguration");
415         }
416
417         if (cloudConfiguration != null) {
418                 if (empty (cloudConfiguration.getLcpCloudRegionId ())) {
419                         throw new ValidationException ("lcpCloudRegionId");
420                 }
421                 if (empty (cloudConfiguration.getTenantId ()) && !(requestScope.equalsIgnoreCase(ModelType.configuration.name()))) {
422                         throw new ValidationException ("tenantId");
423                 }
424         }
425
426
427         if (requestScope.equalsIgnoreCase(ModelType.service.name()) && action == Action.createInstance) {
428                 if (requestParameters == null) {
429                         throw new ValidationException ("requestParameters");
430                 }
431                 if (empty (requestParameters.getSubscriptionServiceType())) {
432                         throw new ValidationException ("subscriptionServiceType");
433                 }
434         }
435         if(this.reqVersion >= 5 && requestScope.equalsIgnoreCase(ModelType.service.name()) && action == Action.createInstance){
436                 parseProjectAndOwningEntity(sir);
437         }
438         if (this.reqVersion > 4 && requestScope.equalsIgnoreCase (ModelType.service.name ()) && action == Action.createInstance) {
439                 SubscriberInfo subscriberInfo = sir.getRequestDetails ().getSubscriberInfo();
440                 if (subscriberInfo == null) {
441                         throw new ValidationException ("subscriberInfo");
442                 }
443                 if (empty (subscriberInfo.getGlobalSubscriberId ())) {
444                         throw new ValidationException ("globalSubscriberId");
445                 }
446         }
447
448         if(requestScope.equalsIgnoreCase(ModelType.service.name())){
449                 this.serviceInstanceType = modelInfo.getModelName();
450         }
451
452         if(requestScope.equalsIgnoreCase(ModelType.network.name())){
453                 this.networkType = modelInfo.getModelName();
454         }
455
456         if (!empty (requestInfo.getInstanceName ())) {
457                 if (!requestInfo.getInstanceName ().matches (Constants.VALID_INSTANCE_NAME_FORMAT)) {
458                         throw new ValidationException ("instanceName format");
459                 }
460         }
461
462         if (empty (requestInfo.getProductFamilyId ()))  {
463                 // Mandatory for vnf Create(aLaCarte=true), Network Create(aLaCarte=true) and network update
464                 //Mandatory for macro request create service instance
465                 if((requestScope.equalsIgnoreCase (ModelType.vnf.name ()) && action == Action.createInstance) || 
466                         (requestScope.equalsIgnoreCase (ModelType.network.name ()) && (action == Action.createInstance || action == Action.updateInstance)) ||
467                                 (this.reqVersion > 3 && !this.aLaCarteFlag && requestScope.equalsIgnoreCase(ModelType.service.name()) && action == Action.createInstance)) {
468                 throw new ValidationException ("productFamilyId");
469         }
470         }
471        
472         //required for all operations in V4
473         if(empty(requestInfo.getRequestorId()) && this.reqVersion >= 4) {
474                 throw new ValidationException ("requestorId");
475         }
476
477         if (empty (requestInfo.getSource ())) {
478                 throw new ValidationException ("source");
479         }
480
481         RelatedInstanceList[] instanceList = sir.getRequestDetails().getRelatedInstanceList();
482
483         String serviceModelName = null;
484         String vnfModelName = null;
485         String asdcServiceModelVersion = null;
486         String volumeGroupId = null;
487         boolean isRelatedServiceInstancePresent = false;
488         boolean isRelatedVnfInstancePresent = false;
489         boolean isSourceVnfPresent = false;
490         boolean isDestinationVnfPresent = false;
491         boolean isConnectionPointPresent = false;
492
493         if (instanceList != null) {
494                 for(RelatedInstanceList relatedInstanceList : instanceList){
495                         RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance();
496
497                         ModelInfo relatedInstanceModelInfo = relatedInstance.getModelInfo ();
498                                 if (relatedInstanceModelInfo == null) {
499                                 throw new ValidationException ("modelInfo in relatedInstance");
500                         }
501
502                         if (relatedInstanceModelInfo.getModelType () == null) {
503                                 throw new ValidationException ("modelType in relatedInstance");
504                         }
505
506                         if(empty(relatedInstance.getInstanceName ()) && ModelType.pnf.equals(relatedInstanceModelInfo.getModelType())) {
507                                 throw new ValidationException ("instanceName in relatedInstance for pnf modelType");
508                         }
509                         
510                         if (!empty (relatedInstance.getInstanceName ())) {
511                         if (!relatedInstance.getInstanceName ().matches (Constants.VALID_INSTANCE_NAME_FORMAT)) {
512                                 throw new ValidationException ("instanceName format in relatedInstance");
513                         }
514                     }
515
516                         if (empty (relatedInstance.getInstanceId ()) && !ModelType.pnf.equals(relatedInstanceModelInfo.getModelType())) {
517                                 throw new ValidationException ("instanceId in relatedInstance");
518                         }
519
520                         if (!empty(relatedInstance.getInstanceId ()) && !UUIDChecker.isValidUUID (relatedInstance.getInstanceId ())) {
521                                 throw new ValidationException ("instanceId format in relatedInstance");
522                         }
523
524
525                         if (action != Action.deleteInstance) {
526                                 if(!(   relatedInstanceModelInfo.getModelType().equals(ModelType.volumeGroup) || 
527                                                 relatedInstanceModelInfo.getModelType().equals(ModelType.connectionPoint) ||
528                                                 relatedInstanceModelInfo.getModelType().equals(ModelType.pnf))) {
529
530                                         if(empty (relatedInstanceModelInfo.getModelInvariantId ())) {
531                                                 throw new ValidationException ("modelInvariantId in relatedInstance");
532                                         } else if(this.reqVersion >= 4 && empty(relatedInstanceModelInfo.getModelVersionId ())) {
533                                                 throw new ValidationException("modelVersionId in relatedInstance");
534                                         } else if(empty(relatedInstanceModelInfo.getModelName ())) {
535                                                 throw new ValidationException ("modelName in relatedInstance");
536                                         } else if (empty (relatedInstanceModelInfo.getModelVersion ())) {
537                                                 throw new ValidationException ("modelVersion in relatedInstance");
538                                         }
539                                 }
540
541                                 if (!empty (relatedInstanceModelInfo.getModelInvariantId ()) &&
542                                                 !UUIDChecker.isValidUUID (relatedInstanceModelInfo.getModelInvariantId ())) {
543                                         throw new ValidationException ("modelInvariantId format in relatedInstance");
544                                 }
545                                 
546                                 if(ModelType.configuration.name().equalsIgnoreCase(requestScope)) {
547                                         if(InstanceDirection.source.equals(relatedInstance.getInstanceDirection()) && relatedInstanceModelInfo.getModelType().equals(ModelType.vnf)) {
548                                                 isSourceVnfPresent = true;
549                                         } else if(InstanceDirection.destination.equals(relatedInstance.getInstanceDirection()) && 
550                                                         (relatedInstanceModelInfo.getModelType().equals(ModelType.vnf) || (relatedInstanceModelInfo.getModelType().equals(ModelType.pnf) && this.reqVersion == 6))) {
551                                                 isDestinationVnfPresent = true;
552                                         }
553                                 }
554                                 
555                                 if(ModelType.connectionPoint.equals(relatedInstanceModelInfo.getModelType()) && ModelType.configuration.name().equalsIgnoreCase(requestScope)) {
556                                         isConnectionPointPresent = true;
557                                 }
558                         }
559
560                         if (empty (relatedInstanceModelInfo.getModelCustomizationName ()) && relatedInstanceModelInfo.getModelType ().equals (ModelType.vnf) ) {
561                                 if(this.reqVersion >=4 && empty (relatedInstanceModelInfo.getModelCustomizationId()) && action != Action.deleteInstance) {
562                                         throw new ValidationException ("modelCustomizationName or modelCustomizationId in relatedInstance of vnf");
563                                 }
564                         }
565
566                         if(relatedInstanceModelInfo.getModelType().equals(ModelType.service)) {
567                                 isRelatedServiceInstancePresent = true;
568                                 if (!relatedInstance.getInstanceId ().equals (this.sir.getServiceInstanceId ())) {
569                                         throw new ValidationException ("serviceInstanceId matching the serviceInstanceId in request URI");
570                                 }
571                                 serviceModelName = relatedInstanceModelInfo.getModelName ();
572                                 asdcServiceModelVersion = relatedInstanceModelInfo.getModelVersion ();
573                         } else if(relatedInstanceModelInfo.getModelType().equals(ModelType.vnf) && !(ModelType.configuration.name().equalsIgnoreCase(requestScope))) {
574                                 isRelatedVnfInstancePresent = true;
575                                 if (!relatedInstance.getInstanceId ().equals (this.sir.getVnfInstanceId ())) {
576                                         throw new ValidationException ("vnfInstanceId matching the vnfInstanceId in request URI");
577                                 }
578                                 vnfModelName = relatedInstanceModelInfo.getModelCustomizationName();
579                         } else if(relatedInstanceModelInfo.getModelType().equals(ModelType.volumeGroup)) {                              
580                                 volumeGroupId = relatedInstance.getInstanceId ();
581                         }
582                 }
583
584                 if(action == Action.createInstance && ModelType.configuration.name().equalsIgnoreCase(requestScope)) {
585                         if(!isSourceVnfPresent) {
586                                 throw new ValidationException ("source vnf relatedInstance for Port Configuration");
587                         } 
588                         
589                         if(!isDestinationVnfPresent) {
590                                 throw new ValidationException ("destination vnf relatedInstance for Port Configuration");
591                         }
592                 }
593
594                 if((action == Action.enablePort || action == Action.disablePort) && ModelType.configuration.name().equalsIgnoreCase(requestScope)) {
595                         if(!isConnectionPointPresent) {
596                                 throw new ValidationException ("connectionPoint relatedInstance for Port Configuration");
597                         }
598                 }
599                 
600                 if(requestScope.equalsIgnoreCase (ModelType.volumeGroup.name ())) {
601                         if (!isRelatedServiceInstancePresent) {
602                                 throw new ValidationException ("related service instance for volumeGroup request");
603                         }
604                         if (!isRelatedVnfInstancePresent) {
605                                 throw new ValidationException ("related vnf instance for volumeGroup request");
606                         }
607                         this.serviceInstanceType = serviceModelName;
608                         this.vnfType = serviceModelName + "/" + vnfModelName;
609                         this.asdcServiceModelVersion = asdcServiceModelVersion;
610                 }
611                 else if(requestScope.equalsIgnoreCase(ModelType.vfModule.name ())) {
612                         if (!isRelatedServiceInstancePresent) {
613                                 throw new ValidationException ("related service instance for vfModule request");
614                         }
615                         if (!isRelatedVnfInstancePresent) {
616                                 throw new ValidationException ("related vnf instance for vfModule request");
617                         }
618                         String vfModuleModelName = modelInfo.getModelName ();
619                         this.vfModuleModelName = vfModuleModelName;
620                         this.serviceInstanceType = serviceModelName;
621                         this.vnfType = serviceModelName + "/" + vnfModelName;
622                         this.asdcServiceModelVersion = asdcServiceModelVersion;
623                         this.vfModuleType = vnfType + "::" + vfModuleModelName;
624                         this.sir.setVolumeGroupInstanceId (volumeGroupId);
625                 }
626                 else if (requestScope.equalsIgnoreCase (ModelType.vnf.name ())) {
627                         if (!isRelatedServiceInstancePresent) {
628                                 throw new ValidationException ("related service instance for vnf request");
629                         }
630                         this.vnfType = serviceModelName + "/" + sir.getRequestDetails().getModelInfo().getModelCustomizationName();
631                }
632         }
633         else if ((( requestScope.equalsIgnoreCase(ModelType.vnf.name ()) || requestScope.equalsIgnoreCase(ModelType.volumeGroup.name ()) || requestScope.equalsIgnoreCase(ModelType.vfModule.name ()) 
634                                 || requestScope.equalsIgnoreCase(ModelType.configuration.name())) && (action == Action.createInstance || action == Action.enablePort || action == Action.disablePort)) ||
635                         (this.reqVersion >= 4 && (requestScope.equalsIgnoreCase(ModelType.volumeGroup.name ()) || requestScope.equalsIgnoreCase(ModelType.vfModule.name ())) && action == Action.updateInstance) ||
636                                 (requestScope.equalsIgnoreCase(ModelType.service.name()) && (action.equals(Action.addRelationships) || action.equals(Action.removeRelationships)))){
637                  msoLogger.debug ("related instance exception");
638                 throw new ValidationException ("related instances");
639         }
640        }
641     }
642     void parsePayload(ServiceInstancesRequest sir, Action action) throws ValidationException{
643         msoLogger.debug("Validating for requestParameters and payload");
644         this.sir = sir;
645         this.action = action;
646         this.requestScope = ModelType.vnf.name();
647         RequestParameters requestParameters = sir.getRequestDetails().getRequestParameters();
648         this.cloudConfiguration = sir.getRequestDetails ().getCloudConfiguration();
649         this.requestInfo = sir.getRequestDetails().getRequestInfo();
650    
651         if(action == Action.inPlaceSoftwareUpdate){
652                 if (cloudConfiguration == null) {
653                         throw new ValidationException ("cloudConfiguration");
654                 }else if (empty (cloudConfiguration.getLcpCloudRegionId ())) {
655                         throw new ValidationException ("lcpCloudRegionId");
656                 }else if (empty (cloudConfiguration.getTenantId ())) {
657                         throw new ValidationException ("tenantId");
658                 }
659         }
660         if(requestInfo == null){
661                 throw new ValidationException("requestInfo");
662         }else if(empty(requestInfo.getRequestorId())) {
663                 throw new ValidationException ("requestorId");
664         }else if (empty (requestInfo.getSource ())) {
665                 throw new ValidationException ("source");
666         }
667         if(requestParameters == null){
668                 throw new ValidationException("requestParameters");
669         }
670     }
671     void parsePlatformAndLineOfBusiness(ServiceInstancesRequest sir) throws ValidationException {
672         msoLogger.debug("Validating Platform and LineOfBusiness Objects");
673         this.sir = sir;
674         platform = sir.getRequestDetails().getPlatform();
675         lineOfBusiness = sir.getRequestDetails().getLineOfBusiness();
676    
677         if(this.reqVersion > 5 && platform == null) {
678                 throw new ValidationException("platform");
679         }
680         
681         if(platform != null && empty(platform.getPlatformName())){
682                 throw new ValidationException("platformName");
683         }
684         
685         if(lineOfBusiness != null && empty(lineOfBusiness.getLineOfBusinessName())){
686                 throw new ValidationException("lineOfBusinessName");
687         }
688     }
689     
690     void parseProjectAndOwningEntity(ServiceInstancesRequest sir) throws ValidationException {
691         msoLogger.debug("Validating Project and OwningEntity Objects");
692         this.sir = sir;
693         this.project = sir.getRequestDetails().getProject();
694         this.owningEntity = sir.getRequestDetails().getOwningEntity();
695         
696         if(this.reqVersion > 5 && owningEntity == null) {
697                 throw new ValidationException("owningEntity");
698         }
699         
700         if(owningEntity != null && empty(owningEntity.getOwningEntityId())){
701                         throw new ValidationException("owningEntityId");
702                 }
703         
704         if(project != null && empty(project.getProjectName())){
705                         throw new ValidationException("projectName");
706                 }
707     }
708     
709     void parseOrchestration (ServiceInstancesRequest sir) throws ValidationException {
710
711         msoLogger.debug ("Validating the Orchestration request");
712
713         this.sir = sir;
714         this.requestInfo = sir.getRequestDetails().getRequestInfo();
715
716         if (this.requestInfo == null) {
717             throw new ValidationException ("requestInfo");
718         }
719
720         if (empty (requestInfo.getSource ())) {
721                 throw new ValidationException ("source");
722         }
723         if (empty (requestInfo.getRequestorId ())) {
724                 throw new ValidationException ("requestorId");
725         }
726     }
727
728     public Map<String, List<String>> getOrchestrationFilters (MultivaluedMap<String, String> queryParams) throws ValidationException {
729
730         String queryParam = null;
731         Map<String, List<String>> orchestrationFilterParams = new HashMap<>();
732
733
734         for (Entry<String,List<String>> entry : queryParams.entrySet()) {
735             queryParam = entry.getKey();
736
737             try{
738                   if("filter".equalsIgnoreCase(queryParam)){
739                           for(String value : entry.getValue()) {
740                                   StringTokenizer st = new StringTokenizer(value, ":");
741         
742                                   int counter=0;
743                                   String mapKey=null;
744                                   List<String> orchestrationList = new ArrayList<>();
745                                   while (st.hasMoreElements()) {
746                                           if(counter == 0){
747                                                   mapKey = st.nextElement() + "";
748                                           } else{
749                                                   orchestrationList.add(st.nextElement() + "");
750                                           }
751                                          counter++;
752                                   }
753                                   orchestrationFilterParams.put(mapKey, orchestrationList);
754                           }
755                   }
756
757             }catch(Exception e){
758                 //msoLogger.error (MessageEnum.APIH_VALIDATION_ERROR, e);
759                 throw new ValidationException ("QueryParam ServiceInfo", e);
760
761                 }
762
763         }
764
765
766         return orchestrationFilterParams;
767   }
768
769     public void createRequestRecord (Status status, Action action) {
770
771         Session session = null;
772         try {
773
774             session = requestsDbSessionFactoryManager.getSessionFactory ().openSession ();
775             session.beginTransaction ();
776
777             if (null == sir) {
778                 sir = new ServiceInstancesRequest ();
779             }
780
781             InfraActiveRequests aq = new InfraActiveRequests ();
782             aq.setRequestId (requestId);
783
784             aq.setRequestAction(action.name());
785             aq.setAction(action.name());
786
787             Timestamp startTimeStamp = new Timestamp (System.currentTimeMillis());
788
789             aq.setStartTime (startTimeStamp);
790
791             if (requestInfo != null) {
792
793                 if(requestInfo.getSource() != null){
794                         aq.setSource(requestInfo.getSource());
795                 }
796                 if(requestInfo.getCallbackUrl() != null){
797                         aq.setCallBackUrl(requestInfo.getCallbackUrl());
798                 }
799                 if(requestInfo.getCorrelator() != null){
800                         aq.setCorrelator(requestInfo.getCorrelator());
801                 }
802
803                 if(requestInfo.getRequestorId() != null) {
804                         aq.setRequestorId(requestInfo.getRequestorId());
805                 }
806             }
807
808             if (modelInfo != null  ||  (action == Action.inPlaceSoftwareUpdate || action == Action.applyUpdatedConfig)) {
809                 aq.setRequestScope(requestScope);
810             }
811
812             if (cloudConfiguration != null) {
813                 if(cloudConfiguration.getLcpCloudRegionId() != null) {
814                         aq.setAicCloudRegion(cloudConfiguration.getLcpCloudRegionId());
815                 }
816
817                 if(cloudConfiguration.getTenantId() != null) {
818                         aq.setTenantId(cloudConfiguration.getTenantId());
819                 }
820
821             }
822
823             if(sir.getServiceInstanceId() != null){
824                 aq.setServiceInstanceId(sir.getServiceInstanceId());
825             }
826
827             if(sir.getVnfInstanceId() != null){
828                 aq.setVnfId(sir.getVnfInstanceId());
829             }
830
831
832             if(ModelType.service.name().equalsIgnoreCase(requestScope)){
833                 if(requestInfo.getInstanceName() != null){
834                         aq.setServiceInstanceName(requestInfo.getInstanceName());
835                 }
836             }
837
838             if(ModelType.network.name().equalsIgnoreCase(requestScope)){
839                 aq.setNetworkName(requestInfo.getInstanceName());
840                 aq.setNetworkType(networkType);
841                 aq.setNetworkId(sir.getNetworkInstanceId());
842             }
843
844             if(ModelType.volumeGroup.name().equalsIgnoreCase(requestScope)){
845                 aq.setVolumeGroupId(sir.getVolumeGroupInstanceId());
846                 aq.setVolumeGroupName(requestInfo.getInstanceName());
847                 aq.setVnfType(vnfType);
848
849             }
850
851             if(ModelType.vfModule.name().equalsIgnoreCase(requestScope)){
852                 aq.setVfModuleName(requestInfo.getInstanceName());
853                 aq.setVfModuleModelName(modelInfo.getModelName());
854                 aq.setVfModuleId(sir.getVfModuleInstanceId());
855                 aq.setVolumeGroupId(sir.getVolumeGroupInstanceId());
856                 aq.setVnfType(vnfType);
857
858             }
859             
860             if(ModelType.configuration.name().equalsIgnoreCase(requestScope)) {
861                 aq.setConfigurationId(sir.getConfigurationId());
862                 aq.setConfigurationName(requestInfo.getInstanceName());
863             }
864
865             if(ModelType.vnf.name().equalsIgnoreCase(requestScope)){
866                 aq.setVnfName(requestInfo.getInstanceName());
867                                 if (null != sir.getRequestDetails()) {
868                                         RelatedInstanceList[] instanceList = sir.getRequestDetails().getRelatedInstanceList();
869
870                                         if (instanceList != null) {
871
872                                                 for(RelatedInstanceList relatedInstanceList : instanceList){
873
874                                                         RelatedInstance relatedInstance = relatedInstanceList.getRelatedInstance();
875                                                         if(relatedInstance.getModelInfo().getModelType().equals(ModelType.service)){
876                                                                 aq.setVnfType(vnfType);
877                                                         }
878                                                 }
879                                         }
880                                 }
881             }
882
883             aq.setRequestBody (this.originalRequestJSON);
884
885             aq.setRequestStatus (status.toString ());
886             aq.setLastModifiedBy (Constants.MODIFIED_BY_APIHANDLER);
887
888             if ((status == Status.FAILED) || (status == Status.COMPLETE)) {
889                 aq.setStatusMessage (this.errorMessage);
890                 aq.setResponseBody (this.responseBody);
891                 aq.setProgress(new Long(100));
892                 Timestamp endTimeStamp = new Timestamp (System.currentTimeMillis());
893                 aq.setEndTime (endTimeStamp);
894             }
895
896             msoLogger.debug ("About to insert a record");
897
898             session.save (aq);
899             session.getTransaction ().commit ();
900             session.close ();
901         } catch (Exception e) {
902                 msoLogger.error (MessageEnum.APIH_DB_INSERT_EXC, "", "", MsoLogger.ErrorCode.DataError, "Exception when creation record request", e);
903             if (session != null) {
904                 session.close ();
905             }
906             if (!status.equals (Status.FAILED)) {
907                 throw e;
908             }
909         }
910     }
911
912     public void updateFinalStatus (Status status) {
913         try {
914             (RequestsDatabase.getInstance()).updateInfraFinalStatus (requestId,
915                                                               status.toString (),
916                                                               this.errorMessage,
917                                                               this.progress,
918                                                               this.responseBody,
919                                                               Constants.MODIFIED_BY_APIHANDLER);
920         } catch (Exception e) {
921                 msoLogger.error(MessageEnum.APIH_DB_UPDATE_EXC, e.getMessage(), "", "", MsoLogger.ErrorCode.DataError, "Exception when updating record in DB");
922             msoLogger.debug ("Exception: ", e);
923         }
924     }
925
926     public Response buildResponse (int httpResponseCode, String errorCode, InfraActiveRequests inProgress) {
927         return buildResponseWithError (httpResponseCode, errorCode, inProgress, null);
928     }
929
930     public Response buildResponseWithError (int httpResponseCode,
931                                             String errorCode,
932                                             InfraActiveRequests inProgress,
933                                             String errorString) {
934
935
936
937         // Log the failed request into the MSO Requests database
938
939         return Response.status (httpResponseCode).entity (null).build ();
940
941     }
942
943     public Response buildResponseFailedValidation (int httpResponseCode, String exceptionMessage) {
944
945
946
947         return Response.status (httpResponseCode).entity (null).build ();
948     }
949     
950     public Platform getPlatform(){
951         return platform;
952     }
953     
954     public void setPlatform(Platform value){
955         this.platform = value;
956     }
957     
958     public LineOfBusiness getLineOfBusiness(){
959         return lineOfBusiness;
960     }
961     
962     public void setLineOfBusiness(LineOfBusiness value){
963         this.lineOfBusiness = value;
964     }
965
966     public Project getProject(){
967         return project;
968     }
969     public void setProject(Project value){
970         this.project = value;
971     }
972     public OwningEntity getOwningEntity(){
973         return owningEntity;
974     }
975     public void setOwningEntity(OwningEntity value){
976         this.owningEntity = value;
977     }
978     public String getRequestUri () {
979         return requestUri;
980     }
981
982     public void setRequestUri (String requestUri) {
983         this.requestUri = requestUri;
984     }
985
986     public VnfInputs getVnfInputs () {
987         return vnfInputs;
988     }
989
990     public RequestInfo getRequestInfo () {
991         return requestInfo;
992     }
993
994     public String getResponseBody () {
995         return responseBody;
996     }
997
998     public void setResponseBody (String responseBody) {
999         this.responseBody = responseBody;
1000     }
1001
1002     public String getHttpResponse () {
1003         return httpResponse;
1004     }
1005
1006     public void setHttpResponse (String httpResponse) {
1007         this.httpResponse = httpResponse;
1008     }
1009
1010     public String getRequestId () {
1011         return requestId;
1012     }
1013
1014     public String getRequestXML () {
1015         return requestXML;
1016     }
1017
1018     public void setRequestXML (String requestXML) {
1019         this.requestXML = requestXML;
1020     }
1021
1022     public RequestStatusType getStatus () {
1023         return status;
1024     }
1025
1026     public String getServiceType () {
1027         if (this.vnfInputs.getServiceType () != null)
1028                 return this.vnfInputs.getServiceType ();
1029         if (this.vnfInputs.getServiceId () != null)
1030                 return this.vnfInputs.getServiceId ();
1031         return null;
1032     }
1033
1034     public void setStatus (RequestStatusType status) {
1035         this.status = status;
1036         switch (status) {
1037         case FAILED:
1038         case COMPLETE:
1039                 this.progress = Constants.PROGRESS_REQUEST_COMPLETED;
1040                 break;
1041         case IN_PROGRESS:
1042                 this.progress = Constants.PROGRESS_REQUEST_IN_PROGRESS;
1043                 break;
1044         }
1045     }
1046
1047     public ModelInfo getModelInfo() {
1048         return modelInfo;
1049     }
1050
1051     public ServiceInstancesRequest getServiceInstancesRequest() {
1052         return sir;
1053     }
1054
1055     public String getServiceInstanceType () {
1056         return serviceInstanceType;
1057     }
1058
1059     public String getNetworkType () {
1060         return networkType;
1061     }
1062
1063     public String getVnfType () {
1064         return vnfType;
1065     }
1066
1067     public String getVfModuleModelName () {
1068         return vfModuleModelName;
1069     }
1070
1071     public String getVfModuleType () {
1072         return vfModuleType;
1073     }
1074
1075     public String getAsdcServiceModelVersion () {
1076         return asdcServiceModelVersion;
1077     }
1078
1079     public static String domToStr (Document doc) {
1080         if (doc == null) {
1081             return null;
1082         }
1083
1084         try {
1085             StringWriter sw = new StringWriter ();
1086             StreamResult sr = new StreamResult (sw);
1087             TransformerFactory tf = TransformerFactory.newInstance ();
1088             Transformer t = tf.newTransformer ();
1089             t.setOutputProperty (OutputKeys.STANDALONE, "yes");
1090             NodeList nl = doc.getDocumentElement ().getChildNodes ();
1091             DOMSource source = null;
1092             for (int x = 0; x < nl.getLength (); x++) {
1093                 Node e = nl.item (x);
1094                 if (e instanceof Element) {
1095                     source = new DOMSource (e);
1096                     break;
1097                 }
1098             }
1099             if (source != null) {
1100                 t.transform (source, sr);
1101
1102                 String s = sw.toString ();
1103                 return s;
1104             }
1105
1106             return null;
1107
1108         } catch (Exception e) {
1109             msoLogger.error (MessageEnum.APIH_DOM2STR_ERROR, "", "", MsoLogger.ErrorCode.DataError, "Exception in domToStr", e);
1110         }
1111         return null;
1112     }
1113
1114     public void addBPMNSpecificInputs(String personaModelId, String personaModelVersion, Boolean isBaseVfModule,
1115                         String vnfPersonaModelId, String vnfPersonaModelVersion) {
1116         vnfInputs.setPersonaModelId(personaModelId);
1117         vnfInputs.setPersonaModelVersion(personaModelVersion);
1118         vnfInputs.setIsBaseVfModule(isBaseVfModule);
1119         vnfInputs.setVnfPersonaModelId(vnfPersonaModelId);
1120         vnfInputs.setVnfPersonaModelVersion(vnfPersonaModelVersion);
1121
1122         this.vnfReq.setVnfInputs(vnfInputs);
1123
1124           StringWriter stringWriter = new StringWriter ();
1125           try {
1126               JAXBContext jaxbContext = JAXBContext.newInstance (VnfRequest.class);
1127               Marshaller jaxbMarshaller = jaxbContext.createMarshaller ();
1128
1129               // output pretty printed
1130               jaxbMarshaller.setProperty (Marshaller.JAXB_FORMATTED_OUTPUT, true);
1131
1132               jaxbMarshaller.marshal (this.vnfReq, stringWriter);
1133
1134           } catch (JAXBException e) {
1135               msoLogger.debug ("Exception: ", e);
1136           }
1137
1138           this.requestXML = stringWriter.toString ();
1139           msoLogger.debug("REQUEST XML to BPEL: " + this.requestXML);
1140
1141
1142     }
1143
1144     private static boolean empty(String s) {
1145           return (s == null || s.trim().isEmpty());
1146     }
1147
1148     public String getRequestJSON() throws JsonGenerationException, JsonMappingException, IOException {
1149         ObjectMapper mapper = new ObjectMapper();
1150         mapper.setSerializationInclusion(Include.NON_NULL);
1151         //mapper.configure(Feature.WRAP_ROOT_VALUE, true);
1152         msoLogger.debug ("building sir from object " + sir);
1153         String requestJSON = mapper.writeValueAsString(sir);
1154         
1155         // Perform mapping from VID-style modelInfo fields to ASDC-style modelInfo fields
1156         
1157         msoLogger.debug("REQUEST JSON before mapping: " + requestJSON);
1158         // modelUuid = modelVersionId
1159         requestJSON = requestJSON.replaceAll("\"modelVersionId\":","\"modelUuid\":");
1160         // modelCustomizationUuid = modelCustomizationId
1161         requestJSON = requestJSON.replaceAll("\"modelCustomizationId\":","\"modelCustomizationUuid\":");
1162         // modelInstanceName = modelCustomizationName
1163         requestJSON = requestJSON.replaceAll("\"modelCustomizationName\":","\"modelInstanceName\":");
1164         // modelInvariantUuid = modelInvariantId 
1165         requestJSON = requestJSON.replaceAll("\"modelInvariantId\":","\"modelInvariantUuid\":");        
1166         msoLogger.debug("REQUEST JSON after mapping: " + requestJSON);
1167         
1168         return requestJSON;
1169     }
1170
1171         public boolean getALaCarteFlag() {
1172                 return aLaCarteFlag;
1173         }
1174
1175         public void setaLaCarteFlag(boolean aLaCarteFlag) {
1176                 this.aLaCarteFlag = aLaCarteFlag;
1177         }
1178
1179         public int getReqVersion() {
1180                 return reqVersion;
1181         }
1182
1183         public void setReqVersion(int reqVersion) {
1184                 this.reqVersion = reqVersion;
1185         }
1186 }