Commit 29190903 authored by Gradl, Tobias's avatar Gradl, Tobias
Browse files

1323: Implement metasearch for SRU endpoints

Task-Url: https://pm.winseda.de/issues/1323
parent 8a1c29c6
Pipeline #11895 failed with stages
in 13 seconds
......@@ -14,7 +14,6 @@ import org.springframework.stereotype.Component;
import com.fasterxml.jackson.core.type.TypeReference;
import de.unibamberg.minf.core.web.localization.LocaleConverter;
import eu.dariah.de.colreg.model.Datamodel;
import eu.dariah.de.colreg.pojo.AccessPojo;
import eu.dariah.de.colreg.pojo.AccrualPojo;
import eu.dariah.de.colreg.pojo.DatamodelPojo;
......
package eu.dariah.de.search.controller.search;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
......@@ -52,34 +53,48 @@ public class QueryExecutionController {
@GetMapping(value={"/",""})
public @ResponseBody QueryResult queryAsGet(@RequestParam String q, HttpServletResponse response, Locale locale) {
public @ResponseBody List<QueryResult> queryAsGet(@RequestParam String q, HttpServletResponse response, Locale locale) {
SimpleQuery query = new SimpleQueryImpl();
query.setQueryString(q);
QueryResult metaQ = sruQueryExecutionService.executeQuery(query, locale);
List<QueryResult> results = new ArrayList<>();
QueryResult qr = queryExecutionService.executeQuery(query, locale);
if (qr!=null) {
results.add(qr);
}
return queryExecutionService.executeQuery(query, locale);
qr = sruQueryExecutionService.executeQuery(query, locale);
if (qr!=null) {
results.add(qr);
}
return results;
}
@PostMapping(value={"/",""})
public @ResponseBody QueryResult queryAsPost(@RequestBody String q, HttpServletResponse response, Locale locale) throws QueryExecutionException {
public @ResponseBody List<QueryResult> queryAsPost(@RequestBody String q, HttpServletResponse response, Locale locale) throws QueryExecutionException {
Query query = this.deserializeQuery(q);
List<QueryResult> results = new ArrayList<>();
if ((query.getSourceIds()==null || query.getSourceIds().isEmpty()) && query.getCustomSearch()!=null && !query.getCustomSearch().isEmpty()) {
List<CustomSearch> cs = customSearchService.findByPrefix(query.getCustomSearch());
if (cs.size()!=1) {
logger.error("Expected exactly one custom search for prefix; found: {}", cs.size());
} else {
if (cs.get(0).getCollectionIds()==null || cs.get(0).getCollectionIds().isEmpty()) {
return new QueryResult();
results.add(new QueryResult());
}
query.setSourceIds(cs.get(0).getCollectionIds());
}
}
QueryResult qr = queryExecutionService.executeQuery(query, locale);
if (qr!=null) {
results.add(qr);
}
QueryResult metaQ = sruQueryExecutionService.executeQuery(query, locale);
return queryExecutionService.executeQuery(query, locale);
qr = sruQueryExecutionService.executeQuery(query, locale);
if (qr!=null) {
results.add(qr);
}
return results;
}
@PostMapping(value="/tags/")
......
......@@ -36,6 +36,7 @@ import eu.dariah.de.search.query.execution.base.BaseQueryService;
import eu.dariah.de.search.query.results.QueryResult;
import eu.dariah.de.search.query.results.QueryResultDatasource;
import eu.dariah.de.search.query.results.ResultElement;
import eu.dariah.de.search.query.results.QueryResult.ResultTypes;
@Component
public class QueryExecutionServiceImpl extends BaseQueryService implements QueryExecutionService {
......@@ -157,6 +158,7 @@ public class QueryExecutionServiceImpl extends BaseQueryService implements Query
protected QueryResult buildQueryResult(Query q, List<SearchResponse> responses, Locale locale) {
QueryResult qr = new QueryResult();
qr.setResultType(ResultTypes.REGULAR);
qr.setResultElements(new ArrayList<ResultElement>());
for (SearchResponse resp : responses) {
......
......@@ -13,6 +13,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
......@@ -52,6 +53,11 @@ public class SruQueryExecutionServiceImpl implements QueryExecutionService {
@Autowired private MappingService mappingService;
@Value("${datamodels.integration}")
private String integrationModelEntityId;
@Value("${datamodels.presentation}")
private String presentationModelEntityId;
@Override
......@@ -90,9 +96,11 @@ public class SruQueryExecutionServiceImpl implements QueryExecutionService {
String result = restTemplate.getForObject(entry.getValue().getUrl(), String.class);
String entityId = null;
String alias = null;
for (Dataset ds : entry.getValue().getDatasets()) {
entityId = ds.getId();
alias = ds.getRemoteAlias();
break;
}
......@@ -120,7 +128,7 @@ public class SruQueryExecutionServiceImpl implements QueryExecutionService {
URIBuilder b = new URIBuilder(entry.getValue().getUrl());
b.addParameter("query", ((SimpleQuery)q).getQueryString());
b.addParameter("recordSchema", "dc");
b.addParameter("recordSchema", alias);
b.addParameter("maximumRecords", "10");
b.addParameter("startRecord", "1");
b.addParameter("recordPacking", "xml");
......
......@@ -8,6 +8,9 @@ import eu.dariah.de.search.pojo.FilterPojo;
public class QueryResult {
public enum ResultTypes { REGULAR, META }
private ResultTypes resultType;
private List<ResultElement> resultElements;
private List<QueryResultDatasource> resultDatasources;
private List<FilterPojo> availableFilters;
......@@ -21,6 +24,10 @@ public class QueryResult {
private boolean hasMore;
private List<String> executedQueries;
public ResultTypes getResultType() { return resultType; }
public void setResultType(ResultTypes resultType) { this.resultType = resultType; }
public List<FilterPojo> getAvailableFilters() { return availableFilters; }
public void setAvailableFilters(List<FilterPojo> availableFilters) { this.availableFilters = availableFilters; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment