Search in sources :

Example 26 with SnomedConceptDocument

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

the class TaxonomyPreCommitHookTest method deleteConceptWithOneStatedChild.

@Test
public void deleteConceptWithOneStatedChild() throws Exception {
    final long namespaceRootLong = Long.parseLong(Concepts.NAMESPACE_ROOT);
    // given a parent concept and child concept
    final SnomedConceptDocument parent = concept().build();
    final SnomedConceptDocument child = concept().build();
    availableImages.add(parent.getId());
    // and a stated relationship between the two
    final SnomedRelationshipIndexEntry childToParentIsa = createStatedRelationship(child.getId(), Concepts.IS_A, parent.getId());
    final SnomedRelationshipIndexEntry childToAnotherConceptIsa = createStatedRelationship(child.getId(), Concepts.IS_A, Concepts.NAMESPACE_ROOT);
    final long parentIdLong = Long.parseLong(parent.getId());
    final long childIdLong = Long.parseLong(child.getId());
    // index the child and parent concept documents as current state
    initRevisions(docWithDefaults(parent).build(), // child concept has stated parent and ROOT ancestor
    docWithDefaults(child).statedParents(PrimitiveSets.newLongSortedSet(parentIdLong)).statedAncestors(PrimitiveSets.newLongSortedSet(IComponent.ROOT_IDL)).build(), // index existing stated relationships
    childToParentIsa, childToAnotherConceptIsa);
    // delete parent concept and its single relationship
    stageRemove(parent);
    stageRemove(childToParentIsa);
    statedChangedConceptIds.add(parentIdLong);
    statedChangedConceptIds.add(childIdLong);
    statedChangedConceptIds.add(namespaceRootLong);
    final ConceptChangeProcessor processor = process();
    // the parent concept should be deleted, but handled by stageRemove
    assertEquals(0, processor.getDeletions().size());
    // and the child concept needs to be reindexed as child of the invisible ROOT ID
    assertEquals(1, processor.getChangedMappings().size());
    final Revision newChildRevision = Iterables.getOnlyElement(processor.getChangedMappings().values()).getNewRevision();
    final SnomedConceptDocument expectedChildRevision = docWithDefaults(child).iconId(Concepts.NAMESPACE_ROOT).statedParents(PrimitiveSets.newLongSortedSet(namespaceRootLong)).statedAncestors(PrimitiveSets.newLongSortedSet(IComponent.ROOT_IDL)).build();
    assertDocEquals(expectedChildRevision, newChildRevision);
    // no new mappings were registered
    assertEquals(0, processor.getNewMappings().size());
}
Also used : SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) Revision(com.b2international.index.revision.Revision) SnomedRelationshipIndexEntry(com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry) Test(org.junit.Test)

Example 27 with SnomedConceptDocument

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

the class TaxonomyPreCommitHookTest method deleteLeafConcept.

// Sanity checks
@Test
public void deleteLeafConcept() throws Exception {
    SnomedConceptDocument concept = concept().build();
    indexRevision(MAIN, docWithDefaults(concept).build());
    stageRemove(concept);
    final ConceptChangeProcessor processor = process();
    assertEquals(0, processor.getNewMappings().size());
    assertEquals(0, processor.getChangedMappings().size());
    assertEquals(0, processor.getDeletions().size());
}
Also used : SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) Test(org.junit.Test)

Example 28 with SnomedConceptDocument

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

the class SnomedRefSetCreateRequest method execute.

@Override
public String execute(TransactionContext context) {
    RefSetSupport.checkType(type, referencedComponentType);
    final SnomedConceptDocument concept;
    if (Strings.isNullOrEmpty(identifierId)) {
        throw new BadRequestException("Reference set identifier ID may not be null or empty.");
    } else {
        try {
            concept = context.lookup(identifierId, SnomedConceptDocument.class);
            if (concept.getRefSetType() != null) {
                throw new BadRequestException("Identifier concept %s has been already registered as refset", identifierId);
            }
        } catch (ComponentNotFoundException e) {
            throw e.toBadRequestException();
        }
    }
    final SnomedConceptDocument.Builder updatedConcept = SnomedConceptDocument.builder(concept);
    final SnomedReferenceSet refSet = new SnomedReferenceSet();
    refSet.setType(type);
    refSet.setReferencedComponentType(referencedComponentType);
    if (SnomedRefSetUtil.isMapping(type)) {
        refSet.setMapTargetComponentType(mapTargetComponentType);
    }
    updatedConcept.refSet(refSet);
    context.update(concept, updatedConcept.build());
    return identifierId;
}
Also used : SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) ComponentNotFoundException(com.b2international.snowowl.core.exceptions.ComponentNotFoundException) SnomedReferenceSet(com.b2international.snowowl.snomed.core.domain.refset.SnomedReferenceSet) BadRequestException(com.b2international.commons.exceptions.BadRequestException)

