Search in sources :

Example 6 with ValidationIssue

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())));
}
Also used : ValidationIssues(com.b2international.snowowl.core.validation.issue.ValidationIssues) ValidationIssue(com.b2international.snowowl.core.validation.issue.ValidationIssue) Test(org.junit.Test)

Example 7 with ValidationIssue

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())));
}
Also used : ValidationIssues(com.b2international.snowowl.core.validation.issue.ValidationIssues) ValidationIssue(com.b2international.snowowl.core.validation.issue.ValidationIssue) Test(org.junit.Test)

Example 8 with ValidationIssue

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()));
}
Also used : ValidationIssues(com.b2international.snowowl.core.validation.issue.ValidationIssues) ValidationIssue(com.b2international.snowowl.core.validation.issue.ValidationIssue) Test(org.junit.Test)

Example 9 with ValidationIssue

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())));
}
Also used : ValidationIssues(com.b2international.snowowl.core.validation.issue.ValidationIssues) ValidationIssue(com.b2international.snowowl.core.validation.issue.ValidationIssue) Test(org.junit.Test)

Example 10 with ValidationIssue

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()));
        }
    });
}
Also used : Iterables(com.google.common.collect.Iterables) AbstractRestService(com.b2international.snowowl.core.rest.AbstractRestService) Promise(com.b2international.snowowl.core.events.util.Promise) Autowired(org.springframework.beans.factory.annotation.Autowired) ValidationIssue(com.b2international.snowowl.core.validation.issue.ValidationIssue) Operation(io.swagger.v3.oas.annotations.Operation) HttpHeaders(com.google.common.net.HttpHeaders) Map(java.util.Map) RemoteJobs(com.b2international.snowowl.core.jobs.RemoteJobs) ApiResponse(io.swagger.v3.oas.annotations.responses.ApiResponse) ResourceURI(com.b2international.snowowl.core.ResourceURI) ValidationRule(com.b2international.snowowl.core.validation.rule.ValidationRule) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) RemoteJobEntry(com.b2international.snowowl.core.jobs.RemoteJobEntry) IEventBus(com.b2international.snowowl.eventbus.IEventBus) Collectors(java.util.stream.Collectors) IDs(com.b2international.snowowl.core.id.IDs) TimeUnit(java.util.concurrent.TimeUnit) Parameter(io.swagger.v3.oas.annotations.Parameter) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) JobRequests(com.b2international.snowowl.core.jobs.JobRequests) Sort(com.b2international.snowowl.core.request.SearchResourceRequest.Sort) Tag(io.swagger.v3.oas.annotations.tags.Tag) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) ValidationConfiguration(com.b2international.snowowl.core.internal.validation.ValidationConfiguration) ResponseEntity(org.springframework.http.ResponseEntity) ValidationRequests(com.b2international.snowowl.core.validation.ValidationRequests) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses) ResourceURI(com.b2international.snowowl.core.ResourceURI) IEventBus(com.b2international.snowowl.eventbus.IEventBus) Operation(io.swagger.v3.oas.annotations.Operation) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Aggregations

ValidationIssue (com.b2international.snowowl.core.validation.issue.ValidationIssue)14 ValidationIssues (com.b2international.snowowl.core.validation.issue.ValidationIssues)9 Test (org.junit.Test)9 BaseRevisionIndexTest (com.b2international.index.revision.BaseRevisionIndexTest)4 Collectors (java.util.stream.Collectors)4 RevisionSearcher (com.b2international.index.revision.RevisionSearcher)3 BranchContext (com.b2international.snowowl.core.domain.BranchContext)3 ValidationConfiguration (com.b2international.snowowl.core.internal.validation.ValidationConfiguration)3 ComponentCategory (com.b2international.snowowl.core.terminology.ComponentCategory)3 ValidationIssueDetailExtension (com.b2international.snowowl.core.validation.issue.ValidationIssueDetailExtension)3 ExtendedLocale (com.b2international.commons.http.ExtendedLocale)2 Options (com.b2international.commons.options.Options)2 Hits (com.b2international.index.Hits)2 Expression (com.b2international.index.query.Expression)2 Expressions (com.b2international.index.query.Expressions)2 ExpressionBuilder (com.b2international.index.query.Expressions.ExpressionBuilder)2 Query (com.b2international.index.query.Query)2 QueryBuilder (com.b2international.index.query.Query.QueryBuilder)2 DecimalUtils (com.b2international.index.util.DecimalUtils)2 ResourceURI (com.b2international.snowowl.core.ResourceURI)2