Android Open Source - bike-friend Station Resource






From Project

Back to project page bike-friend.

License

The source code is released under:

GNU General Public License

If you think the Android project bike-friend listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.lemoulinstudio.bikefriend.webapp.rest;
/*from   w w  w  .j a  v a  2  s. co m*/
import com.lemoulinstudio.bikefriend.webapp.entity.Station;
import com.lemoulinstudio.bikefriend.webapp.vo.StationLogVo;
import com.lemoulinstudio.bikefriend.webapp.vo.StationVo;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.geo.Circle;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

/**
 *
 * @author Vincent Cantin
 */
@Component
@Path("station")
public class StationResource {
  
  @Autowired
  private MongoTemplate db;
  
  @GET
  @Produces(MediaType.APPLICATION_JSON)
  public List<StationVo> getStation(
          @QueryParam("id") String id,
          @QueryParam("provider") Station.Provider provider,
          @QueryParam("lon") Double longitude,
          @QueryParam("lat") Double latitude,
          @QueryParam("dist") Double distance,
          @QueryParam("test") Boolean includeTestStations) {
    Criteria criteria = new Criteria();
    
    if (id != null) {
      criteria = criteria.and("_id").is(new ObjectId(id));
    }
    
    if (provider != null) {
      criteria = criteria.and("provider").is(provider);
    }
    
    if (longitude != null && latitude != null && distance != null) {
      criteria = criteria.and("location").withinSphere(
              new Circle(longitude, latitude, distance / 6371));
    }
    
    if (!Boolean.TRUE.equals(includeTestStations)) {
      criteria = criteria.and("isTestStation").is(false);
    }
    
    List<StationVo> stations = db.find(new Query(criteria), StationVo.class, "station");
    
    return stations;
  }
  
  @GET
  @Path("{stationId}/logs")
  @Produces(MediaType.APPLICATION_JSON)
  public List<StationLogVo> getStationLogs(
          @PathParam("stationId") String stationId,
          @QueryParam("from") long from,
          @QueryParam("to") long to) {
    List<StationLogVo> logs = db.find(new Query(Criteria
            .where("stationId").is(new ObjectId(stationId))
            .and("date").gte(from).lte(to))
            .with(new Sort(Sort.Direction.ASC, "date")),
            StationLogVo.class,
            "stationLog");
    
    return logs;
  }
  
}




Java Source Code List

com.lemoulinstudio.bikefriend.InternetStationProvider.java
com.lemoulinstudio.bikefriend.ParsingException.java
com.lemoulinstudio.bikefriend.StationInfoWindowAdapter.java
com.lemoulinstudio.bikefriend.StationMapActivity.java
com.lemoulinstudio.bikefriend.StationParser.java
com.lemoulinstudio.bikefriend.StationProvider.java
com.lemoulinstudio.bikefriend.Station.java
com.lemoulinstudio.bikefriend.Utils.java
com.lemoulinstudio.bikefriend.cbike.CBikeStationXmlParserV1.java
com.lemoulinstudio.bikefriend.cbike.CBikeStation.java
com.lemoulinstudio.bikefriend.cbike.KaohsiungStationProvider.java
com.lemoulinstudio.bikefriend.ubike.ChanghuaStationProvider.java
com.lemoulinstudio.bikefriend.ubike.TaichungStationProvider.java
com.lemoulinstudio.bikefriend.ubike.TaipeiStationProvider.java
com.lemoulinstudio.bikefriend.ubike.YouBikeStationCSVParserV1.java
com.lemoulinstudio.bikefriend.ubike.YouBikeStationHtmlParserV2.java
com.lemoulinstudio.bikefriend.ubike.YouBikeStationJsonParserV1.java
com.lemoulinstudio.bikefriend.ubike.YouBikeStation.java
com.lemoulinstudio.bikefriend.webapp.StationParser.java
com.lemoulinstudio.bikefriend.webapp.cbike.BIKEStationData.java
com.lemoulinstudio.bikefriend.webapp.cbike.BIKEStation.java
com.lemoulinstudio.bikefriend.webapp.cbike.CBikeStationParser.java
com.lemoulinstudio.bikefriend.webapp.cbike.XmlStation.java
com.lemoulinstudio.bikefriend.webapp.conf.ShutdownHook.java
com.lemoulinstudio.bikefriend.webapp.conf.StartupHook.java
com.lemoulinstudio.bikefriend.webapp.entity.StationLog.java
com.lemoulinstudio.bikefriend.webapp.entity.Station.java
com.lemoulinstudio.bikefriend.webapp.io.InputStreamSequence.java
com.lemoulinstudio.bikefriend.webapp.io.IntArrayInputStream.java
com.lemoulinstudio.bikefriend.webapp.quartz.LoadStationDataJob.java
com.lemoulinstudio.bikefriend.webapp.rest.StationResource.java
com.lemoulinstudio.bikefriend.webapp.ubike.MarkerList.java
com.lemoulinstudio.bikefriend.webapp.ubike.Marker.java
com.lemoulinstudio.bikefriend.webapp.ubike.YouBikeStationParser.java
com.lemoulinstudio.bikefriend.webapp.vo.StationLogVo.java
com.lemoulinstudio.bikefriend.webapp.vo.StationVo.java