/** * Méthode récursive appelée dans le cas de l'importation massive récursive sans création de * nouveau topic: toutes les publications crées le seront dans le thème passé en paramètre. * * @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, l'id passé est toujours le * même dans le cas présent * @throws ImportExportException */ public void processImportRecursiveNoReplicate( ImportReportManager reportManager, MassiveReport massiveReport, GEDImportExport gedIE, AttachmentImportExport attachmentIE, VersioningImportExport versioningIE, PdcImportExport pdcIE, ImportSettings settings) { Iterator<File> itListcontenuPath = getPathContent(new File(settings.getPathToImport())); while (itListcontenuPath.hasNext()) { File file = itListcontenuPath.next(); if (file.isFile()) { importFile(file, reportManager, massiveReport, gedIE, pdcIE, settings); } else if (file.isDirectory()) { // traitement récursif spécifique settings.setPathToImport(file.getAbsolutePath()); processImportRecursiveNoReplicate( reportManager, massiveReport, gedIE, attachmentIE, versioningIE, pdcIE, settings); } } }
/** * 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; }
/** * 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; } } } } } } }
private PublicationDetail importFile( File file, ImportReportManager reportManager, MassiveReport massiveReport, GEDImportExport gedIE, PdcImportExport pdcIE, ImportSettings settings) { SilverTrace.debug( "importExport", "RepositoriesTypeManager.importFile", "root.MSG_GEN_ENTER_METHOD", "file = " + file.getName()); String componentId = gedIE.getCurrentComponentId(); UserDetail userDetail = gedIE.getCurentUserDetail(); PublicationDetail pubDetailToCreate = null; try { // Création du rapport unitaire UnitReport unitReport = new UnitReport(); massiveReport.addUnitReport(unitReport); // Check the file size ResourceLocator uploadSettings = new ResourceLocator("org.silverpeas.util.uploads.uploadSettings", ""); long maximumFileSize = uploadSettings.getLong("MaximumFileSize", 10485760); long fileSize = file.length(); if (fileSize <= 0L) { unitReport.setError(UnitReport.ERROR_NOT_EXISTS_OR_INACCESSIBLE_FILE); reportManager.addNumberOfFilesNotImported(1); return pubDetailToCreate; } else if (fileSize > maximumFileSize) { unitReport.setError(UnitReport.ERROR_FILE_SIZE_EXCEEDS_LIMIT); reportManager.addNumberOfFilesNotImported(1); return pubDetailToCreate; } // On récupére les infos nécéssaires à la création de la publication pubDetailToCreate = PublicationImportExport.convertFileInfoToPublicationDetail(file, settings); pubDetailToCreate.setPk(new PublicationPK("unknown", "useless", componentId)); if ((settings.isDraftUsed() && pdcIE.isClassifyingMandatory(componentId)) || settings.isDraftUsed()) { pubDetailToCreate.setStatus(PublicationDetail.DRAFT); pubDetailToCreate.setStatusMustBeChecked(false); } SilverTrace.debug( "importExport", "RepositoriesTypeManager.importFile", "root.MSG_GEN_PARAM_VALUE", "pubDetailToCreate.status = " + pubDetailToCreate.getStatus()); // Création de la publication pubDetailToCreate = gedIE.createPublicationForMassiveImport(unitReport, pubDetailToCreate, settings); unitReport.setLabel(pubDetailToCreate.getPK().getId()); SilverTrace.debug( "importExport", "RepositoriesTypeManager.importFile", "root.MSG_GEN_PARAM_VALUE", "pubDetailToCreate created"); if (FileUtil.isMail(file.getName())) { // if imported file is an e-mail, its textual content is saved in a dedicated form // and attached files are attached to newly created publication processMailContent( pubDetailToCreate, file, reportManager, unitReport, gedIE, settings.isVersioningUsed()); } // add attachment SimpleDocument document; SimpleDocumentPK pk = new SimpleDocumentPK(null, componentId); if (settings.isVersioningUsed()) { document = new HistorisedDocument(); document.setPublicDocument( settings.getVersionType() == DocumentVersion.TYPE_PUBLIC_VERSION); } else { document = new SimpleDocument(); } document.setPK(pk); document.setFile(new SimpleAttachment()); document.setFilename(file.getName()); document.setSize(fileSize); document.getFile().setCreatedBy(userDetail.getId()); if (settings.useFileDates()) { document.setCreated(pubDetailToCreate.getCreationDate()); if (pubDetailToCreate.getUpdateDate() != null) { document.setUpdated(pubDetailToCreate.getUpdateDate()); } } else { document.setCreated(new Date()); } document.setForeignId(pubDetailToCreate.getPK().getId()); document.setContentType(FileUtil.getMimeType(file.getName())); AttachmentServiceFactory.getAttachmentService() .createAttachment(document, file, pubDetailToCreate.isIndexable(), false); reportManager.addNumberOfFilesProcessed(1); reportManager.addImportedFileSize(document.getSize(), componentId); } catch (Exception ex) { massiveReport.setError(UnitReport.ERROR_ERROR); SilverTrace.error( "importExport", "RepositoriesTypeManager.importFile", "root.EX_NO_MESSAGE", ex); } return pubDetailToCreate; }