@Test public void testLifeCycleResetOnCopy() throws OperationException { DocumentModel source = session.createDocumentModel(ROOT, "Source", FILE); source = session.createDocument(source); String initialLifeCycleState = source.getCurrentLifeCycleState(); source.followTransition("approve"); source = session.getDocument(source.getRef()); Map<String, Serializable> params = Map.of(TARGET_PROPERTY_KEY, ROOT, NAME_PROPERTY_KEY, COPY_DOC_NAME); try (OperationContext context = new OperationContext(session)) { context.setInput(source); DocumentModel result = (DocumentModel) automationService.run(context, CopyDocument.ID, params); txFeature.nextTransaction(); result = session.getDocument(result.getRef()); assertEquals("approved", result.getCurrentLifeCycleState()); } params = Map.of(TARGET_PROPERTY_KEY, ROOT, NAME_PROPERTY_KEY, COPY_DOC_NAME, "resetLifeCycle", true); try (OperationContext context = new OperationContext(session)) { context.setInput(source); DocumentModel result = (DocumentModel) automationService.run(context, CopyDocument.ID, params); txFeature.nextTransaction(); result = session.getDocument(result.getRef()); assertEquals(initialLifeCycleState, result.getCurrentLifeCycleState()); } }
@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; }