Skip to content
Snippets Groups Projects
Commit e2834dd2 authored by Stefan E. Funk's avatar Stefan E. Funk
Browse files

fix: refactor textgrid URI usage (URI <--> base URI)

parent 2a1d8424
No related branches found
No related tags found
No related merge requests found
......@@ -676,6 +676,21 @@ public class OAIPMHUtilities {
return result;
}
/**
* @param theURI
* @return
*/
public static String getTextGridBaseURI(String theURI) {
String result = theURI;
if (theURI.contains(".")) {
result = theURI.substring(0, theURI.indexOf('.')).trim();
}
return result;
}
// **
// GETTERS & SETTERS
// **
......
......@@ -24,14 +24,28 @@ import info.textgrid.middleware.oaipmh.RecordType;
/**
* @author Maximilian Brodhun, SUB Göttingen
* @author Stefan E. Funk, SUB Göttingen
* @version 2022-09-23
* @version 2022-09-27
* @since 2019-03-12
*/
@Component
public class RecordDelivererIDIOM extends RecordDelivererAbstract {
// **
// FINALS
// **
private static final String TEXTGRID_URI_PREFIX = "textgrid:";
// **
// STATICS
// **
private static Logger log = Logger.getLogger(RecordDelivererIDIOM.class.getName());
// **
// CLASS
// **
private IDIOMImages idiomImages;
private RecordType record = new RecordType();
......@@ -55,33 +69,32 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract {
* @throws IOException
*/
@Override
public GetRecordType getRecordById(String id) throws ParseException, IOException {
public GetRecordType getRecordById(final String id) throws ParseException, IOException {
GetRecordType grt = new GetRecordType();
log.fine("identifier: " + id);
log.fine("incoming ID: " + id);
setDatestampsAndObjectType(id);
// Get TG URI and TG base URI from ID.
String tgURI = id;
if (!id.startsWith("textgrid:")) {
tgURI = "textgrid:" + id;
// Get TG URI from ID.
String textgridURI = id;
if (!id.startsWith(TEXTGRID_URI_PREFIX)) {
textgridURI = TEXTGRID_URI_PREFIX + id;
}
String tgBaseURI = tgURI;
// FIXME Why we only replace ".0" here??
tgBaseURI = tgBaseURI.replace(".0", "");
log.fine("tg uri/base uri: " + tgURI + "/" + tgBaseURI);
// Get base URI for ClassicMayanMetsMods and response header here.
String textgridBaseURI = OAIPMHUtilities.getTextGridBaseURI(textgridURI);
log.fine("textgrid uri/base uri: " + textgridURI + "/" + textgridBaseURI);
log.fine("object type is: " + this.objectType);
log.fine(this.objectType + " doc/dom: " + this.dateOfObjectCreation + "/"
+ this.dateOfLastObjectModification);
if (this.objectType.equals("ARTEFACT")) {
try {
ClassicMayanMetsMods metsmods = new ClassicMayanMetsMods(
tgBaseURI,
textgridBaseURI,
this.dateOfObjectCreation,
this.dateOfLastObjectModification);
......@@ -101,7 +114,7 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract {
log.fine("calling idiom image getRecordById()");
GetRecordType idi = this.idiomImages.getRecordById(id);
GetRecordType idi = this.idiomImages.getRecordById(textgridURI);
// Fixes #64
if (idi != null) {
......@@ -109,21 +122,11 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract {
}
}
// See, that IDs have NO revision number.
// FIXME Why we replace ALL revision numbers here?? Is there a difference to tgBaseURI with ".0"
// and ".n"??
String identifierToSet = tgURI;
if (identifierToSet.contains(".")) {
identifierToSet = identifierToSet.substring(0, identifierToSet.indexOf("."));
}
log.fine("identifier to set: " + identifierToSet);
// No setSpec needed here!
// TODO Why not??
String setSpec = "";
HeaderType header =
OAIPMHUtilities.computeResponseHeader(this.dateOfObjectCreation, identifierToSet,
setSpec);
OAIPMHUtilities.computeResponseHeader(this.dateOfObjectCreation, textgridURI, setSpec);
this.record.setHeader(header);
grt.setRecord(this.record);
......@@ -174,20 +177,16 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract {
* @throws ParseException
* @throws IOException
*/
private void setDatestampsAndObjectType(String idInDatabase) throws ParseException, IOException {
private void setDatestampsAndObjectType(final String idInDatabase)
throws ParseException, IOException {
String changedId = idInDatabase;
if (idInDatabase.startsWith("textgrid:")) {
changedId = idInDatabase.substring("textgrid:".length());
// Remove prefix.
if (idInDatabase.startsWith(TEXTGRID_URI_PREFIX)) {
changedId = idInDatabase.substring(TEXTGRID_URI_PREFIX.length());
}
if (!idInDatabase.contains(".0")) {
changedId = changedId + ".0";
}
log.fine("changedId: " + changedId);
JSONObject json = new JSONObject();
String[] searchFields = {TGConstants.CREATED, TGConstants.MODIFIED_FIELD, "notes"};
......@@ -203,7 +202,6 @@ public class RecordDelivererIDIOM extends RecordDelivererAbstract {
this.objectType = OAIPMHUtilities.fieldLoader(json, "notes");
}
// **
// GETTERS & SETTERS
// **
......
......@@ -16,7 +16,6 @@ import org.elasticsearch.index.query.RangeQueryBuilder;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.json.JSONObject;
import info.textgrid.middleware.oaipmh.GetRecordType;
import info.textgrid.middleware.oaipmh.ListRecordsType;
import info.textgrid.middleware.oaipmh.RecordType;
import info.textgrid.middleware.oaipmh.ResumptionTokenType;
......@@ -130,12 +129,12 @@ public class RecordListDelivererIDIOM extends RecordListDelivererAbstract {
String textgridURI =
OAIPMHUtilities.fieldLoader(new JSONObject(hit.getSourceAsMap()), "textgridUri");
log.fine("textgridURI: " + textgridURI);
log.fine("textgrid uri: " + textgridURI);
// Create new record here! We must not set only references here!
// Create new record here!
// NOTE We must not set only references here!!
RecordType record = new RecordType();
RecordType sourceRecord =
this.idiomRecord.getRecordById(textgridURI.replace(".0", "")).getRecord();
RecordType sourceRecord = this.idiomRecord.getRecordById(textgridURI).getRecord();
record.setHeader(sourceRecord.getHeader());
record.setMetadata(sourceRecord.getMetadata());
......
......@@ -118,4 +118,41 @@ public class TestOAIPMHUtilities {
}
}
/**
*
*/
@Test
public void testGetTextGridBaseURI() {
String uriExpected = "textgrid:12345";
String uri = "textgrid:12345.13";
String baseURI = OAIPMHUtilities.getTextGridBaseURI(uri);
if (!baseURI.equals(uriExpected)) {
System.out.println(baseURI + " != " + uriExpected);
assertTrue(false);
}
uri = "textgrid:12345.1";
baseURI = OAIPMHUtilities.getTextGridBaseURI(uri);
if (!baseURI.equals(uriExpected)) {
System.out.println(baseURI + " != " + uriExpected);
assertTrue(false);
}
uri = "textgrid:12345";
baseURI = OAIPMHUtilities.getTextGridBaseURI(uri);
if (!baseURI.equals(uriExpected)) {
System.out.println(baseURI + " != " + uriExpected);
assertTrue(false);
}
uri = "textgrid:12345.3847";
baseURI = OAIPMHUtilities.getTextGridBaseURI(uri);
if (!baseURI.equals(uriExpected)) {
System.out.println(baseURI + " != " + uriExpected);
assertTrue(false);
}
}
}
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