partial implementation

This commit is contained in:
Michele Artini 2024-11-20 10:07:45 +01:00
parent 40f653ab8e
commit 76436688aa
3 changed files with 8 additions and 9 deletions

View File

@ -40,7 +40,7 @@ public class LegacyApiController {
final HttpServletRequest req)
throws DirectIndexApiException {
return service.prepareMetadataInsertion(pub, req.getRemoteAddr());
return service.prepareMetadataInsertOrUpdate(pub, req.getRemoteAddr());
}

View File

@ -93,7 +93,8 @@ public class SwordApiController {
responseHeaders.setLocation(null);
try {
final String openaireId = service.prepareMetadataInsertion(parseMetadata(json), StringUtils.firstNonBlank(authentication.getName(), UNKNOWN_USER));
final String openaireId =
service.prepareMetadataInsertOrUpdate(parseMetadata(json), StringUtils.firstNonBlank(authentication.getName(), UNKNOWN_USER));
final SwordStatusDocument status = SwordStatusDocument.newInstance(baseUrl + "/api/sword/3.0", openaireId);
@ -132,7 +133,10 @@ public class SwordApiController {
try {
if (!solrIndexClientFactory.getClient().existsRecord(id)) { throw new SwordException(SwordErrorType.NotFound); }
service.prepareMetadataReplacement(id, result, StringUtils.firstNonBlank(authentication.getName(), UNKNOWN_USER));
// The presence of an existing openaire ID is used to force the update
result.setOpenaireId(id);
service.prepareMetadataInsertOrUpdate(result, StringUtils.firstNonBlank(authentication.getName(), UNKNOWN_USER));
return new ResponseEntity<>(HttpStatus.ACCEPTED);
} catch (final DirectIndexApiException e) {

View File

@ -38,12 +38,7 @@ public class DirectIndexService {
pendingActionRepository.save(action);
}
public void prepareMetadataReplacement(final String id, final ResultEntry document, final String createdBy) {
// TODO Auto-generated method stub
}
public String prepareMetadataInsertion(final ResultEntry r, final String createdBy) throws DirectIndexApiException {
public String prepareMetadataInsertOrUpdate(final ResultEntry r, final String createdBy) throws DirectIndexApiException {
final PendingAction info = new PendingAction();
if (StringUtils.isNotBlank(r.getOpenaireId())) {