Example 29 with SnomedConceptDocument

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

the class MapTypeRefSetUpdateRequest method execute.

@Override
public Boolean execute(TransactionContext context) {
    // fail fast if refset identifier concept does not exist
    SnomedConceptDocument conceptDocument = context.lookup(referenceSetId, SnomedConceptDocument.class);
    SnomedRefSetType refSetType = conceptDocument.getRefSetType();
    if (!SnomedRefSetUtil.isMapping(refSetType)) {
        throw new BadRequestException("Map target codesystem can be set only for map-type reference sets, reference set: '%s' reference set type: '%s'.", referenceSetId, refSetType);
    }
    Builder conceptBuilder = SnomedConceptDocument.builder(conceptDocument);
    boolean changed = false;
    if (conceptDocument.getMapTargetComponentType() != null) {
        String currentMapTargetComponent = conceptDocument.getMapTargetComponentType();
        if (!mapTargetComponent.equals(currentMapTargetComponent)) {
            conceptBuilder.mapTargetComponentType(mapTargetComponent).build();
            changed = true;
        }
    } else {
        conceptBuilder.mapTargetComponentType(mapTargetComponent).build();
        changed = true;
    }
    if (changed) {
        context.update(conceptDocument, conceptBuilder.build());
    }
    return changed;
}
Also used : SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) Builder(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument.Builder) BadRequestException(com.b2international.commons.exceptions.BadRequestException) SnomedRefSetType(com.b2international.snowowl.snomed.core.domain.refset.SnomedRefSetType)

Example 30 with SnomedConceptDocument

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

the class SnomedValidationIssueDetailTest method duplicateIssueWithSameComponentIdTest.

@Test
public void duplicateIssueWithSameComponentIdTest() throws Exception {
    final String conceptId = RandomSnomedIdentiferGenerator.generateConceptId();
    final ValidationIssue existingIssue = createIssue(conceptId, Collections.emptyMap());
    final ValidationIssue existingIssue2 = createIssue(conceptId, Collections.emptyMap());
    save(existingIssue);
    save(existingIssue2);
    ImmutableMap<String, Object> ruleQuery = ImmutableMap.<String, Object>builder().put("componentType", "concept").put("active", true).build();
    SnomedConceptDocument theConcept = concept(conceptId).active(true).build();
    indexRevision(MAIN, theConcept);
    createSnomedQueryRule(ruleQuery);
    final ValidationIssues issues = validate();
    assertThat(issues.getItems().size()).isEqualTo(1);
}
Also used : SnomedConceptDocument(com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument) ValidationIssues(com.b2international.snowowl.core.validation.issue.ValidationIssues) ValidationIssue(com.b2international.snowowl.core.validation.issue.ValidationIssue) Test(org.junit.Test) BaseRevisionIndexTest(com.b2international.index.revision.BaseRevisionIndexTest)

Aggregations

SnomedConceptDocument (com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument)50 Test (org.junit.Test)41 Revision (com.b2international.index.revision.Revision)38 SnomedDescriptionIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionIndexEntry)23 SnomedDescriptionFragment (com.b2international.snowowl.snomed.datastore.index.entry.SnomedDescriptionFragment)21 SnomedRefSetMemberIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedRefSetMemberIndexEntry)18 SnomedRelationshipIndexEntry (com.b2international.snowowl.snomed.datastore.index.entry.SnomedRelationshipIndexEntry)8 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)3 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)3 Builder (com.b2international.snowowl.snomed.datastore.index.entry.SnomedConceptDocument.Builder)3 IOException (java.io.IOException)3 LongSets (com.b2international.commons.collect.LongSets)2 BadRequestException (com.b2international.commons.exceptions.BadRequestException)2 ExpressionBuilder (com.b2international.index.query.Expressions.ExpressionBuilder)2 ObjectId (com.b2international.index.revision.ObjectId)2 StagingArea (com.b2international.index.revision.StagingArea)2 RevisionDiff (com.b2international.index.revision.StagingArea.RevisionDiff)2 ChangeSetProcessorBase (com.b2international.snowowl.core.repository.ChangeSetProcessorBase)2 Concepts (com.b2international.snowowl.snomed.common.SnomedConstants.Concepts)2 Acceptability (com.b2international.snowowl.snomed.core.domain.Acceptability)2