Skip to content

Commit

Permalink
MET-4463 removing unnecesary code for dates and using try-resource
Browse files Browse the repository at this point in the history
  • Loading branch information
jeortizquan committed Oct 30, 2023
1 parent f5cff0b commit bbf4a31
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ private static ListIdentifiersParameters prepareListIdentifiersParameters(OaiHar
ListIdentifiersParameters parameters = ListIdentifiersParameters.request()
.withMetadataPrefix(harvest.getMetadataPrefix());
if (harvest.getFrom() != null) {
parameters.withFrom(Date.from(harvest.getFrom()).toInstant());
parameters.withFrom(harvest.getFrom());
}
if (harvest.getUntil() != null) {
parameters.withUntil(Date.from(harvest.getUntil()).toInstant());
parameters.withUntil(harvest.getUntil());
}
if (harvest.getSetSpec() != null) {
parameters.withSetSpec(harvest.getSetSpec());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public OaiRecordHeader(String oaiIdentifier, boolean isDeleted, Instant datestam
* @return An instance.
*/
static OaiRecordHeader convert(Header header) {
return new OaiRecordHeader(header.getIdentifier(), header.isDeleted(),
Optional.ofNullable(header.getDatestamp()).orElse(null));
return new OaiRecordHeader(header.getIdentifier(), header.isDeleted(), header.getDatestamp());
}

public String getOaiIdentifier() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,11 @@ public String oaiPmh(
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
final WriterContext context = new XmlOAIWriterContext();
XmlWriter writer = new XmlWriter(outputStream, context);
try {

try (XmlWriter writer = new XmlWriter(outputStream, context)) {
result.write(writer);
} finally {
writer.close();
}

return outputStream.toString();
} catch (XMLStreamException e) {
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, "A problem occurred while serializing the response.",
Expand Down Expand Up @@ -142,7 +141,7 @@ private GetRecord getRecord(String identifier) {
return new GetRecord(resultRecord);
}

private class XmlOAIWriterContext implements WriterContext {
private static class XmlOAIWriterContext implements WriterContext {
@Override
public Granularity getGranularity() {
return Granularity.Day;
Expand Down

0 comments on commit bbf4a31

Please sign in to comment.