use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.
the class DefaultModelBridgeTest method testAuthorReference.
@Test
public void testAuthorReference() throws Exception {
XWikiContext context = mock(XWikiContext.class);
XWiki xwiki = mock(XWiki.class);
XWikiDocument document = mock(XWikiDocument.class);
DocumentReference authorReference = mock(DocumentReference.class);
EntityReference entityReference = mock(EntityReference.class);
when(this.contextProvider.get()).thenReturn(context);
when(context.getWiki()).thenReturn(xwiki);
when(xwiki.getDocument(entityReference, context)).thenReturn(document);
when(document.getAuthorReference()).thenReturn(authorReference);
DocumentReference result = this.mocker.getComponentUnderTest().getAuthorReference(entityReference);
assertEquals(authorReference, result);
}
use of org.xwiki.model.reference.DocumentReference 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));
}
use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.
the class UntypedRecordableEventDescriptorComponentBuilderTest method testBuildComponent.
@Test
public void testBuildComponent() throws Exception {
BaseObject baseObject = mock(BaseObject.class);
XWikiDocument parentDocument = mock(XWikiDocument.class);
DocumentReference documentReference = mock(DocumentReference.class);
when(baseObject.getOwnerDocument()).thenReturn(parentDocument);
when(parentDocument.getDocumentReference()).thenReturn(documentReference);
// Ensure that the user rights are correctly checked
when(this.authorizationManager.hasAccess(any(), any(), any())).thenReturn(true);
List<WikiComponent> result = this.mocker.getComponentUnderTest().buildComponents(baseObject);
assertEquals(1, result.size());
}
use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.
the class DistributionInternalScriptService method getModifiedDocumentsTree.
/**
* @return the document modified during the Distribution Wizard execution
* @since 5.4RC1
*/
public Map<String, Map<String, Map<String, Map<String, DocumentStatus>>>> getModifiedDocumentsTree() {
Map<DocumentReference, DocumentStatus> documents = ((DocumentsModifiedDuringDistributionListener) this.modifiedDocumentsListener).getDocuments().get(this.xcontextProvider.get().getWikiId());
Map<String, Map<String, Map<String, Map<String, DocumentStatus>>>> tree = new TreeMap<>();
if (documents != null) {
for (Map.Entry<DocumentReference, DocumentStatus> document : documents.entrySet()) {
DocumentReference reference = document.getKey();
String wiki = reference.getWikiReference().getName();
// TODO: add support for subspaces
String space = reference.getLastSpaceReference().getName();
String page = reference.getName();
String locale = reference.getLocale() != null ? reference.getLocale().toString() : "";
Map<String, Map<String, Map<String, DocumentStatus>>> spaces = tree.get(wiki);
if (spaces == null) {
spaces = new TreeMap<>();
tree.put(wiki, spaces);
}
Map<String, Map<String, DocumentStatus>> pages = spaces.get(space);
if (pages == null) {
pages = new TreeMap<>();
spaces.put(space, pages);
}
Map<String, DocumentStatus> locales = pages.get(page);
if (locales == null) {
locales = new TreeMap<>();
pages.put(page, locales);
}
locales.put(locale, document.getValue());
}
}
return tree;
}
use of org.xwiki.model.reference.DocumentReference in project xwiki-platform by xwiki.
the class DocumentsModifiedDuringDistributionListener method addDocument.
private void addDocument(String distributionWiki, XWikiDocument document, Action action, LocalExtension previousExtension, LocalExtension nextExtension) {
Map<DocumentReference, DocumentStatus> wikiDocuments = this.documents.get(distributionWiki);
if (wikiDocuments == null) {
wikiDocuments = new HashMap<DocumentReference, DocumentsModifiedDuringDistributionListener.DocumentStatus>();
this.documents.put(distributionWiki, wikiDocuments);
}
DocumentReference reference = document.getDocumentReferenceWithLocale();
DocumentStatus currentStatus = wikiDocuments.get(reference);
String previousVersion;
if (currentStatus != null) {
previousVersion = currentStatus.getPreviousVersion();
if (action == Action.CREATED) {
if (previousVersion != null) {
action = Action.MODIFIED;
}
} else if (action == Action.DELETED) {
if (previousVersion == null) {
// Back to square one
wikiDocuments.remove(reference);
return;
}
} else if (action == Action.MODIFIED) {
action = currentStatus.getAction();
}
} else {
if (action != Action.CREATED) {
previousVersion = document.getOriginalDocument().getVersion();
} else {
previousVersion = null;
}
}
wikiDocuments.put(reference, new DocumentStatus(reference, previousVersion, action, previousExtension, nextExtension));
}
Aggregations