private void processWebHookDocumentMilestoneEvent(
      DocumentStatisticUpdatedEvent event,
      Collection<ContentState> contentStates,
      String message,
      int percentMilestone) {

    HProjectIteration version = projectIterationDAO.findById(event.getProjectIterationId());
    HProject project = version.getProject();

    if (!project.getWebHooks().isEmpty()) {
      WordStatistic stats =
          translationStateCacheImpl.getDocumentStatistics(
              event.getDocumentId(), event.getLocaleId());

      WordStatistic oldStats = StatisticsUtil.copyWordStatistic(stats);
      if (oldStats != null) {
        oldStats.decrement(event.getNewState(), event.getWordCount());
        oldStats.increment(event.getPreviousState(), event.getWordCount());

        boolean shouldPublish =
            hasContentStateReachedMilestone(oldStats, stats, contentStates, percentMilestone);

        if (shouldPublish) {
          HDocument document = documentDAO.getById(event.getDocumentId());

          String editorUrl =
              urlUtil.fullEditorDocumentUrl(
                  project.getSlug(),
                  version.getSlug(),
                  event.getLocaleId(),
                  LocaleId.EN_US,
                  document.getDocId());

          DocumentMilestoneEvent milestoneEvent =
              new DocumentMilestoneEvent(
                  project.getSlug(),
                  version.getSlug(),
                  document.getDocId(),
                  event.getLocaleId(),
                  message,
                  editorUrl);
          for (WebHook webHook : project.getWebHooks()) {
            publishDocumentMilestoneEvent(webHook, milestoneEvent);
          }
        }
      }
    }
  }
  public static boolean isUserAllowedAccess(HProject project) {
    if (project.isRestrictedByRoles()) {
      ZanataIdentity identity = getIdentity();

      if (identity != null) {
        for (HAccountRole role : project.getAllowedRoles()) {
          if (identity.hasRole(role.getName())) {
            return true;
          }
        }
      }

      // no access
      return false;
    } else {
      return true;
    }
  }
  private HProjectIteration retrieveAndCheckIteration(
      String projectSlug, String iterationSlug, boolean writeOperation) {
    HProjectIteration hProjectIteration = projectIterationDAO.getBySlug(projectSlug, iterationSlug);
    HProject hProject = hProjectIteration == null ? null : hProjectIteration.getProject();

    if (hProjectIteration == null) {
      throw new NoSuchEntityException(
          "Project Iteration '" + projectSlug + ":" + iterationSlug + "' not found.");
    } else if (hProjectIteration.getStatus().equals(EntityStatus.OBSOLETE)
        || hProject.getStatus().equals(EntityStatus.OBSOLETE)) {
      throw new NoSuchEntityException(
          "Project Iteration '" + projectSlug + ":" + iterationSlug + "' not found.");
    } else if (writeOperation) {
      if (hProjectIteration.getStatus().equals(EntityStatus.READONLY)
          || hProject.getStatus().equals(EntityStatus.READONLY)) {
        throw new ReadOnlyEntityException(
            "Project Iteration '" + projectSlug + ":" + iterationSlug + "' is read-only.");
      } else {
        return hProjectIteration;
      }
    } else {
      return hProjectIteration;
    }
  }