Search in sources :

Example 1 with Acceptability

use of com.b2international.snowowl.snomed.core.domain.Acceptability in project snow-owl by b2ihealthcare.

the class DescriptionChangeProcessor method processChanges.

private void processChanges(final String id, final Builder doc, final SnomedDescriptionIndexEntry currentRevision, Multimap<Acceptability, RefSetMemberChange> acceptabilityChanges, Multimap<String, RefSetMemberChange> referringRefSets) {
    final Multimap<Acceptability, String> acceptabilityMap = currentRevision == null ? ImmutableMultimap.<Acceptability, String>of() : ImmutableMap.copyOf(currentRevision.getAcceptabilityMap()).asMultimap().inverse();
    final Collection<String> preferredLanguageRefSets = newHashSet(acceptabilityMap.get(Acceptability.PREFERRED));
    final Collection<String> acceptableLanguageRefSets = newHashSet(acceptabilityMap.get(Acceptability.ACCEPTABLE));
    if (acceptabilityChanges != null) {
        collectChanges(acceptabilityChanges.get(Acceptability.PREFERRED), preferredLanguageRefSets);
        collectChanges(acceptabilityChanges.get(Acceptability.ACCEPTABLE), acceptableLanguageRefSets);
    }
    // clear acceptability map first then apply new acceptability settings
    doc.acceptabilityMap(Collections.emptyMap());
    for (String preferredLanguageRefSet : preferredLanguageRefSets) {
        doc.acceptability(preferredLanguageRefSet, Acceptability.PREFERRED);
    }
    for (String acceptableLanguageRefSet : acceptableLanguageRefSets) {
        doc.acceptability(acceptableLanguageRefSet, Acceptability.ACCEPTABLE);
    }
    final Collection<String> currentMemberOf = currentRevision == null ? Collections.emptySet() : currentRevision.getMemberOf();
    final Collection<String> currentActiveMemberOf = currentRevision == null ? Collections.emptySet() : currentRevision.getActiveMemberOf();
    new ReferenceSetMembershipUpdater(referringRefSets.removeAll(id), currentMemberOf, currentActiveMemberOf).update(doc);
}
Also used : ReferenceSetMembershipUpdater(com.b2international.snowowl.snomed.datastore.index.update.ReferenceSetMembershipUpdater) Acceptability(com.b2international.snowowl.snomed.core.domain.Acceptability)

Example 2 with Acceptability

use of com.b2international.snowowl.snomed.core.domain.Acceptability in project snow-owl by b2ihealthcare.

the class SnomedDescriptionAcceptabilityUpdateRequest method doExecute.

