use of org.kie.internal.builder.DecisionTableInputType in project jbpm by kiegroup.
the class SimpleRuntimeEnvironment method addAsset.
/**
* Adds given asset to knowledge builder to produce KieBase
* @param resource asset to be added
* @param type type of the asset
*/
public void addAsset(Resource resource, ResourceType type) {
/**
* The code below (CSV/XLS) was added because of timelines related to switchyard/fuse.
*
* However, it is an ugly hack: As soon as is possible, the code below should be removed or refactored.
* - an "addAsset(Resource, ResourceType, ResourceConfiguration)" method should be added to this implementation
* - or the kbuilder code should be refactored so that there are two ResourceTypes: CSV and XLS
*
* (refactoring the kbuilder code is probably a better idea.)
*/
boolean replaced = false;
if (resource.getSourcePath() != null) {
String path = resource.getSourcePath();
String typeStr = null;
if (path.toLowerCase().endsWith(".csv")) {
typeStr = DecisionTableInputType.CSV.toString();
} else if (path.toLowerCase().endsWith(".xls")) {
typeStr = DecisionTableInputType.XLS.toString();
}
if (typeStr != null) {
String worksheetName = null;
boolean replaceConfig = true;
ResourceConfiguration config = resource.getConfiguration();
if (config != null && config instanceof DecisionTableConfiguration) {
DecisionTableInputType realType = DecisionTableInputType.valueOf(typeStr);
if (((DecisionTableConfiguration) config).getInputType().equals(realType)) {
replaceConfig = false;
} else {
worksheetName = ((DecisionTableConfiguration) config).getWorksheetName();
}
}
if (replaceConfig) {
Properties prop = new Properties();
prop.setProperty(ResourceTypeImpl.KIE_RESOURCE_CONF_CLASS, DecisionTableConfigurationImpl.class.getName());
prop.setProperty(DecisionTableConfigurationImpl.DROOLS_DT_TYPE, typeStr);
if (worksheetName != null) {
prop.setProperty(DecisionTableConfigurationImpl.DROOLS_DT_WORKSHEET, worksheetName);
}
ResourceConfiguration conf = ResourceTypeImpl.fromProperties(prop);
this.kbuilder.add(resource, type, conf);
replaced = true;
}
}
}
if (!replaced) {
this.kbuilder.add(resource, type);
}
if (this.kbuilder.hasErrors()) {
StringBuffer errorMessage = new StringBuffer();
for (KnowledgeBuilderError error : kbuilder.getErrors()) {
errorMessage.append(error.getMessage() + ",");
}
this.kbuilder.undo();
throw new IllegalArgumentException("Cannot add asset: " + errorMessage.toString());
}
}
Aggregations