Search in sources :

Example 11 with WikiReference

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

the class RefactoringScriptServiceTest method rename.

@Test
public void rename() throws Exception {
    SpaceReference spaceReference = new SpaceReference("Alice", new SpaceReference("Users", new WikiReference("dev")));
    getService().rename(spaceReference, "Bob");
    ArgumentCaptor<MoveRequest> request = ArgumentCaptor.forClass(MoveRequest.class);
    verify(this.jobExecutor).execute(eq(RefactoringJobs.RENAME), request.capture());
    assertEquals(RefactoringJobs.RENAME, request.getValue().getJobType());
    assertEquals(Arrays.asList(spaceReference), request.getValue().getEntityReferences());
    assertEquals(new SpaceReference("Bob", spaceReference.getParent()), request.getValue().getDestination());
}
Also used : MoveRequest(org.xwiki.refactoring.job.MoveRequest) SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Example 12 with WikiReference

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

the class RefactoringScriptServiceTest method delete.

@Test
public void delete() throws Exception {
    WikiReference source = new WikiReference("math");
    getService().delete(source);
    ArgumentCaptor<EntityRequest> request = ArgumentCaptor.forClass(EntityRequest.class);
    verify(this.jobExecutor).execute(eq(RefactoringJobs.DELETE), request.capture());
    assertEquals(RefactoringJobs.DELETE, request.getValue().getJobType());
    assertEquals(Arrays.asList(source), request.getValue().getEntityReferences());
    assertFalse(request.getValue().isDeep());
}
Also used : EntityRequest(org.xwiki.refactoring.job.EntityRequest) WikiReference(org.xwiki.model.reference.WikiReference) Test(org.junit.Test)

Example 13 with WikiReference

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

the class DeleteJobTest method deleteSpace.

@Test
public void deleteSpace() throws Throwable {
    SpaceReference spaceReference = new SpaceReference("Space", new WikiReference("wiki"));
    DocumentReference aliceReference = new DocumentReference("wiki", "Space", "Alice");
    DocumentReference bobReference = new DocumentReference("wiki", "Space", "Bob");
    when(this.modelBridge.getDocumentReferences(spaceReference)).thenReturn(Arrays.asList(aliceReference, bobReference));
    run(createRequest(spaceReference));
    // We only verify that the code tries to delete the documents.
    verify(this.mocker.getMockedLogger()).warn("Skipping [{}] because it doesn't exist.", aliceReference);
    verify(this.mocker.getMockedLogger()).warn("Skipping [{}] because it doesn't exist.", bobReference);
}
Also used : SpaceReference(org.xwiki.model.reference.SpaceReference) WikiReference(org.xwiki.model.reference.WikiReference) DocumentReference(org.xwiki.model.reference.DocumentReference) Test(org.junit.Test)

Example 14 with WikiReference

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

the class XWQLQueryExecutor method execute.

