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