Example #1
0
  /**
   * @param pServletRequest parameter
   * @param pServletResponse parameter
   * @throws IOException exception
   * @throws ServletException exception
   */
  @Override
  public void handleService(ServletRequest pServletRequest, ServletResponse pServletResponse)
      throws IOException, ServletException {
    final ByteArrayOutputStream pdf = new ByteArrayOutputStream();
    final String deliveryId = pServletRequest.getParameter(DELIVERY_ID_PARAM);
    RepositoryItem orderBOItem = mOrderManager.getFactureBO(deliveryId);
    OutputStream out = null;

    if (orderBOItem != null) {
      RepositoryItem orderFOItem = mOrderManager.getOrderFO(orderBOItem);
      String profileId =
          (String) orderFOItem.getPropertyValue(CastoConstantesOrders.ORDER_PROPERTY_PROFILEID);
      String currProfileId = getProfileServices().getCurrentProfileId();
      if (!currProfileId.equalsIgnoreCase(profileId)) {
        if (isLoggingError()) {
          logError(
              "Facture with id="
                  + deliveryId
                  + " doesn't belong to profile with id="
                  + currProfileId);
        }
        return;
      }

      Map params = new HashMap();
      params.put(
          "url",
          pServletRequest.getScheme()
              + "://"
              + pServletRequest.getServerName()
              + ":"
              + pServletRequest.getServerPort());

      try {
        PrintPdfHelper.getInstance().generateInvoicePdf(pdf, orderBOItem, params, mCountryList);

        // Set header
        pServletResponse.setContentType(CONTENT_TYPE_PDF);
        pServletResponse.setContentLength(pdf.size());

        out = pServletResponse.getOutputStream();
        pdf.writeTo(out);
        out.flush();
      } catch (IOException e) {
        logError(e);
      } finally {
        if (out != null) {
          out.close();
        }
      }
    } else {
      logError("Facture with id=" + deliveryId + " was not found.");
    } // end if-else
  }
Example #2
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 #3
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 #4
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 #5
0
  public static int printToDataFile(File file, RepositoryItem[] requestsList)
      throws RepositoryException, FileNotFoundException {
    if (file == null || requestsList == null || requestsList.length == 0) {
      // TODO don't forget replace REpository exception by
      // IllegalArgumentException and remove throws declaration
      throw new RepositoryException("Repository item must be a newsletter account type.");
    }

    int recordsExported = 0;
    PrintWriter printWriter = null;
    try {
      printWriter = new PrintWriter(file);
      printWriter.println(getColumnNamesLine());
      MutableRepository mutNewsletterRepository =
          (MutableRepository) requestsList[0].getRepository();

      for (int i = 0; i < requestsList.length; i++) {
        RepositoryItem request = requestsList[i];

        // write record to file
        printWriter.println(repositoryItemToCSVLine(request));

        // move record to history

        MutableRepositoryItem historyNewsletter =
            mutNewsletterRepository.createItem(HISTORY_NEWSLETTER_ITEM_DESCRIPTOR);

        for (String propertyName : ExperianUtils.PROPERTY_NAMES) {
          historyNewsletter.setPropertyValue(propertyName, request.getPropertyValue(propertyName));
        }
        historyNewsletter.setPropertyValue(EXPORT_DATE_PROPERTY, new Date());
        historyNewsletter.setPropertyValue(
            REQUEST_SOURCE_PROPERTY, request.getPropertyValue(REQUEST_SOURCE_PROPERTY));

        mutNewsletterRepository.addItem(historyNewsletter);

        mutNewsletterRepository.removeItem(
            requestsList[i].getRepositoryId(), EXPERIAN_REQUEST_ITEM_DESCRIPTOR_NAME);

        recordsExported++;
      }
    } finally {
      if (printWriter != null) {
        printWriter.close();
        printWriter = null;
      }
    }

    return recordsExported;
  }
Example #6
0
 public static String getNotEmptyDocExtURL(RepositoryItem pDocument) {
   String externalURL = (String) pDocument.getPropertyValue("externalURL");
   if (externalURL != null && externalURL.length() > 0) {
     return externalURL;
   }
   return null;
 }
