@Override
 public void indexComponent(String spaceId, String componentId) throws Exception {
   ComponentInstLight compoInst =
       OrganisationControllerFactory.getOrganisationController()
           .getComponentInstLight(componentId);
   indexComponent(spaceId, compoInst);
 }
 private boolean isPublicationTemplateVisible(
     PublicationTemplate template, GlobalContext globalContext) {
   if (!template.isRestrictedVisibility()) {
     return true;
   } else {
     // template is restricted
     // check it according to current space and component
     if (template.isRestrictedVisibilityToInstance()) {
       if (isTemplateVisibleAccordingToInstance(template, globalContext)) {
         return true;
       }
     } else {
       OrganisationController oc = OrganisationControllerFactory.getOrganisationController();
       boolean allowed = true;
       if (template.isRestrictedVisibilityToApplication()) {
         if (!isTemplateVisibleAccordingToApplication(template, globalContext, oc)) {
           allowed = false;
         }
       }
       if (allowed) {
         if (!template.isRestrictedVisibilityToSpace()) {
           return true;
         } else {
           if (isTemplateVisibleAccordingToSpace(template, globalContext, oc)) {
             return true;
           }
         }
       }
     }
   }
   return false;
 }
Пример #3
0
 @Override
 public Collection<HistoryByUser> getHistoryByObject(
     ForeignPK foreignPK, int action, String objectType) {
   UserDetail[] allUsers =
       OrganisationControllerFactory.getOrganisationController()
           .getAllUsers(foreignPK.getInstanceId());
   return getHistoryByObject(foreignPK, action, objectType, allUsers);
 }
Пример #4
0
 @Override
 public Collection<HistoryByUser> getHistoryByObject(
     ForeignPK foreignPK, int action, String objectType, List<String> userIds) {
   if (userIds == null || userIds.isEmpty()) {
     return getHistoryByObject(foreignPK, action, objectType);
   }
   UserDetail[] users =
       OrganisationControllerFactory.getOrganisationController()
           .getUserDetails(userIds.toArray(new String[userIds.size()]));
   return getHistoryByObject(foreignPK, action, objectType, users);
 }
 /*
  * (non-Javadoc)
  * @see
  * com.silverpeas.notification.builder
  * .AbstractTemplateUserNotificationBuilder#performTemplateData
  * (java.lang.String, java.lang.Object, com.silverpeas.util.template.SilverpeasTemplate)
  */
 @Override
 protected void performTemplateData(
     final String language, final NodePK resource, final SilverpeasTemplate template) {
   getNotificationMetaData()
       .addLanguage(
           language, getBundle(language).getString(getBundleSubjectKey(), getTitle()), "");
   template.setAttribute("path", "");
   template.setAttribute(
       "senderName",
       OrganisationControllerFactory.getOrganisationController()
           .getUserDetail(userId)
           .getDisplayedName());
   template.setAttribute("silverpeasURL", getResourceURL(resource));
 }
 /*
  * (non-Javadoc)
  * @see com.silverpeas.notification.builder.AbstractTemplateUserNotificationBuilder#
  * performNotificationResource(java.lang.String, java.lang.Object,
  * com.silverpeas.notification.model.NotificationResourceData)
  */
 @Override
 protected void performNotificationResource(
     final String language,
     final NodePK resource,
     final NotificationResourceData notificationResourceData) {
   // The resource name corresponds at the label of the instantiated application
   notificationResourceData.setResourceName(
       OrganisationControllerFactory.getOrganisationController()
           .getComponentInstLight(getComponentInstanceId())
           .getLabel());
   notificationResourceData.setResourceId(resource.getId());
   notificationResourceData.setResourceType(getTemplatePath());
   // Exceptionally the resource location is builded at this level
   // Normally, the location is builded by the delayed notification mechanism
   notificationResourceData.setResourceLocation(buildResourceLocation());
 }
 @Override
 protected void performTemplateData(
     String language, Ticket resource, SilverpeasTemplate template) {
   Ticket ticket = getResource();
   String userId = getUserId();
   getNotificationMetaData()
       .addLanguage(
           language, getBundle(language).getString(getBundleSubjectKey(), getTitle()), "");
   template.setAttribute(
       "senderUser",
       OrganisationControllerFactory.getOrganisationController().getUserDetail(userId));
   template.setAttribute("attachmentUrl", fileSharingParam.getAttachmentUrl());
   if (StringUtil.isDefined(fileSharingParam.getAdditionalMessage())) {
     template.setAttribute("additionalMessage", fileSharingParam.getAdditionalMessage());
   }
   template.setAttribute("ticket", resource);
   if (ticket.getNbAccessMax() != 0) {
     template.setAttribute("limitedAccess", "true");
   }
 }
