From 537e0d9c2aee08cad0eaa91958de152bc71a3c9e Mon Sep 17 00:00:00 2001 From: Gabor Nagy Date: Mon, 25 Sep 2023 17:53:09 +0200 Subject: [PATCH] fix(snomed): update resource settings using the generic resource API ... ... after a successful SNOMED CT import --- .../request/rf2/SnomedRf2ImportRequest.java | 26 ++++++++++++------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/snomed/com.b2international.snowowl.snomed.datastore/src/com/b2international/snowowl/snomed/datastore/request/rf2/SnomedRf2ImportRequest.java b/snomed/com.b2international.snowowl.snomed.datastore/src/com/b2international/snowowl/snomed/datastore/request/rf2/SnomedRf2ImportRequest.java index 024d3e1fea7..2d17454d3ea 100644 --- a/snomed/com.b2international.snowowl.snomed.datastore/src/com/b2international/snowowl/snomed/datastore/request/rf2/SnomedRf2ImportRequest.java +++ b/snomed/com.b2international.snowowl.snomed.datastore/src/com/b2international/snowowl/snomed/datastore/request/rf2/SnomedRf2ImportRequest.java @@ -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; @@ -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; @@ -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 // @@ -469,8 +475,8 @@ private void updateCodeSystemSettings(final BranchContext context, final Resourc List 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); } @@ -486,7 +492,7 @@ private void updateCodeSystemSettings(final BranchContext context, final Resourc //////////////////////////// Map 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); }); @@ -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); }