use of org.flyte.api.v1.Variable in project flytekit-java by flyteorg.
the class SdkTestingExecutor method withFixedInputs.
public <T> SdkTestingExecutor withFixedInputs(SdkType<T> type, T value) {
Map<String, Variable> variableMap = type.getVariableMap();
@Var Builder builder = toBuilder();
for (Map.Entry<String, Literal> entry : type.toLiteralMap(value).entrySet()) {
LiteralType literalType = variableMap.get(entry.getKey()).literalType();
builder = builder.putFixedInput(entry.getKey(), entry.getValue(), literalType);
}
return builder.build();
}
use of org.flyte.api.v1.Variable in project flytekit-java by flyteorg.
the class JacksonSdkTypeTest method testPojoVariableMap.
@Test
public void testPojoVariableMap() {
Variable expected = Variable.builder().description("").literalType(LiteralTypes.INTEGER).build();
Map<String, Variable> variableMap = JacksonSdkType.of(PojoInput.class).getVariableMap();
assertThat(variableMap, equalTo(singletonMap("a", expected)));
}
use of org.flyte.api.v1.Variable in project petals-se-flowable by petalslink.
the class GetProcessInstancesOperation method searchProcessInstances.
/**
* Search process instances that are not ended (in state 'active' or 'suspended').
*/
private GetProcessInstancesResponse searchProcessInstances(final GetProcessInstances incomingObject, final ProcessInstanceState state) throws MessagingException {
final ProcessInstanceQuery processInstanceQuery = this.runtimeService.createProcessInstanceQuery();
if (state == ProcessInstanceState.ACTIVE) {
processInstanceQuery.active();
} else if (state == ProcessInstanceState.SUSPENDED) {
processInstanceQuery.suspended();
} else {
// we search all process instances independently of their state: ACTIVE and SUSPENDED
assert state == null;
}
final String processDefinitionId = incomingObject.getProcessDefinitionIdentifier();
if (processDefinitionId != null && !processDefinitionId.isEmpty()) {
processInstanceQuery.processDefinitionKey(processDefinitionId);
}
final String processInstanceId = incomingObject.getProcessInstanceIdentifier();
if (processInstanceId != null && !processInstanceId.isEmpty()) {
processInstanceQuery.processInstanceId(processInstanceId);
}
final Variables variables = incomingObject.getVariables();
if (variables != null && !variables.getVariable().isEmpty()) {
for (final Variable variable : variables.getVariable()) {
processInstanceQuery.variableValueEquals(variable.getName(), Utils.parseVariableValue(variable));
}
}
processInstanceQuery.includeProcessVariables();
final GetProcessInstancesResponse response = new GetProcessInstancesResponse();
final ProcessInstances responseProcessInstances = new ProcessInstances();
response.setProcessInstances(responseProcessInstances);
final List<ProcessInstance> processInstances = processInstanceQuery.list();
for (final ProcessInstance processInstance : processInstances) {
final org.ow2.petals.components.flowable.generic._1.ProcessInstance responseProcessInstance = new org.ow2.petals.components.flowable.generic._1.ProcessInstance();
responseProcessInstances.getProcessInstance().add(responseProcessInstance);
responseProcessInstance.setProcessInstanceIdentifier(processInstance.getProcessInstanceId());
if (processInstance.isSuspended()) {
responseProcessInstance.setState(ProcessInstanceState.SUSPENDED);
} else if (processInstance.isEnded()) {
responseProcessInstance.setState(ProcessInstanceState.FINISHED);
} else {
responseProcessInstance.setState(ProcessInstanceState.ACTIVE);
}
final ProcessDefinitionQuery processDefQuery = this.repositoryService.createProcessDefinitionQuery().processDefinitionId(processInstance.getProcessDefinitionId());
final ProcessDefinition processDefinition = processDefQuery.singleResult();
responseProcessInstance.setProcessDefinitionIdentifier(processDefinition.getKey());
responseProcessInstance.setVariables(Utils.buildVariables(processInstance.getProcessVariables(), this.log));
}
return response;
}
use of org.flyte.api.v1.Variable in project petals-se-flowable by petalslink.
the class Utils method buildVariables.
public static Variables buildVariables(final Map<String, Object> variables, final Logger logger) {
final Variables resultVariables = new Variables();
for (final Entry<String, Object> taskProcessVariable : variables.entrySet()) {
final Variable resultVariable = new Variable();
resultVariable.setName(taskProcessVariable.getKey());
final Object variableValue = taskProcessVariable.getValue();
if (variableValue instanceof Date) {
final GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime((Date) variableValue);
try {
resultVariable.setValue(DatatypeFactory.newInstance().newXMLGregorianCalendar(calendar).toXMLFormat());
} catch (final DatatypeConfigurationException e) {
logger.log(Level.WARNING, String.format("Error converting date value of variable '%s' into XML. Variable copy skiped !", taskProcessVariable.getKey()), e);
}
} else {
resultVariable.setValue(variableValue != null ? variableValue.toString() : "");
}
resultVariables.getVariable().add(resultVariable);
}
return resultVariables;
}
use of org.flyte.api.v1.Variable in project petals-se-flowable by petalslink.
the class ServiceProviderVacationProcessTest method tryToRetrieveProcessInstance.
/**
* Retrieve a process instance.
*
* @param processInstanceId
* The process instance identifier of the process instance to retrieve
* @param expectedStartDate
* The expected start date of the retrieved process instance.
* @param expectedMotivation
* The expected value of the field 'motivation' of the retrieved process instance.
* @param expectedNumberOfDays
* The expected value of the field 'numberOfDays' of the retrieved process instance.
* @param state
* {@link ProcessInstanceState} of the process instances to retrieve.
* @param processStartedBeginFlowLogData
* The first MONIT trace of the process instance execution.
* @param isRetrievedProcessInstanceExpected
* Expected result: <code>true</code> if a process instance must be retrieved; <code>false</code> if no
* process instance must be retrieved
* @throws JAXBException
* @throws IOException
*/
private final void tryToRetrieveProcessInstance(final String processInstanceId, final GregorianCalendar expectedStartDate, final String expectedMotivation, final int expectedNumberOfDays, final ProcessInstanceState state, final FlowLogData processStartedBeginFlowLogData, final boolean isRetrievedProcessInstanceExpected) throws Exception {
// Try to retrieve the process instance using the integration service
final GetProcessInstances getProcessInstancesReq = new GetProcessInstances();
getProcessInstancesReq.setState(state);
getProcessInstancesReq.setProcessDefinitionIdentifier(BPMN_PROCESS_DEFINITION_KEY);
getProcessInstancesReq.setProcessInstanceIdentifier(processInstanceId);
IN_MEMORY_LOG_HANDLER.clear();
final RequestToProviderMessage request = new RequestToProviderMessage(COMPONENT_UNDER_TEST, NATIVE_PROCESSINSTANCES_SVC_CFG, ITG_OP_GETPROCESSINSTANCES, AbsItfOperation.MEPPatternConstants.IN_OUT.value(), toByteArray(getProcessInstancesReq));
{
final ResponseMessage getProcessInstancesRespMsg = COMPONENT.sendAndGetResponse(request);
assertNotNull("No XML payload in response", getProcessInstancesRespMsg.getPayload());
final Object getProcessInstancesRespObj = UNMARSHALLER.unmarshal(getProcessInstancesRespMsg.getPayload());
assertTrue(getProcessInstancesRespObj instanceof GetProcessInstancesResponse);
final GetProcessInstancesResponse getProcessInstancesResp = (GetProcessInstancesResponse) getProcessInstancesRespObj;
assertNotNull(getProcessInstancesResp.getProcessInstances());
assertNotNull(getProcessInstancesResp.getProcessInstances().getProcessInstance());
if (isRetrievedProcessInstanceExpected) {
assertEquals(1, getProcessInstancesResp.getProcessInstances().getProcessInstance().size());
final ProcessInstance processInstance = getProcessInstancesResp.getProcessInstances().getProcessInstance().get(0);
assertEquals(BPMN_PROCESS_DEFINITION_KEY, processInstance.getProcessDefinitionIdentifier());
assertEquals(processInstanceId, processInstance.getProcessInstanceIdentifier());
assertNotNull(processInstance.getVariables());
final List<Variable> variables = processInstance.getVariables().getVariable();
assertNotNull(variables);
assertTrue(variables.size() > 5);
for (final Variable variable : variables) {
if ("startDate".equals(variable.getName())) {
assertEquals(0, expectedStartDate.compareTo(DatatypeFactory.newInstance().newXMLGregorianCalendar(variable.getValue()).toGregorianCalendar()));
} else if ("vacationMotivation".equals(variable.getName())) {
assertEquals(expectedMotivation, variable.getValue());
} else if ("numberOfDays".equals(variable.getName())) {
assertEquals(String.valueOf(expectedNumberOfDays), variable.getValue());
} else if ("employeeName".equals(variable.getName())) {
assertEquals(BPMN_USER_DEMANDEUR, variable.getValue());
} else if ("petals.flow.instance.id".equals(variable.getName())) {
assertEquals(processStartedBeginFlowLogData.get(FlowLogData.FLOW_INSTANCE_ID_PROPERTY_NAME), variable.getValue());
}
}
} else {
assertEquals(0, getProcessInstancesResp.getProcessInstances().getProcessInstance().size());
}
COMPONENT.sendDoneStatus(getProcessInstancesRespMsg);
}
// Check MONIT traces about the service integration invocation
final List<LogRecord> monitLogs_getProcessInstances = IN_MEMORY_LOG_HANDLER.getAllRecords(Level.MONIT);
assertEquals(2, monitLogs_getProcessInstances.size());
final FlowLogData providerBegin_getProcessInstances = assertMonitProviderBeginLog(ITG_PROCESSINSTANCES_PORT_TYPE, ITG_PROCESSINSTANCES_SERVICE, COMPONENT_UNDER_TEST.getNativeEndpointName(ITG_PROCESSINSTANCES_SERVICE), ITG_OP_GETPROCESSINSTANCES, monitLogs_getProcessInstances.get(0));
assertMonitProviderEndLog(providerBegin_getProcessInstances, monitLogs_getProcessInstances.get(1));
assertMonitFlowInstanceIdNotEquals(processStartedBeginFlowLogData, providerBegin_getProcessInstances);
}
Aggregations