Search in sources :

Example 26 with DocumentReference

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

the class DocumentsModifiedDuringDistributionListener method checkXARHandler.

private void checkXARHandler(Event event, XWikiDocument document, XWikiContext xcontext) {
    ExecutionContext context = this.execution.getContext();
    if (context != null) {
        XarExtensionPlan xarExtensionPlan = (XarExtensionPlan) context.getProperty(XarExtensionPlan.CONTEXTKEY_XARINSTALLPLAN);
        if (xarExtensionPlan != null) {
            Request request = this.jobContext.getCurrentJob().getRequest();
            // It's a job started by the Distribution Wizard
            if (StringUtils.equals(request.<String>getProperty("context.action"), "distribution")) {
                String distributionWiki = request.getProperty("context.wiki");
                if (distributionWiki != null) {
                    DocumentReference reference = document.getDocumentReferenceWithLocale();
                    DocumentStatus.Action action = toAction(event);
                    LocalExtension previousExtension = xarExtensionPlan.getPreviousXarExtension(reference);
                    LocalExtension nextExtension = xarExtensionPlan.getNextXarExtension(reference);
                    addDocument(distributionWiki, document, action, previousExtension, nextExtension);
                }
            }
        }
    }
}
Also used : ExecutionContext(org.xwiki.context.ExecutionContext) XarExtensionPlan(org.xwiki.extension.xar.internal.handler.XarExtensionPlan) Request(org.xwiki.job.Request) Action(org.xwiki.extension.distribution.internal.DocumentsModifiedDuringDistributionListener.DocumentStatus.Action) LocalExtension(org.xwiki.extension.LocalExtension) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 27 with DocumentReference

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

the class DocumentsDeletingListener method checkIfPageBelongToExtensions.

private void checkIfPageBelongToExtensions(EntitySelection entitySelection, ExtensionBreakingQuestion question) {
    XarInstalledExtensionRepository repository = (XarInstalledExtensionRepository) installedExtensionRepository;
    DocumentReference documentReference = (DocumentReference) entitySelection.getEntityReference();
    Collection<XarInstalledExtension> extensions = repository.getXarInstalledExtensions(documentReference);
    if (extensions.isEmpty()) {
        question.markAsFreePage(entitySelection);
        return;
    }
    for (XarInstalledExtension extension : extensions) {
        question.pageBelongsToExtension(entitySelection, extension);
    }
}
Also used : XarInstalledExtension(org.xwiki.extension.xar.internal.repository.XarInstalledExtension) XarInstalledExtensionRepository(org.xwiki.extension.xar.internal.repository.XarInstalledExtensionRepository) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 28 with DocumentReference

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

the class AbstractExtensionDistributionStep method install.

protected void install(ExtensionId extensionId, String namespace, boolean jarOnRoot) throws JobException, InterruptedException {
    // Install the default UI
    InstallRequest installRequest = new InstallRequest();
    installRequest.setId(ExtensionRequest.getJobId(ExtensionRequest.JOBID_ACTION_PREFIX, extensionId.getId(), namespace));
    installRequest.addExtension(extensionId);
    installRequest.addNamespace(namespace);
    // Indicate it's allowed to do modification on root namespace
    installRequest.setRootModificationsAllowed(true);
    // Make sure the job is no interactive
    installRequest.setInteractive(false);
    if (jarOnRoot) {
        // Make sure jars are installed on root
        // TODO: use a less script oriented class
        ScriptExtensionRewriter rewriter = new ScriptExtensionRewriter();
        rewriter.installExtensionTypeOnRootNamespace("jar");
        rewriter.installExtensionTypeOnRootNamespace("webjar");
        installRequest.setRewriter(rewriter);
    }
    // Set the author to use
    installRequest.setProperty(AbstractExtensionValidator.PROPERTY_USERREFERENCE, new DocumentReference("xwiki", "XWiki", XWikiRightService.SUPERADMIN_USER));
    installRequest.setExtensionProperty(AbstractExtensionValidator.PROPERTY_USERREFERENCE, XWikiRightService.SUPERADMIN_USER_FULLNAME);
    this.jobExecutor.execute(InstallJob.JOBTYPE, installRequest).join();
}
Also used : ScriptExtensionRewriter(org.xwiki.extension.script.ScriptExtensionRewriter) InstallRequest(org.xwiki.extension.job.InstallRequest) DocumentReference(org.xwiki.model.reference.DocumentReference)

Example 29 with DocumentReference

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

the class DocumentTreeNodeTest method pagination.

/**
 * @see "XWIKI-14643: Missing page in breadcrumbs treeview when treeview is expanded"
 */
