1 package org.kuali.ole.ncip.converter;
2
3 import com.thoughtworks.xstream.XStream;
4 import org.apache.log4j.Logger;
5 import org.kuali.ole.ncip.bo.OLEPlaceRequest;
6
7
8
9
10
11
12
13
14 public class OLEPlaceRequestConverter {
15 final Logger LOG = Logger.getLogger(OLEPlaceRequestConverter.class);
16 public String generatePlaceRequestXml(OLEPlaceRequest olePlaceRequest){
17 XStream xStream = new XStream();
18 xStream.alias("placeRequest",OLEPlaceRequest.class);
19 xStream.omitField(OLEPlaceRequest.class, "expirationDate");
20
21 return xStream.toXML(olePlaceRequest);
22 }
23
24 public String generatePlaceRequestXmlForSip2(OLEPlaceRequest olePlaceRequest){
25 XStream xStream = new XStream();
26 xStream.alias("placeRequest",OLEPlaceRequest.class);
27 xStream.omitField(OLEPlaceRequest.class, "blockOverride");
28 return xStream.toXML(olePlaceRequest);
29 }
30 public Object generatePlaceRequestObject(String xml){
31 XStream xStream = new XStream();
32 xStream.alias("placeRequest",OLEPlaceRequest.class);
33 return xStream.fromXML(xml);
34 }
35 public String generatePlaceRequestJson(String xml) {
36 OLEPlaceRequest olePlaceRequest = (OLEPlaceRequest)generatePlaceRequestObject(xml);
37 OleCirculationHandler xmlContentHandler = new OleCirculationHandler();
38 if(olePlaceRequest==null){
39 olePlaceRequest=new OLEPlaceRequest();
40 }
41 try{
42 return xmlContentHandler.marshalToJSON(olePlaceRequest);
43 }catch(Exception e){
44 LOG.error(e,e);
45 }
46 return null;
47 }
48 }