@Override
protected void doExecute(TransactionContext context, SnomedComponentDocument componentToUpdate) {
    final Iterable<SnomedReferenceSetMember> existingMembers = create ? Collections.emptySet() : SnomedRequests.prepareSearchMember().all().filterByReferencedComponent(componentToUpdate.getId()).filterByRefSetType(Collections.singleton(SnomedRefSetType.LANGUAGE)).build().execute(context);
    final Map<String, Acceptability> newLanguageMembersToCreate = newHashMap(newAcceptabilityMap);
    final ModuleIdProvider moduleIdSupplier = context.service(ModuleIdProvider.class);
    // check if there are existing matches
    for (SnomedReferenceSetMember existingMember : existingMembers) {
        final String acceptabilityId = (String) existingMember.getProperties().get(SnomedRf2Headers.FIELD_ACCEPTABILITY_ID);
        final Acceptability acceptability = Acceptability.getByConceptId(acceptabilityId);
        final String languageReferenceSetId = existingMember.getRefsetId();
        if (null == acceptability) {
            continue;
        }
        final SnomedRefSetMemberIndexEntry.Builder updatedMember = SnomedRefSetMemberIndexEntry.builder(existingMember);
        final SnomedRefSetMemberIndexEntry oldRevision = updatedMember.build();
        if (acceptability.equals(newLanguageMembersToCreate.get(languageReferenceSetId))) {
            // Exact match: make sure that the member is active
            if (ensureMemberActive(context, existingMember, updatedMember)) {
                context.update(oldRevision, updatedMember.build());
            }
            // Remove it from the working list, as we have found a match
            newLanguageMembersToCreate.remove(languageReferenceSetId);
        } else if (newLanguageMembersToCreate.containsKey(languageReferenceSetId)) {
            // Change acceptability, set status to active if required, place it in the supplied module
            final Acceptability newAcceptability = newLanguageMembersToCreate.get(languageReferenceSetId);
            updatedMember.field(SnomedRf2Headers.FIELD_ACCEPTABILITY_ID, newAcceptability.getConceptId());
            ensureMemberActive(context, existingMember, updatedMember);
            updateModule(context, existingMember, updatedMember, moduleIdSupplier.apply(componentToUpdate));
            unsetEffectiveTime(existingMember, updatedMember);
            context.update(oldRevision, updatedMember.build());
            newLanguageMembersToCreate.remove(languageReferenceSetId);
        } else {
            // Not acceptable in this language reference set, remove or inactivate if already released
            if (removeOrDeactivate(context, existingMember, updatedMember)) {
                context.update(oldRevision, updatedMember.build());
            }
        }
    }
    for (final Entry<String, Acceptability> languageMemberEntry : newLanguageMembersToCreate.entrySet()) {
        SnomedComponents.newLanguageMember().withAcceptability(languageMemberEntry.getValue()).withRefSet(languageMemberEntry.getKey()).withModuleId(moduleIdSupplier.apply(componentToUpdate)).withReferencedComponent(componentToUpdate.getId()).addTo(context);
    }
}
Also used : SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) ModuleIdProvider(com.b2international.snowowl.snomed.datastore.request.ModuleRequest.ModuleIdProvider) Acceptability(com.b2international.snowowl.snomed.core.domain.Acceptability)

Example 3 with Acceptability

use of com.b2international.snowowl.snomed.core.domain.Acceptability in project snow-owl by b2ihealthcare.

the class SnomedDescriptionApiTest method testDuplicateMemberCleanupEmptiesAcceptabilityMap.

