@Override public DocumentTranslationMap importDocuments(InputStream in, String repo, DocumentRef root) { DocumentReader reader = null; DocumentModelWriter writer = null; try (CloseableCoreSession coreSession = CoreInstance.openCoreSessionSystem(repo)) { final DocumentModel dst = coreSession.getDocument(root); reader = new NuxeoArchiveReader(in); writer = new DocumentModelWriter(coreSession, dst.getPathAsString()); DocumentPipe pipe = new DocumentPipeImpl(10); pipe.setReader(reader); pipe.setWriter(writer); DocumentTranslationMap map = pipe.run(); coreSession.save(); return map; } catch (IOException e) { throw new NuxeoException(e); } finally { if (reader != null) { reader.close(); } if (writer != null) { writer.close(); } } }
@Override protected DocumentModel createDocument(ExportedDocument xdoc, Path toPath) throws ClientException { String type = xdoc.getType(); boolean isTraining = Constants.CST_DOC_TYPE_TRAINING .equals(type); boolean isContact = Constants.CST_DOC_TYPE_CONTACT.equals(type); String oldUuid = StringUtils.EMPTY; if (isTraining || isContact) { oldUuid = xdoc.getId(); } DocumentModel createDocument = super.createDocument(xdoc, toPath); adaptACPs(createDocument); if (isTraining || isContact) { Map<String, Serializable> props = new HashMap<String, Serializable>( 1); props.put("oldUuid", oldUuid); ToutaticeNotifyEventHelper.notifyEvent(this.session, "storeReferences", createDocument, props); } return createDocument; }
@Override public DocumentTranslationMap write(ExportedDocument xdoc) throws IOException { if (xdoc.getDocument() == null) { // not a valid doc -> this may be a regular folder for example the // root of the tree return null; } Path path = xdoc.getPath(); // if (path.isEmpty() || path.isRoot()) { // return; // TODO avoid to import the root // } path = root.append(path); // compute target path return doWrite(xdoc, path); }
/** * To throw creation or update document exception. */ @Override public DocumentTranslationMap write(ExportedDocument xdoc) throws IOException { DocumentTranslationMap dtm = super.write(xdoc); Boolean compatibilityImport = Boolean.valueOf(Framework.getProperty("ottc.import.archive.compatibility", "true")); // Maybe error in creation or update if(dtm == null){ // (Re-) Check schema definition in case of creation try { Path xDocPath = xdoc.getPath(); Path parentPath = xDocPath.removeLastSegments(1); String name = xDocPath.lastSegment(); DocumentModel docModel = new DocumentModelImpl(parentPath.toString(), name, xdoc.getType()); super.loadSchemas(xdoc, docModel, xdoc.getDocument()); } catch (NuxeoException ce) { if(BooleanUtils.isNotTrue(compatibilityImport)){ if(log.isDebugEnabled()){ log.debug(ce.getMessage(), ce); } throw new IOException(ce.getMessage(), ce); } } } return dtm; }
@Override public void importSnapshot(CoreSession session, InputStream is) throws IOException { String importPath = persister.getDistributionRoot(session).getPathAsString(); DocumentReader reader = new NuxeoArchiveReader(is); DocumentWriter writer = new DocumentModelWriter(session, importPath); DocumentPipe pipe = new DocumentPipeImpl(10); pipe.setReader(reader); pipe.setWriter(writer); pipe.run(); reader.close(); writer.close(); }
private DocumentTranslationMap doWrite(ExportedDocument xdoc, Path targetPath) { DocumentModel previousDoc = null; PathRef pathRef = new PathRef(targetPath.toString()); if (session.exists(pathRef)) { previousDoc = session.getDocument(pathRef); } DocumentModel doc; if (previousDoc == null) { doc = createDocument(xdoc, targetPath); } else { doc = updateDocument(xdoc, previousDoc); } DocumentLocation source = xdoc.getSourceLocation(); DocumentTranslationMap map = new DocumentTranslationMapImpl(source.getServerName(), doc.getRepositoryName()); if (source.getDocRef() != null && source.getDocRef().reference() != null) { map.put(source.getDocRef(), doc.getRef()); } return map; }
@Override public void importDocumentation(CoreSession session, InputStream is) { try { String importPath = getDocumentationRoot(session).getPathAsString(); DocumentReader reader = new NuxeoArchiveReader(is); DocumentWriter writer = new DocumentModelWriter(session, importPath); DocumentPipe pipe = new DocumentPipeImpl(10); pipe.setReader(reader); pipe.setWriter(writer); DocumentTransformer rootCutter = new DocumentTransformer() { @Override public boolean transform(ExportedDocument doc) { doc.setPath(doc.getPath().removeFirstSegments(1)); return true; } }; pipe.addTransformer(rootCutter); pipe.run(); reader.close(); writer.close(); } catch (IOException | NuxeoException e) { log.error("Error while importing documentation", e); } }
DocumentWriter writer = new DocumentModelWriter(session, path, 10); reader.close(); reader = new ToutaticeNuxeoArchiveReader(tmp);
DocumentWriter writer = new DocumentModelWriter(session, parentPath, 10); reader.close(); reader = new NuxeoArchiveReader(source.getFile());
DocumentWriter writer = new DocumentModelWriter(session, parentPath, 10); reader.close(); reader = new NuxeoArchiveReader(source.getFile());