Skip to content

Commit

Permalink
FIX FOR MODSOURCE-709 (#582)
Browse files Browse the repository at this point in the history
* return empty list if no value field

* return emptylist if value field is missingvalue instance

* remove unused import

(cherry picked from commit e607293)
  • Loading branch information
JavokhirAbdullayev authored and RuslanLavrov committed Nov 24, 2023
1 parent e70bc61 commit 8d741f8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.folio.kafka.exception.DuplicateEventException;
import org.folio.okapi.common.GenericCompositeFuture;
import org.folio.processing.value.ListValue;
import org.folio.processing.value.MissingValue;
import org.folio.processing.value.Value;
import org.folio.rest.jaxrs.model.AdditionalInfo;
import org.folio.rest.jaxrs.model.ErrorRecord;
Expand Down Expand Up @@ -96,6 +97,7 @@
import java.util.stream.Collectors;

import static java.lang.String.format;
import static java.util.Collections.emptyList;
import static org.folio.dao.util.AdvisoryLockUtil.acquireLock;
import static org.folio.dao.util.ErrorRecordDaoUtil.ERROR_RECORD_CONTENT;
import static org.folio.dao.util.ParsedRecordDaoUtil.PARSED_RECORD_CONTENT;
Expand Down Expand Up @@ -150,15 +152,12 @@ public class RecordDaoImpl implements RecordDao {

public static final String CONTROL_FIELD_CONDITION_TEMPLATE = "\"{partition}\".\"value\" in ({value})";
public static final String DATA_FIELD_CONDITION_TEMPLATE = "\"{partition}\".\"value\" in ({value}) and \"{partition}\".\"ind1\" LIKE '{ind1}' and \"{partition}\".\"ind2\" LIKE '{ind2}' and \"{partition}\".\"subfield_no\" = '{subfield}'";
public static final String DATA_FIELD_CONDITION_TEMPLATE_EMPTY_VALUE = "\"{partition}\".\"ind1\" LIKE '{ind1}' and" +
" \"{partition}\".\"ind2\" LIKE '{ind2}' and \"{partition}\".\"subfield_no\" = '{subfield}'";
private static final String VALUE_IN_SINGLE_QUOTES = "'%s'";
private static final String RECORD_NOT_FOUND_BY_ID_TYPE = "Record with %s id: %s was not found";
private static final String INVALID_PARSED_RECORD_MESSAGE_TEMPLATE = "Record %s has invalid parsed record; %s";
private static final String WILDCARD = "*";
private static final String PERCENT = "%";
private static final String HASH = "#";
private static final String VALUE = "value";

private static final Field<Integer> COUNT_FIELD = field(name(COUNT), Integer.class);

Expand Down Expand Up @@ -266,6 +265,9 @@ public Future<StrippedParsedRecordCollection> getStrippedParsedRecords(List<Stri
public Future<List<Record>> getMatchedRecords(MatchField matchedField, TypeConnection typeConnection, boolean externalIdRequired, int offset, int limit, String tenantId) {
Name prt = name(typeConnection.getDbType().getTableName());
Table<org.jooq.Record> marcIndexersPartitionTable = table(name(MARC_INDEXERS_PARTITION_PREFIX + matchedField.getTag()));
if (matchedField.getValue() instanceof MissingValue)
return Future.succeededFuture(emptyList());

return getQueryExecutor(tenantId).transaction(txQE -> txQE.query(dsl ->
{
SelectOnConditionStep<org.jooq.Record> query = dsl
Expand Down Expand Up @@ -329,18 +331,15 @@ public Future<List<Record>> getMatchedRecordsWithoutIndexersVersionUsage(MatchFi
private Condition getMatchedFieldCondition(MatchField matchedField, String partition) {
Map<String, String> params = new HashMap<>();
params.put("partition", partition);
params.put(VALUE, getValueInSqlFormat(matchedField.getValue()));
if (matchedField.isControlField() && !params.get(VALUE).isEmpty()) {
params.put("value", getValueInSqlFormat(matchedField.getValue()));
if (matchedField.isControlField()) {
String sql = StrSubstitutor.replace(CONTROL_FIELD_CONDITION_TEMPLATE, params, "{", "}");
return condition(sql);
} else {
params.put("ind1", getSqlInd(matchedField.getInd1()));
params.put("ind2", getSqlInd(matchedField.getInd2()));
params.put("subfield", matchedField.getSubfield());
String sqlTemplate = params.get(VALUE).isEmpty()
? DATA_FIELD_CONDITION_TEMPLATE_EMPTY_VALUE
: DATA_FIELD_CONDITION_TEMPLATE;
String sql = StrSubstitutor.replace(sqlTemplate, params, "{", "}");
String sql = StrSubstitutor.replace(DATA_FIELD_CONDITION_TEMPLATE, params, "{", "}");
return condition(sql);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.folio.dao.util.AdvisoryLockUtil;
import org.folio.dao.util.MatchField;
import org.folio.dao.util.SnapshotDaoUtil;
import org.folio.processing.value.MissingValue;
import org.folio.processing.value.StringValue;
import org.folio.rest.jaxrs.model.ExternalIdsHolder;
import org.folio.rest.jaxrs.model.MarcRecordSearchRequest;
Expand Down Expand Up @@ -113,6 +114,20 @@ public void shouldReturnRecordOnGetMatchedRecordsWhenThereIsNoTrackingRecordAndF
});
}

@Test
public void shouldReturnEmptyListIfValueFieldIsEmpty(TestContext context) {
var async = context.async();
var matchField = new MatchField("010", "1", "", "a", MissingValue.getInstance());

var future = recordDao.getMatchedRecords(matchField, TypeConnection.MARC_BIB, true, 0, 10, TENANT_ID);

future.onComplete(ar -> {
context.assertTrue(ar.succeeded());
context.assertEquals(0, ar.result().size());
async.complete();
});
}

@Test
public void shouldReturnIdOnStreamMarcRecordIdsWhenThereIsNoTrackingRecordAndFallbackQueryEnabled(TestContext context) {
Async async = context.async();
Expand Down

0 comments on commit 8d741f8

Please sign in to comment.