Пример #8
0
  /**
   * This method generates the Javascript instructions to retrieve in AJAX the comments on the given
   * resource and to display them. The generated code is built upon the JQuery toolkit, so that it
   * is required to be included within the the XHTML header section.
   *
   * @return the javascript code to handle a list of comments on a given resource.
   */
  private String setUpJQueryCommentPlugin() {
    String context = URLManager.getApplicationURL();

    OrganisationController controller = OrganisationControllerFactory.getOrganisationController();
    ResourcesWrapper settings = getSettings();
    UserDetail currentUser = controller.getUserDetail(getUserId());
    String[] profiles = controller.getUserProfiles(getUserId(), getComponentId());
    final boolean isAdmin;
    if (profiles != null) {
      isAdmin = Arrays.asList(profiles).contains(SilverpeasRole.admin.name());
    } else {
      isAdmin = currentUser.isAccessAdmin();
    }
    boolean canBeUpdated = settings.getSetting("AdminAllowedToUpdate", true) && isAdmin;

    String script =
        "$('#commentaires').comment({"
            + "uri: '"
            + context
            + "/services/comments/"
            + getComponentId()
            + "/"
            + getResourceType()
            + "/"
            + getResourceId()
            + "', author: { avatar: '"
            + URLManager.getApplicationURL()
            + currentUser.getAvatar()
            + "', id: '"
            + getUserId()
            + "', anonymous: "
            + currentUser.isAnonymous()
            + "}, "
            + "update: { activated: function( comment ) {"
            + "if ("
            + canBeUpdated
            + "|| (comment.author.id === '"
            + getUserId()
            + "'))"
            + "return true; else return false;},icon: '"
            + getUpdateIconURL()
            + "',"
            + "altText: '"
            + settings.getString("GML.update")
            + "'},"
            + "deletion: {activated: function( comment ) {if ("
            + canBeUpdated
            + " || (comment.author.id === '"
            + getUserId()
            + "')) return true; else return false;},"
            + "confirmation: '"
            + settings.getString("comment.suppressionConfirmation")
            + "',"
            + "icon: '"
            + getDeletionIconURL()
            + "',altText: '"
            + settings.getString("GML.delete")
            + "'}, updateBox: { title: '"
            + settings.getString("comment.comment")
            + "'}, editionBox: { title: '"
            + settings.getString("comment.add")
            + "', ok: '"
            + settings.getString("GML.validate")
            + "'}, validate: function(text) { if (text == null || $.trim(text).length == 0) { "
            + "alert('"
            + settings.getString("comment.pleaseFill_single")
            + "');"
            + "} else if (!isValidTextArea(text)) { alert('"
            + settings.getString("comment.champsTropLong")
            + "'); } else { return true; } return false; },"
            + "mandatory: '"
            + getMandatoryFieldSymbolURL()
            + "', mandatoryText: '"
            + settings.getString("GML.requiredField")
            + "'";
    if (isDefined(getCallback())) {
      script += ",callback: " + getCallback() + "});";
    } else {
      script += "});";
    }

    return script;
  }
 /**
  * Gets the organization controller used for performing its task.
  *
  * @return an organization controller instance.
  */
 private OrganisationController getOrganisationController() {
   if (organizationController == null) {
     organizationController = OrganisationControllerFactory.getOrganisationController();
   }
   return organizationController;
 }
