Wiki source code of RefactoringRESTXML
Last modified by Thomas Mortagne on 2022/08/08 11:05
Hide last authors
author | version | line-number | content |
---|---|---|---|
1.1 | 1 | {{groovy}} | |
1.2 | 2 | import org.xwiki.model.reference.*; | |
1.1 | 3 | ||
4 | // Create a request to move a page using the standard API | ||
1.13 | 5 | // That's generally the only part you need to customize for your own request need | |
1.2 | 6 | var source = new SpaceReference("xwiki", "MyParentPage", "MyPage"); | |
7 | var destination = new SpaceReference("xwiki", "MyPageNewLocaltion", "MyPageNewName"); | ||
2.1 | 8 | var jobRequest = services.component.getInstance(org.xwiki.refactoring.script.RequestFactory.class).createMoveRequest(source, destination) | |
1.13 | 9 | ||
10 | /////////// SERIALIZATION //////////////////// | ||
11 | |||
1.9 | 12 | // cleanup the request from properties which make sense for a script but are pretty much useless in the case of a REST request | |
2.1 | 13 | jobRequest.removeProperty("checkrights") | |
14 | jobRequest.removeProperty("user.reference") | ||
15 | jobRequest.removeProperty("caller.reference") | ||
1.1 | 16 | ||
17 | // Convert the standard move request into a REST job request | ||
2.1 | 18 | var restJobRequest = services.component.getInstance(org.xwiki.rest.internal.ModelFactory.class).toRestJobRequest(jobRequest); | |
1.1 | 19 | ||
20 | // Serialize the REST job request into an XML content | ||
1.12 | 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); | ||
1.6 | 26 | marshaller.marshal(restJobRequest, writer); | |
1.1 | 27 | ||
1.7 | 28 | println "{{code language='xml'}}" | |
29 | println writer.toString() | ||
30 | println "{{/code}}" | ||
1.1 | 31 | {{/groovy}} |