Search in sources :

Example 1 with ValidationIssueDetailExtensionProvider

use of com.b2international.snowowl.core.validation.issue.ValidationIssueDetailExtensionProvider in project snow-owl by b2ihealthcare.

the class ValidationPlugin method preRun.

@Override
public void preRun(SnowOwlConfiguration configuration, Environment env) throws Exception {
    if (env.isServer()) {
        final ObjectMapper mapper = env.service(ObjectMapper.class);
        final Index validationIndex = Indexes.createIndex(VALIDATIONS_INDEX, mapper, new Mappings(ValidationIssue.class, ValidationRule.class, ValidationWhiteList.class), env.service(IndexSettings.class).forIndex(env.service(RepositoryConfiguration.class).getIndexConfiguration(), VALIDATIONS_INDEX));
        final ValidationRepository repository = new ValidationRepository(validationIndex);
        env.services().registerService(ValidationRepository.class, repository);
        // register always available validation rule evaluators
        ValidationRuleEvaluator.Registry.register(new GroovyScriptValidationRuleEvaluator(env.getConfigPath()));
        // initialize validation thread pool
        final ValidationConfiguration validationConfig = configuration.getModuleConfig(ValidationConfiguration.class);
        int numberOfValidationThreads = validationConfig.getNumberOfValidationThreads();
        int maxConcurrentExpensiveJobs = validationConfig.getMaxConcurrentExpensiveJobs();
        int maxConcurrentNormalJobs = validationConfig.getMaxConcurrentNormalJobs();
        env.services().registerService(ValidationConfiguration.class, validationConfig);
        env.services().registerService(ValidationThreadPool.class, new ValidationThreadPool(numberOfValidationThreads, maxConcurrentExpensiveJobs, maxConcurrentNormalJobs));
        env.services().registerService(ValidationIssueDetailExtensionProvider.class, new ValidationIssueDetailExtensionProvider(env.service(ClassPathScanner.class)));
        final List<File> listOfFiles = Arrays.asList(env.getConfigPath().toFile().listFiles());
        final Set<File> validationRuleFiles = Sets.newHashSet();
        final Pattern validationFilenamePattern = Pattern.compile("(validation-rules)-(\\w+).(json)");
        for (File file : listOfFiles) {
            final String fileName = file.getName();
            final Matcher match = validationFilenamePattern.matcher(fileName);
            if (match.matches()) {
                validationRuleFiles.add(file);
            }
        }
        final List<ValidationRule> availableRules = Lists.newArrayList();
        for (File validationRulesFile : validationRuleFiles) {
            LOG.info("Synchronizing validation rules from file: " + validationRulesFile);
            availableRules.addAll(mapper.readValue(validationRulesFile, new TypeReference<List<ValidationRule>>() {
            }));
        }
        repository.write(writer -> {
            final Map<String, ValidationRule> existingRules = Maps.uniqueIndex(ValidationRequests.rules().prepareSearch().all().buildAsync().getRequest().execute(env), ValidationRule::getId);
            // index all rules from the file, this will update existing rules as well
            final Set<String> ruleIds = newHashSet();
            for (ValidationRule rule : availableRules) {
                writer.put(rule);
                ruleIds.add(rule.getId());
            }
            // delete rules and associated issues
            Set<String> rulesToDelete = Sets.difference(existingRules.keySet(), ruleIds);
            if (!rulesToDelete.isEmpty()) {
                final Set<String> issuesToDelete = newHashSet(writer.searcher().search(Query.select(String.class).from(ValidationIssue.class).fields(ValidationIssue.Fields.ID).where(Expressions.builder().filter(Expressions.matchAny(ValidationIssue.Fields.RULE_ID, rulesToDelete)).build()).limit(Integer.MAX_VALUE).build()).getHits());
                writer.removeAll(ImmutableMap.<Class<?>, Set<String>>of(ValidationRule.class, rulesToDelete, ValidationIssue.class, issuesToDelete));
            }
            writer.commit();
            return null;
        });
    }
}
Also used : GroovyScriptValidationRuleEvaluator(com.b2international.snowowl.core.validation.eval.GroovyScriptValidationRuleEvaluator) Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) Index(com.b2international.index.Index) ValidationIssue(com.b2international.snowowl.core.validation.issue.ValidationIssue) ValidationWhiteList(com.b2international.snowowl.core.validation.whitelist.ValidationWhiteList) ValidationRule(com.b2international.snowowl.core.validation.rule.ValidationRule) Mappings(com.b2international.index.mapping.Mappings) ValidationIssueDetailExtensionProvider(com.b2international.snowowl.core.validation.issue.ValidationIssueDetailExtensionProvider) TypeReference(com.fasterxml.jackson.core.type.TypeReference) RepositoryConfiguration(com.b2international.snowowl.core.config.RepositoryConfiguration) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with ValidationIssueDetailExtensionProvider

