Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SO-5834: generic dependency model #1188

Merged
merged 26 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7878de1
feat(core): introduce new dependency model
cmark Jul 10, 2023
41080cf
feat(core): migrate resource creation to use the new dependency model
cmark Jul 11, 2023
8add22f
feat(core): allow updating new dependencies field through resource API
cmark Jul 12, 2023
f64a6cc
feat(core): add missing setDependencies method to resource updates req
cmark Jul 12, 2023
6994c9b
Merge remote-tracking branch 'origin/8.x' into feature/SO-5834-depend…
cmark Jul 13, 2023
cb29f83
fix(core): properly convert old dependency model values from new...
cmark Jul 14, 2023
efaf06e
feat(core): add hasQueryPart method to ResourceURIWithQuery
cmark Jul 14, 2023
1be50c6
feat(api): support `dependencies` when creating new codesystems
cmark Jul 14, 2023
91b380b
feat(api): support `dependencies` when updating existing codesystems
cmark Jul 14, 2023
3fc8a5f
fix(test): revert upgrade API to use the old model until migration
cmark Jul 17, 2023
ddf5a52
fix(core): properly update dependencies when syncing a codesystem...
cmark Jul 17, 2023
ea8076f
feat(api): check dependency entry reference integrity before commit
cmark Jul 17, 2023
88c268d
feat(api): check dependency entry duplication when creating a resource
cmark Jul 18, 2023
5ad7e91
feat(api): check dependency entries when updating a resource
cmark Jul 18, 2023
4374cfa
feat(index): add support for query_string expression in index layer
cmark Jul 19, 2023
852dae8
feat(core): rename Dependency field `resourceUri` to `uri`
cmark Jul 20, 2023
84d35d0
feat(core): support searching for dependency array entries via...
cmark Jul 20, 2023
05a8fd1
test(core): add test case to verify unversioned and versioned...
cmark Jul 20, 2023
7dc70be
feat(core): check if a resource being deleted is referenced by...
cmark Jul 20, 2023
2f4f070
fix(core): scope compare in DependencyDocument
cmark Jul 20, 2023
8b9e34c
test: remove duplicate codesystem api test
cmark Jul 20, 2023
9f8985a
feat(core): maintain dependencies on version documents for proper...
cmark Jul 20, 2023
5fa02f0
feat(core): minor Java API changes to ensure third party modules...
cmark Jul 21, 2023
04d8961
feat(core): make sure resource URIs with queries are recognized properly
cmark Jul 24, 2023
cbaf364
fix(core): clarify comment in BaseTerminologyResourceCreateRequest
cmark Jul 26, 2023
13d467b
feat(core): support updating dependencies through other parameters...
cmark Jul 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
* Copyright 2023 B2i Healthcare Pte Ltd, http://b2i.sg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.b2international.index;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.Collection;

import org.elasticsearch.core.List;
import org.junit.Before;
import org.junit.Test;

import com.b2international.index.Fixtures.Data;
import com.b2international.index.query.Expressions;
import com.b2international.index.query.Query;

/**
* @since 8.12
*/
public class QueryStringQueryTest extends BaseIndexTest {

private static final String KEY3 = "key3";

private Data data1;
private Data data2;
private Data data3;

@Override
protected Collection<Class<?>> getTypes() {
return List.of(Data.class);
}

@Before
public void setup() {
data1 = new Data(KEY1);
data1.setField1("value1");
data1.setField2("value2");

data2 = new Data(KEY2);
data2.setField1("value2");
data2.setField2("value1");

data3 = new Data(KEY3);
data3.setField1("field1");
data3.setField2("field2");

indexDocuments(
data1,
data2,
data3
);
}

@Test
public void without_defaultField() throws Exception {
Hits<String> hits = search(Query.select(String.class)
.from(Data.class)
.fields("id")
.where(Expressions.queryString("value1"))
.build());

assertThat(hits).containsOnly(KEY1, KEY2);
}

@Test
public void with_defaultField() throws Exception {
Hits<String> hits = search(Query.select(String.class)
.from(Data.class)
.fields("id")
.where(Expressions.queryString("value1", "field1"))
.build());

assertThat(hits).containsOnly(KEY1);
}

@Test
public void explicit_fields() throws Exception {
Hits<String> hits = search(Query.select(String.class)
.from(Data.class)
.fields("id")
.where(Expressions.queryString("field1:value1"))
.build());

assertThat(hits).containsOnly(KEY1);
}

@Test
public void prefix() throws Exception {
Hits<String> hits = search(Query.select(String.class)
.from(Data.class)
.fields("id")
.where(Expressions.queryString("field1:value*"))
.build());

assertThat(hits).containsOnly(KEY1, KEY2);
}

@Test
public void fuzzy() throws Exception {
Hits<String> hits = search(Query.select(String.class)
.from(Data.class)
.fields("id")
.where(Expressions.queryString("field1:valeu1~1"))
.build());

assertThat(hits).containsOnly(KEY1);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 B2i Healthcare Pte Ltd, http://b2i.sg
* Copyright 2022-2023 B2i Healthcare Pte Ltd, http://b2i.sg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -152,6 +152,8 @@ private void visit(Expression expression) {
visit((ScriptQueryExpression) expression);
} else if (expression instanceof MoreLikeThisPredicate){
visit((MoreLikeThisPredicate) expression);
} else if (expression instanceof QueryStringExpression){
visit((QueryStringExpression) expression);
} else {
throw new IllegalArgumentException("Unexpected expression: " + expression);
}
Expand Down Expand Up @@ -549,5 +551,11 @@ private void visit(MoreLikeThisPredicate mlt) {
)
);
}

