public static DocumentTranslationMap merge(List<DocumentTranslationMap> maps) { if (maps == null || maps.isEmpty()) { return null; } // take first one as reference DocumentTranslationMap ref = maps.get(0); if (ref!=null) { String oldRepo = ref.getOldServerName(); String newRepo = ref.getNewServerName(); DocumentTranslationMap finalMap = new DocumentTranslationMapImpl(oldRepo, newRepo); for (DocumentTranslationMap item : maps) { finalMap.putAll(item.getDocRefMap()); } return finalMap; } return null; }
@Override public DocumentTranslationMap run() throws IOException { if (reader == null) { throw new IllegalArgumentException("Pipe reader cannot be null"); } if (writer == null) { throw new IllegalArgumentException("Pipe writer cannot be null"); } List<DocumentTranslationMap> maps = new ArrayList<>(); readAndWriteDocs(maps); return DocumentTranslationMapImpl.merge(maps); }
@Override public DocumentTranslationMap write(Collection<ExportedDocument> docs) throws IOException { if (docs == null || docs.isEmpty()) { return null; } String newRepo = null; String oldRepo = null; Map<DocumentRef, DocumentRef> newRefs = new HashMap<DocumentRef, DocumentRef>(); for (ExportedDocument doc : docs) { DocumentTranslationMap newMap = write(doc); if (newMap != null) { newRefs.putAll(newMap.getDocRefMap()); // assume repo will be the same for all docs if (oldRepo == null) { oldRepo = newMap.getOldServerName(); } if (newRepo == null) { newRepo = newMap.getNewServerName(); } } } return new DocumentTranslationMapImpl(oldRepo, newRepo, newRefs); }
@Override public DocumentTranslationMap exportDocuments(OutputStream out, DocumentReader customDocReader, String format) { DocumentWriter writer = null; try { DocumentPipe pipe = new DocumentPipeImpl(10); // XXX check format before creating writer writer = new NuxeoArchiveWriter(out); pipe.setWriter(writer); pipe.setReader(customDocReader); List<DocumentTranslationMap> maps = new ArrayList<DocumentTranslationMap>(); DocumentTranslationMap map = pipe.run(); if (map != null) { maps.add(map); } return DocumentTranslationMapImpl.merge(maps); } catch (IOException e) { throw new NuxeoException(e); } finally { // reader will be closed by caller if (writer != null) { writer.close(); } } }
@Override public DocumentTranslationMap write(ExportedDocument[] docs) throws IOException { if (docs == null || docs.length == 0) { return null; } String newRepo = null; String oldRepo = null; Map<DocumentRef, DocumentRef> newRefs = new HashMap<DocumentRef, DocumentRef>(); for (ExportedDocument doc : docs) { DocumentTranslationMap newMap = write(doc); if (newMap != null) { newRefs.putAll(newMap.getDocRefMap()); // assume repo will be the same for all docs if (oldRepo == null) { oldRepo = newMap.getOldServerName(); } if (newRepo == null) { newRepo = newMap.getNewServerName(); } } } return new DocumentTranslationMapImpl(oldRepo, newRepo, newRefs); }
return DocumentTranslationMapImpl.merge(maps);
@Override public DocumentTranslationMap write(ExportedDocument doc) throws IOException { initWriter(); writer.write(doc.getDocument()); // out.write(doc.getDocument().asXML().getBytes()); // keep location unchanged DocumentLocation oldLoc = doc.getSourceLocation(); String oldServerName = oldLoc.getServerName(); DocumentRef oldDocRef = oldLoc.getDocRef(); DocumentTranslationMap map = new DocumentTranslationMapImpl(oldServerName, oldServerName); map.put(oldDocRef, oldDocRef); return map; }
@Override public DocumentTranslationMap write(ExportedDocument doc) throws IOException { OutputFormat format = AbstractDocumentWriter.createPrettyPrint(); XMLWriter writer = null; try { writer = new XMLWriter(out, format); writer.write(doc.getDocument()); } finally { if (writer != null) { writer.close(); } } // keep location unchanged DocumentLocation oldLoc = doc.getSourceLocation(); String oldServerName = oldLoc.getServerName(); DocumentRef oldDocRef = oldLoc.getDocRef(); DocumentTranslationMap map = new DocumentTranslationMapImpl(oldServerName, oldServerName); map.put(oldDocRef, oldDocRef); return map; }
@Override public DocumentTranslationMap write(ExportedDocument doc) throws IOException { String path = doc.getPath().toString(); writeDocument(path, doc); // keep location unchanged DocumentLocation oldLoc = doc.getSourceLocation(); String oldServerName = oldLoc.getServerName(); DocumentRef oldDocRef = oldLoc.getDocRef(); DocumentTranslationMap map = new DocumentTranslationMapImpl(oldServerName, oldServerName); map.put(oldDocRef, oldDocRef); return map; }
try (CloseableCoreSession session = CoreInstance.openCoreSession(repo)) { for (DocumentRef source : sources) { DocumentTranslationMap map = new DocumentTranslationMapImpl(repo, repo); DocumentModel sourceDoc = session.getDocument(source); DocumentModel destDoc = session.copy(source, targetLocation.getDocRef(), null);
@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; } DocumentModel doc = null; String id = xdoc.getId(); try { doc = session.getDocument(new IdRef(id)); } catch (DocumentNotFoundException e) { log.error("Cannot update document. No such document: " + id); return null; } doc = updateDocument(xdoc, doc); DocumentLocation source = xdoc.getSourceLocation(); DocumentTranslationMap map = new DocumentTranslationMapImpl(source.getServerName(), doc.getRepositoryName()); map.put(source.getDocRef(), doc.getRef()); return map; }
@Override public DocumentTranslationMap write(ExportedDocument xdoc) throws IOException { Path path = xdoc.getPath(); if (path.isEmpty() || path.isRoot()) { return null; // TODO avoid to import the root } path = root.append(path); // compute target path DocumentModel doc = createDocument(xdoc, path); DocumentLocation source = xdoc.getSourceLocation(); DocumentTranslationMap map = new DocumentTranslationMapImpl(source.getServerName(), doc.getRepositoryName()); map.put(source.getDocRef(), doc.getRef()); return map; }
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; }