List of usage examples for com.google.gwt.jsonp.client JsonpRequestBuilder requestObject
public <T extends JavaScriptObject> JsonpRequest<T> requestObject(String url, AsyncCallback<T> callback)
From source file:gov.wa.wsdot.mobile.client.activities.trafficmap.seattleincidents.SeattleTrafficAlertsActivity.java
License:Open Source License
private void createTopicsList() { seattleIncidentItems.clear();/*from w ww.j a v a2s . co m*/ view.showProgressIndicator(); JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); // Set timeout for 30 seconds (30000 milliseconds) jsonp.setTimeout(30000); jsonp.requestObject(SEATTLE_INCIDENTS_URL, new AsyncCallback<SeattleIncidentsFeed>() { @Override public void onFailure(Throwable caught) { view.hideProgressIndicator(); phoneGap.getNotification().alert("Can't load data. Check your connection.", new AlertCallback() { @Override public void onOkButtonClicked() { // TODO Auto-generated method stub } }, "Connection Error"); } @Override public void onSuccess(SeattleIncidentsFeed result) { SeattleIncidentItem item = null; if (result.getSeattleIncidents() != null) { int numEntries = result.getSeattleIncidents().getItems().length(); for (int i = 0; i < numEntries; i++) { item = new SeattleIncidentItem(); item.setCategory(result.getSeattleIncidents().getItems().get(i).getCategory()); item.setDescription(result.getSeattleIncidents().getItems().get(i).getDescription()); item.setLastUpdatedTime(dateFormat.format(new Date(Long.parseLong(result .getSeattleIncidents().getItems().get(i).getLastUpdatedTime().substring(6, 19))))); seattleIncidentItems.add(item); } view.hideProgressIndicator(); categorizeAlerts(); view.refresh(); } } }); }
From source file:gov.wa.wsdot.mobile.client.activities.trafficmap.trafficincidents.TrafficAlertsActivity.java
License:Open Source License
private void getHighwayAlerts() { /** //from www. java 2 s .c om * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ dbService.getCacheLastUpdated(Tables.HIGHWAY_ALERTS, new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { boolean shouldUpdate = true; if (!result.isEmpty()) { double now = System.currentTimeMillis(); double lastUpdated = result.get(0).getDouble(CachesColumns.CACHE_LAST_UPDATED); shouldUpdate = (Math.abs(now - lastUpdated) > (5 * 60000)); // Refresh every 5 minutes. } if (shouldUpdate) { try { JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); // Set timeout for 30 seconds (30000 milliseconds) jsonp.setTimeout(30000); jsonp.requestObject(HIGHWAY_ALERTS_URL, new AsyncCallback<HighwayAlerts>() { @Override public void onFailure(Throwable caught) { } @Override public void onSuccess(HighwayAlerts result) { alertsToAdd.clear(); if (result.getAlerts() != null) { HighwayAlertItem item; int size = result.getAlerts().getItems().length(); for (int i = 0; i < size; i++) { item = new HighwayAlertItem(); item.setAlertId(result.getAlerts().getItems().get(i).getAlertID()); item.setHeadlineDescription( result.getAlerts().getItems().get(i).getHeadlineDescription()); item.setEventCategory( result.getAlerts().getItems().get(i).getEventCategory()); item.setStartLatitude(result.getAlerts().getItems().get(i) .getStartRoadwayLocation().getLatitude()); item.setStartLongitude(result.getAlerts().getItems().get(i) .getStartRoadwayLocation().getLongitude()); item.setLastUpdatedTime(dateFormat .format(new Date(Long.parseLong(result.getAlerts().getItems().get(i) .getLastUpdatedTime().substring(6, 19))))); alertsToAdd.add(item); } // Purge existing highway alerts covered by incoming data dbService.deleteHighwayAlerts(new VoidCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess() { // Bulk insert all the new highway alerts dbService.insertHighwayAlerts(alertsToAdd, new RowIdListCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<Integer> rowIds) { // Update the cache table with the time we did the update List<CacheItem> cacheItems = new ArrayList<CacheItem>(); cacheItems.add(new CacheItem(Tables.HIGHWAY_ALERTS, System.currentTimeMillis())); dbService.updateCachesTable(cacheItems, new VoidCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess() { addAlerts(); } }); } }); } }); } } }); } catch (Exception e) { } } else { addAlerts(); } } }); }
From source file:gov.wa.wsdot.mobile.client.activities.trafficmap.TrafficMapActivity.java
License:Open Source License
private void getCameras() { /** /*from w w w . j a va 2 s .c om*/ * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ dbService.getCacheLastUpdated(Tables.CAMERAS, new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { boolean shouldUpdate = true; if (!result.isEmpty()) { double now = System.currentTimeMillis(); double lastUpdated = result.get(0).getDouble(CachesColumns.CACHE_LAST_UPDATED); shouldUpdate = (Math.abs(now - lastUpdated) > (7 * 86400000)); // Refresh every 7 days. } view.showProgressIndicator(); if (shouldUpdate) { /** * Check the cameras table for any starred entries. If we find some, * save them to a list so we can re-star those after we flush the database. */ dbService.getStarredCameras(new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { starred.clear(); if (!result.isEmpty()) { for (GenericRow row : result) { starred.add(row.getInt(CamerasColumns.CAMERA_ID)); } } JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); // Set timeout for 30 seconds (30000 milliseconds) jsonp.setTimeout(30000); jsonp.requestObject(CAMERAS_URL, new AsyncCallback<CamerasFeed>() { @Override public void onFailure(Throwable caught) { view.hideProgressIndicator(); phoneGap.getNotification().alert("Can't load data. Check your connection.", new AlertCallback() { @Override public void onOkButtonClicked() { // TODO Auto-generated method stub } }, "Connection Error"); } @Override public void onSuccess(CamerasFeed result) { if (result.getCameras() != null) { cameraItems.clear(); CameraItem item; int numCameras = result.getCameras().getItems().length(); for (int i = 0; i < numCameras; i++) { item = new CameraItem(); item.setCameraId(result.getCameras().getItems().get(i).getId()); item.setTitle(result.getCameras().getItems().get(i).getTitle()); item.setImageUrl(result.getCameras().getItems().get(i).getUrl()); item.setLatitude(result.getCameras().getItems().get(i).getLat()); item.setLongitude(result.getCameras().getItems().get(i).getLon()); item.setHasVideo(result.getCameras().getItems().get(i).getHasVideo()); item.setRoadName(result.getCameras().getItems().get(i).getRoadName()); if (starred.contains(result.getCameras().getItems().get(i).getId())) { item.setIsStarred(1); } cameraItems.add(item); } // Purge existing cameras covered by incoming data dbService.deleteCameras(new VoidCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess() { // Bulk insert all the new cameras dbService.insertCameras(cameraItems, new RowIdListCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<Integer> rowIds) { // Update the cache table with the time we did the update List<CacheItem> cacheItems = new ArrayList<CacheItem>(); cacheItems.add(new CacheItem(Tables.CAMERAS, System.currentTimeMillis())); dbService.updateCachesTable(cacheItems, new VoidCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess() { view.hideProgressIndicator(); drawCamerasLayer(); } }); } }); } }); } } }); } }); } else { view.hideProgressIndicator(); drawCamerasLayer(); } } }); }
From source file:gov.wa.wsdot.mobile.client.activities.trafficmap.TrafficMapActivity.java
License:Open Source License
private void getHighwayAlerts() { /** /*ww w .ja v a 2s.c o m*/ * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ dbService.getCacheLastUpdated(Tables.HIGHWAY_ALERTS, new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { boolean shouldUpdate = true; if (!result.isEmpty()) { double now = System.currentTimeMillis(); double lastUpdated = result.get(0).getDouble(CachesColumns.CACHE_LAST_UPDATED); shouldUpdate = (Math.abs(now - lastUpdated) > (5 * 60000)); // Refresh every 5 minutes. } if (shouldUpdate) { try { JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); // Set timeout for 30 seconds (30000 milliseconds) jsonp.setTimeout(30000); jsonp.requestObject(HIGHWAY_ALERTS_URL, new AsyncCallback<HighwayAlerts>() { @Override public void onFailure(Throwable caught) { } @Override public void onSuccess(HighwayAlerts result) { highwayAlertItems.clear(); if (result.getAlerts() != null) { HighwayAlertItem item; int size = result.getAlerts().getItems().length(); for (int i = 0; i < size; i++) { item = new HighwayAlertItem(); item.setAlertId(result.getAlerts().getItems().get(i).getAlertID()); item.setHeadlineDescription( result.getAlerts().getItems().get(i).getHeadlineDescription()); item.setEventCategory( result.getAlerts().getItems().get(i).getEventCategory()); item.setPriority(result.getAlerts().getItems().get(i).getPriority()); item.setStartLatitude(result.getAlerts().getItems().get(i) .getStartRoadwayLocation().getLatitude()); item.setStartLongitude(result.getAlerts().getItems().get(i) .getStartRoadwayLocation().getLongitude()); item.setStartRoadName(result.getAlerts().getItems().get(i) .getStartRoadwayLocation().getRoadName()); item.setLastUpdatedTime(dateFormat .format(new Date(Long.parseLong(result.getAlerts().getItems().get(i) .getLastUpdatedTime().substring(6, 19))))); highwayAlertItems.add(item); } // Purge existing highway alerts covered by incoming data dbService.deleteHighwayAlerts(new VoidCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess() { // Bulk insert all the new highway alerts dbService.insertHighwayAlerts(highwayAlertItems, new RowIdListCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<Integer> rowIds) { // Update the cache table with the time we did the update List<CacheItem> cacheItems = new ArrayList<CacheItem>(); cacheItems.add(new CacheItem(Tables.HIGHWAY_ALERTS, System.currentTimeMillis())); dbService.updateCachesTable(cacheItems, new VoidCallback() { @Override public void onFailure( DataServiceException error) { } @Override public void onSuccess() { drawHighwayAlertsLayer(); } }); } }); } }); } } }); } catch (Exception e) { } } else { drawHighwayAlertsLayer(); } } }); }
From source file:gov.wa.wsdot.mobile.client.activities.trafficmap.traveltimes.TravelTimesActivity.java
License:Open Source License
private void createTopicsList(final TravelTimesView view) { /** /*w w w . ja v a2 s . c om*/ * Check the cache table for the last time data was downloaded. If we are within * the allowed time period, don't sync, otherwise get fresh data from the server. */ dbService.getCacheLastUpdated(Tables.TRAVEL_TIMES, new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { boolean shouldUpdate = true; if (!result.isEmpty()) { double now = System.currentTimeMillis(); double lastUpdated = result.get(0).getDouble(CachesColumns.CACHE_LAST_UPDATED); shouldUpdate = (Math.abs(now - lastUpdated) > (5 * 60000)); // Refresh every 5 minutes. } view.showProgressIndicator(); if (shouldUpdate) { /** * Check the travel times table for any starred entries. If we find some, * save them to a list so we can re-star those after we flush the database. * */ dbService.getStarredTravelTimes(new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { starred.clear(); if (!result.isEmpty()) { for (GenericRow row : result) { starred.add(row.getInt(TravelTimesColumns.TRAVEL_TIMES_ID)); } } JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); // Set timeout for 30 seconds (30000 milliseconds) jsonp.setTimeout(30000); jsonp.requestObject(TRAVEL_TIMES_URL, new AsyncCallback<TravelTimes>() { @Override public void onFailure(Throwable caught) { view.hideProgressIndicator(); phoneGap.getNotification().alert("Can't load data. Check your connection.", new AlertCallback() { @Override public void onOkButtonClicked() { // TODO Auto-generated method stub } }, "Connection Error"); } @Override public void onSuccess(TravelTimes result) { if (result.getTravelTimes() != null) { travelTimesItems.clear(); TravelTimesItem item; int numItems = result.getTravelTimes().getItems().length(); for (int i = 0; i < numItems; i++) { item = new TravelTimesItem(); item.setDistance( result.getTravelTimes().getItems().get(i).getDistance()); item.setUpdated(result.getTravelTimes().getItems().get(i).getUpdated()); item.setTitle(result.getTravelTimes().getItems().get(i).getTitle()); item.setAverageTime( result.getTravelTimes().getItems().get(i).getAverage()); item.setRouteId(Integer.parseInt( result.getTravelTimes().getItems().get(i).getRouteId(), 10)); item.setCurrentTime( result.getTravelTimes().getItems().get(i).getCurrent()); if (starred.contains(Integer.parseInt( result.getTravelTimes().getItems().get(i).getRouteId(), 10))) { item.setIsStarred(1); } travelTimesItems.add(item); } // Purge existing mountain passes covered by incoming data dbService.deleteTravelTimes(new VoidCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess() { // Bulk insert all the new travel times dbService.insertTravelTimes(travelTimesItems, new RowIdListCallback() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<Integer> rowIds) { // Update the cache table with the time we did the update ArrayList<CacheItem> cacheItems = new ArrayList<CacheItem>(); cacheItems.add(new CacheItem(Tables.TRAVEL_TIMES, System.currentTimeMillis())); dbService.updateCachesTable(cacheItems, new VoidCallback() { @Override public void onFailure( DataServiceException error) { } @Override public void onSuccess() { dbService.getTravelTimes( new ListCallback<GenericRow>() { @Override public void onFailure( DataServiceException error) { } @Override public void onSuccess( List<GenericRow> result) { getTravelTimes(view, result); } }); } }); } }); } }); } } }); } }); } else { dbService.getTravelTimes(new ListCallback<GenericRow>() { @Override public void onFailure(DataServiceException error) { } @Override public void onSuccess(List<GenericRow> result) { getTravelTimes(view, result); } }); } } }); }
From source file:gov.wa.wsdot.search.client.SearchWidget.java
License:Open Source License
/** * Make call to remote search.usa.gov server for search result data * //from w w w . j av a2 s. co m * @param page * @param query * @param url */ private static void getSearchData(String url, final String query, final String page) { JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); jsonp.requestObject(url, new AsyncCallback<Search>() { @Override public void onFailure(Throwable caught) { searchResultsForHTML.setHTML("<h4>Sorry. We had a problem getting the results for you.</h4>"); loadingImage.setVisible(false); } @Override public void onSuccess(Search search) { if (search.getResults() != null) { updateResults(search, query, page); } } }); }
From source file:gov.wa.wsdot.search.client.SearchWidget.java
License:Open Source License
/** * Make call to remote Flickr server/*from w w w .j a v a2 s . c o m*/ * @param query * @param url_flickr */ private static void getPhotoData(String url, final String query) { JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); jsonp.setCallbackParam("jsoncallback"); jsonp.requestObject(url, new AsyncCallback<Photos>() { @Override public void onFailure(Throwable caught) { // Just fail silently here. } @Override public void onSuccess(Photos photos) { if (photos.getPhotos().getPhoto() != null) { updatePhotoResults(photos, query); } } }); }
From source file:gov.wa.wsdot.search.client.SearchWidget.java
License:Open Source License
/** * Make call to remote search.usa.gov server for type ahead results *//*from w w w . j a v a 2 s . com*/ private static void getSuggestionData(String url) { JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); jsonp.requestObject(url, new AsyncCallback<Words>() { @Override public void onFailure(Throwable caught) { // Just fail silently here. } @Override public void onSuccess(Words words) { if (words.getWords() != null) { updateSuggestions(words); } } }); }
From source file:gov.wa.wsdot.search.client.SearchWidget.java
License:Open Source License
/** * Make call to WSDOT data server to retrieve current high impact alerts. */// w w w . j a v a2 s .c o m private static void getHighwayAlertsData(String url, final String query) { JsonpRequestBuilder jsonp = new JsonpRequestBuilder(); jsonp.setPredeterminedId("HA"); jsonp.requestObject(url, new AsyncCallback<HighwayAlerts>() { @Override public void onFailure(Throwable caught) { // Just fail silently here. } @Override public void onSuccess(HighwayAlerts alerts) { if (alerts.getAlerts().getItems() != null) { updateHighwayAlertsResults(alerts, query); } } }); }
From source file:it.bz.tis.sasabus.html5.client.SASAbusDBClientImpl.java
License:Open Source License
private <T> void connect(String methodUri, final String unmarshallerRootClassSimpleName, final SASAbusDBDataReady<T> callback) { final int i[] = new int[] { 0 }; final long[] times = new long[6]; times[i[0]++] = System.currentTimeMillis(); JsonpRequestBuilder jsonpRequestBuilder = new JsonpRequestBuilder(); jsonpRequestBuilder.requestObject(this.serviceBaseUrl + methodUri, new AsyncCallback<JavaScriptObject>() { @Override//from w ww . j a va 2 s . com public void onSuccess(JavaScriptObject result) { times[i[0]++] = System.currentTimeMillis(); SASAbusBackendUnmarshaller unmarshaller = new SASAbusBackendUnmarshaller(); times[i[0]++] = System.currentTimeMillis(); JSONObject jsonObject = new JSONObject(result); GWTStructure gwtStructure = new GWTStructure(jsonObject); try { times[i[0]++] = System.currentTimeMillis(); Object obj = unmarshaller.newInstance(unmarshallerRootClassSimpleName); times[i[0]++] = System.currentTimeMillis(); unmarshaller.unmarschall(gwtStructure, obj); times[i[0]++] = System.currentTimeMillis(); String report = ""; for (int k = 0; k < times.length - 1; k++) { report += "Time " + k + ": " + (times[k + 1] - times[k]) + "\n"; } callback.ready((T) obj); } catch (Exception e) { this.onFailure(e); } } @Override public void onFailure(Throwable caught) { caught.printStackTrace(); Window.alert("ko contacting server: " + caught.getClass().getName() + " - " + caught.getMessage()); } }); }