Skip to content

Commit

Permalink
fallback option for getMedia() in COMA backend
Browse files Browse the repository at this point in the history
  • Loading branch information
berndmoos committed Jun 7, 2024
1 parent de22ed9 commit dd4f406
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,26 @@ public Media getMedia(String mediaID) throws IOException {

String xp = "//Media[@Id='" + mediaID + "']";
Element mediaElement = (Element) (Node) xPath.evaluate(xp, corpusDocument.getDocumentElement(), XPathConstants.NODE);
String nsLink = mediaElement.getElementsByTagName("NSLink").item(0).getTextContent();
//File corpusFolder = new File(topFolder, corpusID);
//String urlString = corpusFolder.toPath().resolve(nsLink).toUri().toURL().toString();
String urlString = Configuration.getMediaPath() + "/" + corpusID + "/" + nsLink;
return new COMAMedia(mediaID, urlString);
if (mediaElement!=null){
String nsLink = mediaElement.getElementsByTagName("NSLink").item(0).getTextContent();
//File corpusFolder = new File(topFolder, corpusID);
//String urlString = corpusFolder.toPath().resolve(nsLink).toUri().toURL().toString();
String urlString = Configuration.getMediaPath() + "/" + corpusID + "/" + nsLink;
return new COMAMedia(mediaID, urlString);
} else {
// 07-06-2024
// this is a fallback in case the ID of the recording, not the ID of the media was provided
// not sure if this is a good idea
String xp2 = "//Recording[@Id='" + mediaID + "']/Media[1]";
Element mediaElement2 = (Element) (Node) xPath.evaluate(xp2, corpusDocument.getDocumentElement(), XPathConstants.NODE);
if (mediaElement2!=null){
String nsLink = mediaElement2.getElementsByTagName("NSLink").item(0).getTextContent();
//File corpusFolder = new File(topFolder, corpusID);
//String urlString = corpusFolder.toPath().resolve(nsLink).toUri().toURL().toString();
String urlString = Configuration.getMediaPath() + "/" + corpusID + "/" + nsLink;
return new COMAMedia(mediaID, urlString);
}
}

} catch (XPathExpressionException ex) {
Logger.getLogger(COMAFileSystem.class.getName()).log(Level.SEVERE, null, ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private void doit() {
BackendInterface bi = new COMAFileSystem();
System.out.println("There.");

String transcriptID = "1-7-1-24-a";
String transcriptID = "TRS_1-7-1-24-a";
String tokenID = "a6_w29";
Transcript transcript = bi.getTranscript(transcriptID);
String audioID = transcript.getMetadataValue(bi.findMetadataKeyByID("Transcript_Recording ID"));
Expand Down

0 comments on commit dd4f406

Please sign in to comment.