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