use of org.xwiki.rest.model.jaxb.ObjectSummary in project xwiki-platform by xwiki.
the class ObjectsResourceTest method testPUTPropertyWithTextPlain.
@Test
public void testPUTPropertyWithTextPlain() throws Exception {
final String TAG_VALUE = UUID.randomUUID().toString();
/* Make sure that an Object with the TagClass exists. */
createObjectIfDoesNotExists("XWiki.TagClass", this.spaces, this.pageName);
GetMethod getMethod = executeGet(buildURI(PageResource.class, getWiki(), this.spaces, this.pageName).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Page page = (Page) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Link link = getFirstLinkByRelation(page, Relations.OBJECTS);
Assert.assertNotNull(link);
getMethod = executeGet(link.getHref());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Objects objects = (Objects) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertFalse(objects.getObjectSummaries().isEmpty());
Object currentObject = null;
for (ObjectSummary objectSummary : objects.getObjectSummaries()) {
if (objectSummary.getClassName().equals("XWiki.TagClass")) {
link = getFirstLinkByRelation(objectSummary, Relations.OBJECT);
Assert.assertNotNull(link);
getMethod = executeGet(link.getHref());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
currentObject = (Object) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
break;
}
}
Assert.assertNotNull(currentObject);
Property tagsProperty = getProperty(currentObject, "tags");
Assert.assertNotNull(tagsProperty);
Link tagsPropertyLink = getFirstLinkByRelation(tagsProperty, Relations.SELF);
Assert.assertNotNull(tagsPropertyLink);
PutMethod putMethod = executePut(tagsPropertyLink.getHref(), TAG_VALUE, MediaType.TEXT_PLAIN, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(putMethod), HttpStatus.SC_ACCEPTED, putMethod.getStatusCode());
getMethod = executeGet(buildURI(ObjectResource.class, getWiki(), this.spaces, this.pageName, currentObject.getClassName(), currentObject.getNumber()).toString());
Assert.assertEquals(HttpStatus.SC_OK, getMethod.getStatusCode());
currentObject = (Object) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
tagsProperty = getProperty(currentObject, "tags");
Assert.assertEquals(TAG_VALUE, tagsProperty.getValue());
}
use of org.xwiki.rest.model.jaxb.ObjectSummary in project xwiki-platform by xwiki.
the class ObjectsResourceTest method testRepresentation.
@Override
@Test
public void testRepresentation() throws Exception {
GetMethod getMethod = executeGet(buildURI(PageResource.class, getWiki(), this.spaces, this.pageName).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Page page = (Page) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Link link = getFirstLinkByRelation(page, Relations.OBJECTS);
Assert.assertNotNull(link);
getMethod = executeGet(link.getHref());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Objects objects = (Objects) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
Assert.assertFalse(objects.getObjectSummaries().isEmpty());
for (ObjectSummary objectSummary : objects.getObjectSummaries()) {
link = getFirstLinkByRelation(objectSummary, Relations.OBJECT);
getMethod = executeGet(link.getHref());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Object object = (Object) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
checkLinks(objectSummary);
for (Property property : object.getProperties()) {
checkLinks(property);
}
}
}
use of org.xwiki.rest.model.jaxb.ObjectSummary in project xwiki-platform by xwiki.
the class ModelFactory method toDocument.
public boolean toDocument(Document doc, org.xwiki.rest.model.jaxb.Page restPage) throws XWikiException {
boolean modified = false;
if (restPage.getContent() != null) {
doc.setContent(restPage.getContent());
modified = true;
}
if (restPage.getTitle() != null) {
doc.setTitle(restPage.getTitle());
modified = true;
}
if (restPage.getParent() != null) {
doc.setParent(restPage.getParent());
modified = true;
}
if (restPage.getSyntax() != null) {
doc.setSyntaxId(restPage.getSyntax());
modified = true;
}
doc.setHidden(restPage.isHidden());
// Set objects
if (restPage.getObjects() != null) {
Set<ObjectReference> newReferences = new HashSet<>();
// Add/update objects
for (ObjectSummary restObjectSummary : restPage.getObjects().getObjectSummaries()) {
if (restObjectSummary != null) {
org.xwiki.rest.model.jaxb.Object restObject = (org.xwiki.rest.model.jaxb.Object) restObjectSummary;
com.xpn.xwiki.api.Object xwikiObject = doc.getObject(restObject.getClassName(), restObject.getNumber());
if (xwikiObject == null) {
xwikiObject = doc.newObject(restObject.getClassName());
}
toObject(xwikiObject, restObject);
modified = true;
newReferences.add(xwikiObject.getReference());
}
}
// Remove objects
List<com.xpn.xwiki.api.Object> toRemove = new ArrayList<>();
for (Vector<com.xpn.xwiki.api.Object> objects : doc.getxWikiObjects().values()) {
for (com.xpn.xwiki.api.Object object : objects) {
if (!newReferences.contains(object.getReference())) {
toRemove.add(object);
}
}
}
for (com.xpn.xwiki.api.Object obj : toRemove) {
doc.removeObject(obj);
modified = true;
}
}
return modified;
}
Aggregations