Skip to content

Commit 42dcac6

Browse files
authored
Merge pull request #28 from gdcc/25-from-until-fixes
25 from until fixes
2 parents 2023c9f + bed39df commit 42dcac6

152 files changed

Lines changed: 3275 additions & 3430 deletions

File tree

Some content is hidden

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

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ This library is available from Maven Central, simply rely on the main POM:
2222
</dependency>
2323
```
2424

25+
Some minimal usage documentation has been scraped from the DSpace Wiki, mostly
26+
explaining the concepts of this library, and put into [docs/README.md](docs/README.md).
27+
It also contains some minimal explanation of this forks special changes.
28+
Feel free to extend the documentation, pull requests welcome.
29+
2530
## License
2631

2732
See [LICENSE](LICENSE) or [DSpace BSD License](https://raw.github.com/DSpace/DSpace/master/LICENSE)

docs/README.md

Lines changed: 336 additions & 0 deletions
Large diffs are not rendered by default.

xoai-data-provider/src/main/java/io/gdcc/xoai/dataprovider/exceptions/BadArgumentException.java renamed to xoai-common/src/main/java/io/gdcc/xoai/exceptions/BadArgumentException.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,21 @@
66
* http://www.dspace.org/license/
77
*/
88

9-
package io.gdcc.xoai.dataprovider.exceptions;
9+
package io.gdcc.xoai.exceptions;
10+
11+
import io.gdcc.xoai.model.oaipmh.Error;
1012

1113
/**
1214
* @author Development @ Lyncode
1315
* @version 3.1.0
1416
*/
15-
public class BadArgumentException extends HandlerException {
17+
public class BadArgumentException extends OAIException {
1618

17-
/**
18-
*
19-
*/
2019
private static final long serialVersionUID = 6436751364163509217L;
21-
22-
/**
23-
* Creates a new instance of <code>BadArgumentException</code> without
24-
* detail message.
25-
*/
26-
public BadArgumentException() {
20+
21+
@Override
22+
public Error.Code getErrorCode() {
23+
return Error.Code.BAD_ARGUMENT;
2724
}
2825

2926
/**
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
9+
package io.gdcc.xoai.exceptions;
10+
11+
import io.gdcc.xoai.model.oaipmh.Error;
12+
13+
public class BadResumptionTokenException extends OAIException {
14+
@Override
15+
public Error.Code getErrorCode() {
16+
return Error.Code.BAD_RESUMPTION_TOKEN;
17+
}
18+
19+
public BadResumptionTokenException() {
20+
}
21+
22+
public BadResumptionTokenException(String message) {
23+
super(message);
24+
}
25+
26+
public BadResumptionTokenException(String message, Throwable cause) {
27+
super(message, cause);
28+
}
29+
30+
public BadResumptionTokenException(Throwable cause) {
31+
super(cause);
32+
}
33+
}

xoai-data-provider/src/main/java/io/gdcc/xoai/dataprovider/exceptions/IllegalVerbException.java renamed to xoai-common/src/main/java/io/gdcc/xoai/exceptions/BadVerbException.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,37 @@
66
* http://www.dspace.org/license/
77
*/
88

9-
package io.gdcc.xoai.dataprovider.exceptions;
9+
package io.gdcc.xoai.exceptions;
10+
11+
import io.gdcc.xoai.model.oaipmh.Error;
1012

1113
/**
1214
* @author Development @ Lyncode
1315
* @version 3.1.0
1416
*/
15-
public class IllegalVerbException extends HandlerException {
17+
public class BadVerbException extends OAIException {
1618

17-
/**
18-
*
19-
*/
2019
private static final long serialVersionUID = 2748244610538429452L;
21-
20+
21+
@Override
22+
public Error.Code getErrorCode() {
23+
return Error.Code.BAD_VERB;
24+
}
25+
2226
/**
23-
* Creates a new instance of <code>IllegalVerbException</code> without
27+
* Creates a new instance of <code>BadVerbException</code> without
2428
* detail message.
2529
*/
26-
public IllegalVerbException() {
30+
public BadVerbException() {
2731
}
2832

2933
/**
30-
* Constructs an instance of <code>IllegalVerbException</code> with the
34+
* Constructs an instance of <code>BadVerbException</code> with the
3135
* specified detail message.
3236
*
3337
* @param msg the detail message.
3438
*/
35-
public IllegalVerbException(String msg) {
39+
public BadVerbException(String msg) {
3640
super(msg);
3741
}
3842
}

xoai-common/src/main/java/io/gdcc/xoai/exceptions/InvalidResumptionTokenException.java

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* The contents of this file are subject to the license and copyright
3+
* detailed in the LICENSE and NOTICE files at the root of the source
4+
* tree and available online at
5+
*
6+
* http://www.dspace.org/license/
7+
*/
8+
9+
package io.gdcc.xoai.exceptions;
10+
11+
import io.gdcc.xoai.model.oaipmh.Error;
12+
13+
/**
14+
* @author Development @ Lyncode
15+
* @version 3.1.0
16+
*/
17+
public abstract class OAIException extends Exception {
18+
19+
private static final long serialVersionUID = -3229816947775660398L;
20+
21+
/**
22+
* Retrieve the error code from the enumerated list
23+
* @return The matching error code
24+
*/
25+
public abstract Error.Code getErrorCode();
26+
27+
/**
28+
* Generate a more meaningfull error message sent to users/logging/... from the error code and the exception message.
29+
* @return The error message
30+
*/
31+
public String getErrorMessage() {
32+
String errorCodeMessage = getErrorCode().message();
33+
34+
return (errorCodeMessage != null ? errorCodeMessage + ": " : "") +
35+
(getMessage() != null ? getMessage() : "");
36+
}
37+
38+
/**
39+
* Creates a new instance of <code>OAIException</code> without detail
40+
* message.
41+
*/
42+
protected OAIException() {}
43+
44+
/**
45+
* Constructs an instance of <code>OAIException</code> with the specified
46+
* detail message.
47+
*
48+
* @param msg the detail message.
49+
*/
50+
protected OAIException(String msg) {
51+
super(msg);
52+
}
53+
54+
protected OAIException(Throwable ex) {
55+
super(ex.getMessage(), ex);
56+
}
57+
58+
protected OAIException(String message, Throwable ex) {
59+
super(message, ex);
60+
}
61+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package io.gdcc.xoai.exceptions;

xoai-common/src/main/java/io/gdcc/xoai/model/oaipmh/Error.java

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -40,39 +40,41 @@ public void write(XmlWriter writer) throws XmlWriteException {
4040
try {
4141
if (this.code != null)
4242
writer.writeAttribute("code", this.code.toString());
43-
43+
4444
writer.writeCharacters(value);
4545
} catch (XMLStreamException e) {
4646
throw new XmlWriteException(e);
4747
}
4848
}
49-
50-
public static enum Code {
51-
52-
CANNOT_DISSEMINATE_FORMAT("cannotDisseminateFormat"),
53-
ID_DOES_NOT_EXIST("idDoesNotExist"),
54-
BAD_ARGUMENT("badArgument"),
55-
BAD_VERB("badVerb"),
56-
NO_METADATA_FORMATS("noMetadataFormats"),
57-
NO_RECORDS_MATCH("noRecordsMatch"),
58-
BAD_RESUMPTION_TOKEN("badResumptionToken"),
59-
NO_SET_HIERARCHY("noSetHierarchy");
60-
61-
private final String code;
62-
63-
Code(String code) {
64-
this.code = code;
49+
50+
public enum Code {
51+
CANNOT_DISSEMINATE_FORMAT("cannotDisseminateFormat", "Cannot disseminate item with the given format"),
52+
ID_DOES_NOT_EXIST("idDoesNotExist", "The given id does not exist"),
53+
BAD_ARGUMENT("badArgument", null),
54+
BAD_VERB("badVerb", "Illegal OAI verb"),
55+
NO_METADATA_FORMATS("noMetadataFormats", "The item does not have any metadata format available for dissemination"),
56+
NO_RECORDS_MATCH("noRecordsMatch", "No matches for the query"),
57+
BAD_RESUMPTION_TOKEN("badResumptionToken", "The resumption token is invalid"),
58+
NO_SET_HIERARCHY("noSetHierarchy", "This repository does not support sets");
59+
60+
private final String id;
61+
private final String message;
62+
63+
Code(String id, String message) {
64+
this.id = id;
65+
this.message = message;
6566
}
6667

67-
public String code() {
68-
return code;
68+
public String id() {
69+
return id;
70+
}
71+
public String message() {
72+
return message;
6973
}
7074

71-
72-
73-
public static Code fromCode(String code) {
75+
public static Code from(String code) {
7476
for (Code c : Code.values()) {
75-
if (c.code.equals(code)) {
77+
if (c.id.equals(code)) {
7678
return c;
7779
}
7880
}
@@ -81,7 +83,7 @@ public static Code fromCode(String code) {
8183

8284
@Override
8385
public String toString() {
84-
return code;
86+
return id;
8587
}
8688
}
8789
}

xoai-common/src/main/java/io/gdcc/xoai/model/oaipmh/Granularity.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
package io.gdcc.xoai.model.oaipmh;
1010

11-
import java.time.format.DateTimeFormatter;
12-
1311
/**
1412
* @author Development @ Lyncode
1513
* @version 3.1.0
1614
*/
1715
public enum Granularity {
1816
Day("YYYY-MM-DD"),
19-
Second("YYYY-MM-DDThh:mm:ssZ");
17+
Second("YYYY-MM-DDThh:mm:ssZ"),
18+
// Lenient defaults to Second granularity, but can be used to accept Day granularity, too
19+
Lenient(Second.representation);
2020

2121
public static Granularity fromRepresentation (String representation) {
2222
for (Granularity granularity : Granularity.values())
@@ -32,6 +32,7 @@ public static Granularity fromRepresentation (String representation) {
3232
this.representation = representation;
3333
}
3434

35+
@Override
3536
public String toString () {
3637
return representation;
3738
}

0 commit comments

Comments
 (0)