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);
}
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;
}
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;
}
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;
}
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);
}
}
Aggregations