Ejemplo n.º 1
0
  @Override
  public Location addLocation(Long companyId, String name, Double coordX, Double coordY)
      throws Exception {
    try {
      Company company = companyDAO.findByPrimaryKey(companyId);
      if (company == null) {
        throw new Exception("Company doesn't exists");
      }

      Location location = new Location();
      location.setName(name);
      //			GeometryFactory geometryFactory = new GeometryFactory(new
      // PrecisionModel(PrecisionModel.FIXED), 4326);
      //			System.out.print("GeometryFactory");
      //			Geometry geom = (Geometry) geometryFactory.createPoint(new Coordinate(coordX, coordY));
      //			System.out.print("createPoint");
      //			location.setGeom(geom);
      //			System.out.print("setGeom");
      //			location.setCompany(company);
      //			System.out.print("setCompany");

      // First interpret the WKT string to a point
      WKTReader fromText = new WKTReader();
      Geometry geom = null;
      try {
        geom = fromText.read("POINT(10 5)");
      } catch (ParseException e) {
        throw new RuntimeException(
            "Not a WKT string:" + "SRID=4326;POINT(-56.2564083434446 -34.8982159791812)");
      }
      if (!geom.getGeometryType().equals("Point")) {
        throw new RuntimeException("Geometry must be a point. Got a " + geom.getGeometryType());
      }
      System.out.print("createPoint");
      location.setGeom((Point) geom);
      System.out.print("setGeom");
      location.setCompany(company);
      System.out.print("setCompany");

      company.getLocations().put(location.getName(), location);
      System.out.print("put");
      company = companyDAO.update(company);
      System.out.print("update");

      return company.getLocations().get(location.getName());
    } catch (Exception exc) {
      throw exc;
    }
  }
Ejemplo n.º 2
0
 @Override
 public List<Location> findAllLocationsFromCompany(Long companyId) throws Exception {
   try {
     Company company = companyDAO.findByPrimaryKey(companyId);
     if (company == null) {
       throw new Exception("Company doesn't exists");
     }
     return (List<Location>) company.getLocations().values();
   } catch (Exception exc) {
     throw exc;
   }
 }