Skip to content

Commit

Permalink
[MODSOURCE-732]
Browse files Browse the repository at this point in the history
  • Loading branch information
RomanChernetskyi committed Feb 5, 2024
1 parent 0a0800f commit f20ff53
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 12 deletions.
2 changes: 1 addition & 1 deletion descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
},
{
"id": "source-storage-records",
"version": "3.2",
"version": "4.0",
"handlers": [
{
"methods": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ public enum IdType {
AUTHORITY("authorityId"),
EXTERNAL("externalId"),
// NOTE: not really external id but is default from dto
RECORD("matchedId");
RECORD("matchedId"),
SRS_RECORD("id");

private final String idField;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import org.folio.dataimport.util.ExceptionHelper;
import org.folio.rest.jaxrs.model.Record;
import org.folio.rest.jaxrs.model.Record.State;
import org.folio.rest.jaxrs.resource.SourceStorageRecords;
import org.folio.rest.tools.utils.TenantTool;
import org.folio.services.RecordService;
Expand Down Expand Up @@ -115,14 +114,11 @@ public void putSourceStorageRecordsGenerationById(String matchedId, Record entit
}

@Override
public void deleteSourceStorageRecordsById(String id, Map<String, String> okapiHeaders,
public void deleteSourceStorageRecordsById(String id, String idType, Map<String, String> okapiHeaders,
Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
vertxContext.runOnContext(v -> {
try {
recordService.getRecordById(id, tenantId)
.map(recordOptional -> recordOptional.orElseThrow(() -> new NotFoundException(format(NOT_FOUND_MESSAGE, Record.class.getSimpleName(), id))))
.compose(record -> record.getState().equals(State.DELETED) ? Future.succeededFuture(true)
: recordService.updateRecord(record.withState(State.DELETED), tenantId).map(r -> true))
recordService.deleteRecordById(id, toExternalIdType(idType), tenantId).map(r -> true)
.map(updated -> DeleteSourceStorageRecordsByIdResponse.respond204()).map(Response.class::cast)
.otherwise(ExceptionHelper::mapExceptionToResponse).onComplete(asyncResultHandler);
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,4 +253,6 @@ public interface RecordService {
* @return void future
*/
Future<Void> updateRecordsState(String matchedId, RecordState state, RecordType recordType, String tenantId);

Future<Void> deleteRecordById(String id, IdType idType, String tenantId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,14 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.folio.dao.util.RecordDaoUtil;
import org.folio.dao.util.*;
import org.folio.okapi.common.GenericCompositeFuture;
import org.folio.services.exceptions.DuplicateRecordException;
import org.jooq.Condition;
import org.jooq.OrderField;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.folio.dao.RecordDao;
import org.folio.dao.util.IdType;
import org.folio.dao.util.RecordType;
import org.folio.dao.util.SnapshotDaoUtil;
import org.folio.rest.jaxrs.model.FetchParsedRecordsBatchRequest;
import org.folio.rest.jaxrs.model.FieldRange;
import org.folio.rest.jaxrs.model.MarcBibCollection;
Expand Down Expand Up @@ -75,6 +72,8 @@ public class RecordServiceImpl implements RecordService {
private static final String DUPLICATE_RECORD_MSG = "Incoming file may contain duplicates";
private static final String MATCHED_ID_NOT_EQUAL_TO_999_FIELD = "Matched id (%s) not equal to 999ff$s (%s) field";
private static final String RECORD_WITH_GIVEN_MATCHED_ID_NOT_FOUND = "Record with given matched id (%s) not found";
private static final String NOT_FOUND_MESSAGE = "%s with id '%s' was not found";
private static final Character DELETED_LEADER_RECORD_STATUS = 'd';
public static final String UPDATE_RECORD_DUPLICATE_EXCEPTION = "Incoming record could be a duplicate, incoming record generation should not be the same as matched record generation and the execution of job should be started after of creating the previous record generation";
public static final char SUBFIELD_S = 's';
public static final char INDICATOR = 'f';
Expand Down Expand Up @@ -300,6 +299,20 @@ public Future<Void> updateRecordsState(String matchedId, RecordState state, Reco
return recordDao.updateRecordsState(matchedId, state, recordType, tenantId);
}

@Override
public Future<Void> deleteRecordById(String id, IdType idType, String tenantId) {
return recordDao.getRecordByExternalId(id, idType, tenantId)
.map(recordOptional -> recordOptional.orElseThrow(() -> new NotFoundException(format(NOT_FOUND_MESSAGE, Record.class.getSimpleName(), id))))
.map(record -> {
record.withState(Record.State.DELETED);
record.setDeleted(true);
record.setAdditionalInfo(record.getAdditionalInfo().withSuppressDiscovery(true));
ParsedRecordDaoUtil.updateLeaderStatus(record.getParsedRecord(), DELETED_LEADER_RECORD_STATUS);
return record;
})
.compose(record -> updateRecord(record, tenantId)).map(r -> null);
}

private Future<Record> setMatchedIdForRecord(Record record, String tenantId) {
String marcField999s = getFieldFromMarcRecord(record, TAG_999, INDICATOR, INDICATOR, SUBFIELD_S);
if (marcField999s != null) {
Expand Down
6 changes: 6 additions & 0 deletions ramls/source-record-storage-records.raml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ resourceTypes:
application/json:
type: record
delete:
queryParameters:
idType:
description: Type of Id for Record lookup
type: string
example: INSTANCE
default: SRS_RECORD
responses:
204:
/formatted:
Expand Down

0 comments on commit f20ff53

Please sign in to comment.