use of org.kie.pmml.commons.model.KiePMMLFactoryModel in project drools by kiegroup.
the class PMMLCompilerImpl method getKiePMMLModelsWithSources.
@Override
public List<KiePMMLModel> getKiePMMLModelsWithSources(final String factoryClassName, final String packageName, final InputStream inputStream, final String fileName, final HasClassLoader hasClassloader) {
logger.trace("getModels {} {}", inputStream, hasClassloader);
try {
PMML commonPMMLModel = KiePMMLUtil.load(inputStream, fileName);
Set<String> expectedClasses = commonPMMLModel.getModels().stream().map(model -> {
String modelPackageName = getSanitizedPackageName(String.format(PACKAGE_CLASS_TEMPLATE, packageName, model.getModelName()));
return modelPackageName + "." + getSanitizedClassName(model.getModelName());
}).collect(Collectors.toSet());
final List<KiePMMLModel> toReturn = getModelsWithSources(packageName, commonPMMLModel, hasClassloader);
final Set<String> generatedClasses = new HashSet<>();
Map<String, Boolean> expectedClassModelTypeMap = expectedClasses.stream().collect(Collectors.toMap(expectedClass -> expectedClass, expectedClass -> {
HasSourcesMap retrieved = getHasSourceMap(toReturn, expectedClass);
generatedClasses.addAll(retrieved.getSourcesMap().keySet());
return retrieved.isInterpreted();
}));
if (!generatedClasses.containsAll(expectedClasses)) {
expectedClasses.removeAll(generatedClasses);
String missingClasses = String.join(", ", expectedClasses);
throw new KiePMMLException("Expected generated class " + missingClasses + " not found");
}
Map<String, String> factorySourceMap = getFactorySourceCode(factoryClassName, packageName, expectedClassModelTypeMap);
KiePMMLFactoryModel kiePMMLFactoryModel = new KiePMMLFactoryModel(factoryClassName, packageName, factorySourceMap);
toReturn.add(kiePMMLFactoryModel);
return toReturn;
} catch (KiePMMLInternalException e) {
throw new KiePMMLException("KiePMMLInternalException", e);
} catch (KiePMMLException e) {
throw e;
} catch (Exception e) {
throw new ExternalException("ExternalException", e);
}
}
Aggregations