Change the header to SO
[so.git] / mso-api-handlers / mso-api-handler-infra / src / main / java / org / openecomp / mso / apihandlerinfra / VnfMsoInfraRequest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.mso.apihandlerinfra;
22
23
24 import java.io.StringReader;
25 import java.io.StringWriter;
26 import java.sql.Timestamp;
27 import java.text.SimpleDateFormat;
28 import java.util.Date;
29 import java.util.List;
30
31 import javax.ws.rs.core.Response;
32 import javax.xml.bind.JAXBContext;
33 import javax.xml.bind.JAXBException;
34 import javax.xml.bind.Marshaller;
35 import javax.xml.bind.Unmarshaller;
36 import javax.xml.transform.OutputKeys;
37 import javax.xml.transform.Transformer;
38 import javax.xml.transform.TransformerFactory;
39 import javax.xml.transform.dom.DOMSource;
40 import javax.xml.transform.sax.SAXSource;
41 import javax.xml.transform.stream.StreamResult;
42
43 import org.hibernate.Session;
44
45 import org.w3c.dom.Document;
46 import org.w3c.dom.Element;
47 import org.w3c.dom.Node;
48 import org.w3c.dom.NodeList;
49 import org.xml.sax.InputSource;
50
51 import org.openecomp.mso.apihandler.common.ErrorNumbers;
52 import org.openecomp.mso.apihandler.common.ValidationException;
53 import org.openecomp.mso.apihandlerinfra.vnfbeans.ActionType;
54 import org.openecomp.mso.apihandlerinfra.vnfbeans.ObjectFactory;
55 import org.openecomp.mso.apihandlerinfra.vnfbeans.RequestInfo;
56 import org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType;
57 import org.openecomp.mso.apihandlerinfra.vnfbeans.VnfInputs;
58 import org.openecomp.mso.apihandlerinfra.vnfbeans.VnfRequest;
59 import org.openecomp.mso.logger.MsoLogger;
60 import org.openecomp.mso.logger.MessageEnum;
61 import org.openecomp.mso.properties.MsoJavaProperties;
62 import org.openecomp.mso.db.AbstractSessionFactoryManager;
63 import org.openecomp.mso.requestsdb.InfraActiveRequests;
64 import org.openecomp.mso.requestsdb.RequestsDatabase;
65 import org.openecomp.mso.requestsdb.RequestsDbSessionFactoryManager;
66
67 public class VnfMsoInfraRequest {
68
69     private String requestId;
70     private String requestXML;
71     private String requestUri;
72     private VnfRequest vnfReq;
73     private RequestInfo rinfo;
74     private VnfInputs vnfInputs;
75     private String vnfParams;
76     private ActionType action;
77     private String errorMessage;
78     private String httpResponse;
79     private String responseBody;
80     private RequestStatusType status;
81     private long startTime;
82     private long progress = Constants.PROGRESS_REQUEST_RECEIVED;
83
84     private static MsoLogger msoLogger = MsoLogger.getMsoLogger (MsoLogger.Catalog.APIH);
85     private static final String NOT_PROVIDED = "not provided";
86
87     protected AbstractSessionFactoryManager requestsDbSessionFactoryManager = new RequestsDbSessionFactoryManager ();
88     
89     VnfMsoInfraRequest (String requestId) {
90         this.requestId = requestId;
91         this.startTime = System.currentTimeMillis();
92         MsoLogger.setLogContext (requestId, null);
93
94     }
95
96     // Parse request XML
97     void parse (String reqXML, String version, MsoJavaProperties props) throws ValidationException {
98
99         msoLogger.debug ("Validating the request");
100
101         this.requestXML = reqXML;
102
103         VnfRequest vnfReq = null;
104         boolean isWrongRootElement = false;
105
106         try {
107             JAXBContext jaxbContext = JAXBContext.newInstance (VnfRequest.class);
108             Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller ();
109
110             InputSource inputSource = new InputSource (new StringReader (reqXML));
111             SAXSource source = new SAXSource (inputSource);
112
113             if (reqXML.contains ("vnf-request") && !reqXML.contains ("network-request")) {
114                 vnfReq = jaxbUnmarshaller.unmarshal (source, VnfRequest.class).getValue ();
115             } else {
116                 isWrongRootElement = true;
117             }
118
119         } catch (Exception e) {
120                 msoLogger.error (MessageEnum.APIH_VNFREQUEST_VALIDATION_ERROR, "", "", MsoLogger.ErrorCode.DataError, "Exception in format for vnf request ", e);
121             throw new ValidationException ("format for vnf request");
122         }
123
124         if (isWrongRootElement) {
125                 msoLogger.error (MessageEnum.APIH_REQUEST_VALIDATION_ERROR_REASON, "root element is not correct", "", "", MsoLogger.ErrorCode.DataError, "root element is not correct");
126             throw new ValidationException ("root element <vnf-request> expected");
127         }
128
129         if (vnfReq == null) {
130             throw new ValidationException ("vnf-request");
131         }
132         this.vnfReq = vnfReq;
133
134         this.rinfo = vnfReq.getRequestInfo ();
135
136         if (this.rinfo == null) {
137             throw new ValidationException ("request-info");
138         }
139         if (this.rinfo.getRequestId () != null) {
140             msoLogger.info (MessageEnum.APIH_GENERATED_REQUEST_ID, requestId, this.rinfo.getRequestId ());
141         }
142
143         action = this.rinfo.getAction ();
144         if (action == null) {
145             throw new ValidationException ("action");
146         }
147
148         this.vnfInputs = vnfReq.getVnfInputs ();
149         if (this.vnfInputs == null) {
150             throw new ValidationException ("vnf-inputs");
151         }
152         
153         // Verify that BPMN-specific elements are not in the APIH incoming request
154         if (this.vnfInputs.getPersonaModelId () != null || this.vnfInputs.getPersonaModelVersion () != null ||
155                         this.vnfInputs.getIsBaseVfModule () != null || this.vnfInputs.getVnfPersonaModelId () != null ||
156                         this.vnfInputs.getVnfPersonaModelVersion () != null) {
157                  throw new ValidationException ("format for vnf request");              
158         }
159         // Verify that the elements correspond to the version
160         
161                
162         if (version.equals(Constants.SCHEMA_VERSION_V1)) {
163                         if (this.vnfInputs.getVfModuleName () != null || this.vnfInputs.getVfModuleId () != null ||
164                                         this.vnfInputs.getVfModuleModelName () != null || this.vnfInputs.getAsdcServiceModelVersion () != null ||
165                                         this.vnfInputs.getBackoutOnFailure() != null || this.vnfInputs.getAicCloudRegion() != null ||
166                                         this.vnfInputs.getServiceInstanceId  () != null) {
167                                 throw new ValidationException ("format for v1 version of vnf request");
168                         }
169         }
170         else if (version.equals(Constants.SCHEMA_VERSION_V2)) {
171                         if (this.vnfInputs.getServiceType() != null || this.vnfInputs.getAicNodeClli() != null || this.vnfInputs.getServiceInstanceId  () != null) {
172                                 throw new ValidationException ("format for v2 version of vnf request");
173                         }
174         }
175         else if (version.equals(Constants.SCHEMA_VERSION_V3)) {
176                 if (this.vnfInputs.getServiceType() != null || this.vnfInputs.getAicNodeClli() != null) {
177                         throw new ValidationException ("format for v3 version of vnf request");
178                 }
179     }
180         
181         
182         if (!InfraUtils.isActionAllowed (props, "vnf", version, action.value ())) {
183                 throw new ValidationException ("action allowable for version " + version + " of vnf request");          
184         }
185         
186         if ((ActionType.UPDATE.equals(action) || ActionType.DELETE.equals(action)) && this.vnfInputs.getVnfId () == null) {
187                 throw new ValidationException("vnf-id");                
188         }
189              
190         if ((ActionType.UPDATE_VF_MODULE.equals (action) || ActionType.DELETE_VF_MODULE.equals (action)) && this.vnfInputs.getVfModuleId () == null) {
191             throw new ValidationException ("vf-module-id");
192         }
193         
194         if (ActionType.CREATE.equals (action) && this.vnfInputs.getVnfName () == null) {
195             throw new ValidationException ("vnf-name");
196         }         
197          
198         if (ActionType.CREATE_VF_MODULE.equals (action)) {
199                 if (this.vnfInputs.getVfModuleName () == null) {
200                         throw new ValidationException ("vf-module-name");
201                 }
202                 if (!InfraUtils.isValidHeatName(this.vnfInputs.getVfModuleName ())) {
203                         throw new ValidationException ("vf-module-name: no value meeting heat stack name syntax requirements");
204                 }
205         }        
206
207         if (this.vnfInputs.getVnfType () == null) {
208             throw new ValidationException ("vnf-type");
209         }
210         
211         if ((ActionType.CREATE_VF_MODULE.equals (action) || ActionType.UPDATE_VF_MODULE.equals (action) || ActionType.DELETE_VF_MODULE.equals (action)) && this.vnfInputs.getVfModuleModelName () == null) {
212             throw new ValidationException ("vf-module-model-name");
213         }        
214         
215         if (!version.equals(Constants.SCHEMA_VERSION_V1) && this.vnfInputs.getServiceId () == null) {
216                 throw new ValidationException ("service-id ");
217         }
218         
219         if (this.vnfInputs.getServiceType () != null && this.vnfInputs.getServiceId () != null) {
220                 throw new ValidationException ("service-type or service-id ");
221         }
222         
223         if (version.equals(Constants.SCHEMA_VERSION_V1) && this.vnfInputs.getAicNodeClli () == null) {
224                 throw new ValidationException ("aic-node-clli");
225         }
226         
227         if ((version.equals(Constants.SCHEMA_VERSION_V2) || version.equals(Constants.SCHEMA_VERSION_V3)) && (this.vnfInputs.getAicCloudRegion () == null || this.vnfInputs.getAicCloudRegion ().isEmpty())) {
228                 throw new ValidationException ("aic-cloud-region");
229         }
230         
231         if (version.equals(Constants.SCHEMA_VERSION_V3) && this.vnfInputs.getServiceInstanceId () == null) {
232                 throw new ValidationException ("service-instance-id");
233         }
234
235         
236         if (this.vnfInputs.getTenantId () == null) {
237                 throw new ValidationException ("tenant-id");            
238         }
239
240         Object vp = vnfReq.getVnfParams ();
241
242         if (vp != null) {
243             msoLogger.debug ("This object is not null");
244
245             Node node = (Node) vp;
246             Document doc = node.getOwnerDocument ();
247             this.vnfParams = domToStr (doc);
248         }
249
250         msoLogger.debug ("VNFParams: " + this.vnfParams);
251
252         msoLogger.debug ("Request valid");
253
254         // Rebuild the request string for BPEL to include request-id 
255         rinfo.setRequestId (this.requestId);        
256         this.vnfReq.setRequestInfo (rinfo);        
257       
258         StringWriter stringWriter = new StringWriter ();
259         try {
260             JAXBContext jaxbContext = JAXBContext.newInstance (VnfRequest.class);
261             Marshaller jaxbMarshaller = jaxbContext.createMarshaller ();
262
263             // output pretty printed
264             jaxbMarshaller.setProperty (Marshaller.JAXB_FORMATTED_OUTPUT, true);
265
266             jaxbMarshaller.marshal (this.vnfReq, stringWriter);
267
268         } catch (JAXBException e) {
269             msoLogger.debug ("Exception: ", e);
270         }
271
272         this.requestXML = stringWriter.toString ();
273         msoLogger.debug("REQUEST XML to BPEL: " + this.requestXML);
274
275     }
276
277     public void createRequestRecord (Status status) {
278
279         Session session = null;
280         try {
281
282             session = requestsDbSessionFactoryManager.getSessionFactory ().openSession ();
283             session.beginTransaction ();
284
285             InfraActiveRequests aq = new InfraActiveRequests ();
286             aq.setRequestId (requestId);
287             aq.setClientRequestId(rinfo.getRequestId());
288
289             Timestamp startTimeStamp = new Timestamp (System.currentTimeMillis());
290             if (rinfo != null) {
291                 if (rinfo.getAction () != null) {
292                     aq.setAction (rinfo.getAction ().value ());
293                     aq.setRequestAction (RequestActionMap.getMappedRequestAction (rinfo.getAction ().value ()));
294                 }
295                 aq.setSource (rinfo.getSource ());
296             } else {
297                 // Set up mandatory parameters
298                 aq.setAction (NOT_PROVIDED);
299                 aq.setRequestAction (NOT_PROVIDED);
300             }
301
302             aq.setRequestBody (this.requestXML);
303             aq.setRequestScope ("");
304
305             if (vnfInputs != null) {
306                 if (vnfInputs.getVnfId () != null) {
307                     aq.setVnfId (vnfInputs.getVnfId ());
308                 }
309                 if (vnfInputs.getVnfName () != null) {
310                     aq.setVnfName (vnfInputs.getVnfName ());
311                 }
312                 if (vnfInputs.getVnfType () != null) {
313                     aq.setVnfType (vnfInputs.getVnfType ());
314                 }
315                 if (vnfInputs.getServiceInstanceId () != null) {
316                     aq.setServiceInstanceId (vnfInputs.getServiceInstanceId ());
317                 }
318                 if (vnfInputs.getServiceType () != null) {
319                     aq.setServiceType (vnfInputs.getServiceType ());
320                 }
321                 if (vnfInputs.getServiceId () != null) {
322                     aq.setAaiServiceId (vnfInputs.getServiceId ());
323                 }
324                 if (vnfInputs.getAicNodeClli () != null) {
325                     aq.setAicNodeClli (vnfInputs.getAicNodeClli ());
326                 }
327                 if (vnfInputs.getAicCloudRegion () != null) {
328                     aq.setAicCloudRegion (vnfInputs.getAicCloudRegion ());
329                 }
330                 if (vnfInputs.getTenantId () != null) {
331                     aq.setTenantId (vnfInputs.getTenantId ());
332                 }
333                 if (vnfInputs.getProvStatus () != null) {
334                     aq.setProvStatus (vnfInputs.getProvStatus ());
335                 }
336                 if (vnfInputs.getVolumeGroupName () != null) {
337                     aq.setVolumeGroupName (vnfInputs.getVolumeGroupName ());
338                 }
339                 if (vnfInputs.getVolumeGroupId () != null) {
340                     aq.setVolumeGroupId (vnfInputs.getVolumeGroupId ());
341                 }
342                 if (vnfInputs.getVfModuleId () != null) {
343                     aq.setVfModuleId (vnfInputs.getVfModuleId ());
344                 }
345                 if (vnfInputs.getVfModuleName () != null) {
346                     aq.setVfModuleName (vnfInputs.getVfModuleName ());
347                 }
348                 if (vnfInputs.getVfModuleModelName () != null) {
349                     aq.setVfModuleModelName (vnfInputs.getVfModuleModelName ());
350                 }
351                 
352                 if (vnfInputs.getVfModuleName () != null || vnfInputs.getVfModuleId () != null) {
353                         aq.setRequestScope (ModelType.vfModule.name ());
354                 }
355                 else {
356                         aq.setRequestScope (ModelType.vnf.name ());
357                 }
358
359
360             }
361
362             aq.setStartTime (startTimeStamp);
363             aq.setRequestStatus (status.toString ());
364             aq.setLastModifiedBy (Constants.MODIFIED_BY_APIHANDLER);
365             aq.setRequestType ("VNF");
366
367             if (vnfParams != null) {
368                 msoLogger.debug ("Storing vnfParams: " + vnfParams);
369                 aq.setVnfParams (this.vnfParams);
370             }
371
372             if ((status == Status.FAILED) || (status == Status.COMPLETE)) {
373                 aq.setStatusMessage (this.errorMessage);
374                 aq.setResponseBody (this.responseBody);
375
376                 Timestamp endTimeStamp = new Timestamp (System.currentTimeMillis());
377                 aq.setEndTime (endTimeStamp);
378             }
379                 
380             aq.setProgress (this.progress);
381             
382
383             msoLogger.debug ("About to insert a record");
384
385             session.save (aq);
386             session.getTransaction ().commit ();
387             session.close ();
388         } catch (Exception e) {
389                 msoLogger.error (MessageEnum.APIH_DB_INSERT_EXC, "", "", MsoLogger.ErrorCode.AvailabilityError, "Exception in createRequestRecord", e);
390             if (session != null) {
391                 session.close ();
392             }
393             if (!status.equals (Status.FAILED)) {
394                 throw e;
395             }
396         }
397     }
398
399     public void updateFinalStatus (Status status) {
400         int result = 0;
401         try {
402             result = (RequestsDatabase.getInstance()).updateInfraFinalStatus (requestId,
403                                                               status.toString (),
404                                                               this.errorMessage,
405                                                               this.progress,
406                                                               this.responseBody,
407                                                               Constants.MODIFIED_BY_APIHANDLER);
408         } catch (Exception e) {
409                 msoLogger.error (MessageEnum.APIH_DB_UPDATE_EXC, e.getMessage (), "", "", MsoLogger.ErrorCode.AvailabilityError, "Exception in updateFinalStatus");
410             msoLogger.debug ("Exception: ", e);
411         }
412     }
413
414     public Response buildResponse (int httpResponseCode, String errorCode, InfraActiveRequests inProgress) {
415         return buildResponseWithError (httpResponseCode, errorCode, inProgress, null);
416     }
417
418     public Response buildResponseWithError (int httpResponseCode,
419                                             String errorCode,
420                                             InfraActiveRequests inProgress,
421                                             String errorString) {
422
423         ObjectFactory beansObjectFactory = new ObjectFactory ();
424
425         VnfRequest vr = beansObjectFactory.createVnfRequest ();
426
427         RequestInfo ri = beansObjectFactory.createRequestInfo ();
428
429         ri.setRequestId (requestId);
430         ri.setRequestStatus (this.status);
431         ri.setAction (this.rinfo.getAction ());
432         ri.setSource (this.rinfo.getSource ());
433
434         String errorMsg = null;
435         if (errorCode != null) {
436             // If error code is actually an XML error response from BPEL, treat it specially:
437             if (!Messages.errors.containsKey (errorCode)) {
438                 if (errorCode.length () > 300) {
439                     errorMsg = errorCode.substring (0, 299);
440                 } else {
441                     errorMsg = errorCode;
442                 }
443
444             } else {
445
446                 if (inProgress == null) {
447                     if (errorCode.equals (ErrorNumbers.RECIPE_DOES_NOT_EXIST)) {
448                         errorMsg = String.format (Messages.errors.get (errorCode), "vnf", errorString);
449                     } else {
450                         errorMsg = String.format (Messages.errors.get (errorCode), errorString);
451                     }
452                 } else if (errorCode.equals (ErrorNumbers.LOCKED_CREATE_ON_THE_SAME_VNF_NAME_IN_PROGRESS)) {
453                     errorMsg = String.format (Messages.errors.get (errorCode),
454                                               "vnf",
455                                               inProgress.getVnfName (),
456                                               inProgress.getRequestStatus (),
457                                               "vnf");
458                 } else if (errorCode.equals (ErrorNumbers.LOCKED_SAME_ACTION_AND_VNF_ID)) {
459                     errorMsg = String.format (Messages.errors.get (errorCode),
460                                               "vnf",
461                                               inProgress.getVnfId (),
462                                               inProgress.getRequestStatus (),
463                                               inProgress.getAction (),
464                                               "vnf");
465                 }
466             }
467
468             ri.setStatusMessage (errorMsg);
469             this.errorMessage = errorMsg;
470         }
471         ri.setProgress ((int) this.progress);
472
473         Date startDate = new Date (this.startTime);
474         SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss.SSS");
475         String startTimeString = sdf.format (startDate);
476
477         ri.setStartTime (startTimeString);
478         
479         if (this.progress == Constants.PROGRESS_REQUEST_COMPLETED) {
480                 ri.setEndTime(startTimeString);
481         }
482
483         vr.setRequestInfo (ri);
484         
485         this.vnfInputs.setIsBaseVfModule(null);
486         this.vnfInputs.setPersonaModelId(null);
487         this.vnfInputs.setPersonaModelVersion(null);
488         this.vnfInputs.setVnfPersonaModelId(null);
489         this.vnfInputs.setVnfPersonaModelVersion(null);
490
491         vr.setVnfInputs (this.vnfInputs);
492
493         StringWriter stringWriter = new StringWriter ();
494         try {
495             JAXBContext jaxbContext = JAXBContext.newInstance (VnfRequest.class);
496             Marshaller jaxbMarshaller = jaxbContext.createMarshaller ();
497             jaxbMarshaller.setProperty (Marshaller.JAXB_FORMATTED_OUTPUT, true);
498
499             jaxbMarshaller.marshal (vr, stringWriter);
500
501         } catch (JAXBException e) {
502             msoLogger.debug ("Exception: ", e);
503         }
504
505         String response = stringWriter.toString ();
506
507         this.httpResponse = Integer.toString (httpResponseCode);
508         this.responseBody = response;
509         
510         
511         // Log the failed request into the MSO Requests database
512
513         return Response.status (httpResponseCode).entity (response).build ();
514
515     }
516
517     public Response buildResponseFailedValidation (int httpResponseCode, String exceptionMessage) {
518
519         ObjectFactory beansObjectFactory = new ObjectFactory ();
520         VnfRequest vr = beansObjectFactory.createVnfRequest ();
521
522         RequestInfo ri = beansObjectFactory.createRequestInfo ();
523         ri.setRequestId (requestId);
524
525         if (this.rinfo != null) {
526             if (this.rinfo.getAction () != null) {
527                 ri.setAction (this.rinfo.getAction ());
528             } else {
529                 ri.setAction (ActionType.NOT_PROVIDED);
530             }
531             if (this.rinfo.getSource () != null) {
532                 ri.setSource (this.rinfo.getSource ());
533             }
534         } else {
535             ri.setAction (ActionType.NOT_PROVIDED);
536         }
537
538         // Nothing more is expected for this request
539
540         String errorMsg = String.format (Messages.errors.get (ErrorNumbers.REQUEST_FAILED_SCHEMA_VALIDATION
541                                                               + "_service"),
542                                          exceptionMessage);
543         ri.setStatusMessage (errorMsg);
544         this.errorMessage = errorMsg;
545
546         ri.setProgress ((int) this.progress);
547         ri.setRequestStatus (RequestStatusType.FAILED);
548         Date startDate = new Date (this.startTime);
549         SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss.SSS");
550         String startTimeString = sdf.format (startDate);
551
552         ri.setStartTime (startTimeString);
553         ri.setEndTime(startTimeString);
554         
555         vr.setRequestInfo (ri);
556
557         vr.setVnfInputs (this.vnfInputs);
558
559         StringWriter stringWriter = new StringWriter ();
560         try {
561             JAXBContext jaxbContext = JAXBContext.newInstance (VnfRequest.class);
562             Marshaller jaxbMarshaller = jaxbContext.createMarshaller ();
563
564             // output pretty printed
565             jaxbMarshaller.setProperty (Marshaller.JAXB_FORMATTED_OUTPUT, true);
566
567             jaxbMarshaller.marshal (vr, stringWriter);
568
569         } catch (JAXBException e) {
570             msoLogger.debug ("Error marshalling", e);
571         }
572
573         String response = stringWriter.toString ();
574
575         this.httpResponse = Integer.toString (httpResponseCode);
576         this.responseBody = response;
577
578         return Response.status (httpResponseCode).entity (response).build ();
579     }
580
581     public String getRequestUri () {
582         return requestUri;
583     }
584
585     public void setRequestUri (String requestUri) {
586         this.requestUri = requestUri;
587     }
588
589     public VnfInputs getVnfInputs () {
590         return vnfInputs;
591     }
592
593     public RequestInfo getRequestInfo () {
594         return rinfo;
595     }
596
597     public String getResponseBody () {
598         return responseBody;
599     }
600
601     public void setResponseBody (String responseBody) {
602         this.responseBody = responseBody;
603     }
604
605     public String getHttpResponse () {
606         return httpResponse;
607     }
608
609     public void setHttpResponse (String httpResponse) {
610         this.httpResponse = httpResponse;
611     }
612
613     public String getRequestId () {
614         return requestId;
615     }
616
617     public String getRequestXML () {
618         return requestXML;
619     }
620
621     public void setRequestXML (String requestXML) {
622         this.requestXML = requestXML;
623     }
624
625     public RequestStatusType getStatus () {
626         return status;
627     }
628     
629     public String getServiceType () {
630         if (this.vnfInputs.getServiceType () != null) 
631                 return this.vnfInputs.getServiceType ();
632         if (this.vnfInputs.getServiceId () != null) 
633                 return this.vnfInputs.getServiceId ();
634         return null;
635     }
636
637     public void setStatus (RequestStatusType status) {
638         this.status = status;
639         switch (status) {
640         case FAILED:
641         case COMPLETE:
642                 this.progress = Constants.PROGRESS_REQUEST_COMPLETED;
643                 break;
644         case IN_PROGRESS:
645                 this.progress = Constants.PROGRESS_REQUEST_IN_PROGRESS;
646                 break;
647         }
648     }
649
650     public static String domToStr (Document doc) {
651         if (doc == null) {
652             return null;
653         }
654
655         try {
656             StringWriter sw = new StringWriter ();
657             StreamResult sr = new StreamResult (sw);
658             TransformerFactory tf = TransformerFactory.newInstance ();
659             Transformer t = tf.newTransformer ();
660             t.setOutputProperty (OutputKeys.STANDALONE, "yes");
661             NodeList nl = doc.getDocumentElement ().getChildNodes ();
662             DOMSource source = null;
663             for (int x = 0; x < nl.getLength (); x++) {
664                 Node e = nl.item (x);
665                 if (e instanceof Element) {
666                     source = new DOMSource (e);
667                     break;
668                 }
669             }
670             if (source != null) {
671                 t.transform (source, sr);
672
673                 String s = sw.toString ();
674                 return s;
675             }
676
677             return null;
678
679         } catch (Exception e) {
680                 msoLogger.error (MessageEnum.APIH_DOM2STR_ERROR, "", "", MsoLogger.ErrorCode.DataError, "Exception in domToStr", e);
681         }
682         return null;
683     }
684     
685     public void addBPMNSpecificInputs(String personaModelId, String personaModelVersion, Boolean isBaseVfModule,
686                         String vnfPersonaModelId, String vnfPersonaModelVersion) {
687         vnfInputs.setPersonaModelId(personaModelId);
688         vnfInputs.setPersonaModelVersion(personaModelVersion);
689         vnfInputs.setIsBaseVfModule(isBaseVfModule);
690         vnfInputs.setVnfPersonaModelId(vnfPersonaModelId);
691         vnfInputs.setVnfPersonaModelVersion(vnfPersonaModelVersion);
692         
693         this.vnfReq.setVnfInputs(vnfInputs);
694                    
695           StringWriter stringWriter = new StringWriter ();
696           try {
697               JAXBContext jaxbContext = JAXBContext.newInstance (VnfRequest.class);
698               Marshaller jaxbMarshaller = jaxbContext.createMarshaller ();
699
700               // output pretty printed
701               jaxbMarshaller.setProperty (Marshaller.JAXB_FORMATTED_OUTPUT, true);
702
703               jaxbMarshaller.marshal (this.vnfReq, stringWriter);
704
705           } catch (JAXBException e) {
706               msoLogger.debug ("Exception: ", e);
707           }
708
709           this.requestXML = stringWriter.toString ();
710           msoLogger.debug("REQUEST XML to BPEL: " + this.requestXML);
711         
712         
713     }
714 }