Commit 63710b2e authored by Gradl, Tobias's avatar Gradl, Tobias
Browse files

1325: Return results from metasearch with regular queries

Task-Url: https://pm.winseda.de/issues/1325
parent 0662c990
Pipeline #11902 failed with stages
in 7 seconds
package eu.dariah.de.search.query.meta;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
......@@ -19,13 +20,20 @@ import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.module.SimpleModule;
import de.unibamberg.minf.dme.model.base.Element;
import de.unibamberg.minf.dme.model.base.Nonterminal;
import de.unibamberg.minf.dme.model.datamodel.base.Datamodel;
import de.unibamberg.minf.dme.model.mapping.base.Mapping;
import de.unibamberg.minf.processing.consumption.CollectingResourceConsumptionServiceImpl;
import de.unibamberg.minf.processing.model.base.Resource;
import de.unibamberg.minf.processing.model.serialization.ResourceSerializer;
import de.unibamberg.minf.processing.service.base.BaseResourceProcessingServiceImpl;
import de.unibamberg.minf.processing.service.xml.XmlProcessingService;
import eu.dariah.de.search.indexing.model.ResourceContainer;
import eu.dariah.de.search.model.Collection;
import eu.dariah.de.search.model.Dataset;
import eu.dariah.de.search.model.Endpoint;
......@@ -33,14 +41,17 @@ import eu.dariah.de.search.model.ExtendedDatamodelContainer;
import eu.dariah.de.search.query.Query;
import eu.dariah.de.search.query.SimpleQuery;
import eu.dariah.de.search.query.execution.QueryExecutionService;
import eu.dariah.de.search.query.execution.base.BaseResultService;
import eu.dariah.de.search.query.results.QueryResult;
import eu.dariah.de.search.query.results.ResultElement;
import eu.dariah.de.search.query.results.QueryResult.ResultTypes;
import eu.dariah.de.search.service.CollectionService;
import eu.dariah.de.search.service.DatamodelService;
import eu.dariah.de.search.service.MappingService;
import eu.dariah.de.search.transformation.ResourceEnrichmentService;
@Component
public class SruQueryExecutionServiceImpl implements QueryExecutionService {
public class SruQueryExecutionServiceImpl extends BaseResultService implements QueryExecutionService {
protected final Logger logger = LoggerFactory.getLogger(SruQueryExecutionServiceImpl.class);
......@@ -70,8 +81,16 @@ public class SruQueryExecutionServiceImpl implements QueryExecutionService {
coll = collectionService.getAll();
}
ObjectMapper indexingObjectMapper = new ObjectMapper();
SimpleModule module = new SimpleModule();
module.addSerializer(Resource.class, new ResourceSerializer());
indexingObjectMapper.registerModule(module);
// Collect endpoints to federate
Map<String, Endpoint> collectionIdEndpointMap = new HashMap<>();
Endpoint opacEndpoint;
for (Collection c : coll) {
opacEndpoint = null;
......@@ -84,22 +103,15 @@ public class SruQueryExecutionServiceImpl implements QueryExecutionService {
break;
}
}
if (!hasCrawlEp && opacEndpoint!=null) {
collectionIdEndpointMap.put(c.getId(), opacEndpoint);
if (hasCrawlEp || opacEndpoint==null) {
continue;
}
}
// Actually execute federated searches
for (Entry<String, Endpoint> entry : collectionIdEndpointMap.entrySet()) {
String result = restTemplate.getForObject(entry.getValue().getUrl(), String.class);
String result = restTemplate.getForObject(opacEndpoint.getUrl(), String.class);
String entityId = null;
String alias = null;
for (Dataset ds : entry.getValue().getDatasets()) {
for (Dataset ds : opacEndpoint.getDatasets()) {
entityId = ds.getId();
alias = ds.getRemoteAlias();
break;
......@@ -126,21 +138,37 @@ public class SruQueryExecutionServiceImpl implements QueryExecutionService {
processingSvc.setRoot((Nonterminal)r);
processingSvc.init();
URIBuilder b = new URIBuilder(entry.getValue().getUrl());
URIBuilder b = new URIBuilder(opacEndpoint.getUrl());
b.addParameter("query", ((SimpleQuery)q).getQueryString());
b.addParameter("recordSchema", alias);
b.addParameter("maximumRecords", "10");
b.addParameter("startRecord", "1");
b.addParameter("recordPacking", "xml");
logger.debug(b.build().toString());
String sss = restTemplate.getForObject(b.build(), String.class);
processingSvc.setInputStream(IOUtils.toInputStream(sss, Charset.defaultCharset()));
processingSvc.setInputStream(IOUtils.toInputStream(sss, Charset.forName("ISO-8859-1")));
processingSvc.run();
logger.debug("Done");
QueryResult qr = new QueryResult();
qr.setResultType(ResultTypes.META);
qr.setResultElements(new ArrayList<ResultElement>());
if (!enrichmentService.getResourceBatch().isEmpty()) {
for (ResourceContainer rc : enrichmentService.getResourceBatch()) {
qr.getResultElements().add(this.renderResultElement(indexingObjectMapper.convertValue(rc.toSource(), JsonNode.class), c, s.getIndexName(), "", locale, 1, null, null, true, false));
}
}
return qr;
} catch (Exception e) {
logger.error("Error", e);
......
Supports Markdown
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