Пример #10
0
  private Collection<HistoryByUser> getHistoryByObject(
      ForeignPK foreignPK, int action, String objectType, UserDetail[] users) {
    SilverTrace.info(
        "statistic", "StatisticBmEJB.getHistoryByObject()", "root.MSG_GEN_ENTER_METHOD");
    Collection<HistoryObjectDetail> list = null;
    try {
      list = getHistoryByAction(foreignPK, action, objectType);
    } catch (Exception e) {
      throw new StatisticRuntimeException(
          "StatisticBmEJB.getHistoryByObject()",
          SilverpeasRuntimeException.ERROR,
          "statistic.EX_IMPOSSIBLE_DOBTENIR_LETAT_DES_LECTURES",
          e);
    }
    String[] readerIds = new String[list.size()];
    Date[] date = new Date[list.size()];
    Iterator<HistoryObjectDetail> it = list.iterator();
    int i = 0;
    while (it.hasNext()) {
      HistoryObjectDetail historyObject = it.next();
      readerIds[i] = historyObject.getUserId();
      date[i] = historyObject.getDate();
      i++;
    }
    UserDetail[] allUsersByComponent = users;
    UserDetail[] controlledUsers =
        OrganisationControllerFactory.getOrganisationController().getUserDetails(readerIds);

    // ajouter à la liste "allUsers" (liste des users des rôles) les users ayant lu mais ne faisant
    // pas partis d'un rôle
    Collection<UserDetail> allUsers =
        new ArrayList<UserDetail>(allUsersByComponent.length + controlledUsers.length);
    int compteur = 0;
    for (int j = 0; j < allUsersByComponent.length; j++) {
      allUsers.add(allUsersByComponent[j]);
      compteur = j + 1;
    }
    for (int j = compteur; j < controlledUsers.length; j++) {
      if (!allUsers.contains(controlledUsers[j])) {
        allUsers.add(controlledUsers[j]);
      }
    }

    // création de la liste de tous les utilisateur ayant le droit de lecture
    Collection<HistoryByUser> statByUser = new ArrayList<HistoryByUser>(allUsers.size());
    for (UserDetail user : allUsers) {
      if (user != null) {
        HistoryByUser historyByUser = new HistoryByUser(user, null, 0);
        statByUser.add(historyByUser);
      }
    }

    // création d'une liste des accès par utilisateur
    Map<UserDetail, Date> byUser = new HashMap<UserDetail, Date>(controlledUsers.length);
    Map<UserDetail, Integer> nbAccessbyUser =
        new HashMap<UserDetail, Integer>(controlledUsers.length);
    for (int j = 0; j < controlledUsers.length; j++) {
      if (controlledUsers[j] != null) {
        // regarder si la date en cours est > à la date enregistrée...
        Object obj = byUser.get(controlledUsers[j]);
        if (obj != null && !obj.toString().equals("Never")) {
          Date dateTab = (Date) obj;
          if (date[j].after(dateTab)) {
            byUser.put(controlledUsers[j], date[j]);
          }
          Object objNb = nbAccessbyUser.get(controlledUsers[j]);
          int nbAccess = 0;
          if (objNb != null) {
            Integer nb = (Integer) objNb;
            nbAccess = nb.intValue();
            nbAccess = nbAccess + 1;
          }
          nbAccessbyUser.put(controlledUsers[j], Integer.valueOf(nbAccess));
        } else {
          byUser.put(controlledUsers[j], date[j]);
          nbAccessbyUser.put(controlledUsers[j], Integer.valueOf(1));
        }
      }
    }

    // mise à jour de la date de dernier accès et du nombre d'accès pour les
    // utilisateurs ayant lu
    Iterator<HistoryByUser> itStat = statByUser.iterator();
    while (itStat.hasNext()) {
      HistoryByUser historyByUser = itStat.next();
      UserDetail user = historyByUser.getUser();
      // recherche de la date de dernier accès
      Date lastAccess = byUser.get(user);
      if (lastAccess != null) {
        historyByUser.setLastAccess(lastAccess);
      }
      // recherche du nombre d'accès
      Integer nbAccess = nbAccessbyUser.get(user);
      if (nbAccess != null) {
        historyByUser.setNbAccess(nbAccess.intValue());
      }
    }

    // tri de la liste pour mettre en premier les users ayant consulté
    LastAccessComparatorDesc comparateur = new LastAccessComparatorDesc();
    Collections.sort((List<HistoryByUser>) statByUser, comparateur);

    SilverTrace.info(
        "statistic", "StatisticBmEJB.getHistoryByObject()", "root.MSG_GEN_EXIT_METHOD");
    return statByUser;
  }
  /**
   * Méthode métier du moteur d'importExport créant toutes les publications massives définies au
   * niveau du fichier d'import xml passé en paramètre au moteur d'importExport.
   *
   * @param userDetail - contient les informations sur l'utilisateur du moteur d'importExport
   * @param repositoriesType - objet mappé par castor contenant toutes les informations de création
   *     des publications du path défini
   * @return un objet ComponentReport contenant les informations de création des publications
   *     unitaires et nécéssaire au rapport détaillé
   */
  public void processImport(
      RepositoriesType repositoriesType,
      ImportSettings settings,
      ImportReportManager reportManager) {
    List<RepositoryType> listRep_Type = repositoriesType.getListRepositoryType();
    Iterator<RepositoryType> itListRep_Type = listRep_Type.iterator();
    AttachmentImportExport attachmentIE = new AttachmentImportExport();
    VersioningImportExport versioningIE = new VersioningImportExport(settings.getUser());
    PdcImportExport pdcIE = new PdcImportExport();

    while (itListRep_Type.hasNext()) {
      RepositoryType rep_Type = itListRep_Type.next();

      String componentId = rep_Type.getComponentId();
      int topicId = rep_Type.getTopicId();
      String sPath = rep_Type.getPath();

      // Création du rapport de repository
      MassiveReport massiveReport = new MassiveReport();
      reportManager.addMassiveReport(massiveReport, componentId);
      massiveReport.setRepositoryPath(sPath);

      ComponentInst componentInst =
          OrganisationControllerFactory.getOrganisationController().getComponentInst(componentId);
      if (componentInst == null) {
        // le composant n'existe pas
        massiveReport.setError(UnitReport.ERROR_NOT_EXISTS_COMPONENT);
      } else {
        reportManager.setComponentName(componentId, componentInst.getLabel());

        File path = new File(sPath);
        if (!path.isDirectory()) {
          // La variable path ne peut contenir qu'un dossier
          massiveReport.setError(UnitReport.ERROR_NOT_EXISTS_OR_INACCESSIBLE_DIRECTORY);
        } else {
          GEDImportExport gedIE =
              ImportExportFactory.createGEDImportExport(settings.getUser(), componentId);

          Iterator<File> itListcontenuPath = getPathContent(path);
          while (itListcontenuPath.hasNext()) {
            File file = itListcontenuPath.next();
            if (file.isFile()) {
              settings.setFolderId(String.valueOf(topicId));
              importFile(file, reportManager, massiveReport, gedIE, pdcIE, settings);
            } else if (file.isDirectory()) {
              switch (rep_Type.getMassiveTypeInt()) {
                case RepositoryType.NO_RECURSIVE:
                  // on ne fait rien
                  break;
                case RepositoryType.RECURSIVE_NOREPLICATE:
                  // traitement récursif spécifique
                  settings.setPathToImport(file.getAbsolutePath());
                  processImportRecursiveNoReplicate(
                      reportManager,
                      massiveReport,
                      gedIE,
                      attachmentIE,
                      versioningIE,
                      pdcIE,
                      settings);
                  break;
                case RepositoryType.RECURSIVE_REPLICATE:
                  try {
                    NodeDetail nodeDetail = gedIE.addSubTopicToTopic(file, topicId, massiveReport);
                    // Traitement récursif spécifique
                    settings.setPathToImport(file.getAbsolutePath());
                    settings.setFolderId(nodeDetail.getNodePK().getId());
                    processImportRecursiveReplicate(
                        reportManager, massiveReport, gedIE, pdcIE, settings);
                  } catch (ImportExportException ex) {
                    massiveReport.setError(UnitReport.ERROR_NOT_EXISTS_OR_INACCESSIBLE_DIRECTORY);
                  }
                  break;
              }
            }
          }
        }
      }
    }
  }