/* ** Copyright [2012] [Megam Systems] ** ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** ** http://www.apache.org/licenses/LICENSE-2.0 ** ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. */ package org.megam.deccanplato.provider.xero.handler; import static org.megam.deccanplato.provider.Constants.*; import static org.megam.deccanplato.provider.xero.Constants.*; import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.StringTokenizer; import net.oauth.OAuthMessage; import org.megam.deccanplato.provider.BusinessActivity; import org.megam.deccanplato.provider.core.BusinessActivityInfo; import com.rossjourdain.util.xero.ArrayOfAccount; import com.rossjourdain.util.xero.ResponseType; import com.rossjourdain.util.xero.XeroClientException; import com.rossjourdain.util.xero.XeroClientUnexpectedException; import com.rossjourdain.util.xero.XeroPublicClient; import com.rossjourdain.util.xero.XeroXmlManager; /** * @author pandiyaraja * */ public class AccountImpl implements BusinessActivity { private Map<String, String> args = new HashMap<String, String>(); private BusinessActivityInfo bizInfo; /* (non-Javadoc) * @see org.megam.deccanplato.provider.BusinessActivity#setArguments(org.megam.deccanplato.provider.core.BusinessActivityInfo, java.util.Map) */ @Override public void setArguments(BusinessActivityInfo tempBizInfo, Map<String, String> tempArgs) { this.args=tempArgs; this.bizInfo=tempBizInfo; } /* (non-Javadoc) * @see org.megam.deccanplato.provider.BusinessActivity#run() */ @Override public Map<String, String> run() { Map<String, String> outMap=null; switch(bizInfo.getActivityFunction()) { case LIST: outMap=listAll(); break; case VIEW: outMap=list(); break; } return outMap; } /** * This method returns a particular account details by * account id. It converts response data to xml data by using * XeroXmlManager class. * @param outMap * @return */ private Map<String, String> list() { Map<String,String> outMap = new HashMap<String,String>(); try { XeroPublicClient client=new XeroPublicClient(args); String responseString =client.list(args.get(ID), new StringTokenizer(args.get(BIZ_FUNCTION), "#").nextToken()); outMap.put(OUTPUT, responseString); } catch (XeroClientException e) { e.printStackTrace(); } catch (XeroClientUnexpectedException e) { e.printStackTrace(); } return outMap; } /** * This method returns a list of account details by * account id. It converts response data to xml data by using * XeroXmlManager class. * @param outMap * @return */ private Map<String, String> listAll() { Map<String,String> outMap = new HashMap<String,String>(); try { XeroPublicClient client=new XeroPublicClient(args); String responseString =client.listAll(new StringTokenizer(args.get(BIZ_FUNCTION), "#").nextToken()); outMap.put(OUTPUT, responseString); } catch (XeroClientException e) { e.printStackTrace(); } catch (XeroClientUnexpectedException e) { e.printStackTrace(); } return outMap; } /* (non-Javadoc) * @see org.megam.deccanplato.provider.BusinessActivity#name() */ @Override public String name() { // TODO Auto-generated method stub return "account"; } }