/**
  * Méthode récursive appelée dans le cas de l'importation massive récursive avec création de
  * nouveau topic: chaque sous dossier entrainera la création d'un topic de même nom.
  *
  * @param massiveReport - référence sur l'objet de rapport détaillé du cas import massif
  *     permettant de le compléter quelque soit le niveau de récursivité.
  * @param userDetail - contient les informations sur l'utilisateur du moteur d'importExport.
  * @param path - dossier correspondant au niveau de récursivité auquel on se trouve.
  * @param componentId - id du composant dans le lequel l'import massif est effectué.
  * @param topicId - id du thème dans lequel seront crées les éléments du niveau de récursivité
  *     auquel on se trouve.
  * @return the list of publications created by the import.
  * @throws ImportExportException
  */
 public List<PublicationDetail> processImportRecursiveReplicate(
     ImportReportManager reportManager,
     MassiveReport massiveReport,
     GEDImportExport gedIE,
     PdcImportExport pdcIE,
     ImportSettings settings)
     throws ImportExportException {
   List<PublicationDetail> publications = new ArrayList<PublicationDetail>();
   File path = new File(settings.getPathToImport());
   Iterator<File> itListcontenuPath = getPathContent(path);
   while (itListcontenuPath.hasNext()) {
     File file = itListcontenuPath.next();
     if (file.isFile()) {
       PublicationDetail publication =
           importFile(file, reportManager, massiveReport, gedIE, pdcIE, settings);
       if (publication != null) {
         publications.add(publication);
       }
     } else if (file.isDirectory()) {
       NodeDetail nodeDetail =
           gedIE.addSubTopicToTopic(file, Integer.valueOf(settings.getFolderId()), massiveReport);
       // massiveReport.addOneTopicCreated();
       // Traitement récursif spécifique
       ImportSettings recursiveSettings = settings.clone();
       recursiveSettings.setPathToImport(file.getAbsolutePath());
       recursiveSettings.setFolderId(nodeDetail.getNodePK().getId());
       publications.addAll(
           processImportRecursiveReplicate(
               reportManager, massiveReport, gedIE, pdcIE, recursiveSettings));
     }
   }
   return publications;
 }
Exemplo n.º 2
0
  /**
   * Selection des éléments nécessaires à la construction de l'url de l'item.
   *
   * @return
   * @throws Exception
   */
  public String getUrl() throws Exception {
    PublicationDetail pub = null;
    NodeDetail node = null;
    String page = "";
    if (idTopic != null) {
      node = themetracker.getTopic(idTopic);
    } else if (idPub != null) {
      pub = themetracker.getPublicationDetail(idPub);
      Collection<NodePK> fathers = pub.getPublicationBm().getAllFatherPK(pub.getPK());
      Iterator<NodePK> it = fathers.iterator();
      while (it.hasNext()) {
        NodePK pk = it.next();
        node = themetracker.getTopic(pk.getId());
        if (excludeTopicNamed != null) {
          StringTokenizer st = new StringTokenizer(node.getFullPath(), "/");
          boolean found = false;
          while (st.hasMoreTokens()) {
            if (themetracker.getTopic(st.nextToken()).getName().equals(excludeTopicNamed)) {
              found = true;
              break;
            }
          }
          if (found == false) break;
        } else {
          break;
        }
      }

      @SuppressWarnings("unchecked")
      Collection<PublicationDetail> pubs =
          themetracker.getPublicationsByTopic(node.getId() + ",order,asc");
      Iterator<PublicationDetail> iPubs = pubs.iterator();
      int order = 1;
      while (iPubs.hasNext()) {
        PublicationDetail p = iPubs.next();
        if (p.getId().equals(pub.getId())) break;
        order++;
      }
      if (order > 1) page = "-" + order;
    } else {
      throw new Exception("Pas de publication ou de theme");
    }

    if (Boolean.parseBoolean(usePageNumber)) {
      return generateFullSemanticPath(node, pub) + page;
    } else {
      return generateFullSemanticPath(node, pub) + "-" + idPub;
    }
  }
  public String addBody(ResourcesWrapper resource, File file)
      throws QuestionReplyException, ParseException {
    StringBuilder sb = new StringBuilder();
    sb.append("<table width=\"100%\">\n");
    Collection<NodeDetail> categories = getAllCategories();
    QuestionReplyExport exporter = new QuestionReplyExport(resource, file);
    for (NodeDetail category : categories) {
      String categoryId = Integer.toString(category.getId());
      exportCategory(exporter, category, categoryId, sb);
    }
    NodeDetail fakeCategory = new NodeDetail();
    fakeCategory.setName("");
    exportCategory(exporter, fakeCategory, null, sb);

    sb.append("</table>\n");
    return sb.toString();
  }
