@Test public void testCopyChildren() throws OperationException { DocumentModel folder = session.createDocumentModel(ROOT, "SourceFolder", "Folder"); folder = session.createDocument(folder); DocumentModel childDoc = session.createDocumentModel(folder.getPathAsString(), "childDoc", FILE); session.createDocument(childDoc); try (OperationContext context = new OperationContext(session)) { context.setInput(folder); Map<String, Serializable> params = Map.of(TARGET_PROPERTY_KEY, ROOT, NAME_PROPERTY_KEY, COPY_FOLDER_NAME); DocumentModel result = (DocumentModel) automationService.run(context, CopyDocument.ID, params); result = session.getDocument(result.getRef()); assertNotEquals(folder.getId(), result.getId()); assertEquals(COPY_FOLDER_NAME, result.getName()); DocumentModel childCopy = session.getChild(result.getRef(), childDoc.getName()); assertNotEquals(childDoc.getId(), childCopy.getId()); assertEquals(1, session.getChildren(result.getRef()).size()); } }
@OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) { String n = name; if (StringUtils.isEmpty(name)) { n = doc.getName(); } List<CopyOption> options = new ArrayList<>(); if (resetLifeCycle) { options.add(CopyOption.RESET_LIFE_CYCLE); } return session.copy(doc.getRef(), target, n, options.toArray(CopyOption[]::new)); }
CopyDocument { @OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) { String n = name; if (StringUtils.isEmpty(name)) { n = doc.getName(); } List<CopyOption> options = new ArrayList<>(); if (resetLifeCycle) { options.add(CopyOption.RESET_LIFE_CYCLE); } return session.copy(doc.getRef(), target, n, options.toArray(CopyOption[]::new)); } }
CopyDocument { @OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) { String n = name; if (StringUtils.isEmpty(name)) { n = doc.getName(); } List<CopyOption> options = new ArrayList<>(); if (resetLifeCycle) { options.add(CopyOption.RESET_LIFE_CYCLE); } return session.copy(doc.getRef(), target, n, options.toArray(CopyOption[]::new)); }  }
CopyDocument { @OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) { String n = name; if (StringUtils.isEmpty(name)) { n = doc.getName(); } List<CopyOption> options = new ArrayList<>(); if (resetLifeCycle) { options.add(CopyOption.RESET_LIFE_CYCLE); } return session.copy(doc.getRef(), target, n, options.toArray(CopyOption[]::new)); }  @OperationMethod(collector = DocumentModelCollector.class) DocumentModel run(DocumentModel doc); @OperationMethod(collector = DocumentModelCollector.class) DocumentModel run(DocumentRef ref); }
CopyDocument { @OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) { String n = name; if (StringUtils.isEmpty(name)) { n = doc.getName(); } List<CopyOption> options = new ArrayList<>(); if (resetLifeCycle) { options.add(CopyOption.RESET_LIFE_CYCLE); } return session.copy(doc.getRef(), target, n, options.toArray(CopyOption[]::new)); }  @OperationMethod(collector = DocumentModelCollector.class) DocumentModel run(DocumentModel doc); @OperationMethod(collector = DocumentModelCollector.class) DocumentModel run(DocumentRef ref); static final String ID; }