RM-184 && RM-172: update SectionIdentifier javadoc, make RulesLogger and...

This commit is contained in:
Kilian Schüttler 2024-10-10 10:35:12 +02:00
parent 0aea884da2
commit 11a9f2f8aa
10 changed files with 44 additions and 48 deletions

View File

@ -61,6 +61,11 @@ public class Headline extends AbstractSemanticNode {
}
/**
* Extracts the SectionIdentifier from the text of this headline.
*
* @return The SectionIdentifier, with which the headline starts.
*/
@Override
public SectionIdentifier getSectionIdentifier() {

View File

@ -19,7 +19,6 @@ import lombok.extern.slf4j.Slf4j;
@EqualsAndHashCode(onlyExplicitlyIncluded = true, callSuper = true)
public class Section extends AbstractSemanticNode {
@Override
public NodeType getType() {
@ -39,6 +38,11 @@ public class Section extends AbstractSemanticNode {
}
/**
* Returns the SectionIdentifier from the headline obtained by the getHeadline() method.
*
* @return the SectionIdentifier of the associated Headline
*/
@Override
public SectionIdentifier getSectionIdentifier() {
@ -46,7 +50,6 @@ public class Section extends AbstractSemanticNode {
}
@Override
public String toString() {
@ -86,5 +89,4 @@ public class Section extends AbstractSemanticNode {
return streamAllSubNodesOfType(NodeType.HEADLINE).anyMatch(h -> h.containsStringIgnoreCase(value));
}
}

View File

@ -13,7 +13,8 @@ import lombok.Getter;
import lombok.experimental.FieldDefaults;
/**
* Represents a unique identifier for a section within a document.
* Represents the textual identifier sometimes present in a Headline. For example, given the headline 3.1 Results, the section identifier is 3.1.
* Keep in mind, this identifier must not be unique in a single document, as there might be multiple headlines starting with the same textual identifier.
*/
@AllArgsConstructor
@FieldDefaults(makeFinal = true, level = AccessLevel.PRIVATE)
@ -142,7 +143,7 @@ public class SectionIdentifier {
/**
* Determines if the current section is the parent of the given section.
* Determines if the current SectionIdentifier is the parent of the given SectionIdentifier.
*
* @param sectionIdentifier The section identifier to compare against.
* @return true if the current section is the parent of the given section, false otherwise.

View File

@ -182,7 +182,7 @@ public interface SemanticNode {
/**
* Returns a SectionIdentifier, such that it acts as a child of the first Headline associated with this SemanticNode.
* Returns the SectionIdentifier as a child of the SectionIdentifier returned by the getHeadline() method.
*
* @return The SectionIdentifier from the first Headline.
*/

View File

@ -2,7 +2,6 @@ package com.iqser.red.service.redaction.v1.server.model.document.nodes;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.FieldDefaults;
@ -39,6 +38,11 @@ public class SuperSection extends AbstractSemanticNode {
}
/**
* Returns the SectionIdentifier from the headline obtained by the getHeadline() method.
*
* @return the SectionIdentifier of the associated Headline
*/
@Override
public SectionIdentifier getSectionIdentifier() {
@ -46,7 +50,6 @@ public class SuperSection extends AbstractSemanticNode {
}
@Override
public String toString() {
@ -86,5 +89,4 @@ public class SuperSection extends AbstractSemanticNode {
return streamAllSubNodesOfType(NodeType.HEADLINE).anyMatch(h -> h.containsStringIgnoreCase(value));
}
}

View File

@ -15,7 +15,6 @@ import org.kie.api.runtime.rule.QueryResults;
import org.kie.api.runtime.rule.QueryResultsRow;
import org.springframework.stereotype.Service;
import com.iqser.red.service.persistence.service.v1.api.internal.resources.DateFormatsResource;
import com.iqser.red.service.persistence.service.v1.api.shared.model.FileAttribute;
import com.iqser.red.service.persistence.service.v1.api.shared.model.RuleFileType;
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntityLog;
@ -23,7 +22,6 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog
import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog.entitylog.EntryState;
import com.iqser.red.service.persistence.service.v1.api.shared.model.component.ComponentMappingMetadata;
import com.iqser.red.service.redaction.v1.server.RedactionServiceSettings;
import com.iqser.red.service.redaction.v1.server.client.DateFormatsClient;
import com.iqser.red.service.redaction.v1.server.logger.Context;
import com.iqser.red.service.redaction.v1.server.logger.ObjectTrackingEventListener;
import com.iqser.red.service.redaction.v1.server.logger.RulesLogger;
@ -37,7 +35,6 @@ import com.iqser.red.service.redaction.v1.server.service.components.DateConverte
import com.iqser.red.service.redaction.v1.server.service.document.ComponentComparator;
import com.iqser.red.service.redaction.v1.server.service.document.ComponentCreationService;
import com.iqser.red.service.redaction.v1.server.service.websocket.WebSocketService;
import com.iqser.red.service.redaction.v1.server.utils.DateConverter;
import com.iqser.red.service.redaction.v1.server.utils.exception.DroolsTimeoutException;
import com.knecon.fforesight.tenantcommons.TenantContext;
@ -53,6 +50,7 @@ import lombok.extern.slf4j.Slf4j;
public class ComponentDroolsExecutionService {
public static final String COMPONENT_MAPPING_SERVICE_GLOBAL = "componentMappingService";
public static final String RULES_LOGGER_GLOBAL = "logger";
RedactionServiceSettings settings;
ComponentMappingMemoryCache componentMappingMemoryCache;
@ -81,13 +79,12 @@ public class ComponentDroolsExecutionService {
kieSession.addEventListener(new ObjectTrackingEventListener(logger));
kieSession.setGlobal("componentCreationService", componentCreationService);
try {
kieSession.setGlobal("logger", logger);
} catch (RuntimeException e) {
log.warn("Logger is not present");
if (hasGlobalWithName(kieSession, RULES_LOGGER_GLOBAL)) {
kieSession.setGlobal(RULES_LOGGER_GLOBAL, logger);
}
if (hasComponentMappingServiceGlobal(kieSession)) {
if (hasGlobalWithName(kieSession, COMPONENT_MAPPING_SERVICE_GLOBAL)) {
kieSession.setGlobal(COMPONENT_MAPPING_SERVICE_GLOBAL, componentMappingService);
}
@ -169,13 +166,13 @@ public class ComponentDroolsExecutionService {
}
private static boolean hasComponentMappingServiceGlobal(KieSession kieSession) {
private static boolean hasGlobalWithName(KieSession kieSession, String globalName) {
return kieSession.getKieBase().getKiePackages()
.stream()
.flatMap(kiePackage -> kiePackage.getGlobalVariables()
.stream())
.anyMatch(global -> global.getName().equals(COMPONENT_MAPPING_SERVICE_GLOBAL));
.anyMatch(global -> global.getName().equals(globalName));
}

View File

@ -73,7 +73,7 @@ public class DroolsValidationService {
DroolsValidation customValidation = ruleFileBluePrint.getDroolsValidation();
addSyntaxDeprecatedWarnings(ruleFileType, ruleFileBluePrint, customValidation);
addSyntaxDeprecatedWarnings(ruleFileBluePrint, customValidation);
addSyntaxErrorMessages(ruleFileType, ruleFileBluePrint, customValidation);
@ -85,7 +85,7 @@ public class DroolsValidationService {
}
private void addSyntaxDeprecatedWarnings(RuleFileType ruleFileType, RuleFileBluePrint ruleFileBluePrint, DroolsValidation customValidation) {
private void addSyntaxDeprecatedWarnings(RuleFileBluePrint ruleFileBluePrint, DroolsValidation customValidation) {
// find deprecated elements in the ruleFileBluePrint
DroolsSyntaxDeprecatedWarnings warningMessageForImports = getWarningsForDeprecatedImports(ruleFileBluePrint);
@ -93,25 +93,6 @@ public class DroolsValidationService {
customValidation.getDeprecatedWarnings().add(warningMessageForImports);
}
customValidation.getDeprecatedWarnings().addAll(getWarningsForDeprecatedRules(ruleFileBluePrint));
if (ruleFileType.equals(RuleFileType.COMPONENT)) {
if (!ruleFileBluePrint.getGlobals().contains(ComponentDroolsExecutionService.COMPONENT_MAPPING_SERVICE_GLOBAL)) {
customValidation.getDeprecatedWarnings().add(buildComponentMappingServiceMissingMessage(ruleFileBluePrint));
}
}
}
private static DroolsSyntaxDeprecatedWarnings buildComponentMappingServiceMissingMessage(RuleFileBluePrint ruleFileBluePrint) {
return DroolsSyntaxDeprecatedWarnings.builder()
.message("global ComponentMappingService "
+ ComponentDroolsExecutionService.COMPONENT_MAPPING_SERVICE_GLOBAL
+ "\n is missing from the rules, consider adding it, as it will be required in future versions!")
.line(ruleFileBluePrint.getGlobalsLine())
.column(0)
.build();
}
@ -284,7 +265,7 @@ public class DroolsValidationService {
private DroolsBlacklistErrorMessage checkAndGetBlackListedMessages(SearchImplementation blacklistedKeywordSearchImplementation, String stringToCheck, int lineIndexStart) {
String nonWhitespaceRuleText = StringUtils.deleteWhitespace(stringToCheck);
String sanitizedRuleText= nonWhitespaceRuleText.replaceAll("\"(\\\\.|[^\"\\\\])*\"|'(\\\\.|[^'\\\\])*'" ,"");
String sanitizedRuleText = nonWhitespaceRuleText.replaceAll("\"(\\\\.|[^\"\\\\])*\"|'(\\\\.|[^'\\\\])*'", "");
List<SearchImplementation.MatchPosition> matches = blacklistedKeywordSearchImplementation.getMatches(sanitizedRuleText);

View File

@ -1,5 +1,7 @@
package com.iqser.red.service.redaction.v1.server.service.drools;
import static com.iqser.red.service.redaction.v1.server.service.drools.ComponentDroolsExecutionService.RULES_LOGGER_GLOBAL;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
@ -109,10 +111,9 @@ public class EntityDroolsExecutionService {
kieSession.setGlobal("entityCreationService", entityCreationService);
kieSession.setGlobal("manualChangesApplicationService", manualChangesApplicationService);
kieSession.setGlobal("dictionary", dictionary);
try {
kieSession.setGlobal("logger", logger);
} catch (RuntimeException e) {
log.warn("Logger is not present");
if (hasGlobalWithName(kieSession, RULES_LOGGER_GLOBAL)) {
kieSession.setGlobal(RULES_LOGGER_GLOBAL, logger);
}
kieSession.insert(document);
@ -202,4 +203,14 @@ public class EntityDroolsExecutionService {
}
}
private static boolean hasGlobalWithName(KieSession kieSession, String globalName) {
return kieSession.getKieBase().getKiePackages()
.stream()
.flatMap(kiePackage -> kiePackage.getGlobalVariables()
.stream())
.anyMatch(global -> global.getName().equals(globalName));
}
}

View File

@ -29,8 +29,6 @@ import com.iqser.red.service.persistence.service.v1.api.shared.model.analysislog
import com.iqser.red.service.persistence.service.v1.api.shared.model.FileAttribute;
global ComponentCreationService componentCreationService
global ComponentMappingService componentMappingService
global RulesLogger logger
/**

View File

@ -60,7 +60,6 @@ global Document document
global EntityCreationService entityCreationService
global ManualChangesApplicationService manualChangesApplicationService
global Dictionary dictionary
global RulesLogger logger
/**