public boolean rulesExist() {

    NodeRef nodeUserHomes = alfrescoUtilsService.getNodeRef("/app:company_home/app:user_homes");

    boolean ruleNodeUserExit = false;
    List<Rule> listRulesExistantes = ruleService.getRules(nodeUserHomes);
    if (null != listRulesExistantes && !listRulesExistantes.isEmpty()) {
      for (Rule ruleExistant : listRulesExistantes) {
        if (ruleExistant.getTitle().equals(CreateRulesWebScript.NOM_REGLE_NODE_USER)) {
          ruleNodeUserExit = true;
        }
      }
    }

    NodeRef nodeSites = alfrescoUtilsService.getNodeRef("/app:company_home/site:sites");

    boolean ruleNodeSitesExit = false;
    listRulesExistantes = ruleService.getRules(nodeSites);
    if (null != listRulesExistantes && !listRulesExistantes.isEmpty()) {
      for (Rule ruleExistant : listRulesExistantes) {
        if (ruleExistant.getTitle().equals(CreateRulesWebScript.NOM_REGLE_SITE_SIRH)) {
          ruleNodeSitesExit = true;
        }
      }
    }

    return ruleNodeSitesExit && ruleNodeUserExit;
  }
  public void traiteGroupAgentSHD(Integer idAgent, String nameFolderAgent) {

    List<PersonInfo> listPersonSHD = new ArrayList<PersonInfo>();
    List<Integer> listeSuperieurHierarchique = sirhWsConsumer.getListSuperieurOfAgent(idAgent);
    String groupSHD = PREFIXE_GROUP + nameFolderAgent + SHD;
    for (Integer idSup : listeSuperieurHierarchique) {

      if (null != idSup) {
        PersonInfo personSHD = alfrescoUtilsService.getPersonInfoByIdAgent(idSup);

        // AJOUT
        if (null != personSHD) {
          Set<String> listGroup = authorityService.getAuthoritiesForUser(personSHD.getUserName());
          if (!alfrescoUtilsService.isExistGroupForUser(listGroup, groupSHD)
              && authorityService.authorityExists(personSHD.getUserName())) {
            authorityService.addAuthority(groupSHD, personSHD.getUserName());
            if (!listPersonSHD.contains(personSHD)) {
              listPersonSHD.add(personSHD);
            }
            logger.debug("User " + personSHD.getUserName() + " adding in Group " + groupSHD);
          } else if (alfrescoUtilsService.isExistGroupForUser(listGroup, groupSHD)
              && authorityService.authorityExists(personSHD.getUserName())) {
            if (!listPersonSHD.contains(personSHD)) {
              listPersonSHD.add(personSHD);
            }
            logger.debug("User " + personSHD.getUserName() + " existing in Group " + groupSHD);
          }
        }
      }
    }

    // SUPPRESSION
    Set<String> listUsersGoupSHD =
        authorityService.getContainedAuthorities(AuthorityType.USER, groupSHD, true);
    if (null != listUsersGoupSHD) {

      for (String userGroupSHD : listUsersGoupSHD) {
        if (!alfrescoUtilsService.isExistUserInListPersonInfo(listPersonSHD, userGroupSHD)) {
          authorityService.removeAuthority(groupSHD, userGroupSHD);
          logger.debug("User " + userGroupSHD + " deleted in Group " + groupSHD);
        }
      }
    }
  }
  @Override
  protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {

    long startTime = System.currentTimeMillis();

    logger.info("DEBUT Web Script SynchroniseDroitsSHDWebScript");

    Map<String, Object> model = new HashMap<String, Object>();
    model.put("nomWebScript", "SynchroniseDroitsSHDWebScript");

    if (!isSiteSirhExist()) {
      logger.debug("Site SIRH not exist");

      long endTime = System.currentTimeMillis();

      model.put("nbrAgentCree", "Site SIRH not exist");
      model.put("tempsExecution", endTime - startTime);

      return model;
    }

    NodeRef nodeAgents =
        alfrescoUtilsService.getNodeRef(
            "/app:company_home/site:sites/cm:SIRH/cm:documentLibrary/cm:Agents");

    List<ChildAssociationRef> listChildren = nodeService.getChildAssocs(nodeAgents);

    int nbrAgentCree = 0;
    if (null != listChildren && 0 < listChildren.size()) {
      for (ChildAssociationRef child : listChildren) {
        // nous gerons nous meme les transactions
        // car nous avons eu "TransactionalCache' is full"
        // cela ralentit fortement Alfresco
        UserTransaction trx =
            serviceRegistry.getTransactionService().getNonPropagatingUserTransaction(false);
        try {
          trx.begin();

          String nameFolderAgent =
              (String) nodeService.getProperty(child.getChildRef(), ContentModel.PROP_NAME);
          Integer idAgent = null;
          try {
            idAgent =
                new Integer(
                    nameFolderAgent.substring(
                        nameFolderAgent.length() - 7, nameFolderAgent.length()));
          } catch (NumberFormatException e) {
            logger.error("Error ParseException Node : " + nameFolderAgent);
            idAgent = null;
          }

          if (null != idAgent) {
            logger.debug("Add SHD Rights to " + idAgent);
            traiteDroitsOfNodeAgent(child, idAgent, nameFolderAgent);
            nbrAgentCree++;
          }

          trx.commit();
        } catch (Throwable e) {
          try {
            trx.rollback();
          } catch (IllegalStateException | SecurityException | SystemException e1) {
            logger.error(e1.getMessage());
          }
        }
      }
    }

    long endTime = System.currentTimeMillis();

    logger.info("FIN Web Script SynchroniseDroitsSHDWebScript");

    model.put("tempsExecution", endTime - startTime);
    model.put("nombreAgentsAjoutesSHD", nbrAgentCree);

    return model;
  }