use of org.xwiki.rest.model.jaxb.Class in project xwiki-platform by xwiki.
the class ModelFactory method toRestClass.
public Class toRestClass(URI baseUri, com.xpn.xwiki.api.Class xwikiClass) {
Class clazz = this.objectFactory.createClass();
clazz.setId(xwikiClass.getName());
clazz.setName(xwikiClass.getName());
DocumentReference reference = xwikiClass.getReference();
String wikiName = reference.getWikiReference().getName();
for (java.lang.Object xwikiPropertyClassObject : xwikiClass.getProperties()) {
PropertyClass xwikiPropertyClass = (PropertyClass) xwikiPropertyClassObject;
Property property = this.objectFactory.createProperty();
property.setName(xwikiPropertyClass.getName());
property.setType(xwikiPropertyClass.getxWikiClass().getName());
for (java.lang.Object xwikiPropertyObject : xwikiPropertyClass.getProperties()) {
com.xpn.xwiki.api.Property xwikiProperty = (com.xpn.xwiki.api.Property) xwikiPropertyObject;
java.lang.Object value = xwikiProperty.getValue();
Attribute attribute = this.objectFactory.createAttribute();
attribute.setName(xwikiProperty.getName());
if (value != null) {
attribute.setValue(value.toString());
} else {
attribute.setValue("");
}
property.getAttributes().add(attribute);
}
String propertyUri = Utils.createURI(baseUri, ClassPropertyResource.class, wikiName, xwikiClass.getName(), xwikiPropertyClass.getName()).toString();
Link propertyLink = this.objectFactory.createLink();
propertyLink.setHref(propertyUri);
propertyLink.setRel(Relations.SELF);
property.getLinks().add(propertyLink);
clazz.getProperties().add(property);
}
String classUri = Utils.createURI(baseUri, ClassResource.class, wikiName, xwikiClass.getName()).toString();
Link classLink = this.objectFactory.createLink();
classLink.setHref(classUri);
classLink.setRel(Relations.SELF);
clazz.getLinks().add(classLink);
String propertiesUri = Utils.createURI(baseUri, ClassPropertiesResource.class, wikiName, xwikiClass.getName()).toString();
Link propertyLink = this.objectFactory.createLink();
propertyLink.setHref(propertiesUri);
propertyLink.setRel(Relations.PROPERTIES);
clazz.getLinks().add(propertyLink);
String objectsUri = Utils.createURI(baseUri, AllObjectsForClassNameResource.class, wikiName, xwikiClass.getName()).toString();
Link objectsLink = this.objectFactory.createLink();
objectsLink.setHref(objectsUri);
objectsLink.setRel(Relations.OBJECTS);
clazz.getLinks().add(objectsLink);
return clazz;
}
use of org.xwiki.rest.model.jaxb.Class in project xwiki-platform by xwiki.
the class ClassPropertyResourceImpl method getClassProperty.
@Override
public Property getClassProperty(String wikiName, String className, String propertyName) throws XWikiRestException {
String database = Utils.getXWikiContext(componentManager).getWikiId();
try {
Utils.getXWikiContext(componentManager).setWikiId(wikiName);
com.xpn.xwiki.api.Class xwikiClass = Utils.getXWikiApi(componentManager).getClass(className);
if (xwikiClass == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
Class clazz = DomainObjectFactory.createClass(objectFactory, uriInfo.getBaseUri(), wikiName, xwikiClass);
for (Property property : clazz.getProperties()) {
if (property.getName().equals(propertyName)) {
String classUri = Utils.createURI(uriInfo.getBaseUri(), ClassResource.class, wikiName, xwikiClass.getName()).toString();
Link classLink = objectFactory.createLink();
classLink.setHref(classUri);
classLink.setRel(Relations.CLASS);
property.getLinks().add(classLink);
return property;
}
}
throw new WebApplicationException(Status.NOT_FOUND);
} catch (XWikiException e) {
throw new XWikiRestException(e);
} finally {
Utils.getXWikiContext(componentManager).setWikiId(database);
}
}
use of org.xwiki.rest.model.jaxb.Class in project xwiki-platform by xwiki.
the class ClassesResourceTest method testRepresentation.
@Override
@Test
public void testRepresentation() throws Exception {
GetMethod getMethod = executeGet(buildURI(ClassesResource.class, getWiki()).toString());
Assert.assertEquals(getHttpMethodInfo(getMethod), HttpStatus.SC_OK, getMethod.getStatusCode());
Classes classes = (Classes) unmarshaller.unmarshal(getMethod.getResponseBodyAsStream());
for (Class clazz : classes.getClazzs()) {
checkLinks(clazz);
for (Property property : clazz.getProperties()) {
checkLinks(property);
}
}
}
use of org.xwiki.rest.model.jaxb.Class in project xwiki-platform by xwiki.
the class ClassPropertiesResourceImpl method getClassProperties.
@Override
public Properties getClassProperties(String wikiName, String className) throws XWikiRestException {
String database = Utils.getXWikiContext(componentManager).getWikiId();
try {
Utils.getXWikiContext(componentManager).setWikiId(wikiName);
com.xpn.xwiki.api.Class xwikiClass = Utils.getXWikiApi(componentManager).getClass(className);
if (xwikiClass == null) {
throw new WebApplicationException(Status.NOT_FOUND);
}
Class clazz = DomainObjectFactory.createClass(objectFactory, uriInfo.getBaseUri(), wikiName, xwikiClass);
Properties properties = objectFactory.createProperties();
properties.getProperties().addAll(clazz.getProperties());
String classUri = Utils.createURI(uriInfo.getBaseUri(), ClassResource.class, wikiName, xwikiClass.getName()).toString();
Link classLink = objectFactory.createLink();
classLink.setHref(classUri);
classLink.setRel(Relations.CLASS);
properties.getLinks().add(classLink);
return properties;
} catch (XWikiException e) {
throw new XWikiRestException(e);
} finally {
Utils.getXWikiContext(componentManager).setWikiId(database);
}
}
Aggregations