Search in sources :

Example 51 with PMMLRequestData

use of org.kie.api.pmml.PMMLRequestData in project drools by kiegroup.

the class PMMLCommandExecutorImpl method getCleanedRequestData.

/**
 * Return a <b>new</b> <code>PMMLRequestData</code> with the values of the original <code>PMMLRequestData</code> restored to their actual type.
 *
 * Needed because <code>JSONMarshallerPMMLParamInfo</code> convert all of them to <code>String</code>
 *
 * @see <a href="https://github.com/kiegroup/droolsjbpm-integration/blob/master/kie-server-parent/kie-server-api/src/main/java/org/kie/server/api/marshalling/json/JSONMarshallerPMMLParamInfo.java#L67">JSONMarshallerPMMLParamInfo.PMMLParamSerializer.serialize(ParameterInfo, JsonGenerator, SerializerProvider)</a>
 * @param source
 * @return
 */
@SuppressWarnings("rawtype")
protected PMMLRequestData getCleanedRequestData(PMMLRequestData source) {
    final PMMLRequestData toReturn = new PMMLRequestData();
    toReturn.setSource(source.getSource());
    toReturn.setCorrelationId(source.getCorrelationId());
    toReturn.setModelName(source.getModelName());
    source.getRequestParams().forEach(parameterInfo -> {
        Object value = ConverterTypeUtil.convert(parameterInfo.getType(), parameterInfo.getValue());
        ParameterInfo<?> toAdd = new ParameterInfo(parameterInfo.getCorrelationId(), parameterInfo.getName(), parameterInfo.getType(), value);
        toReturn.addRequestParam(toAdd);
    });
    return toReturn;
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) ParameterInfo(org.kie.api.pmml.ParameterInfo)

Example 52 with PMMLRequestData

use of org.kie.api.pmml.PMMLRequestData in project drools by kiegroup.

the class PMMLCommandExecutorImplTest method validateNoModelName.

@Test(expected = KiePMMLException.class)
public void validateNoModelName() {
    PMMLRequestData pmmlRequestData = new PMMLRequestData();
    pmmlRequestData.setSource("source");
    PMMLCommandExecutorImpl cmdExecutor = new PMMLCommandExecutorImpl();
    cmdExecutor.validate(pmmlRequestData);
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) Test(org.junit.Test)

Example 53 with PMMLRequestData

use of org.kie.api.pmml.PMMLRequestData in project drools by kiegroup.

the class PMMLCommandExecutorImplTest method getPMMLRequestData.

@SuppressWarnings("rawtype")
private PMMLRequestData getPMMLRequestData() {
    PMMLRequestData toReturn = new PMMLRequestData();
    String correlationId = "correlationId";
    toReturn.setSource("source");
    toReturn.setCorrelationId(correlationId);
    toReturn.setModelName("modelName");
    List<Class> classList = Arrays.asList(Integer.class, Double.class, Boolean.class, String.class);
    classList.forEach(aClass -> {
        Object value = getRandomValue(aClass.getSimpleName()).toString();
        ParameterInfo<?> toAdd = new ParameterInfo(correlationId, RandomStringUtils.random(4, true, false), aClass, value);
        toReturn.addRequestParam(toAdd);
    });
    return toReturn;
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) ParameterInfo(org.kie.api.pmml.ParameterInfo)

Example 54 with PMMLRequestData

use of org.kie.api.pmml.PMMLRequestData in project drools by kiegroup.

the class PMMLCommandExecutorImplTest method getCleanedRequestData.

@Test()
public void getCleanedRequestData() {
    PMMLRequestData pmmlRequestData = getPMMLRequestData();
    PMMLCommandExecutorImpl cmdExecutor = new PMMLCommandExecutorImpl();
    PMMLRequestData retrieved = cmdExecutor.getCleanedRequestData(pmmlRequestData);
    assertNotNull(retrieved);
    assertEquals(pmmlRequestData.getSource(), retrieved.getSource());
    assertEquals(pmmlRequestData.getCorrelationId(), retrieved.getCorrelationId());
    assertEquals(pmmlRequestData.getModelName(), retrieved.getModelName());
    Map<String, ParameterInfo> requestParams = retrieved.getMappedRequestParams();
    pmmlRequestData.getRequestParams().forEach(parameterInfo -> {
        assertTrue(requestParams.containsKey(parameterInfo.getName()));
        ParameterInfo cleaned = requestParams.get(parameterInfo.getName());
        assertEquals(parameterInfo.getName(), cleaned.getName());
        assertEquals(parameterInfo.getCorrelationId(), cleaned.getCorrelationId());
        assertEquals(parameterInfo.getType(), cleaned.getType());
        assertEquals(parameterInfo.getValue(), cleaned.getValue().toString());
        assertEquals(cleaned.getType(), cleaned.getValue().getClass());
    });
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) ParameterInfo(org.kie.api.pmml.ParameterInfo) Test(org.junit.Test)

Example 55 with PMMLRequestData

use of org.kie.api.pmml.PMMLRequestData in project drools by kiegroup.

the class PMMLCommandExecutorImplTest method validateNoSource.

@Test(expected = KiePMMLException.class)
public void validateNoSource() {
    PMMLRequestData pmmlRequestData = new PMMLRequestData();
    pmmlRequestData.setModelName("modelName");
    PMMLCommandExecutorImpl cmdExecutor = new PMMLCommandExecutorImpl();
    cmdExecutor.validate(pmmlRequestData);
}
Also used : PMMLRequestData(org.kie.api.pmml.PMMLRequestData) Test(org.junit.Test)

Aggregations

PMMLRequestData (org.kie.api.pmml.PMMLRequestData)68 Test (org.junit.Test)53 PMML4Result (org.kie.api.pmml.PMML4Result)30 DroolsAbstractPMMLTest (org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)28 InternalRuleUnitExecutor (org.drools.core.impl.InternalRuleUnitExecutor)17 RuleUnitExecutor (org.kie.api.runtime.rule.RuleUnitExecutor)17 KieBase (org.kie.api.KieBase)16 KiePMMLMiningField (org.kie.pmml.commons.model.KiePMMLMiningField)16 ParameterInfo (org.kie.api.pmml.ParameterInfo)14 KiePMMLInterval (org.kie.pmml.commons.model.expressions.KiePMMLInterval)14 Map (java.util.Map)13 PMMLExecutor (org.kie.pmml.pmml_4_2.PMMLExecutor)11 ArrayList (java.util.ArrayList)9 Arrays (java.util.Arrays)9 Collections (java.util.Collections)9 List (java.util.List)9 Optional (java.util.Optional)9 IntStream (java.util.stream.IntStream)9 Assert.assertTrue (org.junit.Assert.assertTrue)9 DATA_TYPE (org.kie.pmml.api.enums.DATA_TYPE)9