Ejemplo n.º 1
0
 @Override
 public void serializeContent(XmlSerializer serializer) throws IOException {
   if (isEmpty()) return;
   SerializerUtils.addTextTag(serializer, VCardProperty.FN.toString(), getFormattedName());
   serializer.startTag(null, N_NAME);
   for (Entry<NameProperty, String> entry : name.entrySet())
     SerializerUtils.addTextTag(serializer, entry.getKey().toString(), entry.getValue());
   serializer.endTag(null, N_NAME);
   for (Entry<VCardProperty, String> entry : properties.entrySet())
     if (entry.getKey() != VCardProperty.FN)
       SerializerUtils.addTextTag(serializer, entry.getKey().toString(), entry.getValue());
   for (Photo photo : photos) photo.serialize(serializer);
   for (Address address : addresses) address.serialize(serializer);
   for (Label label : labels) label.serialize(serializer);
   for (Telephone telephone : telephones) telephone.serialize(serializer);
   for (Email email : emails) email.serialize(serializer);
   for (Logo logo : logos) logo.serialize(serializer);
   for (Sound sound : sounds) sound.serialize(serializer);
   for (Geo geo : geos) geo.serialize(serializer);
   for (Organization organization : organizations) organization.serialize(serializer);
   if (!categories.isEmpty()) {
     serializer.startTag(null, CATEGORIES_NAME);
     for (String keyword : categories)
       SerializerUtils.addTextTag(serializer, KEYWORD_NAME, keyword);
     serializer.endTag(null, CATEGORIES_NAME);
   }
   if (classification != null)
     SerializerUtils.addTextTag(serializer, CLASS_NAME, classification.toString());
   for (Key key : keys) key.serialize(serializer);
 }
Ejemplo n.º 2
0
 @Nonnull
 private GeoRectangle calcBoundingBox(final double c) {
   final double lowerLeftLat = center.getLat() - (Geo.metersToDegreesLat(radiusMeters) * c);
   final double lowerLeftLon =
       center.getLon() - (Geo.metersToDegreesLonAtLat(radiusMeters, center.getLat()) * c);
   final double upperRightLat = center.getLat() + (Geo.metersToDegreesLat(radiusMeters) * c);
   final double upperRightLon =
       center.getLon() + Geo.metersToDegreesLonAtLat(radiusMeters, center.getLat() * c);
   return new GeoRectangle(
       new GeoPoint(lowerLeftLat, lowerLeftLon), new GeoPoint(upperRightLat, upperRightLon));
 }
 public double evaluate(double input, double wavelength, double low, double high) {
   switch (this) {
     case sine:
       return Geo.sineSync(input, wavelength, low, high);
     case triangle:
       return Geo.triSync(input, wavelength, low, high);
     case square:
       return Geo.sqrSync(input, wavelength, low, high);
     default:
       return Double.NaN;
   }
 }
Ejemplo n.º 4
0
 /**
  * Create a circle geo area with 2 points: one is the center, the other a point on the circle.
  *
  * @param center Center.
  * @param point Point in circle.
  */
 public GeoCircle(@Nonnull final GeoPoint center, @Nonnull final GeoPoint point) {
   super();
   assert center != null;
   assert point != null;
   final double lat = Math.abs(center.getLat() - point.getLat());
   final double lon = Math.abs(center.getLon() - point.getLon());
   final double w = Geo.degreesLatToMeters(lat);
   final double h = Geo.degreesLonToMetersAtLat(lon, (center.getLat() + point.getLat()) / 2.0);
   final double radius = Math.sqrt((w * w) + (h * h));
   this.center = center;
   this.radiusMeters = radius;
 }
Ejemplo n.º 5
0
    /**
     * Works by computing the centroid, then finding the largest radius. This will not, in general,
     * produce the minimal bounding circle.
     */
    protected void init(GeoArray region) {
      Geo c = Intersection.center(region, new Geo()); // centroid
      Geo storage = new Geo();
      double r = 0.0;
      int length = region.getSize();
      for (int i = 0; i < length; i++) {
        double pr = c.distance(region.get(i, storage));
        if (pr > r) {
          r = pr;
        }
      }

      init(c, r);
    }