@Override
public <T> List<T> execute(Query query) throws QueryException {
    EntityReference currentEntityReference = this.context.getCurrentEntityReference();
    Query nativeQuery;
    try {
        this.progress.startStep(query, "query.xwql.progress.execute", "Execute XWQL query [{}]", query);
        if (query.getWiki() != null) {
            if (currentEntityReference.getType() == EntityType.WIKI) {
                this.context.setCurrentEntityReference(new WikiReference(query.getWiki()));
            } else {
                this.context.setCurrentEntityReference(currentEntityReference.replaceParent(currentEntityReference.extractReference(EntityType.WIKI), new WikiReference(query.getWiki())));
            }
        }
        nativeQuery = getQueryManager().createQuery(this.translator.translate(query.getStatement()), this.translator.getOutputLanguage());
        nativeQuery.setLimit(query.getLimit());
        nativeQuery.setOffset(query.getOffset());
        nativeQuery.setWiki(query.getWiki());
        if (query.getFilters() != null) {
            for (QueryFilter filter : query.getFilters()) {
                nativeQuery.addFilter(filter);
            }
        }
        for (Entry<String, Object> e : query.getNamedParameters().entrySet()) {
            nativeQuery.bindValue(e.getKey(), e.getValue());
        }
        for (Entry<Integer, Object> e : query.getPositionalParameters().entrySet()) {
            nativeQuery.bindValue(e.getKey(), e.getValue());
        }
        if (nativeQuery instanceof SecureQuery && query instanceof SecureQuery) {
            // No need to validate the HQL query for short XWQL queries
            if (((SecureQuery) query).isCurrentAuthorChecked() && !isShortFormStatement(query.getStatement())) {
                ((SecureQuery) nativeQuery).checkCurrentAuthor(true);
            }
            // Let HQL module take care of that is supported
            ((SecureQuery) nativeQuery).checkCurrentUser(((SecureQuery) query).isCurrentUserChecked());
        }
        return nativeQuery.execute();
    } catch (Exception e) {
        if (e instanceof QueryException) {
            throw (QueryException) e;
        }
        throw new QueryException("Exception while translating [" + query.getStatement() + "] XWQL query to the [" + this.translator.getOutputLanguage() + "] language", query, e);
    } finally {
        this.context.setCurrentEntityReference(currentEntityReference);
        this.progress.endStep(query);
    }
}
Also used : QueryFilter(org.xwiki.query.QueryFilter) QueryException(org.xwiki.query.QueryException) Query(org.xwiki.query.Query) SecureQuery(org.xwiki.query.SecureQuery) EntityReference(org.xwiki.model.reference.EntityReference) WikiReference(org.xwiki.model.reference.WikiReference) SecureQuery(org.xwiki.query.SecureQuery) QueryException(org.xwiki.query.QueryException) ComponentLookupException(org.xwiki.component.manager.ComponentLookupException)

Example 15 with WikiReference

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

the class RestoreJob method initialize.

@Override
public void initialize(Request request) {
    super.initialize(request);
    // Build the job group path.
    // Note: Because of the nature of the RestoreJob that works with with DeletedDocument IDs and BatchIDs (and not
    // with EntityReferences), the only way we can try to avoid executing operation at the same time on the same
    // reference is to use a group path at the wiki level, hoping most restore operations are fast and do not block
    // for long.
    WikiReference wikiReference = ((RestoreRequest) request).getWikiReference();
    if (wikiReference != null) {
        // Note:
        this.groupPath = new JobGroupPath(wikiReference.getName(), ROOT_GROUP);
    }
}
Also used : RestoreRequest(org.xwiki.refactoring.job.RestoreRequest) JobGroupPath(org.xwiki.job.JobGroupPath) WikiReference(org.xwiki.model.reference.WikiReference)

Aggregations

WikiReference (org.xwiki.model.reference.WikiReference)220 DocumentReference (org.xwiki.model.reference.DocumentReference)127 Test (org.junit.Test)106 SpaceReference (org.xwiki.model.reference.SpaceReference)58 XWikiContext (com.xpn.xwiki.XWikiContext)33 XWikiException (com.xpn.xwiki.XWikiException)24 EntityReference (org.xwiki.model.reference.EntityReference)24 XWikiDocument (com.xpn.xwiki.doc.XWikiDocument)23 ArrayList (java.util.ArrayList)19 AccessDeniedException (org.xwiki.security.authorization.AccessDeniedException)18 LocalDocumentReference (org.xwiki.model.reference.LocalDocumentReference)15 WikiDescriptor (org.xwiki.wiki.descriptor.WikiDescriptor)11 ComponentLookupException (org.xwiki.component.manager.ComponentLookupException)10 WikiManagerException (org.xwiki.wiki.manager.WikiManagerException)10 XWiki (com.xpn.xwiki.XWiki)9 BaseObject (com.xpn.xwiki.objects.BaseObject)9 ComponentManager (org.xwiki.component.manager.ComponentManager)9 Expectations (org.jmock.Expectations)8 Before (org.junit.Before)8 DefaultComponentDescriptor (org.xwiki.component.descriptor.DefaultComponentDescriptor)8