Search in sources :

Example 1 with Version

use of org.suigeneris.jrcs.rcs.Version in project xwiki-platform by xwiki.

the class DeleteVersionsAction method action.

@Override
public boolean action(XWikiContext context) throws XWikiException {
    DeleteVersionsForm form = (DeleteVersionsForm) context.getForm();
    if (!form.isConfirmed() || !csrfTokenCheck(context)) {
        return true;
    }
    XWikiDocument doc = context.getDoc();
    String language = form.getLanguage();
    XWikiDocument tdoc = doc.getTranslatedDocument(language, context);
    XWikiDocumentArchive archive = tdoc.getDocumentArchive(context);
    // Get the versions
    Version[] versions = getVersionsFromForm(form, archive);
    Version v1 = versions[0];
    Version v2 = versions[1];
    if (v1 != null && v2 != null) {
        // Remove the versions
        archive.removeVersions(v1, v2, context);
        context.getWiki().getVersioningStore().saveXWikiDocArchive(archive, true, context);
        tdoc.setDocumentArchive(archive);
        // Is this the last remaining version? If so, then recycle the document.
        if (archive.getLatestVersion() == null) {
            // Wrap the work as a batch operation.
            BatchOperationExecutor batchOperationExecutor = Utils.getComponent(BatchOperationExecutor.class);
            batchOperationExecutor.execute(() -> {
                if (StringUtils.isEmpty(language) || language.equals(doc.getDefaultLanguage())) {
                    context.getWiki().deleteAllDocuments(doc, context);
                } else {
                    // Only delete the translation
                    context.getWiki().deleteDocument(tdoc, context);
                }
            });
        } else {
            // If we delete the most recent (current) version, then rollback to latest undeleted version.
            if (!tdoc.getRCSVersion().equals(archive.getLatestVersion())) {
                XWikiDocument newdoc = archive.loadDocument(archive.getLatestVersion(), context);
                // Reset the document reference, since the one taken from the archive might be wrong (old name from
                // before a rename)
                newdoc.setDocumentReference(tdoc.getDocumentReference());
                // Get rid of objects that don't exist in new version
                newdoc.addXObjectsToRemoveFromVersion(tdoc);
                // Make sure we don't create a new rev!
                newdoc.setMetaDataDirty(false);
                newdoc.setContentDirty(false);
                // Make sure the previous current document is seen as original document of
                // the new current document for comparisons
                newdoc.setOriginalDocument(tdoc.getOriginalDocument());
                // Update the database with what is now the current document
                context.getWiki().saveDocument(newdoc, newdoc.getComment(), context);
                context.setDoc(newdoc);
            }
        }
    }
    sendRedirect(context);
    return false;
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiDocumentArchive(com.xpn.xwiki.doc.XWikiDocumentArchive) Version(org.suigeneris.jrcs.rcs.Version) BatchOperationExecutor(org.xwiki.refactoring.batch.BatchOperationExecutor)

Example 2 with Version

use of org.suigeneris.jrcs.rcs.Version in project xwiki-platform by xwiki.

the class XWikiHibernateVersioningStore method getXWikiDocVersions.

@Override
public Version[] getXWikiDocVersions(XWikiDocument doc, XWikiContext context) throws XWikiException {
    try {
        XWikiDocumentArchive archive = getXWikiDocumentArchive(doc, context);
        if (archive == null) {
            return new Version[0];
        }
        Collection<XWikiRCSNodeInfo> nodes = archive.getNodes();
        Version[] versions = new Version[nodes.size()];
        Iterator<XWikiRCSNodeInfo> it = nodes.iterator();
        for (int i = 0; i < versions.length; i++) {
            XWikiRCSNodeInfo node = it.next();
            versions[versions.length - 1 - i] = node.getId().getVersion();
        }
        return versions;
    } catch (Exception e) {
        Object[] args = { doc.getFullName() };
        throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_READING_REVISIONS, "Exception while reading document {0} revisions", e, args);
    }
}
Also used : XWikiDocumentArchive(com.xpn.xwiki.doc.XWikiDocumentArchive) Version(org.suigeneris.jrcs.rcs.Version) XWikiRCSNodeInfo(com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo) XWikiException(com.xpn.xwiki.XWikiException) HibernateException(org.hibernate.HibernateException) XWikiException(com.xpn.xwiki.XWikiException)

Example 3 with Version

use of org.suigeneris.jrcs.rcs.Version in project xwiki-platform by xwiki.

the class XWikiHibernateVersioningStore method loadXWikiDoc.

