Package cave.nice.testMessage.data

Examples of cave.nice.testMessage.data.DataManager


          Response.status(Status.BAD_REQUEST)
              .entity("Required parameter 'notifyIfNoOpenTests' not provided")
              .build());
    }

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

      // First, check if a policy of the selected type exists, If so, we
      // update it
      for (ReportingPolicy reportingPolicy : account
          .getReportingPolicies()) {
        if (type.equals(reportingPolicy.getType())) {
          throw new WebApplicationException(Status.CONFLICT);
        }
      }

      dataManager.addNewReportingPolicy(account, type,
          notifyAfterMinutes, notifyIfNoOpenTests);

      URI newEntityURI = uriInfo.getBaseUri().resolve(
          "/resources/accounts/" + emailAddress.getAddress()
              + "/reportingPolicies/" + type);

      return Response.created(newEntityURI).build();
    } catch (UnknownVerifiedAccountException e) {
      throw new WebApplicationException(Response
          .status(Status.NOT_FOUND)
          .entity("No account '" + emailAddress.getAddress()
              + "' found").build());
    } catch (DuplicatedReportingPolicyException e) {
      throw new WebApplicationException(Response.status(Status.CONFLICT)
          .entity(e.getMessage()).build());
    } finally {
      dataManager.close();
    }
  }
View Full Code Here


          .status(Status.BAD_REQUEST)
          .entity("Required parameter 'type' not provided").build());
    }
    */

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

      // First, check if a policy of the selected type exists, If so, we
      // update it
      ReportingPolicy reportingPolicy = account.getReportingPolicy(type);
      boolean modified = false;
      if (notifyAfterMinutes != null && reportingPolicy.getNotifyAfterMinutes() != notifyAfterMinutes) {
        reportingPolicy.setNotifyAfterMinutes(notifyAfterMinutes);
        modified = true;
      }
      if (notifyIfNoOpenTests != null && reportingPolicy.isNotifyIfNoOpenTests() != notifyIfNoOpenTests) {
        reportingPolicy.setNotifyIfNoOpenTests(notifyIfNoOpenTests);
        modified = true;
      }

      if (modified) {
        return Response.status(Status.OK).build();
      }

      return Response.status(Status.NOT_MODIFIED).build();
    } catch (NoSuchElementException e) {
      throw new WebApplicationException(Status.NOT_FOUND);
    } catch (UnknownVerifiedAccountException e) {
      throw new WebApplicationException(Response
          .status(Status.NOT_FOUND)
          .entity("No account '" + emailAddress.getAddress()
              + "' found").build());
    } finally {
      dataManager.close();
    }
  }
View Full Code Here

  @Path("/{emailAddress}/reportingPolicies")
  @Produces(MediaType.APPLICATION_JSON)
  public Response getReportingPolicies(
      @PathParam("emailAddress") InternetAddress emailAddress)
      throws WebApplicationException {
    DataManager dataManager = getDataManager();
    try {
      VerifiedAccount account = dataManager
          .getVerifiedAccount(emailAddress);

      List<ReportingPolicy> reportingPolicies = Lists
          .newArrayList(account.getReportingPolicies());

      return Response.ok(reportingPolicies).build();
    } catch (UnknownVerifiedAccountException e) {
      throw new WebApplicationException(Response
          .status(Status.NOT_FOUND)
          .entity("No account '" + emailAddress.getAddress()
              + "' found").build());
    } finally {
      dataManager.close();
    }
  }
View Full Code Here

  @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
  public Response deleteReportingPolicy(
      @PathParam("emailAddress") InternetAddress emailAddress,
      @FormParam("type") ReportingPolicyType type)
      throws WebApplicationException {
    DataManager dataManager = getDataManager();
    try {
      VerifiedAccount account = dataManager
          .getVerifiedAccount(emailAddress);

      ReportingPolicy reportingPolicy = account.getReportingPolicy(type);
      dataManager.removeReportingPolicy(account, reportingPolicy);
      return Response.status(Status.NO_CONTENT).build();
    } catch (UnknownVerifiedAccountException e) {
      throw new WebApplicationException(Response
          .status(Status.NOT_FOUND)
          .entity("No account '" + emailAddress.getAddress()
              + "' found").build());
    } catch (NoSuchElementException e) {
      throw new WebApplicationException(Response
          .status(Status.NOT_FOUND)
          .entity("No reporting policy of type '" + type
              + "' found for the account '"
              + emailAddress.getAddress() + "'").build());
    } finally {
      dataManager.close();
    }
  }
