added a method to retrieve a record from the index
This commit is contained in:
parent
8a8507e8af
commit
b68ffc2cdf
|
@ -1,5 +1,8 @@
|
||||||
package eu.dnetlib.app.directindex.controllers;
|
package eu.dnetlib.app.directindex.controllers;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.apache.commons.lang3.exception.ExceptionUtils;
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
||||||
|
@ -10,6 +13,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
@ -23,6 +27,8 @@ import eu.dnetlib.app.directindex.errors.DirectIndexApiException;
|
||||||
import eu.dnetlib.app.directindex.input.ResultEntry;
|
import eu.dnetlib.app.directindex.input.ResultEntry;
|
||||||
import eu.dnetlib.app.directindex.mapping.SolrRecordMapper;
|
import eu.dnetlib.app.directindex.mapping.SolrRecordMapper;
|
||||||
import eu.dnetlib.app.directindex.service.DirectIndexService;
|
import eu.dnetlib.app.directindex.service.DirectIndexService;
|
||||||
|
import eu.dnetlib.app.directindex.solr.SolrIndexClientFactory;
|
||||||
|
import eu.dnetlib.dhp.schema.solr.SolrRecord;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/api")
|
@RequestMapping("/api")
|
||||||
|
@ -37,20 +43,33 @@ public class LegacyApiController {
|
||||||
@Autowired
|
@Autowired
|
||||||
private SolrRecordMapper solrRecordMapper;
|
private SolrRecordMapper solrRecordMapper;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private SolrIndexClientFactory solrIndexClientFactory;
|
||||||
|
|
||||||
@PostMapping("/results/feedObject")
|
@PostMapping("/results/feedObject")
|
||||||
public String feedResult(@RequestBody final ResultEntry pub,
|
public String feedResult(@RequestBody final ResultEntry pub, final HttpServletRequest req)
|
||||||
@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit,
|
|
||||||
final HttpServletRequest req)
|
|
||||||
throws DirectIndexApiException {
|
throws DirectIndexApiException {
|
||||||
|
|
||||||
return service.prepareMetadataInsertOrUpdate(pub, req.getRemoteAddr());
|
return service.prepareMetadataInsertOrUpdate(pub, req.getRemoteAddr());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/result/{openaireId}")
|
||||||
|
public Map<String, Object> getResultWithOpenaireId(@PathVariable(value = "openaireId") final String openaireId) throws DirectIndexApiException {
|
||||||
|
|
||||||
|
final SolrRecord indexed = solrIndexClientFactory.getClient().findRecord(openaireId);
|
||||||
|
|
||||||
|
final Map<String, Object> res = new LinkedHashMap<String, Object>();
|
||||||
|
res.put("indexed_oaf", indexed);
|
||||||
|
res.put("indexed_simple", indexed != null ? solrRecordMapper.toResultEntry(indexed) : null);
|
||||||
|
res.put("pending_action", service.findPendingAction(openaireId).orElse(null));
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
@DeleteMapping("/result/{openaireId}")
|
@DeleteMapping("/result/{openaireId}")
|
||||||
public boolean deleteResultWithOpenaireId(@PathVariable(value = "openaireId") final String openaireId,
|
public boolean deleteResultWithOpenaireId(@PathVariable(value = "openaireId") final String openaireId, final HttpServletRequest req)
|
||||||
@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit,
|
throws DirectIndexApiException {
|
||||||
final HttpServletRequest req) throws DirectIndexApiException {
|
|
||||||
|
|
||||||
service.prepareMetadataDeletion(openaireId, req.getRemoteAddr());
|
service.prepareMetadataDeletion(openaireId, req.getRemoteAddr());
|
||||||
|
|
||||||
|
@ -61,7 +80,6 @@ public class LegacyApiController {
|
||||||
public boolean deleteResultWithOriginalId(
|
public boolean deleteResultWithOriginalId(
|
||||||
@RequestParam(value = "originalId", required = true) final String originalId,
|
@RequestParam(value = "originalId", required = true) final String originalId,
|
||||||
@RequestParam(value = "collectedFromId", required = true) final String collectedFromId,
|
@RequestParam(value = "collectedFromId", required = true) final String collectedFromId,
|
||||||
@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit,
|
|
||||||
final HttpServletRequest req) throws DirectIndexApiException {
|
final HttpServletRequest req) throws DirectIndexApiException {
|
||||||
|
|
||||||
final String openaireId = solrRecordMapper.calculateOpenaireId(originalId, collectedFromId);
|
final String openaireId = solrRecordMapper.calculateOpenaireId(originalId, collectedFromId);
|
||||||
|
|
|
@ -192,7 +192,8 @@ public class SolrRecordMapper {
|
||||||
re.setContexts(contexts);
|
re.setContexts(contexts);
|
||||||
|
|
||||||
// @formatter:off
|
// @formatter:off
|
||||||
final List<String> projects = r.getLinks()
|
if (r.getLinks() != null) {
|
||||||
|
final List<String> projects = r.getLinks()
|
||||||
.stream()
|
.stream()
|
||||||
.filter(l -> l.getHeader().getRelatedRecordType() == RecordType.project)
|
.filter(l -> l.getHeader().getRelatedRecordType() == RecordType.project)
|
||||||
.map(p -> String.format("info:eu-repo/grantAgreement/%s/%s/%s/%s/%s/%s",
|
.map(p -> String.format("info:eu-repo/grantAgreement/%s/%s/%s/%s/%s/%s",
|
||||||
|
@ -204,9 +205,10 @@ public class SolrRecordMapper {
|
||||||
StringUtils.defaultIfBlank(p.getAcronym(), "")))
|
StringUtils.defaultIfBlank(p.getAcronym(), "")))
|
||||||
.distinct()
|
.distinct()
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
// @formatter:on
|
|
||||||
|
|
||||||
re.setLinksToProjects(projects);
|
re.setLinksToProjects(projects);
|
||||||
|
}
|
||||||
|
// @formatter:on
|
||||||
|
|
||||||
return re;
|
return re;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package eu.dnetlib.app.directindex.service;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
@ -31,6 +32,11 @@ public class DirectIndexService {
|
||||||
@Autowired
|
@Autowired
|
||||||
private DatasourceManagerClient dsmClient;
|
private DatasourceManagerClient dsmClient;
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public Optional<PendingAction> findPendingAction(final String id) {
|
||||||
|
return pendingActionRepository.findById(id);
|
||||||
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
public void prepareMetadataDeletion(final String openaireId, final String createdBy) {
|
public void prepareMetadataDeletion(final String openaireId, final String createdBy) {
|
||||||
final PendingAction action = new PendingAction();
|
final PendingAction action = new PendingAction();
|
||||||
|
@ -136,4 +142,5 @@ public class DirectIndexService {
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue