Search in sources :

Example 1 with ResourceConfiguration

use of org.kie.api.io.ResourceConfiguration in project drools by kiegroup.

the class KnowledgeBuilderImpl method add.

public void add(Resource resource, ResourceType type) {
    ResourceConfiguration resourceConfiguration = resource instanceof BaseResource ? resource.getConfiguration() : null;
    add(resource, type, resourceConfiguration);
}
Also used : BaseResource(org.drools.core.io.impl.BaseResource) ResourceConfiguration(org.kie.api.io.ResourceConfiguration)

Example 2 with ResourceConfiguration

use of org.kie.api.io.ResourceConfiguration in project drools by kiegroup.

the class AbstractKieModule method addResourceToCompiler.

public final boolean addResourceToCompiler(CompositeKnowledgeBuilder ckbuilder, KieBaseModel kieBaseModel, String fileName, ResourceChangeSet rcs) {
    ResourceConfiguration conf = getResourceConfiguration(fileName);
    Resource resource = getResource(fileName);
    if (resource != null) {
        ResourceType resourceType = conf instanceof ResourceConfigurationImpl && ((ResourceConfigurationImpl) conf).getResourceType() != null ? ((ResourceConfigurationImpl) conf).getResourceType() : ResourceType.determineResourceType(fileName);
        if (resourceType == ResourceType.DTABLE && conf instanceof DecisionTableConfiguration) {
            for (RuleTemplateModel template : kieBaseModel.getRuleTemplates()) {
                if (template.getDtable().equals(fileName)) {
                    Resource templateResource = getResource(template.getTemplate());
                    if (templateResource != null) {
                        ((DecisionTableConfiguration) conf).addRuleTemplateConfiguration(templateResource, template.getRow(), template.getCol());
                    }
                }
            }
        }
        if (conf == null) {
            ckbuilder.add(resource, resourceType, rcs);
        } else {
            ckbuilder.add(resource, resourceType, conf, rcs);
        }
        return true;
    }
    return false;
}
Also used : DecisionTableConfiguration(org.kie.internal.builder.DecisionTableConfiguration) Resource(org.kie.api.io.Resource) ResourceConfigurationImpl(org.drools.core.builder.conf.impl.ResourceConfigurationImpl) ResourceType(org.kie.api.io.ResourceType) RuleTemplateModel(org.kie.api.builder.model.RuleTemplateModel) ResourceConfiguration(org.kie.api.io.ResourceConfiguration)

Example 3 with ResourceConfiguration

use of org.kie.api.io.ResourceConfiguration in project drools by kiegroup.

the class AbstractKieModule method updateResource.

public static boolean updateResource(CompositeKnowledgeBuilder ckbuilder, InternalKieModule kieModule, String resourceName, ResourceChangeSet changes) {
    ResourceConfiguration conf = kieModule.getResourceConfiguration(resourceName);
    Resource resource = kieModule.getResource(resourceName);
    if (resource != null) {
        if (conf == null) {
            ckbuilder.add(resource, ResourceType.determineResourceType(resourceName), changes);
        } else {
            ckbuilder.add(resource, ResourceType.determineResourceType(resourceName), conf, changes);
        }
        return true;
    }
    return false;
}
Also used : Resource(org.kie.api.io.Resource) ResourceConfiguration(org.kie.api.io.ResourceConfiguration)

Example 4 with ResourceConfiguration

use of org.kie.api.io.ResourceConfiguration in project drools by kiegroup.

the class AbstractKieModule method getResourceConfiguration.

public ResourceConfiguration getResourceConfiguration(String fileName) {
    ResourceConfiguration conf = resourceConfigurationCache.get(fileName);
    if (conf != null) {
        return conf;
    }
    if (isAvailable(fileName + ".properties")) {
        // configuration file available
        Properties prop = new Properties();
        try {
            prop.load(new ByteArrayInputStream(getBytes(fileName + ".properties")));
        } catch (IOException e) {
            log.error("Error loading resource configuration from file: " + fileName + ".properties");
        }
        conf = ResourceTypeImpl.fromProperties(prop);
    } else if (ResourceType.DTABLE.matchesExtension(fileName)) {
        int lastDot = fileName.lastIndexOf('.');
        if (lastDot >= 0 && fileName.length() > lastDot + 1) {
            String extension = fileName.substring(lastDot + 1);
            Properties prop = new Properties();
            prop.setProperty(ResourceTypeImpl.KIE_RESOURCE_CONF_CLASS, DecisionTableConfigurationImpl.class.getName());
            prop.setProperty(DecisionTableConfigurationImpl.DROOLS_DT_TYPE, DecisionTableInputType.valueOf(extension.toUpperCase()).toString());
            conf = ResourceTypeImpl.fromProperties(prop);
        }
    }
    resourceConfigurationCache.put(fileName, conf);
    return conf;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IOException(java.io.IOException) Properties(java.util.Properties) ResourceConfiguration(org.kie.api.io.ResourceConfiguration)

Example 5 with ResourceConfiguration

use of org.kie.api.io.ResourceConfiguration in project drools by kiegroup.

the class KieFileSystemImpl method write.

public KieFileSystem write(Resource resource) {
    try {
        String target = resource.getTargetPath() != null ? resource.getTargetPath() : resource.getSourcePath();
        if (target != null) {
            String prefix = resource.getResourceType() == ResourceType.JAVA ? JAVA_ROOT : RESOURCES_ROOT;
            write(prefix + target, readBytesFromInputStream(resource.getInputStream()));
            ResourceConfiguration conf = resource.getConfiguration();
            if (conf != null) {
                Properties prop = ResourceTypeImpl.toProperties(conf);
                ByteArrayOutputStream buff = new ByteArrayOutputStream();
                prop.store(buff, "Configuration properties for resource: " + target);
                write(prefix + target + ".properties", buff.toByteArray());
            }
            return this;
        } else {
            throw new RuntimeException("Resource does not have neither a source nor a target path. Impossible to add it to the bundle. Please set either the source or target name of the resource before adding it." + resource.toString());
        }
    } catch (IOException e) {
        throw new RuntimeException("Unable to write Resource: " + resource.toString(), e);
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Properties(java.util.Properties) ResourceConfiguration(org.kie.api.io.ResourceConfiguration)

Aggregations

ResourceConfiguration (org.kie.api.io.ResourceConfiguration)6 IOException (java.io.IOException)2 Properties (java.util.Properties)2 Resource (org.kie.api.io.Resource)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ResourceConfigurationImpl (org.drools.core.builder.conf.impl.ResourceConfigurationImpl)1 BaseResource (org.drools.core.io.impl.BaseResource)1 InternalResource (org.drools.core.io.internal.InternalResource)1 RuleTemplateModel (org.kie.api.builder.model.RuleTemplateModel)1 ResourceType (org.kie.api.io.ResourceType)1 DecisionTableConfiguration (org.kie.internal.builder.DecisionTableConfiguration)1 Element (org.w3c.dom.Element)1