Example #1
0
  /**
   * Returns filterURL property.
   *
   * @param pFilter parameter to set.
   * @return filterURL property.
   * @throws UnsupportedEncodingException - exception
   */
  public static String getFilterURL(RepositoryItem pFilter) throws UnsupportedEncodingException {
    String name = (String) pFilter.getPropertyValue("tagTitle");
    name = SEOUtils.prepareNameForURL(name);

    StringBuffer url = new StringBuffer();
    url.append("/conseils-et-forums/")
        .append(name)
        .append('+')
        .append(pFilter.getRepositoryId())
        .append(EXTENSION_HTML);

    return url.toString();
  }
Example #2
0
  /**
   * Returns topicURL property.
   *
   * @param pTopic parameter to set.
   * @return topicURL property.
   * @throws UnsupportedEncodingException - exception
   */
  public static String getTopicURL(RepositoryItem pTopic) throws UnsupportedEncodingException {
    String name = (String) pTopic.getPropertyValue(PROPERTY_TITLE);
    name = SEOUtils.prepareNameForURL(name);

    StringBuffer url = new StringBuffer();
    url.append("/lancez-vous/")
        .append(name)
        .append('-')
        .append(pTopic.getRepositoryId())
        .append(EXTENSION_HTML);

    return url.toString();
  }
Example #3
0
  /**
   * Returns productURL property.
   *
   * @param pProduct parameter to set.
   * @return productURL property.
   * @throws UnsupportedEncodingException - exception
   */
  public static String getProductURL(RepositoryItem pProduct) throws UnsupportedEncodingException {
    String name = (String) pProduct.getPropertyValue(PROPERTY_DISPLAY_NAME);
    name = SEOUtils.prepareNameForURL(name);

    StringBuffer url = new StringBuffer();
    url.append('/')
        .append(name)
        .append('-')
        .append(pProduct.getRepositoryId())
        .append(EXTENSION_HTML);

    return url.toString();
  }
