Package iEvents.services

Source Code of iEvents.services.Tempo

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package iEvents.services;

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

import UtilClasses.PrevisaoMetereologica;
import UtilServices.Weather;
import com.google.gson.Gson;
import java.util.Arrays;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;


/**
* REST Web Service
*
* @author Developer
*/
@Path("tempo")
public class Tempo {

    @Context
    private UriInfo context;

    private List<String> allowedModes = Arrays.asList( "short", "normal", "long" );
   
    /**
     * Creates a new instance of Teatro
     */
    public Tempo() {
    }
   
    /**
     * Retrieves representation of an instance of bioware.search.resources.SimpleSearch
     * @return an instance of java.lang.String
     */
    @GET
    @Produces("application/json")
    public String getJson( @QueryParam("mode") String mode,
                            @QueryParam("distrito") String distrito,
                            @QueryParam("callback") String callback
                          ) {
 
        //Verificar mode
        if( mode == null || mode.isEmpty() ){
              mode = "short";   //Valor por defeito
        }
        else if( !allowedModes.contains(mode) ){ return "{\"error\":\"invalid mode\"}"; }

        if( distrito == null || distrito.isEmpty() ){
            return "{\"error\":\"missing parameter district\"}";
        }
       
        //Criar objecto gson para fazer a transformacao
        Gson gson = new Gson();

        PrevisaoMetereologica data = Weather.getWeatherByRegion(distrito);
        String dataOut = new String();
       
        if( data != null ){
            dataOut = gson.toJson(data);
        }

        if( callback == null || callback.isEmpty() )
            return "{\"data\":" + dataOut + "}";
        else
            return ( callback + "({\"data\":" + dataOut + "})" );
       
    }

}

TOP

Related Classes of iEvents.services.Tempo

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.