Skip to content

Commit a4e0601

Browse files
Merge pull request #9 from CSUC/release/1.3
Release/1.3
2 parents 82b800c + c5a811e commit a4e0601

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+595
-2555
lines changed

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@
1010
path = YASGUI.server
1111
url = https://github.com/CSUC/YASGUI.server.git
1212
branch = echoes
13+
[submodule "database"]
14+
path = database
15+
url = https://github.com/CSUC/database.git
16+
branch = echoes

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ services: mongodb
33
sudo: false
44
jdk:
55
- oraclejdk8
6+
env:
7+
- EDM=external
68
before_install:
79
- git submodule update --init --recursive
8-
script: mvn clean install
10+
script: mvn install -D$EDM -B -V
911
notifications:
1012
email:
1113
recipients:

Binding-Core/pom.xml

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
<parent>
44
<artifactId>ECHOES-Tools</artifactId>
55
<groupId>org.csuc</groupId>
6-
<version>1.1.2</version>
6+
<version>1.3</version>
77
</parent>
8+
<version>1.3</version>
89
<modelVersion>4.0.0</modelVersion>
910

1011
<artifactId>Binding-Core</artifactId>
@@ -28,6 +29,10 @@
2829
<groupId>org.apache.logging.log4j</groupId>
2930
<artifactId>log4j-iostreams</artifactId>
3031
</dependency>
32+
<dependency>
33+
<groupId>org.apache.logging.log4j</groupId>
34+
<artifactId>log4j-core</artifactId>
35+
</dependency>
3136
<dependency>
3237
<groupId>org.apache.logging.log4j</groupId>
3338
<artifactId>log4j-api</artifactId>
@@ -36,6 +41,31 @@
3641
<groupId>org.jibx</groupId>
3742
<artifactId>jibx-schema</artifactId>
3843
</dependency>
44+
<dependency>
45+
<groupId>org.csuc</groupId>
46+
<artifactId>metadata-schema-definitions-a2a</artifactId>
47+
<version>1.1</version>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.csuc</groupId>
51+
<artifactId>metadata-schema-definitions-oaidc</artifactId>
52+
<version>1.1</version>
53+
</dependency>
54+
<dependency>
55+
<groupId>org.csuc</groupId>
56+
<artifactId>metadata-schema-definitions-ead</artifactId>
57+
<version>1.1</version>
58+
</dependency>
59+
<dependency>
60+
<groupId>org.csuc</groupId>
61+
<artifactId>metadata-schema-definitions-memorix</artifactId>
62+
<version>1.1</version>
63+
</dependency>
64+
<dependency>
65+
<groupId>org.csuc</groupId>
66+
<artifactId>metadata-schema-definitions-oaipmh</artifactId>
67+
<version>1.1</version>
68+
</dependency>
3969
</dependencies>
4070

4171
<build>
@@ -44,6 +74,10 @@
4474
<directory>src/main/resources</directory>
4575
<filtering>true</filtering>
4676
</resource>
77+
<resource>
78+
<directory>src/test/resources</directory>
79+
<filtering>true</filtering>
80+
</resource>
4781
</resources>
4882
</build>
4983
</project>

Binding-Core/src/main/java/org/csuc/deserialize/JaxbUnmarshal.java

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
*/
44
package org.csuc.deserialize;
55

6+
import isbn._1_931666_22_9.Ead;
7+
import nl.memorix_maior.api.rest._3.Memorix;
8+
import nl.mindbus.a2a.A2AType;
69
import org.apache.logging.log4j.LogManager;
710
import org.apache.logging.log4j.Logger;
11+
import org.openarchives.oai._2.OAIPMHtype;
12+
import org.openarchives.oai._2_0.oai_dc.OaiDcType;
813
import org.w3c.dom.Node;
914
import org.xml.sax.SAXException;
1015
import org.xml.sax.SAXNotRecognizedException;
1116

