001package org.kuali.ole.ncip.converter; 002 003import com.thoughtworks.xstream.XStream; 004import org.apache.log4j.Logger; 005import org.kuali.ole.ncip.bo.OLERenewItem; 006import org.kuali.ole.ncip.bo.OLERenewItemList; 007 008/** 009 * Created with IntelliJ IDEA. 010 * User: sheiksalahudeenm 011 * Date: 9/3/13 012 * Time: 8:52 PM 013 * To change this template use File | Settings | File Templates. 014 */ 015public class OLERenewItemConverter { 016 final Logger LOG = Logger.getLogger(OLEItemFineConverter.class); 017 018 private static XStream xStream = getXstream(); 019 private static XStream xStream1 = getXstream1(); 020 private static XStream xStreamList = getXstreamList(); 021 private static XStream xStreamList1 = getXstreamList1(); 022 023 public String generateRenewItemXml(OLERenewItem olePlaceRequest) { 024 return xStream.toXML(olePlaceRequest); 025 } 026 027 public String generateRenewItemXmlForSIP2(OLERenewItem olePlaceRequest) { 028 return xStream1.toXML(olePlaceRequest); 029 } 030 031 public Object generateRenewItemObject(String xml) { 032 return xStream1.fromXML(xml); 033 } 034 035 public String generateRenewItemListXml(OLERenewItemList olePlaceRequest) { 036 return xStreamList.toXML(olePlaceRequest); 037 } 038 039 public String generateRenewItemListXmlForSip2(OLERenewItemList olePlaceRequest) { 040 return xStreamList1.toXML(olePlaceRequest); 041 } 042 043 public Object generateRenewItemListObject(String xml) { 044 return xStreamList1.fromXML(xml); 045 } 046 047 public Object generateRenewItemListObjectForSip2(String xml) { 048 return xStreamList1.fromXML(xml); 049 } 050 051 public String generateRenewItemListJson(String xml) { 052 OLERenewItemList oleRenewItemList = (OLERenewItemList) generateRenewItemListObject(xml); 053 OleCirculationHandler xmlContentHandler = new OleCirculationHandler(); 054 if (oleRenewItemList == null) { 055 oleRenewItemList = new OLERenewItemList(); 056 } 057 try { 058 return xmlContentHandler.marshalToJSON(oleRenewItemList); 059 } catch (Exception e) { 060 LOG.error(e, e); 061 } 062 return null; 063 } 064 public String generateRenewItemJson(String xml) { 065 OLERenewItem oleRenewItem = (OLERenewItem) generateRenewItemObject(xml); 066 OleCirculationHandler xmlContentHandler = new OleCirculationHandler(); 067 if (oleRenewItem == null) { 068 oleRenewItem = new OLERenewItem(); 069 } 070 try { 071 return xmlContentHandler.marshalToJSON(oleRenewItem); 072 } catch (Exception e) { 073 LOG.error(e, e); 074 } 075 return null; 076 } 077 private static XStream getXstreamList() { 078 XStream xStream = new XStream(); 079 xStream.alias("renewItem", OLERenewItem.class); 080 xStream.alias("renewItemList", OLERenewItemList.class); 081 xStream.omitField(OLERenewItem.class, "patronBarcode"); 082 xStream.omitField(OLERenewItem.class, "titleIdentifier"); 083 xStream.omitField(OLERenewItem.class, "itemBarcode"); 084 xStream.omitField(OLERenewItem.class, "feeAmount"); 085 xStream.omitField(OLERenewItem.class, "feeType"); 086 xStream.omitField(OLERenewItem.class, "mediaType"); 087 xStream.omitField(OLERenewItem.class, "transactionId"); 088 xStream.omitField(OLERenewItem.class, "itemProperties"); 089 xStream.addImplicitCollection(OLERenewItemList.class, "renewItemList", OLERenewItem.class); 090 return xStream; 091 } 092 093 private static XStream getXstreamList1() { 094 XStream xStream = new XStream(); 095 xStream.alias("renewItem", OLERenewItem.class); 096 xStream.alias("renewItemList", OLERenewItemList.class); 097 xStream.addImplicitCollection(OLERenewItemList.class, "renewItemList", OLERenewItem.class); 098 return xStream; 099 } 100 101 private static XStream getXstream() { 102 XStream xStream = new XStream(); 103 xStream.alias("renewItem", OLERenewItem.class); 104 xStream.omitField(OLERenewItem.class, "patronBarcode"); 105 xStream.omitField(OLERenewItem.class, "titleIdentifier"); 106 xStream.omitField(OLERenewItem.class, "itemBarcode"); 107 xStream.omitField(OLERenewItem.class, "feeAmount"); 108 xStream.omitField(OLERenewItem.class, "feeType"); 109 xStream.omitField(OLERenewItem.class, "mediaType"); 110 xStream.omitField(OLERenewItem.class, "transactionId"); 111 xStream.omitField(OLERenewItem.class, "itemProperties"); 112 return xStream; 113 } 114 115 private static XStream getXstream1() { 116 XStream xStream = new XStream(); 117 xStream.alias("renewItem", OLERenewItem.class); 118 return xStream; 119 } 120 121 122}