Search in sources :

Example 1 with MergeConfiguration

use of com.xpn.xwiki.doc.merge.MergeConfiguration in project xwiki-platform by xwiki.

the class DocumentMergeImporter method merge.

private XarEntryMergeResult merge(String comment, XWikiDocument currentDocument, XWikiDocument previousDocument, XWikiDocument nextDocument, PackageConfiguration configuration) throws Exception {
    XWikiContext xcontext = this.xcontextProvider.get();
    // 3 ways merge
    XWikiDocument mergedDocument = currentDocument.clone();
    MergeConfiguration mergeConfiguration = new MergeConfiguration();
    mergeConfiguration.setProvidedVersionsModifiables(true);
    MergeResult documentMergeResult;
    try {
        documentMergeResult = mergedDocument.merge(previousDocument, nextDocument, mergeConfiguration, xcontext);
    } catch (Exception e) {
        // Unexpected error, lets behave as if there was a conflict
        documentMergeResult = new MergeResult();
        documentMergeResult.getLog().error("Unexpected exception thrown. Usually means there is a bug in the merge.", e);
        documentMergeResult.setModified(true);
    }
    documentMergeResult.getLog().log(this.logger);
    XWikiDocument documentToSave;
    if (documentMergeResult.isModified() || !documentMergeResult.getLog().getLogsFrom(LogLevel.ERROR).isEmpty()) {
        documentToSave = askDocumentToSave(currentDocument, previousDocument, nextDocument, mergedDocument, configuration, documentMergeResult);
        if (documentToSave != currentDocument) {
            saveDocument(documentToSave, comment, false, configuration);
        }
    }
    return new XarEntryMergeResult(new XarEntry(new LocalDocumentReference(mergedDocument.getDocumentReferenceWithLocale())), documentMergeResult);
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) XarEntry(org.xwiki.xar.XarEntry) MergeResult(com.xpn.xwiki.doc.merge.MergeResult) XWikiContext(com.xpn.xwiki.XWikiContext) MergeConfiguration(com.xpn.xwiki.doc.merge.MergeConfiguration)

Example 2 with MergeConfiguration

use of com.xpn.xwiki.doc.merge.MergeConfiguration in project xwiki-platform by xwiki.

the class XWikiDocumentMergeTest method before.

@Before
public void before() throws Exception {
    this.oldcore.registerMockEnvironment();
    this.currentDocument = new XWikiDocument(new DocumentReference("wiki", "space", "page"));
    this.previousDocument = this.currentDocument.clone();
    this.nextDocument = this.currentDocument.clone();
    this.xclass = new BaseClass();
    this.xclass.setDocumentReference(new DocumentReference("wiki", "classspace", "class"));
    this.xclass.addTextField("string", "String", 30);
    this.xclass.addTextAreaField("area", "Area", 10, 10);
    this.xclass.addTextAreaField("puretextarea", "Pure text area", 10, 10);
    // set the text areas an non interpreted content
    ((TextAreaClass) this.xclass.getField("puretextarea")).setContentType("puretext");
    this.xclass.addPasswordField("passwd", "Password", 30);
    this.xclass.addBooleanField("boolean", "Boolean", "yesno");
    this.xclass.addNumberField("int", "Int", 10, "integer");
    this.xclass.addStaticListField("stringlist", "StringList", "value1, value2");
    this.xobject = new BaseObject();
    this.xobject.setXClassReference(this.xclass.getDocumentReference());
    this.xobject.setStringValue("string", "string");
    this.xobject.setLargeStringValue("area", "area");
    this.xobject.setStringValue("passwd", "passwd");
    this.xobject.setIntValue("boolean", 1);
    this.xobject.setIntValue("int", 42);
    this.xobject.setStringListValue("stringlist", Arrays.asList("VALUE1", "VALUE2"));
    this.configuration = new MergeConfiguration();
}
Also used : BaseClass(com.xpn.xwiki.objects.classes.BaseClass) MergeConfiguration(com.xpn.xwiki.doc.merge.MergeConfiguration) TextAreaClass(com.xpn.xwiki.objects.classes.TextAreaClass) DocumentReference(org.xwiki.model.reference.DocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Before(org.junit.Before)

Example 3 with MergeConfiguration

use of com.xpn.xwiki.doc.merge.MergeConfiguration in project xwiki-platform by xwiki.

the class BaseObjectTest method testMerge.

@Test
public void testMerge() {
    BaseObject previousObject = new BaseObject();
    previousObject.setStringValue("str", "value");
    BaseObject nextObject = new BaseObject();
    nextObject.setStringValue("str", "newvalue");
    BaseObject currentObject = new BaseObject();
    currentObject.setStringValue("str", "value");
    MergeConfiguration mergeConfiguration = new MergeConfiguration();
    MergeResult mergeResult = new MergeResult();
    currentObject.merge(previousObject, nextObject, mergeConfiguration, this.oldcore.getXWikiContext(), mergeResult);
    List<LogEvent> errors = mergeResult.getLog().getLogsFrom(LogLevel.WARN);
    if (errors.size() > 0) {
        Assert.fail("Found error or warning during the merge (" + errors.get(0) + ")");
    }
    Assert.assertEquals("newvalue", currentObject.getStringValue("str"));
}
Also used : LogEvent(org.xwiki.logging.event.LogEvent) MergeResult(com.xpn.xwiki.doc.merge.MergeResult) MergeConfiguration(com.xpn.xwiki.doc.merge.MergeConfiguration) Test(org.junit.Test)

Aggregations

MergeConfiguration (com.xpn.xwiki.doc.merge.MergeConfiguration)3 MergeResult (com.xpn.xwiki.doc.merge.MergeResult)2 XWikiContext (com.xpn.xwiki.XWikiContext)1 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)1 BaseObject (com.xpn.xwiki.objects.BaseObject)1 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)1 TextAreaClass (com.xpn.xwiki.objects.classes.TextAreaClass)1 Before (org.junit.Before)1 Test (org.junit.Test)1 LogEvent (org.xwiki.logging.event.LogEvent)1 DocumentReference (org.xwiki.model.reference.DocumentReference)1 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)1 XarEntry (org.xwiki.xar.XarEntry)1