changeset: 1052:84f2a992c880 branch: 1.4.3.1-sql-nofulltext parent: 1019:70f4825f0509 user: Benjamin JALON date: Mon Mar 23 18:00:13 2009 +0100 summary: NXP-3302 : Add in history tab versions that have been published diff -r 70f4825f0509 -r 84f2a992c880 nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/VersionModel.java --- a/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/VersionModel.java Tue Mar 03 18:52:41 2009 +0100 +++ b/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/VersionModel.java Mon Mar 23 18:00:13 2009 +0100 @@ -43,4 +43,9 @@ void setLabel(String label); + Boolean getVersionPublished(); + + void setVersionPublished(Boolean value); + + } diff -r 70f4825f0509 -r 84f2a992c880 nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/facet/VersioningDocument.java --- a/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/facet/VersioningDocument.java Tue Mar 03 18:52:41 2009 +0100 +++ b/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/facet/VersioningDocument.java Mon Mar 23 18:00:13 2009 +0100 @@ -43,7 +43,7 @@ String CURRENT_DOCUMENT_MINOR_VERSION_KEY = "CURRENT_DOCUMENT_MINOR_VERSION"; String CURRENT_DOCUMENT_MAJOR_VERSION_KEY = "CURRENT_DOCUMENT_MAJOR_VERSION"; - + Long getMinorVersion() throws DocumentException; void setMinorVersion(Long value); @@ -52,6 +52,10 @@ void setMajorVersion(Long value); + Boolean isVersionHasBeenPublished() throws DocumentException; + + void setVersionHasBeenPublished(Boolean value); + /** * This will force the adapter to re-load document from repository. * Useful when versioning data is broken. diff -r 70f4825f0509 -r 84f2a992c880 nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/impl/VersionModelImpl.java --- a/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/impl/VersionModelImpl.java Tue Mar 03 18:52:41 2009 +0100 +++ b/nuxeo-core-api/src/main/java/org/nuxeo/ecm/core/api/impl/VersionModelImpl.java Mon Mar 23 18:00:13 2009 +0100 @@ -37,6 +37,8 @@ protected String label; protected String description; + + protected Boolean isVersionPublished; public Calendar getCreated() { return created; @@ -61,5 +63,15 @@ public void setLabel(String label) { this.label = label; } + + public Boolean getVersionPublished() { + return isVersionPublished; + } + + public void setVersionPublished(Boolean value) { + this.isVersionPublished = value; + } + + } diff -r 70f4825f0509 -r 84f2a992c880 nuxeo-core/src/main/java/org/nuxeo/ecm/core/api/AbstractSession.java --- a/nuxeo-core/src/main/java/org/nuxeo/ecm/core/api/AbstractSession.java Tue Mar 03 18:52:41 2009 +0100 +++ b/nuxeo-core/src/main/java/org/nuxeo/ecm/core/api/AbstractSession.java Mon Mar 23 18:00:13 2009 +0100 @@ -1649,13 +1649,41 @@ */ private DocumentModel createDocumentSnapshot(DocumentModel doc) throws ClientException { - if (!isDirty(doc.getRef())) { + return createDocumentSnapshot(doc, false); + } + + /** + * Creates a snapshot (version) for the given DocumentModel. + * + * @param docModel + * @return the last version (that was just created) + * @throws ClientException + */ + private DocumentModel createDocumentSnapshot(DocumentModel docModel, boolean isForPublication) + throws ClientException { + DocumentRef docRef = docModel.getRef(); + Document doc = null; + + // Set document to be checked-in as published + if (isForPublication) { + try { + doc = resolveReference(docModel.getRef()); + DocumentModel oldDoc = readModel(doc, null); + + oldDoc.setPropertyValue("uid:is_version_published", Boolean.TRUE); + writeModel(doc, oldDoc); + } catch (DocumentException e) { + throw new ClientException("Failed to check in document " + docRef, + e); + } + } + + if (!isDirty(docModel.getRef())) { log.debug("Document not dirty -> avoid creating a new version"); return null; } // Do a checkin / checkout of the edited version - DocumentRef docRef = doc.getRef(); VersionModel newVersion = new VersionModelImpl(); String vlabel = generateVersionLabelFor(docRef); newVersion.setLabel(vlabel); @@ -1666,20 +1694,37 @@ // save(); checkIn(docRef, newVersion); - log.debug("doc checked in " + doc.getTitle()); + log.debug("doc checked in " + docModel.getTitle()); checkOut(docRef); - log.debug("doc checked out " + doc.getTitle()); + log.debug("doc checked out " + docModel.getTitle()); // send notifications about new version // TODO we need to make it clearer the fact that this event is // about new version snapshot and not about versioning fields change // (i.e. major, minor version increment) + + // Set current document as un-published + if (isForPublication) { + try { + doc = resolveReference(docModel.getRef()); + DocumentModel oldDoc = readModel(doc, null); + + oldDoc.setPropertyValue("uid:is_version_published", Boolean.FALSE); + writeModel(doc, oldDoc); + } catch (DocumentException e) { + throw new ClientException("Failed to check in document " + docRef, + e); + } + } + + DocumentModel oldDoc = getDocumentWithVersion(docRef, newVersion); + // VersioningChangeNotifier.notifyVersionChange(oldDoc, doc); return oldDoc; } - + public void saveDocuments(DocumentModel[] docModels) throws ClientException { // TODO: optimize this - avoid calling at each iteration saveDoc... for (DocumentModel docModel : docModels) { @@ -2525,7 +2570,7 @@ docToPublish.putContextData( VersioningDocument.CREATE_SNAPSHOT_ON_SAVE_KEY, true); // snapshot the document - createDocumentSnapshot(docToPublish); + createDocumentSnapshot(docToPublish, true); VersionModel version = getLastVersion(docRef); DocumentModel newProxy = createProxy(sectionRef, docRef, version, overwriteExistingProxy); diff -r 70f4825f0509 -r 84f2a992c880 nuxeo-core/src/main/resources/schema/uid.xsd --- a/nuxeo-core/src/main/resources/schema/uid.xsd Tue Mar 03 18:52:41 2009 +0100 +++ b/nuxeo-core/src/main/resources/schema/uid.xsd Mon Mar 23 18:00:13 2009 +0100 @@ -7,6 +7,8 @@ + +