Example #1
0
  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {

    final VelocityEngine engine = new VelocityEngine();
    engine.setProperty(
        "runtime.log.logsystem.class", "org.apache.velocity.runtime.log.NullLogChute");
    try {
      engine.init();
    } catch (Exception e) {
      log.log(Level.SEVERE, "Could not initialize velocity", e);
    }

    Template t = null;
    try {
      t = engine.getTemplate("Env.vm");
    } catch (Exception e) {
      log.log(Level.SEVERE, "Could not get the template `CurrentUser`", e);
      return;
    }

    final VelocityContext context = new VelocityContext();
    final Map<String, String> props = PropertyUtil.getPropertiesMap(properties);

    // if the showStatisticsFeature is not present in appengine-web.xml, we want it to be false.
    if (props.get("showStatisticsFeature") == null) {
      props.put("showStatisticsFeature", "false");
    }

    if (props.get("showMonitoringFeature") == null) {
      props.put("showMonitoringFeature", "false");
    }

    if (props.get("mandatoryQuestionID") == null) {
      props.put("mandatoryQuestionID", "false");
    }

    if (props.get("showExternalSourcesFeature") == null) {
      props.put("showExternalSourcesFeature", "false");
    }

    props.put("appId", SystemProperty.applicationId.get());

    if (props.get("useGoogleMapsLayers") == null) {
      props.put("useGoogleMapsLayers", "false");
    }

    if (props.get("googleMapsRegionBias") == null) {
      props.put("googleMapsRegionBias", "");
    }

    final BaseDAO<Country> countryDAO = new BaseDAO<Country>(Country.class);
    final JSONArray jsonArray = new JSONArray();
    for (Country c : countryDAO.list(Constants.ALL_RESULTS)) {
      if (c.getIncludeInExternal() != null
          && c.getIncludeInExternal()
          && (c.getCentroidLat().equals(0d) || c.getCentroidLon().equals(0d))) {
        log.log(
            Level.SEVERE,
            "Country "
                + c.getIsoAlpha2Code()
                + " was configured to show in the map, but doesn't have proper centroids");
        continue;
      }
      if (c.getIncludeInExternal() != null && c.getIncludeInExternal()) {
        jsonArray.put(new JSONObject(c));
      }
    }
    props.put("countries", jsonArray.toString());

    context.put("env", props);

    final List<Map<String, String>> roles = new ArrayList<Map<String, String>>();
    for (AppRole r : AppRole.values()) {
      if (r.getLevel() < 10) {
        continue; // don't expose NEW_USER, nor SUPER_USER
      }
      Map<String, String> role = new HashMap<String, String>();
      role.put("value", String.valueOf(r.getLevel()));
      role.put("label", "_" + r.toString());
      roles.add(role);
    }
    context.put("roles", roles);

    final StringWriter writer = new StringWriter();
    t.merge(context, writer);

    resp.setContentType("application/javascript;charset=UTF-8");

    final PrintWriter pw = resp.getWriter();
    pw.println(writer.toString());
    pw.close();
  }
Example #2
0
  public OGRFeature save(OGRFeature item) {
    // If type == country then must update can't have 2 shapes for 1 country
    if (item.getFeatureType().equals(FeatureType.COUNTRY)) {
      OGRFeature existingItem = findByCountryAndType(item.getCountryCode(), FeatureType.COUNTRY);
      if (existingItem != null) {
        existingItem.setGeometry(item.getGeometry());
        existingItem.setBoundingBox(item.getBoundingBox());
        super.save(existingItem);
        item = existingItem;
      } else {
        super.save(item);
      }
      // Save to country table as well so that we have populated it
      CountryDao countryDao = new CountryDao();
      Country country = countryDao.findByCode(item.getCountryCode());
      if (country == null) {
        country = new Country();
        country.setName(item.getName());
        country.setDisplayName(item.getName());
        country.setCentroidLat(item.getCentroidLat());
        country.setCentroidLon(item.getCentroidLon());
        country.setIsoAlpha2Code(item.getCountryCode());
        countryDao.save(country);
      } else if (country.getName() == null || country.getDisplayName() == null) {
        country.setName(item.getName());
        country.setDisplayName(item.getName());
        countryDao.save(country);
      }
      return item;
    } else {
      ArrayList<String> subList = new ArrayList<String>();
      if (item.getSub1() != null) {
        subList.add(item.getSub1());
      }
      if (item.getSub2() != null) {
        subList.add(item.getSub2());
      }
      if (item.getSub3() != null) {
        subList.add(item.getSub3());
      }
      if (item.getSub4() != null) {
        subList.add(item.getSub4());
      }
      if (item.getSub5() != null) {
        subList.add(item.getSub5());
      }
      if (item.getSub6() != null) {
        subList.add(item.getSub6());
      }

      OGRFeature existingItem =
          findByCountryTypeAndSub(
              item.getCountryCode(), item.getName(), FeatureType.SUB_COUNTRY_OTHER, subList);
      if (existingItem != null) {
        boolean isSame = true;
        if (item.getSub1() != null
            && existingItem.getSub1() != null
            && !existingItem.getSub1().equals(item.getSub1())) {
          isSame = false;
        }
        if ((item.getSub2() != null
                && existingItem.getSub2() != null
                && !existingItem.getSub2().equals(item.getSub2()))
            || (item.getSub2() == null && existingItem.getSub2() != null)) {
          isSame = false;
        }
        if (item.getSub3() != null
            && existingItem.getSub3() != null
            && !existingItem.getSub3().equals(item.getSub3())) {
          isSame = false;
        }
        if (item.getSub4() != null
            && existingItem.getSub4() != null
            && !existingItem.getSub4().equals(item.getSub4())) {
          isSame = false;
        }
        if (item.getSub5() != null
            && existingItem.getSub5() != null
            && !existingItem.getSub5().equals(item.getSub5())) {
          isSame = false;
        }
        if (item.getSub6() != null
            && existingItem.getSub6() != null
            && !existingItem.getSub6().equals(item.getSub6())) {
          isSame = false;
        }
        if (isSame) {
          existingItem.setGeometry(item.getGeometry());
          existingItem.setBoundingBox(item.getBoundingBox());
          existingItem.setCentroidLat(item.getCentroidLat());
          existingItem.setCentroidLon(item.getCentroidLon());
          super.save(existingItem);
          return existingItem;
        }
      }
      super.save(item);
      return item;
    }
  }