use of org.folio.rest.jaxrs.model.SourceRecordCollection in project mod-source-record-storage by folio-org.
the class RecordDaoImpl method getSourceRecords.
@Override
public Future<SourceRecordCollection> getSourceRecords(List<String> externalIds, IdType idType, RecordType recordType, Boolean deleted, String tenantId) {
Condition condition = RecordDaoUtil.getExternalIdsCondition(externalIds, idType).and(RecordDaoUtil.filterRecordByDeleted(deleted));
Name cte = name(CTE);
Name prt = name(recordType.getTableName());
return getQueryExecutor(tenantId).transaction(txQE -> txQE.query(dsl -> dsl.with(cte.as(dsl.selectCount().from(RECORDS_LB).where(condition.and(recordType.getRecordImplicitCondition())))).select(getRecordFieldsWithCount(prt)).from(RECORDS_LB).leftJoin(table(prt)).on(RECORDS_LB.ID.eq(field(TABLE_FIELD_TEMPLATE, UUID.class, prt, name(ID)))).rightJoin(dsl.select().from(table(cte))).on(trueCondition()).where(condition.and(recordType.getSourceRecordImplicitCondition())))).map(this::toSourceRecordCollection);
}
use of org.folio.rest.jaxrs.model.SourceRecordCollection in project mod-source-record-storage by folio-org.
the class RecordDaoImpl method getSourceRecords.
@Override
public Future<SourceRecordCollection> getSourceRecords(Condition condition, RecordType recordType, Collection<OrderField<?>> orderFields, int offset, int limit, String tenantId) {
Name cte = name(CTE);
Name prt = name(recordType.getTableName());
return getQueryExecutor(tenantId).transaction(txQE -> txQE.query(dsl -> dsl.with(cte.as(dsl.selectCount().from(RECORDS_LB).where(condition.and(recordType.getSourceRecordImplicitCondition())))).select(getRecordFieldsWithCount(prt)).from(RECORDS_LB).leftJoin(table(prt)).on(RECORDS_LB.ID.eq(field(TABLE_FIELD_TEMPLATE, UUID.class, prt, name(ID)))).rightJoin(dsl.select().from(table(cte))).on(trueCondition()).where(condition.and(recordType.getSourceRecordImplicitCondition())).orderBy(orderFields).offset(offset).limit(limit))).map(this::toSourceRecordCollection);
}
use of org.folio.rest.jaxrs.model.SourceRecordCollection in project mod-source-record-storage by folio-org.
the class RecordDaoImpl method toSourceRecordCollection.
private SourceRecordCollection toSourceRecordCollection(QueryResult result) {
SourceRecordCollection sourceRecordCollection = new SourceRecordCollection().withTotalRecords(0);
List<SourceRecord> sourceRecords = result.stream().map(res -> asRow(res.unwrap())).map(row -> {
sourceRecordCollection.setTotalRecords(row.getInteger(COUNT));
return RecordDaoUtil.toSourceRecord(RecordDaoUtil.toRecord(row)).withParsedRecord(ParsedRecordDaoUtil.toParsedRecord(row));
}).collect(Collectors.toList());
if (!sourceRecords.isEmpty() && Objects.nonNull(sourceRecords.get(0).getRecordId())) {
sourceRecordCollection.withSourceRecords(sourceRecords);
}
return sourceRecordCollection;
}
use of org.folio.rest.jaxrs.model.SourceRecordCollection in project mod-source-record-storage by folio-org.
the class SourceRecordApiTest method shouldReturnSourceRecordWithAdditionalInfoOnGetBySpecifiedSnapshotId.
@Test
public void shouldReturnSourceRecordWithAdditionalInfoOnGetBySpecifiedSnapshotId(TestContext testContext) {
postSnapshots(testContext, snapshot_2);
String matchedId = UUID.randomUUID().toString();
Record newRecord = new Record().withId(matchedId).withSnapshotId(snapshot_2.getJobExecutionId()).withRecordType(Record.RecordType.MARC_BIB).withRawRecord(rawRecord).withParsedRecord(marcRecord).withMatchedId(matchedId).withAdditionalInfo(new AdditionalInfo().withSuppressDiscovery(true));
Async async = testContext.async();
Response createResponse = RestAssured.given().spec(spec).body(newRecord).when().post(SOURCE_STORAGE_RECORDS_PATH);
assertThat(createResponse.statusCode(), is(HttpStatus.SC_CREATED));
Record createdRecord = createResponse.body().as(Record.class);
async.complete();
async = testContext.async();
Response getResponse = RestAssured.given().spec(spec).when().get(SOURCE_STORAGE_SOURCE_RECORDS_PATH + "?snapshotId=" + newRecord.getSnapshotId() + "&suppressFromDiscovery=true");
assertThat(getResponse.statusCode(), is(HttpStatus.SC_OK));
SourceRecordCollection sourceRecordCollection = getResponse.body().as(SourceRecordCollection.class);
assertThat(sourceRecordCollection.getSourceRecords().size(), is(1));
SourceRecord sourceRecord = sourceRecordCollection.getSourceRecords().get(0);
assertThat(sourceRecord.getRecordId(), is(createdRecord.getId()));
// NOTE: raw record is no longer returned with source records for effeciency
// assertThat(sourceRecord.getRawRecord().getContent(), is(rawRecord.getContent()));
assertThat(sourceRecord.getAdditionalInfo().getSuppressDiscovery(), is(createdRecord.getAdditionalInfo().getSuppressDiscovery()));
async.complete();
}
Aggregations