Package com.drighetto.lmb.persistence.model

Examples of com.drighetto.lmb.persistence.model.Ride


   */
  @Test
  public void testDao01() throws Exception {
    long start = System.currentTimeMillis();
    Rides rs = Rides.BERTRANGE_HOWALD;
    Ride r = HowaldTunnelStatisticsDao.retrieveRideInformations(rs);
    Assert.assertNotNull(r);
    Assert.assertEquals(rs.getDriveWayCode(), r.getShortName());
    Assert.assertNotNull(r.getDisplayName());
    Assert.assertTrue(r.getCurrent() > 0);
    Assert.assertTrue(r.getAverage() > 0);
    Assert.assertTrue(r.getMaximum() > 0);
    System.out.printf("Test 'testDao01' performed in %s ms\n", (System.currentTimeMillis() - start));
  }
View Full Code Here


   */
  @Test
  public void testDao02() throws Exception {
    long start = System.currentTimeMillis();
    Rides rs = Rides.BERCHEM_HOWALD;
    Ride r = HowaldTunnelStatisticsDao.retrieveRideInformations(rs);
    Assert.assertNotNull(r);
    Assert.assertEquals(rs.getDriveWayCode(), r.getShortName());
    Assert.assertNotNull(r.getDisplayName());
    Assert.assertTrue(r.getCurrent() > 0);
    Assert.assertTrue(r.getAverage() > 0);
    Assert.assertTrue(r.getMaximum() > 0);
    System.out.printf("Test 'testDao02' performed in %s ms\n", (System.currentTimeMillis() - start));
  }
View Full Code Here

   */
  @Test
  public void testDao03() throws Exception {
    long start = System.currentTimeMillis();
    Rides rs = Rides.IRRGARTEN_HOWALD;
    Ride r = HowaldTunnelStatisticsDao.retrieveRideInformations(rs);
    Assert.assertNotNull(r);
    Assert.assertEquals(rs.getDriveWayCode(), r.getShortName());
    Assert.assertNotNull(r.getDisplayName());
    Assert.assertTrue(r.getCurrent() > 0);
    Assert.assertTrue(r.getAverage() > 0);
    Assert.assertTrue(r.getMaximum() > 0);
    System.out.printf("Test 'testDao03' performed in %s ms\n", (System.currentTimeMillis() - start));
  }
View Full Code Here

   *        Ride desired
   * @return the ride informations through a VO
   * @throws LMBException
   */
  public static Ride retrieveRideInformations(Rides rides) throws LMBException {
    Ride ride = null;
    try {
      /*
       * Step 1 : Use a HTML parser (JTidy) to load the page as XML object
       * document
       */
      Tidy tidy = new Tidy();
      tidy.setIndentContent(false);
      tidy.setHideComments(true);
      tidy.setQuiet(true);
      tidy.setShowWarnings(false);
      tidy.setShowErrors(0);
      tidy.setXHTML(false);
      tidy.setSmartIndent(false);
      Document doc = tidy.parseDOM(new URL(HTML_URL).openStream(), null);

      /*
       * Step 2 : Get the ID identifying the content according to the ride
       * specified (the content is stored in a DIV)
       */
      String divID = "";
      switch (rides) {
      case BERCHEM_HOWALD: {
        divID = "stats-3";
        break;
      }
      case IRRGARTEN_HOWALD: {
        divID = "stats-2";
        break;
      }
      case BERTRANGE_HOWALD: {
        divID = "stats-1";
        break;
      }
      default: {
        divID = "stats-1";
        break;
      }
      }

      /* Step 3 : Use XPATH to extract ride informations */
      XPath xp = XPathFactory.newInstance().newXPath();
      // Extract the short name
      String expr = "//div[@id='" + divID + "']/div[@class='header']/h3/text()";
      String rideShortName = xp.evaluate(expr, doc);
      // Extract the display name
      expr = "//div[@id='" + divID + "']/div[@class='header']/span/text()";
      String rideDisplayName = xp.evaluate(expr, doc);
      // Extract the current delay
      expr = "//div[@id='" + divID + "']/ul/li[@class='time-actu']/span/text()";
      int rideCurrentDelay = Integer.parseInt(xp.evaluate(expr, doc).trim().split(" ")[0]);
      // Extract the average delay
      expr = "//div[@id='" + divID + "']/ul/li[@class='time-average']/span/text()";
      int rideAverageDelay = Integer.parseInt(xp.evaluate(expr, doc).trim().split(" ")[0]);
      // Extract the max delay
      expr = "//div[@id='" + divID + "']/ul/li[@class='time-max']/span/text()";
      int rideMaximumDelay = Integer.parseInt(xp.evaluate(expr, doc).trim().split(" ")[0]);

      /* Step 4 : Create the storage VO */
      ride = new Ride(rideShortName, rideDisplayName, rideCurrentDelay, rideAverageDelay, rideMaximumDelay);

    } catch (Exception e) {
      throw new LMBException(e);
    }

View Full Code Here

              rd = r;
              break;
            }
          }
        }
        Ride r = HowaldTunnelStatisticsDao.retrieveRideInformations(rd);
        // Store ride informations in a request attribute
        req.setAttribute("THRIDE", r);
      } catch (LMBException e) {
        LOGGER.severe(e.getMessage());
        req.removeAttribute("THRIDE");
View Full Code Here

TOP

Related Classes of com.drighetto.lmb.persistence.model.Ride

Copyright © 2018 www.massapicom. 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.