private void visit(QueryStringExpression qs) {
deque.push(
QueryBuilders.queryString(q -> q.query(qs.getQuery()).defaultField(qs.getDefaultField()))
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ private void visit(Expression expression) {
visit((ScriptQueryExpression)expression);
} else if (expression instanceof MoreLikeThisPredicate) {
visit((MoreLikeThisPredicate) expression);
} else if (expression instanceof QueryStringExpression) {
visit((QueryStringExpression) expression);
} else {
throw new IllegalArgumentException("Unexpected expression: " + expression);
}
Expand Down Expand Up @@ -433,4 +435,11 @@ private void visit(MoreLikeThisPredicate mlt) {
);
}

private void visit(QueryStringExpression qs) {
deque.push(
QueryBuilders.queryStringQuery(qs.getQuery())
.defaultField(qs.getDefaultField())
);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2022 B2i Healthcare Pte Ltd, http://b2i.sg
* Copyright 2011-2023 B2i Healthcare Pte Ltd, http://b2i.sg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -303,5 +303,14 @@ public static Expression matchAnyObject(String field, Iterable<?> values) {
public static MoreLikeThisPredicate moreLikeThis(Iterable<String> fields, Iterable<String> likeTexts, Iterable<String> unlikeTexts) {
return new MoreLikeThisPredicate(fields, likeTexts, unlikeTexts);
}

public static QueryStringExpression queryString(String query) {
return queryString(query, null);
}

public static QueryStringExpression queryString(String query, String defaultField) {
return new QueryStringExpression(query, defaultField);
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright 2023 B2i Healthcare Pte Ltd, http://b2i.sg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.b2international.index.query;

import java.util.Objects;

/**
* @since 8.12
*/
public final class QueryStringExpression implements Expression {

private final String query;
private final String defaultField;

public QueryStringExpression(String query, String defaultField) {
this.query = query;
this.defaultField = defaultField;
}

public String getQuery() {
return query;
}

public String getDefaultField() {
return defaultField;
}

@Override
public int hashCode() {
return Objects.hash(query, defaultField);
}

@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj == null) return false;
if (getClass() != obj.getClass()) return false;
QueryStringExpression predicate = (QueryStringExpression) obj;
return Objects.equals(query, predicate.query)
&& Objects.equals(defaultField, predicate.defaultField);
}

@Override
public String toString() {
return String.format("QUERY_STRING(%s)[defaultField:'%s']", query, defaultField);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021-2022 B2i Healthcare Pte Ltd, http://b2i.sg
* Copyright 2021-2023 B2i Healthcare Pte Ltd, http://b2i.sg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -67,7 +67,8 @@ public void cleanUp() {
.execute(Services.bus())
.getSync(1, TimeUnit.MINUTES)
.forEach(bundle -> {
ResourceRequests.prepareDelete(bundle.getId())
ResourceRequests.prepareDelete(bundle.getResourceURI())
.force(true)
.build(USER, String.format("Delete bundle: %s", bundle.getId()))
.execute(Services.bus())
.getSync(1, TimeUnit.MINUTES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.b2international.snowowl.core.rest.auth.AuthorizationTest;
import com.b2international.snowowl.core.rest.auth.BasicAuthenticationTest;
import com.b2international.snowowl.core.rest.bundle.BundleRestApiTest;
import com.b2international.snowowl.core.rest.codesystem.CodeSystemApiDependencyTest;
import com.b2international.snowowl.core.rest.codesystem.CodeSystemApiTest;
import com.b2international.snowowl.core.rest.rate.RateLimitTest;
import com.b2international.snowowl.core.rest.resource.ResourceApiTest;
Expand All @@ -40,6 +41,7 @@
AuthorizationTest.class,
RateLimitTest.class,
CodeSystemApiTest.class,
CodeSystemApiDependencyTest.class,
ResourceApiTest.class,
BundleApiTest.class,
BundleRestApiTest.class,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2021 B2i Healthcare Pte Ltd, http://b2i.sg
* Copyright 2021-2023 B2i Healthcare Pte Ltd, http://b2i.sg
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,10 +38,11 @@ public void after() {
.getSync(1, TimeUnit.MINUTES)
.forEach(resource -> {
ResourceRequests
.prepareDelete(resource.getId())
.build(RestExtensions.USER, "Delete " + resource.getId())
.execute(Services.bus())
.getSync(1, TimeUnit.MINUTES);
.prepareDelete(resource.getResourceURI())
.force(true)
.build(RestExtensions.USER, "Delete " + resource.getId())
.execute(Services.bus())
.getSync(1, TimeUnit.MINUTES);
});
}

Expand Down
Loading