@Test
public void pagination() throws Exception {
    TreeNode documentTreeNode = this.mocker.getComponentUnderTest();
    documentTreeNode.getProperties().put("hierarchyMode", "reference");
    documentTreeNode.getProperties().put("showTranslations", true);
    documentTreeNode.getProperties().put("showAttachments", true);
    documentTreeNode.getProperties().put("showClassProperties", true);
    documentTreeNode.getProperties().put("showObjects", true);
    documentTreeNode.getProperties().put("showAddDocument", true);
    when(this.authorization.hasAccess(Right.EDIT, documentReference.getParent())).thenReturn(true);
    when(this.translationsTreeNode.getChildCount("translations:wiki:Path.To.Page.WebHome")).thenReturn(1);
    when(this.attachmentsTreeNode.getChildCount("attachments:wiki:Path.To.Page.WebHome")).thenReturn(1);
    when(this.classPropertiesTreeNode.getChildCount("classProperties:wiki:Path.To.Page.WebHome")).thenReturn(1);
    when(this.objectsTreeNode.getChildCount("objects:wiki:Path.To.Page.WebHome")).thenReturn(1);
    assertEquals(Arrays.asList("translations:wiki:Path.To.Page.WebHome", "attachments:wiki:Path.To.Page.WebHome", "classProperties:wiki:Path.To.Page.WebHome"), documentTreeNode.getChildren("document:wiki:Path.To.Page.WebHome", 0, 3));
    verify(this.nestedPagesOrderedByName, never()).execute();
    DocumentReference alice = new DocumentReference("wiki", Arrays.asList("Path.To.Page"), "Alice");
    when(this.nestedPagesOrderedByName.execute()).thenReturn(Collections.singletonList(alice));
    when(this.defaultEntityReferenceSerializer.serialize(alice)).thenReturn("wiki:Path.To.Page.Alice");
    assertEquals(Arrays.asList("objects:wiki:Path.To.Page.WebHome", "addDocument:wiki:Path.To.Page.WebHome", "document:wiki:Path.To.Page.Alice"), documentTreeNode.getChildren("document:wiki:Path.To.Page.WebHome", 3, 3));
    verify(this.nestedPagesOrderedByName).setOffset(0);
    verify(this.nestedPagesOrderedByName).setLimit(1);
    DocumentReference bob = new DocumentReference("wiki", Arrays.asList("Path.To.Page"), "Bob");
    DocumentReference carol = new DocumentReference("wiki", Arrays.asList("Path.To.Page"), "Carol");
    when(this.nestedPagesOrderedByName.execute()).thenReturn(Arrays.asList(bob, carol));
    when(this.defaultEntityReferenceSerializer.serialize(bob)).thenReturn("wiki:Path.To.Page.Bob");
    when(this.defaultEntityReferenceSerializer.serialize(carol)).thenReturn("wiki:Path.To.Page.Carol");
    assertEquals(Arrays.asList("document:wiki:Path.To.Page.Bob", "document:wiki:Path.To.Page.Carol"), documentTreeNode.getChildren("document:wiki:Path.To.Page.WebHome", 6, 3));
    verify(this.nestedPagesOrderedByName).setOffset(1);
    verify(this.nestedPagesOrderedByName).setLimit(3);
}
Also used : TreeNode(org.xwiki.tree.TreeNode) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 30 with DocumentReference

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

the class DocumentTreeNode method getChildDocuments.

@Override
protected List<DocumentReference> getChildDocuments(DocumentReference documentReference, int offset, int limit) throws QueryException {
    Query query = getChildDocumentsQuery(documentReference);
    query.setOffset(offset);
    query.setLimit(limit);
    List<DocumentReference> documentReferences = new ArrayList<DocumentReference>();
    for (Object result : query.execute()) {
        documentReferences.add(this.explicitDocumentReferenceResolver.resolve((String) result, documentReference));
    }
    return documentReferences;
}
Also used : Query(org.xwiki.query.Query) ArrayList(java.util.ArrayList) DocumentReference(org.xwiki.model.reference.DocumentReference)

Aggregations

DocumentReference (org.xwiki.model.reference.DocumentReference)1324 Test (org.junit.Test)711 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)482 BaseObject (com.xpn.xwiki.objects.BaseObject)250 XWikiContext (com.xpn.xwiki.XWikiContext)186 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)157 ArrayList (java.util.ArrayList)128 WikiReference (org.xwiki.model.reference.WikiReference)127 XWikiException (com.xpn.xwiki.XWikiException)121 EntityReference (org.xwiki.model.reference.EntityReference)113 SpaceReference (org.xwiki.model.reference.SpaceReference)96 XWiki (com.xpn.xwiki.XWiki)82 HashMap (java.util.HashMap)54 XWikiAttachment (com.xpn.xwiki.doc.XWikiAttachment)52 Expectations (org.jmock.Expectations)50 Before (org.junit.Before)50 DocumentModelBridge (org.xwiki.bridge.DocumentModelBridge)46 BaseClass (com.xpn.xwiki.objects.classes.BaseClass)45 AttachmentReference (org.xwiki.model.reference.AttachmentReference)44 Date (java.util.Date)42