Package cave.nice.testMessage.data

Examples of cave.nice.testMessage.data.DataManager


  @POST
  @Path("/{emailAddress}/verificationMessageRequest")
  public void sendConfirmation(@Context ServletContext context,
      @PathParam("emailAddress") InternetAddress emailAddress)
      throws WebApplicationException {
    DataManager dataManager = getDataManager();
    try {
      performSendConfirmation(context,
          dataManager.getUnverifiedAccount(emailAddress));
    } catch (UnknownUnverifiedAccountException e) {
      throw new WebApplicationException(Status.NOT_FOUND);
    } finally {
      dataManager.close();
    }
  }
View Full Code Here


      emailAddress.validate();
    } catch (AddressException e1) {
      throw new InvalidEmailAddressException(emailAddress);
    }

    DataManager dataManager = getDataManager();
    try {
      UnverifiedAccount account = dataManager
          .getUnverifiedAccount(emailAddress);
      dataManager.removeAccount(account);
      /*
       * We return a 202 "Accepted" instead of a 204 "No content" because
       * the modification could date some time to be propagated
       */
      return Response.status(Status.ACCEPTED).build();
    } catch (UnknownUnverifiedAccountException e) {
      throw new WebApplicationException(e);
    } finally {
      dataManager.close();
    }
  }
View Full Code Here

                  + "' and the personal name '"
                  + TestMessageConstants.TEST_MESSAGE_SENDER_NAME
                  + "'").entity(e).build());
    }

    DataManager dataManager = getDataManager();
    try {
      Session session = Session
          .getDefaultInstance(new Properties(), null);

      String notificationMailAddress = unverifiedAccount
          .getEmailAddress();
      Message msg = null;
      try {
        msg = new MimeMessage(session);
        msg.setFrom(appInternetAddress);
        msg.addRecipient(Message.RecipientType.TO, new InternetAddress(
            notificationMailAddress));
        msg.setReplyTo(new InternetAddress[] { appInternetAddress });
        msg.setSubject("Confirm the registration of your account '"
            + unverifiedAccount.getEmailAddress()
            + "' to Test Message");
        msg.setContent(
            getConfirmationEmail(context, unverifiedAccount),
            "text/html");

        Transport.send(msg);
      } catch (Exception e) {
        throw new WebApplicationException(Response
            .status(Status.INTERNAL_SERVER_ERROR)
            .entity("Error while sending the report to '"
                + notificationMailAddress + "': " + msg)
            .entity(e).build());
      }
    } finally {
      dataManager.close();
    }
  }
View Full Code Here

  }

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    DataManager dataStoreManager = DataManager.getInstance();

    try {
      DateTime currentTime = dataStoreManager.getCurrentTime();
      List<VerifiedAccount> accounts = dataStoreManager.getVerifiedAccounts();
      for (VerifiedAccount account : accounts) {
        /*
         * TODO Use account-specific configurations
         */
        tasksQueue
            .add(TaskOptions.Builder
                .withUrl("/resources/accounts/" + account.getEmailAddress() + "/reportRequest")
                .param("type", ReportType.TEXT_PLAIN.toString()).param("medium", ReportingMedium.GTalk.toString()));
      }
      LOGGER.info("Round of checks started at " + currentTime);
    } catch (CannotRetrieveEntitiesException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } finally {
      dataStoreManager.close();
    }
  }
View Full Code Here

  }

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    DataManager dataStoreManager = DataManager.getInstance();

    try {
      Properties props = new Properties();
      Session session = Session.getDefaultInstance(props, null);
      MimeMessage message = null;
      try {
        message = new MimeMessage(session, req.getInputStream());
      } catch (MessagingException e) {
        throw new ServletException(
            "Error while retrieving an incoming mail", e);
      }
      Address[] froms = null;
      try {
        froms = message.getFrom();
      } catch (MessagingException e) {
        throw new ServletException(
            "Error while retrieving an the 'from' field from the following message: "
                + message, e);
      }
      InternetAddress from = null;
      switch (froms.length) {
      case 0: {
        /*
         * No from address? How are we supposed to check the validity of
         * the test?
         *
         * TODO Check if the email has at least a valid test identifier
         * inside. If not, figure out something
         */
        throw new ServletException(
            "The following message has no 'from' field set: "
                + message);
      }
      case 1: {
        /*
         * That's how we like it ;-)
         */
        from = (InternetAddress) froms[0];
        break;
      }
      default: {
        /*
         * Uhm... multiple 'from'? TODO Check for a 'from' we know, and
         * assume that. Plus, log a warning.
         */
        throw new ServletException(
            "The following message has multiple 'from' fields set: "
                + message);
      }

      }
      try {
        if (message
            .getHeader(TestMessageConstants.SMTP_HEADER_TEST_IDENTIFIER) != null
            || message
                .getHeader(TestMessageConstants.SMTP_HEADER_ACCOUNT_IDENTIFIER) != null) {
          processTestAnswerInHeaders(dataStoreManager, message);
        } else {
          processTestAnswerInMessageBody(dataStoreManager, message,
              from);
        }
      } catch (DataManagerException e) {
        throw new ServletException(e.getMessage());
      } catch (Exception e) {
        UnprocessedEMail em = dataStoreManager
            .storeUnprocessedEMail(message);
        LOGGER.log(Level.SEVERE,
            "Incoming message could not be processed, saved as UnprocessedEMail "
                + KeyFactory.keyToString(em.getIdentifier()), e);
      }
    } finally {
      dataStoreManager.close();
    }
  }
View Full Code Here

    User user = userService.getCurrentUser();
    if (user == null) {
      return SKIP_BODY;
    }

    DataManager dataManager = DataManager.getInstance();
    try {
      verifiedAccounts = dataManager.getVerifiedAccounts();
      if (verifiedAccounts.isEmpty()) {
        return SKIP_BODY;
      }
    } catch (Exception e) {
      throw new JspException(e);
    } finally {
      dataManager.close();
    }

    return EVAL_PAGE;
  }
View Full Code Here

TOP

Related Classes of cave.nice.testMessage.data.DataManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.