Package org.kie.internal.builder

Examples of org.kie.internal.builder.CompositeKnowledgeBuilder


        return Collections.emptyList();
    }

  private KnowledgeBuilder compositeBuild(List<ResourceDescr> resources, Map<Resource, ResourceDescr> resourceMap) throws CoreException {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(getBuilderConfiguration(resources));
    CompositeKnowledgeBuilder compositeKBuilder = kbuilder.batch();
    for (ResourceDescr resourceDescr : resources) {
      Resource resource = resourceDescr.getContentAsDroolsResource();
      resourceMap.put(resource, resourceDescr);
      compositeKBuilder.add(resource, resourceDescr.getType());
    }
    try {
      compositeKBuilder.build();
    } catch (DecisionTableParseException dtpe) {
      // swallow
    }
    return kbuilder;
  }
View Full Code Here


                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" ) ) {
                            fileCount += AbstractKieModule.addFile( ckbuilder,
                                                                    newKM,
                                                                    resourceName ) ? 1 : 0;
                        }
                    }
                }
                if( fileCount > 0 ) {
                    ckbuilder.build();
                }
            }
        }

        for (String kbaseToRemove : kbasesToRemove) {
View Full Code Here

        PackageBuilderConfiguration pconf = new PackageBuilderConfiguration(kieProject.getClonedClassLoader());
        pconf.setCompilationCache(kModule.getCompilationCache(kBaseModel.getName()));

        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(pconf);
        CompositeKnowledgeBuilder ckbuilder = kbuilder.batch();

        Map<String, InternalKieModule> assets = new HashMap<String, InternalKieModule>();

        for (String include : getTransitiveIncludes(kieProject, kBaseModel)) {
            if (StringUtils.isEmpty(include)) {
                continue;
            }
            InternalKieModule includeModule = kieProject.getKieModuleForKBase(include);
            if (includeModule == null) {
                log.error("Unable to build KieBase, could not find include: " + include);
                return null;
            }
            addFiles(assets,
                    kieProject.getKieBaseModel(include),
                    includeModule);
        }

        addFiles(assets,
                kBaseModel,
                kModule);

        if (assets.isEmpty()) {
            if (kModule instanceof FileKieModule) {
                log.warn("No files found for KieBase " + kBaseModel.getName() + ", searching folder " + kModule.getFile());
            } else {
                log.warn("No files found for KieBase " + kBaseModel.getName());
            }
        } else {
            for (Map.Entry<String, InternalKieModule> entry : assets.entrySet()) {
                addFile(ckbuilder, entry.getValue(), entry.getKey());
            }
        }

        ckbuilder.build();

        if (kbuilder.hasErrors()) {
            for (KnowledgeBuilderError error : kbuilder.getErrors()) {
                messages.addMessage(error);
            }
View Full Code Here

        List<KnowledgeBuilderError> currentErrors = new ArrayList<KnowledgeBuilderError>();

        InternalKieModule kieModule = (InternalKieModule) kieBuilder.getKieModuleIgnoringErrors();
        for (KieBaseModel kBaseModel : kieModule.getKieModuleModel().getKieBaseModels().values()) {
            KnowledgeBuilder kBuilder = kieModule.getKnowledgeBuilderForKieBase( kBaseModel.getName() );
            CompositeKnowledgeBuilder ckbuilder = kBuilder.batch();

            boolean modified = false;
            PackageBuilder pkgBuilder = ((KnowledgeBuilderImpl)kBuilder).getPackageBuilder();
            Set<String> wrongResources = resourcesWithErrors.get(kBaseModel.getName());
            for ( String resourceName : wrongResources ) {
                modified = pkgBuilder.removeObjectsGeneratedFromResource(new DummyResource(resourceName)) || modified;
                modified = addResource(ckbuilder, kBaseModel, kieModule, resourceName) || modified;
            }

            for (String file : files) {
                String resourceName = file.startsWith(KieBuilderImpl.RESOURCES_ROOT) ?
                        file.substring(KieBuilderImpl.RESOURCES_ROOT.length()) :
                        file;

                if ( wrongResources.contains(resourceName) ) {
                    modified = true;
                } else {
                    // remove the objects generated by the old Resource
                    modified = pkgBuilder.removeObjectsGeneratedFromResource(new DummyResource(resourceName)) || modified;
                    // add the modified Resource
                    modified = addResource(ckbuilder, kBaseModel, kieModule, resourceName) || modified;
                }
            }

            if (modified) {
                ckbuilder.build();
                resourcesWithErrors.put(kBaseModel.getName(), findResourcesWithErrors(kBuilder));
                if ( kBuilder.hasErrors() ) {
                    currentErrors.addAll(kBuilder.getErrors());
                    kBuilder.undo();
                } else {
View Full Code Here

                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) {
View Full Code Here

        PackageBuilderConfiguration pconf = new PackageBuilderConfiguration(kieProject.getClonedClassLoader());
        pconf.setCompilationCache(kModule.getCompilationCache(kBaseModel.getName()));

        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(pconf);
        CompositeKnowledgeBuilder ckbuilder = kbuilder.batch();

        Map<String, InternalKieModule> assets = new HashMap<String, InternalKieModule>();

        for (String include : getTransitiveIncludes(kieProject, kBaseModel)) {
            if (StringUtils.isEmpty(include)) {
                continue;
            }
            InternalKieModule includeModule = kieProject.getKieModuleForKBase(include);
            if (includeModule == null) {
                log.error("Unable to build KieBase, could not find include: " + include);
                return null;
            }
            addFiles(assets,
                    kieProject.getKieBaseModel(include),
                    includeModule);
        }

        addFiles(assets,
                kBaseModel,
                kModule);

        if (assets.isEmpty()) {
            if (kModule instanceof FileKieModule) {
                log.warn("No files found for KieBase " + kBaseModel.getName() + ", searching folder " + kModule.getFile());
            } else {
                log.warn("No files found for KieBase " + kBaseModel.getName());
            }
        } else {
            for (Map.Entry<String, InternalKieModule> entry : assets.entrySet()) {
                addFile(ckbuilder, entry.getValue(), entry.getKey());
            }
        }

        ckbuilder.build();

        if (kbuilder.hasErrors()) {
            for (KnowledgeBuilderError error : kbuilder.getErrors()) {
                messages.addMessage(error);
            }
View Full Code Here

        PackageBuilderConfiguration pconf = new PackageBuilderConfiguration( kieProject.getClassLoader() );
        pconf.setCompilationCache( kModule.getCompilationCache( kBaseModel.getName() ) );

        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(pconf);
        CompositeKnowledgeBuilder ckbuilder = kbuilder.batch();

        Set<String> includes = kBaseModel.getIncludes();
        if ( includes != null && !includes.isEmpty() ) {
            for ( String include : includes ) {
                if ( StringUtils.isEmpty( include ) ) {
                    continue;
                }
                InternalKieModule includeModule = kieProject.getKieModuleForKBase( include );
                if ( includeModule == null ) {
                    log.error( "Unable to build KieBase, could not find include: " + include );
                    return null;
                }
                addFiles(ckbuilder,
                        kieProject.getKieBaseModel(include),
                        includeModule);
            }
        }

        addFiles( ckbuilder,
                  kBaseModel,
                  kModule );

        ckbuilder.build();
       
        if ( kbuilder.hasErrors() ) {
            for ( KnowledgeBuilderError error : kbuilder.getErrors() ) {
                messages.addMessage( error );
            }
View Full Code Here

        return Collections.emptyList();
    }

  private KnowledgeBuilder compositeBuild(List<ResourceDescr> resources, Map<Resource, ResourceDescr> resourceMap) throws CoreException {
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(getBuilderConfiguration(resources));
    CompositeKnowledgeBuilder compositeKBuilder = kbuilder.batch();
    for (ResourceDescr resourceDescr : resources) {
      Resource resource = resourceDescr.getContentAsDroolsResource();
      resourceMap.put(resource, resourceDescr);
      compositeKBuilder.add(resource, resourceDescr.getType());
    }
    try {
      compositeKBuilder.build();
    } catch (DecisionTableParseException dtpe) {
      // swallow
    }
    return kbuilder;
  }
View Full Code Here

                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" ) ) {
                            fileCount += AbstractKieModule.addFile( ckbuilder,
                                                                    newKM,
                                                                    resourceName ) ? 1 : 0;
                        }
                    }
                }
                if( fileCount > 0 ) {
                    ckbuilder.build();
                }
            }
        }

        for (String kbaseToRemove : kbasesToRemove) {
View Full Code Here

TOP

Related Classes of org.kie.internal.builder.CompositeKnowledgeBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.