Example #7
0
  public static String repositoryItemToCSVLine(RepositoryItem experianRequest)
      throws RepositoryException {
    getExperianRequestIremDescriptor(experianRequest);
    StringBuilder sb = new StringBuilder();

    for (int i = 0; i < PROPERTY_NAMES.length; i++) {
      String propertyName = PROPERTY_NAMES[i];
      Object propertyValue = experianRequest.getPropertyValue(propertyName);
      String printValue = "";
      if (propertyValue != null) {

        if (ENUM_PROPERTIES.contains(propertyName)) {
          printValue = VALUES_TO_CODES.get(propertyValue).toString();
        } else {
          if (ExperianUtils.BOOLEAN_PROPERTIES.contains(propertyName)) {
            printValue = BOOLEAN_TO_CODES.get(propertyValue.toString());
          } else {
            if (propertyValue instanceof Date) {
              Date dateValue = (Date) propertyValue;
              printValue = Constants.DATE_FORMAT_EXPERIAN.format(dateValue);
            } else {
              printValue = propertyValue.toString();
            }
          }
        }
      }

      if (i != 0) {
        sb.append(ExperianUtils.DATA_FILE_DELIMETER);
      }

      sb.append(printValue);
    }
    return sb.toString();
  }
Example #8
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();
  }
Example #9
0
 public static List<Object> getValuesList(RepositoryItem experianRequest)
     throws RepositoryException {
   RepositoryItemDescriptor itemDescriptor = getExperianRequestIremDescriptor(experianRequest);
   String[] propertyNames = itemDescriptor.getPropertyNames();
   List<Object> temp = new ArrayList<Object>();
   for (int i = 0; i < propertyNames.length; i++) {
     Object value = experianRequest.getPropertyValue(propertyNames[i]);
     temp.add(value);
   }
   return temp;
 }
