use of com.b2international.snowowl.core.validation.issue.ValidationIssue in project snow-owl by b2ihealthcare.
the class GenericValidationRuleTest method rule45c.
@Test
public void rule45c() throws Exception {
final String ruleId = "45c";
indexRule(ruleId);
// index invalid non-defining relationship to group 0
final SnomedRelationshipIndexEntry nonDefiningRelationshipInGroup0 = relationship(Concepts.MORPHOLOGY, Concepts.CAUSATIVE_AGENT, Concepts.MODULE_SCT_MODEL_COMPONENT, Concepts.ADDITIONAL_RELATIONSHIP).relationshipGroup(0).build();
// index valid defining relationship to group 0
final SnomedRelationshipIndexEntry definingRelationshipInGroup0 = relationship(Concepts.MORPHOLOGY, Concepts.CAUSATIVE_AGENT, Concepts.MODULE_SCT_MODEL_COMPONENT, Concepts.STATED_RELATIONSHIP).relationshipGroup(0).build();
// index valid non-defining relationship to group 2
final SnomedRelationshipIndexEntry relationshipInGroup2 = relationship(Concepts.MORPHOLOGY, Concepts.CAUSATIVE_AGENT, Concepts.MODULE_SCT_MODEL_COMPONENT, Concepts.ADDITIONAL_RELATIONSHIP).relationshipGroup(2).build();
indexRevision(MAIN, nonDefiningRelationshipInGroup0, definingRelationshipInGroup0, relationshipInGroup2);
ValidationIssues issues = validate(ruleId);
assertThat(issues.stream().map(ValidationIssue::getAffectedComponent).collect(Collectors.toSet())).contains(ComponentIdentifier.of(SnomedRelationship.TYPE, nonDefiningRelationshipInGroup0.getId())).doesNotContainAnyElementsOf(ImmutableList.of(ComponentIdentifier.of(SnomedRelationship.TYPE, definingRelationshipInGroup0.getId()), ComponentIdentifier.of(SnomedRelationship.TYPE, relationshipInGroup2.getId())));
}
use of com.b2international.snowowl.core.validation.issue.ValidationIssue in project snow-owl by b2ihealthcare.
the class GenericValidationRuleTest method rule80.
@Test
public void rule80() throws Exception {
final String ruleId = "80";
indexRule(ruleId);
SnomedConceptDocument invalidConcept = concept(generateConceptId()).active(true).build();
SnomedConceptDocument validConcept1 = concept(generateConceptId()).active(true).build();
SnomedConceptDocument validConcept2 = concept(generateConceptId()).active(true).build();
SnomedRelationshipIndexEntry relationshipOnValidConcept = relationship(validConcept1.getId(), Concepts.IS_A, invalidConcept.getId()).build();
SnomedRefSetMemberIndexEntry owlAxiomMemberOnValidConcpet = member(validConcept2.getId(), Concepts.REFSET_OWL_AXIOM).classAxiomRelationships(Lists.newArrayList(SnomedOWLRelationshipDocument.create(Concepts.IS_A, validConcept1.getId(), 0))).referenceSetType(SnomedRefSetType.OWL_AXIOM).build();
indexRevision(MAIN, invalidConcept, validConcept1, validConcept2, relationshipOnValidConcept, owlAxiomMemberOnValidConcpet);
ValidationIssues issues = validate(ruleId);
assertThat(issues.stream().map(ValidationIssue::getAffectedComponent).collect(Collectors.toSet())).contains(ComponentIdentifier.of(SnomedConcept.TYPE, invalidConcept.getId())).doesNotContainAnyElementsOf(ImmutableList.of(ComponentIdentifier.of(SnomedConcept.TYPE, validConcept1.getId()), ComponentIdentifier.of(SnomedConcept.TYPE, validConcept2.getId())));
}
use of com.b2international.snowowl.core.validation.issue.ValidationIssue in project snow-owl by b2ihealthcare.
the class GenericValidationRuleTest method rule_mrcm_constraint_type.
@Test
public void rule_mrcm_constraint_type() throws Exception {
final String ruleId = "rule_mrcm_constraint_type";
indexRule(ruleId);
// First MRCM rule
final SnomedRefSetMemberIndexEntry mrcmDomainMember1 = member(Concepts.CONCEPT_MODEL_ATTRIBUTE, Concepts.REFSET_MRCM_DOMAIN_INTERNATIONAL).referenceSetType(SnomedRefSetType.MRCM_DOMAIN).domainConstraint(String.format("<<%s", Concepts.CONCEPT_MODEL_ATTRIBUTE)).build();
final SnomedRefSetMemberIndexEntry mrcmAttributeDomainMember1 = member(Concepts.FINDING_SITE, Concepts.REFSET_MRCM_ATTRIBUTE_DOMAIN_INTERNATIONAL).referenceSetType(SnomedRefSetType.MRCM_ATTRIBUTE_DOMAIN).domainId(Concepts.CONCEPT_MODEL_ATTRIBUTE).build();
// Second MRCM rule
final SnomedRefSetMemberIndexEntry mrcmDomainMember2 = member(Concepts.PHYSICAL_OBJECT, Concepts.REFSET_MRCM_DOMAIN_INTERNATIONAL).referenceSetType(SnomedRefSetType.MRCM_DOMAIN).domainConstraint(String.format("<<%s", Concepts.PHYSICAL_OBJECT)).build();
final SnomedRefSetMemberIndexEntry mrcmAttributeDomainMember2 = member(Concepts.HAS_ACTIVE_INGREDIENT, Concepts.REFSET_MRCM_ATTRIBUTE_DOMAIN_INTERNATIONAL).referenceSetType(SnomedRefSetType.MRCM_ATTRIBUTE_DOMAIN).domainId(Concepts.PHYSICAL_OBJECT).build();
// Relationships
final SnomedRelationshipIndexEntry relationship1 = relationship(Concepts.CONCEPT_MODEL_ATTRIBUTE, Concepts.IS_A, Concepts.CONCEPT_MODEL_ATTRIBUTE).relationshipGroup(1).build();
final SnomedRelationshipIndexEntry relationship2 = relationship(Concepts.CONCEPT_MODEL_ATTRIBUTE, Concepts.FINDING_SITE, Concepts.PHYSICAL_OBJECT).relationshipGroup(1).build();
final SnomedRelationshipIndexEntry relationship3 = relationship(Concepts.ROOT_CONCEPT, Concepts.TEXT_DEFINITION, Concepts.PHYSICAL_OBJECT).relationshipGroup(2).build();
final SnomedRelationshipIndexEntry relationship4 = relationship(Concepts.PHYSICAL_OBJECT, Concepts.FINDING_SITE, Concepts.TEXT_DEFINITION).relationshipGroup(0).build();
final SnomedRelationshipIndexEntry relationship5 = relationship(Concepts.PHYSICAL_OBJECT, Concepts.HAS_ACTIVE_INGREDIENT, Concepts.PHYSICAL_OBJECT).relationshipGroup(3).build();
final SnomedRelationshipIndexEntry relationship6 = concreteValue(Concepts.PHYSICAL_OBJECT, Concepts.HAS_ACTIVE_INGREDIENT, new RelationshipValue(Integer.valueOf(5))).build();
final SnomedRelationshipIndexEntry relationship7 = concreteValue(Concepts.PHYSICAL_OBJECT, Concepts.FINDING_SITE, new RelationshipValue(Integer.valueOf(15))).build();
final SnomedRelationshipIndexEntry relationship8 = concreteValue(Concepts.CONCEPT_MODEL_ATTRIBUTE, Concepts.HAS_ACTIVE_INGREDIENT, new RelationshipValue(Integer.valueOf(20))).build();
// OWL axioms
SnomedRefSetMemberIndexEntry axiomMember1 = member(Concepts.CONCEPT_MODEL_ATTRIBUTE, Concepts.REFSET_OWL_AXIOM).referenceSetType(SnomedRefSetType.OWL_AXIOM).classAxiomRelationships(Lists.newArrayList(SnomedOWLRelationshipDocument.create(Concepts.FINDING_SITE, Concepts.CONCEPT_MODEL_ATTRIBUTE, 0))).owlExpression(String.format("ObjectSomeValuesFrom(:%s :%s)", Concepts.FINDING_SITE, Concepts.CONCEPT_MODEL_ATTRIBUTE)).build();
SnomedRefSetMemberIndexEntry axiomMember2 = member(Concepts.PHYSICAL_OBJECT, Concepts.REFSET_OWL_AXIOM).referenceSetType(SnomedRefSetType.OWL_AXIOM).classAxiomRelationships(Lists.newArrayList(SnomedOWLRelationshipDocument.create(Concepts.FINDING_SITE, Concepts.PHYSICAL_OBJECT, 0))).owlExpression(String.format("ObjectSomeValuesFrom(:%s :%s)", Concepts.FINDING_SITE, Concepts.PHYSICAL_OBJECT)).build();
SnomedRefSetMemberIndexEntry axiomMember3 = member(Concepts.CONCEPT_MODEL_ATTRIBUTE, Concepts.REFSET_OWL_AXIOM).referenceSetType(SnomedRefSetType.OWL_AXIOM).classAxiomRelationships(Lists.newArrayList(SnomedOWLRelationshipDocument.create(Concepts.PHYSICAL_OBJECT, Concepts.CONCEPT_MODEL_ATTRIBUTE, 0))).owlExpression(String.format("ObjectSomeValuesFrom(:%s :%s)", Concepts.PHYSICAL_OBJECT, Concepts.CONCEPT_MODEL_ATTRIBUTE)).build();
indexRevision(MAIN, mrcmDomainMember1, mrcmAttributeDomainMember1, mrcmDomainMember2, mrcmAttributeDomainMember2, relationship1, relationship2, relationship3, relationship4, relationship5, relationship6, relationship7, relationship8, axiomMember1, axiomMember2, axiomMember3);
ValidationIssues issues = validate(ruleId);
Assertions.assertThat(issues.stream().map(ValidationIssue::getAffectedComponent).collect(Collectors.toSet())).contains(ComponentIdentifier.of(SnomedReferenceSetMember.TYPE, axiomMember2.getId()), ComponentIdentifier.of(SnomedReferenceSetMember.TYPE, axiomMember3.getId()), ComponentIdentifier.of(SnomedRelationship.TYPE, relationship3.getId()), ComponentIdentifier.of(SnomedRelationship.TYPE, relationship4.getId()), ComponentIdentifier.of(SnomedRelationship.TYPE, relationship7.getId()), ComponentIdentifier.of(SnomedRelationship.TYPE, relationship8.getId())).doesNotContain(ComponentIdentifier.of(SnomedReferenceSetMember.TYPE, axiomMember1.getId()), ComponentIdentifier.of(SnomedRelationship.TYPE, relationship1.getId()), ComponentIdentifier.of(SnomedRelationship.TYPE, relationship2.getId()), ComponentIdentifier.of(SnomedRelationship.TYPE, relationship5.getId()), ComponentIdentifier.of(SnomedRelationship.TYPE, relationship5.getId()), ComponentIdentifier.of(SnomedRelationship.TYPE, relationship6.getId()));
}
use of com.b2international.snowowl.core.validation.issue.ValidationIssue in project snow-owl by b2ihealthcare.
the class GenericValidationRuleTest method rule38a.
@Test
public void rule38a() throws Exception {
// Active concepts should have at least one active inferred parent.
final String ruleId = "38a";
indexRule(ruleId);
final SnomedConceptDocument activeConceptWithInferredParent = concept(generateConceptId()).active(true).parents(Long.valueOf(Concepts.MODULE_SCT_MODEL_COMPONENT)).build();
final SnomedConceptDocument activeConceptWithoutInferredParent = concept(generateConceptId()).active(true).build();
final SnomedConceptDocument inactiveConceptWithoutInferredParent = concept(generateConceptId()).active(false).build();
indexRevision(MAIN, activeConceptWithInferredParent, activeConceptWithoutInferredParent, inactiveConceptWithoutInferredParent);
ValidationIssues issues = validate(ruleId);
assertThat(issues.stream().map(ValidationIssue::getAffectedComponent).collect(Collectors.toSet())).contains(ComponentIdentifier.of(SnomedConcept.TYPE, activeConceptWithoutInferredParent.getId())).doesNotContainAnyElementsOf(ImmutableList.of(ComponentIdentifier.of(SnomedConcept.TYPE, activeConceptWithInferredParent.getId()), ComponentIdentifier.of(SnomedConcept.TYPE, inactiveConceptWithoutInferredParent.getId())));
}
use of com.b2international.snowowl.core.validation.issue.ValidationIssue in project snow-owl by b2ihealthcare.
the class RepositoryValidationRestService method getValidationResults.
@Operation(summary = "Retrieve the validation issues from a completed validation on a branch. Output may differ by the chosen content type.")
@ApiResponses({ @ApiResponse(responseCode = "200", description = "OK"), @ApiResponse(responseCode = "404", description = "Branch not found") })
@RequestMapping(value = "/validations/{validationId}/issues", method = RequestMethod.GET, produces = { AbstractRestService.JSON_MEDIA_TYPE, AbstractRestService.CSV_MEDIA_TYPE })
@ResponseBody
public Promise<Collection<Object>> getValidationResults(@Parameter(description = "The unique validation identifier.") @PathVariable(value = "validationId") final String validationId, @Parameter(description = "The search key to use for retrieving the next page of results") @RequestParam(value = "searchAfter", required = false) final String searchAfter, @Parameter(description = "The maximum number of items to return") @RequestParam(value = "limit", defaultValue = "50", required = false) final int limit, @Parameter(hidden = true) @RequestHeader(value = HttpHeaders.ACCEPT, defaultValue = AbstractRestService.JSON_MEDIA_TYPE, required = false) final String contentType) {
final IEventBus bus = getBus();
return getValidationRun(validationId).thenWith(validationJob -> {
final ResourceURI codeSystemURI = getCodeSystemURIFromJob(validationJob);
if (AbstractRestService.CSV_MEDIA_TYPE.equals(contentType)) {
return ValidationRequests.issues().prepareSearch().isWhitelisted(false).all().filterByResourceUri(codeSystemURI).sortBy(Sort.fieldAsc(ValidationIssue.Fields.RULE_ID)).buildAsync().execute(bus).then(issues -> {
final Set<String> rulesToFetch = issues.stream().map(ValidationIssue::getRuleId).collect(Collectors.toSet());
final Map<String, String> ruleDescriptionById = ValidationRequests.rules().prepareSearch().all().filterByIds(rulesToFetch).buildAsync().execute(bus).getSync(1, TimeUnit.MINUTES).stream().collect(Collectors.toMap(ValidationRule::getId, ValidationRule::getMessageTemplate));
return issues.stream().map(issue -> {
final String ruleId = issue.getRuleId();
final String ruleDescription = ruleDescriptionById.get(ruleId);
final String affectedComponentLabel = Iterables.getFirst(issue.getAffectedComponentLabels(), "No label found");
final String affectedComponentId = issue.getAffectedComponent().getComponentId();
return new ValidationIssueReport(ruleId, ruleDescription, affectedComponentId, affectedComponentLabel);
}).collect(Collectors.toList());
});
} else {
return ValidationRequests.issues().prepareSearch().isWhitelisted(false).setLimit(limit).setSearchAfter(searchAfter).filterByResourceUri(codeSystemURI).buildAsync().execute(bus).then(issues -> issues.getItems().stream().collect(Collectors.toList()));
}
});
}
Aggregations