Exemplo n.º 4
0
  /**
   * Deletes the specified node and all of its children within the specified data source connection.
   *
   * @param pk the primary key of the father node to delete.
   * @param inConnection the connection to use in the deletion.
   * @param afterDeletion the method to invoke after the deletion of a node.
   */
  public static void deleteNodes(
      final NodePK pk, final Connection inConnection, final AnonymousMethodOnNode afterDeletion) {
    try {
      Collection<NodeDetail> children = NodeDAO.getChildrenDetails(inConnection, pk);
      for (NodeDetail childNode : children) {
        deleteNodes(childNode.getNodePK(), inConnection, afterDeletion);
      }

      deleteNode(pk, inConnection);
      if (afterDeletion != null) {
        afterDeletion.invoke(pk);
      }
    } catch (Exception ex) {
      throw new NodeRuntimeException(
          "NodeBmEJB.removeNode()",
          SilverpeasRuntimeException.ERROR,
          "node.DELETING_NODE_FAILED",
          "nodeId = " + pk.getId(),
          ex);
    }
  }
 @Override
 public boolean isReadable(ShareableResource resource) {
   Ticket ticket = SharingServiceFactory.getSharingTicketService().getTicket(resource.getToken());
   try {
     if (ticket != null && ticket instanceof NodeTicket) {
       NodePK nodePk =
           new NodePK(String.valueOf(ticket.getSharedObjectId()), ticket.getComponentId());
       Collection<NodePK> autorizedNodes = getNodeDescendants(nodePk);
       autorizedNodes.add(nodePk);
       if (resource.getAccessedObject() instanceof AttachmentDetail) {
         AttachmentDetail attachment = (AttachmentDetail) resource.getAccessedObject();
         return isPublicationReadable(
             attachment.getForeignKey(), nodePk.getInstanceId(), autorizedNodes);
       }
       if (resource.getAccessedObject() instanceof SimpleDocument) {
         SimpleDocument attachment = (SimpleDocument) resource.getAccessedObject();
         return isPublicationReadable(
             new ForeignPK(attachment.getForeignId(), attachment.getInstanceId()),
             nodePk.getInstanceId(),
             autorizedNodes);
       }
       if (resource.getAccessedObject() instanceof Document) {
         Document document = (Document) resource.getAccessedObject();
         return isPublicationReadable(
             document.getForeignKey(), nodePk.getInstanceId(), autorizedNodes);
       }
       if (resource.getAccessedObject() instanceof NodeDetail) {
         NodeDetail node = (NodeDetail) resource.getAccessedObject();
         return autorizedNodes.contains(node.getNodePK());
       }
     }
   } catch (Exception ex) {
     return false;
   }
   return false;
 }
 public void exportCategory(
     QuestionReplyExport exporter, NodeDetail category, String categoryId, StringBuilder sb)
     throws QuestionReplyException, ParseException {
   // titre de la catégorie
   sb.append("<tr>\n");
   sb.append("<td class=\"titreCateg\" width=\"91%\">")
       .append(category.getName())
       .append("</td>\n");
   sb.append("</tr>\n");
   // contenu de la catégorie
   sb.append("<tr>\n");
   sb.append("<td colspan=\"2\">\n");
   Collection<Question> questions = getQuestionsByCategory(categoryId);
   for (Question question : questions) {
     exporter.exportQuestion(question, sb, this);
   }
   sb.append("</td>\n");
   sb.append("</tr>\n");
 }
  /**
   * 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;
              }
            }
          }
        }
      }
    }
  }
  /** Returns the access path of the object. */
  private String getPath(String componentId, String nodeId, String language) {
    String path = "";

    // Space > SubSpace
    if (componentId != null && !"useless".equals(componentId)) {
      List<SpaceInst> listSpaces = organizationController.getSpacePathToComponent(componentId);
      for (SpaceInst space : listSpaces) {
        path += space.getName(language) + " > ";
      }

      // Service
      path += organizationController.getComponentInstLight(componentId).getLabel(language);

      // Theme > SubTheme
      String pathString = "";
      if (nodeId != null) {
        NodeBm nodeBm = null;
        try {
          NodeBmHome nodeBmHome =
              EJBUtilitaire.getEJBObjectRef(JNDINames.NODEBM_EJBHOME, NodeBmHome.class);
          nodeBm = nodeBmHome.create();
        } catch (Exception e) {
          SilverTrace.error(
              "form", "ExplorerFieldDisplayer.display", "form.EX_CANT_CREATE_NODEBM_HOME", e);
        }

        if (nodeBm != null) {
          NodePK nodePk = new NodePK(nodeId, componentId);
          Collection<NodeDetail> listPath = null;
          try {
            listPath = nodeBm.getPath(nodePk);
          } catch (RemoteException e) {
            SilverTrace.error(
                "form", "ExplorerFieldDisplayer.display", "form.EX_CANT_GET_PATH_NODE", nodeId);
          }

          if (listPath != null) {
            Collections.reverse((List<NodeDetail>) listPath);
            String nodeName;
            for (NodeDetail nodeInPath : listPath) {
              if (!nodeInPath.getNodePK().getId().equals("0")) {
                if (language != null) {
                  nodeName = nodeInPath.getName(language);
                } else {
                  nodeName = nodeInPath.getName();
                }
                pathString += nodeName + " > ";
              }
            }

            if (StringUtil.isDefined(pathString)) {
              pathString = pathString.substring(0, pathString.length() - 3); // remove last '>'
            }
          }
        }
      }

      if (pathString.length() > 0) {
        path += " > " + pathString;
      }
    }

    return path;
  }