/**
   * Generalised method to redirect the form page to different transactional form pages
   *
   * @return
   */
  @ValidationErrorPage(value = COMMON_FORM)
  @Action(value = "/search/searchProperty-commonSearch")
  public String commonSearch() {
    final BasicProperty basicProperty =
        basicPropertyDAO.getBasicPropertyByIndexNumAndParcelID(assessmentNum, null);
    if (basicProperty == null) {
      addActionError(getText("validation.property.doesnot.exists"));
      return COMMON_FORM;
    }
    checkIsDemandActive(basicProperty.getProperty());
    if (APPLICATION_TYPE_REVISION_PETITION.equals(applicationType)) {
      if (isDemandActive) {
        addActionError(getText("revPetition.demandActive"));
        return COMMON_FORM;
      }
    } else if (APPLICATION_TYPE_ALTER_ASSESSENT.equals(applicationType)
        || APPLICATION_TYPE_BIFURCATE_ASSESSENT.equals(applicationType)
        || APPLICATION_TYPE_TRANSFER_OF_OWNERSHIP.equals(applicationType)) {
      if (!isDemandActive) {
        addActionError(getText("error.msg.demandInactive"));
        return COMMON_FORM;
      }
    } else if (APPLICATION_TYPE_DEMAND_BILL.equals(applicationType))
      if (basicProperty.getProperty().getIsExemptedFromTax()) {
        addActionError(getText("error.msg.taxExempted"));
        return COMMON_FORM;
      }

    return applicationType;
  }
  /** @return */
  @Action(value = "/collectPropertyTax-generateBill")
  public String generateBill() {
    if (LOGGER.isDebugEnabled())
      LOGGER.debug(
          "Entered method generatePropertyTaxBill, Generating bill for index no : " + propertyId);
    if (propertyId == null || propertyId.isEmpty()) {
      setErrorMsg(getText("mandatory.assessmentNo"));
      return RESULT_ERROR;
    }
    final BasicProperty basicProperty =
        basicPropertyService.findByNamedQuery(
            PropertyTaxConstants.QUERY_BASICPROPERTY_BY_UPICNO, propertyId);
    if (basicProperty == null) {
      setErrorMsg(getText("validation.property.doesnot.exists"));
      return RESULT_ERROR;
    }
    if (LOGGER.isDebugEnabled())
      LOGGER.debug("generatePropertyTaxBill : BasicProperty :" + basicProperty);

    if (basicProperty.getProperty().getIsExemptedFromTax()) {
      args.add(propertyId);
      setErrorMsg(getText("msg.collection.tax.exempted", args));
      return RESULT_ERROR;
    }

    final Map<String, BigDecimal> demandCollMap =
        propertyTaxUtil.getDemandAndCollection(basicProperty.getProperty());
    final BigDecimal currDue =
        demandCollMap.get(CURR_DMD_STR).subtract(demandCollMap.get(CURR_COLL_STR));
    final BigDecimal arrDue =
        demandCollMap.get(ARR_DMD_STR).subtract(demandCollMap.get(ARR_COLL_STR));

    if (currDue.compareTo(BigDecimal.ZERO) <= 0 && arrDue.compareTo(BigDecimal.ZERO) <= 0) {
      args.add(propertyId);
      isAssessmentNoValid = Boolean.TRUE;
      setErrorMsg(getText("msg.collection.fully.paid", args));
      return RESULT_ERROR;
    }
    propertyTaxBillable.setLevyPenalty(true);
    propertyTaxBillable.setBasicProperty(basicProperty);
    propertyTaxBillable.setUserId(Long.valueOf(getSession().get("userid").toString()));
    propertyTaxBillable.setReferenceNumber(
        propertyTaxNumberGenerator.generateBillNumber(
            basicProperty.getPropertyID().getWard().getBoundaryNum().toString()));
    propertyTaxBillable.setBillType(propertyTaxUtil.getBillTypeByCode(BILLTYPE_AUTO));

    final String billXml = ptBillServiceImpl.getBillXML(propertyTaxBillable);
    try {
      collectXML = URLEncoder.encode(billXml, "UTF-8");
    } catch (final UnsupportedEncodingException e) {
      throw new RuntimeException(e.getMessage());
    }
    if (LOGGER.isDebugEnabled())
      LOGGER.debug(
          "Exiting method generatePropertyTaxBill, collectXML (before decode): " + billXml);
    return RESULT_VIEW;
  }
 /**
  * @param pmv
  * @return
  */
 private List<Map<String, String>> getResultsFromMv(final PropertyMaterlizeView pmv) {
   if (LOGGER.isDebugEnabled()) {
     LOGGER.debug("Entered into getSearchResults method");
     LOGGER.debug("Assessment Number : " + pmv.getPropertyId());
   }
   BasicProperty basicProperty =
       basicPropertyDAO.getBasicPropertyByPropertyID(pmv.getPropertyId());
   Property property = basicProperty.getProperty();
   if (basicProperty != null) {
     checkIsDemandActive(basicProperty.getProperty());
   }
   if (pmv.getPropertyId() != null
       || org.apache.commons.lang.StringUtils.isNotEmpty(pmv.getPropertyId()))
     if (pmv != null) {
       final Map<String, String> searchResultMap = new HashMap<String, String>();
       searchResultMap.put("assessmentNum", pmv.getPropertyId());
       searchResultMap.put("ownerName", pmv.getOwnerName());
       searchResultMap.put("parcelId", pmv.getGisRefNo());
       searchResultMap.put("address", pmv.getPropertyAddress());
       searchResultMap.put("source", pmv.getSource().toString());
       searchResultMap.put("isDemandActive", String.valueOf(isDemandActive));
       searchResultMap.put(
           "propType", property.getPropertyDetail().getPropertyTypeMaster().getCode());
       searchResultMap.put("isTaxExempted", String.valueOf(property.getIsExemptedFromTax()));
       searchResultMap.put("isUnderWorkflow", String.valueOf(basicProperty.isUnderWorkflow()));
       searchResultMap.put(
           "enableVacancyRemission",
           String.valueOf(propertyTaxUtil.enableVacancyRemission(basicProperty.getUpicNo())));
       searchResultMap.put(
           "enableMonthlyUpdate",
           String.valueOf(propertyTaxUtil.enableMonthlyUpdate(basicProperty.getUpicNo())));
       searchResultMap.put(
           "enableVRApproval",
           String.valueOf(propertyTaxUtil.enableVRApproval(basicProperty.getUpicNo())));
       if (pmv.getIsExempted()) {
         searchResultMap.put("currDemand", "0");
         searchResultMap.put("arrDemandDue", "0");
         searchResultMap.put("currDemandDue", "0");
       } else {
         searchResultMap.put("currDemand", pmv.getAggrCurrDmd().toString());
         searchResultMap.put(
             "currDemandDue", pmv.getAggrCurrDmd().subtract(pmv.getAggrCurrColl()).toString());
         searchResultMap.put(
             "arrDemandDue", pmv.getAggrArrDmd().subtract(pmv.getAggrArrColl()).toString());
       }
       searchList.add(searchResultMap);
     }
   if (LOGGER.isDebugEnabled()) {
     LOGGER.debug("Search list : " + (searchList != null ? searchList : ZERO));
     LOGGER.debug("Exit from getSearchResults method");
   }
   return searchList;
 }
  /**
   * @param assessmentNumber
   * @return
   */
  private List<Map<String, String>> getSearchResults(final String assessmentNumber) {
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Entered into getSearchResults method");
      LOGGER.debug("Assessment Number : " + assessmentNumber);
    }
    if (assessmentNumber != null
        || org.apache.commons.lang.StringUtils.isNotEmpty(assessmentNumber)) {

      final BasicProperty basicProperty =
          basicPropertyDAO.getBasicPropertyByPropertyID(assessmentNumber);
      if (LOGGER.isDebugEnabled()) LOGGER.debug("BasicProperty : " + basicProperty);
      if (basicProperty != null) {
        final Property property = basicProperty.getProperty();
        if (LOGGER.isDebugEnabled()) LOGGER.debug("Property : " + property);

        checkIsDemandActive(property);

        final Map<String, BigDecimal> demandCollMap = ptDemandDAO.getDemandCollMap(property);

        final Map<String, String> searchResultMap = new HashMap<String, String>();
        searchResultMap.put("assessmentNum", assessmentNumber);
        searchResultMap.put("ownerName", basicProperty.getFullOwnerName());
        searchResultMap.put("address", basicProperty.getAddress().toString());
        searchResultMap.put("source", basicProperty.getSource().toString());
        searchResultMap.put("isDemandActive", String.valueOf(isDemandActive));
        searchResultMap.put(
            "propType", property.getPropertyDetail().getPropertyTypeMaster().getCode());
        searchResultMap.put("isTaxExempted", String.valueOf(property.getIsExemptedFromTax()));
        searchResultMap.put("isUnderWorkflow", String.valueOf(basicProperty.isUnderWorkflow()));
        searchResultMap.put(
            "enableVacancyRemission",
            String.valueOf(propertyTaxUtil.enableVacancyRemission(basicProperty.getUpicNo())));
        searchResultMap.put(
            "enableMonthlyUpdate",
            String.valueOf(propertyTaxUtil.enableMonthlyUpdate(basicProperty.getUpicNo())));
        searchResultMap.put(
            "enableVRApproval",
            String.valueOf(propertyTaxUtil.enableVRApproval(basicProperty.getUpicNo())));
        if (!property.getIsExemptedFromTax()) {
          searchResultMap.put("currDemand", demandCollMap.get(CURR_DMD_STR).toString());
          searchResultMap.put(
              "arrDemandDue",
              demandCollMap.get(ARR_DMD_STR).subtract(demandCollMap.get(ARR_COLL_STR)).toString());
          searchResultMap.put(
              "currDemandDue",
              demandCollMap
                  .get(CURR_DMD_STR)
                  .subtract(demandCollMap.get(CURR_COLL_STR))
                  .toString());
        } else {
          searchResultMap.put("currDemand", "0");
          searchResultMap.put("arrDemandDue", "0");
          searchResultMap.put("currDemandDue", "0");
        }
        if (LOGGER.isDebugEnabled())
          LOGGER.debug(
              "Assessment Number : "
                  + searchResultMap.get("assessmentNum")
                  + ", "
                  + "Owner Name : "
                  + searchResultMap.get("ownerName")
                  + ", "
                  + "Parcel id : "
                  + searchResultMap.get("parcelId")
                  + ", "
                  + "Address : "
                  + searchResultMap.get("address")
                  + ", "
                  + "Current Demand : "
                  + searchResultMap.get("currDemand")
                  + ", "
                  + "Arrears Demand Due : "
                  + searchResultMap.get("arrDemandDue")
                  + ", "
                  + "Current Demand Due : "
                  + searchResultMap.get("currDemandDue"));
        searchList.add(searchResultMap);
      }
    }
    if (LOGGER.isDebugEnabled()) {
      LOGGER.debug("Search list : " + (searchList != null ? searchList : ZERO));
      LOGGER.debug("Exit from getSearchResults method");
    }
    return searchList;
  }