use of com.b2international.snowowl.core.validation.issue.ValidationIssueDetailExtensionProvider in project snow-owl by b2ihealthcare.

the class SnomedValidationIssueDetailTest method setup.

@Before
public void setup() {
    final Index index = Indexes.createIndex(UUID.randomUUID().toString(), getMapper(), new Mappings(ValidationRule.class, ValidationIssue.class, ValidationWhiteList.class));
    repository = new ValidationRepository(index);
    ClassPathScanner scanner = new ClassPathScanner("com.b2international");
    context = TestBranchContext.on(MAIN).with(ObjectMapper.class, getMapper()).with(EclParser.class, new DefaultEclParser(INJECTOR.getInstance(IParser.class), INJECTOR.getInstance(IResourceValidator.class))).with(EclSerializer.class, new DefaultEclSerializer(INJECTOR.getInstance(ISerializer.class))).with(Index.class, rawIndex()).with(RevisionIndex.class, index()).with(ValidationThreadPool.class, new ValidationThreadPool(1, 1, 1)).with(ValidationRepository.class, repository).with(ClassPathScanner.class, scanner).with(ValidationIssueDetailExtensionProvider.class, new ValidationIssueDetailExtensionProvider(scanner)).with(ResourceURIPathResolver.class, ResourceURIPathResolver.fromMap(Map.of("SNOMEDCT", Branch.MAIN_PATH))).build();
    evaluator = new SnomedQueryValidationRuleEvaluator();
    if (!ValidationRuleEvaluator.Registry.types().contains(evaluator.type())) {
        ValidationRuleEvaluator.Registry.register(evaluator);
    }
    context.service(ValidationIssueDetailExtensionProvider.class).addExtension(new SnomedValidationIssueDetailExtension());
}
Also used : ValidationRepository(com.b2international.snowowl.core.internal.validation.ValidationRepository) RevisionIndex(com.b2international.index.revision.RevisionIndex) DefaultEclSerializer(com.b2international.snowowl.snomed.core.ecl.DefaultEclSerializer) ValidationThreadPool(com.b2international.snowowl.core.internal.validation.ValidationThreadPool) RevisionIndex(com.b2international.index.revision.RevisionIndex) Index(com.b2international.index.Index) DefaultEclSerializer(com.b2international.snowowl.snomed.core.ecl.DefaultEclSerializer) EclSerializer(com.b2international.snowowl.snomed.core.ecl.EclSerializer) ValidationIssue(com.b2international.snowowl.core.validation.issue.ValidationIssue) ValidationWhiteList(com.b2international.snowowl.core.validation.whitelist.ValidationWhiteList) ValidationRule(com.b2international.snowowl.core.validation.rule.ValidationRule) DefaultEclParser(com.b2international.snowowl.snomed.core.ecl.DefaultEclParser) Mappings(com.b2international.index.mapping.Mappings) ValidationIssueDetailExtensionProvider(com.b2international.snowowl.core.validation.issue.ValidationIssueDetailExtensionProvider) ClassPathScanner(com.b2international.snowowl.core.plugin.ClassPathScanner) SnomedValidationIssueDetailExtension(com.b2international.snowowl.snomed.validation.detail.SnomedValidationIssueDetailExtension) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ISerializer(org.eclipse.xtext.serializer.ISerializer) Before(org.junit.Before)

