use of org.kie.pmml.api.exceptions.KiePMMLException in project drools by kiegroup.
the class KiePMMLTreeModelFactory method getKiePMMLTreeModel.
public static KiePMMLTreeModel getKiePMMLTreeModel(final DroolsCompilationDTO<TreeModel> compilationDTO) throws IllegalAccessException, InstantiationException {
logger.trace("getKiePMMLTreeModel {} {}", compilationDTO.getPackageName(), compilationDTO.getModel());
Map<String, String> sourcesMap = getKiePMMLTreeModelSourcesMap(compilationDTO);
try {
Class<?> kiePMMLTreeModelClass = compilationDTO.compileAndLoadClass(sourcesMap);
return (KiePMMLTreeModel) kiePMMLTreeModelClass.newInstance();
} catch (Exception e) {
throw new KiePMMLException(e);
}
}
use of org.kie.pmml.api.exceptions.KiePMMLException in project drools by kiegroup.
the class KiePMMLTreeModelFactory method getKiePMMLTreeModelSourcesMap.
public static Map<String, String> getKiePMMLTreeModelSourcesMap(final DroolsCompilationDTO<TreeModel> compilationDTO) {
logger.trace("getKiePMMLTreeModelSourcesMap {} {} {}", compilationDTO.getFields(), compilationDTO.getModel(), compilationDTO.getPackageName());
CompilationUnit cloneCU = getKiePMMLModelCompilationUnit(compilationDTO, KIE_PMML_TREE_MODEL_TEMPLATE_JAVA, KIE_PMML_TREE_MODEL_TEMPLATE);
String className = compilationDTO.getSimpleClassName();
ClassOrInterfaceDeclaration modelTemplate = cloneCU.getClassByName(className).orElseThrow(() -> new KiePMMLException(MAIN_CLASS_NOT_FOUND + ": " + className));
setConstructor(compilationDTO, modelTemplate);
Map<String, String> toReturn = new HashMap<>();
String fullClassName = compilationDTO.getPackageCanonicalClassName();
toReturn.put(fullClassName, cloneCU.toString());
return toReturn;
}
use of org.kie.pmml.api.exceptions.KiePMMLException in project drools by kiegroup.
the class KiePMMLMiningModelFactory method getKiePMMLMiningModel.
public static KiePMMLMiningModel getKiePMMLMiningModel(final MiningModelCompilationDTO compilationDTO) {
logger.debug("getKiePMMLMiningModel {}", compilationDTO.getModel());
final List<KiePMMLModel> nestedModels = new ArrayList<>();
Map<String, String> sourcesMap = getKiePMMLMiningModelSourcesMapCompiled(compilationDTO, nestedModels);
try {
Class<?> kiePMMLMiningModel = compilationDTO.compileAndLoadClass(sourcesMap);
return (KiePMMLMiningModel) kiePMMLMiningModel.newInstance();
} catch (Exception e) {
throw new KiePMMLException(e);
}
}
use of org.kie.pmml.api.exceptions.KiePMMLException in project drools by kiegroup.
the class KiePMMLSegmentationFactory method getSegmentationSourcesMapCommon.
static Map<String, String> getSegmentationSourcesMapCommon(final MiningModelCompilationDTO compilationDTO, final Map<String, String> toReturn) {
logger.debug("getSegmentationSourcesMapCommon {}", compilationDTO.getSegmentation());
String className = compilationDTO.getSegmentationClassName();
CompilationUnit cloneCU = JavaParserUtils.getKiePMMLModelCompilationUnit(className, compilationDTO.getSegmentationPackageName(), KIE_PMML_SEGMENTATION_TEMPLATE_JAVA, KIE_PMML_SEGMENTATION_TEMPLATE);
ClassOrInterfaceDeclaration segmentationTemplate = cloneCU.getClassByName(className).orElseThrow(() -> new KiePMMLException(MAIN_CLASS_NOT_FOUND + ": " + className));
final ConstructorDeclaration constructorDeclaration = segmentationTemplate.getDefaultConstructor().orElseThrow(() -> new KiePMMLInternalException(String.format(MISSING_DEFAULT_CONSTRUCTOR, compilationDTO.getSegmentationName())));
// Avoid stream/map to preserve insertion order and then execution order
final List<String> segmentsClasses = new ArrayList<>();
if (compilationDTO.getSegmentation().getSegments() != null) {
for (Segment segment : compilationDTO.getSegmentation().getSegments()) {
segmentsClasses.add(getSanitizedPackageName(compilationDTO.getSegmentationPackageName() + "." + segment.getId()) + "." + getSanitizedClassName(segment.getId()));
}
}
if (!toReturn.keySet().containsAll(segmentsClasses)) {
String missingClasses = String.join(", ", segmentsClasses);
throw new KiePMMLException("Expected generated class " + missingClasses + " not found");
}
setConstructor(className, compilationDTO.getSegmentationName(), constructorDeclaration, MULTIPLE_MODEL_METHOD.byName(compilationDTO.getSegmentation().getMultipleModelMethod().value()), segmentsClasses);
toReturn.put(getFullClassName(cloneCU), cloneCU.toString());
return toReturn;
}
use of org.kie.pmml.api.exceptions.KiePMMLException in project drools by kiegroup.
the class KiePMMLSegmentFactory method getSegmentSourcesMapCompiled.
public static Map<String, String> getSegmentSourcesMapCompiled(final SegmentCompilationDTO segmentCompilationDTO, final List<KiePMMLModel> nestedModels) {
logger.debug(GET_SEGMENT, segmentCompilationDTO.getSegment());
final KiePMMLModel nestedModel = getFromCommonDataAndTransformationDictionaryAndModelWithSourcesCompiled(segmentCompilationDTO).orElseThrow(() -> new KiePMMLException("Failed to get the KiePMMLModel for segment " + segmentCompilationDTO.getModel().getModelName()));
final Map<String, String> toReturn = getSegmentSourcesMapCommon(segmentCompilationDTO, nestedModels, nestedModel);
segmentCompilationDTO.addFields(getFieldsFromModel(segmentCompilationDTO.getModel()));
return toReturn;
}
Aggregations