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 9 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
Expand Up @@ -40,6 +40,7 @@
import com.b2international.commons.exceptions.NotFoundException;
import com.b2international.commons.http.AcceptLanguageHeader;
import com.b2international.commons.json.Json;
import com.b2international.snowowl.core.Dependency;
import com.b2international.snowowl.core.Resource;
import com.b2international.snowowl.core.ResourceURI;
import com.b2international.snowowl.core.branch.Branch;
Expand Down Expand Up @@ -264,7 +265,7 @@ public void codesystem15_CreateWithDedicatedBranchPath() {
}

@Test
public void codesystem16_CreateWithExtensionOf() {
public void codesystem16_CreateWithExtensionOfOldModel() {
final String parentCodeSystemId = "cs11";
final Json parentRequestBody = prepareCodeSystemCreateRequestBody(parentCodeSystemId);
assertCodeSystemCreated(parentRequestBody);
Expand All @@ -277,11 +278,11 @@ public void codesystem16_CreateWithExtensionOf() {

final Json requestBody = prepareCodeSystemCreateRequestBody(codeSystemId)
.without("branchPath")
.with("extensionOf", CodeSystem.uri("cs11/v1"));
.with("extensionOf", CodeSystem.uri(parentCodeSystemId, "v1"));

assertCodeSystemCreated(requestBody);

final String expectedBranchPath = Branch.get(Branch.MAIN_PATH, "cs11", "v1", codeSystemId);
final String expectedBranchPath = Branch.get(Branch.MAIN_PATH, parentCodeSystemId, "v1", codeSystemId);

try {

Expand All @@ -292,6 +293,9 @@ public void codesystem16_CreateWithExtensionOf() {
.execute(Services.bus())
.getSync();

assertCodeSystemGet(codeSystemId)
.body("extensionOf", equalTo("codesystems/cs11/v1"));

} catch (NotFoundException e) {
fail("Branch " + expectedBranchPath + " did not get created as part of code system creation");
}
Expand Down Expand Up @@ -367,7 +371,7 @@ public void codesystem20_UpdateInvalidBranchPath() {
}

@Test
public void codesystem21_UpdateExtensionOf() {
public void codesystem21_UpdateExtensionOfOldModel() {
final String parentCodeSystemId = "cs13";
final Json parentRequestBody = prepareCodeSystemCreateRequestBody(parentCodeSystemId);
assertCodeSystemCreated(parentRequestBody);
Expand Down Expand Up @@ -652,6 +656,75 @@ public void codesystem33_AllowDraftResourcesToBeQueriedWithLATEST() throws Excep
.getSync();
}

@Test
public void codesystem34_CreateWithExtensionOfNewModel() {
final String parentCodeSystemId = "cs34";
final Json parentRequestBody = prepareCodeSystemCreateRequestBody(parentCodeSystemId);
assertCodeSystemCreated(parentRequestBody);
assertCodeSystemGet(parentCodeSystemId).statusCode(200);

final Json versionRequestBody = prepareVersionCreateRequestBody(CodeSystem.uri(parentCodeSystemId), "v1", "2023-07-14");
assertVersionCreated(versionRequestBody).statusCode(201);

final String codeSystemId = "cs35";

final Json requestBody = prepareCodeSystemCreateRequestBody(codeSystemId)
.without("branchPath")
.with("dependencies", List.of(Dependency.of(CodeSystem.uri(parentCodeSystemId, "v1"), "extensionOf")));

assertCodeSystemCreated(requestBody);

final String expectedBranchPath = Branch.get(Branch.MAIN_PATH, parentCodeSystemId, "v1", codeSystemId);

try {

// Check if the branch has been created
RepositoryRequests.branching()
.prepareGet(expectedBranchPath)
.build(TOOLING_ID)
.execute(Services.bus())
.getSync();

// check extensionOf value comes back as part of both dependencies and extensionOf
assertCodeSystemGet(codeSystemId)
.statusCode(200)
.body("extensionOf", equalTo("codesystems/cs34/v1"))
.body("dependencies", hasItem(Map.of("resourceUri", "codesystems/cs34/v1", "scope", "extensionOf")));

} catch (NotFoundException e) {
fail("Branch " + expectedBranchPath + " did not get created as part of code system creation");
}
}

@Test
public void codesystem35_UpdateExtensionOfNewModel() {
final String parentCodeSystemId = "cs35";
final Json parentRequestBody = prepareCodeSystemCreateRequestBody(parentCodeSystemId);
assertCodeSystemCreated(parentRequestBody);
assertCodeSystemGet(parentCodeSystemId).statusCode(200);

final Json v3RequestBody = prepareVersionCreateRequestBody(CodeSystem.uri(parentCodeSystemId), "v3", "2020-04-16");
assertVersionCreated(v3RequestBody).statusCode(201);
final Json v4RequestBody = prepareVersionCreateRequestBody(CodeSystem.uri(parentCodeSystemId), "v4", "2020-04-17");
assertVersionCreated(v4RequestBody).statusCode(201);

final String codeSystemId = "cs36";
final Json requestBody = prepareCodeSystemCreateRequestBody(codeSystemId)
.without("branchPath")
.with("dependencies", List.of(Dependency.of(CodeSystem.uri("cs35/v3"), "extensionOf")));

assertCodeSystemCreated(requestBody);
assertCodeSystemUpdated(codeSystemId, Json.object("dependencies", List.of(Dependency.of(CodeSystem.uri("cs35/v4"), "extensionOf"))));

final String expectedBranchPath = Branch.get(Branch.MAIN_PATH, "cs35", "v4", codeSystemId);

assertCodeSystemGet(codeSystemId)
.statusCode(200)
.body("extensionOf", equalTo("codesystems/cs35/v4"))
.body("dependencies", hasItem(Map.of("resourceUri", "codesystems/cs35/v4", "scope", "extensionOf")))
.body("branchPath", equalTo(expectedBranchPath));
}

private long getCodeSystemCreatedAt(final String id) {
return assertCodeSystemGet(id)
.statusCode(200)
Expand Down
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 @@ -138,11 +138,11 @@ public final String getPurpose() {
return purpose;
}

public void setSettings(Map<String, Object> settings) {
public final void setSettings(Map<String, Object> settings) {
this.settings = settings;
}

public Map<String, Object> getSettings() {
public final Map<String, Object> getSettings() {
return settings;
}
}
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 @@ -124,11 +124,11 @@ public final String getPurpose() {
return purpose;
}

public void setSettings(Map<String, Object> settings) {
public final void setSettings(Map<String, Object> settings) {
this.settings = settings;
}

public Map<String, Object> getSettings() {
public final Map<String, Object> getSettings() {
return settings;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.snowowl.core.rest;

import java.util.List;

import com.b2international.snowowl.core.Dependency;

/**
* @since 8.12
*/
public abstract class BaseTerminologyResourceRestInput extends BaseResourceRestInput {

private List<Dependency> dependencies;

public List<Dependency> getDependencies() {
return dependencies;
}

public void setDependencies(List<Dependency> dependencies) {
this.dependencies = dependencies;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* 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.snowowl.core.rest;

import java.util.List;

import com.b2international.snowowl.core.Dependency;

/**
* @since 8.12
*/
public abstract class BaseTerminologyResourceUpdateRestInput extends BaseResourceUpdateRestInput {

private List<Dependency> dependencies;

public List<Dependency> getDependencies() {
return dependencies;
}

public void setDependencies(List<Dependency> dependencies) {
this.dependencies = dependencies;
}

}
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 All @@ -18,12 +18,12 @@
import com.b2international.snowowl.core.ResourceURI;
import com.b2international.snowowl.core.codesystem.CodeSystemCreateRequestBuilder;
import com.b2international.snowowl.core.codesystem.CodeSystemRequests;
import com.b2international.snowowl.core.rest.BaseResourceRestInput;
import com.b2international.snowowl.core.rest.BaseTerminologyResourceRestInput;

/**
* @since 8.0
*/
public final class CodeSystemCreateRestInput extends BaseResourceRestInput {
public final class CodeSystemCreateRestInput extends BaseTerminologyResourceRestInput {

private String oid;
private String branchPath;
Expand Down Expand Up @@ -54,10 +54,18 @@ public String getToolingId() {
return toolingId;
}

/**
* @param extensionOf
* @deprecated - replaced by {@link #setDependencies(java.util.List)}, will be removed in 9.0
*/
public void setExtensionOf(ResourceURI extensionOf) {
this.extensionOf = extensionOf;
}

/**
* @return
* @deprecated - replaced by {@link #getDependencies()}, will be removed in 9.0
*/
public ResourceURI getExtensionOf() {
return extensionOf;
}
Expand All @@ -79,7 +87,9 @@ public CodeSystemCreateRequestBuilder toCodeSystemCreateRequest() {
.setOid(getOid())
.setBranchPath(getBranchPath())
.setToolingId(getToolingId())
.setExtensionOf(getExtensionOf())
.setSettings(getSettings());
.setSettings(getSettings())
.setDependencies(getDependencies())
// XXX support old model input until 9.0
.setExtensionOf(getExtensionOf());
}
}
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 All @@ -18,12 +18,12 @@
import com.b2international.snowowl.core.ResourceURI;
import com.b2international.snowowl.core.codesystem.CodeSystemRequests;
import com.b2international.snowowl.core.codesystem.CodeSystemUpdateRequestBuilder;
import com.b2international.snowowl.core.rest.BaseResourceUpdateRestInput;
import com.b2international.snowowl.core.rest.BaseTerminologyResourceUpdateRestInput;

/**
* @since 8.0
*/
public final class CodeSystemUpdateRestInput extends BaseResourceUpdateRestInput {
public final class CodeSystemUpdateRestInput extends BaseTerminologyResourceUpdateRestInput {

private String oid;
private String branchPath;
Expand All @@ -45,10 +45,18 @@ public String getBranchPath() {
return branchPath;
}

/**
* @param extensionOf
* @deprecated - replaced by {@link #setDependencies(java.util.List)}, will be removed in 9.0
*/
public void setExtensionOf(ResourceURI extensionOf) {
this.extensionOf = extensionOf;
}

/**
* @return
* @deprecated - replaced by {@link #getDependencies()}, will be removed in 9.0
*/
public ResourceURI getExtensionOf() {
return extensionOf;
}
Expand All @@ -68,7 +76,10 @@ public CodeSystemUpdateRequestBuilder toCodeSystemUpdateRequest(String codeSyste
.setBundleId(getBundleId())
.setOid(getOid())
.setBranchPath(getBranchPath())
.setSettings(getSettings())
.setDependencies(getDependencies())
// XXX maintain old model field options until 9.0
.setExtensionOf(getExtensionOf())
.setSettings(getSettings());
;
}
}
Loading