kbasesToRemove.add( kbaseName );
} else {
// attaching the builder to the kbase
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder( (KnowledgeBase) kBaseEntry.getValue() );
PackageBuilder pkgbuilder = kbuilder instanceof PackageBuilder ? ((PackageBuilder) kbuilder) : ((KnowledgeBuilderImpl)kbuilder).getPackageBuilder();
CompositeKnowledgeBuilder ckbuilder = kbuilder.batch();
int fileCount = 0;
// remove resources first
for( ResourceChangeSet rcs : cs.getChanges().values() ) {
if( rcs.getChangeType().equals( ChangeType.REMOVED ) ) {
String resourceName = rcs.getResourceName();
if( KieBuilderImpl.filterFileInKBase( kieBaseModel, resourceName ) && ! resourceName.endsWith( ".properties" ) ) {
pkgbuilder.removeObjectsGeneratedFromResource( currentKM.getResource( resourceName ) );
}
}
}
// then update and add new resources
for( ResourceChangeSet rcs : cs.getChanges().values() ) {
if( ! rcs.getChangeType().equals( ChangeType.REMOVED ) ) {
String resourceName = rcs.getResourceName();
if( KieBuilderImpl.filterFileInKBase( kieBaseModel, resourceName ) && ! resourceName.endsWith( ".properties" ) ) {
Resource resource = currentKM.getResource( rcs.getResourceName() );
List<ResourceChange> changes = rcs.getChanges();
if( ! changes.isEmpty() ) {
// we need to deal with individual parts of the resource
fileCount += AbstractKieModule.updateResource( ckbuilder,
newKM,
resourceName,
rcs ) ? 1 : 0;
} else {
// the whole resource has to handled
if( rcs.getChangeType().equals( ChangeType.UPDATED ) ) {
pkgbuilder.removeObjectsGeneratedFromResource( resource );
}
fileCount += AbstractKieModule.addFile( ckbuilder,
newKM,
resourceName ) ? 1 : 0;
}
}
}
KieBase kBase = kBaseEntry.getValue();
for ( ResourceChangeSet.RuleLoadOrder loadOrder : rcs.getLoadOrder() ) {
Rule rule = (Rule) ((KnowledgePackageImp)kBase.getKiePackage( loadOrder.getPkgName() )).getRule( loadOrder.getRuleName() );
if ( rule != null ) {
// rule can be null, if it didn't exist before
rule.setLoadOrder( loadOrder.getLoadOrder() );
}
}
}
if( fileCount > 0 ) {
ckbuilder.build();
}
}
}
for (String kbaseToRemove : kbasesToRemove) {