List of usage examples for java.util Vector toArray
@SuppressWarnings("unchecked") public synchronized <T> T[] toArray(T[] a)
From source file:com.ravi.apps.android.newsbytes.sync.NewsSyncAdapter.java
/** * Parses the input string in JSON format, extracts the news data and then writes it * into the content provider. Throws a JSON exception in case of any error. *//* ww w .ja va 2 s . co m*/ private void getNewsDataFromJson(String newsJsonStr) throws JSONException { try { // Create the JSON object from the input string. JSONObject newsJson = new JSONObject(newsJsonStr); // Get the JSON array containing the results. JSONArray resultsJsonArray = null; if (newsJson.has(NYT_RESULTS) && newsJson.get(NYT_RESULTS) instanceof JSONArray && newsJson.getJSONArray(NYT_RESULTS) != null && newsJson.getJSONArray(NYT_RESULTS).length() != 0) { resultsJsonArray = newsJson.getJSONArray(NYT_RESULTS); } else { // Query did not return any results, log message and return. Log.d(LOG_TAG, getContext().getString(R.string.msg_err_zero_results)); return; } // Get length of the results array. int resultsLength = resultsJsonArray.length(); // Create a vector of content values to hold the news stories. Vector<ContentValues> vectorContentValues = new Vector<ContentValues>(resultsLength); // Traverse the json array extracting each news story. for (int i = 0; i < resultsLength; i++) { // Get the JSON object corresponding to a news story. JSONObject jsonNewsStory = resultsJsonArray.getJSONObject(i); // Extract the headline from the JSON object. String headline = null; // Check if headline exists and is a non-empty string. if (jsonNewsStory.has(NYT_TITLE) && jsonNewsStory.get(NYT_TITLE) instanceof String && !jsonNewsStory.getString(NYT_TITLE).isEmpty()) { headline = jsonNewsStory.getString(NYT_TITLE); } else { // No headline found, skip this story. continue; } // Extract the thumbnail and photo from the JSON object. JSONArray multimediaJsonArray = null; String uriThumbnail = null; byte[] thumbnail = null; // Stores a blob when marked as favorite, null for now. String captionThumbnail = null; String copyrightThumbnail = null; String uriPhoto = null; byte[] photo = null; // Stores a blob when marked as favorite, null for now. String captionPhoto = null; String copyrightPhoto = null; // Check if multimedia exists and is in json array format. if (jsonNewsStory.has(NYT_MULTIMEDIA) && jsonNewsStory.get(NYT_MULTIMEDIA) instanceof JSONArray && jsonNewsStory.getJSONArray(NYT_MULTIMEDIA) != null) { // Get the multimedia json array. multimediaJsonArray = jsonNewsStory.getJSONArray(NYT_MULTIMEDIA); // Traverse the multimedia json array. for (int j = 0; j < multimediaJsonArray.length(); j++) { // Get the JSON object corresponding to an image. JSONObject jsonImage = multimediaJsonArray.getJSONObject(j); // Get the image format. String format = null; if (jsonImage.has(NYT_FORMAT) && jsonImage.get(NYT_FORMAT) instanceof String && jsonImage.getString(NYT_FORMAT) != null && !jsonImage.getString(NYT_FORMAT).isEmpty()) { // Get the image format. format = jsonImage.getString(NYT_FORMAT); } else { // Image format not found, skip this image. continue; } // Extract the image only if it's thumbnail or normal format. if (format.equals(NYT_FORMAT_STANDARD_THUMBNAIL)) { // Extract thumbnail uri. if (jsonImage.has(NYT_URL) && jsonImage.get(NYT_URL) instanceof String && jsonImage.getString(NYT_URL) != null && !jsonImage.getString(NYT_URL).isEmpty()) { uriThumbnail = jsonImage.getString(NYT_URL); } else { // Thumbnail uri not found, skip this image. continue; } // Extract thumbnail caption. if (jsonImage.has(NYT_CAPTION) && jsonImage.get(NYT_CAPTION) instanceof String && jsonImage.getString(NYT_CAPTION) != null && !jsonImage.getString(NYT_CAPTION).isEmpty()) { captionThumbnail = jsonImage.getString(NYT_CAPTION); } // Extract thumbnail copyright. if (jsonImage.has(NYT_COPYRIGHT) && jsonImage.get(NYT_COPYRIGHT) instanceof String && jsonImage.getString(NYT_COPYRIGHT) != null && !jsonImage.getString(NYT_COPYRIGHT).isEmpty()) { copyrightThumbnail = jsonImage.getString(NYT_COPYRIGHT); } } else if (format.equals(NYT_FORMAT_NORMAL)) { // Extract photo uri. if (jsonImage.has(NYT_URL) && jsonImage.get(NYT_URL) instanceof String && jsonImage.getString(NYT_URL) != null && !jsonImage.getString(NYT_URL).isEmpty()) { uriPhoto = jsonImage.getString(NYT_URL); } else { // Photo uri not found, skip this image. continue; } // Extract photo caption. if (jsonImage.has(NYT_CAPTION) && jsonImage.get(NYT_CAPTION) instanceof String && jsonImage.getString(NYT_CAPTION) != null && !jsonImage.getString(NYT_CAPTION).isEmpty()) { captionPhoto = jsonImage.getString(NYT_CAPTION); } // Extract photo copyright. if (jsonImage.has(NYT_COPYRIGHT) && jsonImage.get(NYT_COPYRIGHT) instanceof String && jsonImage.getString(NYT_COPYRIGHT) != null && !jsonImage.getString(NYT_COPYRIGHT).isEmpty()) { copyrightPhoto = jsonImage.getString(NYT_COPYRIGHT); } } } } else { // No thumbnail or photo found, skip this story. continue; } // Extract the summary from the JSON object. String summary = null; if (jsonNewsStory.has(NYT_ABSTRACT) && jsonNewsStory.get(NYT_ABSTRACT) instanceof String && !jsonNewsStory.getString(NYT_ABSTRACT).isEmpty()) { summary = jsonNewsStory.getString(NYT_ABSTRACT); } // Extract the uri for the story from the JSON object. String uriStory = null; if (jsonNewsStory.has(NYT_URL) && jsonNewsStory.get(NYT_URL) instanceof String && !jsonNewsStory.getString(NYT_URL).isEmpty()) { uriStory = jsonNewsStory.getString(NYT_URL); } // Extract the author from the JSON object. String author = null; if (jsonNewsStory.has(NYT_BYLINE) && jsonNewsStory.get(NYT_BYLINE) instanceof String && !jsonNewsStory.getString(NYT_BYLINE).isEmpty()) { author = jsonNewsStory.getString(NYT_BYLINE); } // Extract the date from the JSON object. String date = null; if (jsonNewsStory.has(NYT_PUBLISHED_DATE) && jsonNewsStory.get(NYT_PUBLISHED_DATE) instanceof String && !jsonNewsStory.getString(NYT_PUBLISHED_DATE).isEmpty()) { date = jsonNewsStory.getString(NYT_PUBLISHED_DATE); } // Marked as favorite, false for now. int isFavorite = 0; // Create content values for this news story. ContentValues newsValues = new ContentValues(); newsValues.put(NewsContract.NewsEntry.COLUMN_HEADLINE, headline); newsValues.put(NewsContract.NewsEntry.COLUMN_SUMMARY, summary); newsValues.put(NewsContract.NewsEntry.COLUMN_URI_STORY, uriStory); newsValues.put(NewsContract.NewsEntry.COLUMN_AUTHOR, author); newsValues.put(NewsContract.NewsEntry.COLUMN_DATE, date); newsValues.put(NewsContract.NewsEntry.COLUMN_URI_THUMBNAIL, uriThumbnail); newsValues.put(NewsContract.NewsEntry.COLUMN_THUMBNAIL, thumbnail); newsValues.put(NewsContract.NewsEntry.COLUMN_CAPTION_THUMBNAIL, captionThumbnail); newsValues.put(NewsContract.NewsEntry.COLUMN_COPYRIGHT_THUMBNAIL, copyrightThumbnail); newsValues.put(NewsContract.NewsEntry.COLUMN_URI_PHOTO, uriPhoto); newsValues.put(NewsContract.NewsEntry.COLUMN_PHOTO, photo); newsValues.put(NewsContract.NewsEntry.COLUMN_CAPTION_PHOTO, captionPhoto); newsValues.put(NewsContract.NewsEntry.COLUMN_COPYRIGHT_PHOTO, copyrightPhoto); newsValues.put(NewsContract.NewsEntry.COLUMN_IS_FAVORITE, isFavorite); // Add the content values into the vector. vectorContentValues.add(newsValues); } // Check rows inserted and deleted. int rowsInserted = 0; int rowsDeleted = 0; // Add the news stories into the database. if (vectorContentValues.size() > 0) { // Copy the vector values into content values array. ContentValues[] arrayContentValues = new ContentValues[vectorContentValues.size()]; vectorContentValues.toArray(arrayContentValues); // Delete the older data before inserting, except those marked as favorite. rowsDeleted = getContext().getContentResolver().delete(NewsContract.NewsEntry.CONTENT_URI, NewsContract.NewsEntry.COLUMN_IS_FAVORITE + "=?", new String[] { Integer.toString(0) }); // Bulk insert into news table. rowsInserted = getContext().getContentResolver().bulkInsert(NewsContract.NewsEntry.CONTENT_URI, arrayContentValues); } Log.d(LOG_TAG, getContext().getString(R.string.log_sync_completed)); Log.d(LOG_TAG, getContext().getString(R.string.log_rows_deleted) + rowsDeleted); Log.d(LOG_TAG, getContext().getString(R.string.log_rows_inserted) + rowsInserted); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } }
From source file:com.glandorf1.joe.wsprnetviewer.app.sync.WsprNetViewerSyncAdapter.java
/** * Parse the Document containing the wspr data in HTML format. * Call from 'doInBackground()', etc.//w w w. j a v a 2 s . co m */ public void getWsprDataFromTags(Context context, Document wsprHtml, int maxSpots, String gridsquareSetting, boolean drupal) throws Throwable { // These are the names of the objects that need to be extracted. // column# 0 1 2 3 4 5 6 7 8 9 10 // Timestamp Call MHz SNR Drift Grid Pwr Reporter RGrid km az // 2014-08-25 20:40 DL8EDC 7.040186 -4 0 JO31le 5 LA3JJ/L JO59bh 925 11 // Gridsquare information final String WSPRNET_IDX_CITY = "city_name"; final String WSPRNET_IDX_COUNTRY_NAME = "name"; //final String WSPRNET_IDX_COORD = "coord"; final String WSPRNET_IDX_COORD_LAT = "lat"; final String WSPRNET_IDX_COORD_LONG = "lon"; // Wspr information html element indices for their 'new' drupal interface. // e.g.: http://wsprnet.org/drupal/wsprnet/spots final int WSPRNET_IDX_TIMESTAMP = 0; final int WSPRNET_IDX_TX_CALLSIGN = 1; final int WSPRNET_IDX_TX_FREQ_MHZ = 2; final int WSPRNET_IDX_RX_SNR = 3; final int WSPRNET_IDX_RX_DRIFT = 4; final int WSPRNET_IDX_TX_GRIDSQUARE = 5; final int WSPRNET_IDX_TX_POWER = 6; final int WSPRNET_IDX_RX_CALLSIGN = 7; final int WSPRNET_IDX_RX_GRIDSQUARE = 8; final int WSPRNET_IDX_DISTANCE = 9; final int WSPRNET_IDX_AZIMUTH = 10; // Wspr information html element indices for their 'old' url query interface. // e.g.: http://wsprnet.org/olddb?mode=html&band=all&limit=10&findcall=&findreporter=&sort=date final int WSPRNET_IDX_OLDDB_TIMESTAMP = 0; final int WSPRNET_IDX_OLDDB_TX_CALLSIGN = 1; final int WSPRNET_IDX_OLDDB_TX_FREQ_MHZ = 2; final int WSPRNET_IDX_OLDDB_RX_SNR = 3; final int WSPRNET_IDX_OLDDB_RX_DRIFT = 4; final int WSPRNET_IDX_OLDDB_TX_GRIDSQUARE = 5; final int WSPRNET_IDX_OLDDB_TX_POWER_DBM = 6; final int WSPRNET_IDX_OLDDB_TX_POWER_W = 7; final int WSPRNET_IDX_OLDDB_RX_CALLSIGN = 8; final int WSPRNET_IDX_OLDDB_RX_GRIDSQUARE = 9; final int WSPRNET_IDX_OLDDB_DISTANCE_KM = 10; final int WSPRNET_IDX_OLDDB_DISTANCE_MILES = 11; // Notification calculations double minSNR = Utility.getNotifyMinSNR(context); double notifyBandMHz = Utility.getNotifyBand(context), notifyBandMHzMin = notifyBandMHz - 0.001, notifyBandMHzMax = notifyBandMHz + 0.001; if (notifyBandMHz < 0.00001) { notifyBandMHzMin = 0; notifyBandMHzMax = 1e300; } String bandName = ""; mBandNameIdx = -1; // reset which band was found for notification int nHits = 0, nHitsSnr = 0, nHitsBand = 0, nHitsDistance = 0, nHitsTxCall = 0, nHitsRxCall = 0, nHitsTxGrid = 0, nHitsRxGrid = 0; double notifyMinTxRxKm = Utility.getNotifyTxRxKm(context); // Get the tx/rx notify callsigns, but configure for wildcard matching with regex's. String displayTxCallsign = Utility.getNotifyCallsign(context, true), displayRxCallsign = Utility.getNotifyCallsign(context, false); String displayTxGridsquare = Utility.getNotifyGridsquare(context, true), displayRxGridsquare = Utility.getNotifyGridsquare(context, false); String notifyTxCallsign = Utility.filterCleanupMatch(displayTxCallsign), notifyRxCallsign = Utility.filterCleanupMatch(displayRxCallsign); String notifyTxGridsquare = Utility.filterCleanupMatch(displayTxGridsquare), notifyRxGridsquare = Utility.filterCleanupMatch(displayRxGridsquare); boolean snrOk = false, bandOk = false, distanceOk = false, txCallOk = false, rxCallOk = false, txGridOk = false, rxGridOk = false; boolean snrEna = true, bandEna = (notifyBandMHz < 0.00001), distanceEna = (notifyMinTxRxKm >= 0.001), txCallEna = (notifyTxCallsign.length() > 0), rxCallEna = (notifyRxCallsign.length() > 0), txGridEna = (notifyTxGridsquare.length() > 0), rxGridEna = (notifyRxGridsquare.length() > 0); // Delete items older than the cutoff period specified in the settings menu. // TODO: It might be easier to use System.currentTimeMillis(), which returns time in UTC. BUT, // todo: Date objects seem to work in the local time zone; wasn't able to initialize one to UTC. Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); TimeZone tz = TimeZone.getDefault(); int offsetUTC = tz.getOffset(cal.getTimeInMillis()) / 1000; int seconds = Utility.cutoffSeconds(context); cal.add(Calendar.SECOND, -offsetUTC); cal.add(Calendar.SECOND, -seconds); String cutoffTimestamp = WsprNetContract.getDbTimestampString(cal.getTime()); int d; d = context.getContentResolver().delete(WsprNetContract.SignalReportEntry.CONTENT_URI, WsprNetContract.SignalReportEntry.COLUMN_TIMESTAMPTEXT + " <= ?", new String[] { cutoffTimestamp }); Log.v(LOG_TAG, "getWsprDataFromTags: deleted " + Integer.toString(d) + " old items."); // Get the cutoff date for notifications. cal.setTime(new Date()); seconds = Utility.updateIntervalSeconds(context); cal.add(Calendar.SECOND, -offsetUTC); cal.add(Calendar.SECOND, -seconds); long cutoffNotifyTimeMin = getShortTimestamp(cal.getTime()); cal.add(Calendar.SECOND, 2 * seconds); long cutoffNotifyTimeMax = getShortTimestamp(cal.getTime()); long iTimestamp = 0; try { // TODO: get city name, lat/long from gridsquare; determine how to look this up String cityName = context.getString(R.string.unknown_city); // generic text until the city/country is looked up String countryName = context.getString(R.string.unknown_country); double cityLatitude = Utility.gridsquareToLatitude(gridsquareSetting); double cityLongitude = Utility.gridsquareToLongitude(gridsquareSetting); Log.v(LOG_TAG, cityName + ", with coord: " + cityLatitude + " " + cityLongitude); // Insert the gridsquare into the database. long locationID = addGridsquare(context, gridsquareSetting, cityName, countryName, cityLatitude, cityLongitude); Elements wsprHeader, wsprHeader1, wsprHeader2; // TODO: someday, match up header name instead of relying on a fixed column # Elements wsprData; if (drupal == true) { wsprHeader = wsprHtml .select("div#block-system-main.block.block-system div.content table tbody tr:eq(0)"); wsprData = wsprHtml .select("div#block-system-main.block.block-system div.content table tbody tr:gt(0)"); } else { wsprHeader1 = wsprHtml.select("html body table tbody tr:eq(0)"); wsprHeader2 = wsprHtml.select("html body table tbody tr:eq(1)"); wsprData = wsprHtml.select("html body table tbody tr:gt(1)"); } // Get and insert the new wspr information into the database Vector<ContentValues> cVVector = new Vector<ContentValues>(wsprData.size()); for (int i = 0; (i < wsprData.size()) && (i < maxSpots); i++) { Elements wsprTDRow = wsprData.get(i).select("td"); // table data row split into <td> elements // These are the values that will be collected. // column# 0 1 2 3 4 5 6 7 8 9 10 // Timestamp Call MHz SNR Drift Grid Pwr Reporter RGrid km az String timestamp, txCallsign, txGridsquare, rxCallsign, rxGridsquare; Double txFreqMhz, rxSnr, rxDrift, txPower, kmDistance, azimuth; if (drupal == true) { // Wspr information for the 'drupal' url query interface. // Get wspr info from http://www.wsprnet.org/drupal/wsprnet/spots; e.g.: // <table> // <tr> <th's> Timestamp Call MHz SNR Drift Grid Pwr Reporter RGrid km az // <tr> <td's> 2014-08-25 20:40 DL8EDC 7.040186 -4 0 JO31le 5 LA3JJ/L JO59bh 925 11 // <tr> <td's> 2014-08-25 20:40 DL8EDC 7.040183 -9 0 JO31le 5 OZ2ABB JO65au 618 31 // <tr> <td's> 2014-08-25 20:40 DL8EDC 7.040178 -14 0 JO31le 5 OH7FES KP53bh 1919 37 // ... </table> // Note: each item in the header or row is a <td> (but not shown above.) // Use the Firefox plugin Firebug to determine the html structure: // highlight one of the table rows, right-click on the corresponding <TR> element in the // plugin, then select "Copy CSS Path"; clipboard contains, e.g.: // html.js body.html.not-front.not-logged-in.one-sidebar.sidebar-first.page-wsprnet.page-wsprnet-spots div#page div#middlecontainer div#main div#squeeze div#squeeze-content div#inner-content div.region.region-content div#block-system-main.block.block-system div.content table tbody tr //Elements wsprHeader = wsprHtml.select("div#block-system-main.block.block-system div.content table tbody tr:eq(0)"); //Elements wsprData = wsprHtml.select("div#block-system-main.block.block-system div.content table tbody tr:gt(0)"); //Element wsprOneRow = wsprData.get(0); // syntax to get specific element # //Elements wsprTDRow = wsprRow.select("th"); // syntax to get header elements //Elements wsprTDRow = wsprRow.select("td"); // syntax to get data elements // Get rid of " " (non-break space character) // Save timestamp as: "yyyyMMddHHmmssSSS" timestamp = parseTimestamp(wsprTDRow.get(WSPRNET_IDX_TIMESTAMP).text() .replace(Utility.NBSP, ' ').replace(" .", ".").replace(".0000", "").trim()); txCallsign = wsprTDRow.get(WSPRNET_IDX_TX_CALLSIGN).text().replace(Utility.NBSP, ' ').trim() .toUpperCase(); txFreqMhz = Double.parseDouble( wsprTDRow.get(WSPRNET_IDX_TX_FREQ_MHZ).text().replace(Utility.NBSP, ' ').trim()); rxSnr = Double.parseDouble( wsprTDRow.get(WSPRNET_IDX_RX_SNR).text().replace(Utility.NBSP, ' ').trim()); rxDrift = Double.parseDouble( wsprTDRow.get(WSPRNET_IDX_RX_DRIFT).text().replace(Utility.NBSP, ' ').trim()); txGridsquare = wsprTDRow.get(WSPRNET_IDX_TX_GRIDSQUARE).text().replace(Utility.NBSP, ' ') .trim(); // mixed case! txPower = Double.parseDouble( wsprTDRow.get(WSPRNET_IDX_TX_POWER).text().replace(Utility.NBSP, ' ').trim()); rxCallsign = wsprTDRow.get(WSPRNET_IDX_RX_CALLSIGN).text().replace(Utility.NBSP, ' ').trim() .toUpperCase(); rxGridsquare = wsprTDRow.get(WSPRNET_IDX_RX_GRIDSQUARE).text().replace(Utility.NBSP, ' ') .trim(); // mixed case! kmDistance = Double.parseDouble( wsprTDRow.get(WSPRNET_IDX_DISTANCE).text().replace(Utility.NBSP, ' ').trim()); azimuth = Double.parseDouble( wsprTDRow.get(WSPRNET_IDX_AZIMUTH).text().replace(Utility.NBSP, ' ').trim()); } else { // Wspr information for the 'old' url query interface. // e.g.: http://wsprnet.org/olddb?mode=html&band=all&limit=10&findcall=&findreporter=&sort=date // Save timestamp as: "yyyyMMddHHmmssSSS" timestamp = parseTimestamp(wsprTDRow.get(WSPRNET_IDX_OLDDB_TIMESTAMP).text() .replace(Utility.NBSP, ' ').replace(" .", ".").replace(".0000", "").trim()); txCallsign = wsprTDRow.get(WSPRNET_IDX_OLDDB_TX_CALLSIGN).text().replace(Utility.NBSP, ' ') .trim().toUpperCase(); txFreqMhz = Double.parseDouble( wsprTDRow.get(WSPRNET_IDX_OLDDB_TX_FREQ_MHZ).text().replace(Utility.NBSP, ' ').trim()); rxSnr = Double.parseDouble( wsprTDRow.get(WSPRNET_IDX_OLDDB_RX_SNR).text().replace(Utility.NBSP, ' ').trim()); rxDrift = Double.parseDouble( wsprTDRow.get(WSPRNET_IDX_OLDDB_RX_DRIFT).text().replace(Utility.NBSP, ' ').trim()); txGridsquare = wsprTDRow.get(WSPRNET_IDX_OLDDB_TX_GRIDSQUARE).text().replace(Utility.NBSP, ' ') .trim(); // mixed case! txPower = Double.parseDouble( wsprTDRow.get(WSPRNET_IDX_OLDDB_TX_POWER_DBM).text().replace(Utility.NBSP, ' ').trim()); rxCallsign = wsprTDRow.get(WSPRNET_IDX_OLDDB_RX_CALLSIGN).text().replace(Utility.NBSP, ' ') .trim().toUpperCase(); rxGridsquare = wsprTDRow.get(WSPRNET_IDX_OLDDB_RX_GRIDSQUARE).text().replace(Utility.NBSP, ' ') .trim(); // mixed case! kmDistance = Double.parseDouble( wsprTDRow.get(WSPRNET_IDX_OLDDB_DISTANCE_KM).text().replace(Utility.NBSP, ' ').trim()); //miDistance = Double.parseDouble(wsprTDRow.get(WSPRNET_IDX_OLDDB_DISTANCE_MILES).text().replace(Utility.NBSP, ' ').trim()); // azimuth not provided; must calculate it ourselves azimuth = Utility.latLongToAzimuth(Utility.gridsquareToLatitude(txGridsquare), Utility.gridsquareToLongitude(txGridsquare), Utility.gridsquareToLatitude(rxGridsquare), Utility.gridsquareToLongitude(rxGridsquare)); } // parse the html // Collect the values together. ContentValues wsprValues = new ContentValues(); wsprValues.put(WsprNetContract.SignalReportEntry.COLUMN_LOC_KEY, locationID); wsprValues.put(WsprNetContract.SignalReportEntry.COLUMN_TIMESTAMPTEXT, timestamp); wsprValues.put(WsprNetContract.SignalReportEntry.COLUMN_TX_CALLSIGN, txCallsign); wsprValues.put(WsprNetContract.SignalReportEntry.COLUMN_TX_FREQ_MHZ, txFreqMhz); wsprValues.put(WsprNetContract.SignalReportEntry.COLUMN_RX_SNR, rxSnr); wsprValues.put(WsprNetContract.SignalReportEntry.COLUMN_RX_DRIFT, rxDrift); wsprValues.put(WsprNetContract.SignalReportEntry.COLUMN_TX_GRIDSQUARE, txGridsquare); wsprValues.put(WsprNetContract.SignalReportEntry.COLUMN_TX_POWER, txPower); wsprValues.put(WsprNetContract.SignalReportEntry.COLUMN_RX_CALLSIGN, rxCallsign); wsprValues.put(WsprNetContract.SignalReportEntry.COLUMN_RX_GRIDSQUARE, rxGridsquare); wsprValues.put(WsprNetContract.SignalReportEntry.COLUMN_DISTANCE, kmDistance); wsprValues.put(WsprNetContract.SignalReportEntry.COLUMN_AZIMUTH, azimuth); cVVector.add(wsprValues); // Are any reports significant enough to notify the user? // For now, notify user if the SNR (signal-to-noise ratio) in a report for a particular // band is above a threshold. The SNR and frequency band are user preferences. // TODO: determine the full criteria for notifications. E.g.: // a specific frequency band has opened up, // maybe to a particular region, // maybe some minimum number of reports at a minimum SNR. try { iTimestamp = Long .parseLong(timestamp.substring(0, WsprNetContract.TIMESTAMP_FORMAT_DB_SHORT.length())); if ((cutoffNotifyTimeMin > 0) && (cutoffNotifyTimeMax > 0) && (cutoffNotifyTimeMin <= iTimestamp) && (iTimestamp < cutoffNotifyTimeMax)) { // getFrequencyBandCheck() will check what band the TX frequency is in. // frequencyBandNotifyCheck will check if it is in the notification band. double bandMHz = getFrequencyBandCheck(context, txFreqMhz, mBandFrequencyTolerancePercent); bandOk = !bandEna || frequencyBandNotifyCheck(bandMHz, notifyBandMHzMin, notifyBandMHzMax); snrOk = !snrEna || (rxSnr >= minSNR); distanceOk = !distanceEna || (kmDistance >= notifyMinTxRxKm); txCallOk = !txCallEna || txCallsign.matches(notifyTxCallsign); rxCallOk = !rxCallEna || rxCallsign.matches(notifyRxCallsign); txGridOk = !txGridEna || txGridsquare.toUpperCase().matches(notifyTxGridsquare); rxGridOk = !rxGridEna || rxGridsquare.toUpperCase().matches(notifyRxGridsquare); if (bandOk && snrOk && distanceOk && txCallOk && rxCallOk && txGridOk && rxGridOk) { nHits++; nHitsBand += (bandEna && bandOk) ? 1 : 0; nHitsSnr += (snrEna && snrOk) ? 1 : 0; nHitsDistance += (distanceEna && distanceOk) ? 1 : 0; nHitsTxCall += (txCallEna && txCallOk) ? 1 : 0; nHitsRxCall += (rxCallEna && rxCallOk) ? 1 : 0; nHitsTxGrid += (txGridEna && txGridEna) ? 1 : 0; nHitsRxGrid += (rxGridEna && rxGridEna) ? 1 : 0; } } } catch (Exception e) { // nothing to do } } // parse html tags // Insert items into database. if (cVVector.size() > 0) { ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); int ii = context.getContentResolver().bulkInsert(WsprNetContract.SignalReportEntry.CONTENT_URI, cvArray); Log.v(LOG_TAG, "getWsprDataFromTags: inserted " + cVVector.size() + "(" + Integer.toString(ii) + ") items"); } // Remove items with an unreasonable timestamp (>24 hours from now); otherwise, they're displayed forever! // TODO: don't insert these in the first place! cal.setTime(new Date()); cal.add(Calendar.HOUR, 24); String tomorrowTimestamp = WsprNetContract.getDbTimestampString(cal.getTime()); d = context.getContentResolver().delete(WsprNetContract.SignalReportEntry.CONTENT_URI, WsprNetContract.SignalReportEntry.COLUMN_TIMESTAMPTEXT + " > ?", new String[] { tomorrowTimestamp }); Log.v(LOG_TAG, "getWsprDataFromTags: deleted " + Integer.toString(d) + " invalid items."); // Did any reports meet the notification criteria? if (nHits > 0) { String description = ""; if (notifyBandMHz < 0.00001) { bandName = "---"; } else { bandName = getFrequencyBandName(context, mBandNameIdx); //description += context.getString(R.string.band_open) + ":"; } if (nHitsTxCall > 0) { description += " " + context.getString(R.string.pref_filter_label_tx_callsign) + "=" + displayTxCallsign + ";"; } if (nHitsRxCall > 0) { description += " " + context.getString(R.string.pref_filter_label_rx_callsign) + "=" + displayRxCallsign + ";"; } if (nHitsTxGrid > 0) { description += " " + context.getString(R.string.pref_filter_label_tx_gridsquare) + "=" + displayTxGridsquare + ";"; } if (nHitsRxGrid > 0) { description += " " + context.getString(R.string.pref_filter_label_rx_gridsquare) + "=" + displayRxGridsquare + ";"; } if (nHitsDistance > 0) { // TODO: Display either km or miles. See SettingsActivity.java, onPreferenceChange(). description += " distance>=" + Utility.formatDistance(context, notifyMinTxRxKm, Utility.isMetric(context)) + "km;"; } notifyWspr(context, bandName, description, minSNR); } } catch (Exception e) { Log.d(LOG_TAG, "getWsprDataFromTags exception: " + e.toString()); } }
From source file:com.irets.datadownloader.SearchPropertyServlet.java
@Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { SimpleDateFormat sdf = new SimpleDateFormat("MMM dd,yyyy HH:mm"); long reqInputArrivalTime = System.currentTimeMillis(); Date resultdate = new Date(reqInputArrivalTime); System.out.println("Calling Me @:" + sdf.format(resultdate) + ", from: " + request.getRemoteAddr() + ", with url> " + request.getRequestURL() + "?" + request.getQueryString()); long startTime = reqInputArrivalTime; WebApplicationContext wac = WebApplicationContextUtils .getRequiredWebApplicationContext(getServletContext()); SearchService propServices = this.getSearchService(wac); propServices.setContextPath(this.getUrl3(request)); //propServices.setServer(this.getServer(request)); Filter filer = new Filter(); ArrayList<FilterItem> filterItemArrayList = new ArrayList<FilterItem>(1); ArrayList<FilterItem> exactFilterItemArrayList = new ArrayList<FilterItem>(1); ArrayList<FilterItem> multipleFilterItemArrayList = new ArrayList<FilterItem>(1); ArrayList<String> keywordArrayList = new ArrayList<String>(1); Vector<SimpleRange> rangeVector = new Vector<SimpleRange>(1); GeoParameter geoParam = null;// w ww . ja v a 2s .c om // SimpleRange aRange = new SimpleRange("price_list",null,50000); // filer.setRanges(new SimpleRange[]{aRange}); int start = 0; int limit = -1; // if(request.getParameter("ListingId") != null){ // FilterItem filterItem = new FilterItem(); // filterItem.setField("number_MLS"); // filterItem.setValue(request.getParameter("ListingId")); // filterItemArrayList.add(filterItem); // } if (request.getParameter("ListPrice") != null) { SimpleRange aRange; String listPrice = request.getParameter("ListPrice"); System.out.println("List price is " + listPrice); String min = ""; String max = ""; if (!listPrice.equalsIgnoreCase("No Min-No Max")) { if (listPrice.indexOf(":") != -1) { // System.out.println("listPrice : -->>"+listPrice); min = listPrice.substring(0, listPrice.indexOf(":")); max = listPrice.substring(listPrice.indexOf(":") + 1, listPrice.length()); aRange = new SimpleRange("price_list", min, max); } else if (listPrice.endsWith("+")) { // System.out.println("listPrice +-->>"+listPrice); min = listPrice.substring(0, listPrice.indexOf("+")); aRange = new SimpleRange("price_list", min, null); } else if (listPrice.endsWith("-")) { // System.out.println("listPrice - -->>"+listPrice); max = listPrice.substring(0, listPrice.indexOf("-")); aRange = new SimpleRange("price_list", null, max); } else if (listPrice.length() > 0) { // Exact match.... min = listPrice.substring(0, listPrice.length()); max = min; aRange = new SimpleRange("price_list", min, max); } else { aRange = new SimpleRange("price_list", null, null); } rangeVector.add(aRange); } } if (request.getParameter("Bedrooms") != null) { SimpleRange aRange; String bedrooms = request.getParameter("Bedrooms"); String min = ""; String max = ""; if (!bedrooms.equalsIgnoreCase("No Min-No Max")) { if (bedrooms.indexOf(":") != -1) { // System.out.println("Bedrooms: -->>"+bedrooms); min = bedrooms.substring(0, bedrooms.indexOf(":")); max = bedrooms.substring(bedrooms.indexOf(":") + 1, bedrooms.length()); aRange = new SimpleRange("number_beds_Total", min, max); } else if (bedrooms.endsWith("+")) { // System.out.println("Bedrooms+ -->>"+bedrooms); min = bedrooms.substring(0, bedrooms.indexOf("+")); aRange = new SimpleRange("number_beds_Total", min, null); } else if (bedrooms.endsWith("-")) { // System.out.println("Bedrooms- -->>"+bedrooms); max = bedrooms.substring(0, bedrooms.indexOf("-")); aRange = new SimpleRange("number_beds_Total", null, max); } else if (bedrooms.length() > 0) { // Exact match.... min = bedrooms.substring(0, bedrooms.length()); max = min; aRange = new SimpleRange("number_beds_Total", min, max); } else { aRange = new SimpleRange("number_beds_Total", null, null); } rangeVector.add(aRange); } } if (request.getParameter("FullBathrooms") != null) { SimpleRange aRange; String fullBath = request.getParameter("FullBathrooms"); String min = ""; String max = ""; if (!fullBath.equalsIgnoreCase("No Min-No Max")) { if (fullBath.indexOf(":") != -1) { // System.out.println("FullBathrooms: -->>"+fullBath); min = fullBath.substring(0, fullBath.indexOf(":")); max = fullBath.substring(fullBath.indexOf(":") + 1, fullBath.length()); aRange = new SimpleRange("number_baths_Full", min, max); } else if (fullBath.endsWith("+")) { // System.out.println("FullBathrooms+ -->>"+fullBath); min = fullBath.substring(0, fullBath.indexOf("+")); aRange = new SimpleRange("number_baths_Full", min, null); } else if (fullBath.endsWith("-")) { // System.out.println("FullBathrooms- -->>"+fullBath); max = fullBath.substring(0, fullBath.indexOf("-")); aRange = new SimpleRange("number_baths_Full", null, max); } else if (fullBath.length() > 0) { min = fullBath.substring(0, fullBath.length()); max = min; aRange = new SimpleRange("number_baths_Full", min, max); } else { aRange = new SimpleRange("number_baths_Full", null, null); } rangeVector.add(aRange); } } if (request.getParameter("SqFt") != null) { SimpleRange aRange; String sqFt = request.getParameter("SqFt"); String min = ""; String max = ""; if (!sqFt.equalsIgnoreCase("No Min-No Max")) { if (sqFt.indexOf(":") != -1) { // System.out.println("SqFt: -->>"+sqFt); min = sqFt.substring(0, sqFt.indexOf(":")); max = sqFt.substring(sqFt.indexOf(":") + 1, sqFt.length()); aRange = new SimpleRange("sqft_Structure", min, max); } else if (sqFt.endsWith("+")) { // System.out.println("SqFt+ -->>"+sqFt); min = sqFt.substring(0, sqFt.indexOf("+")); aRange = new SimpleRange("sqft_Structure", min, null); } else if (sqFt.endsWith("-")) { // System.out.println("SqFt- -->>"+sqFt); max = sqFt.substring(0, sqFt.indexOf("-")); aRange = new SimpleRange("sqft_Structure", null, max); } else if (sqFt.length() > 0) { min = sqFt.substring(0, sqFt.length()); max = min; aRange = new SimpleRange("sqft_Structure", min, max); } else { aRange = new SimpleRange("sqft_Structure", null, null); } rangeVector.add(aRange); } } // Date range for the property. if (request.getParameter("Age") != null) { SimpleRange aRange; String age = request.getParameter("Age"); String min = ""; String max = ""; if (!age.equalsIgnoreCase("No Min-No Max")) { if (age.indexOf(":") != -1) { System.out.println("age: -->>" + age); min = age.substring(0, age.indexOf(":")); max = age.substring(age.indexOf(":") + 1, age.length()); aRange = new SimpleRange("date_Listing_Modification", min, max); } else if (age.endsWith("+")) { // System.out.println("SqFt+ -->>"+sqFt); min = age.substring(0, age.indexOf("+")); aRange = new SimpleRange("date_Listing_Modification", min, null); } else if (age.endsWith("-")) { // System.out.println("SqFt- -->>"+sqFt); max = age.substring(0, age.indexOf("-")); aRange = new SimpleRange("date_Listing_Modification", null, max); } else if (age.length() > 0) { min = age.substring(0, age.length()); max = min; aRange = new SimpleRange("date_Listing_Modification", min, max); } else { aRange = new SimpleRange("date_Listing_Modification", null, null); } System.out.println("Range is " + aRange.getMinValue() + ", " + aRange.getMaxValue()); rangeVector.add(aRange); } } // Range for Longitude if (request.getParameter("Longitude") != null) { SimpleRange aRange; String longitude = request.getParameter("Longitude"); System.out.println("Longitude is " + longitude); String min = ""; String max = ""; if (longitude.indexOf(":") != -1) { min = longitude.substring(0, longitude.indexOf(":")); max = longitude.substring(longitude.indexOf(":") + 1, longitude.length()); aRange = new SimpleRange("_long", min, max); } else { aRange = new SimpleRange("_long", null, null); } rangeVector.add(aRange); } // Range for Latitude if (request.getParameter("Latitude") != null) { SimpleRange aRange; String latitude = request.getParameter("Latitude"); System.out.println("Latitude is " + latitude); String min = ""; String max = ""; if (latitude.indexOf(":") != -1) { min = latitude.substring(0, latitude.indexOf(":")); max = latitude.substring(latitude.indexOf(":") + 1, latitude.length()); aRange = new SimpleRange("lat", min, max); } else { aRange = new SimpleRange("lat", null, null); } rangeVector.add(aRange); } // Near by homes // Format required is Latitude,Longitude,distance if (request.getParameter("NBH") != null) { String nbh = request.getParameter("NBH"); String[] s = nbh.split(","); if (s.length == 3) { Float f = Float.valueOf(s[2]); if (f >= 10) // 10 miles radius max s[2] = "10"; else if (f < 0) // if negative distance s[2] = "1"; geoParam = new GeoParameter(s[0], s[1], s[2]); } } else { // City and Zip are optional if NBH is provided. if (request.getParameter("Zip") != null) { FilterItem filterItem = new FilterItem(); filterItem.setField("zipCode"); // remove the space first String inZipcode = request.getParameter("Zip"); StringBuffer zipBuffer = new StringBuffer(); if (inZipcode.indexOf(",") > -1) { StringTokenizer sToken = new StringTokenizer(inZipcode, ","); while (sToken.hasMoreElements()) { String object = (String) sToken.nextElement(); zipBuffer.append("'"); zipBuffer.append(object); zipBuffer.append("'"); if (sToken.countTokens() > 0) zipBuffer.append(","); } } else { zipBuffer.append("'"); zipBuffer.append(inZipcode); zipBuffer.append("'"); } //System.out.println(zipBuffer.toString()); filterItem.setValue(zipBuffer.toString()); multipleFilterItemArrayList.add(filterItem); } if (request.getParameter("City") != null) { FilterItem filterItem = new FilterItem(); filterItem.setField("name_City"); String cityList = request.getParameter("City"); StringBuffer cityMod = new StringBuffer(); if (cityList.indexOf(",") > -1) { StringTokenizer sToken = new StringTokenizer(cityList, ","); while (sToken.hasMoreElements()) { String object = (String) sToken.nextElement(); cityMod.append("'"); cityMod.append(getCity(object)); cityMod.append("'"); if (sToken.countTokens() > 0) cityMod.append(","); } } else { cityMod.append("'"); cityMod.append(getCity(cityList)); cityMod.append("'"); } filterItem.setValue(cityMod.toString()); multipleFilterItemArrayList.add(filterItem); } } // Status of property, link Active or Pending // For backward compatibility, Status=A. we added extra checks // for Status=ACTIVE or PENDING /* * if(request.getParameter("Status") != null && (request.getParameter("Status").equalsIgnoreCase("ACTIVE")|| request.getParameter("Status").equalsIgnoreCase("PENDING"))){ FilterItem filterItem = new FilterItem(); filterItem.setField("status_Listing"); filterItem.setValue(request.getParameter("Status")); if (request.getParameter("Status").equalsIgnoreCase("PENDING")){ filterItem.setValue(propServices.getPendingStatus()); } filterItemArrayList.add(filterItem); } */ if (request.getParameter("Status") != null && (request.getParameter("Status").equalsIgnoreCase("ACTIVE") || request.getParameter("Status").equalsIgnoreCase("PENDING"))) { FilterItem filterItem = new FilterItem(); filterItem.setField("status_Listing"); StringBuffer statusMod = new StringBuffer(); String statusList = null; if (request.getParameter("Status").equalsIgnoreCase("ACTIVE")) { statusList = propServices.getActiveStatus(); } else if (request.getParameter("Status").equalsIgnoreCase("PENDING")) { statusList = propServices.getPendingStatus(); } if (statusList.indexOf(",") > -1) { StringTokenizer sToken = new StringTokenizer(statusList, ","); while (sToken.hasMoreElements()) { String object = (String) sToken.nextElement(); statusMod.append("'"); statusMod.append(object); statusMod.append("'"); if (sToken.countTokens() > 0) statusMod.append(","); } } else { statusMod.append("'"); statusMod.append(statusList); statusMod.append("'"); } System.out.println("Status query..: " + statusMod.toString()); filterItem.setValue(statusMod.toString()); multipleFilterItemArrayList.add(filterItem); } if (request.getParameter("ListingId") != null) { FilterItem filterItem = new FilterItem(); filterItem.setField("number_MLS"); String listingId = request.getParameter("ListingId"); String mlsNumberPrefix = propServices.getMlsNumberPrefix(); StringBuffer listingIdList = new StringBuffer(); if (listingId.indexOf(",") > -1) { StringTokenizer sToken = new StringTokenizer(listingId, ","); while (sToken.hasMoreElements()) { String object = (String) sToken.nextElement(); if ((mlsNumberPrefix != null) && (!mlsNumberPrefix.equals("")) && (!object.contains(mlsNumberPrefix))) { listingIdList.append("'" + mlsNumberPrefix); } else { listingIdList.append("'"); } listingIdList.append(object); listingIdList.append("'"); if (sToken.countTokens() > 0) listingIdList.append(","); } } else { if ((mlsNumberPrefix != null) && (!mlsNumberPrefix.equals("")) && (!listingId.contains(mlsNumberPrefix))) listingIdList.append("'" + mlsNumberPrefix); else listingIdList.append("'"); listingIdList.append(listingId); listingIdList.append("'"); } filterItem.setValue(listingIdList.toString()); multipleFilterItemArrayList.add(filterItem); //System.out.println("got listing id "+ request.getParameter("ListingId")); } if (request.getParameter("ListingAgentLic") != null) { FilterItem filterItem = new FilterItem(); filterItem.setField("listing_license_number"); String listingId = request.getParameter("ListingAgentLic"); if (listingId.indexOf(",") > -1) { StringTokenizer sToken = new StringTokenizer(listingId, ","); while (sToken.hasMoreElements()) { keywordArrayList.add((String) sToken.nextElement()); } } else { keywordArrayList.add(listingId); } //System.out.println("got listing agent lic "+ request.getParameter("ListingAgentLic")); } if (request.getParameter("offset") != null) { start = Integer.parseInt(request.getParameter("offset")); } if (request.getParameter("limit") != null) { limit = Integer.parseInt(request.getParameter("limit")); } String sort = request.getParameter("sort"); if (sort != null) { if (sort.equalsIgnoreCase("City")) { sort = "name_City"; } else if (sort.equalsIgnoreCase("YearBuilt")) { sort = "year_Built"; } else if (sort.equalsIgnoreCase("ListPrice")) { sort = "price_List"; } else if (sort.equalsIgnoreCase("Sqft")) { sort = "sqft_Structure"; } else if (sort.equalsIgnoreCase("LotSqFt")) { sort = "Size_Lot"; } else if (sort.equalsIgnoreCase("Type")) { sort = ""; } else if (sort.equalsIgnoreCase("Bedrooms")) { sort = "number_beds_Total"; } else if (sort.equalsIgnoreCase("FullBathrooms")) { sort = "number_baths_Full"; } else if (sort.equalsIgnoreCase("ExteriorFeatures")) { sort = "type_Property"; } else if (sort.equalsIgnoreCase("none")) { sort = null; } } String sort_direction = request.getParameter("sort_direction"); if (sort_direction != null) { if (sort_direction.equalsIgnoreCase("none")) { sort_direction = null; } else if (sort_direction.equalsIgnoreCase("ASC")) { sort_direction = "asc"; } else { sort_direction = "desc"; } } else { //{TOD: why do we need this?? if (request.getParameter("ListingAgentLic") != null) { sort = "price_List"; sort_direction = "desc"; // with agent listing, they want desc } else { sort_direction = "asc"; // default sorting order } } // Type of property, link Single Family, Townhouse, Condominium if (request.getParameter("ExteriorFeatures") != null) { String param = request.getParameter("ExteriorFeatures"); FilterItem filterItem = new FilterItem(); filterItem.setField("type_Property"); List<ExteriorFeaturesData> extFeatureData = propServices.getExtFeaturesData(); // Getting ExFeatures list from properties files if (extFeatureData != null) { System.out.println("Exterior Features param is " + param); for (ExteriorFeaturesData efd : extFeatureData) { if (efd.getName().equalsIgnoreCase(param)) { filterItem.setValue(efd.getInSearchFields()); break; } } if (filterItem.getValue() != null) { System.out.println("Exterior Features value " + filterItem.getValue()); multipleFilterItemArrayList.add(filterItem); } } else {// Getting ExFeatures list from DB filterItem.setValue(param); System.out.println("Exterior Features (single) " + filterItem.getValue()); filterItemArrayList.add(filterItem); } } // Adding the search parameter for Full Address if (request.getParameter("FullAddress") != null) { FilterItem filterItem = new FilterItem(); filterItem.setField("address_Filtered"); filterItem.setValue(request.getParameter("FullAddress")); filterItemArrayList.add(filterItem); } boolean returnOpenHouseData = false; if (request.getParameter("OpenHouse") != null) { if (request.getParameter("OpenHouse").equals("1")) { returnOpenHouseData = true; } } // Put the keyword search (using it for license id) String[] filterArrayKeyword = new String[keywordArrayList.size()]; filterArrayKeyword = keywordArrayList.toArray(filterArrayKeyword); filer.setKeywords(filterArrayKeyword); // Put range in the filter SimpleRange[] sRangeArray = new SimpleRange[rangeVector.size()]; sRangeArray = rangeVector.toArray(sRangeArray); filer.setRanges(sRangeArray); // Put single value item in the filter with '%value%' FilterItem[] filterArray = new FilterItem[filterItemArrayList.size()]; filterArray = filterItemArrayList.toArray(filterArray); filer.setFilters(filterArray); // Put single value item in the filter, with exact search with 'value' FilterItem[] exactFilterArray = new FilterItem[exactFilterItemArrayList.size()]; exactFilterArray = exactFilterItemArrayList.toArray(exactFilterArray); filer.setExactFilters(exactFilterArray); // Put the multiple values (',' separated) item in the filter. FilterItem[] filterItemA = new FilterItem[multipleFilterItemArrayList.size()]; filterItemA = multipleFilterItemArrayList.toArray(filterItemA); filer.setSearchForFieldItems(filterItemA); //System.out.println("time in making query:"+(new Date().getTime()-startTime)+" msecs"); //System.out.println("limit " + request.getParameter("limit") + ", offset " + // request.getParameter("offset") +", sort " + sort + ", sort direction "+ sort_direction); Object returnObj = null; startTime = new Date().getTime(); // Create a Timer and a TimerTask Timer timer = new Timer(); TimerTask task = new SearchPropertyTimerTask(request, response, this.getOutputType()); // Set timer for 30 sec, method takes args in milliseconds. timer.schedule(task, 30 * 1000); boolean timedoutResponse = true;// Default is timed out response. try { /* for testing of timer functionality. try { Thread.sleep(10000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ Properties prop = propServices.searchForProperties(start, limit, sort, sort_direction, filer, geoParam, returnOpenHouseData); prop.setElapsedTime(BigInteger.valueOf(System.currentTimeMillis() - reqInputArrivalTime)); if (this.getOutputType().equalsIgnoreCase("json")) { returnObj = getJSONReturnObj(prop); } else { returnObj = prop; } } catch (LargeResultSetException e) { Errors errors = new Errors(); com.irets.generated.Error error = new com.irets.generated.Error(); error.setCode(e.getErrorCode()); error.setDescription(e.getMessage()); errors.getError().add(error); errors.setTotalcount(BigInteger.valueOf(e.getTotalCount())); errors.setElapsedtime(BigInteger.valueOf(System.currentTimeMillis() - reqInputArrivalTime)); returnObj = errors; System.out.println(e.getMessage()); } finally { if (task.cancel()) { timedoutResponse = false;// No timeout, send normal response. } } System.out.println("time in database call:" + (new Date().getTime() - startTime) + " msecs"); //startTime = new Date().getTime(); //GSONHelper.serializeToJSON(prop, response.getOutputStream()); if (!timedoutResponse) { if (this.getOutputType().equalsIgnoreCase("json")) { response.setContentType("application/json"); JacksonJSONHelper.serializeToJSON(returnObj, response.getOutputStream(), response); } else { response.setContentType("text/xml"); JAXBHelper.serializeToXML(returnObj, response.getOutputStream()); } } //System.out.println("time in making output:"+(new Date().getTime()-startTime)+" msecs"); System.out.println("Done!!!! elapsed time: " + (System.currentTimeMillis() - reqInputArrivalTime)); }