/** * “Copyright 2012 Megam Systems” * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. **/ package org.megam.deccanplato.provider.salesforce.chatter.handler; import static org.megam.deccanplato.provider.Constants.*; import static org.megam.deccanplato.provider.salesforce.crm.Constants.*; import java.io.IOException; import java.net.URISyntaxException; import java.util.HashMap; import java.util.Map; import org.apache.http.client.ClientProtocolException; import org.megam.deccanplato.http.TransportMachinery; import org.megam.deccanplato.http.TransportResponse; import org.megam.deccanplato.http.TransportTools; import org.megam.deccanplato.provider.BusinessActivity; import org.megam.deccanplato.provider.core.BusinessActivityInfo; /** * @author pandiyaraja * *This Record Feed class implements salesforce chatter record feed items *this class shows record feed url and record feed item */ public class RecordFeedImpl implements BusinessActivity{ private BusinessActivityInfo bizInfo; private Map<String, String> args = new HashMap<String, String>(); /* * (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.bizInfo = tempBizInfo; this.args = tempArgs; } /* * (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 = list(); break; case VIEW: outMap=view(); break; } return outMap; } /** * This business method Returns the feed-items for all the records the current, * signed-in user is following, or all the feed-items of the specified recordId. * @param outMap(User id) * @return */ private Map<String, String> view() { Map<String, String> outMap=new HashMap<>(); final String SALESFORCE_CHATTER_ACTIVITY_URL = "/services/data/v26.0/chatter/records/"+args.get(ID)+"/followers"; Map<String, String> header = new HashMap<String, String>(); header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN)); TransportTools tst = new TransportTools(args.get(INSTANCE_URL) + SALESFORCE_CHATTER_ACTIVITY_URL, null, header); try { String response = TransportMachinery.get(tst).entityToString(); outMap.put(OUTPUT, response); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); }; return outMap; } /** * This business method Returns a URL to the feed-items for all * the records the current user is following, or a URL to all * the feed-items of the specified recordId. * @param outMap(User ID) * @return */ private Map<String, String> list() { Map<String, String> outMap=new HashMap<>(); final String SALESFORCE_CHATTER_ACTIVITY_URL = "/services/data/v26.0/chatter/records/"+args.get(ID); Map<String, String> header = new HashMap<String, String>(); header.put(S_AUTHORIZATION, S_OAUTH + args.get(ACCESS_TOKEN)); TransportTools tst = new TransportTools(args.get(INSTANCE_URL) + SALESFORCE_CHATTER_ACTIVITY_URL, null, header); try { String response = TransportMachinery.get(tst).entityToString(); outMap.put(OUTPUT, response); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } return outMap; } /* * (non-Javadoc) * * @see org.megam.deccanplato.provider.BusinessActivity#name() */ @Override public String name() { return "record"; } }