Example #4
0
  /**
   * Returns documentURL property.
   *
   * @param pDocument parameter to set.
   * @return documentURL property.
   * @throws UnsupportedEncodingException - exception
   */
  public static String getDocumentURL(RepositoryItem pDocument)
      throws UnsupportedEncodingException {
    String externalURL = getNotEmptyDocExtURL(pDocument);
    if (externalURL != null) {
      return externalURL;
    }
    String name = (String) pDocument.getPropertyValue(PROPERTY_TITLE);
    name = SEOUtils.prepareNameForURL(name);

    StringBuffer url = new StringBuffer();
    url.append("/doc/")
        .append(name)
        .append('-')
        .append(pDocument.getRepositoryId())
        .append(EXTENSION_DOC);

    return url.toString();
  }
  /**
   * ToDo: DOCUMENT ME!
   *
   * @param pContext ToDo: DOCUMENT ME!
   * @throws ProcessException ToDo: DOCUMENT ME!
   */
  protected void doExecuteAction(ProcessExecutionContext pContext) throws ProcessException {
    if (mLogger.isLoggingDebug()) {
      mLogger.logDebug("Entering doExecuteAction");
      mLogger.logDebug("Message is " + pContext.getMessage());
    }

    InviteMessage inviteMessage = ((com.castorama.scenario.InviteMessage) pContext.getMessage());
    String email = inviteMessage.getReferee();

    if (StringUtils.isBlank(email)) {
      if (mLogger.isLoggingWarning()) {
        mLogger.logWarning("Empty email. Exiting.");
      }
      return;
    }

    if (mProfileTools.getItemFromEmail(email) != null) {
      if (mLogger.isLoggingWarning()) {
        mLogger.logWarning("User with email " + email + " already registered. Exiting.");
      }
      return;
    }

    RepositoryItem referrer = null;

    try {
      referrer = mProfileRepository.getItem(inviteMessage.getProfileId(), "user");
    } catch (RepositoryException e1) {
      throw new ProcessException("Can not find referrer with id=" + inviteMessage.getProfileId());
    }

    Set referees = (Set) referrer.getPropertyValue(PROPERTY_REFEREE);

    if (referees != null) {
      for (Iterator iterator = referees.iterator(); iterator.hasNext(); ) {
        RepositoryItem referee = (RepositoryItem) iterator.next();

        // check if the user is already invited
        if (((String) referee.getPropertyValue(PROPERTY_EMAIL)).equalsIgnoreCase(email)) {
          if (mLogger.isLoggingWarning()) {
            mLogger.logWarning(email + " is already invited by referrer. Exiting.");
          }
          return;
        }
      }
    }

    RepositoryItem refereePromo = mReferrerProgramConfig.getRefereePromotion();

    if (refereePromo == null) {
      throw new ProcessException("Referee promo is not set");
    }

    RepositoryItem referrerPromo = mReferrerProgramConfig.getReferrerPromotion();

    if (referrerPromo == null) {
      throw new ProcessException("Referrer promo is not set");
    }

    if (mLogger.isLoggingDebug()) {
      mLogger.logDebug("refereePromo is " + refereePromo);
      mLogger.logDebug("referrerPromo is " + referrerPromo);
    }

    String couponId = null;

    // find first available coupon
    try {
      Connection connection = null;
      ResultSet resultSet = null;
      PreparedStatement ps = null;

      try {
        connection = ((GSARepository) mProfileRepository).getDataSource().getConnection();

        ps = connection.prepareStatement(GET_COUPON_ID_FOR_REFEREE_SQL);
        ps.setString(1, refereePromo.getRepositoryId());
        resultSet = ps.executeQuery();

        if (resultSet.next()) {
          couponId = resultSet.getString("COUPON_ID");
        }
      } catch (Exception e) {
        throw new ProcessException("Can not retrieve coupon", e);
      } finally {
        if (resultSet != null) {
          try {
            resultSet.close();
          } catch (Exception e) {
          }
        }
        if (ps != null) {
          try {
            ps.close();
          } catch (Exception e) {
          }
        }
        if (connection != null) {
          try {
            connection.close();
          } catch (Exception e) {
          }
        }
      } // end try-catch-finally

      if (couponId == null) {
        throw new ProcessException("No coupons available");
      }

      if (mLogger.isLoggingDebug()) {
        mLogger.logDebug("Coupon found");
      }

      // creates referrer item
      MutableRepositoryItem referee =
          ((MutableRepository) mProfileRepository).createItem(ITEM_REFEREE);
      referee.setPropertyValue(PROPERTY_EMAIL, email);
      referee.setPropertyValue(PROPERTY_COUPONID, couponId);
      ((MutableRepository) mProfileRepository).addItem(referee);
      referees.add(referee);
      ((MutableRepository) mProfileRepository).updateItem((MutableRepositoryItem) referrer);

      if (mLogger.isLoggingDebug()) {
        mLogger.logDebug("Coupon assigned");
      }
    } catch (RepositoryException e) {
      throw new ProcessException("Can not send email", e);
    } // end try-catch

    String lastName = (String) referrer.getPropertyValue(LAST_NAME_PROFILE_PROP);
    String firstName = (String) referrer.getPropertyValue(FIRST_NAME_PROFILE_PROP);
    String referrerName = lastName + " " + firstName;

    try {
      Map<String, String> params = new HashMap<String, String>();
      params.put(EMAIL_PARAM_COUPON, couponId);
      params.put(EMAIL_PARAM_REFERRER, referrerName);

      Double adjuster = (Double) refereePromo.getPropertyValue(PROPERTY_ADJUSTER);
      params.put(EMAIL_PARAM_PROMO_AMOUNT, NUMBER_FORMAT.format(adjuster));
      String subject = String.format(Locale.FRANCE, mEmailSubject, referrerName);

      // send invitation to referee
      sendEmail(
          pContext,
          subject,
          mFromEmail,
          email,
          (String) getParameterValue(PARAM_TEMPLATE, pContext),
          params);

      params = new HashMap<String, String>();
      params.put(EMAIL_PARAM_REFERRER, referrerName);

      Date expDate = (Date) refereePromo.getPropertyValue(PROPERTY_END_USABLE);

      if (expDate != null) {
        params.put(EMAIL_PARAM_EXP_DATE, DATE_FORMAT.format(expDate));
      }

      adjuster = (Double) referrerPromo.getPropertyValue(PROPERTY_ADJUSTER);
      params.put(EMAIL_PARAM_PROMO_AMOUNT, NUMBER_FORMAT.format(adjuster));

      // send confirmation to referrer
      sendEmail(
          pContext,
          subject,
          mFromEmail,
          (String) referrer.getPropertyValue(PROPERTY_EMAIL),
          (String) getParameterValue(PARAM_REFERRER_TEMPLATE, pContext),
          params);
    } catch (ActionException e) {
      throw new ProcessException("Can not send email", e);
    } // end try-catch
  }