@Test
public void testDuplicateMemberCleanupEmptiesAcceptabilityMap() throws Exception {
    String descriptionId = createNewDescription(branchPath);
    // Inject inactive language member with different acceptability (API won't allow it)
    String memberIdToUpdate = UUID.randomUUID().toString();
    SnomedRefSetMemberIndexEntry member = SnomedRefSetMemberIndexEntry.builder().id(memberIdToUpdate).active(false).released(false).moduleId(Concepts.MODULE_SCT_CORE).refsetId(Concepts.REFSET_LANGUAGE_TYPE_UK).referencedComponentId(descriptionId).referenceSetType(SnomedRefSetType.LANGUAGE).field(SnomedRf2Headers.FIELD_ACCEPTABILITY_ID, Concepts.REFSET_DESCRIPTION_ACCEPTABILITY_PREFERRED).build();
    new RepositoryRequest<>(SnomedTerminologyComponentConstants.TOOLING_ID, context -> {
        ApplicationContext.getServiceForClass(RepositoryManager.class).get(SnomedTerminologyComponentConstants.TOOLING_ID).service(RevisionIndex.class).prepareCommit(branchPath.getPath()).stageNew(member).withContext(context.inject().bind(ModuleIdProvider.class, c -> c.getModuleId()).build()).commit(ApplicationContext.getServiceForClass(TimestampProvider.class).getTimestamp(), "test", "Added duplicate language reference set member to " + descriptionId);
        return null;
    }).execute(ApplicationContext.getServiceForClass(Environment.class));
    // Check the acceptability map; the description should be acceptable in the UK reference set
    SnomedDescription description = getComponent(branchPath, SnomedComponentType.DESCRIPTION, descriptionId, "members()").statusCode(200).extract().as(SnomedDescription.class);
    assertEquals(Acceptability.ACCEPTABLE, description.getAcceptabilityMap().get(Concepts.REFSET_LANGUAGE_TYPE_UK));
    assertEquals(2, description.getMembers().getTotal());
    String memberIdToDelete = null;
    for (SnomedReferenceSetMember descriptionMember : description.getMembers()) {
        if (Concepts.REFSET_DESCRIPTION_ACCEPTABILITY_ACCEPTABLE.equals(descriptionMember.getProperties().get(SnomedRf2Headers.FIELD_ACCEPTABILITY_ID))) {
            memberIdToDelete = descriptionMember.getId();
            break;
        }
    }
    assertNotNull(memberIdToDelete);
    // Using bulk update, remove the currently active member and activate the inactive one, also changing its acceptability
    Json bulkRequest = Json.object("requests", Json.array(Json.object("action", "delete", "memberId", memberIdToDelete), Json.object("action", "update", "memberId", memberIdToUpdate, "active", true, "acceptabilityId", Concepts.REFSET_DESCRIPTION_ACCEPTABILITY_ACCEPTABLE)), "commitComment", "Consolidated language reference set members");
    bulkUpdateMembers(branchPath, Concepts.REFSET_LANGUAGE_TYPE_UK, bulkRequest).statusCode(204);
    // Verify that description acceptability is still acceptable, but only one member remains
    SnomedDescription newDescription = getComponent(branchPath, SnomedComponentType.DESCRIPTION, descriptionId, "members()").statusCode(200).extract().as(SnomedDescription.class);
    assertEquals(Acceptability.ACCEPTABLE, newDescription.getAcceptabilityMap().get(Concepts.REFSET_LANGUAGE_TYPE_UK));
    assertEquals(1, newDescription.getMembers().getTotal());
    SnomedReferenceSetMember languageMember = Iterables.getOnlyElement(newDescription.getMembers());
    assertEquals(memberIdToUpdate, languageMember.getId());
    assertEquals(true, languageMember.isActive());
}
Also used : SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) CoreMatchers(org.hamcrest.CoreMatchers) RestExtensions.assertCreated(com.b2international.snowowl.test.commons.rest.RestExtensions.assertCreated) SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) Json(com.b2international.commons.json.Json) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) SnomedRestFixtures(com.b2international.snowowl.snomed.core.rest.SnomedRestFixtures) SnomedComponentType(com.b2international.snowowl.snomed.core.rest.SnomedComponentType) IdentifierStatus(com.b2international.snowowl.snomed.cis.domain.IdentifierStatus) ApplicationContext.getServiceForClass(com.b2international.snowowl.core.ApplicationContext.getServiceForClass) Map(java.util.Map) RevisionIndex(com.b2international.index.revision.RevisionIndex) RepositoryRequest(com.b2international.snowowl.core.request.RepositoryRequest) ISnomedIdentifierService(com.b2international.snowowl.snomed.cis.ISnomedIdentifierService) ConflictException(com.b2international.commons.exceptions.ConflictException) BulkRequestBuilder(com.b2international.snowowl.core.events.bulk.BulkRequestBuilder) RepositoryManager(com.b2international.snowowl.core.RepositoryManager) ContentType(io.restassured.http.ContentType) TimestampProvider(com.b2international.index.revision.TimestampProvider) InactivationProperties(com.b2international.snowowl.snomed.core.domain.InactivationProperties) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) LocalDate(java.time.LocalDate) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest) SnomedComponentRestRequests(com.b2international.snowowl.snomed.core.rest.SnomedComponentRestRequests) CodeSystemVersionRestRequests.getNextAvailableEffectiveDate(com.b2international.snowowl.test.commons.codesystem.CodeSystemVersionRestRequests.getNextAvailableEffectiveDate) Acceptability(com.b2international.snowowl.snomed.core.domain.Acceptability) Iterables(com.google.common.collect.Iterables) CodeSystemVersionRestRequests.createVersion(com.b2international.snowowl.test.commons.codesystem.CodeSystemVersionRestRequests.createVersion) SnomedRefSetRestRequests.updateRefSetComponent(com.b2international.snowowl.snomed.core.rest.SnomedRefSetRestRequests.updateRefSetComponent) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) ModuleIdProvider(com.b2international.snowowl.snomed.datastore.request.ModuleRequest.ModuleIdProvider) AssociationTarget(com.b2international.snowowl.snomed.core.domain.AssociationTarget) TermFilter(com.b2international.snowowl.core.request.TermFilter) Environment(com.b2international.snowowl.core.setup.Environment) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) CodeSystemVersionRestRequests.createCodeSystemAndVersion(com.b2international.snowowl.test.commons.codesystem.CodeSystemVersionRestRequests.createCodeSystemAndVersion) BulkRequest(com.b2international.snowowl.core.events.bulk.BulkRequest) RestExtensions.givenAuthenticatedRequest(com.b2international.snowowl.test.commons.rest.RestExtensions.givenAuthenticatedRequest) SctId(com.b2international.snowowl.snomed.cis.domain.SctId) SnomedReferenceSetMembers(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMembers) BranchPathUtils(com.b2international.snowowl.core.branch.BranchPathUtils) SnomedApiTestConstants(com.b2international.snowowl.snomed.core.rest.SnomedApiTestConstants) SnomedRefSetRestRequests.bulkUpdateMembers(com.b2international.snowowl.snomed.core.rest.SnomedRefSetRestRequests.bulkUpdateMembers) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) SnomedTerminologyComponentConstants(com.b2international.snowowl.snomed.common.SnomedTerminologyComponentConstants) TextConstants(com.b2international.index.compat.TextConstants) CodeSystemRestRequests.createCodeSystem(com.b2international.snowowl.test.commons.codesystem.CodeSystemRestRequests.createCodeSystem) TimeUnit(java.util.concurrent.TimeUnit) Assert.assertNull(org.junit.Assert.assertNull) TransactionContext(com.b2international.snowowl.core.domain.TransactionContext) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) DateTimeFormatter(java.time.format.DateTimeFormatter) SnomedRf2Headers(com.b2international.snowowl.snomed.common.SnomedRf2Headers) Collections(java.util.Collections) IBranchPath(com.b2international.snowowl.core.api.IBranchPath) Assert.assertEquals(org.junit.Assert.assertEquals) ApplicationContext(com.b2international.snowowl.core.ApplicationContext) ComponentCategory(com.b2international.snowowl.core.terminology.ComponentCategory) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) SnomedReferenceSetMember(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember) TimestampProvider(com.b2international.index.revision.TimestampProvider) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) RevisionIndex(com.b2international.index.revision.RevisionIndex) Environment(com.b2international.snowowl.core.setup.Environment) RepositoryManager(com.b2international.snowowl.core.RepositoryManager) Json(com.b2international.commons.json.Json) AbstractSnomedApiTest(com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest) Test(org.junit.Test)

