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());
}
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());
}
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;
}
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;
}
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);
}
Aggregations