View Full Code Here

  @DELETE
  @Path("/{emailAddress}")
  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) {
      throw new WebApplicationException(Response
          .status(Status.NOT_FOUND)
          .entity("No account '" + emailAddress.getAddress()
              + "' found").build());
    } finally {
      dataManager.close();
    }
  }
View Full Code Here

  private final Queue tasksQueue = QueueFactory
      .getQueue(TestMessageConstants.REPORTING_TASKS_QUEUE_NAME);

  public void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException {
    DataManager dataStoreManager = DataManager.getInstance();

    try {
      /*
       * Perform test of the email. It generates an email and sends it to
       * the specified address specified. The email contains a timestamp,
       * that is kept by the servlet using a database and it is checked by
       * the CheckMessageServlet
       */
      List<VerifiedAccount> accounts = dataStoreManager
          .getVerifiedAccounts();
      for (VerifiedAccount account : accounts) {
        /*
         * TODO Add task names
         */
        tasksQueue.add(TaskOptions.Builder
            .withUrl("/resources/accounts/"
                + account.getEmailAddress() + "/tests"));
      }
    } catch (CannotRetrieveEntitiesException e) {
      throw new ServletException(e);
    } finally {
      dataStoreManager.close();
    }
  }
View Full Code Here

  private UriInfo uriInfo;

  @GET
  @Produces(MediaType.APPLICATION_JSON)
  public Response getUnverifiedAccounts() {
    DataManager dataManager = getDataManager();
    try {
      return Response.ok(dataManager.getUnverifiedAccounts()).build();
    } catch (CannotRetrieveEntitiesException e) {
      // TODO Log error, not return it
      throw new WebApplicationException(Response.serverError().entity(e)
          .build());
    } finally {
      dataManager.close();
    }
  }
View Full Code Here

      throws WebApplicationException {
    if(emailAddress == null) {
      throw new MissingRequiredParameterException("emailAddress");
    }

    DataManager dataManager = getDataManager();
    UnverifiedAccount newAccount = null;
    try {
      UnverifiedAccount unverifiedAccount = dataManager
          .getUnverifiedAccount(emailAddress);
      throw new WebApplicationException(
          Response.status(Status.BAD_REQUEST)
              .entity("The submitted email address '"
                  + emailAddress
                  + "' results already registered (but not yet verified!) since "
                  + unverifiedAccount.getRegistrationDate())
              .build());
    } catch (UnknownUnverifiedAccountException e1) {
      try {
        VerifiedAccount verifiedAccount = dataManager
            .getVerifiedAccount(emailAddress);
        throw new WebApplicationException(Response
            .status(Status.BAD_REQUEST)
            .entity("The submitted email address '" + emailAddress
                + "' results already registered since "
                + verifiedAccount.getRegistrationDate())
            .build());
      } catch (UnknownVerifiedAccountException e) {
        /*
         * All right, that is how we like it ;-)
         */
        try {
          newAccount = dataManager
              .createUnverifiedAccount(emailAddress);
          performSendConfirmation(context, newAccount);

          URI accountURI = uriInfo.getBaseUri().resolve(
              "/resources/unverifiedAccounts/"
                  + newAccount.getEmailAddress());

          return Response.created(accountURI).build();
        } catch (WebApplicationException e2) {
          dataManager.removeAccount(newAccount);

          throw e2;
        }
      }
    } finally {
      dataManager.close();
    }
  }
View Full Code Here

  private static final long serialVersionUID = 5826401999229297670L;

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
      throws ServletException, IOException {
    DataManager dataStoreManager = DataManager.getInstance();
    try {
      dataStoreManager.removeExpiredUnverifiedAccounts();
    } finally {
      dataStoreManager.close();
    }
  }
View Full Code Here

      throw new WebApplicationException(Response
          .status(Status.BAD_REQUEST)
          .entity("Mandatory parameter 'challenge' not set").build());
    }

    DataManager dataManager = getDataManager();
    try {
      dataManager.verifyAccount(emailAddress, challenge);
      return Response.ok().build();
    } catch (Exception e) {
      throw new WebApplicationException(
          Response.status(Status.BAD_REQUEST)
              .entity("Could not verify account with challenge '"
                  + challenge
                  + "'. Either the challenge is wrong, or the email address specified is not pending verification (it may altogether not existing in the system).")
              .build());
    } finally {
      dataManager.close();
    }
  }
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.