Example 4 with Acceptability

use of com.b2international.snowowl.snomed.core.domain.Acceptability in project snow-owl by b2ihealthcare.

the class DescriptionChangeProcessor method process.

@Override
public void process(StagingArea staging, RevisionSearcher searcher) throws IOException {
    final Map<String, Multimap<Acceptability, RefSetMemberChange>> acceptabilityChangesByDescription = new DescriptionAcceptabilityChangeProcessor().process(staging, searcher);
    final Multimap<String, RefSetMemberChange> referringRefSets = HashMultimap.create(memberChangeProcessor.process(staging, searcher));
    // (re)index new and dirty descriptions
    final Map<String, SnomedDescriptionIndexEntry> newDescriptionsById = staging.getNewObjects(SnomedDescriptionIndexEntry.class).collect(Collectors.toMap(description -> description.getId(), description -> description));
    final Map<String, SnomedDescriptionIndexEntry> changedDescriptionsById = staging.getChangedRevisions(SnomedDescriptionIndexEntry.class).collect(Collectors.toMap(diff -> diff.newRevision.getId(), diff -> (SnomedDescriptionIndexEntry) diff.newRevision));
    final Set<String> changedDescriptionIds = newHashSet(changedDescriptionsById.keySet());
    final Set<String> referencedDescriptionIds = newHashSet(referringRefSets.keySet());
    referencedDescriptionIds.removeAll(newDescriptionsById.keySet());
    changedDescriptionIds.addAll(referencedDescriptionIds);
    // load the known descriptions
    final Iterable<SnomedDescriptionIndexEntry> changedDescriptionHits = searcher.get(SnomedDescriptionIndexEntry.class, changedDescriptionIds);
    final Map<String, SnomedDescriptionIndexEntry> changedDescriptionRevisionsById = Maps.uniqueIndex(changedDescriptionHits, Revision::getId);
    // load missing descriptions with only changed acceptability values
    final Set<String> descriptionsToBeLoaded = newHashSet();
    for (String descriptionWithAccepatibilityChange : acceptabilityChangesByDescription.keySet()) {
        if (!newDescriptionsById.containsKey(descriptionWithAccepatibilityChange) && !changedDescriptionIds.contains(descriptionWithAccepatibilityChange)) {
            descriptionsToBeLoaded.add(descriptionWithAccepatibilityChange);
        }
    }
    // process changes
    for (final String id : Iterables.concat(newDescriptionsById.keySet(), changedDescriptionIds)) {
        if (newDescriptionsById.containsKey(id)) {
            final SnomedDescriptionIndexEntry description = newDescriptionsById.get(id);
            final Builder doc = SnomedDescriptionIndexEntry.builder(description);
            processChanges(id, doc, null, acceptabilityChangesByDescription.get(id), referringRefSets);
            stageNew(doc.build());
        } else if (changedDescriptionIds.contains(id)) {
            final SnomedDescriptionIndexEntry currentDoc = changedDescriptionRevisionsById.get(id);
            if (currentDoc == null) {
                throw new IllegalStateException(String.format("Current description revision should not be null for: %s", id));
            }
            final SnomedDescriptionIndexEntry description = changedDescriptionsById.get(id);
            final Builder doc;
            if (description != null) {
                doc = SnomedDescriptionIndexEntry.builder(description);
            } else {
                doc = SnomedDescriptionIndexEntry.builder(currentDoc);
            }
            processChanges(id, doc, currentDoc, acceptabilityChangesByDescription.get(id), referringRefSets);
            stageChange(currentDoc, doc.build());
        } else {
            throw new IllegalStateException(String.format("Description %s is missing from new and dirty maps", id));
        }
    }
    // process cascading acceptability changes in unchanged docs
    if (!descriptionsToBeLoaded.isEmpty()) {
        for (SnomedDescriptionIndexEntry unchangedDescription : searcher.get(SnomedDescriptionIndexEntry.class, descriptionsToBeLoaded)) {
            final Builder doc = SnomedDescriptionIndexEntry.builder(unchangedDescription);
            processChanges(unchangedDescription.getId(), doc, unchangedDescription, acceptabilityChangesByDescription.get(unchangedDescription.getId()), HashMultimap.<String, RefSetMemberChange>create());
            stageChange(unchangedDescription, doc.build());
        }
    }
}
Also used : Builder(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry.Builder) RefSetMemberChange(com.b2international.snowowl.snomed.datastore.index.refset.RefSetMemberChange) ChangeSetProcessorBase(com.b2international.snowowl.core.repository.ChangeSetProcessorBase) Acceptability(com.b2international.snowowl.snomed.core.domain.Acceptability) Revision(com.b2international.index.revision.Revision) Collection(java.util.Collection) Set(java.util.Set) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) SnomedDescription(com.b2international.snowowl.snomed.core.domain.SnomedDescription) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) Map(java.util.Map) StagingArea(com.b2international.index.revision.StagingArea) ReferenceSetMembershipUpdater(com.b2international.snowowl.snomed.datastore.index.update.ReferenceSetMembershipUpdater) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) SnomedDescriptionIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry) Collections(java.util.Collections) com.google.common.collect(com.google.common.collect) RefSetMemberChange(com.b2international.snowowl.snomed.datastore.index.refset.RefSetMemberChange) Builder(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry.Builder) SnomedDescriptionIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry) Revision(com.b2international.index.revision.Revision)