Example 3 with ValidationIssueDetailExtensionProvider

use of com.b2international.snowowl.core.validation.issue.ValidationIssueDetailExtensionProvider in project snow-owl by b2ihealthcare.

the class BaseValidationTest method setup.

@Before
public final void setup() {
    final ClassPathScanner scanner = new ClassPathScanner("com.b2international");
    Builder context = TestBranchContext.on(MAIN).with(ClassLoader.class, getClass().getClassLoader()).with(ClassPathScanner.class, scanner).with(Index.class, rawIndex()).with(RevisionIndex.class, index()).with(ObjectMapper.class, getMapper()).with(ValidationRepository.class, new ValidationRepository(rawIndex())).with(ValidationThreadPool.class, new ValidationThreadPool(1, 1, 1)).with(ValidationIssueDetailExtensionProvider.class, new ValidationIssueDetailExtensionProvider(scanner)).with(TerminologyRegistry.class, TerminologyRegistry.INSTANCE).with(ResourceURIPathResolver.class, ResourceURIPathResolver.fromMap(getTestCodeSystemPathMap())).with(ScriptEngine.Registry.class, new ScriptEngine.Registry(scanner));
    configureContext(context);
    this.context = context.build();
    initializeData();
}
Also used : ValidationRepository(com.b2international.snowowl.core.internal.validation.ValidationRepository) RevisionIndex(com.b2international.index.revision.RevisionIndex) ValidationIssueDetailExtensionProvider(com.b2international.snowowl.core.validation.issue.ValidationIssueDetailExtensionProvider) ValidationThreadPool(com.b2international.snowowl.core.internal.validation.ValidationThreadPool) ValidateRequestBuilder(com.b2international.snowowl.core.validation.ValidateRequestBuilder) Builder(com.b2international.snowowl.test.commons.snomed.TestBranchContext.Builder) ResourceURIPathResolver(com.b2international.snowowl.core.uri.ResourceURIPathResolver) ClassPathScanner(com.b2international.snowowl.core.plugin.ClassPathScanner) ScriptEngine(com.b2international.snowowl.core.scripts.ScriptEngine) Before(org.junit.Before)

Aggregations

ValidationIssueDetailExtensionProvider (com.b2international.snowowl.core.validation.issue.ValidationIssueDetailExtensionProvider)3 Index (com.b2international.index.Index)2 Mappings (com.b2international.index.mapping.Mappings)2 RevisionIndex (com.b2international.index.revision.RevisionIndex)2 ValidationRepository (com.b2international.snowowl.core.internal.validation.ValidationRepository)2 ValidationThreadPool (com.b2international.snowowl.core.internal.validation.ValidationThreadPool)2 ClassPathScanner (com.b2international.snowowl.core.plugin.ClassPathScanner)2 ValidationIssue (com.b2international.snowowl.core.validation.issue.ValidationIssue)2 ValidationRule (com.b2international.snowowl.core.validation.rule.ValidationRule)2 ValidationWhiteList (com.b2international.snowowl.core.validation.whitelist.ValidationWhiteList)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Before (org.junit.Before)2 RepositoryConfiguration (com.b2international.snowowl.core.config.RepositoryConfiguration)1 ScriptEngine (com.b2international.snowowl.core.scripts.ScriptEngine)1 ResourceURIPathResolver (com.b2international.snowowl.core.uri.ResourceURIPathResolver)1 ValidateRequestBuilder (com.b2international.snowowl.core.validation.ValidateRequestBuilder)1 GroovyScriptValidationRuleEvaluator (com.b2international.snowowl.core.validation.eval.GroovyScriptValidationRuleEvaluator)1 DefaultEclParser (com.b2international.snowowl.snomed.core.ecl.DefaultEclParser)1 DefaultEclSerializer (com.b2international.snowowl.snomed.core.ecl.DefaultEclSerializer)1 EclSerializer (com.b2international.snowowl.snomed.core.ecl.EclSerializer)1