Skip to content

Commit

Permalink
fix(snomed): update resource settings using the generic resource API ...
Browse files Browse the repository at this point in the history
... after a successful SNOMED CT import
  • Loading branch information
nagyo committed Sep 25, 2023
1 parent 42f25fb commit 537e0d9
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import com.b2international.commons.http.ExtendedLocale;
import com.b2international.index.query.Query;
import com.b2international.index.revision.RevisionSearcher;
import com.b2international.snowowl.core.Resource;
import com.b2international.snowowl.core.ResourceURI;
import com.b2international.snowowl.core.TerminologyResource;
import com.b2international.snowowl.core.api.SnowowlRuntimeException;
Expand All @@ -58,7 +59,6 @@
import com.b2international.snowowl.core.attachments.InternalAttachmentRegistry;
import com.b2international.snowowl.core.authorization.AccessControl;
import com.b2international.snowowl.core.codesystem.CodeSystem;
import com.b2international.snowowl.core.codesystem.CodeSystemRequests;
import com.b2international.snowowl.core.date.DateFormats;
import com.b2international.snowowl.core.date.EffectiveTimes;
import com.b2international.snowowl.core.domain.BranchContext;
Expand Down Expand Up @@ -430,12 +430,18 @@ private DB createDb() {
}

@SuppressWarnings("deprecation")
private void updateCodeSystemSettings(final BranchContext context, final ResourceURI codeSystemUri) throws Exception {
private void updateCodeSystemSettings(final BranchContext context, final ResourceURI resourceUri) throws Exception {

// fetch codesystem to get the latest settings
CodeSystem currentSnomedCodeSystem = CodeSystemRequests.prepareGetCodeSystem(codeSystemUri.getResourceId())
.buildAsync()
.get(context);
Resource resource = ResourceRequests.prepareGet(resourceUri)
.buildAsync()
.get(context);

if (!(resource instanceof TerminologyResource)) {
return;
}

TerminologyResource currentResource = (TerminologyResource) resource;

/////////////
// Locales //
Expand Down Expand Up @@ -469,8 +475,8 @@ private void updateCodeSystemSettings(final BranchContext context, final Resourc

List<ExtendedLocale> currentLocales = newArrayList();

if (!CompareUtils.isEmpty(currentSnomedCodeSystem.getLocales())) {
currentSnomedCodeSystem.getLocales().stream()
if (!CompareUtils.isEmpty(currentResource.getLocales())) {
currentResource.getLocales().stream()
.map(locale -> ExtendedLocale.valueOf(locale))
.forEach(currentLocales::add);
}
Expand All @@ -486,7 +492,7 @@ private void updateCodeSystemSettings(final BranchContext context, final Resourc
////////////////////////////

Map<String, SnomedLanguageConfig> mergedLanguagesConfiguration = Maps.newLinkedHashMap();
SnomedDescriptionUtils.getLanguagesConfiguration(context.service(ObjectMapper.class), currentSnomedCodeSystem).forEach(config -> {
SnomedDescriptionUtils.getLanguagesConfiguration(context.service(ObjectMapper.class), currentResource).forEach(config -> {
mergedLanguagesConfiguration.put(config.getLanguageTag(), config);
});

Expand All @@ -500,12 +506,12 @@ private void updateCodeSystemSettings(final BranchContext context, final Resourc

});

CodeSystemRequests.prepareUpdateCodeSystem(codeSystemUri.getResourceId())
ResourceRequests.prepareUpdate(resourceUri.getResourceId())
.setSettings(Map.of(
CodeSystem.CommonSettings.LOCALES, currentLocales,
SnomedTerminologyComponentConstants.CODESYSTEM_LANGUAGE_CONFIG_KEY, mergedLanguagesConfiguration.values()
))
.build(author, String.format("Update '%s' settings based on RF2 import", codeSystemUri.getResourceId()))
.build(author, String.format("Update '%s' settings based on RF2 import", resourceUri.getResourceId()))
.execute(context.service(IEventBus.class))
.getSync(2, TimeUnit.MINUTES);
}
Expand Down

0 comments on commit 537e0d9

Please sign in to comment.