Search in sources :

Example 1 with DocumentVersionReference

use of org.xwiki.extension.xar.job.diff.DocumentVersionReference in project xwiki-platform by xwiki.

the class DiffXarJob method diff.

private void diff(XWikiDocument document, ExtensionId extensionId) {
    if (getRequest().isVerbose()) {
        this.logger.info("Computing differences for document [{}]", document.getDocumentReferenceWithLocale());
    }
    // Use the extension id as the document version.
    XWikiDocument previousDocument = document.duplicate(new DocumentVersionReference(document.getDocumentReference(), extensionId));
    XWikiContext xcontext = this.xcontextProvider.get();
    try {
        XWikiDocument nextDocument = xcontext.getWiki().getDocument(document.getDocumentReferenceWithLocale(), xcontext);
        if (nextDocument.isNew()) {
            nextDocument = null;
        }
        maybeAddDocumentDiff(this.documentDiffBuilder.diff(previousDocument, nextDocument));
    } catch (XWikiException e) {
        this.logger.error("Failed to get document [{}] from the database.", document.getDocumentReference(), e);
    }
}
Also used : XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) DocumentVersionReference(org.xwiki.extension.xar.job.diff.DocumentVersionReference) XWikiContext(com.xpn.xwiki.XWikiContext) XWikiException(com.xpn.xwiki.XWikiException)

Example 2 with DocumentVersionReference

use of org.xwiki.extension.xar.job.diff.DocumentVersionReference in project xwiki-platform by xwiki.

the class XarInstalledExtensionRepository method getXarInstalledExtensions.

/**
 * @param reference the reference of the document
 * @return the extension owners of the passed document
 * @since 8.1M2
 */
public Collection<XarInstalledExtension> getXarInstalledExtensions(DocumentReference reference) {
    if (reference instanceof DocumentVersionReference) {
        DocumentVersionReference versionReference = (DocumentVersionReference) reference;
        if (versionReference.getVersion() instanceof ExtensionId) {
            ExtensionId extensionId = (ExtensionId) versionReference.getVersion();
            if (extensionId != null) {
                return Arrays.asList((XarInstalledExtension) getInstalledExtension(extensionId));
            }
        }
    }
    Collection<XarInstalledExtension> wikiExtensions = this.documents.get(reference.getLocale() == null ? new DocumentReference(reference, Locale.ROOT) : reference);
    Collection<XarInstalledExtension> rootExtensions = this.rootDocuments.get(reference.getLocalDocumentReference().getLocale() == null ? new LocalDocumentReference(reference.getLocalDocumentReference(), Locale.ROOT) : reference.getLocalDocumentReference());
    List<XarInstalledExtension> allExtensions = new ArrayList<>();
    if (wikiExtensions != null) {
        allExtensions.addAll(wikiExtensions);
    }
    if (rootExtensions != null) {
        allExtensions.addAll(rootExtensions);
    }
    return allExtensions;
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentVersionReference(org.xwiki.extension.xar.job.diff.DocumentVersionReference) ArrayList(java.util.ArrayList) ExtensionId(org.xwiki.extension.ExtensionId) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) DocumentReference(org.xwiki.model.reference.DocumentReference)

Aggregations

DocumentVersionReference (org.xwiki.extension.xar.job.diff.DocumentVersionReference)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiException (com.xpn.xwiki.XWikiException)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 ArrayList (java.util.ArrayList)1 ExtensionId (org.xwiki.extension.ExtensionId)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)1