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);
}
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();
}
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"));
}
Aggregations