use of org.drools.modelcompiler.CanonicalKiePackages in project drools by kiegroup.
the class CanonicalKieBaseUpdater method run.
@Override
public void run() {
CanonicalKieModule oldKM = (CanonicalKieModule) ctx.currentKM;
CanonicalKieModule newKM = (CanonicalKieModule) ctx.newKM;
List<RuleImpl> rulesToBeRemoved;
List<RuleImpl> rulesToBeAdded;
if (ctx.modifyingUsedClass) {
// remove all ObjectTypeNodes for the modified classes
for (Class<?> cls : ctx.modifiedClasses) {
clearInstancesOfModifiedClass(cls);
}
rulesToBeRemoved = getAllRulesInKieBase(oldKM, ctx.currentKieBaseModel);
rulesToBeAdded = getAllRulesInKieBase(newKM, ctx.newKieBaseModel);
} else {
newKM.setModuleClassLoader(((CanonicalKieModule) ctx.currentKM).getModuleClassLoader());
CanonicalKiePackages newPkgs = newKM.getKiePackages(ctx.newKieBaseModel);
rulesToBeRemoved = new ArrayList<>();
rulesToBeAdded = new ArrayList<>();
for (ResourceChangeSet changeSet : ctx.cs.getChanges().values()) {
if (!isPackageInKieBase(ctx.newKieBaseModel, changeSet.getResourceName())) {
continue;
}
InternalKnowledgePackage oldKpkg = ctx.kBase.getPackage(changeSet.getResourceName());
InternalKnowledgePackage kpkg = (InternalKnowledgePackage) newPkgs.getKiePackage(changeSet.getResourceName());
for (ResourceChange change : changeSet.getChanges()) {
String changedItemName = change.getName();
if (change.getChangeType() == ChangeType.UPDATED || change.getChangeType() == ChangeType.REMOVED) {
if (change.getType() == ResourceChange.Type.GLOBAL) {
ctx.kBase.removeGlobal(changedItemName);
} else {
rulesToBeRemoved.add(oldKpkg.getRule(changedItemName));
}
}
if (change.getChangeType() == ChangeType.UPDATED || change.getChangeType() == ChangeType.ADDED) {
if (change.getType() == ResourceChange.Type.GLOBAL) {
try {
ctx.kBase.addGlobal(changedItemName, kpkg.getTypeResolver().resolveType(kpkg.getGlobals().get(changedItemName)));
} catch (ClassNotFoundException e) {
throw new RuntimeException(e);
}
} else {
rulesToBeAdded.add(kpkg.getRule(changedItemName));
}
}
}
}
}
ctx.kBase.removeRules(rulesToBeRemoved);
ctx.kBase.addRules(rulesToBeAdded);
}
Aggregations