001package org.kuali.ole.ncip.converter;
002
003import com.thoughtworks.xstream.XStream;
004import org.apache.log4j.Logger;
005import org.kuali.ole.ncip.bo.OLELookupUserResponse;
006import org.kuali.ole.ncip.bo.OLEUserPrivilege;
007
008/**
009 * Created with IntelliJ IDEA.
010 * User: sheiksalahudeenm
011 * Date: 9/4/13
012 * Time: 12:05 PM
013 * To change this template use File | Settings | File Templates.
014 */
015public class OLELookupUserResponseConverter {
016    final Logger LOG = Logger.getLogger(OLELookupUserResponseConverter.class);
017
018    public String generateLookupUserResponseXml(OLELookupUserResponse lookupUser){
019        XStream xstream = new XStream();
020        xstream.alias("lookupUser",OLELookupUserResponse.class);
021        xstream.alias("userPrivilege",OLEUserPrivilege.class);
022        xstream.aliasField("userPrivileges", OLELookupUserResponse.class, "userPrivileges");
023        String response  =xstream.toXML(lookupUser);
024
025        System.out.println(response);
026        return  response;
027    }
028
029
030
031    public OLELookupUserResponse getLookupUser(String xml){
032        XStream xstream = new XStream();
033        xstream.alias("lookupUser",OLELookupUserResponse.class);
034        xstream.alias("userPrivilege",OLEUserPrivilege.class);
035        xstream.aliasField("userPrivileges", OLELookupUserResponse.class, "userPrivileges");
036        OLELookupUserResponse oleLookupUser   =(OLELookupUserResponse)xstream.fromXML(xml);
037        return oleLookupUser;
038    }
039
040    public String generateLookupUserJson(String xml) {
041        OLELookupUserResponse oleLookupUser = (OLELookupUserResponse)getLookupUser(xml);
042        OleCirculationHandler xmlContentHandler = new OleCirculationHandler();
043        try{
044            return xmlContentHandler.marshalToJSON(oleLookupUser);
045        }catch(Exception e){
046            LOG.error(e,e);
047        }
048        return null;
049    }
050
051
052
053
054}