Ejemplo n.º 6
0
    /**
     * Works by computing the centroid, then finding the largest radius. This will not, in general,
     * produce the minimal bounding circle.
     */
    protected void init(Geo[] region) {
      Geo c = Intersection.center(region); // centroid

      double r = 0.0;
      int length = region.length;
      for (int i = 0; i < length; i++) {
        double pr = c.distance(region[i]);
        if (pr > r) {
          r = pr;
        }
      }

      init(c, r);
    }
Ejemplo n.º 7
0
  private boolean searchGeoDesc(LazyValidatorForm frm, String geoFlag) {
    boolean isValid = false;

    frm.set(GEO_DESC, "");
    try {
      String geoSerial = ((String) frm.get(GEO_SERIAL));
      if (!Utils.isEmpty(geoSerial)) {
        geoSerial = geoSerial.trim();
        if (Utils.isValidNotZeroNumber(geoSerial, 6)) {
          String geoDesc = Geo.getGeoDesc(Integer.parseInt(geoSerial), geoFlag);
          if (!Utils.isEmpty(geoDesc)) {
            frm.set(GEO_DESC, geoDesc);
            isValid = true;
          }
        }
      }
    } catch (Exception ex) {
    }

    return isValid;
  }
Ejemplo n.º 8
0
  public ActionForward execute(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest httpServletRequest,
      HttpServletResponse httpServletResponse) {
    LazyValidatorForm frm = (LazyValidatorForm) actionForm;
    resetFocusControl(frm, CANCEL);
    ActionMessages msgs = new ActionMessages();

    if (formCanceled(frm)) {
      return actionMapping.findForward(SUCCESS);
    }

    String geoFlag = (String) frm.get(GEO_FLAG);
    if (Utils.isEmpty(geoFlag)) {
      geoFlag = (String) httpServletRequest.getParameter(GEO_FLAG);
      frm.set(GEO_FLAG, geoFlag);
    }

    if (!formSaved(frm)) {
      setFormMode(frm, ((String) httpServletRequest.getParameter(BROWSE_ACTION)));
      setFormId(frm, (String) httpServletRequest.getParameter(BROWSE_ID));
      try {
        LoginInfo loginInfo = getLoginInfo(httpServletRequest);

        String geoFlagDesc = Misc.getHardCodeDesc(Constants.TableId.GEO_FLAG, geoFlag);
        frm.set(GEO_FLAG_DESC, geoFlagDesc);

        if (!loginInfo.userHasAccess("Geo_Conversion", getFormMode(frm))) {
          if (isFormInModifyMode(frm)
              && loginInfo.userHasAccess("Geo_Conversion", Constants.ActionType.ENQUERY)) {
            setFormMode(frm, Constants.ActionType.ENQUERY);
          } else {
            throw new Exception(INVALID_ACCESS);
          }
        }
        if (!geoFlag.equals(Constants.GeoFlag.VILLAGE)) {
          throw new Exception(INVALID_ACCESS);
        }
        if (!isFormInAddMode(frm)) {
          String formKey = (String) httpServletRequest.getParameter(BROWSE_KEY);
          GeoFormationInfo inf = Geo.getGeoFormationDetails(Integer.parseInt(formKey));
          frm.set(GEO_FORMATION_SERIAL, Integer.toString(inf.getGeoFormationSerial()));
          frm.set(GEO_SERIAL, Integer.toString(inf.getGeoSerial()));
          frm.set(APPROVAL_LETTER_NO, inf.getApprovalLetterNo());
          frm.set(APPROVAL_LETTER_DATE, DateUtils.revFormatDate(inf.getApprovalLetterDate()));
          frm.set(GEO_DESC, Geo.getGeoDesc(inf.getGeoSerial()));
        }
        frm.set(GEO_FLAG_DESC, geoFlagDesc);

        if (isFormInModifyMode(frm)) {
          resetFocusControl(frm, APPROVAL_LETTER_NO);
        }
      } catch (Exception ex) {
        addError(msgs, ex.getMessage());
        saveErrors(httpServletRequest, msgs);
      }
      return actionMapping.findForward(EDIT);
    } else {
      try {
        String geoFlagDesc = (String) frm.get(GEO_FLAG_DESC);
        if (!geoFlag.equals(Constants.GeoFlag.VILLAGE)) {
          addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "علامت محل جغرافيايي");
          setFocusControl(frm, GEO_SERIAL);
        }
        GeoFormationInfo inf = new GeoFormationInfo();
        resetFocusControl(frm, "");
        if (isFormInDeleteMode(frm) || isFormInModifyMode(frm)) {
          String geoFormationSerial = ((String) frm.get(GEO_FORMATION_SERIAL)).trim();
          if (Utils.isEmpty(geoFormationSerial)) {
            addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "سريال");
            setFocusControl(frm, GEO_SERIAL);
          } else if (!Utils.isValidNotZeroNumber(geoFormationSerial, 6)) {
            addError(msgs, FIELD_INVALID, "سريال");
            setFocusControl(frm, GEO_SERIAL);
          } else {
            inf.setGeoFormationSerial(Integer.parseInt(geoFormationSerial));
          }
        }

        if (isFormInAddMode(frm)) {
          String geoSerial = ((String) frm.get(GEO_SERIAL)).trim();
          if (Utils.isEmpty(geoSerial)) {
            addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "سريال " + geoFlagDesc);
            setFocusControl(frm, GEO_SERIAL);
          }
          /*  else if (searchGeoDesc(frm, geoFlag) == false) {
            addError(msgs, FIELD_INVALID, "سريال " + geoFlagDesc);
            setFocusControl(frm, GEO_SERIAL);
          }  */
          else {
            inf.setGeoSerial(Integer.parseInt(geoSerial));
          }
        }

        if (!isFormInDeleteMode(frm)) {
          String approvalLetterNo = Utils.trimConvert((String) frm.get(APPROVAL_LETTER_NO));
          frm.set(APPROVAL_LETTER_NO, approvalLetterNo);
          if (Utils.isEmpty(approvalLetterNo)) {
            addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "شماره تصويب نامه");
            setFocusControl(frm, APPROVAL_LETTER_NO);
          } else if (approvalLetterNo.length() > 20) {
            addError(msgs, FIELD_INVALID, "شماره تصويب نامه");
            setFocusControl(frm, APPROVAL_LETTER_NO);
          } else {
            inf.setApprovalLetterNo(approvalLetterNo);
          }

          String approvalLetterDate = ((String) frm.get(APPROVAL_LETTER_DATE)).trim();
          if (Utils.isEmpty(approvalLetterDate)) {
            addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "تاريخ تصويب نامه");
            setFocusControl(frm, APPROVAL_LETTER_DATE);
          } else if (!DateUtils.isValidRevFormattedFDate(approvalLetterDate)) {
            addError(msgs, FIELD_INVALID, "تاريخ تصويب نامه");
            setFocusControl(frm, APPROVAL_LETTER_DATE);
          } else if (DateUtils.unformatRevFormattedFdate(approvalLetterDate)
                  .compareTo(DateUtils.fDate())
              > 0) {
            addError(msgs, FIELD_SHOULD_BE_LESS_THAN, "تاريخ تصويب نامه", "تاريخ روز");
            setFocusControl(frm, APPROVAL_LETTER_DATE);
          } else {
            inf.setApprovalLetterDate(DateUtils.unformatRevFormattedFdate(approvalLetterDate));
          }
        }

        if (!msgs.isEmpty()) {
          saveErrors(httpServletRequest, msgs);
          return actionMapping.findForward(EDIT);
        }
        resetFocusControl(frm, CANCEL);
        Geo.saveConversion(getFormMode(frm), inf, geoFlag);
        httpServletRequest.setAttribute(BROWSE_KEY, inf.getKey());
        return actionMapping.findForward(SUCCESS);
      } catch (Exception ex) {
        resetFocusControl(frm, CANCEL);
        addError(msgs, ex.getMessage());
        saveErrors(httpServletRequest, msgs);
        return actionMapping.findForward(EDIT);
      }
    }
  }
