Skip to content

Commit

Permalink
Update for foreign key for search MODINVSTOR-339 / RMB 26.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdickmeiss committed Aug 8, 2019
1 parent ef172c7 commit 1c48c05
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 132 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<ramlfiles_path>${basedir}/ramls/</ramlfiles_path>
<raml-module-builder-version>26.2.4</raml-module-builder-version>
<raml-module-builder-version>26.3.1</raml-module-builder-version>
<argLine />
</properties>

Expand Down
36 changes: 0 additions & 36 deletions src/main/java/org/folio/rest/impl/InstanceStorageAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,48 +44,12 @@ public class InstanceStorageAPI implements InstanceStorage {
// lower case headers
private static final String TENANT_HEADER = "x-okapi-tenant";
public static final String MODULE = "mod_inventory_storage";
public static final String INSTANCE_HOLDINGS_VIEW = "instance_holding_view";
public static final String INSTANCE_HOLDINGS_ITEMS_VIEW = "instance_holding_item_view";
public static final String INSTANCE_TABLE = "instance";
private static final String INSTANCE_SOURCE_MARC_TABLE = "instance_source_marc";
private static final String INSTANCE_RELATIONSHIP_TABLE = "instance_relationship";
private final Messages messages = Messages.getInstance();

PreparedCQL handleCQL(String query, int limit, int offset) throws FieldException {
boolean containsHoldingsRecordProperties = query != null && query.contains("holdingsRecords.");
boolean containsItemsRecordProperties = query != null && query.contains("item.");

if(containsItemsRecordProperties && containsHoldingsRecordProperties) {
//it_jsonb is the alias given items in the view in the DB
query = query.replaceAll("item\\.", INSTANCE_HOLDINGS_ITEMS_VIEW+".it_jsonb.");

//ho_jsonb is the alias given holdings in the view in the DB
query = query.replaceAll("holdingsRecords\\.", INSTANCE_HOLDINGS_ITEMS_VIEW+".ho_jsonb.");

return new PreparedCQL(INSTANCE_HOLDINGS_ITEMS_VIEW, query, limit, offset, Arrays.asList(
INSTANCE_HOLDINGS_ITEMS_VIEW + ".jsonb",
INSTANCE_HOLDINGS_ITEMS_VIEW + ".it_jsonb",
INSTANCE_HOLDINGS_ITEMS_VIEW + ".ho_jsonb"), INSTANCE_TABLE + ".jsonb");
}

if(containsItemsRecordProperties) {
//it_jsonb is the alias given items in the view in the DB
query = query.replaceAll("item\\.", INSTANCE_HOLDINGS_ITEMS_VIEW+".it_jsonb.");

return new PreparedCQL(INSTANCE_HOLDINGS_ITEMS_VIEW, query, limit, offset, Arrays.asList(
INSTANCE_HOLDINGS_ITEMS_VIEW + ".jsonb",
INSTANCE_HOLDINGS_ITEMS_VIEW + ".it_jsonb"), INSTANCE_TABLE + ".jsonb");
}

if(containsHoldingsRecordProperties) {
//ho_jsonb is the alias given holdings in the view in the DB
query = query.replaceAll("holdingsRecords\\.", INSTANCE_HOLDINGS_VIEW+".ho_jsonb.");

return new PreparedCQL(INSTANCE_HOLDINGS_VIEW, query, limit, offset, Arrays.asList(
INSTANCE_HOLDINGS_VIEW+".jsonb",
INSTANCE_HOLDINGS_VIEW + ".ho_jsonb"), INSTANCE_TABLE + ".jsonb");
}

return new PreparedCQL(INSTANCE_TABLE, query, limit, offset, Arrays.asList(INSTANCE_TABLE + ".jsonb"), INSTANCE_TABLE + ".jsonb");
}

Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/templates/db_scripts/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@
{
"fieldName": "instanceId",
"targetTable": "instance",
"tableAlias" : "holdingsRecords",
"tOps": "ADD"
},
{
Expand Down Expand Up @@ -721,6 +722,7 @@
{
"fieldName": "holdingsRecordId",
"targetTable": "holdings_record",
"targetTableAlias" : "holdingsRecords",
"tOps": "ADD"
},
{
Expand Down
14 changes: 7 additions & 7 deletions src/test/java/org/folio/rest/api/InstanceStorageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1325,12 +1325,12 @@ public void testCrossTableQueries() throws Exception {
createHoldings(jho3);
////////////////////////done //////////////////////////////////////

String url1 = url+URLEncoder.encode("title=Long Way to a Small Angry Planet* sortBy holdingsRecords.permanentLocationId/sort.descending title", "UTF-8");
String url2 = url+URLEncoder.encode("title=cql.allRecords=1 sortBy holdingsRecords.permanentLocationId/sort.ascending", "UTF-8");
String url3 = url+URLEncoder.encode("holdingsRecords.permanentLocationId=99999999-dee7-48eb-b03f-d02fdf0debd0 sortBy holdingsRecords.permanentLocationId/sort.descending title", "UTF-8");
String url4 = url+URLEncoder.encode("title=cql.allRecords=1 sortby holdingsRecords.permanentLocationId title", "UTF-8");
String url5 = url+URLEncoder.encode("title=cql.allRecords=1 and holdingsRecords.permanentLocationId=99999999-dee7-48eb-b03f-d02fdf0debd0 "
+ "sortby holdingsRecords.permanentLocationId", "UTF-8");
String url1 = url+ URLEncoder.encode("title=Long Way to a Small Angry Planet* sortby title", "UTF-8");
String url2 = url+ URLEncoder.encode("title=cql.allRecords=1 sortBy title", "UTF-8");
String url3 = url+ URLEncoder.encode("holdingsRecords.permanentLocationId=99999999-dee7-48eb-b03f-d02fdf0debd0 sortBy title", "UTF-8");
String url4 = url+ URLEncoder.encode("title=cql.allRecords=1 sortby title", "UTF-8");
String url5 = url+ URLEncoder.encode("title=cql.allRecords=1 and holdingsRecords.permanentLocationId=99999999-dee7-48eb-b03f-d02fdf0debd0 "
+ "sortby title", "UTF-8");
//non existant - 0 results
String url6 = url+URLEncoder.encode("title=cql.allRecords=1 and holdingsRecords.permanentLocationId=abc* sortby holdingsRecords.permanentLocationId", "UTF-8");

Expand All @@ -1357,7 +1357,7 @@ public void testCrossTableQueries() throws Exception {

if(i==0){
assertThat(3, is(cqlResponse.getJson().getInteger("totalRecords")));
assertThat("TEST2" , is(cqlResponse.getJson().getJsonArray("instances").getJsonObject(0).getString("source")));
assertThat("TEST1" , is(cqlResponse.getJson().getJsonArray("instances").getJsonObject(0).getString("source")));
} else if(i==1){
assertThat(3, is(cqlResponse.getJson().getInteger("totalRecords")));
assertThat("TEST1" , is(cqlResponse.getJson().getJsonArray("instances").getJsonObject(0).getString("source")));
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/org/folio/rest/api/StorageTestSuite.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.concurrent.TimeoutException;

import org.folio.rest.RestVerticle;
import org.folio.rest.impl.InstanceStorageAPITest;
import org.folio.rest.impl.StorageHelperTest;
import org.folio.rest.persist.PostgresClient;
import org.folio.rest.support.HttpClient;
Expand All @@ -35,7 +34,6 @@

@Suite.SuiteClasses({
InstanceStorageTest.class,
InstanceStorageAPITest.class,
HoldingsStorageTest.class,
ItemStorageTest.class,
LoanTypeTest.class,
Expand Down
86 changes: 0 additions & 86 deletions src/test/java/org/folio/rest/impl/InstanceStorageAPITest.java

This file was deleted.

0 comments on commit 1c48c05

Please sign in to comment.