001package org.kuali.ole.ncip.converter;
002
003import com.thoughtworks.xstream.XStream;
004import org.apache.log4j.Logger;
005import org.kuali.ole.ncip.bo.OLEPlaceRequest;
006
007/**
008 * Created with IntelliJ IDEA.
009 * User: sheiksalahudeenm
010 * Date: 9/3/13
011 * Time: 7:59 PM
012 * To change this template use File | Settings | File Templates.
013 */
014public class OLEPlaceRequestConverter {
015    final Logger LOG = Logger.getLogger(OLEPlaceRequestConverter.class);
016    public String generatePlaceRequestXml(OLEPlaceRequest olePlaceRequest){
017        XStream xStream = new XStream();
018        xStream.alias("placeRequest",OLEPlaceRequest.class);
019        //xStream.omitField(OLEPlaceRequest.class, "expirationDate");
020       // xStream.omitField(OLEPlaceRequest.class, "blockOverride");
021        return xStream.toXML(olePlaceRequest);
022    }
023
024    public String generatePlaceRequestXmlForSip2(OLEPlaceRequest olePlaceRequest){
025        XStream xStream = new XStream();
026        xStream.alias("placeRequest",OLEPlaceRequest.class);
027        xStream.omitField(OLEPlaceRequest.class, "blockOverride");
028        return xStream.toXML(olePlaceRequest);
029    }
030    public Object generatePlaceRequestObject(String xml){
031        XStream xStream = new XStream();
032        xStream.alias("placeRequest",OLEPlaceRequest.class);
033        return xStream.fromXML(xml);
034    }
035    public String generatePlaceRequestJson(String xml) {
036        OLEPlaceRequest olePlaceRequest = (OLEPlaceRequest)generatePlaceRequestObject(xml);
037        OleCirculationHandler xmlContentHandler = new OleCirculationHandler();
038        if(olePlaceRequest==null){
039            olePlaceRequest=new OLEPlaceRequest();
040        }
041        try{
042            return xmlContentHandler.marshalToJSON(olePlaceRequest);
043        }catch(Exception e){
044            LOG.error(e,e);
045        }
046        return null;
047    }
048}