@Test public void testAutoCheckOut() throws Exception { DocumentModel doc = new DocumentModelImpl("/", "file", "File"); doc.setPropertyValue("dc:title", "t0"); doc = session.createDocument(doc); assertTrue(doc.isCheckedOut()); session.checkIn(doc.getRef(), null, null); doc.refresh(); assertFalse(doc.isCheckedOut()); // auto-checkout doc.setPropertyValue("dc:title", "t1"); doc = session.saveDocument(doc); assertTrue(doc.isCheckedOut()); session.checkIn(doc.getRef(), null, null); doc.refresh(); assertFalse(doc.isCheckedOut()); // disable auto-checkout doc.setPropertyValue("dc:title", "t2"); doc.putContextData(VersioningService.DISABLE_AUTO_CHECKOUT, Boolean.TRUE); doc = session.saveDocument(doc); assertFalse(doc.isCheckedOut()); assertEquals("t2", doc.getPropertyValue("dc:title")); // can still be checked out normally afterwards doc.checkOut(); assertTrue(doc.isCheckedOut()); assertEquals("t2", doc.getPropertyValue("dc:title")); }
@Test public void testCheckInCheckOut() throws Exception { DocumentModel doc = new DocumentModelImpl("/", "file#789", "File"); assertTrue(doc.isCheckedOut()); doc = session.createDocument(doc); assertTrue(session.isCheckedOut(doc.getRef())); assertTrue(doc.isCheckedOut()); session.save(); assertTrue(session.isCheckedOut(doc.getRef())); assertTrue(doc.isCheckedOut()); DocumentRef verRef = session.checkIn(doc.getRef(), null, null); DocumentModel ver = session.getDocument(verRef); assertTrue(ver.isVersion()); doc.refresh(); assertFalse(session.isCheckedOut(doc.getRef())); assertFalse(doc.isCheckedOut()); session.checkOut(doc.getRef()); assertTrue(session.isCheckedOut(doc.getRef())); // using DocumentModel API DocumentRef verRef2 = doc.checkIn(null, null); DocumentModel ver2 = session.getDocument(verRef2); assertTrue(ver2.isVersion()); assertFalse(doc.isCheckedOut()); doc.checkOut(); assertTrue(doc.isCheckedOut()); }
@Test public void testLiveProxyUpdate() throws Exception { DocumentModel section = session.createDocumentModel("/", "section", "Folder"); section = session.createDocument(section); DocumentModel doc = session.createDocumentModel("/", "file", "File"); doc = session.createDocument(doc); session.save(); // create a live proxy DocumentModel proxy = session.createProxy(doc.getRef(), section.getRef()); // --- change the doc, see changes on the proxy immediately without save --- // update doc.setPropertyValue("dc:title", "foo"); doc = session.saveDocument(doc); assertEquals("foo", doc.getPropertyValue("dc:title")); // visible immediately on the proxy proxy.refresh(); assertEquals("foo", proxy.getPropertyValue("dc:title")); // lifecycle change doc.followTransition("approve"); assertEquals("approved", doc.getCurrentLifeCycleState()); // visible immediately on the proxy proxy.refresh(); assertEquals("approved", proxy.getCurrentLifeCycleState()); // check in for version change doc.checkIn(VersioningOption.MINOR, null); assertFalse(doc.isCheckedOut()); assertEquals("0.1", doc.getVersionLabel()); // visible immediately on the proxy proxy.refresh(); assertFalse(proxy.isCheckedOut()); assertEquals("0.1", proxy.getVersionLabel()); // check out doc.checkOut(); assertTrue(doc.isCheckedOut()); assertEquals("0.1+", doc.getVersionLabel()); // visible immediately on the proxy proxy.refresh(); assertTrue(proxy.isCheckedOut()); assertEquals("0.1+", proxy.getVersionLabel()); // --- change the proxy, see changes on the doc immediately without save --- // update proxy.setPropertyValue("dc:title", "bar"); proxy = session.saveDocument(proxy); assertEquals("bar", proxy.getPropertyValue("dc:title")); // visible immediately on the doc, no save() needed doc.refresh(); assertEquals("bar", doc.getPropertyValue("dc:title")); // lifecycle change proxy.followTransition("backToProject"); assertEquals("project", proxy.getCurrentLifeCycleState()); // visible immediately on the doc doc.refresh(); assertEquals("project", doc.getCurrentLifeCycleState()); // check in for version change proxy.checkIn(VersioningOption.MINOR, null); assertFalse(proxy.isCheckedOut()); assertEquals("0.2", proxy.getVersionLabel()); // visible immediately on the doc doc.refresh(); assertFalse(doc.isCheckedOut()); assertEquals("0.2", doc.getVersionLabel()); // check out proxy.checkOut(); assertTrue(proxy.isCheckedOut()); assertEquals("0.2+", proxy.getVersionLabel()); // visible immediately on the doc doc.refresh(); assertTrue(doc.isCheckedOut()); assertEquals("0.2+", doc.getVersionLabel()); }
@Test public void testCmisProperties() throws Exception { /* * checked out doc (live; private working copy) */ DocumentModel doc = new DocumentModelImpl("/", "myfile", "File"); doc = session.createDocument(doc); assertTrue(doc.isCheckedOut()); // nuxeo prop, false only on live assertFalse(doc.isVersion()); assertFalse(doc.isProxy()); assertFalse(doc.hasFacet(FacetNames.IMMUTABLE)); assertFalse(doc.isImmutable()); String versionSeriesId = doc.getVersionSeriesId(); assertNotNull(versionSeriesId); // assertNotSame(versionSeriesId, doc.getId()); assertEquals("0.0", doc.getVersionLabel()); assertNull(doc.getCheckinComment()); assertFalse(doc.isMajorVersion()); assertFalse(doc.isLatestVersion()); assertFalse(doc.isLatestMajorVersion()); assertTrue(doc.isVersionSeriesCheckedOut()); assertEquals(doc.getId(), session.getWorkingCopy(doc.getRef()).getId()); /* * proxy to checked out doc (live proxy) */ DocumentModel proxy = session.createProxy(doc.getRef(), session.getRootDocument().getRef()); assertTrue(proxy.isCheckedOut()); // nuxeo prop, false only on live assertFalse(proxy.isVersion()); assertTrue(proxy.isProxy()); assertFalse(proxy.hasFacet(FacetNames.IMMUTABLE)); assertFalse(proxy.isImmutable()); assertEquals(versionSeriesId, proxy.getVersionSeriesId()); assertEquals("0.0", proxy.getVersionLabel()); assertNull(proxy.getCheckinComment()); assertFalse(proxy.isMajorVersion()); assertFalse(proxy.isLatestVersion()); assertFalse(proxy.isLatestMajorVersion()); assertTrue(proxy.isVersionSeriesCheckedOut()); assertTrue(doc.isVersionSeriesCheckedOut()); assertEquals(doc.getId(), session.getWorkingCopy(proxy.getRef()).getId()); /* * checked in doc */ DocumentRef verRef = doc.checkIn(VersioningOption.MINOR, "comment"); session.save(); DocumentModel ver = session.getDocument(verRef); proxy.refresh(); assertFalse(doc.isCheckedOut()); assertFalse(doc.isVersion()); assertFalse(doc.isProxy()); // assertTrue(doc.hasFacet(FacetNames.IMMUTABLE)); // debatable // assertTrue(doc.isImmutable()); // debatable assertEquals(versionSeriesId, doc.getVersionSeriesId()); assertEquals("0.1", doc.getVersionLabel()); assertNull(doc.getCheckinComment()); assertFalse(doc.isMajorVersion()); assertFalse(doc.isLatestVersion()); assertFalse(doc.isLatestMajorVersion()); assertFalse(doc.isVersionSeriesCheckedOut()); assertFalse(proxy.isVersionSeriesCheckedOut()); assertEquals(doc.getId(), session.getWorkingCopy(proxy.getRef()).getId()); // TODO proxy to checked in doc /* * version */ // assertFalse(ver.isCheckedOut()); // TODO assertTrue(ver.isVersion()); assertFalse(ver.isProxy()); assertTrue(ver.hasFacet(FacetNames.IMMUTABLE)); assertTrue(ver.isImmutable()); assertEquals(versionSeriesId, ver.getVersionSeriesId()); assertEquals("0.1", ver.getVersionLabel()); assertEquals("comment", ver.getCheckinComment()); assertFalse(ver.isMajorVersion()); assertTrue(ver.isLatestVersion()); assertFalse(ver.isLatestMajorVersion()); assertFalse(ver.isVersionSeriesCheckedOut()); assertEquals(doc.getId(), session.getWorkingCopy(ver.getRef()).getId()); /* * proxy to version */ proxy = session.createProxy(ver.getRef(), session.getRootDocument().getRef()); assertFalse(proxy.isCheckedOut()); assertFalse(proxy.isVersion()); assertTrue(proxy.isProxy()); assertTrue(proxy.hasFacet(FacetNames.IMMUTABLE)); assertTrue(proxy.isImmutable()); assertEquals(versionSeriesId, proxy.getVersionSeriesId()); assertEquals("0.1", proxy.getVersionLabel()); assertEquals("comment", proxy.getCheckinComment()); assertFalse(proxy.isMajorVersion()); assertTrue(proxy.isLatestVersion()); assertFalse(proxy.isLatestMajorVersion()); assertFalse(proxy.isVersionSeriesCheckedOut()); assertFalse(doc.isVersionSeriesCheckedOut()); assertFalse(ver.isVersionSeriesCheckedOut()); assertEquals(doc.getId(), session.getWorkingCopy(proxy.getRef()).getId()); /* * re-checked out doc */ doc.checkOut(); ver.refresh(); proxy.refresh(); assertTrue(doc.isCheckedOut()); assertFalse(doc.isVersion()); assertFalse(doc.isProxy()); assertFalse(doc.hasFacet(FacetNames.IMMUTABLE)); assertFalse(doc.isImmutable()); assertEquals(versionSeriesId, doc.getVersionSeriesId()); assertEquals("0.1+", doc.getVersionLabel()); assertNull(doc.getCheckinComment()); assertFalse(doc.isMajorVersion()); assertFalse(doc.isLatestVersion()); assertFalse(doc.isLatestMajorVersion()); assertTrue(doc.isVersionSeriesCheckedOut()); assertTrue(ver.isVersionSeriesCheckedOut()); assertTrue(proxy.isVersionSeriesCheckedOut()); assertEquals(doc.getId(), session.getWorkingCopy(doc.getRef()).getId()); /* * major checkin */ DocumentRef majRef = doc.checkIn(VersioningOption.MAJOR, "yo"); DocumentModel maj = session.getDocument(majRef); ver.refresh(); proxy.refresh(); assertTrue(maj.isMajorVersion()); assertTrue(maj.isLatestVersion()); assertTrue(maj.isLatestMajorVersion()); assertFalse(maj.isVersionSeriesCheckedOut()); assertEquals(doc.getId(), session.getWorkingCopy(maj.getRef()).getId()); // previous ver assertFalse(ver.isMajorVersion()); assertFalse(ver.isLatestVersion()); assertFalse(ver.isLatestMajorVersion()); assertFalse(ver.isVersionSeriesCheckedOut()); assertFalse(doc.isVersionSeriesCheckedOut()); assertFalse(proxy.isVersionSeriesCheckedOut()); assertEquals(doc.getId(), session.getWorkingCopy(ver.getRef()).getId()); }