Example #10
0
 private static RepositoryItemDescriptor getExperianRequestIremDescriptor(
     RepositoryItem experianRequest) throws RepositoryException {
   RepositoryItemDescriptor itemDescriptor = null;
   if (experianRequest == null
       || !(itemDescriptor = experianRequest.getItemDescriptor())
           .getItemDescriptorName()
           .equals(EXPERIAN_REQUEST_ITEM_DESCRIPTOR_NAME)) {
     // TODO don't forget replace REpository exception by
     // IllegalArgumentException and remove throws declaration
     throw new RepositoryException("Repository item must be a newsletter account type.");
   }
   return itemDescriptor;
 }
 protected void doValidateAccessPrivileges(AssetEditorInfo editorInfo, Collection pUpdates) {
   PropertyUpdate mappingPropUpdate =
       BaseAssetService.findPropertyUpdate(SynonymProperty.SYNONYM_LIST, pUpdates);
   boolean isQueryParserSynonym = false;
   if (mappingPropUpdate != null) {
     String fileName = "";
     String updatedProperty =
         StringUtils.defaultIfEmpty((String) mappingPropUpdate.getPropertyValue(), fileName);
     String tokens[] = StringUtils.split(updatedProperty, '/');
     try {
       RepositoryItem synonym =
           searchRepository.getItem(
               tokens[tokens.length - 1], SearchRepositoryItemDescriptor.SYNONYM_LIST);
       if (synonym != null
           && synonym
               .getPropertyValue(SynonymListProperty.FILENAME)
               .equals(QUERY_PARSER_SYNONYMS)) {
         isQueryParserSynonym = true;
       }
     } catch (Exception ex) {
       if (isLoggingError()) {
         logError("Cannot check privileges", ex);
       }
     }
   }
   mappingPropUpdate = BaseAssetService.findPropertyUpdate(SynonymProperty.MAPPING, pUpdates);
   if (mappingPropUpdate != null) {
     RepositoryItem currentItem = (RepositoryItem) editorInfo.getAssetWrapper().getAsset();
     RepositoryItem synonym =
         (RepositoryItem)
             currentItem.getPropertyValue(SearchRepositoryItemDescriptor.SYNONYM_LIST);
     if (synonym != null
         && synonym.getPropertyValue(SynonymListProperty.FILENAME).equals(QUERY_PARSER_SYNONYMS)) {
       isQueryParserSynonym = true;
     }
   }
   if (isQueryParserSynonym && isNotPriviledged()) {
     editorInfo
         .getAssetService()
         .addError(SynonymProperty.MAPPING, ERROR_INSUFFICIENT_PRIVILEDGES);
   }
 }
  /**
   * 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 #13
0
  /**
   * Extends service method of DynamoServlet to returns payment amounts by gift card and credit
   * card.
   *
   * @see atg.servlet.DynamoServlet#service(atg.servlet.DynamoHttpServletRequest,
   *     atg.servlet.DynamoHttpServletResponse)
   */
  @Override
  public void service(DynamoHttpServletRequest pRequest, DynamoHttpServletResponse pResponse)
      throws ServletException, IOException {

    boolean isEmpty = true;
    String paymentMethod = pRequest.getParameter(PAYMENT_METHOD);
    if (null != paymentMethod && 0 < paymentMethod.trim().length()) {
      List<OrderPaymentElement> elements = new ArrayList<OrderPaymentElement>();
      if (paymentMethod.equalsIgnoreCase("Call-Center")) {
        elements.add(new OrderPaymentElement("Téléphone", "en attente de paiement", null));
      } else if (paymentMethod.equalsIgnoreCase("Virement")) {
        elements.add(new OrderPaymentElement("Virement Bancaire", "en attente de paiement", null));
      } else if (paymentMethod.equalsIgnoreCase("Cheque")) {
        elements.add(new OrderPaymentElement("Chèque", "en attente de paiement", null));
      } else if (paymentMethod.equalsIgnoreCase("Atout")) {
        String orderId = pRequest.getParameter(ORDER_ID);
        Repository repository = getRepository();
        long sofincoAmount = 0;
        if (null != repository) {
          try {
            RepositoryView logsipsView = repository.getView(LOG_SIPS);
            QueryBuilder queryBuilder = logsipsView.getQueryBuilder();
            QueryExpression propertyQuery =
                queryBuilder.createPropertyQueryExpression(PROPERTTY_ORDER_ID);
            QueryExpression valueQuery = queryBuilder.createConstantQueryExpression(orderId);
            Query query =
                queryBuilder.createComparisonQuery(propertyQuery, valueQuery, QueryBuilder.EQUALS);
            RepositoryItem[] logsipsItems = logsipsView.executeQuery(query);
            String paymentType;
            String responseCode;
            Integer amount;
            if (null != logsipsItems && 0 < logsipsItems.length) {
              for (RepositoryItem logsipsItem : logsipsItems) {
                responseCode = (String) logsipsItem.getPropertyValue(PROPERTTY_RESPONSE_CODE);
                if (isErrorCodeOK(responseCode)) {
                  amount = (Integer) logsipsItem.getPropertyValue(PROPERTTY_AMOUNT);
                  if (null != amount) {
                    paymentType = (String) logsipsItem.getPropertyValue(PROPERTTY_PAYMENT_TYPE);
                    if ("SOFINCO".equalsIgnoreCase(paymentType)) {
                      sofincoAmount += amount;
                    }
                  }
                }
              }
            }
          } catch (Exception e) {
            if (isLoggingError()) {
              logError(e);
            }
          }
        }
        elements.add(
            new OrderPaymentElement(
                CARTE_CASTORAMA_PAYMENT_TYPE, null, new Double(sofincoAmount / 100.0)));
      } else {
        String orderId = pRequest.getParameter(ORDER_ID);
        Repository repository = getRepository();
        long giftAmount = 0;
        long blueAmount = 0;
        long visaAmount = 0;
        long amexAmount = 0;
        long euroAmount = 0;
        if (null != repository) {
          try {
            RepositoryView logsipsView = repository.getView(LOG_SIPS);
            QueryBuilder queryBuilder = logsipsView.getQueryBuilder();
            QueryExpression propertyQuery =
                queryBuilder.createPropertyQueryExpression(PROPERTTY_ORDER_ID);
            QueryExpression valueQuery = queryBuilder.createConstantQueryExpression(orderId);
            Query query =
                queryBuilder.createComparisonQuery(propertyQuery, valueQuery, QueryBuilder.EQUALS);
            RepositoryItem[] logsipsItems = logsipsView.executeQuery(query);
            String paymentType;
            String responseCode;
            Integer amount;
            if (null != logsipsItems && 0 < logsipsItems.length) {
              for (RepositoryItem logsipsItem : logsipsItems) {
                responseCode = (String) logsipsItem.getPropertyValue(PROPERTTY_RESPONSE_CODE);
                if (isErrorCodeOK(responseCode)) {
                  amount = (Integer) logsipsItem.getPropertyValue(PROPERTTY_AMOUNT);
                  if (null != amount) {
                    paymentType = (String) logsipsItem.getPropertyValue(PROPERTTY_PAYMENT_TYPE);
                    if ("SVS".equalsIgnoreCase(paymentType)) {
                      giftAmount += amount;
                    } else if ("CB".equalsIgnoreCase(paymentType)) {
                      blueAmount += amount;
                    } else if ("VISA".equalsIgnoreCase(paymentType)) {
                      visaAmount += amount;
                    } else if ("AMEX".equalsIgnoreCase(paymentType)) {
                      amexAmount += amount;
                    } else if ("EUROCARD_MASTERCARD".equalsIgnoreCase(paymentType)) {
                      euroAmount += amount;
                    } else if ("MASTERCARD".equalsIgnoreCase(paymentType)) {
                      euroAmount += amount;
                    }
                  }
                }
              }
            }
            if (0 != giftAmount) {
              elements.add(
                  new OrderPaymentElement(
                      CARTE_CADEAU_PAYMENT_TYPE, null, new Double(giftAmount / 100.0)));
            }
            if (0 != blueAmount) {
              elements.add(
                  new OrderPaymentElement(
                      CARTE_BLEUE_PAYMENT_TYPE, null, new Double(blueAmount / 100.0)));
            }
            if (0 != visaAmount) {
              elements.add(
                  new OrderPaymentElement(
                      CARTE_VISA_PAYMENT_TYPE, null, new Double(visaAmount / 100.0)));
            }
            if (0 != amexAmount) {
              elements.add(
                  new OrderPaymentElement(
                      CARTE_AMERICAN_EXPRESS_PAYMENT_TYPE, null, new Double(amexAmount / 100.0)));
            }
            if (0 != euroAmount) {
              elements.add(
                  new OrderPaymentElement(
                      CARTE_EUROCARD_MASTERCARD_PAYMENT_TYPE,
                      null,
                      new Double(euroAmount / 100.0)));
            }

          } catch (Exception e) {
            if (isLoggingError()) {
              logError(e);
            }
          }
        }
      }

      int count = 0;
      if (0 < elements.size()) {
        pRequest.setParameter(SIZE, elements.size());
        pRequest.serviceLocalParameter(OUTPUT_START, pRequest, pResponse);
        Iterator<OrderPaymentElement> iterator = elements.iterator();
        while (iterator.hasNext()) {
          pRequest.setParameter(INDEX, count);
          OrderPaymentElement element = iterator.next();
          pRequest.setParameter(PAYMENT_TYPE, element.type);
          pRequest.setParameter(PAYMENT_DESCRIPTION, element.description);
          pRequest.setParameter(PAYMENT_AMOUNT, element.amount);
          pRequest.serviceLocalParameter(OUTPUT, pRequest, pResponse);
          count++;
        }
        pRequest.serviceLocalParameter(OUTPUT_END, pRequest, pResponse);
        isEmpty = false;
      }
    }
    if (isEmpty) {
      pRequest.serviceLocalParameter(EMPTY, pRequest, pResponse);
    }
  }
Example #14
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;
  }