OntologyInfo ontology = null;
// this flag will be true if we have an unversioned request, see Issue 24.
boolean unversionedRequest = false;
MmiUri foundMmiUri = null;
OntRequest ontReq = _getThreadLocalOntRequest();
String version = ontReq.mmiUri.getVersion();
if ( version == null || version.equals(MmiUri.LATEST_VERSION_INDICATOR) ) {
//
// handling of unversioned and latest-version requests. (see Issue 24)
//
// Get latest version trying all possible topic extensions:
OntologyInfo mostRecentOntology = db.getMostRecentOntologyVersion(ontReq.mmiUri);
if ( mostRecentOntology != null ) {
try {
//
// Note that mostRecentOntology.getUri() won't have the term component.
// So, we have to transfer it to foundMmiUri:
//
foundMmiUri = new MmiUri(mostRecentOntology.getUri()).copyWithTerm(ontReq.mmiUri.getTerm());
if ( log.isDebugEnabled() ) {
log.debug("Found ontology version: " +mostRecentOntology.getUri());
if ( ! ontReq.mmiUri.getExtension().equals(foundMmiUri.getExtension()) ) {
log.debug("Restored requested extension to: " +ontReq.mmiUri);
}
}
// also, restore the original requested extension:
foundMmiUri = foundMmiUri.copyWithExtension(ontReq.mmiUri.getExtension());
}
catch (URISyntaxException e) {
return new InternalErrorResponse("Shouldn't happen", e);
}
// OK: here, foundMmiUri refers to the latest version.
if ( version == null ) {
// unversioned request.
unversionedRequest = true;
ontology = mostRecentOntology;
// and let the dispatch continue.
}
else {
// request was with version = MmiUri.LATEST_VERSION_INDICATOR.
// Use a redirect so the user gets the actual latest version:
String latestUri = foundMmiUri.getTermUri();
return new RedirectResponse(latestUri);
}
}
else {
// No versions available!