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;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
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.web.bind.annotation.DeleteMapping;
|
||||
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.PostMapping;
|
||||
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.mapping.SolrRecordMapper;
|
||||
import eu.dnetlib.app.directindex.service.DirectIndexService;
|
||||
import eu.dnetlib.app.directindex.solr.SolrIndexClientFactory;
|
||||
import eu.dnetlib.dhp.schema.solr.SolrRecord;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api")
|
||||
|
@ -37,20 +43,33 @@ public class LegacyApiController {
|
|||
@Autowired
|
||||
private SolrRecordMapper solrRecordMapper;
|
||||
|
||||
@Autowired
|
||||
private SolrIndexClientFactory solrIndexClientFactory;
|
||||
|
||||
@PostMapping("/results/feedObject")
|
||||
public String feedResult(@RequestBody final ResultEntry pub,
|
||||
@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit,
|
||||
final HttpServletRequest req)
|
||||
public String feedResult(@RequestBody final ResultEntry pub, final HttpServletRequest req)
|
||||
throws DirectIndexApiException {
|
||||
|
||||
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}")
|
||||
public boolean deleteResultWithOpenaireId(@PathVariable(value = "openaireId") final String openaireId,
|
||||
@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit,
|
||||
final HttpServletRequest req) throws DirectIndexApiException {
|
||||
public boolean deleteResultWithOpenaireId(@PathVariable(value = "openaireId") final String openaireId, final HttpServletRequest req)
|
||||
throws DirectIndexApiException {
|
||||
|
||||
service.prepareMetadataDeletion(openaireId, req.getRemoteAddr());
|
||||
|
||||
|
@ -61,7 +80,6 @@ public class LegacyApiController {
|
|||
public boolean deleteResultWithOriginalId(
|
||||
@RequestParam(value = "originalId", required = true) final String originalId,
|
||||
@RequestParam(value = "collectedFromId", required = true) final String collectedFromId,
|
||||
@RequestParam(value = "commit", required = false, defaultValue = "true") final boolean commit,
|
||||
final HttpServletRequest req) throws DirectIndexApiException {
|
||||
|
||||
final String openaireId = solrRecordMapper.calculateOpenaireId(originalId, collectedFromId);
|
||||
|
|
|
@ -192,7 +192,8 @@ public class SolrRecordMapper {
|
|||
re.setContexts(contexts);
|
||||
|
||||
// @formatter:off
|
||||
final List<String> projects = r.getLinks()
|
||||
if (r.getLinks() != null) {
|
||||
final List<String> projects = r.getLinks()
|
||||
.stream()
|
||||
.filter(l -> l.getHeader().getRelatedRecordType() == RecordType.project)
|
||||
.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(), "")))
|
||||
.distinct()
|
||||
.collect(Collectors.toList());
|
||||
// @formatter:on
|
||||
|
||||
re.setLinksToProjects(projects);
|
||||
re.setLinksToProjects(projects);
|
||||
}
|
||||
// @formatter:on
|
||||
|
||||
return re;
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package eu.dnetlib.app.directindex.service;
|
|||
import java.time.LocalDateTime;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
|
@ -31,6 +32,11 @@ public class DirectIndexService {
|
|||
@Autowired
|
||||
private DatasourceManagerClient dsmClient;
|
||||
|
||||
@Transactional
|
||||
public Optional<PendingAction> findPendingAction(final String id) {
|
||||
return pendingActionRepository.findById(id);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void prepareMetadataDeletion(final String openaireId, final String createdBy) {
|
||||
final PendingAction action = new PendingAction();
|
||||
|
@ -136,4 +142,5 @@ public class DirectIndexService {
|
|||
|
||||
return info;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue