use of org.xwiki.rest.model.jaxb.Property in project xwiki-platform by xwiki.
the class ObjectPropertyResourceImpl method getObjectProperty.
@Override
public Property getObjectProperty(String wikiName, String spaceName, String pageName, String className, Integer objectNumber, String propertyName, Boolean withPrettyNames) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
Document doc = documentInfo.getDocument();
XWikiDocument xwikiDocument = Utils.getXWiki(componentManager).getDocument(doc.getDocumentReference(), Utils.getXWikiContext(componentManager));
com.xpn.xwiki.objects.BaseObject baseObject = xwikiDocument.getObject(className, objectNumber);
if (baseObject == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
Object object = DomainObjectFactory.createObject(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, baseObject, false, Utils.getXWikiApi(componentManager), withPrettyNames);
for (Property property : object.getProperties()) {
if (property.getName().equals(propertyName)) {
String objectUri = Utils.createURI(uriInfo.getBaseUri(), ObjectResource.class, doc.getWiki(), Utils.getSpacesFromSpaceId(doc.getSpace()), doc.getName(), object.getClassName(), object.getNumber()).toString();
Link objectLink = objectFactory.createLink();
objectLink.setHref(objectUri);
objectLink.setRel(Relations.OBJECT);
property.getLinks().add(objectLink);
return property;
}
}
throw new WebApplicationException(Status.NOT_FOUND);
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.model.jaxb.Property in project xwiki-platform by xwiki.
the class ObjectPropertyResourceImpl method updateObjectProperty.
@Override
public Response updateObjectProperty(String wikiName, String spaceName, String pageName, String className, Integer objectNumber, String propertyName, Boolean minorRevision, Property property) throws XWikiRestException {
try {
DocumentInfo documentInfo = getDocumentInfo(wikiName, spaceName, pageName, null, null, true, false);
Document doc = documentInfo.getDocument();
if (!doc.hasAccessLevel("edit", Utils.getXWikiUser(componentManager))) {
throw new WebApplicationException(Status.UNAUTHORIZED);
}
XWikiDocument xwikiDocument = Utils.getXWiki(componentManager).getDocument(doc.getDocumentReference(), Utils.getXWikiContext(componentManager));
com.xpn.xwiki.objects.BaseObject baseObject = xwikiDocument.getObject(className, objectNumber);
if (baseObject == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
baseObject.set(propertyName, property.getValue(), Utils.getXWikiContext(componentManager));
doc.save("", Boolean.TRUE.equals(minorRevision));
baseObject = xwikiDocument.getObject(className, objectNumber);
Object object = DomainObjectFactory.createObject(objectFactory, uriInfo.getBaseUri(), Utils.getXWikiContext(componentManager), doc, baseObject, false, Utils.getXWikiApi(componentManager), false);
for (Property p : object.getProperties()) {
if (p.getName().equals(propertyName)) {
return Response.status(Status.ACCEPTED).entity(p).build();
}
}
throw new WebApplicationException(Status.INTERNAL_SERVER_ERROR);
} catch (XWikiException e) {
throw new XWikiRestException(e);
}
}
use of org.xwiki.rest.model.jaxb.Property in project xwiki-platform by xwiki.
the class FormUrlEncodedPropertyReader method readFrom.
@Override
public Property readFrom(Class<Property> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
ObjectFactory objectFactory = new ObjectFactory();
Property property = objectFactory.createProperty();
Representation representation = new InputRepresentation(entityStream, org.restlet.data.MediaType.APPLICATION_WWW_FORM);
Form form = new Form(representation);
/*
* If the form is empty then it might have happened that some filter has invalidated the entity stream. Try to
* read data using getParameter()
*/
if (form.getNames().isEmpty()) {
HttpServletRequest httpServletRequest = ServletUtils.getRequest(Request.getCurrent());
Enumeration<String> names = httpServletRequest.getParameterNames();
while (names.hasMoreElements()) {
String name = names.nextElement();
if (name.startsWith(PROPERTY_PREFIX)) {
property.setName(name.replace(PROPERTY_PREFIX, ""));
property.setValue(httpServletRequest.getParameter(name));
break;
}
}
} else {
for (String name : form.getNames()) if (name.startsWith(PROPERTY_PREFIX)) {
property.setName(name.replace(PROPERTY_PREFIX, ""));
property.setValue(form.getFirstValue(name));
break;
}
}
return property;
}
Aggregations