Package cave.nice.testMessage.data

Examples of cave.nice.testMessage.data.VerifiedAccount


  public Response deleteAccount(
      @PathParam("emailAddress") InternetAddress emailAddress)
      throws WebApplicationException {
    DataManager dataManager = getDataManager();
    try {
      VerifiedAccount account = dataManager
          .getVerifiedAccount(emailAddress);

      dataManager.removeAccount(account);
      return Response.status(Status.NO_CONTENT).build();
    } catch (UnknownVerifiedAccountException e) {
View Full Code Here


    ReportingMedium reportingMedium = ReportingMedium
        .valueOf(reportingMediumString);

    DataManager dataManager = getDataManager();
    try {
      VerifiedAccount account = dataManager
          .getVerifiedAccount(emailAddress);
      List<Test> openTests = dataManager.getOpenTests(account);

      final String report;
      try {
        report = ReportsGenerator.getReport(getCurrentUser(), account,
            openTests, reportType, dataManager.getCurrentTime());
      } catch (Exception e) {
        // TODO Log error
        return Response
            .serverError()
            .entity("Error while generating the report for the account: "
                + account.getEmailAddress()).build();
      }

      switch (reportingMedium) {
      case GMail: {
        InternetAddress appInternetAddress = null;
        try {
          appInternetAddress = new InternetAddress(
              TestMessageConstants.NOTIFICATIONS_EMAIL_ADDRESS,
              TestMessageConstants.TEST_MESSAGE_SENDER_NAME);
        } catch (UnsupportedEncodingException e) {
          throw new WebApplicationException(e);
        }

        Session session = Session.getDefaultInstance(new Properties(),
            null);

        String notificationMailAddress = getCurrentUser().getEmail();
        try {
          MimeMessage msg = new MimeMessage(session);
          msg.setFrom(appInternetAddress);
          msg.addRecipient(Message.RecipientType.TO,
              new InternetAddress(notificationMailAddress));
          msg.setReplyTo(new InternetAddress[] { appInternetAddress });
          msg.setSubject("Test Message Report for the account '"
              + account.getEmailAddress() + "'");
          msg.setContent(report, "text/html");

          Transport.send(msg);
        } catch (Exception e) {
          // TODO Log error
View Full Code Here

      @PathParam("emailAddress") InternetAddress emailAddress,
      @QueryParam("since") Date sinceDate) {
    // TODO Implement since
    DataManager dataManager = getDataManager();
    try {
      VerifiedAccount account = dataManager
          .getVerifiedAccount(emailAddress);
      Report report = new Report();
      report.setTimestamp(new Date());
      report.setOpenTests(Lists.newLinkedList(dataManager.getOpenTests(account)));
      report.setClosedTests(Lists.newLinkedList(dataManager.getClosedTests(account)));
View Full Code Here

      reportType = ReportType.TEXT_PLAIN;
    }

    DataManager dataManager = getDataManager();
    try {
      VerifiedAccount account = dataManager
          .getVerifiedAccount(emailAddress);
      return Response.ok(
          ReportsGenerator.getReport(getCurrentUser(), account,
              dataManager.getOpenTests(account), reportType,
              dataManager.getCurrentTime()), mediaType).build();
View Full Code Here

      @PathParam("emailAddress") InternetAddress emailAddress,
      @FormParam("challenge") UUID challenge)
      throws WebApplicationException {
    DataManager dataManager = getDataManager();
    try {
      VerifiedAccount account = dataManager
          .getVerifiedAccount(emailAddress);
      Test test = dataManager.getTestOfAccount(account, challenge);
      dataManager.markTestAsAnswered(test, new Date());
      LOGGER.info("REST answer to the test with challenge '"
          + test.getChallenge() + "' of the email account '"
          + account.getEmailAddress() + "'");
    } catch (UknownTestChallengeException e) {
      throw new WebApplicationException(Response
          .status(Status.NOT_FOUND)
          .entity("No test with challenge '" + challenge
              + "' is found").build());
View Full Code Here

      throws WebApplicationException {
    UUID challenge = UUID.randomUUID();
    DataManager dataManager = getDataManager();

    try {
      VerifiedAccount account = dataManager
          .getVerifiedAccount(emailAddress);
      Test newTest = dataManager.createTest(account, new Date(),
          challenge);

      if (sendTest) {
        Session session = Session.getDefaultInstance(new Properties(),
            null);
        Message msg = null;
        try {
          InternetAddress appInternetAddress = new InternetAddress(
              TestMessageConstants.TESTS_EMAIL_ADDRESS,
              TestMessageConstants.TEST_MESSAGE_SENDER_NAME);

          Map<String, Object> params = Maps.newHashMap();
          params.put("challenge", newTest.getChallenge());
          params.put(
              "url",
              "http://"
                  + SystemProperty.applicationId.get()
                  + ".appspot.com/answerTest.jsp?emailAddress="
                  + account.getEmailAddress() + "&challenge="
                  + newTest.getChallenge());

          String content = TemplateManager.getInstance(context)
              .applyTemplate(TemplateType.TEST_MESSAGE, params);

          msg = new MimeMessage(session);
          msg.setFrom(appInternetAddress);
          msg.addRecipient(Message.RecipientType.TO,
              account.getInternetAddress());
          msg.setReplyTo(new InternetAddress[] { appInternetAddress });
          msg.addHeader(
              TestMessageConstants.SMTP_HEADER_ACCOUNT_IDENTIFIER,
              KeyFactory.keyToString(account.getIdentifier()));
          msg.addHeader(
              TestMessageConstants.SMTP_HEADER_TEST_IDENTIFIER,
              KeyFactory.keyToString(newTest.getIdentifier()));
          msg.setSubject("Test Message on "
              + DateFormat.getInstance()
                  .format(newTest.getDate()));
          msg.setContent(content, "text/plain");
          Transport.send(msg);
        } catch (Exception e) {
          /*
           * Remove the test that was not successfully sent
           */
          dataManager.removeTest(newTest);

          throw new WebApplicationException(
              Response.serverError()
                  .entity("Error while sending the following test message to '"
                      + account.getEmailAddress()
                      + "': "
                      + msg).entity(e).build());
        }
      }

View Full Code Here

  public List<Test> getAllTests(
      @PathParam("emailAddress") InternetAddress emailAddress)
      throws WebApplicationException {
    DataManager dataManager = getDataManager();
    try {
      VerifiedAccount account = dataManager
          .getVerifiedAccount(emailAddress);

      return Lists.newArrayList(account.getTests());
    } catch (UnknownVerifiedAccountException e) {
      throw new WebApplicationException(Response
          .status(Status.NOT_FOUND)
          .entity("No account '" + emailAddress.getAddress()
              + "' found").build());
View Full Code Here

  public List<Test> getClosedTests(
      @PathParam("emailAddress") InternetAddress emailAddress)
      throws WebApplicationException {
    DataManager dataManager = getDataManager();
    try {
      VerifiedAccount account = dataManager
          .getVerifiedAccount(emailAddress);
      // checkAuthentication(userOwnerOf(account).or(userIsAdministrator()));

      return Lists.newArrayList(dataManager.getClosedTests(account));
    } catch (CannotRetrieveEntitiesException e) {
View Full Code Here

      @PathParam("emailAddress") InternetAddress emailAddress)
      throws WebApplicationException {
    DataManager dataManager = getDataManager();

    try {
      VerifiedAccount account = dataManager
          .getVerifiedAccount(emailAddress);

      return Lists.newArrayList(dataManager.getOpenTests(account));
    } catch (CannotRetrieveEntitiesException e) {
      throw new WebApplicationException(
View Full Code Here

      @PathParam("emailAddress") InternetAddress emailAddress,
      @PathParam("challenge") UUID challenge)
      throws WebApplicationException {
    DataManager dataManager = getDataManager();
    try {
      VerifiedAccount account = dataManager
          .getVerifiedAccount(emailAddress);

      Test test = dataManager.getTestOfAccount(account, challenge);
      dataManager.removeTest(test);
      return Response.ok().build();
View Full Code Here

TOP

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

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.