private boolean sendNotification(
      HttpServletRequest request,
      HttpServletResponse response,
      Repository db,
      String login,
      String commit,
      String url,
      String authorName,
      String message)
      throws ServletException, URISyntaxException, IOException, JSONException, CoreException,
          Exception {
    UserEmailUtil util = UserEmailUtil.getUtil();
    if (!util.isEmailConfigured()) {
      return statusHandler.handleRequest(
          request,
          response,
          new ServerStatus(
              IStatus.ERROR,
              HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
              "Smpt server not configured",
              null));
    }
    IOrionCredentialsService userAdmin = UserServiceHelper.getDefault().getUserStore();
    User user = (User) userAdmin.getUser(UserConstants.KEY_LOGIN, login);
    try {
      if (reviewRequestEmail == null) {
        reviewRequestEmail = new EmailContent(EMAIL_REVIEW_REQUEST_FILE);
      }

      String emailAdress = user.getEmail();

      util.sendEmail(
          reviewRequestEmail.getTitle(),
          reviewRequestEmail
              .getContent()
              .replaceAll(EMAIL_COMMITER_NAME, authorName)
              .replaceAll(EMAIL_URL_LINK, url)
              .replaceAll(EMAIL_COMMIT_MESSAGE, message),
          emailAdress);

      JSONObject result = new JSONObject();
      result.put(GitConstants.KEY_RESULT, "Email sent");
      OrionServlet.writeJSONResponse(
          request, response, result, JsonURIUnqualificationStrategy.ALL_NO_GIT);
      return true;
    } catch (Exception e) {
      return statusHandler.handleRequest(
          request,
          response,
          new ServerStatus(
              IStatus.ERROR,
              HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
              "User doesn't exist",
              null));
    }
  };
Esempio n. 2
0
 /**
  * Restore a HostAuth from the database, given its unique id
  *
  * @param context
  * @param id
  * @return the instantiated HostAuth
  */
 public static HostAuth restoreHostAuthWithId(Context context, long id) {
   return EmailContent.restoreContentWithId(
       context, HostAuth.class, HostAuth.CONTENT_URI, HostAuth.CONTENT_PROJECTION, id);
 }