use of org.xwiki.rest.model.jaxb.ObjectSummary in project xwiki-platform by xwiki.
the class ModelFactory method toRestObjectSummary.
public ObjectSummary toRestObjectSummary(URI baseUri, Document doc, BaseObject xwikiObject, boolean useVersion, Boolean withPrettyNames) {
ObjectSummary objectSummary = objectFactory.createObjectSummary();
fillObjectSummary(objectSummary, doc, xwikiObject, withPrettyNames);
Link objectLink = getObjectLink(objectFactory, baseUri, doc, xwikiObject, useVersion, Relations.OBJECT);
objectSummary.getLinks().add(objectLink);
String propertiesUri;
if (useVersion) {
propertiesUri = Utils.createURI(baseUri, ObjectPropertiesAtPageVersionResource.class, doc.getWiki(), Utils.getSpacesFromSpaceId(doc.getSpace()), doc.getName(), doc.getVersion(), xwikiObject.getClassName(), xwikiObject.getNumber()).toString();
} else {
propertiesUri = Utils.createURI(baseUri, ObjectPropertiesResource.class, doc.getWiki(), Utils.getSpacesFromSpaceId(doc.getSpace()), doc.getName(), xwikiObject.getClassName(), xwikiObject.getNumber()).toString();
}
Link propertyLink = objectFactory.createLink();
propertyLink.setHref(propertiesUri);
propertyLink.setRel(Relations.PROPERTIES);
objectSummary.getLinks().add(propertyLink);
return objectSummary;
}
use of org.xwiki.rest.model.jaxb.ObjectSummary in project xwiki-platform by xwiki.
the class AllObjectsForClassNameResourceImpl method getObjects.
@Override
public Objects getObjects(String wikiName, String className, Integer start, Integer number, String order, Boolean withPrettyNames) throws XWikiRestException {
String database = Utils.getXWikiContext(componentManager).getWikiId();
try {
Objects objects = new Objects();
Utils.getXWikiContext(componentManager).setWikiId(wikiName);
String query = "select doc, obj from BaseObject as obj, XWikiDocument as doc where obj.name=doc.fullName and obj.className=:className";
if ("date".equals(order)) {
query += " order by doc.date desc";
}
List<Object> queryResult = null;
queryResult = queryManager.createQuery(query, Query.XWQL).bindValue("className", className).setLimit(number).setOffset(start).execute();
for (Object object : queryResult) {
Object[] fields = (Object[]) object;
XWikiDocument xwikiDocument = (XWikiDocument) fields[0];
xwikiDocument.setDatabase(wikiName);
Document doc = new Document(xwikiDocument, Utils.getXWikiContext(componentManager));
BaseObject xwikiObject = (BaseObject) fields[1];
ObjectSummary objectSummary = DomainObjectFactory.createObjectSummary(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, xwikiObject, false, Utils.getXWikiApi(componentManager), withPrettyNames);
objects.getObjectSummaries().add(objectSummary);
}
return objects;
} catch (Exception e) {
throw new XWikiRestException(e);
} finally {
Utils.getXWikiContext(componentManager).setWikiId(database);
}
}
use of org.xwiki.rest.model.jaxb.ObjectSummary in project xwiki-platform by xwiki.
the class ObjectsResourceTest method testPUTPropertyFormUrlEncoded.
@Test
public void testPUTPropertyFormUrlEncoded() 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);
NameValuePair[] nameValuePairs = new NameValuePair[1];
nameValuePairs[0] = new NameValuePair("property#tags", TAG_VALUE);
PostMethod postMethod = executePostForm(String.format("%s?method=PUT", tagsPropertyLink.getHref()), nameValuePairs, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_ACCEPTED, postMethod.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 testPUTProperty.
@Test
public void testPUTProperty() 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);
Property newTags = objectFactory.createProperty();
newTags.setValue(TAG_VALUE);
PutMethod putMethod = executePutXml(tagsPropertyLink.getHref(), newTags, 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 createObjectIfDoesNotExists.
private Object createObjectIfDoesNotExists(String className, List<String> spaces, String pageName) throws Exception {
createPageIfDoesntExist(spaces, pageName, "");
GetMethod getMethod = executeGet(buildURI(ObjectsResource.class, getWiki(), spaces, pageName).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Objects objects = (Objects) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
for (ObjectSummary objectSummary : objects.getObjectSummaries()) {
if (objectSummary.getClassName().equals(className)) {
Link link = getFirstLinkByRelation(objectSummary, Relations.OBJECT);
Assert.assertNotNull(link);
getMethod = executeGet(link.getHref());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Object object = (Object) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
return object;
}
}
/* If no object of that class is found, then create a new one */
Object object = objectFactory.createObject();
object.setClassName(className);
PostMethod postMethod = executePostXml(buildURI(ObjectsResource.class, getWiki(), spaces, pageName).toString(), object, TestUtils.SUPER_ADMIN_CREDENTIALS.getUserName(), TestUtils.SUPER_ADMIN_CREDENTIALS.getPassword());
Assert.assertEquals(getHttpMethodInfo(postMethod), HttpStatus.SC_CREATED, postMethod.getStatusCode());
object = (Object) unmarshaller.unmarshal(postMethod.getResponseBodyAsStream());
return object;
}
Aggregations