/** * @param session * @param document * @return true if working copy of document is different from last version. */ public static boolean isBeingModified(CoreSession session, DocumentModel document) { boolean is = false; String versionLabel = document.getVersionLabel(); DocumentModel lastDocumentVersion = session.getLastDocumentVersion(document.getRef()); if (lastDocumentVersion != null) { String lastDocumentVersionLabel = lastDocumentVersion.getVersionLabel(); is = !StringUtils.equals(versionLabel, lastDocumentVersionLabel); } return is; }
@OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel input) { IdRef idRef = new IdRef(input.getId()); return session.getLastDocumentVersion(idRef); }
/** * @return the document or the last version document in case of versioning handled */ @PUT @Consumes(MediaType.APPLICATION_JSON) public Response doPut(DocumentModel inputDoc, @Context HttpHeaders headers) { DocumentModelJsonReader.applyPropertyValues(inputDoc, doc); CoreSession session = ctx.getCoreSession(); versioningDocFromHeaderIfExists(headers); updateCommentFromHeader(headers); try { doc = session.saveDocument(doc); session.save(); } catch (ConcurrentUpdateException e) { return Response.status(Status.CONFLICT).entity("Invalid change token").build(); } DocumentModel returnedDoc = isVersioning ? session.getLastDocumentVersion(doc.getRef()) : doc; return Response.ok(returnedDoc).build(); }
@Override public DocumentDescriptor getCurrentVersion(@WebParam(name = "sessionId") String sid, @WebParam(name = "uuid") String uuid) { WSRemotingSession rs = initSession(sid); DocumentModel doc = rs.getDocumentManager().getLastDocumentVersion(new IdRef(uuid)); if (doc != null) { return new DocumentDescriptor(doc, doc.getVersionLabel()); } return null; }
@Path("last") public DocumentObject getLastVersion() { DocumentObject dobj = (DocumentObject) getTarget(); DocumentModel doc = dobj.getDocument(); DocumentModel v = dobj.getCoreSession().getLastDocumentVersion(doc.getRef()); if (v != null) { return dobj.newDocument(v); } throw new WebResourceNotFoundException( "No version found for " + ((DocumentObject) getTarget()).getDocument().getPath()); }
@OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentRef doc) { if (session.isCheckedOut(doc)) { DocumentRef ver = session.checkIn(doc, getVersioningOption(), comment); if (versionVarName != null) { ctx.put(versionVarName, ver); } } else { if (versionVarName != null) { ctx.put(versionVarName, session.getLastDocumentVersion(doc)); } } return session.getDocument(doc); }
@OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) throws Exception { if (!doc.hasFacet(FacetNames.VERSIONABLE)) { throw new NuxeoException(String.format( "The document (id:'%s') with title '%s' doesn't have 'versionable' facet", doc.getId(), doc.getTitle())); } // Create major version tagging it as explicit doc.putContextData(VersioningService.VERSIONING_OPTION, VersioningOption.MAJOR); doc.addFacet(ToutaticeNuxeoStudioConst.CST_FACET_EXPLICIT_VERSION); DocumentHelper.saveDocument(session, doc); doc.removeFacet(ToutaticeNuxeoStudioConst.CST_FACET_EXPLICIT_VERSION); return session.getLastDocumentVersion(doc.getRef()); }
@OperationMethod(collector = DocumentModelCollector.class) public DocumentModel run(DocumentModel doc) { if (doc.isCheckedOut()) { DocumentRef ver = session.checkIn(doc.getRef(), getVersioningOption(), comment); doc.refresh(DocumentModel.REFRESH_STATE, null); if (versionVarName != null) { ctx.put(versionVarName, ver); } } else { if (versionVarName != null) { ctx.put(versionVarName, session.getLastDocumentVersion(doc.getRef())); } } return doc; }