Ejemplo n.º 9
0
  public ActionForward execute(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest httpServletRequest,
      HttpServletResponse httpServletResponse) {
    LazyValidatorForm frm = (LazyValidatorForm) actionForm;

    if (formCanceled(frm)) {
      return actionMapping.findForward(SUCCESS);
    }

    resetFocusControl(frm, CANCEL);
    ActionMessages msgs = new ActionMessages();
    if (!formSaved(frm)) {
      setFormMode(frm, ((String) httpServletRequest.getParameter(BROWSE_ACTION)));
      setFormId(frm, (String) httpServletRequest.getParameter(BROWSE_ID));
      try {
        LoginInfo loginInfo = getLoginInfo(httpServletRequest);
        if (!loginInfo.userHasAccess(getFormId(frm), getFormMode(frm))) {
          if (isFormInModifyMode(frm)
              && loginInfo.userHasAccess(getFormId(frm), Constants.ActionType.ENQUERY)) {
            setFormMode(frm, Constants.ActionType.ENQUERY);
          } else {
            throw new Exception(INVALID_ACCESS);
          }
        }

        if (!isFormInAddMode(frm)) {
          String formKey = (String) httpServletRequest.getParameter(BROWSE_KEY);
          VillageInfo inf = Geo.getVillageDetails(Integer.parseInt(formKey));
          frm.set(GEO_SERIAL, Integer.toString(inf.getGeoSerial()));
          frm.set(GEO_DESC, inf.getGeoDesc());
          frm.set(OSTAN_SERIAL, Integer.toString(inf.getOstanSerial()));
          frm.set(SHAHRESTAN_SERIAL, Integer.toString(inf.getShahrestanSerial()));
          frm.set(BAKHSH_SERIAL, Integer.toString(inf.getBakhshSerial()));
          frm.set(DEHESTAN_SERIAL, Integer.toString(inf.getDehestanSerial()));
          if (inf.isInactive()) {
            frm.set(CODE_ACTIVE_FLAG, "on");
          }
        } else {
          frm.set(GEO_SERIAL, Integer.toString(Geo.getNewGeoSerial(Constants.GeoFlag.VILLAGE)));
        }

        String serial;
        serial = (String) frm.get(OSTAN_SERIAL);
        if (Utils.isEmpty(serial)) {
          serial = "0";
          frm.set(OSTAN_SERIAL, serial);
        }
        frm.set(OSTAN_DESC, Geo.getOstanDesc(Integer.parseInt(serial)));

        serial = (String) frm.get(SHAHRESTAN_SERIAL);
        if (Utils.isEmpty(serial)) {
          serial = "0";
          frm.set(SHAHRESTAN_SERIAL, serial);
        }
        frm.set(SHAHRESTAN_DESC, Geo.getShahrestanDesc(Integer.parseInt(serial)));

        serial = (String) frm.get(BAKHSH_SERIAL);
        if (Utils.isEmpty(serial)) {
          serial = "0";
          frm.set(BAKHSH_SERIAL, serial);
        }
        frm.set(BAKHSH_DESC, Geo.getBakhshDesc(Integer.parseInt(serial)));

        serial = (String) frm.get(DEHESTAN_SERIAL);
        if (Utils.isEmpty(serial)) {
          serial = "0";
          frm.set(DEHESTAN_SERIAL, serial);
        }
        frm.set(DEHESTAN_DESC, Geo.getDehestanDesc(Integer.parseInt(serial)));

        if (isFormInAddMode(frm)) {
          resetFocusControl(frm, GEO_SERIAL);
        } else if (isFormInModifyMode(frm)) {
          resetFocusControl(frm, GEO_DESC);
        }
      } catch (Exception ex) {
        addError(msgs, ex.getMessage());
        saveErrors(httpServletRequest, msgs);
      }
      return actionMapping.findForward(EDIT);
    } else {
      VillageInfo inf = new VillageInfo();
      String geoSerial = ((String) frm.get(GEO_SERIAL)).trim();
      resetFocusControl(frm, "");
      if (Utils.isEmpty(geoSerial)) {
        addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "كد");
        setFocusControl(frm, GEO_SERIAL);
      } else if (!Utils.isValidNotZeroNumber(geoSerial, 6)) {
        addError(msgs, FIELD_INVALID, "كد");
        setFocusControl(frm, GEO_SERIAL);
      } else {
        inf.setGeoSerial(Integer.parseInt(geoSerial));
      }

      if (!isFormInDeleteMode(frm)) {
        String geoDesc = Utils.charVal((String) frm.get(GEO_DESC));
        frm.set(GEO_DESC, geoDesc);
        if (Utils.isEmpty(geoDesc)) {
          addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "نام");
          setFocusControl(frm, GEO_DESC);
        } else if (geoDesc.length() > 50) {
          addError(msgs, FIELD_INVALID, "نام");
          setFocusControl(frm, GEO_DESC);
        } else {
          inf.setGeoDesc(geoDesc);
        }

        String ostanSerial = (String) frm.get(OSTAN_SERIAL).toString();
        if (Utils.isEmpty(ostanSerial)) {
          addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "استان");
          setFocusControl(frm, GEO_DESC);
        } else if (!Utils.isValidNotZeroNumber(ostanSerial, 6)) {
          addError(msgs, FIELD_INVALID, "استان");
          setFocusControl(frm, GEO_DESC);
        } else {
          inf.setOstanSerial(Integer.parseInt(ostanSerial));
        }

        String shahrestanSerial = (String) frm.get(SHAHRESTAN_SERIAL).toString();
        if (Utils.isEmpty(shahrestanSerial)) {
          addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "شهرستان");
          setFocusControl(frm, GEO_DESC);
        } else if (!Utils.isValidNotZeroNumber(shahrestanSerial, 6)) {
          addError(msgs, FIELD_INVALID, "شهرستان");
          setFocusControl(frm, GEO_DESC);
        } else {
          inf.setShahrestanSerial(Integer.parseInt(shahrestanSerial));
        }

        String bakhshSerial = (String) frm.get(BAKHSH_SERIAL).toString();
        if (Utils.isEmpty(bakhshSerial)) {
          addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "بخش");
          setFocusControl(frm, GEO_DESC);
        } else if (!Utils.isValidNotZeroNumber(bakhshSerial, 6)) {
          addError(msgs, FIELD_INVALID, "بخش");
          setFocusControl(frm, GEO_DESC);
        } else {
          inf.setBakhshSerial(Integer.parseInt(bakhshSerial));
        }

        String dehestanSerial = (String) frm.get(DEHESTAN_SERIAL).toString();
        if (Utils.isEmpty(dehestanSerial)) {
          addError(msgs, FIELD_CAN_NOT_BE_EMPTY, "دهستان");
          setFocusControl(frm, GEO_DESC);
        } else if (!Utils.isValidNotZeroNumber(dehestanSerial, 6)) {
          addError(msgs, FIELD_INVALID, "دهستان");
          setFocusControl(frm, GEO_DESC);
        } else {
          inf.setDehestanSerial(Integer.parseInt(dehestanSerial));
        }

        if (Utils.isEmpty(frm.get(CODE_ACTIVE_FLAG))) {
          inf.setCodeActiveFlag(Constants.CodeActiveFlag.ACTIVE);
        } else {
          inf.setCodeActiveFlag(Constants.CodeActiveFlag.INACTIVE);
        }
      }

      if (!msgs.isEmpty()) {
        saveErrors(httpServletRequest, msgs);
        return actionMapping.findForward(EDIT);
      }
      resetFocusControl(frm, CANCEL);
      try {
        Geo.saveVillage(getFormMode(frm), inf);
        httpServletRequest.setAttribute(BROWSE_KEY, inf.getKey());
        return actionMapping.findForward(SUCCESS);
      } catch (Exception ex) {
        resetFocusControl(frm, CANCEL);
        addError(msgs, ex.getMessage());
        saveErrors(httpServletRequest, msgs);
        return actionMapping.findForward(EDIT);
      }
    }
  }