Wiki source code of RefactoringRESTXML

Last modified by Thomas Mortagne on 2022/08/08 11:05

Show last authors
1 {{groovy}}
2 import org.xwiki.model.reference.*;
3
4 // Create a request to move a page using the standard API
5 // That's generally the only part you need to customize for your own request need
6 var source = new SpaceReference("xwiki", "MyParentPage", "MyPage");
7 var destination = new SpaceReference("xwiki", "MyPageNewLocaltion", "MyPageNewName");
8 var jobRequest = services.component.getInstance(org.xwiki.refactoring.script.RequestFactory.class).createMoveRequest(source, destination)
9
10 /////////// SERIALIZATION ////////////////////
11
12 // cleanup the request from properties which make sense for a script but are pretty much useless in the case of a REST request
13 jobRequest.removeProperty("checkrights")
14 jobRequest.removeProperty("user.reference")
15 jobRequest.removeProperty("caller.reference")
16
17 // Convert the standard move request into a REST job request
18 var restJobRequest = services.component.getInstance(org.xwiki.rest.internal.ModelFactory.class).toRestJobRequest(jobRequest);
19
20 // Serialize the REST job request into an XML content
21 var writer = new java.io.StringWriter();
22 var context = javax.xml.bind.JAXBContext.newInstance("org.xwiki.rest.model.jaxb");
23 var marshaller = context.createMarshaller();
24 // Format the XML to make the example more readable but the XML obviously does not need to be formatter in the request
25 marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
26 marshaller.marshal(restJobRequest, writer);
27
28 println "{{code language='xml'}}"
29 println writer.toString()
30 println "{{/code}}"
31 {{/groovy}}