Exemple #1
0
  public ActionForward rate(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Throwable {

    String itemNaturalKey = (String) request.getParameter("itemNaturalKey");
    String value = (String) request.getParameter("rate");
    ContentSessionBean contentSessionBean = getContentBean(request).getContentSessionBean();
    Site site = contentSessionBean.getSiteDomain().getSite();
    String siteId = site.getSiteId();
    if (value != null) {
      EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
      Item item = ItemDAO.loadNatural(siteId, itemNaturalKey);
      int itemRatingCount = item.getItemRatingCount().intValue();
      float itemRating = item.getItemRating().floatValue();

      int rate = Integer.parseInt(value);
      if (itemRatingCount != 0) {
        itemRating = ((itemRating * itemRatingCount) + rate) / (itemRatingCount + 1);
        itemRatingCount += 1;
      } else {
        itemRatingCount = 1;
        itemRating = rate;
      }
      item.setItemRating(new Float(itemRating));
      item.setItemRatingCount(new Integer(itemRatingCount));
      em.persist(item);
    }
    ActionForward forward = actionMapping.findForward("success");
    forward =
        new ActionForward(
            forward.getPath()
                + contentSessionBean.getSiteDomain().getSiteDomainPrefix()
                + "/"
                + contentSessionBean
                    .getSiteProfile()
                    .getSiteProfileClass()
                    .getSiteProfileClassName()
                + "/item/"
                + itemNaturalKey,
            forward.getRedirect());
    return forward;
  }
  public void extract(AdminListingActionForm actionForm, HttpServletRequest request)
      throws Throwable {

    EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
    SiteCurrencyClassListingActionForm form = (SiteCurrencyClassListingActionForm) actionForm;
    Site site = getAdminBean(request).getSite();

    Query query = null;
    String sql =
        "select	siteCurrencyClass "
            + "from 		SiteCurrencyClass siteCurrencyClass "
            + "where 	siteCurrencyClass.site.siteId = :siteId ";
    if (!Format.isNullOrEmpty(form.getSrSiteCurrencyClassName())) {
      sql += "and siteCurrencyClassName like :siteCurrencyClassName ";
    }
    query = em.createQuery(sql);
    query.setParameter("siteId", site.getSiteId());
    if (!Format.isNullOrEmpty(form.getSrSiteCurrencyClassName())) {
      query.setParameter("siteCurrencyClassName", form.getSrSiteCurrencyClassName());
    }
    Iterator<?> iterator = query.getResultList().iterator();
    Vector<SiteCurrencyClassDisplayForm> vector = new Vector<SiteCurrencyClassDisplayForm>();
    while (iterator.hasNext()) {
      SiteCurrencyClass siteCurrencyClass = (SiteCurrencyClass) iterator.next();
      SiteCurrencyClassDisplayForm siteCurrencyClassDisplay = new SiteCurrencyClassDisplayForm();
      siteCurrencyClassDisplay.setSiteCurrencyClassId(
          siteCurrencyClass.getSiteCurrencyClassId().toString());
      siteCurrencyClassDisplay.setSiteCurrencyClassName(
          siteCurrencyClass.getSiteCurrencyClassName());
      String localeName =
          getLocaleName(
              siteCurrencyClass.getCurrencyLocaleLanguage(),
              siteCurrencyClass.getCurrencyLocaleCountry());
      siteCurrencyClassDisplay.setLocaleName(localeName);
      siteCurrencyClassDisplay.setSystemRecord(String.valueOf(siteCurrencyClass.getSystemRecord()));
      vector.add(siteCurrencyClassDisplay);
    }
    SiteCurrencyClassDisplayForm siteCurrencyClasses[] =
        new SiteCurrencyClassDisplayForm[vector.size()];
    vector.copyInto(siteCurrencyClasses);
    form.setSiteCurrencyClasses(siteCurrencyClasses);
  }
  public ActionForward performAction(
      ActionMapping actionMapping,
      ActionForm actionForm,
      HttpServletRequest request,
      HttpServletResponse response)
      throws Exception {

    EntityManager em = JpaConnection.getInstance().getCurrentEntityManager();
    Site site = getAdminBean(request).getSite();

    JSONEscapeObject jsonResult = new JSONEscapeObject();
    Vector<JSONEscapeObject> countries = new Vector<JSONEscapeObject>();
    Query query =
        em.createQuery("from Country country where siteId = :siteId order by countryName");
    query.setParameter("siteId", site.getSiteId());
    Iterator<?> iterator = query.getResultList().iterator();
    while (iterator.hasNext()) {
      Country country = (Country) iterator.next();
      JSONEscapeObject jsonCountry = new JSONEscapeObject();
      jsonCountry.put("countryId", country.getCountryId());
      jsonCountry.put("countryCode", country.getCountryCode());
      jsonCountry.put("countryName", country.getCountryName());
      Iterator<?> iterator1 = country.getStates().iterator();
      Vector<JSONEscapeObject> states = new Vector<JSONEscapeObject>();
      while (iterator1.hasNext()) {
        State state = (State) iterator1.next();
        JSONEscapeObject jsonState = new JSONEscapeObject();
        jsonState.put("stateId", state.getStateId());
        jsonState.put("stateCode", state.getStateCode());
        jsonState.put("stateName", state.getStateName());
        states.add(jsonState);
      }
      jsonCountry.put("states", states);
      countries.add(jsonCountry);
    }
    jsonResult.put("countries", countries);
    String jsonString = jsonResult.toHtmlString();
    streamWebService(response, jsonString);
    return null;
  }