Skip to content

Commit

Permalink
Merge pull request #279 from JULIELab/api
Browse files Browse the repository at this point in the history
Api
  • Loading branch information
khituras authored Sep 20, 2024
2 parents 7af800a + cb4fa94 commit 59d03f7
Show file tree
Hide file tree
Showing 12 changed files with 349 additions and 225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ private Stream<Event> resultDocuments2Events(Stream<ISearchServerDocument> docum
Optional<Integer> likelihood = eventDocument.get(FIELD_EVENT_LIKELIHOOD);
Optional<String> sentence = eventDocument.get(FIELD_EVENT_SENTENCE_TEXT);
Optional<String> paragraph = eventDocument.get(FIELD_EVENT_PARAGRAPH_TEXT);
String source = (String)eventDocument.get(FIELD_SOURCE).get(); // pubmed or pmc
List<String> sentenceArgumentHl = eventDocument.getHighlights().get(FIELD_EVENT_SENTENCE_TEXT_ARGUMENTS);
List<String> sentenceTriggerHl = eventDocument.getHighlights().get(FIELD_EVENT_SENTENCE_TEXT_TRIGGER);
List<String> sentenceFilterHl = eventDocument.getHighlights().get(FIELD_EVENT_SENTENCE_TEXT);
Expand Down Expand Up @@ -170,9 +171,12 @@ private Stream<Event> resultDocuments2Events(Stream<ISearchServerDocument> docum

Event event = new Event();
event.setArity(eventArity);
// Only one ID is present currently
pmid.ifPresent(event::setDocId);
pmcid.ifPresent(event::setDocId);

if (source.equals("pubmed") && pmid.isPresent())
event.setDocId(pmid.get());
else if (source.equals("pmc") && pmcid.isPresent())
event.setDocId(pmcid.get());

event.setEventId(eventId);
event.setArguments(arguments);
if (likelihood.isPresent())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ public class EventRetrievalService implements IEventRetrievalService {

public static final String FIELD_AGGREGATION_VALUE = "aggregationvalue";

public static final String FIELD_SOURCE = "source";

/**
* The values in the field have the form symbol1---symbol2
*/
Expand All @@ -131,6 +133,7 @@ public class EventRetrievalService implements IEventRetrievalService {
public static final List<String> FIELDS_FOR_TABLE = Arrays.asList(
FIELD_PMID,
FIELD_PMCID,
FIELD_SOURCE,
FIELD_EVENT_LIKELIHOOD,
FIELD_EVENT_SENTENCE_TEXT,
// FIELD_EVENT_PARAGRAPH_TEXT,
Expand Down
54 changes: 34 additions & 20 deletions gepi/gepi-webapp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
<version>${tapestry-release-version}</version>
</dependency>

<dependency>
<groupId>org.apache.tapestry</groupId>
<artifactId>tapestry-rest-jackson</artifactId>
<version>${tapestry-release-version}</version>
</dependency>

<!-- EF 10-2020: required for the built-in less compiler. However, the last time I wanted to include this, the less compiler library was not loaded
by intellij. Since I didn't need it, I just removed the dependency. -->
<!-- <dependency>-->
Expand Down Expand Up @@ -90,6 +96,14 @@ of testing facilities designed for use with TestNG (http://testng.org/), so it's
<!-- <scope>provided</scope>-->
</dependency>

<!-- Required to write HttpRequestBodyConverters for the REST API -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>

<!-- Provide dependency to the Tapestry javadoc taglet which replaces the Maven component report -->
<dependency>
<groupId>org.apache.tapestry</groupId>
Expand Down Expand Up @@ -171,26 +185,26 @@ of testing facilities designed for use with TestNG (http://testng.org/), so it's
<skip>false</skip>
</configuration>
</plugin>
<!-- <plugin>-->
<!-- &lt;!&ndash; Run the application using "mvn jetty:run" &ndash;&gt;-->
<!-- <groupId>org.mortbay.jetty</groupId>-->
<!-- <artifactId>maven-jetty-plugin</artifactId>-->
<!-- <version>6.1.16</version>-->
<!-- <configuration>-->
<!-- &lt;!&ndash; Log to the console. &ndash;&gt;-->
<!-- <requestLog implementation="org.mortbay.jetty.NCSARequestLog">-->
<!-- &lt;!&ndash; This doesn't do anything for Jetty, but is a workaround for a Maven bug-->
<!-- that prevents the requestLog from being set. &ndash;&gt;-->
<!-- <append>true</append>-->
<!-- </requestLog>-->
<!-- <systemProperties>-->
<!-- <systemProperty>-->
<!-- <name>tapestry.execution-mode</name>-->
<!-- <value>development</value>-->
<!-- </systemProperty>-->
<!-- </systemProperties>-->
<!-- </configuration>-->
<!-- </plugin>-->
<!-- <plugin>-->
<!-- &lt;!&ndash; Run the application using "mvn jetty:run" &ndash;&gt;-->
<!-- <groupId>org.mortbay.jetty</groupId>-->
<!-- <artifactId>maven-jetty-plugin</artifactId>-->
<!-- <version>6.1.16</version>-->
<!-- <configuration>-->
<!-- &lt;!&ndash; Log to the console. &ndash;&gt;-->
<!-- <requestLog implementation="org.mortbay.jetty.NCSARequestLog">-->
<!-- &lt;!&ndash; This doesn't do anything for Jetty, but is a workaround for a Maven bug-->
<!-- that prevents the requestLog from being set. &ndash;&gt;-->
<!-- <append>true</append>-->
<!-- </requestLog>-->
<!-- <systemProperties>-->
<!-- <systemProperty>-->
<!-- <name>tapestry.execution-mode</name>-->
<!-- <value>development</value>-->
<!-- </systemProperty>-->
<!-- </systemProperties>-->
<!-- </configuration>-->
<!-- </plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,11 @@ public class GepiInput {
*/
@ActivationRequestParameter
private boolean reset;

public GepiRequestData getRequestData() {
return requestData;
}

/**
* TODO This is here to allow for paging requests. It overlaps with {@link #data} which should be sorted out at some point.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import de.julielab.java.utilities.FileUtilities;
import org.apache.tapestry5.ComponentResources;
import org.apache.tapestry5.StreamResponse;
import org.apache.tapestry5.SymbolConstants;
import org.apache.tapestry5.annotations.*;
import org.apache.tapestry5.beanmodel.BeanModel;
import org.apache.tapestry5.beanmodel.services.BeanModelSource;
Expand All @@ -24,6 +25,7 @@
import org.apache.tapestry5.http.services.Response;
import org.apache.tapestry5.ioc.LoggerSource;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.ioc.annotations.Symbol;
import org.apache.tapestry5.services.javascript.JavaScriptSupport;
import org.slf4j.Logger;

Expand Down Expand Up @@ -88,58 +90,31 @@ public class TableResultWidget extends GepiWidget {
@Persist(TabPersistentField.TAB)
private Format contextFormat;
@Inject
@Symbol(SymbolConstants.PRODUCTION_MODE)
private boolean productionMode;
@Inject
private IEventRetrievalService eventRetrievalService;
@Inject
private LoggerSource loggerSource;
@Environmental
private JavaScriptSupport javaScriptSupport;

// @Property
// private List<String> selectedColumns;
@Inject
private IGeneIdService geneIdService;
// @Inject
// private TypeCoercer typeCoercer;
//
// public ValueEncoder getColumnsEncoder() {
// return new StringValueEncoder();
// }
//
// public SelectModel getColumnsModel() {
// return new SelectModelImpl(tableModel.getPropertyNames().stream().map(p -> new OptionModelImpl(p)).toArray(OptionModel[]::new));
// }

// @Inject
// private AjaxResponseRenderer ajaxResponseRenderer;
//
// @InjectComponent
// private GepiWidgetLayout gepiWidgetLayout;
//
// for columns selection
// public void onSuccessFromColumnsForm() {
// tableModel.include(selectedColumns.toArray(String[]::new));
// ajaxResponseRenderer.addRender(gepiWidgetLayout.getBodyZone());
// }

@Log
void setupRender() {
getEventSource();
List<String> availableColumns = new ArrayList<>(List.of("firstArgumentPreferredName",
"secondArgumentPreferredName",
// "firstArgumentText",
// "secondArgumentText",
"firstArgumentGeneId",
"secondArgumentGeneId",
// "firstArgumentMatchType",
// "secondArgumentMatchType",
"allEventTypes",
"factuality",
"fulltextMatchSource",
"docId",
// "eventId",
"context"
// ,
// "geneMappingSources"
));
if (inputMode != null && !inputMode.contains(InputMode.FULLTEXT_QUERY))
availableColumns.remove("fulltextMatchSource");
Expand All @@ -149,16 +124,10 @@ void setupRender() {

tableModel.get("firstArgumentPreferredName").label("Gene A Symbol");
tableModel.get("secondArgumentPreferredName").label("Gene B Symbol");
// tableModel.get("firstArgumentText").label("Gene A Text");
// tableModel.get("secondArgumentText").label("Gene B Text");
tableModel.get("firstArgumentGeneId").label("Gene A Gene ID");
tableModel.get("secondArgumentGeneId").label("Gene B Gene ID");
// tableModel.get("firstArgumentMatchType").label("gene A match type");
// tableModel.get("secondArgumentMatchType").label("gene B match type");
tableModel.get("allEventTypes").label("Relation Types");
tableModel.get("docId").label("Document ID");
// tableModel.get("eventId").label("event id");
// tableModel.get("geneMappingSources").label("gene tagger");
// Disable the sorting buttons. Since we reorder the event arguments so that arguments from list A
// always appear as the "first" argument, we cannot sort in ElasticSearch because there is no fixed
// field we could sort on for the gene arguments. Other columns would be possible to sort on but
Expand All @@ -177,28 +146,14 @@ public Object parseObject(String source, ParsePosition pos) {
return source;
}
};
// selectedColumns = tableModel.getPropertyNames();
}

/**
* When the form containing the filter elements is submitted, we want to re-render the table via AJAX
*/
// void onValidateFromFilterCriteria() {
// if (request.isXHR()) {
// ajaxResponseRenderer.addRender(tableZone);
// }
// }
public EventPagesDataSource getEventSource() {
// FilteredGepiRequestData filteredRequest = new FilteredGepiRequestData(requestData);
// filteredRequest.setEventTypeFilter(filterEventType);
return new EventPagesDataSource(loggerSource.getLogger(EventPagesDataSource.class), dataService.getData(requestData.getDataSessionId()).getPagedResult(), eventRetrievalService, geneIdService, requestData);
}

void onUpdateTableData() {
log.debug("Waiting for table data.");
// beanEvents = getEsResult().get().getEventList().stream()
// .map(e -> new BeanModelEvent(e))
// .collect(Collectors.toList());
log.debug("Table data was loaded.");

}
Expand Down Expand Up @@ -233,18 +188,6 @@ public StreamResponse onDownload() {
@Override
public void prepareResponse(Response response) {
try {
// Future<EventRetrievalResult> unrolledResult4download = getUnrolledResult4download();
// // Check if we have the download data cached. Otherwise, get it and cache it
// if (unrolledResult4download == null) {
// long time = System.currentTimeMillis();
// log.info("[{}] Retrieving unrolled result for Excel sheet creation.", requestData.getDataSessionId());
// unrolledResult4download = eventRetrievalService.getEvents(requestData, 0, Integer.MAX_VALUE, false);
// // We use a weak reference for the complete data since it requires much memory because of all
// // the context data. The GC should be able to evict it, if necessary.
// dataService.getData(requestData.getDataSessionId()).setUnrolledResult4download(new WeakReference<>(unrolledResult4download));
// time = System.currentTimeMillis() - time;
// log.info("[{}] Unrolled result retrieval for Excel sheet creation took {} seconds", requestData.getDataSessionId(), time / 1000);
// }
final Future<EventRetrievalResult> unrolledResult4download = dataService.getUnrolledResult4download(requestData, eventRetrievalService);
statisticsFile = dataService.getOverviewExcel(unrolledResult4download, requestData.getDataSessionId(), requestData.getInputMode(), requestData.getSentenceFilterString(), requestData.getParagraphFilterString(), requestData.getSectionNameFilterString());

Expand Down Expand Up @@ -293,7 +236,7 @@ public String getArgumentLink(int argPosition) {

public void afterRender() {
final Link downloadEventLink = resources.createEventLink("download");
javaScriptSupport.require("gepi/charts/tablewidget").invoke("download").with(downloadEventLink.toAbsoluteURI().replace(":80", ""));
javaScriptSupport.require("gepi/charts/tablewidget").invoke("download").with(downloadEventLink.toAbsoluteURI(productionMode));
javaScriptSupport.require("gepi/charts/tablewidget").invoke("setupHighlightTooltips");
javaScriptSupport.require("gepi/base").invoke("setuptooltips");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@ private void readParameters(Request request) {
if (listATextAreaValue == null)
listATextAreaValue = request.getParameter(ALIST);
if (listATextAreaValue != null)
listATextAreaValue = Arrays.stream(listATextAreaValue.split("[\n,]")).map(this::decodeUrlEncoding).collect(Collectors.joining("\n"));
listATextAreaValue = Arrays.stream(decodeUrlEncoding(listATextAreaValue).split("[\n,]")).collect(Collectors.joining("\n"));
listBTextAreaValue = request.getParameter(LISTB);
if (listBTextAreaValue == null)
listBTextAreaValue = request.getParameter(BLIST);
if (listBTextAreaValue != null)
listBTextAreaValue = Arrays.stream(listBTextAreaValue.split("[\n,]")).map(this::decodeUrlEncoding).collect(Collectors.joining("\n"));
listBTextAreaValue = Arrays.stream(decodeUrlEncoding(listBTextAreaValue).split("[\n,]")).collect(Collectors.joining("\n"));
taxId = request.getParameter(TAXID);
selectedEventTypes = new ArrayList<>(EnumSet.allOf(EventTypes.class));
final String eventTypesString = request.getParameter(EVENTTYPES);
Expand Down Expand Up @@ -161,7 +161,7 @@ private void readParameters(Request request) {
interactionRetrievalLimitForAggregations = INTERACTION_RETRIEVAL_LIMIT_FOR_AGGREGATIONS;
format = request.getParameter(FORMAT) != null ? request.getParameter(FORMAT).toLowerCase() : null;
if (format == null)
format = "web";
format = "tsv";
try {
interactionRetrievalLimitForAggregations = Integer.parseInt(request.getParameter(INTERACTION_RETRIEVAL_LIMIT));
} catch (NumberFormatException e) {
Expand All @@ -170,6 +170,14 @@ private void readParameters(Request request) {
}
}

/**
* This method is required for the help pages. For some reason, Tapestry converts the percent-URL-encodings
* in the HTML attributes into these dollar-sign encodings which are then not translated back.
*
* The API - when used with cURL, for example - works just fine.
* @param encodedString
* @return
*/
private String decodeUrlEncoding(String encodedString) {
return encodedString.replaceAll("\\$002520", " ")
.replaceAll("\\$00253[Aa]", ":")
Expand Down
Loading

0 comments on commit 59d03f7

Please sign in to comment.