17+
import javax.xml.XMLConstants;
1218
import javax.xml.bind.JAXBContext;
1319
import javax.xml.bind.JAXBElement;
1420
import javax.xml.bind.JAXBException;
@@ -23,11 +29,17 @@
2329
import javax.xml.transform.dom.DOMSource;
2430
import javax.xml.transform.sax.SAXSource;
2531
import javax.xml.transform.stream.StreamSource;
32+
import javax.xml.validation.Schema;
33+
import javax.xml.validation.SchemaFactory;
2634
import java.io.File;
2735
import java.io.IOException;
2836
import java.io.InputStream;
2937
import java.io.StringReader;
3038
import java.net.URL;
39+
import java.util.ArrayList;
40+
import java.util.List;
41+
import java.util.Objects;
42+
import java.util.stream.Stream;
3143

3244

3345
/**
@@ -48,6 +60,7 @@ public JaxbUnmarshal(File file, Class[] classType) {
4860
JAXBContext jc = JAXBContext.newInstance(classType);
4961
Unmarshaller u = jc.createUnmarshaller();
5062
u.setEventHandler(validationEvent);
63+
u.setSchema(addSchema(classType));
5164

5265
Object obj = u.unmarshal(file);
5366

@@ -56,24 +69,25 @@ public JaxbUnmarshal(File file, Class[] classType) {
5669
else data = obj;
5770

5871
logger.debug(String.format("isValidating %s", validationEvent.isValidating() ));
59-
} catch (JAXBException e) {
72+
} catch (JAXBException | SAXException e) {
6073
logger.error(String.format("JaxbUnmarshal file %s", e));
61-
}
74+
}
6275
}
6376

6477
public JaxbUnmarshal(InputStream inputStream, Class[] classType) {
6578
try {
6679
JAXBContext jc = JAXBContext.newInstance(classType);
6780
Unmarshaller u = jc.createUnmarshaller();
6881
u.setEventHandler(validationEvent);
82+
u.setSchema(addSchema(classType));
6983

7084
Object obj = u.unmarshal(inputStream);
7185
if(obj instanceof JAXBElement)
7286
data = ((JAXBElement<Object>) obj).getValue();
7387
else data = obj;
7488

7589
logger.debug(String.format("isValidating %s", validationEvent.isValidating() ));
76-
} catch (JAXBException e) {
90+
} catch (JAXBException | SAXException e) {
7791
logger.error(String.format("JaxbUnmarshal InputStream %s", e));
7892
}
7993
}
@@ -85,6 +99,7 @@ public JaxbUnmarshal(URL url, Class[] classType) {
8599
JAXBContext jc = JAXBContext.newInstance(classType);
86100
Unmarshaller u = jc.createUnmarshaller();
87101
u.setEventHandler(validationEvent);
102+
u.setSchema(addSchema(classType));
88103

89104
Object obj = u.unmarshal(url);
90105

@@ -93,7 +108,7 @@ public JaxbUnmarshal(URL url, Class[] classType) {
93108
else data = obj;
94109

95110
logger.debug(String.format("isValidating %s", validationEvent.isValidating() ));
96-
} catch (JAXBException e) {
111+
} catch (JAXBException | SAXException e) {
97112
logger.error(String.format("JaxbUnmarshal URL %s", e));
98113
}
99114
}
@@ -104,6 +119,7 @@ public JaxbUnmarshal(StringBuffer stringbuffer, Class[] classType) {
104119
JAXBContext jc = JAXBContext.newInstance(classType);
105120
Unmarshaller u = jc.createUnmarshaller();
106121
u.setEventHandler(validationEvent);
122+
u.setSchema(addSchema(classType));
107123

108124
Object obj = u.unmarshal(new StreamSource(new StringReader(stringbuffer.toString())));
109125

@@ -112,17 +128,18 @@ public JaxbUnmarshal(StringBuffer stringbuffer, Class[] classType) {
112128
else data = obj;
113129

114130
logger.debug(String.format("isValidating %s", validationEvent.isValidating() ));
115-
} catch (JAXBException e) {
131+
} catch (JAXBException | SAXException e) {
116132
logger.error(String.format("JaxbUnmarshal StringBuffer %s", e));
117133
}
118134
}
119135

120-
public JaxbUnmarshal(Node node, Class<?> classType) throws IOException {
136+
public JaxbUnmarshal(Node node, Class[] classType) throws IOException {
121137
logger.debug(String.format("read Node %s", node));
122138
try {
123139
Source xmlSource = new DOMSource(node);
124140
Unmarshaller u = JAXBContext.newInstance(classType).createUnmarshaller();
125141
u.setEventHandler(validationEvent);
142+
u.setSchema(addSchema(classType));
126143

127144
Object obj = u.unmarshal(xmlSource);
128145

@@ -131,7 +148,7 @@ public JaxbUnmarshal(Node node, Class<?> classType) throws IOException {
131148
else data = obj;
132149

133150
logger.debug(String.format("isValidating %s", validationEvent.isValidating() ));
134-
}catch (JAXBException e) {
151+
}catch (JAXBException | SAXException e) {
135152
logger.error(String.format("JaxbUnmarshal Node %s", e));
136153
}
137154
}
@@ -172,6 +189,7 @@ public JaxbUnmarshal(SAXSource saxSource, Class[] classType) {
172189
Unmarshaller u = jc.createUnmarshaller();
173190
ValidationEventCollector vec = new ValidationEventCollector();
174191
u.setEventHandler( vec );
192+
u.setSchema(addSchema(classType));
175193

176194
// turn off the JAXB provider's default validation mechanism to
177195
// avoid duplicate validation
@@ -201,6 +219,7 @@ public JaxbUnmarshal(XMLStreamReader xmlStreamReader, Class[] classType) {
201219
try {
202220
JAXBContext jc = JAXBContext.newInstance(classType);
203221
Unmarshaller u = jc.createUnmarshaller();
222+
u.setSchema(addSchema(classType));
204223

205224
Object obj = u.unmarshal(xmlStreamReader);
206225

@@ -209,7 +228,7 @@ public JaxbUnmarshal(XMLStreamReader xmlStreamReader, Class[] classType) {
209228
else data = obj;
210229

211230
logger.debug(String.format("isValidating %s", validationEvent.isValidating() ));
212-
} catch (JAXBException e) {
231+
} catch (JAXBException | SAXException e) {
213232
logger.error(String.format("JaxbUnmarshal XMLStreamReader %s", e));
214233
}
215234
}
@@ -219,6 +238,7 @@ public JaxbUnmarshal(XMLEventReader xmlEventReader, Class[] classType) {
219238
try {
220239
JAXBContext jc = JAXBContext.newInstance(classType);
221240
Unmarshaller u = jc.createUnmarshaller();
241+
u.setSchema(addSchema(classType));
222242

223243
Object obj = u.unmarshal(xmlEventReader);
224244

@@ -227,7 +247,7 @@ public JaxbUnmarshal(XMLEventReader xmlEventReader, Class[] classType) {
227247
else data = obj;
228248

229249
logger.debug(String.format("isValidating %s", validationEvent.isValidating() ));
230-
}catch (JAXBException e) {
250+
}catch (JAXBException | SAXException e) {
231251
logger.error(String.format("JaxbUnmarshal XMLEventReader %s", e));
232252
}
233253
}
@@ -239,4 +259,20 @@ public Object getObject() {
239259
public boolean isValidating() {
240260
return validationEvent.isValidating();
241261
}
262+
263+
private Schema addSchema(Class[] classType) throws SAXException {
264+
List<Source> list = new ArrayList<>();
265+
266+
Stream.of(classType).forEach(type ->{
267+
if(Objects.equals(type, A2AType.class)) list.add(new StreamSource(A2AType.class.getClassLoader().getResource("A2AAllInOne_v.1.7.xsd").toExternalForm()));
268+
if(Objects.equals(type, OaiDcType.class)) list.add(new StreamSource(OaiDcType.class.getClassLoader().getResource("oai_dc.xsd").toExternalForm()));
269+
if(Objects.equals(type, Ead.class)) list.add(new StreamSource(Ead.class.getClassLoader().getResource("apeEAD.xsd").toExternalForm()));
270+
if(Objects.equals(type, Memorix.class)) list.add(new StreamSource(Memorix.class.getClassLoader().getResource("MRX-API-ANY.xsd").toExternalForm()));
271+
if(Objects.equals(type, OAIPMHtype.class)) list.add(new StreamSource(OAIPMHtype.class.getClassLoader().getResource("OAI-PMH.xsd").toExternalForm()));
272+
});
273+
274+
Source[] schemaFiles = list.toArray(new Source[list.size()]);
275+
SchemaFactory sf = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI );
276+
return sf.newSchema( schemaFiles );
277+
}
242278
}

Binding-Core/src/test/java/org/csuc/AppTest.java

Lines changed: 0 additions & 38 deletions
This file was deleted.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package org.csuc.deserialize;
2+
3+
import isbn._1_931666_22_9.Ead;
4+
import nl.memorix_maior.api.rest._3.Memorix;
5+
import nl.mindbus.a2a.A2AType;
6+
import org.junit.Before;
7+
import org.junit.Test;
8+
import org.openarchives.oai._2_0.oai_dc.OaiDcType;
9+
10+
import java.io.File;
11+
12+
import static org.junit.Assert.*;
13+
14+
public class JaxbUnmarshalTest {
15+
16+
private File A2A;
17+
private File DC;
18+
private File EAD;
19+
private File MEMORIX;
20+
21+
@Before
22+
public void setUp() {
23+
ClassLoader classLoader = getClass().getClassLoader();
24+
A2A = new File(classLoader.getResource("a2a.xml").getFile());
25+
DC = new File(classLoader.getResource("dc.xml").getFile());
26+
EAD = new File(classLoader.getResource("ead.xml").getFile());
27+
MEMORIX = new File(classLoader.getResource("memorix.xml").getFile());
28+
}
29+
30+
@Test
31+
public void getObject() {
32+
assertNotNull(new JaxbUnmarshal(A2A, new Class[]{A2AType.class}).getObject());
33+
assertNotNull(new JaxbUnmarshal(DC, new Class[]{OaiDcType.class}).getObject());
34+
assertNotNull(new JaxbUnmarshal(EAD, new Class[]{Ead.class}).getObject());
35+
assertNotNull(new JaxbUnmarshal(MEMORIX, new Class[]{Memorix.class}).getObject());
36+
37+
assertNull(new JaxbUnmarshal(DC, new Class[]{A2AType.class}).getObject());
38+
assertNull(new JaxbUnmarshal(A2A, new Class[]{OaiDcType.class}).getObject());
39+
}
40+
41+
@Test
42+
public void isValidating() {
43+
assertTrue(new JaxbUnmarshal(A2A, new Class[]{A2AType.class}).isValidating());
44+
assertTrue(new JaxbUnmarshal(DC, new Class[]{OaiDcType.class}).isValidating());
45+
assertTrue(new JaxbUnmarshal(EAD, new Class[]{Ead.class}).isValidating());
46+
assertTrue(new JaxbUnmarshal(MEMORIX, new Class[]{Memorix.class}).isValidating());
47+
48+
49+
assertFalse(new JaxbUnmarshal(DC, new Class[]{A2AType.class}).isValidating());
50+
assertFalse(new JaxbUnmarshal(EAD, new Class[]{A2AType.class}).isValidating());
51+
assertFalse(new JaxbUnmarshal(MEMORIX, new Class[]{A2AType.class}).isValidating());
52+
}
53+
}

0 commit comments

Comments
 (0)