use of org.xwiki.extension.xar.question.ConflictQuestion.GlobalAction in project xwiki-platform by xwiki.
the class DocumentMergeImporter method askDocumentToSave.
private XWikiDocument askDocumentToSave(XWikiDocument currentDocument, XWikiDocument previousDocument, XWikiDocument nextDocument, XWikiDocument mergedDocument, PackageConfiguration configuration, MergeResult documentMergeResult) {
// Indicate future author to whoever is going to answer the question
if (currentDocument != null) {
nextDocument.setCreatorReference(currentDocument.getCreatorReference());
}
if (mergedDocument != null) {
mergedDocument.setCreatorReference(currentDocument.getCreatorReference());
}
DocumentReference userReference = configuration != null ? configuration.getUserReference() : null;
if (userReference != null) {
nextDocument.setAuthorReference(userReference);
nextDocument.setContentAuthorReference(userReference);
for (XWikiAttachment attachment : nextDocument.getAttachmentList()) {
attachment.setAuthorReference(nextDocument.getAuthorReference());
}
if (mergedDocument != null) {
mergedDocument.setAuthorReference(userReference);
mergedDocument.setContentAuthorReference(userReference);
for (XWikiAttachment attachment : mergedDocument.getAttachmentList()) {
if (attachment.isContentDirty()) {
attachment.setAuthorReference(mergedDocument.getAuthorReference());
}
}
}
}
// Calculate the conflict type
ConflictQuestion.ConflictType type;
if (previousDocument == null) {
type = ConflictQuestion.ConflictType.CURRENT_EXIST;
} else if (currentDocument == null) {
type = ConflictQuestion.ConflictType.CURRENT_DELETED;
} else if (documentMergeResult != null) {
if (!documentMergeResult.getLog().getLogs(LogLevel.ERROR).isEmpty()) {
type = ConflictQuestion.ConflictType.MERGE_FAILURE;
} else {
type = ConflictQuestion.ConflictType.MERGE_SUCCESS;
}
} else {
type = null;
}
// Create a question
ConflictQuestion question = new ConflictQuestion(currentDocument, previousDocument, nextDocument, mergedDocument, type);
// Find the answer
GlobalAction contextAction = getMergeConflictAnswer(question.getType(), configuration);
if (contextAction != null && contextAction != GlobalAction.ASK) {
question.setGlobalAction(contextAction);
} else if (configuration != null && configuration.getJobStatus() != null && configuration.isInteractive()) {
try {
// Ask what to do
configuration.getJobStatus().ask(question);
if (question.isAlways()) {
setMergeConflictAnswer(question.getType(), question.getGlobalAction());
}
} catch (InterruptedException e) {
// TODO: log something ?
}
}
// Find the XWikiDocument to save
XWikiDocument documentToSave;
switch(question.getGlobalAction()) {
case CURRENT:
documentToSave = currentDocument;
break;
case NEXT:
documentToSave = nextDocument;
break;
case PREVIOUS:
documentToSave = previousDocument;
break;
case CUSTOM:
documentToSave = question.getCustomDocument() != null ? question.getCustomDocument() : mergedDocument;
break;
default:
documentToSave = mergedDocument;
break;
}
return documentToSave;
}
Aggregations