Skip to content
Snippets Groups Projects
Commit 55ab599e authored by mbrodhu's avatar mbrodhu
Browse files

Resolve response errors

parent 4741e694
No related branches found
No related tags found
No related merge requests found
...@@ -27,14 +27,14 @@ public class ErrorHandler { ...@@ -27,14 +27,14 @@ public class ErrorHandler {
if (errorDescription.equals("BadArgument")) { if (errorDescription.equals("BadArgument")) {
this.errorCode = OAIPMHerrorcodeType.BAD_ARGUMENT; this.errorCode = OAIPMHerrorcodeType.BAD_ARGUMENT;
} else if (errorDescription.equals("ResumptionTokenError")) { } else if (errorDescription.equals("badResumptionToken")) {
this.errorCode = OAIPMHerrorcodeType.BAD_RESUMPTION_TOKEN; this.errorCode = OAIPMHerrorcodeType.BAD_RESUMPTION_TOKEN;
} else if (errorDescription.equals("VerbError")) { } else if (errorDescription.equals("VerbError")) {
this.errorCode = OAIPMHerrorcodeType.BAD_VERB; this.errorCode = OAIPMHerrorcodeType.BAD_VERB;
this.error.setValue("Illegal OAI-PMH verb"); this.error.setValue("Illegal OAI-PMH verb");
} else if (errorDescription.equals("FormatError")) { } else if (errorDescription.equals("FormatError")) {
this.errorCode = OAIPMHerrorcodeType.CANNOT_DISSEMINATE_FORMAT; this.errorCode = OAIPMHerrorcodeType.CANNOT_DISSEMINATE_FORMAT;
} else if (errorDescription.equals("IDError")) { } else if (errorDescription.equals("idDoesNotExist")) {
this.errorCode = OAIPMHerrorcodeType.ID_DOES_NOT_EXIST; this.errorCode = OAIPMHerrorcodeType.ID_DOES_NOT_EXIST;
} else if (errorDescription.equals("MetadataFormatError")) { } else if (errorDescription.equals("MetadataFormatError")) {
this.error.setValue("There are no metadata formats available for the specified item."); this.error.setValue("There are no metadata formats available for the specified item.");
......
...@@ -3,6 +3,9 @@ package info.textgrid.middleware; ...@@ -3,6 +3,9 @@ package info.textgrid.middleware;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import javax.swing.plaf.synth.SynthSpinnerUI;
import info.textgrid.middleware.oaipmh.ListIdentifiersType; import info.textgrid.middleware.oaipmh.ListIdentifiersType;
import info.textgrid.middleware.oaipmh.RequestType; import info.textgrid.middleware.oaipmh.RequestType;
...@@ -57,19 +60,18 @@ public abstract class IdentifierListDelivererAbstract implements IdentifierListD ...@@ -57,19 +60,18 @@ public abstract class IdentifierListDelivererAbstract implements IdentifierListD
if (request.getResumptionToken() != null) { if (request.getResumptionToken() != null) {
boolean restokDCExisting = RecordListDelivererIDIOM.cursorCollector != null boolean restokDCExisting = RecordListDelivererIDIOM.cursorCollector != null
&& RecordListDelivererIDIOM.cursorCollector.containsKey(request.getResumptionToken()); && RecordListDelivererIDIOM.cursorCollector.containsKey(request.getResumptionToken());
System.out.println(request.getResumptionToken() + " exists: " + RecordListDelivererDC.cursorCollector.containsKey(request.getResumptionToken()));
boolean restokIDIOMExisting = RecordListDelivererDC.cursorCollector != null boolean restokIDIOMExisting = RecordListDelivererDC.cursorCollector != null
&& RecordListDelivererDC.cursorCollector.containsKey(request.getResumptionToken()); && RecordListDelivererDC.cursorCollector.containsKey(request.getResumptionToken());
if (restokDCExisting || restokIDIOMExisting) { if (!restokDCExisting || !restokIDIOMExisting) {
result.setError(TGConstants.OAI_BAD_RESUMPTION_TOKEN, "The value of the " System.out.println("BUHUH");
result.setError(TGConstants.OAI_BAD_RESUMPTION_TOKEN, "The value of the "
+ request.getResumptionToken() + " argument is invalid or expired."); + request.getResumptionToken() + " argument is invalid or expired.");
} }
} }
List<String> errorValues = new ArrayList<String>(); List<String> errorValues = new ArrayList<String>();
if (request.getResumptionToken() != null && request.getMetadataPrefix() != null) {
errorValues.add("metadataPrefix");
}
if (request.getResumptionToken() == null && request.getMetadataPrefix() == null) { if (request.getResumptionToken() == null && request.getMetadataPrefix() == null) {
errorValues.add("metadataPrefix"); errorValues.add("metadataPrefix");
} }
......
...@@ -251,9 +251,8 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -251,9 +251,8 @@ public class OAIPMHImpl implements OAIPMHProducer {
if (getRecord != null) { if (getRecord != null) {
oaipmhRoot.setGetRecord(getRecord); oaipmhRoot.setGetRecord(getRecord);
} else { } else {
ErrorHandler idError = new ErrorHandler(); ErrorHandler idError = new ErrorHandler();
idError.setError(TGConstants.OAI_NO_RECORD_MATCH, "The value of the identifier: " idError.setError(TGConstants.OAI_ID_DOES_NOT_EXIST, "No matching identifier ");
+ request.getIdentifier() + " is unknown or illegal in this repository");
oaipmhRoot.getError().add(idError.getError()); oaipmhRoot.getError().add(idError.getError());
} }
} }
...@@ -322,7 +321,7 @@ public class OAIPMHImpl implements OAIPMHProducer { ...@@ -322,7 +321,7 @@ public class OAIPMHImpl implements OAIPMHProducer {
oaipmhRoot.getError().add(requestErrors.getError()); oaipmhRoot.getError().add(requestErrors.getError());
} else { } else {
oaipmhRoot.setListIdentifiers(listIdentifiers); oaipmhRoot.setListIdentifiers(listIdentifiers);
} }
} else { } else {
ErrorHandler idError = new ErrorHandler(); ErrorHandler idError = new ErrorHandler();
idError.setError(TGConstants.OAI_NO_RECORD_MATCH, "The value of the identifier: " idError.setError(TGConstants.OAI_NO_RECORD_MATCH, "The value of the identifier: "
......
...@@ -3,6 +3,7 @@ package info.textgrid.middleware; ...@@ -3,6 +3,7 @@ package info.textgrid.middleware;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigInteger; import java.math.BigInteger;
import java.text.DateFormat;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -280,5 +281,42 @@ public class OAIPMHUtilities { ...@@ -280,5 +281,42 @@ public class OAIPMHUtilities {
return null; return null;
} }
public static boolean isThisDateValid(String dateToValidate){
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.S");
dateFormat.setLenient(false);
try {
dateFormat.parse(dateToValidate.trim());
} catch (ParseException pe) {
return false;
}
return true;
}
private static final String[] formats = {
"yyyy-MM-dd'T'HH:mm:ss'Z'", "yyyy-MM-dd'T'HH:mm:ssZ",
"yyyy-MM-dd'T'HH:mm:ss", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'",
"yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd HH:mm:ss",
"MM/dd/yyyy HH:mm:ss", "MM/dd/yyyy'T'HH:mm:ss.SSS'Z'",
"MM/dd/yyyy'T'HH:mm:ss.SSSZ", "MM/dd/yyyy'T'HH:mm:ss.SSS",
"MM/dd/yyyy'T'HH:mm:ssZ", "MM/dd/yyyy'T'HH:mm:ss",
"yyyy:MM:dd HH:mm:ss", "yyyyMMdd", };
public static String getFormatOfDate(String d) {
if (d != null) {
for (String parse : formats) {
SimpleDateFormat sdf = new SimpleDateFormat(parse);
try {
sdf.parse(d);
return parse;
} catch (ParseException e) {
}
}
}
return d;
}
} }
...@@ -29,6 +29,7 @@ public abstract class RecordListDelivererAbstract implements RecordListDeliverer ...@@ -29,6 +29,7 @@ public abstract class RecordListDelivererAbstract implements RecordListDeliverer
ErrorHandler result = new ErrorHandler(); ErrorHandler result = new ErrorHandler();
// Check if metadata prefix is existing and valid. // Check if metadata prefix is existing and valid.
if (request.getMetadataPrefix() != null if (request.getMetadataPrefix() != null
&& !request.getMetadataPrefix().equals(OAIPMHUtilities.OAIDC_PREFIX) && !request.getMetadataPrefix().equals(OAIPMHUtilities.OAIDC_PREFIX)
...@@ -41,16 +42,20 @@ public abstract class RecordListDelivererAbstract implements RecordListDeliverer ...@@ -41,16 +42,20 @@ public abstract class RecordListDelivererAbstract implements RecordListDeliverer
// Check if resumptionToken is invalid or existing. // Check if resumptionToken is invalid or existing.
if (request.getResumptionToken() != null) { if (request.getResumptionToken() != null) {
boolean restokDCExisting = RecordListDelivererIDIOM.cursorCollector != null boolean restokDCExisting = RecordListDelivererIDIOM.cursorCollector != null
&& RecordListDelivererIDIOM.cursorCollector.containsKey(request.getResumptionToken()); && RecordListDelivererIDIOM.cursorCollector.containsKey(request.getResumptionToken());
boolean restokIDIOMExisting = RecordListDelivererDC.cursorCollector != null System.out.println(request.getResumptionToken() + " exists: " + RecordListDelivererDC.cursorCollector.containsKey(request.getResumptionToken()));
&& RecordListDelivererDC.cursorCollector.containsKey(request.getResumptionToken()); boolean restokIDIOMExisting = RecordListDelivererDC.cursorCollector != null
if (restokDCExisting || restokIDIOMExisting) { && RecordListDelivererDC.cursorCollector.containsKey(request.getResumptionToken());
result.setError(TGConstants.OAI_BAD_RESUMPTION_TOKEN, "The value of the " if (!restokDCExisting || !restokIDIOMExisting) {
+ request.getResumptionToken() + " argument is invalid or expired."); System.out.println("BUHUH");
result.setError(TGConstants.OAI_BAD_RESUMPTION_TOKEN, "The value of the "
+ request.getResumptionToken() + " argument is invalid or expired.");
}
} }
}
// Check if query to ElastisSearch responses with more then zero results // Check if query to ElastisSearch responses with more then zero results
// FIXME what the heck? // FIXME what the heck?
if (true) { if (true) {
...@@ -60,15 +65,21 @@ public abstract class RecordListDelivererAbstract implements RecordListDeliverer ...@@ -60,15 +65,21 @@ public abstract class RecordListDelivererAbstract implements RecordListDeliverer
// Check params in general. // Check params in general.
List<String> errorValues = new ArrayList<String>(); List<String> errorValues = new ArrayList<String>();
if (request.getResumptionToken() != null && request.getMetadataPrefix() != null) {
errorValues.add("metadataPrefix");
}
if (request.getResumptionToken() == null && request.getMetadataPrefix() == null) { if (request.getResumptionToken() == null && request.getMetadataPrefix() == null) {
errorValues.add("metadataPrefix"); errorValues.add("metadataPrefix");
} }
if (request.getIdentifier() != null) { if (request.getIdentifier() != null) {
errorValues.add("identifier"); errorValues.add("identifier");
} }
if(request.getFrom()!= null && !OAIPMHUtilities.isThisDateValid(request.getFrom())) {
errorValues.add("from");
}
if(request.getUntil() != null && !OAIPMHUtilities.isThisDateValid(request.getUntil())) {
errorValues.add("until");
}
if(OAIPMHUtilities.getFormatOfDate(request.getFrom()).equals(OAIPMHUtilities.getFormatOfDate(request.getFrom()))) {
errorValues.add("The granularities for from and until doesn't match");
}
if (errorValues.size() > 0) { if (errorValues.size() > 0) {
result.setError(TGConstants.OAI_BAD_ARGUMENT, "The request includes illegal arguments " result.setError(TGConstants.OAI_BAD_ARGUMENT, "The request includes illegal arguments "
+ "or is missing required arguments: " + errorValues); + "or is missing required arguments: " + errorValues);
...@@ -76,5 +87,6 @@ public abstract class RecordListDelivererAbstract implements RecordListDeliverer ...@@ -76,5 +87,6 @@ public abstract class RecordListDelivererAbstract implements RecordListDeliverer
return result; return result;
} }
} }
...@@ -34,6 +34,8 @@ public final class TGConstants { ...@@ -34,6 +34,8 @@ public final class TGConstants {
public static final String OAI_NO_RECORD_MATCH = "RecordMatchError"; public static final String OAI_NO_RECORD_MATCH = "RecordMatchError";
public static final String OAI_NO_SET_HIERARCHY = "SetHierarchyError"; public static final String OAI_NO_SET_HIERARCHY = "SetHierarchyError";
public static final String OAI_BAD_RESUMPTION_TOKEN = "badResumptionToken"; public static final String OAI_BAD_RESUMPTION_TOKEN = "badResumptionToken";
public static final String OAI_ID_DOES_NOT_EXIST = "idDoesNotExist";
public static final String OAI_TIMESTAMP_ERROR = "cannotDisseminateFormat";
// TextGrid Metadata Fields for OAI-PMH Request (Mapping to DC) // TextGrid Metadata Fields for OAI-PMH Request (Mapping to DC)
public static final String CREATED = "created"; public static final String CREATED = "created";
......
...@@ -159,6 +159,17 @@ public class OaiPmhTest { ...@@ -159,6 +159,17 @@ public class OaiPmhTest {
System.out.println("-----------------------------------\n"); System.out.println("-----------------------------------\n");
} }
/**
* @throws ParseException
*/
@Test
@Ignore
public void testGetDateFormat() throws ParseException {
System.out.println("Test get time format");
System.out.println(OAIPMHUtilities.getFormatOfDate("2019-12-02T15:36:13Z"));
System.out.println("-----------------------------------\n");
}
/** /**
* @throws ParseException * @throws ParseException
*/ */
...@@ -190,7 +201,7 @@ public class OaiPmhTest { ...@@ -190,7 +201,7 @@ public class OaiPmhTest {
record.setIdentifierField("textgridUri"); record.setIdentifierField("textgridUri");
System.out.println("Test for the verb \"GetRecord\" with succesfull response"); System.out.println("Test for the verb \"GetRecord\" with succesfull response");
String p = this.request.getRequest("GetRecord", "textgrid:vqn0.0", "oai_dc", "", "", "", ""); String p = this.request.getRequest("GetRecord", "identifier\"id", "oai_dc", "", "", "", "");
System.out.println(p); System.out.println(p);
System.out.println("-----------------------------------\n"); System.out.println("-----------------------------------\n");
} }
...@@ -233,8 +244,7 @@ public class OaiPmhTest { ...@@ -233,8 +244,7 @@ public class OaiPmhTest {
OaiPmhTest.identifierList.setIdentifierField("textgridUri"); OaiPmhTest.identifierList.setIdentifierField("textgridUri");
OaiPmhTest.identifierList.setSearchResponseSize("100"); OaiPmhTest.identifierList.setSearchResponseSize("100");
System.out.println("Test for the verb \"ListIdentifiers\" with succesfull response"); System.out.println("Test for the verb \"ListIdentifiers\" with succesfull response");
String p = this.request.getRequest("ListIdentifiers", "", "oai_dc", String p = this.request.getRequest("ListIdentifiers", "", "oai_dc", "", "2000-02-05", "", "junk");
"project:TGPR-26236625-1acc-b921-a5fa-53567c3eeb80", "", "", "");
System.out.println(p); System.out.println(p);
System.out.println("-----------------------------------\n"); System.out.println("-----------------------------------\n");
} }
...@@ -337,7 +347,7 @@ public class OaiPmhTest { ...@@ -337,7 +347,7 @@ public class OaiPmhTest {
System.out.println("Test for the verb \"ListRecords\" with sets with succesfull response"); System.out.println("Test for the verb \"ListRecords\" with sets with succesfull response");
//String p = this.request.getRequest("ListRecords", "", "oai_dc", "project:TGPR-f89ad029-4eb2-ae5c-6028-5db876513128", "", "", ""); //String p = this.request.getRequest("ListRecords", "", "oai_dc", "project:TGPR-f89ad029-4eb2-ae5c-6028-5db876513128", "", "", "");
String p = this.request.getRequest("ListRecords", "", "oai_dc", "", "2012-05-09T00:33:55.364+02:00", "2012-05-09T00:33:55.364+02:00", ""); String p = this.request.getRequest("ListRecords", "", "oai_dc", "", "2012-05-09T00:33:55.364+02:00", "2012-05-09", "");
System.out.println(p); System.out.println(p);
String resToken = ""; String resToken = "";
/*for (Map.Entry<String, Integer> entry : RecordListDelivererDC.cursorCollector.entrySet()) { /*for (Map.Entry<String, Integer> entry : RecordListDelivererDC.cursorCollector.entrySet()) {
...@@ -414,7 +424,7 @@ public class OaiPmhTest { ...@@ -414,7 +424,7 @@ public class OaiPmhTest {
OaiPmhTest.recordList.setModifiedField(TGConstants.CREATED); OaiPmhTest.recordList.setModifiedField(TGConstants.CREATED);
OaiPmhTest.recordList.setIdentifierField(TGConstants.URI); OaiPmhTest.recordList.setIdentifierField(TGConstants.URI);
OaiPmhTest.recordList.setSearchResponseSize("100"); OaiPmhTest.recordList.setSearchResponseSize("100");
String r = this.request.getRequest("ListRecords", "", "oai_dc", "", "", "", ""); String r = this.request.getRequest("ListRecords", "", "oai_dc", "", "2002-02-06T05:35:00Z", "", "");
System.out.println(r); System.out.println(r);
System.out.println("-----------------------------------\n"); System.out.println("-----------------------------------\n");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment