Fix compilazione statica drools

This commit is contained in:
2024-08-06 16:56:06 +02:00
parent 5cf7b89472
commit 01552d5335
2 changed files with 38 additions and 34 deletions

View File

@@ -5,6 +5,7 @@ import it.integry.ems.properties.EmsProperties;
import org.springframework.web.context.ContextLoader;
import java.io.File;
import java.nio.file.Paths;
import java.util.HashMap;
public class UtilityDirs {
@@ -75,7 +76,7 @@ public class UtilityDirs {
}
public static String getWebAppPath() {
return CATALINA_HOME + "/webapps/ems-api/";
return Paths.get(CATALINA_HOME, "webapps", "ems-api").toString();
}

View File

@@ -2,7 +2,7 @@ package it.integry.ems_model.rulescompleting;
import it.integry.annotations.PostContextConstruct;
import it.integry.ems.utility.UtilityDebug;
import it.integry.ems.utility.UtilityFile;
import it.integry.ems.utility.UtilityDirs;
import it.integry.ems_model.base.EntityInterface;
import it.integry.ems_model.base.EntityPropertyHolder;
import it.integry.ems_model.exception.RulesNotCompiledException;
@@ -26,6 +26,7 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.Connection;
@Service
@@ -65,10 +66,10 @@ public class DroolsDataCompleting {
KieServices kieServices = KieServices.Factory.get();
KieFileSystem kFileSystem = kieServices.newKieFileSystem();
String compiledRulesPath = getBaseAppFolder() + "drools" + pathS;
String compiledRulesPath = getCompiledDroolsFolder();
String compiledRulesFileName = "compiled_kie_base.ckie";
File compiledDrlFile = new File(compiledRulesPath + compiledRulesFileName);
File compiledDrlFile = new File(compiledRulesPath, compiledRulesFileName);
//System.out.println("AIO: " + compiledRulesPath);
@@ -77,11 +78,14 @@ public class DroolsDataCompleting {
System.setProperty("drools.dialect.mvel.strict", "false");
if (!compiledDrlFile.exists()) {
if (shouldCompileDrools()) {
File directory = new File(compiledRulesPath);
if (!directory.exists()) {
if (!directory.exists())
directory.mkdirs();
}
if(compiledDrlFile.exists())
compiledDrlFile.delete();
for (String drl : dlrs) {
String resourcePath = pathS + "rules" + pathS + drl;
@@ -124,12 +128,6 @@ public class DroolsDataCompleting {
KieContainer kieContainer = kieServices.newKieContainer(kieServices.getRepository().getDefaultReleaseId());
kieBase = kieContainer.getKieBase();
serialize(kieBase, compiledDrlFile);
if (UtilityDebug.isDebugExecution()) {
String fullPath = getDebugPath() + "drools" + pathS;
UtilityFile.directoryCreate(fullPath);
serialize(kieBase, new File(fullPath + compiledRulesFileName));
}
} else {
kieBase = deserialize(KieBase.class, compiledDrlFile);
}
@@ -140,31 +138,36 @@ public class DroolsDataCompleting {
}
private String getBaseAppFolder() {
if (UtilityDebug.isDebugExecution() && "TRUE".equalsIgnoreCase(System.getProperty("DISABLE_DROOLS_COMPILE"))) {
return getDebugPath();
}
String fullPath = getClass().getResource("").toString();
String[] singleElemsOfPath = fullPath.split("/");
String currentFolderName = "";
for (String aSingleElemsOfPath : singleElemsOfPath) {
if (aSingleElemsOfPath.contains("-api")) {
currentFolderName = aSingleElemsOfPath;
}
}
return System.getProperty("catalina.base") + File.separator + "webapps" + File.separator + currentFolderName + File.separator;
private boolean shouldCompileDrools() {
return !UtilityDebug.isDebugExecution() || !"TRUE".equalsIgnoreCase(System.getProperty("DISABLE_DROOLS_COMPILE"));
}
private String getDebugPath() {
return "C:\\Work\\Prod_Java\\";
private String getCompiledDroolsFolder() {
return Paths.get(UtilityDirs.getWebAppPath(), "drools").toString();
//
// if (UtilityDebug.isDebugExecution() && "TRUE".equalsIgnoreCase(System.getProperty("DISABLE_DROOLS_COMPILE"))) {
// return getDebugPath();
// }
//
// String fullPath = getClass().getResource("").toString();
// String[] singleElemsOfPath = fullPath.split("/");
//
//
// String currentFolderName = "";
//
// for (String aSingleElemsOfPath : singleElemsOfPath) {
// if (aSingleElemsOfPath.contains("-api")) {
// currentFolderName = aSingleElemsOfPath;
// }
// }
//
// return System.getProperty("catalina.base") + File.separator + "webapps" + File.separator + currentFolderName + File.separator;
}
// private String getDebugPath() {
// }
private <T> void serialize(T o, File outputFile) throws IOException {
ObjectOutputStream out = new ObjectOutputStream(Files.newOutputStream(outputFile.toPath()));
out.writeObject(o);