Search in sources :

Example 1 with LocalDocumentReference

use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.

the class XarExtensionPlan method getNextXarExtension.

public LocalExtension getNextXarExtension(DocumentReference documentReference) {
    WikiReference wikiReference = documentReference.getWikiReference();
    LocalDocumentReference localDocumentReference = new LocalDocumentReference(documentReference);
    return getNextXarExtension(wikiReference.getName(), localDocumentReference);
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) WikiReference(org.xwiki.model.reference.WikiReference)

Example 2 with LocalDocumentReference

use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.

the class XarExtensionPlan method getPreviousXarExtension.

public XarInstalledExtension getPreviousXarExtension(DocumentReference documentReference) {
    String wiki = documentReference.getWikiReference().getName();
    LocalDocumentReference localDocumentReference = new LocalDocumentReference(documentReference);
    return getPreviousXarExtension(wiki, localDocumentReference);
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference)

Example 3 with LocalDocumentReference

use of org.xwiki.model.reference.LocalDocumentReference 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 4 with LocalDocumentReference

use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.

the class DefaultModelBridgeTest method testCheckXObjectPresenceWithPresentXObject.

@Test
public void testCheckXObjectPresenceWithPresentXObject() throws Exception {
    XWikiDocument document = mock(XWikiDocument.class);
    List<String> xObjectTypes = Arrays.asList("type1");
    DocumentReference documentReferenceFromDocumentXObjects = mock(DocumentReference.class);
    Map<DocumentReference, List<BaseObject>> documentXObjects = new HashMap<DocumentReference, List<BaseObject>>() {

        {
            put(documentReferenceFromDocumentXObjects, Collections.EMPTY_LIST);
        }
    };
    DocumentReference resolvedType1 = mock(DocumentReference.class);
    LocalDocumentReference localDocumentReferenceType1 = mock(LocalDocumentReference.class);
    when(resolvedType1.getLocalDocumentReference()).thenReturn(localDocumentReferenceType1);
    when(this.documentReferenceResolver.resolve(eq("type1"))).thenReturn(resolvedType1);
    when(document.getXObjects()).thenReturn(documentXObjects);
    when(documentReferenceFromDocumentXObjects.getLocalDocumentReference()).thenReturn(localDocumentReferenceType1);
    assertTrue(this.mocker.getComponentUnderTest().checkXObjectPresence(xObjectTypes, document));
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) HashMap(java.util.HashMap) List(java.util.List) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) BaseObject(com.xpn.xwiki.objects.BaseObject) Test(org.junit.Test)

Example 5 with LocalDocumentReference

use of org.xwiki.model.reference.LocalDocumentReference in project xwiki-platform by xwiki.

the class SendMailConfigClassDocumentConfigurationSourceTest method getPropertyWhenNoSendMailConfigClassXObject.

@Test
public void getPropertyWhenNoSendMailConfigClassXObject() throws Exception {
    Cache<Object> cache = mock(Cache.class);
    CacheManager cacheManager = this.mocker.getInstance(CacheManager.class);
    when(cacheManager.createNewCache(any(CacheConfiguration.class))).thenReturn(cache);
    WikiDescriptorManager wikiDescriptorManager = this.mocker.getInstance(WikiDescriptorManager.class);
    when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("wiki");
    LocalDocumentReference classReference = new LocalDocumentReference("Mail", "SendMailConfigClass");
    XWikiDocument document = mock(XWikiDocument.class);
    when(document.getXObject(classReference)).thenReturn(null);
    DocumentReference documentReference = new DocumentReference("wiki", "Mail", "MailConfig");
    XWiki xwiki = mock(XWiki.class);
    when(xwiki.getDocument(eq(documentReference), any(XWikiContext.class))).thenReturn(document);
    XWikiContext xcontext = mock(XWikiContext.class);
    when(xcontext.getWiki()).thenReturn(xwiki);
    Provider<XWikiContext> xcontextProvider = this.mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
    when(xcontextProvider.get()).thenReturn(xcontext);
    assertEquals("defaultValue", this.mocker.getComponentUnderTest().getProperty("key", "defaultValue"));
}
Also used : LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) XWikiDocument(com.xpn.xwiki.doc.XWikiDocument) WikiDescriptorManager(org.xwiki.wiki.descriptor.WikiDescriptorManager) CacheManager(org.xwiki.cache.CacheManager) XWiki(com.xpn.xwiki.XWiki) XWikiContext(com.xpn.xwiki.XWikiContext) BaseObject(com.xpn.xwiki.objects.BaseObject) CacheConfiguration(org.xwiki.cache.config.CacheConfiguration) DocumentReference(org.xwiki.model.reference.DocumentReference) LocalDocumentReference(org.xwiki.model.reference.LocalDocumentReference) Test(org.junit.Test)

Aggregations

LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)58 Test (org.junit.Test)28 DocumentReference (org.xwiki.model.reference.DocumentReference)25 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)23 BaseObject (com.xpn.xwiki.objects.BaseObject)19 XWikiContext (com.xpn.xwiki.XWikiContext)10 EntityReference (org.xwiki.model.reference.EntityReference)10 ArrayList (java.util.ArrayList)8 ViewPage (org.xwiki.test.ui.po.ViewPage)6 Page (org.xwiki.rest.model.jaxb.Page)5 DocumentCreatedEvent (org.xwiki.bridge.event.DocumentCreatedEvent)4 DocumentDeletedEvent (org.xwiki.bridge.event.DocumentDeletedEvent)4 DocumentUpdatedEvent (org.xwiki.bridge.event.DocumentUpdatedEvent)4 Event (org.xwiki.observation.event.Event)4 XWiki (com.xpn.xwiki.XWiki)3 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)2 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)2 Principal (java.security.Principal)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2