@Override
public XWikiDocument loadXWikiDoc(XWikiDocument basedoc, String sversion, XWikiContext inputxcontext) throws XWikiException {
    XWikiContext context = getExecutionXContext(inputxcontext, true);
    try {
        XWikiDocumentArchive archive = getXWikiDocumentArchive(basedoc, context);
        Version version = new Version(sversion);
        XWikiDocument doc = archive.loadDocument(version, context);
        if (doc == null) {
            Object[] args = { basedoc.getDocumentReferenceWithLocale(), version.toString() };
            throw new XWikiException(XWikiException.MODULE_XWIKI_STORE, XWikiException.ERROR_XWIKI_STORE_HIBERNATE_UNEXISTANT_VERSION, "Version {1} does not exist while reading document {0}", null, args);
        }
        // Make sure the document has the same name
        // as the new document (in case there was a name change
        // FIXME: is this really needed ?
        doc.setDocumentReference(basedoc.getDocumentReference());
        doc.setStore(basedoc.getStore());
        return doc;
    } finally {
        restoreExecutionXContext();
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XWikiDocumentArchive(com.xpn.xwiki.doc.XWikiDocumentArchive) Version(org.suigeneris.jrcs.rcs.Version) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException)

Example 4 with Version

use of org.suigeneris.jrcs.rcs.Version in project xwiki-platform by xwiki.

the class XWikiDocument method getLastChanges.

public List<Delta> getLastChanges(XWikiContext context) throws XWikiException, DifferentiationFailedException {
    Version version = getRCSVersion();
    try {
        String prev = getDocumentArchive(context).getPrevVersion(version).toString();
        XWikiDocument prevDoc = context.getWiki().getDocument(this, prev, context);
        return getDeltas(Diff.diff(ToString.stringToArray(prevDoc.getContent()), ToString.stringToArray(getContent())));
    } catch (Exception ex) {
        LOGGER.debug("Exception getting differences from previous version: " + ex.getMessage());
    }
    return new ArrayList<Delta>();
}
Also used : Version(org.suigeneris.jrcs.rcs.Version) ArrayList(java.util.ArrayList) ToString(org.suigeneris.jrcs.util.ToString) XWikiException(com.xpn.xwiki.XWikiException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) DifferentiationFailedException(org.suigeneris.jrcs.diff.DifferentiationFailedException) ExecutionContextException(org.xwiki.context.ExecutionContextException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException) MissingParserException(org.xwiki.rendering.parser.MissingParserException) IOException(java.io.IOException) ParseException(org.xwiki.rendering.parser.ParseException) TransformationException(org.xwiki.rendering.transformation.TransformationException) QueryException(org.xwiki.query.QueryException)

Example 5 with Version

use of org.suigeneris.jrcs.rcs.Version in project xwiki-platform by xwiki.

the class XWikiDocument method getRevisions.

/**
 * Get document versions matching criterias like author, minimum creation date, etc.
 *
 * @param criteria criteria used to match versions
 * @return a list of matching versions
 */
public List<String> getRevisions(RevisionCriteria criteria, XWikiContext context) throws XWikiException {
    List<String> results = new ArrayList<String>();
    Version[] revisions = getRevisions(context);
    XWikiRCSNodeInfo nextNodeinfo = null;
    XWikiRCSNodeInfo nodeinfo;
    for (Version revision : revisions) {
        nodeinfo = nextNodeinfo;
        nextNodeinfo = getRevisionInfo(revision.toString(), context);
        if (nodeinfo == null) {
            continue;
        }
        // Minor/Major version matching
        if (criteria.getIncludeMinorVersions() || !nextNodeinfo.isMinorEdit()) {
            // Author matching
            if (criteria.getAuthor().equals("") || criteria.getAuthor().equals(nodeinfo.getAuthor())) {
                // Date range matching
                Date versionDate = nodeinfo.getDate();
                if (versionDate.after(criteria.getMinDate()) && versionDate.before(criteria.getMaxDate())) {
                    results.add(nodeinfo.getVersion().toString());
                }
            }
        }
    }
    nodeinfo = nextNodeinfo;
    if (nodeinfo != null) {
        if (criteria.getAuthor().equals("") || criteria.getAuthor().equals(nodeinfo.getAuthor())) {
            // Date range matching
            Date versionDate = nodeinfo.getDate();
            if (versionDate.after(criteria.getMinDate()) && versionDate.before(criteria.getMaxDate())) {
                results.add(nodeinfo.getVersion().toString());
            }
        }
    }
    return criteria.getRange().subList(results);
}
Also used : Version(org.suigeneris.jrcs.rcs.Version) XWikiRCSNodeInfo(com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo) ArrayList(java.util.ArrayList) ToString(org.suigeneris.jrcs.util.ToString) Date(java.util.Date)

Aggregations

Version (org.suigeneris.jrcs.rcs.Version)24 XWikiException (com.xpn.xwiki.XWikiException)7 ToString (org.suigeneris.jrcs.util.ToString)6 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)5 ArrayList (java.util.ArrayList)5 DocumentReference (org.xwiki.model.reference.DocumentReference)5 XWikiRCSNodeInfo (com.xpn.xwiki.doc.rcs.XWikiRCSNodeInfo)4 Date (java.util.Date)4 Archive (org.suigeneris.jrcs.rcs.Archive)4 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)3 XWikiDocumentArchive (com.xpn.xwiki.doc.XWikiDocumentArchive)3 XWikiRCSNodeContent (com.xpn.xwiki.doc.rcs.XWikiRCSNodeContent)3 XWikiContext (com.xpn.xwiki.XWikiContext)2 Test (org.junit.Test)2 Document (com.xpn.xwiki.api.Document)1 XWikiAttachmentArchive (com.xpn.xwiki.doc.XWikiAttachmentArchive)1 XWikiRCSNodeId (com.xpn.xwiki.doc.rcs.XWikiRCSNodeId)1 IOException (java.io.IOException)1 URL (java.net.URL)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1