org.megam.deccanplato.provider.maluuba.handler.NormalizeEndpointImpl.java Source code

Java tutorial

Introduction

Here is the source code for org.megam.deccanplato.provider.maluuba.handler.NormalizeEndpointImpl.java

Source

/* 
** 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.maluuba.handler;

import static org.megam.deccanplato.provider.Constants.*;
import static org.megam.deccanplato.provider.maluuba.Constants.*;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.message.BasicNameValuePair;
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 class gets input from json data and retrives list of entities.
 *this class fetches time and date format text and sets time or date 
 *format. @pram type defines date range or time range. It returns 
 *specified text's date or time format value as start and end date or time. 
 */
public class NormalizeEndpointImpl 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.bizInfo = tempBizInfo;
        this.args = tempArgs;

    }

    /* (non-Javadoc)
     * @see org.megam.deccanplato.provider.BusinessActivity#run()
     */
    @Override
    public Map<String, String> run() {

        Map<String, String> outMap = new HashMap<String, String>();
        final String NORMALIZE_URL = "http://napi.maluuba.com/v0/normalize?" + PHRASE + "=" + args.get(PHRASE) + "&"
                + TYPE + "=" + args.get(TYPE) + "&" + APIKEY + "=" + args.get(APIKEY) + "&" + TIMEZONE + "="
                + args.get(TIMEZONE);

        TransportTools tst = new TransportTools(NORMALIZE_URL, null, null);
        String responseBody = null;

        TransportResponse response = null;

        try {
            response = TransportMachinery.get(tst);
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        responseBody = response.entityToString();

        outMap.put(OUTPUT, responseBody);
        return outMap;
    }

    /* (non-Javadoc)
     * @see org.megam.deccanplato.provider.BusinessActivity#name()
     */
    @Override
    public String name() {
        // TODO Auto-generated method stub
        return "normalize";
    }
}