Search in sources :

Example 51 with SnomedRefSetMemberIndexEntry

use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry 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 52 with SnomedRefSetMemberIndexEntry

use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry in project snow-owl by b2ihealthcare.

the class SnomedExtendedMapMemberCreateDelegate method execute.

@Override
public String execute(SnomedReferenceSet refSet, TransactionContext context) {
    checkRefSetType(refSet, SnomedRefSetType.EXTENDED_MAP);
    checkReferencedComponent(refSet);
    checkHasProperty(SnomedRf2Headers.FIELD_MAP_GROUP);
    checkHasProperty(SnomedRf2Headers.FIELD_MAP_PRIORITY);
    checkHasProperty(SnomedRf2Headers.FIELD_MAP_RULE);
    checkHasProperty(SnomedRf2Headers.FIELD_MAP_ADVICE);
    checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_MODULE_ID, getModuleId());
    checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_REFERENCED_COMPONENT_ID, getReferencedComponentId());
    checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_CORRELATION_ID);
    final String mapCategoryId = getComponentId(SnomedRf2Headers.FIELD_MAP_CATEGORY_ID);
    if (SnomedIdentifiers.isValid(mapCategoryId)) {
        checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_MAP_CATEGORY_ID);
    }
    if (SnomedIdentifiers.isValid(getProperty(SnomedRf2Headers.FIELD_MAP_TARGET))) {
        checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_MAP_TARGET);
    }
    SnomedRefSetMemberIndexEntry member = SnomedComponents.newComplexMapMember().withId(getId()).withActive(isActive()).withReferencedComponent(getReferencedComponentId()).withModuleId(getModuleId()).withRefSet(getReferenceSetId()).withMapTargetId(getComponentId(SnomedRf2Headers.FIELD_MAP_TARGET)).withGroup(getProperty(SnomedRf2Headers.FIELD_MAP_GROUP, Integer.class)).withPriority(getProperty(SnomedRf2Headers.FIELD_MAP_PRIORITY, Integer.class)).withMapRule(getProperty(SnomedRf2Headers.FIELD_MAP_RULE)).withMapAdvice(getProperty(SnomedRf2Headers.FIELD_MAP_ADVICE)).withCorrelationId(getComponentId(SnomedRf2Headers.FIELD_CORRELATION_ID)).withMapCategoryId(mapCategoryId).addTo(context);
    return member.getId();
}
Also used : SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry)

Example 53 with SnomedRefSetMemberIndexEntry

use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry in project snow-owl by b2ihealthcare.

the class SnomedMemberBuilder method addTo.

public final SnomedRefSetMemberIndexEntry addTo(TransactionContext context) {
    final SnomedRefSetMemberIndexEntry member = build(context);
    context.add(member);
    return member;
}
Also used : SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry)

Example 54 with SnomedRefSetMemberIndexEntry

use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry in project snow-owl by b2ihealthcare.

the class SnomedRefSetMemberUpdateRequest method execute.

@Override
public Boolean execute(TransactionContext context) {
    SnomedRefSetMemberIndexEntry member = context.lookup(componentId(), SnomedRefSetMemberIndexEntry.class);
    SnomedRefSetMemberIndexEntry.Builder updatedMember = SnomedRefSetMemberIndexEntry.builder(member);
    /* 
		 * TODO: Generalize the logic below: any attempts of retrieving a missing component during component update
		 * (with the exception of the component that is being updated) should return a 400 response instead of a 404. 
		 */
    try {
        SnomedRefSetType type = member.getReferenceSetType();
        boolean changed = false;
        changed |= updateStatus(member, updatedMember);
        changed |= updateModule(member, updatedMember);
        changed |= updateEffectiveTime(member, updatedMember);
        SnomedRefSetMemberUpdateDelegate delegate = getDelegate(type);
        changed |= delegate.execute(member, updatedMember, context);
        if (changed) {
            if (!isEffectiveTimeUpdate()) {
                updatedMember.effectiveTime(EffectiveTimes.UNSET_EFFECTIVE_TIME);
            }
            context.update(member, updatedMember.build());
        }
        return changed;
    } catch (ComponentNotFoundException e) {
        throw e.toBadRequestException();
    }
}
Also used : SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry) ComponentNotFoundException(com.b2international.snowowl.core.exceptions.ComponentNotFoundException) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType)

Example 55 with SnomedRefSetMemberIndexEntry

use of com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry in project snow-owl by b2ihealthcare.

the class SnomedSimpleMapMemberCreateDelegate method execute.

@Override
public String execute(SnomedReferenceSet refSet, TransactionContext context) {
    checkRefSetType(refSet, SnomedRefSetType.SIMPLE_MAP);
    checkReferencedComponent(refSet);
    checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_MODULE_ID, getModuleId());
    checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_REFERENCED_COMPONENT_ID, getReferencedComponentId());
    if (SnomedIdentifiers.isValid(getProperty(SnomedRf2Headers.FIELD_MAP_TARGET))) {
        checkComponentExists(refSet, context, SnomedRf2Headers.FIELD_MAP_TARGET);
    }
    SnomedRefSetMemberIndexEntry member = SnomedComponents.newSimpleMapMember().withId(getId()).withActive(isActive()).withReferencedComponent(getReferencedComponentId()).withModuleId(getModuleId()).withRefSet(getReferenceSetId()).withMapTargetId(getComponentId(SnomedRf2Headers.FIELD_MAP_TARGET)).addTo(context);
    return member.getId();
}
Also used : SnomedRefSetMemberIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry)

Aggregations

SnomedRefSetMemberIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry)59 Test (org.junit.Test)29 Revision (com.b2international.index.revision.Revision)28 SnomedConceptDocument (com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument)19 SnomedDescriptionIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry)15 SnomedRefSetType (com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType)8 SnomedRelationshipIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry)8 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)7 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)7 IOException (java.io.IOException)7 CompareUtils (com.b2international.commons.CompareUtils)5 Expressions (com.b2international.index.query.Expressions)5 ExpressionBuilder (com.b2international.index.query.Expressions.ExpressionBuilder)5 Query (com.b2international.index.query.Query)5 StagingArea (com.b2international.index.revision.StagingArea)5 SnowowlRuntimeException (com.b2international.snowowl.core.api.SnowowlRuntimeException)5 SnomedDescriptionFragment (com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionFragment)5 Expressions.active (com.b2international.snowowl.snomed.datastore.index.entry.SnomedDocument.Expressions.active)5 Sets.newHashSet (com.google.common.collect.Sets.newHashSet)5 Collection (java.util.Collection)5