Example 5 with Acceptability

use of com.b2international.snowowl.snomed.core.domain.Acceptability in project snow-owl by b2ihealthcare.

the class DescriptionAcceptabilityChangeProcessor method process.

public Map<String, Multimap<Acceptability, RefSetMemberChange>> process(StagingArea staging, RevisionSearcher searcher) throws IOException {
    final Multimap<String, RefSetMemberChange> preferredMemberChanges = HashMultimap.create();
    final Multimap<String, RefSetMemberChange> acceptableMemberChanges = HashMultimap.create();
    // add active new and active dirty members
    final Stream<SnomedRefSetMemberIndexEntry> newAndDirtyMembers = Streams.concat(staging.getNewObjects(SnomedRefSetMemberIndexEntry.class).filter(member -> member.getReferenceSetType() == SnomedRefSetType.LANGUAGE), staging.getChangedRevisions(SnomedRefSetMemberIndexEntry.class).map(diff -> (SnomedRefSetMemberIndexEntry) diff.newRevision).filter(member -> member.getReferenceSetType() == SnomedRefSetType.LANGUAGE));
    newAndDirtyMembers.forEach(member -> {
        if (member.isActive()) {
            final String uuid = member.getId();
            final String refSetId = member.getRefsetId();
            final RefSetMemberChange change = new RefSetMemberChange(uuid, refSetId, MemberChangeKind.ADDED, member.isActive());
            registerChange(preferredMemberChanges, acceptableMemberChanges, member.getAcceptabilityId(), member.getReferencedComponentId(), change);
        }
    });
    // remove dirty inactive (and/or changed in acceptability) members
    final List<SnomedRefSetMemberIndexEntry> dirtyMembers = staging.getChangedRevisions(SnomedRefSetMemberIndexEntry.class).map(diff -> (SnomedRefSetMemberIndexEntry) diff.newRevision).filter(member -> member.getReferenceSetType() == SnomedRefSetType.LANGUAGE).collect(Collectors.toList());
    final Set<String> dirtyMemberIds = dirtyMembers.stream().map(SnomedRefSetMemberIndexEntry::getId).collect(Collectors.toSet());
    final List<SnomedRefSetMemberIndexEntry> detachedLanguageMembers = staging.getRemovedObjects(SnomedRefSetMemberIndexEntry.class).filter(member -> member.getReferenceSetType() == SnomedRefSetType.LANGUAGE).collect(Collectors.toList());
    final Map<String, SnomedRefSetMemberIndexEntry> currentRevisionsByMemberId = newHashMap();
    detachedLanguageMembers.forEach(member -> currentRevisionsByMemberId.put(member.getId(), member));
    searcher.get(SnomedRefSetMemberIndexEntry.class, dirtyMemberIds).forEach(member -> currentRevisionsByMemberId.put(member.getId(), member));
    for (SnomedRefSetMemberIndexEntry member : dirtyMembers) {
        final String uuid = member.getId();
        final String refSetId = member.getRefsetId();
        final RefSetMemberChange change = new RefSetMemberChange(uuid, refSetId, MemberChangeKind.REMOVED, member.isActive());
        final SnomedRefSetMemberIndexEntry before = currentRevisionsByMemberId.get(member.getId());
        if (before != null) {
            final String beforeAcceptabilityId = before.getAcceptabilityId();
            final boolean beforeActive = before.isActive();
            final boolean acceptabilityChanged = !member.getAcceptabilityId().equals(beforeAcceptabilityId);
            if (beforeActive && acceptabilityChanged) {
                registerChange(preferredMemberChanges, acceptableMemberChanges, beforeAcceptabilityId, member.getReferencedComponentId(), change);
            }
        }
        if (!member.isActive()) {
            registerChange(preferredMemberChanges, acceptableMemberChanges, member.getAcceptabilityId(), member.getReferencedComponentId(), change);
        }
    }
    for (final SnomedRefSetMemberIndexEntry before : detachedLanguageMembers) {
        if (before.isActive()) {
            final String uuid = before.getId();
            final String refSetId = before.getRefsetId();
            final String referencedComponentId = before.getReferencedComponentId();
            final String beforeAcceptabilityId = before.getAcceptabilityId();
            final RefSetMemberChange change = new RefSetMemberChange(uuid, refSetId, MemberChangeKind.REMOVED, before.isActive());
            registerChange(preferredMemberChanges, acceptableMemberChanges, beforeAcceptabilityId, referencedComponentId, change);
        }
    }
    final Map<String, Multimap<Acceptability, RefSetMemberChange>> changes = newHashMap();
    for (String descriptionId : Iterables.concat(preferredMemberChanges.keySet(), acceptableMemberChanges.keySet())) {
        if (!changes.containsKey(descriptionId)) {
            changes.put(descriptionId, HashMultimap.<Acceptability, RefSetMemberChange>create());
        }
        final Multimap<Acceptability, RefSetMemberChange> memberChanges = changes.get(descriptionId);
        memberChanges.putAll(Acceptability.PREFERRED, preferredMemberChanges.get(descriptionId));
        memberChanges.putAll(Acceptability.ACCEPTABLE, acceptableMemberChanges.get(descriptionId));
    }
    return changes;
}
Also used : RefSetMemberChange(com.b2international.snowowl.snomed.datastore.index.refset.RefSetMemberChange) Acceptability(com.b2international.snowowl.snomed.core.domain.Acceptability) Iterables(com.google.common.collect.Iterables) Maps.newHashMap(com.google.common.collect.Maps.newHashMap) SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) Set(java.util.Set) IOException(java.io.IOException) Multimap(com.google.common.collect.Multimap) Streams(com.google.common.collect.Streams) Collectors(java.util.stream.Collectors) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) List(java.util.List) Stream(java.util.stream.Stream) HashMultimap(com.google.common.collect.HashMultimap) RevisionSearcher(com.b2international.index.revision.RevisionSearcher) Map(java.util.Map) StagingArea(com.b2international.index.revision.StagingArea) MemberChangeKind(com.b2international.snowowl.snomed.datastore.index.refset.RefSetMemberChange.MemberChangeKind) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType) RefSetMemberChange(com.b2international.snowowl.snomed.datastore.index.refset.RefSetMemberChange) Acceptability(com.b2international.snowowl.snomed.core.domain.Acceptability) SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) Multimap(com.google.common.collect.Multimap) HashMultimap(com.google.common.collect.HashMultimap)

Aggregations

Acceptability (com.b2international.snowowl.snomed.core.domain.Acceptability)5 SnomedRefSetMemberIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)2 StagingArea (com.b2international.index.revision.StagingArea)2 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)2 SnomedDescription (com.b2international.snowowl.snomed.core.domain.SnomedDescription)2 SnomedRefSetType (com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType)2 SnomedReferenceSetMember (com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSetMember)2 RefSetMemberChange (com.b2international.snowowl.snomed.datastore.index.refset.RefSetMemberChange)2 ModuleIdProvider (com.b2international.snowowl.snomed.datastore.request.ModuleRequest.ModuleIdProvider)2 Iterables (com.google.common.collect.Iterables)2 IOException (java.io.IOException)2 Collections (java.util.Collections)2 List (java.util.List)2 Set (java.util.Set)2 ConflictException (com.b2international.commons.exceptions.ConflictException)1 Json (com.b2international.commons.json.Json)1 TextConstants (com.b2international.index.compat.TextConstants)1