Initial OpenECOMP MSO commit
[so.git] / mso-api-handlers / mso-api-handler-infra / src / main / java / org / openecomp / mso / apihandlerinfra / VnfMsoInfraRequest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
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.Calendar;
29 import java.util.Date;
30 import java.util.List;
31
32 import javax.ws.rs.core.Response;
33 import javax.xml.bind.JAXBContext;
34 import javax.xml.bind.JAXBException;
35 import javax.xml.bind.Marshaller;
36 import javax.xml.bind.Unmarshaller;
37 import javax.xml.transform.OutputKeys;
38 import javax.xml.transform.Transformer;
39 import javax.xml.transform.TransformerFactory;
40 import javax.xml.transform.dom.DOMSource;
41 import javax.xml.transform.sax.SAXSource;
42 import javax.xml.transform.stream.StreamResult;
43
44 import org.hibernate.Session;
45
46 import org.w3c.dom.Document;
47 import org.w3c.dom.Element;
48 import org.w3c.dom.Node;
49 import org.w3c.dom.NodeList;
50 import org.xml.sax.InputSource;
51
52 import org.openecomp.mso.apihandler.common.ErrorNumbers;
53 import org.openecomp.mso.apihandler.common.ValidationException;
54 import org.openecomp.mso.apihandlerinfra.vnfbeans.ActionType;
55 import org.openecomp.mso.apihandlerinfra.vnfbeans.ObjectFactory;
56 import org.openecomp.mso.apihandlerinfra.vnfbeans.RequestInfo;
57 import org.openecomp.mso.apihandlerinfra.vnfbeans.RequestStatusType;
58 import org.openecomp.mso.apihandlerinfra.vnfbeans.VnfInputs;
59 import org.openecomp.mso.apihandlerinfra.vnfbeans.VnfRequest;
60 import org.openecomp.mso.logger.MsoLogger;
61 import org.openecomp.mso.logger.MessageEnum;
62 import org.openecomp.mso.properties.MsoJavaProperties;
63 import org.openecomp.mso.requestsdb.HibernateUtil;
64 import org.openecomp.mso.requestsdb.InfraActiveRequests;
65 import org.openecomp.mso.requestsdb.RequestsDatabase;
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     VnfMsoInfraRequest (String requestId) {
88         this.requestId = requestId;
89         Calendar startTimeCalendar = Calendar.getInstance ();
90         this.startTime = startTimeCalendar.getTimeInMillis ();
91         MsoLogger.setLogContext (requestId, null);
92
93     }
94
95     // Parse request XML
96     void parse (String reqXML, String version, MsoJavaProperties props) throws ValidationException {
97
98         msoLogger.debug ("Validating the request");
99
100         this.requestXML = reqXML;
101
102         VnfRequest vnfReq = null;
103         boolean isWrongRootElement = false;
104
105         try {
106             JAXBContext jaxbContext = JAXBContext.newInstance (VnfRequest.class);
107             Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller ();
108
109             InputSource inputSource = new InputSource (new StringReader (reqXML));
110             SAXSource source = new SAXSource (inputSource);
111
112             if (reqXML.contains ("vnf-request") && !reqXML.contains ("network-request")) {
113                 vnfReq = jaxbUnmarshaller.unmarshal (source, VnfRequest.class).getValue ();
114             } else {
115                 isWrongRootElement = true;
116             }
117
118         } catch (Exception e) {
119                 msoLogger.error (MessageEnum.APIH_VNFREQUEST_VALIDATION_ERROR, "", "", MsoLogger.ErrorCode.DataError, "Exception in format for vnf request ", e);
120             throw new ValidationException ("format for vnf request");
121         }
122
123         if (isWrongRootElement) {
124                 msoLogger.error (MessageEnum.APIH_REQUEST_VALIDATION_ERROR_REASON, "root element is not correct", "", "", MsoLogger.ErrorCode.DataError, "root element is not correct");
125             throw new ValidationException ("root element <vnf-request> expected");
126         }
127
128         if (vnfReq == null) {
129             throw new ValidationException ("vnf-request");
130         }
131         this.vnfReq = vnfReq;
132
133         this.rinfo = vnfReq.getRequestInfo ();
134
135         if (this.rinfo == null) {
136             throw new ValidationException ("request-info");
137         }
138         if (this.rinfo.getRequestId () != null) {
139             msoLogger.info (MessageEnum.APIH_GENERATED_REQUEST_ID, requestId, this.rinfo.getRequestId ());
140         }
141
142         action = this.rinfo.getAction ();
143         if (action == null) {
144             throw new ValidationException ("action");
145         }
146
147         this.vnfInputs = vnfReq.getVnfInputs ();
148         if (this.vnfInputs == null) {
149             throw new ValidationException ("vnf-inputs");
150         }
151         
152         // Verify that BPMN-specific elements are not in the APIH incoming request
153         if (this.vnfInputs.getPersonaModelId () != null || this.vnfInputs.getPersonaModelVersion () != null ||
154                         this.vnfInputs.getIsBaseVfModule () != null || this.vnfInputs.getVnfPersonaModelId () != null ||
155                         this.vnfInputs.getVnfPersonaModelVersion () != null) {
156                  throw new ValidationException ("format for vnf request");              
157         }
158         // Verify that the elements correspond to the version
159         
160                
161         if (version.equals(Constants.SCHEMA_VERSION_V1)) {
162                         if (this.vnfInputs.getVfModuleName () != null || this.vnfInputs.getVfModuleId () != null ||
163                                         this.vnfInputs.getVfModuleModelName () != null || this.vnfInputs.getAsdcServiceModelVersion () != null ||
164                                         this.vnfInputs.getBackoutOnFailure() != null || this.vnfInputs.getAicCloudRegion() != null ||
165                                         this.vnfInputs.getServiceInstanceId  () != null) {
166                                 throw new ValidationException ("format for v1 version of vnf request");
167                         }
168         }
169         else if (version.equals(Constants.SCHEMA_VERSION_V2)) {
170                         if (this.vnfInputs.getServiceType() != null || this.vnfInputs.getAicNodeClli() != null || this.vnfInputs.getServiceInstanceId  () != null) {
171                                 throw new ValidationException ("format for v2 version of vnf request");
172                         }
173         }
174         else if (version.equals(Constants.SCHEMA_VERSION_V3)) {
175                 if (this.vnfInputs.getServiceType() != null || this.vnfInputs.getAicNodeClli() != null) {
176                         throw new ValidationException ("format for v3 version of vnf request");
177                 }
178     }
179         
180         
181         if (!InfraUtils.isActionAllowed (props, "vnf", version, action.value ())) {
182                 throw new ValidationException ("action allowable for version " + version + " of vnf request");          
183         }
184         
185         if ((ActionType.UPDATE.equals(action) || ActionType.DELETE.equals(action)) && this.vnfInputs.getVnfId () == null) {
186                 throw new ValidationException("vnf-id");                
187         }
188              
189         if ((ActionType.UPDATE_VF_MODULE.equals (action) || ActionType.DELETE_VF_MODULE.equals (action)) && this.vnfInputs.getVfModuleId () == null) {
190             throw new ValidationException ("vf-module-id");
191         }
192         
193         if (ActionType.CREATE.equals (action) && this.vnfInputs.getVnfName () == null) {
194             throw new ValidationException ("vnf-name");
195         }         
196          
197         if (ActionType.CREATE_VF_MODULE.equals (action)) {
198                 if (this.vnfInputs.getVfModuleName () == null) {
199                         throw new ValidationException ("vf-module-name");
200                 }
201                 if (!InfraUtils.isValidHeatName(this.vnfInputs.getVfModuleName ())) {
202                         throw new ValidationException ("vf-module-name: no value meeting heat stack name syntax requirements");
203                 }
204         }        
205
206         if (this.vnfInputs.getVnfType () == null) {
207             throw new ValidationException ("vnf-type");
208         }
209         
210         if ((ActionType.CREATE_VF_MODULE.equals (action) || ActionType.UPDATE_VF_MODULE.equals (action) || ActionType.DELETE_VF_MODULE.equals (action)) && this.vnfInputs.getVfModuleModelName () == null) {
211             throw new ValidationException ("vf-module-model-name");
212         }        
213         
214         if (!version.equals(Constants.SCHEMA_VERSION_V1) && this.vnfInputs.getServiceId () == null) {
215                 throw new ValidationException ("service-id ");
216         }
217         
218         if (this.vnfInputs.getServiceType () != null && this.vnfInputs.getServiceId () != null) {
219                 throw new ValidationException ("service-type or service-id ");
220         }
221         
222         if (version.equals(Constants.SCHEMA_VERSION_V1) && this.vnfInputs.getAicNodeClli () == null) {
223                 throw new ValidationException ("aic-node-clli");
224         }
225         
226         if ((version.equals(Constants.SCHEMA_VERSION_V2) || version.equals(Constants.SCHEMA_VERSION_V3)) && (this.vnfInputs.getAicCloudRegion () == null || this.vnfInputs.getAicCloudRegion ().isEmpty())) {
227                 throw new ValidationException ("aic-cloud-region");
228         }
229         
230         if (version.equals(Constants.SCHEMA_VERSION_V3) && this.vnfInputs.getServiceInstanceId () == null) {
231                 throw new ValidationException ("service-instance-id");
232         }
233
234         
235         if (this.vnfInputs.getTenantId () == null) {
236                 throw new ValidationException ("tenant-id");            
237         }
238
239         Object vp = vnfReq.getVnfParams ();
240
241         if (vp != null) {
242             msoLogger.debug ("This object is not null");
243
244             Node node = (Node) vp;
245             Document doc = node.getOwnerDocument ();
246             this.vnfParams = domToStr (doc);
247         }
248
249         msoLogger.debug ("VNFParams: " + this.vnfParams);
250
251         msoLogger.debug ("Request valid");
252
253         // Rebuild the request string for BPEL to include request-id 
254         rinfo.setRequestId (this.requestId);        
255         this.vnfReq.setRequestInfo (rinfo);        
256       
257         StringWriter stringWriter = new StringWriter ();
258         try {
259             JAXBContext jaxbContext = JAXBContext.newInstance (VnfRequest.class);
260             Marshaller jaxbMarshaller = jaxbContext.createMarshaller ();
261
262             // output pretty printed
263             jaxbMarshaller.setProperty (Marshaller.JAXB_FORMATTED_OUTPUT, true);
264
265             jaxbMarshaller.marshal (this.vnfReq, stringWriter);
266
267         } catch (JAXBException e) {
268             msoLogger.debug ("Exception: ", e);
269         }
270
271         this.requestXML = stringWriter.toString ();
272         msoLogger.debug("REQUEST XML to BPEL: " + this.requestXML);
273
274     }
275
276     public void createRequestRecord (Status status) {
277
278         Session session = null;
279         try {
280
281             session = HibernateUtil.getSessionFactory ().openSession ();
282             session.beginTransaction ();
283
284             InfraActiveRequests aq = new InfraActiveRequests ();
285             aq.setRequestId (requestId);
286             aq.setClientRequestId(rinfo.getRequestId());
287
288             Timestamp startTimeStamp = new Timestamp (Calendar.getInstance ().getTimeInMillis ());
289             if (rinfo != null) {
290                 if (rinfo.getAction () != null) {
291                     aq.setAction (rinfo.getAction ().value ());
292                     aq.setRequestAction (RequestActionMap.getMappedRequestAction (rinfo.getAction ().value ()));
293                 }
294                 aq.setSource (rinfo.getSource ());
295             } else {
296                 // Set up mandatory parameters
297                 aq.setAction (NOT_PROVIDED);
298                 aq.setRequestAction (NOT_PROVIDED);
299             }
300
301             aq.setRequestBody (this.requestXML);
302             aq.setRequestScope ("");
303
304             if (vnfInputs != null) {
305                 if (vnfInputs.getVnfId () != null) {
306                     aq.setVnfId (vnfInputs.getVnfId ());
307                 }
308                 if (vnfInputs.getVnfName () != null) {
309                     aq.setVnfName (vnfInputs.getVnfName ());
310                 }
311                 if (vnfInputs.getVnfType () != null) {
312                     aq.setVnfType (vnfInputs.getVnfType ());
313                 }
314                 if (vnfInputs.getServiceInstanceId () != null) {
315                     aq.setServiceInstanceId (vnfInputs.getServiceInstanceId ());
316                 }
317                 if (vnfInputs.getServiceType () != null) {
318                     aq.setServiceType (vnfInputs.getServiceType ());
319                 }
320                 if (vnfInputs.getServiceId () != null) {
321                     aq.setAaiServiceId (vnfInputs.getServiceId ());
322                 }
323                 if (vnfInputs.getAicNodeClli () != null) {
324                     aq.setAicNodeClli (vnfInputs.getAicNodeClli ());
325                 }
326                 if (vnfInputs.getAicCloudRegion () != null) {
327                     aq.setAicCloudRegion (vnfInputs.getAicCloudRegion ());
328                 }
329                 if (vnfInputs.getTenantId () != null) {
330                     aq.setTenantId (vnfInputs.getTenantId ());
331                 }
332                 if (vnfInputs.getProvStatus () != null) {
333                     aq.setProvStatus (vnfInputs.getProvStatus ());
334                 }
335                 if (vnfInputs.getVolumeGroupName () != null) {
336                     aq.setVolumeGroupName (vnfInputs.getVolumeGroupName ());
337                 }
338                 if (vnfInputs.getVolumeGroupId () != null) {
339                     aq.setVolumeGroupId (vnfInputs.getVolumeGroupId ());
340                 }
341                 if (vnfInputs.getVfModuleId () != null) {
342                     aq.setVfModuleId (vnfInputs.getVfModuleId ());
343                 }
344                 if (vnfInputs.getVfModuleName () != null) {
345                     aq.setVfModuleName (vnfInputs.getVfModuleName ());
346                 }
347                 if (vnfInputs.getVfModuleModelName () != null) {
348                     aq.setVfModuleModelName (vnfInputs.getVfModuleModelName ());
349                 }
350                 
351                 if (vnfInputs.getVfModuleName () != null || vnfInputs.getVfModuleId () != null) {
352                         aq.setRequestScope (ModelType.vfModule.name ());
353                 }
354                 else {
355                         aq.setRequestScope (ModelType.vnf.name ());
356                 }
357
358
359             }
360
361             aq.setStartTime (startTimeStamp);
362             aq.setRequestStatus (status.toString ());
363             aq.setLastModifiedBy (Constants.MODIFIED_BY_APIHANDLER);
364             aq.setRequestType ("VNF");
365
366             if (vnfParams != null) {
367                 msoLogger.debug ("Storing vnfParams: " + vnfParams);
368                 aq.setVnfParams (this.vnfParams);
369             }
370
371             if ((status == Status.FAILED) || (status == Status.COMPLETE)) {
372                 aq.setStatusMessage (this.errorMessage);
373                 aq.setResponseBody (this.responseBody);
374
375                 Calendar endTime = Calendar.getInstance ();
376                 Timestamp endTimeStamp = new Timestamp (endTime.getTimeInMillis ());
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.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 }