Search in sources :

Example 46 with Variable

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();
}
Also used : Variable(org.flyte.api.v1.Variable) Var(com.google.errorprone.annotations.Var) Literal(org.flyte.api.v1.Literal) LiteralType(org.flyte.api.v1.LiteralType) HashMap(java.util.HashMap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap)

Example 47 with Variable

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)));
}
Also used : Variable(org.flyte.api.v1.Variable) Test(org.junit.jupiter.api.Test)

Example 48 with Variable

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;
}
Also used : Variable(org.ow2.petals.components.flowable.generic._1.Variable) GetProcessInstancesResponse(org.ow2.petals.components.flowable.generic._1.GetProcessInstancesResponse) ProcessDefinitionQuery(org.flowable.engine.repository.ProcessDefinitionQuery) ProcessDefinition(org.flowable.engine.repository.ProcessDefinition) Variables(org.ow2.petals.components.flowable.generic._1.Variables) ProcessInstances(org.ow2.petals.components.flowable.generic._1.ProcessInstances) GetProcessInstances(org.ow2.petals.components.flowable.generic._1.GetProcessInstances) ProcessInstanceQuery(org.flowable.engine.runtime.ProcessInstanceQuery) HistoricProcessInstanceQuery(org.flowable.engine.history.HistoricProcessInstanceQuery) ProcessInstance(org.flowable.engine.runtime.ProcessInstance) HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance)

Example 49 with Variable

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;
}
Also used : Variables(org.ow2.petals.components.flowable.generic._1.Variables) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) Variable(org.ow2.petals.components.flowable.generic._1.Variable) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date)

Example 50 with Variable

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);
}
Also used : GetProcessInstances(org.ow2.petals.components.flowable.generic._1.GetProcessInstances) Variable(org.ow2.petals.components.flowable.generic._1.Variable) RequestToProviderMessage(org.ow2.petals.component.framework.junit.impl.message.RequestToProviderMessage) LogRecord(java.util.logging.LogRecord) GetProcessInstancesResponse(org.ow2.petals.components.flowable.generic._1.GetProcessInstancesResponse) ProcessInstance(org.ow2.petals.components.flowable.generic._1.ProcessInstance) List(java.util.List) ResponseMessage(org.ow2.petals.component.framework.junit.ResponseMessage) FlowLogData(org.ow2.petals.commons.log.FlowLogData)

Aggregations

Variable (ucar.nc2.Variable)103 IOException (java.io.IOException)51 Attribute (ucar.nc2.Attribute)34 Variable (org.jpl7.Variable)33 Query (org.jpl7.Query)32 Array (ucar.ma2.Array)30 Term (org.jpl7.Term)29 ArrayList (java.util.ArrayList)22 Dimension (ucar.nc2.Dimension)22 NetcdfFile (ucar.nc2.NetcdfFile)20 Compound (org.jpl7.Compound)19 Map (java.util.Map)18 InvalidRangeException (ucar.ma2.InvalidRangeException)16 Atom (org.jpl7.Atom)15 ArrayDouble (ucar.ma2.ArrayDouble)15 File (java.io.File)10 List (java.util.List)10 ArrayFloat (ucar.ma2.ArrayFloat)10 WritableRaster (java.awt.image.WritableRaster)8 HashMap (java.util.HashMap)8