Example #6
0
 public static List<Object> createValuesList(
     Abonnement abonnement, String source, Repository profileRepository)
     throws RepositoryException {
   String profileId = abonnement.getProfile();
   Profile profile = Profile.getInstance(profileRepository, profileId, DESCRIPTOR_NAME_PROFILE);
   RepositoryItem contactItem = null;
   if (profile != null) {
     contactItem = (RepositoryItem) profile.getPropertyValue("billingAddress");
   }
   RepositoryItem newsletterItem = abonnement.getRepositoryItem();
   Iterator<String> it = experianRequestItemProperties.keySet().iterator();
   List<Object> propertyValuesList = new ArrayList<Object>(33);
   while (it.hasNext()) {
     boolean isSettedVar = false;
     String key = it.next();
     int type = experianRequestItemProperties.get(key);
     try {
       /*
        * 1 - profile 2 - contactInfo 3 - newsletter
        */
       switch (type) {
         case 1:
           {
             if (profile != null) {
               propertyValuesList.add(profile.getPropertyValue(key));
               isSettedVar = true;
             } else {
               if (abonnement.getEmail() != null && key.equalsIgnoreCase(EMAIL_LOGIN)) {
                 propertyValuesList.add(abonnement.getEmail());
                 isSettedVar = true;
               }
             }
             break;
           }
         case 2:
           {
             if (contactItem != null) {
               propertyValuesList.add(contactItem.getPropertyValue(key));
               isSettedVar = true;
             }
             break;
           }
         case 3:
           {
             propertyValuesList.add(newsletterItem.getPropertyValue(key));
             isSettedVar = true;
             break;
           }
         case 4:
           {
             propertyValuesList.add(newsletterItem.getPropertyValue("id_magasin_ref") != null);
             isSettedVar = true;
             break;
           }
         case 5:
           {
             Object referenceObj = newsletterItem.getPropertyValue("id_magasin_ref");
             if (referenceObj == null) {
               break;
             }
             RepositoryItem reference = null;
             String temp = null;
             if (referenceObj instanceof RepositoryItem) {
               reference = (RepositoryItem) referenceObj;
               temp = reference.getRepositoryId();
             }
             propertyValuesList.add(temp != null ? temp : new Object());
             isSettedVar = true;
             break;
           }
         case 6:
           {
             propertyValuesList.add(source);
             isSettedVar = true;
             break;
           }
       }
       if (!isSettedVar) {
         propertyValuesList.add(null);
       }
     } catch (Throwable e) {
       // TODO delete before install to production
       // propertyValuesList.add(new Object());
       if (LOGGER.isErrorEnabled()) {
         LOGGER.error(e);
       }
     }
   }
   return propertyValuesList;
 }
  /**
   * Méthode appelée par le webservice.
   *
   * @param a_requestXML la requête sous format XML envoyé par les clients
   * @param retourne un XML contenant la réponse
   */
  public String rechercheClients(String a_requestXML) {
    if (isLoggingDebug()) {
      logDebug(a_requestXML);
    }

    String l_resultXML = null;

    List<String> users = new ArrayList<String>();

    setTotalPagesCount(0);

    try {
      RechercheClientsRequest l_request =
          RechercheClientsRequest.unmarshal(new StringReader(a_requestXML));
      String l_id = l_request.getId();
      String l_email = l_request.getEmail();
      String l_prenom = l_request.getPrenom();
      String l_nom = l_request.getNom();
      String l_codePostal = l_request.getCodePostal();
      int l_pageSize = l_request.getPageSize();
      if (l_pageSize == 0) l_pageSize = getDefaultPageSize();
      int l_pageNumber = l_request.getPageNumber();
      if (l_pageNumber == 0) l_pageNumber = 1;
      int l_start = l_pageSize * (l_pageNumber - 1);
      int l_end = l_start + l_pageSize;

      if (!StringUtils.isBlank(l_id)) {

        if (isLoggingDebug()) {
          logDebug("Search by ID " + l_id + " ...");
        }

        // ------------------------------------------------------------
        // REG_CC_5_1
        // ------------------------------------------------------------

        if (!getWebServicesTools().isNumericOnly(l_id)) {
          l_resultXML = getXML(CODE_RETOUR_NUMERO_CLIENT_INCORRECT, null);
        } else {
          RepositoryItem item = getProfileRepository().getItem(l_id, "user");
          if (item != null) {
            users.add(item.getRepositoryId());
          }
        }

      } else if (!StringUtils.isBlank(l_email)) {

        if (isLoggingDebug()) {
          logDebug("Search by email " + l_email + " ...");
        }

        // ------------------------------------------------------------
        // REG_CC_5_2
        // ------------------------------------------------------------

        if (!getWebServicesTools().isEmail(l_email)) {
          l_resultXML = getXML(CODE_RETOUR_EMAIL_INCORRECT, null);
        } else {
          RepositoryItemDescriptor rid = getProfileRepository().getItemDescriptor("user");
          RepositoryView view = rid.getRepositoryView();
          RqlStatement req = RqlStatement.parseRqlStatement("login = ?0");
          RepositoryItem clients[] = req.executeQuery(view, new Object[] {l_email});

          if (clients != null && clients.length > l_start) {
            setTotalPagesCount((int) Math.ceil((double) clients.length / l_pageSize));
            l_end = Math.min(l_end, clients.length);
            for (int i = l_start; i < l_end; i++) {
              users.add(clients[i].getRepositoryId());
            }
          }
        }

      } else if (!StringUtils.isBlank(l_prenom) && !StringUtils.isBlank(l_nom)) {

        if (isLoggingDebug()) {
          logDebug("Search by firstName " + l_prenom + " and lastName " + l_nom + " ...");
        }

        // AP l_prenom = getWebServicesTools().removeAccentsAndCapitals(l_prenom);
        // AP l_nom = getWebServicesTools().removeAccentsAndCapitals(l_nom);

        // ------------------------------------------------------------
        // REG_CC_5_8
        // ------------------------------------------------------------

        // ------------------------------------------------------------
        // On récupére les profils correspondant au nom/prénom sans tenir
        // compte de la casse ni des accents
        // ------------------------------------------------------------

        StringBuilder query = new StringBuilder();
        query.append("lastName EQUALS IGNORECASE ?0 AND firstName EQUALS IGNORECASE ?1");
        if (!StringUtils.isBlank(l_codePostal)) {
          if (isLoggingDebug()) {
            logDebug("Search by postalCode " + l_codePostal + " ...");
          }

          query.append(" AND billingAddress.postalCode = ?2");
        }

        // ------------------------------------------------------------
        // REG_CC_5_7
        // ------------------------------------------------------------
        query.append(
            " ORDER BY firstName CASE IGNORECASE, lastName CASE IGNORECASE, billingAddress.postalCode, billingAddress.city CASE IGNORECASE");
        if (isLoggingDebug()) {
          logDebug("RQL:" + query);
        }

        // ------------------------------------------------------------
        // REG_CC_5_5
        // ------------------------------------------------------------
        RepositoryView view = getProfileRepository().getItemDescriptor("user").getRepositoryView();
        RqlStatement req = RqlStatement.parseRqlStatement(query.toString());
        RepositoryItem clients[] =
            req.executeQueryUncached(view, new Object[] {l_nom, l_prenom, l_codePostal});

        if (clients != null && clients.length > l_start) {
          setTotalPagesCount((int) Math.ceil((double) clients.length / l_pageSize));
          l_end = Math.min(l_end, clients.length);
          for (int i = l_start; i < l_end; i++) {
            users.add(clients[i].getRepositoryId());
          }
        }

        /*ap
        String[] ids = getWebServicesTools().getUserIdsMatchingFirstNameAndLastName(l_prenom, l_nom);

        if (ids != null && ids.length > 0)
        {
        	if (isLoggingDebug()) {
        		logDebug("Users matching firstName and lastName:" + Arrays.asList(ids));
        	}

        	// on construit la requête en commençant par rajouter ces IDs (qui matche firstName et lastName)
        	StringBuffer l_requete = new StringBuffer("ID IN { ");
        	for (int i = 0; i < ids.length; i++)
        	{
        		l_requete.append((i > 0 ? "," : "") + "\"" + ids[i] + "\"");
        	}
        	l_requete.append(" }");

        	// ------------------------------------------------------------
        	// REG_CC_5_4
        	// ------------------------------------------------------------
        	if (!StringUtils.isBlank(l_codePostal)) {
        		if (isLoggingDebug()) {
        			logDebug("Search by postalCode " + l_codePostal + " ...");
        		}

        		l_requete.append(" AND billingAddress.postalCode = ?0");
        	}

        	// ------------------------------------------------------------
        	// REG_CC_5_7
        	// ------------------------------------------------------------
        	l_requete.append(" ORDER BY firstName CASE IGNORECASE, lastName CASE IGNORECASE, billingAddress.postalCode, billingAddress.city CASE IGNORECASE");
        	if (isLoggingDebug()) {
        		logDebug("RQL:" +  l_requete);
        	}

        	// ------------------------------------------------------------
        	// REG_CC_5_5
        	// ------------------------------------------------------------
        	RepositoryView view = getProfileRepository().getItemDescriptor("user").getRepositoryView();
        	RqlStatement req = RqlStatement.parseRqlStatement(l_requete.toString());
        	RepositoryItem clients[] = req.executeQueryUncached(view, new Object[] { l_codePostal });

        	if (clients != null && clients.length > 0) {
        		for (int i = 0; i < clients.length; i++) {
        			users.add(clients[i].getPropertyValue("id"));
        		}
        	}

        }
        else
        {
        	if (isLoggingDebug()) {
        		logDebug("No users matching firstName and lastName");
        	}
        }

        */

      } else if (!StringUtils.isBlank(l_nom)) {
        if (isLoggingDebug()) {
          logDebug("Search by lastName " + l_nom + " ...");
        }

        StringBuilder query = new StringBuilder();
        query.append("lastName EQUALS IGNORECASE ?0");
        if (!StringUtils.isBlank(l_codePostal)) {
          if (isLoggingDebug()) {
            logDebug("Search by postalCode " + l_codePostal + " ...");
          }

          query.append(" AND billingAddress.postalCode = ?1");
        }

        query.append(
            " ORDER BY firstName CASE IGNORECASE, lastName CASE IGNORECASE, billingAddress.postalCode, billingAddress.city CASE IGNORECASE");
        if (isLoggingDebug()) {
          logDebug("RQL:" + query);
        }

        RepositoryView view = getProfileRepository().getItemDescriptor("user").getRepositoryView();
        RqlStatement req = RqlStatement.parseRqlStatement(query.toString());
        RepositoryItem clients[] =
            req.executeQueryUncached(view, new Object[] {l_nom, l_codePostal});

        if (clients != null && clients.length > l_start) {
          setTotalPagesCount((int) Math.ceil((double) clients.length / l_pageSize));
          l_end = Math.min(l_end, clients.length);
          for (int i = l_start; i < l_end; i++) {
            users.add(clients[i].getRepositoryId());
          }
        }

      } else if (!StringUtils.isBlank(l_prenom) && !StringUtils.isBlank(l_codePostal)) {
        if (isLoggingDebug()) {
          logDebug("Search by firstName " + l_prenom + " and postalCode " + l_codePostal + " ...");
        }

        StringBuilder query = new StringBuilder();
        query.append("firstName EQUALS IGNORECASE ?0 AND billingAddress.postalCode = ?1");

        query.append(
            " ORDER BY firstName CASE IGNORECASE, lastName CASE IGNORECASE, billingAddress.postalCode, billingAddress.city CASE IGNORECASE");
        if (isLoggingDebug()) {
          logDebug("RQL:" + query);
        }

        RepositoryView view = getProfileRepository().getItemDescriptor("user").getRepositoryView();
        RqlStatement req = RqlStatement.parseRqlStatement(query.toString());
        RepositoryItem clients[] =
            req.executeQueryUncached(view, new Object[] {l_prenom, l_codePostal});

        if (clients != null && clients.length > l_start) {
          setTotalPagesCount((int) Math.ceil((double) clients.length / l_pageSize));
          l_end = Math.min(l_end, clients.length);
          for (int i = l_start; i < l_end; i++) {
            users.add(clients[i].getRepositoryId());
          }
        }

      } else if (!StringUtils.isBlank(l_codePostal)) {
        if (isLoggingDebug()) {
          logDebug("Search by postalCode " + l_codePostal + " ...");
        }

        StringBuilder query = new StringBuilder();
        query.append("billingAddress.postalCode = ?0");

        query.append(
            " ORDER BY firstName CASE IGNORECASE, lastName CASE IGNORECASE, billingAddress.postalCode, billingAddress.city CASE IGNORECASE");
        if (isLoggingDebug()) {
          logDebug("RQL:" + query);
        }

        RepositoryView view = getProfileRepository().getItemDescriptor("user").getRepositoryView();
        RqlStatement req = RqlStatement.parseRqlStatement(query.toString());
        RepositoryItem clients[] = req.executeQueryUncached(view, new Object[] {l_codePostal});

        if (clients != null && clients.length > l_start) {
          setTotalPagesCount((int) Math.ceil((double) clients.length / l_pageSize));
          l_end = Math.min(l_end, clients.length);
          for (int i = l_start; i < l_end; i++) {
            users.add(clients[i].getRepositoryId());
          }
        }

      } else {

        // ------------------------------------------------------------
        // REG_CC_5_3
        // ------------------------------------------------------------

        l_resultXML = getXML(CODE_RETOUR_NOM_ET_PRENOM_VIDE, null);
      }

      // ------------------------------------------------------------
      // REG_CC_5_9
      // ------------------------------------------------------------

      // si aucune erreur, alors tout s'est bien passé (!). On set le code d'erreur (clients trouvés
      // ou non)
      if (l_resultXML == null) {
        /*for (Iterator l_it = users.iterator(); l_it.hasNext();)
        {
        	// on vérifie que les ids existent
        	String l_idToCheck = (String) l_it.next();
        	if (getProfileRepository().getItem(l_idToCheck, "user") == null)
        	{
        		if (isLoggingDebug()) {
        			logDebug("ID " + l_idToCheck + " doesn't exist, removing ...");
        		}
        		l_it.remove();
        	}
        }
        */

        if (isLoggingDebug()) {
          logDebug("Users list:" + users);
        }

        if (users.size() > 0) {
          l_resultXML = getXML(CODE_RETOUR_OK, users);
        } else {
          l_resultXML = getXML(CODE_RETOUR_AUCUN_RESULTAT, null);
        }
      }

    } catch (MarshalException l_me) {
      if (isLoggingError()) {
        logError(l_me);
      }
    } catch (ValidationException l_ve) {
      if (isLoggingError()) {
        logError(l_ve);
      }
    } catch (RepositoryException l_re) {
      if (isLoggingError()) {
        logError(l_re);
      }
    } catch (Exception l_e) {
      if (isLoggingError()) {
        logError(l_e);
      }
    }

    if (l_resultXML == null) {
      if (isLoggingDebug()) {
        logDebug("Internal error. See ATG logs for more information.");
      }
      l_resultXML = getXML(CODE_RETOUR_INCONNU, users);
    }

    if (isLoggingDebug()) {
      logDebug(l_resultXML);
    }
    return l_resultXML;
  }