Skip to content

Commit

Permalink
Merge pull request #4398 from inception-project/feature/4397-Better-e…
Browse files Browse the repository at this point in the history
…rror-message-when-PMC-document-cannot-be-found

#4397 - Better error message when PMC document cannot be found
  • Loading branch information
reckart authored Dec 27, 2023
2 parents 3446478 + fa191af commit 546e37f
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 18 deletions.
4 changes: 4 additions & 0 deletions inception/inception-external-search-pubmed/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@
*/
package de.tudarmstadt.ukp.inception.externalsearch.pubmed.pmcoa;

import java.io.IOException;
import java.util.Map;

import org.springframework.http.HttpMethod;
import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter;
import org.springframework.web.client.HttpClientErrorException.NotFound;
import org.springframework.web.client.RestTemplate;

import de.tudarmstadt.ukp.inception.externalsearch.pubmed.traits.PubMedProviderTraits;
Expand All @@ -40,14 +42,25 @@ public PmcOaClient()
restTemplate.getMessageConverters().add(new MappingJackson2XmlHttpMessageConverter());
}

public byte[] bioc(PubMedProviderTraits aTraits, String aID)
public byte[] bioc(PubMedProviderTraits aTraits, String aID) throws IOException
{
var variables = Map.of( //
PARAM_ID, aID);
try {
var variables = Map.of( //
PARAM_ID, aID);

var response = restTemplate.exchange(BIOC_URL, HttpMethod.GET, null, byte[].class,
variables);
var response = restTemplate.exchange(BIOC_URL, HttpMethod.GET, null, byte[].class,
variables);

return response.getBody();
return response.getBody();
}
catch (NotFound e) {
throw new IOException("BioC version of document [" + aID + "] not found at ["
+ BIOC_URL.replace("{id}", aID)
+ "]. The Open Access files and BioC versions are not updated as "
+ "quickly as the PMC website itself is updated. It may take a couple of days until "
+ "a particular file is available as BioC. Another reason could be that the document you "
+ "are looking for is not included in the Open Access set. Try adding "
+ "`\"open access\"[filter]` without \"`\" to your search to filter by Open Access files.");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@

import java.io.Serializable;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

//The @JsonSerialize annotation avoid the "InvalidDefinitionException: No serializer found"
//exception without having to set SerializationFeature.FAIL_ON_EMPTY_BEANS
@JsonSerialize
@JsonIgnoreProperties(ignoreUnknown = true)
public class PubMedProviderTraits
implements Serializable
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import static de.tudarmstadt.ukp.inception.app.ui.externalsearch.DocumentDetailsPage.PAGE_PARAM_DOCUMENT_ID;
import static de.tudarmstadt.ukp.inception.app.ui.externalsearch.DocumentDetailsPage.PAGE_PARAM_REPOSITORY_ID;

import java.io.IOException;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;
Expand Down Expand Up @@ -95,7 +93,7 @@ private String getDocumentText()
try {
return externalSearchService.getDocumentText(repo, collectionId, documentId);
}
catch (IOException e) {
catch (Exception e) {
return "ERROR: " + e.getMessage();
}
}
Expand All @@ -105,7 +103,7 @@ private ExternalSearchResult getDocumentResult()
try {
return externalSearchService.getDocumentResult(repo, collectionId, documentId);
}
catch (IOException e) {
catch (Exception e) {
return new ExternalSearchResult(repo, collectionId, documentId);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
<html xmlns:wicket="http://wicket.apache.org">
<body>
<wicket:panel>
<div class="flex-h-container">
<div class="fs-1 me-4">
<i wicket:id="icon"/>
<div class="d-flex">
<div class="fs-1 mx-2">
<i wicket:id="icon" class="text-muted"/>
</div>
<a wicket:id="titleLink" class="flex-content text-decoration-none text-reset">
<a wicket:id="titleLink" class="flex-grow-1 text-decoration-none text-reset mx-2">
<h5>
<wicket:container wicket:id="title"/>
</h5>
Expand All @@ -33,12 +33,12 @@ <h5>
</li>
</ul>
</a>
<div class="flex-v-container">
<a wicket:id="importLink" class="btn btn-secondary">
<div class="flex-v-container mx-2 flex-shrink-0">
<a wicket:id="importLink" class="btn btn-outline-secondary">
<i class="fas fa-plus"></i>
<wicket:message key="import"/>
</a>
<a wicket:id="openLink" class="btn btn-secondary">
<a wicket:id="openLink" class="btn btn-outline-secondary">
<i class="fas fa-folder-open"></i>
<wicket:message key="open"/>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@
limitations under the License.
-->
<html xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.4-strict.dtd">
<head>
<wicket:head>
<style>
.results-table thead {
position: sticky;
top: 0px;
}
.results-table thead td {
border-bottom: 0px;
}
</style>
</wicket:head>
</head>
<body>
<wicket:extend>
<div class="flex-content flex-v-container flex-gutter">
Expand All @@ -40,7 +53,7 @@
</form>
<div class="scrolling flex-content flex-h-container mb-0">
<div wicket:id="dataTableContainer" class="w-100">
<table wicket:id="resultsTable" class="table" cellspacing="0" >
<table wicket:id="resultsTable" class="table results-table" cellspacing="0" >
[Results table]
</table>
</div>
Expand Down

0 comments on commit 546e37f

Please sign in to comment.