Add the logo setter to the Community DTO

That fixes potential deserialization issues.
This is covered by a test on the generated JAXB schema.
This commit is contained in:
Arnaud de Bossoreille
2015-10-16 22:21:54 +02:00
parent 432795ed9b
commit 093228b3fa
3 changed files with 237 additions and 0 deletions

View File

@@ -181,6 +181,10 @@ public class Community extends DSpaceObject{
return logo;
}
public void setLogo(Bitstream logo) {
this.logo = logo;
}
// Renamed because of xml annotation exception with this attribute and getSubCommunities.
@XmlElement(name = "subcommunities", required = true)
public List<Community> getSubcommunities() {

View File

@@ -0,0 +1,70 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.rest.common;
import static org.junit.Assert.assertEquals;
import java.io.InputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.SchemaOutputResolver;
import javax.xml.transform.Result;
import javax.xml.transform.stream.StreamResult;
import org.apache.commons.io.IOUtils;
import org.junit.Test;
public class TestJAXBSchema {
private static class TestSchemaOutputResolver extends SchemaOutputResolver {
private final Writer output;
public TestSchemaOutputResolver(Writer output) {
this.output = output;
}
public Result createOutput(String namespaceUri, String suggestedFileName) throws IOException {
StreamResult result = new StreamResult(output);
result.setSystemId("xsd0.xsd");
return result;
}
}
@Test
public void testFullSchema() throws Exception {
StringWriter writer = new StringWriter();
TestSchemaOutputResolver resolver = new TestSchemaOutputResolver(writer);
JAXBContext context = JAXBContext.newInstance(
Bitstream.class,
CheckSum.class,
Collection.class,
Community.class,
DSpaceObject.class,
Item.class,
MetadataEntry.class,
ResourcePolicy.class,
Status.class,
User.class
);
context.generateSchema(resolver);
String res = "org/dspace/rest/common/expected_xsd0.xsd";
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(res);
String expected = IOUtils.toString(is, "UTF-8");
// System.err.println(writer.toString());
assertEquals("JAXB schema", expected, writer.toString());
}
}

View File

@@ -0,0 +1,163 @@
<?xml version="1.0" standalone="yes"?>
<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="bitstream" type="bitstream"/>
<xs:element name="collection" type="collection"/>
<xs:element name="community" type="community"/>
<xs:element name="dspaceobject" type="dSpaceObject"/>
<xs:element name="item" type="item"/>
<xs:element name="metadataentry" type="metadataEntry"/>
<xs:element name="resourcepolicy" type="resourcePolicy"/>
<xs:element name="status" type="status"/>
<xs:element name="user" type="user"/>
<xs:complexType name="bitstream">
<xs:complexContent>
<xs:extension base="dSpaceObject">
<xs:sequence>
<xs:element name="bundleName" type="xs:string" minOccurs="0"/>
<xs:element name="checkSum" type="checkSum" minOccurs="0"/>
<xs:element name="description" type="xs:string" minOccurs="0"/>
<xs:element name="format" type="xs:string" minOccurs="0"/>
<xs:element name="mimeType" type="xs:string" minOccurs="0"/>
<xs:element name="parentObject" type="dSpaceObject" minOccurs="0"/>
<xs:element name="policies" type="resourcePolicy" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="retrieveLink" type="xs:string" minOccurs="0"/>
<xs:element name="sequenceId" type="xs:int" minOccurs="0"/>
<xs:element name="sizeBytes" type="xs:long" minOccurs="0"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="dSpaceObject">
<xs:sequence>
<xs:element name="link" type="xs:string"/>
<xs:element name="expand" type="xs:string" maxOccurs="unbounded"/>
<xs:element name="handle" type="xs:string" minOccurs="0"/>
<xs:element name="id" type="xs:int" minOccurs="0"/>
<xs:element name="name" type="xs:string" minOccurs="0"/>
<xs:element name="type" type="xs:string" minOccurs="0"/>
<xs:element name="UUID" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="checkSum">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="checkSumAlgorithm" type="xs:string"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:complexType name="resourcePolicy">
<xs:sequence>
<xs:element name="action" type="action" minOccurs="0"/>
<xs:element name="endDate" type="xs:dateTime" minOccurs="0"/>
<xs:element name="epersonId" type="xs:string" minOccurs="0"/>
<xs:element name="groupId" type="xs:string" minOccurs="0"/>
<xs:element name="id" type="xs:int" minOccurs="0"/>
<xs:element name="resourceId" type="xs:string" minOccurs="0"/>
<xs:element name="resourceType" type="xs:string" minOccurs="0"/>
<xs:element name="rpDescription" type="xs:string" minOccurs="0"/>
<xs:element name="rpName" type="xs:string" minOccurs="0"/>
<xs:element name="rpType" type="xs:string" minOccurs="0"/>
<xs:element name="startDate" type="xs:dateTime" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="collection">
<xs:complexContent>
<xs:extension base="dSpaceObject">
<xs:sequence>
<xs:element name="copyrightText" type="xs:string" minOccurs="0"/>
<xs:element name="introductoryText" type="xs:string" minOccurs="0"/>
<xs:element name="items" type="item" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="license" type="xs:string" minOccurs="0"/>
<xs:element name="numberItems" type="xs:int" minOccurs="0"/>
<xs:element name="parentCommunity" type="community" minOccurs="0"/>
<xs:element name="parentCommunityList" type="community" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="shortDescription" type="xs:string" minOccurs="0"/>
<xs:element name="sidebarText" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="item">
<xs:complexContent>
<xs:extension base="dSpaceObject">
<xs:sequence>
<xs:element name="archived" type="xs:string" minOccurs="0"/>
<xs:element name="bitstreams" type="bitstream" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="lastModified" type="xs:string" minOccurs="0"/>
<xs:element name="metadata" type="metadataEntry" maxOccurs="unbounded"/>
<xs:element name="parentCollection" type="collection" minOccurs="0"/>
<xs:element name="parentCollectionList" type="collection" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="parentCommunityList" type="community" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="withdrawn" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="metadataEntry">
<xs:sequence>
<xs:element name="key" type="xs:string" minOccurs="0"/>
<xs:element name="language" type="xs:string" minOccurs="0"/>
<xs:element name="value" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="community">
<xs:complexContent>
<xs:extension base="dSpaceObject">
<xs:sequence>
<xs:element name="collections" type="collection" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="copyrightText" type="xs:string" minOccurs="0"/>
<xs:element name="countItems" type="xs:int" minOccurs="0"/>
<xs:element name="introductoryText" type="xs:string" minOccurs="0"/>
<xs:element name="logo" type="bitstream" minOccurs="0"/>
<xs:element name="parentCommunity" type="community" minOccurs="0"/>
<xs:element name="shortDescription" type="xs:string" minOccurs="0"/>
<xs:element name="sidebarText" type="xs:string" minOccurs="0"/>
<xs:element name="subcommunities" type="community" maxOccurs="unbounded"/>
</xs:sequence>
</xs:extension>
</xs:complexContent>
</xs:complexType>
<xs:complexType name="status">
<xs:sequence>
<xs:element name="authenticated" type="xs:boolean"/>
<xs:element name="email" type="xs:string" minOccurs="0"/>
<xs:element name="fullname" type="xs:string" minOccurs="0"/>
<xs:element name="okay" type="xs:boolean"/>
<xs:element name="token" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="user">
<xs:sequence>
<xs:element name="email" type="xs:string" minOccurs="0"/>
<xs:element name="password" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="action">
<xs:restriction base="xs:string">
<xs:enumeration value="READ"/>
<xs:enumeration value="WRITE"/>
<xs:enumeration value="DELETE"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>