Merge branch 'RED-7886' into 'master'
RED-7886 - Endpoint for rule validation Closes RED-7886 See merge request redactmanager/redaction-service!278
This commit is contained in:
commit
5fb3626208
@ -0,0 +1,20 @@
|
|||||||
|
package com.iqser.red.service.redaction.v1.model;
|
||||||
|
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.experimental.FieldDefaults;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@Builder
|
||||||
|
@AllArgsConstructor
|
||||||
|
@NoArgsConstructor
|
||||||
|
@FieldDefaults(level = AccessLevel.PRIVATE)
|
||||||
|
public class DroolsSyntaxDeprecatedWarnings {
|
||||||
|
|
||||||
|
Integer line;
|
||||||
|
Integer column;
|
||||||
|
String message;
|
||||||
|
}
|
||||||
@ -19,6 +19,8 @@ public class DroolsSyntaxValidation {
|
|||||||
|
|
||||||
@Builder.Default
|
@Builder.Default
|
||||||
List<DroolsSyntaxErrorMessage> droolsSyntaxErrorMessages = new LinkedList<>();
|
List<DroolsSyntaxErrorMessage> droolsSyntaxErrorMessages = new LinkedList<>();
|
||||||
|
@Builder.Default
|
||||||
|
List<DroolsSyntaxDeprecatedWarnings> droolsSyntaxDeprecatedWarnings = new LinkedList<>();
|
||||||
|
|
||||||
|
|
||||||
public void addErrorMessage(int line, int column, String message) {
|
public void addErrorMessage(int line, int column, String message) {
|
||||||
|
|||||||
@ -60,6 +60,8 @@ dependencies {
|
|||||||
implementation("net.logstash.logback:logstash-logback-encoder:7.4")
|
implementation("net.logstash.logback:logstash-logback-encoder:7.4")
|
||||||
implementation("ch.qos.logback:logback-classic")
|
implementation("ch.qos.logback:logback-classic")
|
||||||
|
|
||||||
|
implementation("org.reflections:reflections:0.10.2")
|
||||||
|
|
||||||
testImplementation(project(":rules-management"))
|
testImplementation(project(":rules-management"))
|
||||||
testImplementation("org.apache.pdfbox:pdfbox:${pdfBoxVersion}")
|
testImplementation("org.apache.pdfbox:pdfbox:${pdfBoxVersion}")
|
||||||
testImplementation("org.apache.pdfbox:pdfbox-tools:${pdfBoxVersion}")
|
testImplementation("org.apache.pdfbox:pdfbox-tools:${pdfBoxVersion}")
|
||||||
|
|||||||
@ -46,10 +46,18 @@ public class Application {
|
|||||||
return new TimedAspect(registry);
|
return new TimedAspect(registry);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public DictionaryMergeService dictionaryMergeService() {
|
public DictionaryMergeService dictionaryMergeService() {
|
||||||
|
|
||||||
return new DictionaryMergeService();
|
return new DictionaryMergeService();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Bean(initMethod = "findDeprecatedMethods")
|
||||||
|
public DeprecatedElementsFinder deprecatedElementsFinder() {
|
||||||
|
|
||||||
|
return new DeprecatedElementsFinder();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,108 @@
|
|||||||
|
package com.iqser.red.service.redaction.v1.server;
|
||||||
|
|
||||||
|
import static java.util.stream.Collectors.groupingBy;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import org.reflections.Reflections;
|
||||||
|
import org.reflections.scanners.Scanners;
|
||||||
|
import org.reflections.util.ConfigurationBuilder;
|
||||||
|
|
||||||
|
import com.iqser.red.service.redaction.v1.server.model.dictionary.SearchImplementation;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
public class DeprecatedElementsFinder {
|
||||||
|
|
||||||
|
public static final String PACKAGE_NAME = "com.iqser.red.service.redaction.v1.server";
|
||||||
|
private Set<Method> deprecatedMethods;
|
||||||
|
@Getter
|
||||||
|
private Map<String, String> deprecatedMethodsSignaturesMap;
|
||||||
|
private Set<Class<?>> deprecatedClasses;
|
||||||
|
@Getter
|
||||||
|
private SearchImplementation classesSearchImplementation;
|
||||||
|
@Getter
|
||||||
|
private SearchImplementation methodsSearchImplementation;
|
||||||
|
|
||||||
|
|
||||||
|
public void findDeprecatedMethods() {
|
||||||
|
|
||||||
|
deprecatedMethods = new HashSet<>();
|
||||||
|
deprecatedClasses = new HashSet<>();
|
||||||
|
deprecatedMethodsSignaturesMap = new HashMap<>();
|
||||||
|
|
||||||
|
Reflections reflections = new Reflections(new ConfigurationBuilder().forPackage(PACKAGE_NAME)
|
||||||
|
.setExpandSuperTypes(true)
|
||||||
|
.setScanners(Scanners.MethodsAnnotated, Scanners.TypesAnnotated, Scanners.SubTypes));
|
||||||
|
|
||||||
|
deprecatedMethods = reflections.get(Scanners.MethodsAnnotated.with(Deprecated.class).as(Method.class));
|
||||||
|
|
||||||
|
deprecatedClasses = reflections.get(Scanners.TypesAnnotated.with(Deprecated.class).asClass());
|
||||||
|
|
||||||
|
if (!deprecatedClasses.isEmpty()) {
|
||||||
|
deprecatedClasses.forEach(deprecatedType -> deprecatedMethods.addAll(Arrays.stream(deprecatedType.getDeclaredMethods())
|
||||||
|
.collect(Collectors.toSet())));
|
||||||
|
classesSearchImplementation = new SearchImplementation(deprecatedClasses.stream()
|
||||||
|
.map(Class::getName)
|
||||||
|
.collect(Collectors.toSet()), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!deprecatedMethods.isEmpty()) {
|
||||||
|
methodsSearchImplementation = new SearchImplementation(deprecatedMethods.stream()
|
||||||
|
.map(Method::getName)
|
||||||
|
.collect(Collectors.toSet()), false);
|
||||||
|
deprecatedMethodsSignaturesMap = new HashMap<>();
|
||||||
|
Map<String, List<Method>> deprecatedMethodsNameMap = deprecatedMethods.stream()
|
||||||
|
.collect(groupingBy(Method::getName));
|
||||||
|
for (String deprecatedMethod : deprecatedMethodsNameMap.keySet()) {
|
||||||
|
deprecatedMethodsSignaturesMap.computeIfAbsent(deprecatedMethod,
|
||||||
|
key -> deprecatedMethodsNameMap.get(deprecatedMethod)
|
||||||
|
.stream()
|
||||||
|
.map(this::getMethodSignature)
|
||||||
|
.collect(Collectors.joining("\n")));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("For package: {} found deprecated classes {} deprecated methods {}", PACKAGE_NAME, deprecatedClasses.size(), deprecatedMethods.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Set<Method> getDeprecatedMethods() {
|
||||||
|
|
||||||
|
if (this.deprecatedMethods == null) {
|
||||||
|
findDeprecatedMethods();
|
||||||
|
}
|
||||||
|
return this.deprecatedMethods;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public Set<Class<?>> getDeprecatedClasses() {
|
||||||
|
|
||||||
|
if (this.deprecatedClasses == null) {
|
||||||
|
findDeprecatedMethods();
|
||||||
|
}
|
||||||
|
return this.deprecatedClasses;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getMethodSignature(Method method) {
|
||||||
|
|
||||||
|
String methodName = method.getName();
|
||||||
|
String parameterTypes = Arrays.stream(method.getGenericParameterTypes())
|
||||||
|
.map(Type::getTypeName)
|
||||||
|
.collect(Collectors.joining(", "));
|
||||||
|
|
||||||
|
return method.getGenericReturnType() + " " + methodName + "(" + parameterTypes + ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,6 +1,9 @@
|
|||||||
package com.iqser.red.service.redaction.v1.server.service.drools;
|
package com.iqser.red.service.redaction.v1.server.service.drools;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -12,24 +15,34 @@ import org.springframework.stereotype.Service;
|
|||||||
|
|
||||||
import com.google.common.collect.Sets;
|
import com.google.common.collect.Sets;
|
||||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.RuleFileType;
|
import com.iqser.red.service.persistence.service.v1.api.shared.model.RuleFileType;
|
||||||
|
import com.iqser.red.service.redaction.v1.model.DroolsSyntaxDeprecatedWarnings;
|
||||||
import com.iqser.red.service.redaction.v1.model.DroolsSyntaxErrorMessage;
|
import com.iqser.red.service.redaction.v1.model.DroolsSyntaxErrorMessage;
|
||||||
import com.iqser.red.service.redaction.v1.model.DroolsSyntaxValidation;
|
import com.iqser.red.service.redaction.v1.model.DroolsSyntaxValidation;
|
||||||
import com.iqser.red.service.redaction.v1.model.RuleValidationModel;
|
import com.iqser.red.service.redaction.v1.model.RuleValidationModel;
|
||||||
|
import com.iqser.red.service.redaction.v1.server.DeprecatedElementsFinder;
|
||||||
|
import com.iqser.red.service.redaction.v1.server.model.dictionary.SearchImplementation;
|
||||||
import com.iqser.red.service.redaction.v1.server.model.drools.BasicQuery;
|
import com.iqser.red.service.redaction.v1.server.model.drools.BasicQuery;
|
||||||
|
import com.iqser.red.service.redaction.v1.server.model.drools.BasicRule;
|
||||||
|
import com.iqser.red.service.redaction.v1.server.model.drools.RuleClass;
|
||||||
import com.iqser.red.service.redaction.v1.server.model.drools.RuleFileBluePrint;
|
import com.iqser.red.service.redaction.v1.server.model.drools.RuleFileBluePrint;
|
||||||
|
import com.iqser.red.service.redaction.v1.server.model.drools.RuleUnit;
|
||||||
import com.iqser.red.service.redaction.v1.server.storage.RuleManagementResources;
|
import com.iqser.red.service.redaction.v1.server.storage.RuleManagementResources;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.SneakyThrows;
|
import lombok.SneakyThrows;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
|
@Slf4j
|
||||||
public class DroolsSyntaxValidationService {
|
public class DroolsSyntaxValidationService {
|
||||||
|
|
||||||
private static final Pattern allowedImportsPattern = Pattern.compile("^(?:import\\s+static\\s+)?(?:import\\s+)?(?:com\\.knecon\\.fforesight|com\\.iqser\\.red)\\..*;$");
|
private static final Pattern allowedImportsPattern = Pattern.compile("^(?:import\\s+static\\s+)?(?:import\\s+)?(?:com\\.knecon\\.fforesight|com\\.iqser\\.red)\\..*;$");
|
||||||
|
|
||||||
private final KieContainerCreationService kieContainerCreationService;
|
private final KieContainerCreationService kieContainerCreationService;
|
||||||
|
|
||||||
|
private final DeprecatedElementsFinder deprecatedElementsFinder;
|
||||||
|
|
||||||
|
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
public DroolsSyntaxValidation testRules(RuleValidationModel rules) {
|
public DroolsSyntaxValidation testRules(RuleValidationModel rules) {
|
||||||
@ -43,15 +56,74 @@ public class DroolsSyntaxValidationService {
|
|||||||
}
|
}
|
||||||
DroolsSyntaxValidation droolsCompilerSyntaxValidation = buildDroolsCompilerSyntaxValidation(rules);
|
DroolsSyntaxValidation droolsCompilerSyntaxValidation = buildDroolsCompilerSyntaxValidation(rules);
|
||||||
droolsCompilerSyntaxValidation.getDroolsSyntaxErrorMessages().addAll(customDroolsSyntaxValidation.getDroolsSyntaxErrorMessages());
|
droolsCompilerSyntaxValidation.getDroolsSyntaxErrorMessages().addAll(customDroolsSyntaxValidation.getDroolsSyntaxErrorMessages());
|
||||||
|
droolsCompilerSyntaxValidation.getDroolsSyntaxDeprecatedWarnings().addAll(customDroolsSyntaxValidation.getDroolsSyntaxDeprecatedWarnings());
|
||||||
return droolsCompilerSyntaxValidation;
|
return droolsCompilerSyntaxValidation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DroolsSyntaxDeprecatedWarnings getWarningsForDeprecatedImports(RuleFileBluePrint ruleFileBluePrint) {
|
||||||
|
|
||||||
|
if (!deprecatedElementsFinder.getDeprecatedClasses().isEmpty()) {
|
||||||
|
String imports = ruleFileBluePrint.getImports();
|
||||||
|
SearchImplementation classesSearchImplementation = deprecatedElementsFinder.getClassesSearchImplementation();
|
||||||
|
List<SearchImplementation.MatchPosition> matches = classesSearchImplementation.getMatches(imports);
|
||||||
|
if (!matches.isEmpty()) {
|
||||||
|
String sb = "Following imports are deprecated: \n" + matches.stream()
|
||||||
|
.map(m -> imports.substring(m.startIndex(), m.endIndex()))
|
||||||
|
.collect(Collectors.joining("\n"));
|
||||||
|
return DroolsSyntaxDeprecatedWarnings.builder().line(ruleFileBluePrint.getImportLine()).column(0).message(sb)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private List<DroolsSyntaxDeprecatedWarnings> getWarningsForDeprecatedRules(RuleFileBluePrint ruleFileBluePrint) {
|
||||||
|
|
||||||
|
List<DroolsSyntaxDeprecatedWarnings> warningMessages = new ArrayList<>();
|
||||||
|
|
||||||
|
// checks the rules for deprecateMethods
|
||||||
|
if (!deprecatedElementsFinder.getDeprecatedMethods().isEmpty()) {
|
||||||
|
SearchImplementation methodsSearchImplementation = deprecatedElementsFinder.getMethodsSearchImplementation();
|
||||||
|
Map<String, String> deprecatedMethodsSignatureMap = deprecatedElementsFinder.getDeprecatedMethodsSignaturesMap();
|
||||||
|
|
||||||
|
for (RuleClass ruleClass : ruleFileBluePrint.getRuleClasses()) {
|
||||||
|
for (RuleUnit ruleUnit : ruleClass.ruleUnits()) {
|
||||||
|
for (BasicRule basicRule : ruleUnit.rules()) {
|
||||||
|
List<SearchImplementation.MatchPosition> matches = methodsSearchImplementation.getMatches(basicRule.getCode());
|
||||||
|
if (!matches.isEmpty()) {
|
||||||
|
String warningMessage = matches.stream()
|
||||||
|
.map(m -> basicRule.getCode().substring(m.startIndex(), m.endIndex()))
|
||||||
|
.distinct()
|
||||||
|
.map(dm -> String.format("Method %s might be deprecated because of \n %s \n", dm, deprecatedMethodsSignatureMap.get(dm)))
|
||||||
|
.collect(Collectors.joining("\n"));
|
||||||
|
warningMessages.add(DroolsSyntaxDeprecatedWarnings.builder().line(basicRule.getLine()).column(0).message(warningMessage)
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return warningMessages.stream()
|
||||||
|
.sorted(Comparator.comparingInt(DroolsSyntaxDeprecatedWarnings::getLine))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private DroolsSyntaxValidation buildCustomDroolsSyntaxValidation(String ruleString, RuleFileType ruleFileType) throws DroolsParserException {
|
private DroolsSyntaxValidation buildCustomDroolsSyntaxValidation(String ruleString, RuleFileType ruleFileType) throws DroolsParserException {
|
||||||
|
|
||||||
RuleFileBluePrint ruleFileBluePrint = RuleFileParser.buildBluePrintFromRulesString(ruleString);
|
RuleFileBluePrint ruleFileBluePrint = RuleFileParser.buildBluePrintFromRulesString(ruleString);
|
||||||
|
|
||||||
DroolsSyntaxValidation customSyntaxValidation = ruleFileBluePrint.getDroolsSyntaxValidation();
|
DroolsSyntaxValidation customSyntaxValidation = ruleFileBluePrint.getDroolsSyntaxValidation();
|
||||||
|
|
||||||
|
// find deprecated elements in the ruleFileBluePrint
|
||||||
|
DroolsSyntaxDeprecatedWarnings warningMessageForImports = getWarningsForDeprecatedImports(ruleFileBluePrint);
|
||||||
|
if (warningMessageForImports != null) {
|
||||||
|
customSyntaxValidation.getDroolsSyntaxDeprecatedWarnings().add(warningMessageForImports);
|
||||||
|
}
|
||||||
|
customSyntaxValidation.getDroolsSyntaxDeprecatedWarnings().addAll(getWarningsForDeprecatedRules(ruleFileBluePrint));
|
||||||
|
|
||||||
RuleFileBluePrint baseRuleFileBluePrint = switch (ruleFileType) {
|
RuleFileBluePrint baseRuleFileBluePrint = switch (ruleFileType) {
|
||||||
case ENTITY -> RuleFileParser.buildBluePrintFromRulesString(RuleManagementResources.getBaseRuleFileString());
|
case ENTITY -> RuleFileParser.buildBluePrintFromRulesString(RuleManagementResources.getBaseRuleFileString());
|
||||||
case COMPONENT -> RuleFileParser.buildBluePrintFromRulesString(RuleManagementResources.getBaseComponentRuleFileString());
|
case COMPONENT -> RuleFileParser.buildBluePrintFromRulesString(RuleManagementResources.getBaseComponentRuleFileString());
|
||||||
@ -60,35 +132,36 @@ public class DroolsSyntaxValidationService {
|
|||||||
if (!importsAreValid(baseRuleFileBluePrint, ruleFileBluePrint)) {
|
if (!importsAreValid(baseRuleFileBluePrint, ruleFileBluePrint)) {
|
||||||
customSyntaxValidation.getDroolsSyntaxErrorMessages()
|
customSyntaxValidation.getDroolsSyntaxErrorMessages()
|
||||||
.add(DroolsSyntaxErrorMessage.builder()
|
.add(DroolsSyntaxErrorMessage.builder()
|
||||||
.line(ruleFileBluePrint.getImportLine())
|
.line(ruleFileBluePrint.getImportLine())
|
||||||
.column(0)
|
.column(0)
|
||||||
.message(String.format("Changing the imports is not allowed! Must be: %n%s", baseRuleFileBluePrint.getImports()))
|
.message(String.format("Changing the imports is not allowed! Must be: %n%s", baseRuleFileBluePrint.getImports()))
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
if (!ruleFileBluePrint.getGlobals().equals(baseRuleFileBluePrint.getGlobals())) {
|
if (!ruleFileBluePrint.getGlobals().equals(baseRuleFileBluePrint.getGlobals())) {
|
||||||
customSyntaxValidation.getDroolsSyntaxErrorMessages()
|
customSyntaxValidation.getDroolsSyntaxErrorMessages()
|
||||||
.add(DroolsSyntaxErrorMessage.builder()
|
.add(DroolsSyntaxErrorMessage.builder()
|
||||||
.line(ruleFileBluePrint.getGlobalsLine())
|
.line(ruleFileBluePrint.getGlobalsLine())
|
||||||
.column(0)
|
.column(0)
|
||||||
.message(String.format("Changing the globals is not allowed! Must be: %n%s", baseRuleFileBluePrint.getGlobals()))
|
.message(String.format("Changing the globals is not allowed! Must be: %n%s", baseRuleFileBluePrint.getGlobals()))
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
baseRuleFileBluePrint.getQueries().forEach(basicQuery -> {
|
baseRuleFileBluePrint.getQueries()
|
||||||
if (!validateQueryIsPresent(basicQuery, ruleFileBluePrint)) {
|
.forEach(basicQuery -> {
|
||||||
customSyntaxValidation.getDroolsSyntaxErrorMessages()
|
if (!validateQueryIsPresent(basicQuery, ruleFileBluePrint)) {
|
||||||
.add(DroolsSyntaxErrorMessage.builder()
|
customSyntaxValidation.getDroolsSyntaxErrorMessages()
|
||||||
.line(basicQuery.getLine())
|
.add(DroolsSyntaxErrorMessage.builder()
|
||||||
.column(0)
|
.line(basicQuery.getLine())
|
||||||
.message(String.format("Changing or removing the query %s is not allowed! Must be: %n%s", basicQuery.getName(), basicQuery.getCode()))
|
.column(0)
|
||||||
.build());
|
.message(String.format("Changing or removing the query %s is not allowed! Must be: %n%s", basicQuery.getName(), basicQuery.getCode()))
|
||||||
}
|
.build());
|
||||||
});
|
}
|
||||||
|
});
|
||||||
if (ruleFileType.equals(RuleFileType.ENTITY)) {
|
if (ruleFileType.equals(RuleFileType.ENTITY)) {
|
||||||
String requiredAgendaGroup = "LOCAL_DICTIONARY_ADDS";
|
String requiredAgendaGroup = "LOCAL_DICTIONARY_ADDS";
|
||||||
if (!validateAgendaGroupIsPresent(ruleFileBluePrint, requiredAgendaGroup)) {
|
if (!validateAgendaGroupIsPresent(ruleFileBluePrint, requiredAgendaGroup)) {
|
||||||
customSyntaxValidation.getDroolsSyntaxErrorMessages().add(DroolsSyntaxErrorMessage.builder().line(0)
|
customSyntaxValidation.getDroolsSyntaxErrorMessages()
|
||||||
.column(0).message(String.format("At least one rule with Agenda-Group '%s' required!", requiredAgendaGroup))
|
.add(DroolsSyntaxErrorMessage.builder().line(0).column(0).message(String.format("At least one rule with Agenda-Group '%s' required!", requiredAgendaGroup))
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return customSyntaxValidation;
|
return customSyntaxValidation;
|
||||||
@ -97,7 +170,8 @@ public class DroolsSyntaxValidationService {
|
|||||||
|
|
||||||
private boolean validateAgendaGroupIsPresent(RuleFileBluePrint ruleFileBluePrint, String agendaGroupName) {
|
private boolean validateAgendaGroupIsPresent(RuleFileBluePrint ruleFileBluePrint, String agendaGroupName) {
|
||||||
|
|
||||||
return ruleFileBluePrint.streamAllRules().anyMatch(basicRule -> basicRule.getAgendaGroup().equals(agendaGroupName));
|
return ruleFileBluePrint.streamAllRules()
|
||||||
|
.anyMatch(basicRule -> basicRule.getAgendaGroup().equals(agendaGroupName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -109,13 +183,16 @@ public class DroolsSyntaxValidationService {
|
|||||||
|
|
||||||
Set<String> additionalImports = Sets.difference(imports, baseImports);
|
Set<String> additionalImports = Sets.difference(imports, baseImports);
|
||||||
|
|
||||||
return additionalImports.stream().allMatch(additionalImport -> allowedImportsPattern.matcher(additionalImport).matches());
|
return additionalImports.stream()
|
||||||
|
.allMatch(additionalImport -> allowedImportsPattern.matcher(additionalImport).matches());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static boolean validateQueryIsPresent(BasicQuery queryToCheckFor, RuleFileBluePrint ruleFileBluePrint) {
|
private static boolean validateQueryIsPresent(BasicQuery queryToCheckFor, RuleFileBluePrint ruleFileBluePrint) {
|
||||||
|
|
||||||
return ruleFileBluePrint.getQueries().stream().anyMatch(query -> query.getName().equals(queryToCheckFor.getName()) && query.getCode().equals(queryToCheckFor.getCode()));
|
return ruleFileBluePrint.getQueries()
|
||||||
|
.stream()
|
||||||
|
.anyMatch(query -> query.getName().equals(queryToCheckFor.getName()) && query.getCode().equals(queryToCheckFor.getCode()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -124,9 +201,9 @@ public class DroolsSyntaxValidationService {
|
|||||||
var versionId = System.currentTimeMillis();
|
var versionId = System.currentTimeMillis();
|
||||||
var testRules = "test-rules";
|
var testRules = "test-rules";
|
||||||
KieBuilder kieBuilder = kieContainerCreationService.registerNewKieContainerVersion(testRules,
|
KieBuilder kieBuilder = kieContainerCreationService.registerNewKieContainerVersion(testRules,
|
||||||
versionId,
|
versionId,
|
||||||
rules.getRulesString(),
|
rules.getRulesString(),
|
||||||
RuleFileType.valueOf(rules.getRuleFileType()));
|
RuleFileType.valueOf(rules.getRuleFileType()));
|
||||||
return buildDroolsCompilerSyntaxValidation(kieBuilder);
|
return buildDroolsCompilerSyntaxValidation(kieBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -134,14 +211,18 @@ public class DroolsSyntaxValidationService {
|
|||||||
private DroolsSyntaxValidation buildDroolsCompilerSyntaxValidation(KieBuilder kieBuilder) {
|
private DroolsSyntaxValidation buildDroolsCompilerSyntaxValidation(KieBuilder kieBuilder) {
|
||||||
|
|
||||||
List<Message> errorMessages = kieBuilder.getResults().getMessages(Message.Level.ERROR);
|
List<Message> errorMessages = kieBuilder.getResults().getMessages(Message.Level.ERROR);
|
||||||
List<DroolsSyntaxErrorMessage> droolsSyntaxErrorMessages = errorMessages.stream().map(this::buildDroolsSyntaxErrorMessage).collect(Collectors.toList());
|
List<DroolsSyntaxErrorMessage> droolsSyntaxErrorMessages = errorMessages.stream()
|
||||||
return DroolsSyntaxValidation.builder().droolsSyntaxErrorMessages(droolsSyntaxErrorMessages).build();
|
.map(this::buildDroolsSyntaxErrorMessage)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
return DroolsSyntaxValidation.builder().droolsSyntaxErrorMessages(droolsSyntaxErrorMessages)
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private DroolsSyntaxErrorMessage buildDroolsSyntaxErrorMessage(Message message) {
|
private DroolsSyntaxErrorMessage buildDroolsSyntaxErrorMessage(Message message) {
|
||||||
|
|
||||||
return DroolsSyntaxErrorMessage.builder().line(message.getLine()).column(message.getColumn()).message(message.getText()).build();
|
return DroolsSyntaxErrorMessage.builder().line(message.getLine()).column(message.getColumn()).message(message.getText())
|
||||||
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package com.iqser.red.service.redaction.v1.server.drools.files.management.services;
|
package com.iqser.red.service.redaction.v1.server.drools.files.management.services;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
@ -18,6 +19,7 @@ import org.springframework.core.io.ClassPathResource;
|
|||||||
import com.iqser.red.service.persistence.service.v1.api.shared.model.RuleFileType;
|
import com.iqser.red.service.persistence.service.v1.api.shared.model.RuleFileType;
|
||||||
import com.iqser.red.service.redaction.v1.model.DroolsSyntaxValidation;
|
import com.iqser.red.service.redaction.v1.model.DroolsSyntaxValidation;
|
||||||
import com.iqser.red.service.redaction.v1.model.RuleValidationModel;
|
import com.iqser.red.service.redaction.v1.model.RuleValidationModel;
|
||||||
|
import com.iqser.red.service.redaction.v1.server.DeprecatedElementsFinder;
|
||||||
import com.iqser.red.service.redaction.v1.server.client.RulesClient;
|
import com.iqser.red.service.redaction.v1.server.client.RulesClient;
|
||||||
import com.iqser.red.service.redaction.v1.server.model.drools.RuleFileBluePrint;
|
import com.iqser.red.service.redaction.v1.server.model.drools.RuleFileBluePrint;
|
||||||
import com.iqser.red.service.redaction.v1.server.service.document.EntityEnrichmentService;
|
import com.iqser.red.service.redaction.v1.server.service.document.EntityEnrichmentService;
|
||||||
@ -47,13 +49,15 @@ class DroolsSyntaxValidationServiceTest {
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
void testRules() {
|
void testRules() {
|
||||||
|
|
||||||
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient));
|
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient),
|
||||||
|
new DeprecatedElementsFinder());
|
||||||
var rulesFile = new ClassPathResource("drools/rules.drl");
|
var rulesFile = new ClassPathResource("drools/rules.drl");
|
||||||
|
|
||||||
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
||||||
|
|
||||||
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), rulesString));
|
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), rulesString));
|
||||||
droolsSyntaxValidation.getDroolsSyntaxErrorMessages().forEach(System.out::println);
|
droolsSyntaxValidation.getDroolsSyntaxErrorMessages()
|
||||||
|
.forEach(System.out::println);
|
||||||
assertTrue(droolsSyntaxValidation.isCompiled());
|
assertTrue(droolsSyntaxValidation.isCompiled());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -62,14 +66,16 @@ class DroolsSyntaxValidationServiceTest {
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
void testRulesWithRemovedImportsAndChangedName() {
|
void testRulesWithRemovedImportsAndChangedName() {
|
||||||
|
|
||||||
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient));
|
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient),
|
||||||
|
new DeprecatedElementsFinder());
|
||||||
var rulesFile = new ClassPathResource("drools/rules.drl");
|
var rulesFile = new ClassPathResource("drools/rules.drl");
|
||||||
|
|
||||||
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
||||||
rulesString = rulesString.replaceAll("import com.iqser.red.service.redaction.v1.server.model.document.nodes.TableCell;", "");
|
rulesString = rulesString.replaceAll("import com.iqser.red.service.redaction.v1.server.model.document.nodes.TableCell;", "");
|
||||||
rulesString = rulesString.replaceAll("rule \"LDS.0.0: Run local dictionary search\"", "rule \"LDS.0.0: run local dictionary search\"");
|
rulesString = rulesString.replaceAll("rule \"LDS.0.0: Run local dictionary search\"", "rule \"LDS.0.0: run local dictionary search\"");
|
||||||
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), rulesString));
|
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), rulesString));
|
||||||
droolsSyntaxValidation.getDroolsSyntaxErrorMessages().forEach(System.out::println);
|
droolsSyntaxValidation.getDroolsSyntaxErrorMessages()
|
||||||
|
.forEach(System.out::println);
|
||||||
assertTrue(droolsSyntaxValidation.isCompiled());
|
assertTrue(droolsSyntaxValidation.isCompiled());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,102 +83,32 @@ class DroolsSyntaxValidationServiceTest {
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
void testRulesWithAddedImports() {
|
void testRulesWithAddedImports() {
|
||||||
|
|
||||||
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient));
|
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient),
|
||||||
|
new DeprecatedElementsFinder());
|
||||||
var rulesFile = new ClassPathResource("drools/rules.drl");
|
var rulesFile = new ClassPathResource("drools/rules.drl");
|
||||||
|
|
||||||
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
||||||
rulesString = rulesString.replaceAll("import com.iqser.red.service.redaction.v1.server.model.document.nodes.TableCell;", "import com.iqser.red.service.redaction.v1.server.model.document.nodes.TableCell;\nimport com.iqser.red.service.redaction.v1.server.service.document.EntityComparators;");
|
rulesString = rulesString.replaceAll("import com.iqser.red.service.redaction.v1.server.model.document.nodes.TableCell;",
|
||||||
|
"import com.iqser.red.service.redaction.v1.server.model.document.nodes.TableCell;\nimport com.iqser.red.service.redaction.v1.server.service.document.EntityComparators;");
|
||||||
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), rulesString));
|
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), rulesString));
|
||||||
droolsSyntaxValidation.getDroolsSyntaxErrorMessages().forEach(System.out::println);
|
droolsSyntaxValidation.getDroolsSyntaxErrorMessages()
|
||||||
|
.forEach(System.out::println);
|
||||||
assertTrue(droolsSyntaxValidation.isCompiled());
|
assertTrue(droolsSyntaxValidation.isCompiled());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@SneakyThrows
|
|
||||||
void testRulesWithUnallowedAddedImports() {
|
|
||||||
|
|
||||||
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient));
|
|
||||||
var rulesFile = new ClassPathResource("drools/rules.drl");
|
|
||||||
|
|
||||||
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
|
||||||
rulesString = rulesString.replaceAll("import com.iqser.red.service.redaction.v1.server.model.document.nodes.TableCell;", "import com.iqser.red.service.redaction.v1.server.model.document.nodes.TableCell;\nimport com.google.common.collect.Sets;");
|
|
||||||
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), rulesString));
|
|
||||||
droolsSyntaxValidation.getDroolsSyntaxErrorMessages().forEach(System.out::println);
|
|
||||||
assertFalse(droolsSyntaxValidation.isCompiled());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@SneakyThrows
|
|
||||||
void testAllRules() {
|
|
||||||
|
|
||||||
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient));
|
|
||||||
var rulesFile = new ClassPathResource("drools/all_redact_manager_rules.drl");
|
|
||||||
|
|
||||||
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
|
||||||
|
|
||||||
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), rulesString));
|
|
||||||
droolsSyntaxValidation.getDroolsSyntaxErrorMessages().forEach(System.out::println);
|
|
||||||
assertTrue(droolsSyntaxValidation.isCompiled());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@SneakyThrows
|
|
||||||
void testAcceptanceRules() {
|
|
||||||
|
|
||||||
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient));
|
|
||||||
var rulesFile = new ClassPathResource("drools/acceptance_rules.drl");
|
|
||||||
|
|
||||||
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
|
||||||
|
|
||||||
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), rulesString));
|
|
||||||
droolsSyntaxValidation.getDroolsSyntaxErrorMessages().forEach(System.out::println);
|
|
||||||
assertTrue(droolsSyntaxValidation.isCompiled());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@SneakyThrows
|
|
||||||
void testManualRedactionRules() {
|
|
||||||
|
|
||||||
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient));
|
|
||||||
var rulesFile = new ClassPathResource("drools/manual_redaction_rules.drl");
|
|
||||||
|
|
||||||
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
|
||||||
|
|
||||||
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), rulesString));
|
|
||||||
droolsSyntaxValidation.getDroolsSyntaxErrorMessages().forEach(System.out::println);
|
|
||||||
assertTrue(droolsSyntaxValidation.isCompiled());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@SneakyThrows
|
|
||||||
void testRulesV2() {
|
|
||||||
|
|
||||||
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient));
|
|
||||||
var rulesFile = new ClassPathResource("drools/rules_v2.drl");
|
|
||||||
|
|
||||||
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
|
||||||
|
|
||||||
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), rulesString));
|
|
||||||
droolsSyntaxValidation.getDroolsSyntaxErrorMessages().forEach(System.out::println);
|
|
||||||
assertTrue(droolsSyntaxValidation.isCompiled());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
void testDocumineRules() {
|
void testDocumineRules() {
|
||||||
|
|
||||||
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient));
|
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient),
|
||||||
|
new DeprecatedElementsFinder());
|
||||||
var rulesFile = new ClassPathResource("drools/documine_flora.drl");
|
var rulesFile = new ClassPathResource("drools/documine_flora.drl");
|
||||||
|
|
||||||
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
||||||
|
|
||||||
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), rulesString));
|
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), rulesString));
|
||||||
droolsSyntaxValidation.getDroolsSyntaxErrorMessages().forEach(System.out::println);
|
droolsSyntaxValidation.getDroolsSyntaxErrorMessages()
|
||||||
|
.forEach(System.out::println);
|
||||||
assertTrue(droolsSyntaxValidation.isCompiled());
|
assertTrue(droolsSyntaxValidation.isCompiled());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -181,7 +117,8 @@ class DroolsSyntaxValidationServiceTest {
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
void testCorruptedRules() {
|
void testCorruptedRules() {
|
||||||
|
|
||||||
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient));
|
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient),
|
||||||
|
new DeprecatedElementsFinder());
|
||||||
var rulesFile = new ClassPathResource("drools/rules.drl");
|
var rulesFile = new ClassPathResource("drools/rules.drl");
|
||||||
|
|
||||||
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
||||||
@ -196,12 +133,13 @@ class DroolsSyntaxValidationServiceTest {
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
void testCorruptedImports() {
|
void testCorruptedImports() {
|
||||||
|
|
||||||
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient));
|
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient),
|
||||||
|
new DeprecatedElementsFinder());
|
||||||
var rulesFile = new ClassPathResource("drools/rules.drl");
|
var rulesFile = new ClassPathResource("drools/rules.drl");
|
||||||
|
|
||||||
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
||||||
String corruptedRules = rulesString.replaceAll("import com.iqser.red.service.redaction.v1.server.model.document.nodes.ImageType;",
|
String corruptedRules = rulesString.replaceAll("import com.iqser.red.service.redaction.v1.server.model.document.nodes.ImageType;",
|
||||||
"import com.iqser.red.service.redaction.v1.server.model.document.nodes.ImageType;\nimport com.iqser.red.service.redaction.v1.server.model.document.nodes.SomethingElse;");
|
"import com.iqser.red.service.redaction.v1.server.model.document.nodes.ImageType;\nimport com.iqser.red.service.redaction.v1.server.model.document.nodes.SomethingElse;");
|
||||||
|
|
||||||
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), corruptedRules));
|
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), corruptedRules));
|
||||||
assertFalse(droolsSyntaxValidation.isCompiled());
|
assertFalse(droolsSyntaxValidation.isCompiled());
|
||||||
@ -212,14 +150,16 @@ class DroolsSyntaxValidationServiceTest {
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
void testRemoveQuery() {
|
void testRemoveQuery() {
|
||||||
|
|
||||||
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient));
|
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient),
|
||||||
|
new DeprecatedElementsFinder());
|
||||||
var rulesFile = new ClassPathResource("drools/rules.drl");
|
var rulesFile = new ClassPathResource("drools/rules.drl");
|
||||||
|
|
||||||
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
||||||
String corruptedRules = rulesString.replaceAll("query \"getFileAttributes\"\n.*\n *end", "");
|
String corruptedRules = rulesString.replaceAll("query \"getFileAttributes\"\n.*\n *end", "");
|
||||||
|
|
||||||
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), corruptedRules));
|
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), corruptedRules));
|
||||||
droolsSyntaxValidation.getDroolsSyntaxErrorMessages().forEach(System.out::println);
|
droolsSyntaxValidation.getDroolsSyntaxErrorMessages()
|
||||||
|
.forEach(System.out::println);
|
||||||
assertFalse(droolsSyntaxValidation.isCompiled());
|
assertFalse(droolsSyntaxValidation.isCompiled());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -228,13 +168,15 @@ class DroolsSyntaxValidationServiceTest {
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
void testComponentDrools() {
|
void testComponentDrools() {
|
||||||
|
|
||||||
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient));
|
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient),
|
||||||
|
new DeprecatedElementsFinder());
|
||||||
var rulesFile = new ClassPathResource("drools/documine_flora_components.drl");
|
var rulesFile = new ClassPathResource("drools/documine_flora_components.drl");
|
||||||
|
|
||||||
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
||||||
|
|
||||||
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.COMPONENT.name(), rulesString));
|
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.COMPONENT.name(), rulesString));
|
||||||
droolsSyntaxValidation.getDroolsSyntaxErrorMessages().forEach(System.out::println);
|
droolsSyntaxValidation.getDroolsSyntaxErrorMessages()
|
||||||
|
.forEach(System.out::println);
|
||||||
assertTrue(droolsSyntaxValidation.isCompiled());
|
assertTrue(droolsSyntaxValidation.isCompiled());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -243,13 +185,15 @@ class DroolsSyntaxValidationServiceTest {
|
|||||||
@SneakyThrows
|
@SneakyThrows
|
||||||
void testComponentDroolsAsEntityDrools() {
|
void testComponentDroolsAsEntityDrools() {
|
||||||
|
|
||||||
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient));
|
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient),
|
||||||
|
new DeprecatedElementsFinder());
|
||||||
var rulesFile = new ClassPathResource("drools/documine_flora_components.drl");
|
var rulesFile = new ClassPathResource("drools/documine_flora_components.drl");
|
||||||
|
|
||||||
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
||||||
|
|
||||||
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), rulesString));
|
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), rulesString));
|
||||||
droolsSyntaxValidation.getDroolsSyntaxErrorMessages().forEach(System.out::println);
|
droolsSyntaxValidation.getDroolsSyntaxErrorMessages()
|
||||||
|
.forEach(System.out::println);
|
||||||
assertFalse(droolsSyntaxValidation.isCompiled());
|
assertFalse(droolsSyntaxValidation.isCompiled());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -259,13 +203,15 @@ class DroolsSyntaxValidationServiceTest {
|
|||||||
@Disabled
|
@Disabled
|
||||||
void attemptImportsFixToAllRuleFiles() {
|
void attemptImportsFixToAllRuleFiles() {
|
||||||
|
|
||||||
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient));
|
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient),
|
||||||
|
new DeprecatedElementsFinder());
|
||||||
|
|
||||||
List<String> ruleFiles = List.of("drools/rules.drl", "drools/all_redact_manager_rules.drl",
|
List<String> ruleFiles = List.of("drools/rules.drl",
|
||||||
"drools/documine_flora.drl",
|
"drools/all_redact_manager_rules.drl",
|
||||||
"drools/manual_redaction_rules.drl",
|
"drools/documine_flora.drl",
|
||||||
"drools/acceptance_rules.drl",
|
"drools/manual_redaction_rules.drl",
|
||||||
"drools/rules_v2.drl");
|
"drools/acceptance_rules.drl",
|
||||||
|
"drools/rules_v2.drl");
|
||||||
|
|
||||||
for (String ruleFile : ruleFiles) {
|
for (String ruleFile : ruleFiles) {
|
||||||
var rulesFile = new ClassPathResource(ruleFile);
|
var rulesFile = new ClassPathResource(ruleFile);
|
||||||
@ -288,4 +234,109 @@ class DroolsSyntaxValidationServiceTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SneakyThrows
|
||||||
|
void testRulesWithUnallowedAddedImports() {
|
||||||
|
|
||||||
|
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient),
|
||||||
|
new DeprecatedElementsFinder());
|
||||||
|
var rulesFile = new ClassPathResource("drools/rules.drl");
|
||||||
|
|
||||||
|
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
||||||
|
rulesString = rulesString.replaceAll("import com.iqser.red.service.redaction.v1.server.model.document.nodes.TableCell;",
|
||||||
|
"import com.iqser.red.service.redaction.v1.server.model.document.nodes.TableCell;\nimport com.google.common.collect.Sets;");
|
||||||
|
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), rulesString));
|
||||||
|
droolsSyntaxValidation.getDroolsSyntaxErrorMessages()
|
||||||
|
.forEach(System.out::println);
|
||||||
|
assertFalse(droolsSyntaxValidation.isCompiled());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SneakyThrows
|
||||||
|
void testAllRules() {
|
||||||
|
|
||||||
|
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient),
|
||||||
|
new DeprecatedElementsFinder());
|
||||||
|
var rulesFile = new ClassPathResource("drools/all_redact_manager_rules.drl");
|
||||||
|
|
||||||
|
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
||||||
|
|
||||||
|
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), rulesString));
|
||||||
|
droolsSyntaxValidation.getDroolsSyntaxErrorMessages()
|
||||||
|
.forEach(System.out::println);
|
||||||
|
assertTrue(droolsSyntaxValidation.isCompiled());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SneakyThrows
|
||||||
|
void testAcceptanceRules() {
|
||||||
|
|
||||||
|
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient),
|
||||||
|
new DeprecatedElementsFinder());
|
||||||
|
var rulesFile = new ClassPathResource("drools/acceptance_rules.drl");
|
||||||
|
|
||||||
|
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
||||||
|
|
||||||
|
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), rulesString));
|
||||||
|
droolsSyntaxValidation.getDroolsSyntaxErrorMessages()
|
||||||
|
.forEach(System.out::println);
|
||||||
|
assertTrue(droolsSyntaxValidation.isCompiled());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SneakyThrows
|
||||||
|
void testManualRedactionRules() {
|
||||||
|
|
||||||
|
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient),
|
||||||
|
new DeprecatedElementsFinder());
|
||||||
|
var rulesFile = new ClassPathResource("drools/manual_redaction_rules.drl");
|
||||||
|
|
||||||
|
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
||||||
|
|
||||||
|
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), rulesString));
|
||||||
|
droolsSyntaxValidation.getDroolsSyntaxErrorMessages()
|
||||||
|
.forEach(System.out::println);
|
||||||
|
assertTrue(droolsSyntaxValidation.isCompiled());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SneakyThrows
|
||||||
|
void testRulesV2() {
|
||||||
|
|
||||||
|
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient),
|
||||||
|
new DeprecatedElementsFinder());
|
||||||
|
var rulesFile = new ClassPathResource("drools/rules_v2.drl");
|
||||||
|
|
||||||
|
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
||||||
|
|
||||||
|
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), rulesString));
|
||||||
|
droolsSyntaxValidation.getDroolsSyntaxErrorMessages()
|
||||||
|
.forEach(System.out::println);
|
||||||
|
assertTrue(droolsSyntaxValidation.isCompiled());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@SneakyThrows
|
||||||
|
void testRulesWithDeprecatedFunctions() {
|
||||||
|
|
||||||
|
DroolsSyntaxValidationService droolsSyntaxValidationService = new DroolsSyntaxValidationService(new KieContainerCreationService(rulesClient),
|
||||||
|
new DeprecatedElementsFinder());
|
||||||
|
var rulesFile = new ClassPathResource("drools/rules.drl");
|
||||||
|
|
||||||
|
String rulesString = new String(rulesFile.getInputStream().readAllBytes());
|
||||||
|
rulesString = rulesString.replaceAll(".resize\\(", ".resizeEntityAndReinsert(");
|
||||||
|
|
||||||
|
DroolsSyntaxValidation droolsSyntaxValidation = droolsSyntaxValidationService.testRules(new RuleValidationModel(RuleFileType.ENTITY.name(), rulesString));
|
||||||
|
droolsSyntaxValidation.getDroolsSyntaxErrorMessages()
|
||||||
|
.forEach(System.out::println);
|
||||||
|
assertTrue(droolsSyntaxValidation.isCompiled());
|
||||||
|
assertEquals(droolsSyntaxValidation.getDroolsSyntaxDeprecatedWarnings().size(), 2);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user