Beispiel #1
0
 public static void createAndAddToRepository(List<Object> properties, Repository repository)
     throws RepositoryException {
   if (ExperianUtils.experianRequestItemProperties.size() != properties.size()) {
     StringBuffer sb = new StringBuffer("Incorrect size of list. List must have size = ");
     sb.append(ExperianUtils.experianRequestItemProperties.size());
     sb.append(", but not ");
     sb.append(properties.size());
     sb.append(".");
     throw new RuntimeException(sb.toString());
   }
   ;
   MutableRepositoryItem mri = ((MutableRepository) repository).createItem("experianRequest");
   Iterator<String> it = ExperianUtils.experianRequestItemProperties.keySet().iterator();
   int i = 0;
   while (it.hasNext()) {
     try {
       String temp = it.next();
       mri.setPropertyValue(temp, properties.get(i));
       // throw new NullPointerException("Test exception");
     } catch (Exception ex) {
       if (LOGGER.isErrorEnabled()) {
         LOGGER.error(ex);
       }
     }
     i++;
   }
   ((MutableRepository) repository).addItem(mri);
 }
  /** Sets sets last modification date and last modifier properties to a recently edited asset. */
  @Override
  public void preUpdateAsset(AssetEditorInfo pEditorInfo, Collection pUpdates) {
    super.preUpdateAsset(pEditorInfo, pUpdates);

    MutableRepositoryItem currentItem = getItemForUpdate(pEditorInfo);

    currentItem.setPropertyValue(
        BaseAssetProperty.LAST_MODIFIED_DATE, new Timestamp(System.currentTimeMillis()));
    currentItem.setPropertyValue(
        BaseAssetProperty.LAST_MODIFIED_BY, getUserProfile().getRepositoryId());
  }
Beispiel #3
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;
  }
  /** Sets creation date and creator properties to a recently created asset. */
  @Override
  public void preAddAsset(AssetEditorInfo pEditorInfo, Collection pUpdates) {
    super.preAddAsset(pEditorInfo, pUpdates);
    // Get the current item being created
    MutableRepositoryItem currentItem =
        (MutableRepositoryItem) pEditorInfo.getAssetWrapper().getAsset();

    String currentUserId = getUserProfile().getRepositoryId();

    // Set control/review fields
    Timestamp timestamp = new Timestamp(System.currentTimeMillis());
    currentItem.setPropertyValue(BaseAssetProperty.LAST_MODIFIED_DATE, timestamp);
    currentItem.setPropertyValue(BaseAssetProperty.LAST_MODIFIED_BY, currentUserId);
    currentItem.setPropertyValue(BaseAssetProperty.CREATION_DATE, timestamp);
    currentItem.setPropertyValue(BaseAssetProperty.CREATED_BY, currentUserId);
  }
  /**
   * 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
  }