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());
}
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());
}
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);
}
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);
}
}
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);
}
}
Aggregations