diff --git a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java index f0a0387655106dbaa3120ceb2d78fa35f36dd5c4..95fc76efebea806b070b89e94fb6495dacd69dc5 100644 --- a/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java +++ b/oaipmh-core/src/main/java/info/textgrid/middleware/OAIPMHImpl.java @@ -41,7 +41,8 @@ import org.apache.commons.logging.LogFactory; public class OAIPMHImpl implements OAIPMHProducer { private ErrorHandler error = new ErrorHandler(); - private org.apache.commons.logging.Log log = LogFactory.getLog(OAIPMHImpl.class); + private org.apache.commons.logging.Log log = LogFactory + .getLog(OAIPMHImpl.class); private OAI_ESClient oaiEsClient; private RepIdentification rep; private RecordListDeliverer recordList; @@ -49,8 +50,8 @@ public class OAIPMHImpl implements OAIPMHProducer { private MetadataFormatListDeliverer metadataFormatList; private SetDeliverer setList; private IdentifierListDeliverer identifierList; - public boolean textgrid; - public boolean dariah; + public boolean textgrid; + public boolean dariah; ListIdentifiersType lit = new ListIdentifiersType(); @@ -86,15 +87,11 @@ public class OAIPMHImpl implements OAIPMHProducer { @QueryParam("until") @DefaultValue("") String until, @QueryParam("resumptionToken") @DefaultValue("") String resumptionToken) { - - ObjectFactory obf = new ObjectFactory(); OAIPMHType response = new OAIPMHType(); JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(response); VerbType verbParam = setVerb(verb); RequestType request = new RequestType(); - - /*----Setting the responseDate of today-----*/ try { @@ -117,7 +114,8 @@ public class OAIPMHImpl implements OAIPMHProducer { setMetadataPrefixRequestValue(metadataPrefix, request); setResumptionTokenRequestValue(resumptionToken, request); setSetRequestValue(set, request); - setVerbRequestValue(verb, verbParam, request); + + request.setVerb(verbParam); if (textgrid == true) { request.setValue(TGConstants.TG_REP_BASEURL); @@ -126,8 +124,6 @@ public class OAIPMHImpl implements OAIPMHProducer { request.setValue(DARIAHConstants.DARIAH_REP_BASEURL); } - - if (verbParam != null) { if (verbParam.value().equals("Identify")) { oaipmhRoot = identifyRequest(obf, response, request); @@ -149,9 +145,8 @@ public class OAIPMHImpl implements OAIPMHProducer { oaipmhRoot = listRecordsRequest(obf, response, request); } } else { - response.getError().add(error.setError("VerbError")); - - + response.getError().add(error.setError("VerbError")); + } response.setRequest(request); @@ -176,12 +171,17 @@ public class OAIPMHImpl implements OAIPMHProducer { if (rep.requestChecker(request)) { tgRepIdentificationRequest.setBaseURL(rep.getBaseUrl()); - tgRepIdentificationRequest.setDeletedRecord(rep.getDeletedRecordStatus()); - tgRepIdentificationRequest.setEarliestDatestamp(rep.getEarliestDatestamp()); + tgRepIdentificationRequest.setDeletedRecord(rep + .getDeletedRecordStatus()); + tgRepIdentificationRequest.setEarliestDatestamp(rep + .getEarliestDatestamp()); tgRepIdentificationRequest.setGranularity(rep.getGranularity()); - tgRepIdentificationRequest.setRepositoryName(rep.getRepositoryName()); - tgRepIdentificationRequest.setProtocolVersion(rep.getProtocolVersion()); - tgRepIdentificationRequest.getAdminEmail().add(rep.getAdminMaiAddresss()); + tgRepIdentificationRequest.setRepositoryName(rep + .getRepositoryName()); + tgRepIdentificationRequest.setProtocolVersion(rep + .getProtocolVersion()); + tgRepIdentificationRequest.getAdminEmail().add( + rep.getAdminMaiAddresss()); oai.setIdentify(tgRepIdentificationRequest); } else { @@ -224,13 +224,16 @@ public class OAIPMHImpl implements OAIPMHProducer { // TGConstants.TGFields); JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai); - if (request.getMetadataPrefix() != null && !request.getMetadataPrefix().equals("oai_dc")) { - error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR).setValue( + if (request.getMetadataPrefix() != null + && !request.getMetadataPrefix().equals("oai_dc")) { + error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR) + .setValue( "The value of the metadataPrefix: " + request.getMetadataPrefix() + " is not supported by the item identified by the value of: " + request.getIdentifier()); - oai.getError().add( error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR)); + oai.getError().add( + error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR)); } else if (recDeliv.requestChecker(request)) { @@ -248,7 +251,8 @@ public class OAIPMHImpl implements OAIPMHProducer { "The value of the identifier: " + request.getIdentifier() + " is unknown or illegal in this repository"); - oai.getError().add(error.setError(TGConstants.OAI_NO_RECORD_MATCH)); + oai.getError().add( + error.setError(TGConstants.OAI_NO_RECORD_MATCH)); } } else { @@ -292,105 +296,117 @@ public class OAIPMHImpl implements OAIPMHProducer { List<String> errorValues = new ArrayList<String>(); JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai); - //if (identifierList.requestChecker(request)) { - - if(request.getResumptionToken() != null && request.getMetadataPrefix() != null){ - errorValues.add("MetadataPrefix"); - error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue("The request includes illegal arguments or missing requiered arguments:" + errorValues); - oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT)); - }else if(request.getResumptionToken() != null && request.getSet() != null){ - errorValues.add("Set"); - error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue("The request includes illegal arguments or missing requiered arguments:" + errorValues); - oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT)); - }else if(request.getResumptionToken() == null && request.getMetadataPrefix() == null){ - errorValues.add("MetadataPrefix"); - error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue("The request includes illegal arguments or missing requiered arguments:" + errorValues); - oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT)); - }else if (request.getMetadataPrefix() != null && !request.getMetadataPrefix().equals(TGConstants.METADATA_DC_PREFIX )){ - error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR).setValue("The value of the metadataPrefix: " - + request.getMetadataPrefix() - + " is not supported by the item identified by the value of: " - + request.getIdentifier()); - oai.getError().add(error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR)); - } - else{ - System.out.println("bla1000"); - if(request.getResumptionToken() != null && RecordListDeliverer.cursorCollector.containsKey(request.getResumptionToken())){ - error.setError(TGConstants.OAI_BAD_RESUMPTION_TOKEN).setValue("The value of the resumptionToken argument is invalid or expired"); - oai.getError().add(error.setError(TGConstants.OAI_BAD_RESUMPTION_TOKEN)); - }else { - lit = identifierList.processIdentifierList(request.getFrom(), request.getUntil(), request.getSet(), request.getResumptionToken()); - if (lit != null) { - System.out.println("bla2000"); - oai.setListIdentifiers(lit); - } else { - error.setError(TGConstants.OAI_NO_RECORD_MATCH).setValue("The combination of the values " - + request.getFrom() + " and " - + request.getUntil() - + " results in an empty list"); - oai.getError().add(error.setError(TGConstants.OAI_NO_RECORD_MATCH)); - } - } - } - - //} - - - - /*if(request.getResumptionToken() != null && (request.getSet() != null || request.getMetadataPrefix() != null)){ - error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue( - "The request includes illegal arguments or missing requiered arguments:" + errorValues); - oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT)); - } - else { - - - if (request.getMetadataPrefix() != null && !request.getMetadataPrefix().equals(TGConstants.METADATA_DC_PREFIX )) { - try { - error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR).setValue("The value of the metadataPrefix: " - + request.getMetadataPrefix() - + " is not supported by the item identified by the value of: " - + request.getIdentifier()); - oai.getError().add(error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR)); + // if (identifierList.requestChecker(request)) { - } catch (Exception e) { - // TODO Auto-generated catch block - log.debug(e); - } + if (request.getResumptionToken() != null + && request.getMetadataPrefix() != null) { + errorValues.add("MetadataPrefix"); + error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue( + "The request includes illegal arguments or missing requiered arguments:" + + errorValues); + oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT)); + } else if (request.getResumptionToken() != null + && request.getSet() != null) { + errorValues.add("Set"); + error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue( + "The request includes illegal arguments or missing requiered arguments:" + + errorValues); + oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT)); + } else if (request.getResumptionToken() == null + && request.getMetadataPrefix() == null) { + errorValues.add("MetadataPrefix"); + error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue( + "The request includes illegal arguments or missing requiered arguments:" + + errorValues); + oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT)); + } else if (request.getMetadataPrefix() != null + && !request.getMetadataPrefix().equals( + TGConstants.METADATA_DC_PREFIX)) { + error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR) + .setValue( + "The value of the metadataPrefix: " + + request.getMetadataPrefix() + + " is not supported by the item identified by the value of: " + + request.getIdentifier()); + oai.getError().add( + error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR)); + } else { + System.out.println("bla1000"); + if (request.getResumptionToken() != null + && RecordListDeliverer.cursorCollector.containsKey(request + .getResumptionToken())) { + error.setError(TGConstants.OAI_BAD_RESUMPTION_TOKEN) + .setValue( + "The value of the resumptionToken argument is invalid or expired"); + oai.getError().add( + error.setError(TGConstants.OAI_BAD_RESUMPTION_TOKEN)); } else { - try { - lit = identifierList.processIdentifierList(request.getFrom(), request.getUntil(), request.getSet(), request.getResumptionToken()); - if (lit != null) { - oai.setListIdentifiers(lit); - } else { - error.setError(TGConstants.OAI_NO_RECORD_MATCH).setValue("The combination of the values " - + request.getFrom() + " and " - + request.getUntil() - + " results in an empty list"); - oai.getError().add(error.setError(TGConstants.OAI_NO_RECORD_MATCH)); - } - - } catch (Exception e) { - // TODO Auto-generated catch block - log.debug(e); + lit = identifierList.processIdentifierList(request.getFrom(), + request.getUntil(), request.getSet(), + request.getResumptionToken()); + if (lit != null) { + System.out.println("bla2000"); + oai.setListIdentifiers(lit); + } else { + error.setError(TGConstants.OAI_NO_RECORD_MATCH).setValue( + "The combination of the values " + + request.getFrom() + " and " + + request.getUntil() + + " results in an empty list"); + oai.getError().add( + error.setError(TGConstants.OAI_NO_RECORD_MATCH)); } } - - } - - } else { - if (request.getIdentifier() != null) { - errorValues.add("identifier"); - } - if (request.getMetadataPrefix() == null) { - errorValues.add("metadataPrefix"); - } - error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue( - "The request includes illegal arguments " - + "or missing requiered arguments: " + errorValues); - oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT)); + } - }*/ + // } + + /* + * if(request.getResumptionToken() != null && (request.getSet() != null + * || request.getMetadataPrefix() != null)){ + * error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue( + * "The request includes illegal arguments or missing requiered arguments:" + * + errorValues); + * oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT)); } + * else { + * + * + * if (request.getMetadataPrefix() != null && + * !request.getMetadataPrefix().equals(TGConstants.METADATA_DC_PREFIX )) + * { try { + * error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR).setValue + * ("The value of the metadataPrefix: " + request.getMetadataPrefix() + + * " is not supported by the item identified by the value of: " + + * request.getIdentifier()); + * oai.getError().add(error.setError(TGConstants + * .OAI_METADATA_FORMAT_ERROR)); + * + * } catch (Exception e) { // TODO Auto-generated catch block + * log.debug(e); } } else { try { lit = + * identifierList.processIdentifierList(request.getFrom(), + * request.getUntil(), request.getSet(), request.getResumptionToken()); + * if (lit != null) { oai.setListIdentifiers(lit); } else { + * error.setError(TGConstants.OAI_NO_RECORD_MATCH).setValue( + * "The combination of the values " + request.getFrom() + " and " + + * request.getUntil() + " results in an empty list"); + * oai.getError().add(error.setError(TGConstants.OAI_NO_RECORD_MATCH)); + * } + * + * } catch (Exception e) { // TODO Auto-generated catch block + * log.debug(e); } } + * + * } + * + * } else { if (request.getIdentifier() != null) { + * errorValues.add("identifier"); } if (request.getMetadataPrefix() == + * null) { errorValues.add("metadataPrefix"); } + * error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue( + * "The request includes illegal arguments " + + * "or missing requiered arguments: " + errorValues); + * oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT)); + * + * } + */ return oaipmhRoot; } @@ -444,7 +460,8 @@ public class OAIPMHImpl implements OAIPMHProducer { "The value of the identifier: " + request.getIdentifier() + " is unknown or illegal in this repository"); - oai.getError().add(error.setError(TGConstants.OAI_NO_RECORD_MATCH)); + oai.getError().add( + error.setError(TGConstants.OAI_NO_RECORD_MATCH)); } } else { if (request.getFrom() != null) { @@ -475,83 +492,89 @@ public class OAIPMHImpl implements OAIPMHProducer { public JAXBElement<OAIPMHType> listRecordsRequest(ObjectFactory obf, OAIPMHType oai, RequestType request) { - //System.out.println("blablablabla"); + // System.out.println("blablablabla"); List<String> errorValues = new ArrayList<String>(); ListRecordsType listRecords = new ListRecordsType(); - //RecordListDeliverer recordList = new RecordListDeliverer(oaiEsClient,// TGConstants.TGFields); + // RecordListDeliverer recordList = new + // RecordListDeliverer(oaiEsClient,// TGConstants.TGFields); JAXBElement<OAIPMHType> oaipmhRoot = obf.createOAIPMH(oai); - - if(request.getResumptionToken() != null && request.getMetadataPrefix() != null){ + + if (request.getResumptionToken() != null + && request.getMetadataPrefix() != null) { errorValues.add("MetadataPrefix"); - error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue("The request includes illegal arguments or missing requiered arguments:" + errorValues); - oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT)); - }else if(request.getResumptionToken() != null && request.getSet() != null){ + error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue( + "The request includes illegal arguments or missing requiered arguments:" + + errorValues); + oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT)); + } else if (request.getResumptionToken() != null + && request.getSet() != null) { errorValues.add("Set"); - error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue("The request includes illegal arguments or missing requiered arguments:" + errorValues); - oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT)); - } - else if(request.getResumptionToken() == null && request.getMetadataPrefix() == null){ + error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue( + "The request includes illegal arguments or missing requiered arguments:" + + errorValues); + oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT)); + } else if (request.getResumptionToken() == null + && request.getMetadataPrefix() == null) { errorValues.add("MetadataPrefix"); - error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue("The request includes illegal arguments or missing requiered arguments:" + errorValues); - oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT)); - }else if (request.getMetadataPrefix() != null && !request.getMetadataPrefix().equals(TGConstants.METADATA_DC_PREFIX )){ - error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR).setValue("The value of the metadataPrefix: " - + request.getMetadataPrefix() - + " is not supported by the item identified by the value of: " - + request.getIdentifier()); - oai.getError().add(error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR)); - } - else{ - listRecords = recordList.getRecords(request.getFrom(), request.getUntil(), request.getSet(), request.getResumptionToken()); - if (listRecords != null) { + error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue( + "The request includes illegal arguments or missing requiered arguments:" + + errorValues); + oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT)); + } else if (request.getMetadataPrefix() != null + && !request.getMetadataPrefix().equals( + TGConstants.METADATA_DC_PREFIX)) { + error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR) + .setValue( + "The value of the metadataPrefix: " + + request.getMetadataPrefix() + + " is not supported by the item identified by the value of: " + + request.getIdentifier()); + oai.getError().add( + error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR)); + } else { + listRecords = recordList.getRecords(request.getFrom(), + request.getUntil(), request.getSet(), + request.getResumptionToken()); + if (listRecords != null) { oai.setListRecords(listRecords); } else { - error.setError(TGConstants.OAI_NO_RECORD_MATCH).setValue("The combination of the values " - + request.getFrom() + " and " - + request.getUntil() - + " results in an empty list"); - oai.getError().add(error.setError(TGConstants.OAI_NO_RECORD_MATCH)); + error.setError(TGConstants.OAI_NO_RECORD_MATCH).setValue( + "The combination of the values " + request.getFrom() + + " and " + request.getUntil() + + " results in an empty list"); + oai.getError().add( + error.setError(TGConstants.OAI_NO_RECORD_MATCH)); } } - - - /*if (recordList.requestChecker(request)) { - - if (!request.getMetadataPrefix().equals(TGConstants.METADATA_DC_PREFIX)) { - error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR).setValue( - "The value of the metadataPrefix: " - + request.getMetadataPrefix() - + " is not supported by the item identified by the value of: " - + request.getIdentifier()); - oai.getError().add(error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR)); - } else { - //System.out.println("SET FROM REQUEST: " + request.getSet()); - listRecords = recordList.getRecords(request.getFrom(), request.getUntil(), request.getSet(), request.getResumptionToken()); - if (recordList.isFoundItems()) { - // if(listRecords!=null){ - oai.setListRecords(listRecords); - } else { - error.setError(TGConstants.OAI_NO_RECORD_MATCH).setValue( - "The combination of the values " - + request.getFrom() + " and " - + request.getUntil() - + " results in an empty list"); - oai.getError().add(error.setError(TGConstants.OAI_NO_RECORD_MATCH)); - } - } - } else { - if (request.getIdentifier() != null) { - errorValues.add("identifier"); - } - if (request.getMetadataPrefix() == null) { - errorValues.add("metadataPrefix"); - } - error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue( - "The request includes illegal " - + "arguments or is missing required arguments: " - + errorValues); - oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT)); - }*/ + + /* + * if (recordList.requestChecker(request)) { + * + * if + * (!request.getMetadataPrefix().equals(TGConstants.METADATA_DC_PREFIX)) + * { error.setError(TGConstants.OAI_METADATA_FORMAT_ERROR).setValue( + * "The value of the metadataPrefix: " + request.getMetadataPrefix() + + * " is not supported by the item identified by the value of: " + + * request.getIdentifier()); + * oai.getError().add(error.setError(TGConstants + * .OAI_METADATA_FORMAT_ERROR)); } else { + * //System.out.println("SET FROM REQUEST: " + request.getSet()); + * listRecords = recordList.getRecords(request.getFrom(), + * request.getUntil(), request.getSet(), request.getResumptionToken()); + * if (recordList.isFoundItems()) { // if(listRecords!=null){ + * oai.setListRecords(listRecords); } else { + * error.setError(TGConstants.OAI_NO_RECORD_MATCH).setValue( + * "The combination of the values " + request.getFrom() + " and " + + * request.getUntil() + " results in an empty list"); + * oai.getError().add(error.setError(TGConstants.OAI_NO_RECORD_MATCH)); + * } } } else { if (request.getIdentifier() != null) { + * errorValues.add("identifier"); } if (request.getMetadataPrefix() == + * null) { errorValues.add("metadataPrefix"); } + * error.setError(TGConstants.OAI_BAD_ARGUMENT).setValue( + * "The request includes illegal " + + * "arguments or is missing required arguments: " + errorValues); + * oai.getError().add(error.setError(TGConstants.OAI_BAD_ARGUMENT)); } + */ return oaipmhRoot; } @@ -567,9 +590,12 @@ public class OAIPMHImpl implements OAIPMHProducer { public VerbType setVerb(String verb) { VerbType verbParam = null; - if (verb == null || verb.equals("Identify")) { + if (verb == null) { + verb = "Identify"; + } + + if (verb != null && verb.equals("Identify")) { verbParam = VerbType.IDENTIFY; - return verbParam; } else if (verb != null && verb.equals("ListMetadataFormats")) { verbParam = VerbType.LIST_METADATA_FORMATS; } else if (verb != null && verb.equals("ListSets")) { @@ -671,22 +697,6 @@ public class OAIPMHImpl implements OAIPMHProducer { } } - /** - * Setting the from value for the request - * - * @param verb - * : String value from REST request - * @param verbParam - * : OAIPMH verb type - */ - - public void setVerbRequestValue(String verb, VerbType verbParam, - RequestType request) { - - if (!verb.isEmpty()) { - request.setVerb(verbParam); - } - } public RequestType setRequestType(String verb) {