@Override protected TypedValue transformQueryResultIntoTypedValue(HistoricDetail queryResult) { if (!(queryResult instanceof HistoricVariableUpdate)) { throw new InvalidRequestException(Status.BAD_REQUEST, "Historic detail with Id '" + getId() + "' is not a variable update."); } HistoricVariableUpdate update = (HistoricVariableUpdate) queryResult; return update.getTypedValue(); }
@Override protected TypedValue transformQueryResultIntoTypedValue(HistoricDetail queryResult) { if (!(queryResult instanceof HistoricVariableUpdate)) { throw new InvalidRequestException(Status.BAD_REQUEST, "Historic detail with Id '" + getId() + "' is not a variable update."); } HistoricVariableUpdate update = (HistoricVariableUpdate) queryResult; return update.getTypedValue(); }
@Test public void testGetQueryWhereFileWasDeleted() { doThrow(new IllegalArgumentException("Parameter 'filename' is null")).when(historicUpdateMock).getTypedValue(); // GET expect() .statusCode(Status.OK.getStatusCode()) .when() .get(HISTORIC_DETAIL_RESOURCE_URL); verify(mockedQuery).list(); verify(mockedQuery).disableBinaryFetching(); verifyNoMoreInteractions(mockedQuery); }
@Test public void testQueryWhenFileWasDeleted() { doThrow(new IllegalArgumentException("Parameter 'filename' is null")).when(historicUpdateMock).getTypedValue(); given() .then() .expect() .statusCode(Status.OK.getStatusCode()) .contentType(MediaType.APPLICATION_JSON) .when() .get(OPTIMIZE_VARIABLE_UPDATE_PATH); verify(mockedOptimizeService).getHistoricVariableUpdates(null, null, Integer.MAX_VALUE); verifyNoMoreInteractions(mockedOptimizeService); } }
@Test public void testPostQueryWhereFileWasDeleted() { doThrow(new IllegalArgumentException("Parameter 'filename' is null")).when(historicUpdateMock).getTypedValue(); given() .contentType(POST_JSON_CONTENT_TYPE) .header("accept", MediaType.APPLICATION_JSON) .body(Collections.emptyMap()) .expect() .statusCode(Status.OK.getStatusCode()) .when() .post(HISTORIC_DETAIL_RESOURCE_URL); verify(mockedQuery).list(); verify(mockedQuery).disableBinaryFetching(); verifyNoMoreInteractions(mockedQuery); }
when(mockVariable.getTypedValue()).thenReturn(typedValue); when(mockVariable.getProcessDefinitionKey()).thenReturn(processDefinitionKey); when(mockVariable.getProcessDefinitionId()).thenReturn(processDefinitionId);
@Test public void getHistoricVariableByteArrayUpdates() { // given BpmnModelInstance simpleDefinition = Bpmn.createExecutableProcess("process") .startEvent() .endEvent() .done(); testHelper.deploy(simpleDefinition); List<String> serializable = new ArrayList<String>(); serializable.add("one"); serializable.add("two"); serializable.add("three"); Map<String, Object> variables = new HashMap<String, Object>(); variables.put("var", serializable); runtimeService.startProcessInstanceByKey("process", variables); runtimeService.startProcessInstanceByKey("process", variables); runtimeService.startProcessInstanceByKey("process", variables); runtimeService.startProcessInstanceByKey("process", variables); // when List<HistoricVariableUpdate> historicVariableUpdates = optimizeService.getHistoricVariableUpdates(new Date(1L), null, 10); // then assertThat(historicVariableUpdates.size(), is(4)); for (HistoricVariableUpdate variableUpdate : historicVariableUpdates) { ObjectValue typedValue = (ObjectValue) variableUpdate.getTypedValue(); assertThat(typedValue.isDeserialized(), is(false)); assertThat(typedValue.getValueSerialized(), notNullValue()); } }
@Ignore @Test public void testHistoryServiceEngineAccess_HistoricDetailBinaryFile() { HistoricDetailQuery query = mock(HistoricDetailQuery.class); HistoricVariableUpdate instance = mock(HistoricVariableUpdate.class); String filename = "test.txt"; byte[] byteContent = "test".getBytes(); String encoding = "UTF-8"; FileValue variableValue = Variables.fileValue(filename).file(byteContent).mimeType(ContentType.TEXT.toString()).encoding(encoding).create(); when(instance.getTypedValue()).thenReturn(variableValue); when(query.singleResult()).thenReturn(instance); when(mockHistoryService.createHistoricDetailQuery()).thenReturn(query); given() .pathParam("name", EXAMPLE_ENGINE_NAME) .then().expect() .statusCode(Status.OK.getStatusCode()) . body(is(equalTo(new String(byteContent)))) .and() .header("Content-Disposition", "attachment; filename="+filename) .contentType(CoreMatchers.<String>either(equalTo(ContentType.TEXT.toString() + ";charset=UTF-8")).or(equalTo(ContentType.TEXT.toString() + " ;charset=UTF-8"))) .when() .get(HISTORY_BINARY_DETAIL_URL); verify(mockHistoryService).createHistoricDetailQuery(); verifyZeroInteractions(processEngine); }
protected static void fromHistoricVariableUpdate(HistoricVariableUpdateDto dto, HistoricVariableUpdate historicVariableUpdate) { dto.revision = historicVariableUpdate.getRevision(); dto.variableName = historicVariableUpdate.getVariableName(); dto.variableInstanceId = historicVariableUpdate.getVariableInstanceId(); if (historicVariableUpdate.getErrorMessage() == null) { try { VariableValueDto variableValueDto = VariableValueDto.fromTypedValue(historicVariableUpdate.getTypedValue()); dto.value = variableValueDto.getValue(); dto.variableType = variableValueDto.getType(); dto.valueInfo = variableValueDto.getValueInfo(); } catch (RuntimeException e) { dto.errorMessage = e.getMessage(); dto.variableType = VariableValueDto.toRestApiTypeName(historicVariableUpdate.getTypeName()); } } else { dto.errorMessage = historicVariableUpdate.getErrorMessage(); dto.variableType = VariableValueDto.toRestApiTypeName(historicVariableUpdate.getTypeName()); } }
protected static void fromHistoricVariableUpdate(HistoricVariableUpdateDto dto, HistoricVariableUpdate historicVariableUpdate) { dto.revision = historicVariableUpdate.getRevision(); dto.variableName = historicVariableUpdate.getVariableName(); dto.variableInstanceId = historicVariableUpdate.getVariableInstanceId(); if (historicVariableUpdate.getErrorMessage() == null) { try { VariableValueDto variableValueDto = VariableValueDto.fromTypedValue(historicVariableUpdate.getTypedValue()); dto.value = variableValueDto.getValue(); dto.variableType = variableValueDto.getType(); dto.valueInfo = variableValueDto.getValueInfo(); } catch (RuntimeException e) { dto.errorMessage = e.getMessage(); dto.variableType = VariableValueDto.toRestApiTypeName(historicVariableUpdate.getTypeName()); } } else { dto.errorMessage = historicVariableUpdate.getErrorMessage(); dto.variableType = VariableValueDto.toRestApiTypeName(historicVariableUpdate.getTypeName()); } }
protected VariableMap collectInitialVariables(CommandContext commandContext, HistoricProcessInstance processInstance) { HistoryService historyService = commandContext.getProcessEngineConfiguration().getHistoryService(); HistoricActivityInstance startActivityInstance = resolveStartActivityInstance(processInstance); HistoricDetailQueryImpl query = (HistoricDetailQueryImpl) historyService.createHistoricDetailQuery() .variableUpdates() .executionId(processInstance.getId()) .activityInstanceId(startActivityInstance.getId()); List<HistoricDetail> historicDetails = query .sequenceCounter(1) .list(); VariableMap variables = new VariableMapImpl(); for (HistoricDetail detail : historicDetails) { HistoricVariableUpdate variableUpdate = (HistoricVariableUpdate) detail; variables.putValueTyped(variableUpdate.getVariableName(), variableUpdate.getTypedValue()); } return variables; }
protected VariableMap collectInitialVariables(CommandContext commandContext, HistoricProcessInstance processInstance) { HistoryService historyService = commandContext.getProcessEngineConfiguration().getHistoryService(); HistoricActivityInstance startActivityInstance = resolveStartActivityInstance(processInstance); HistoricDetailQueryImpl query = (HistoricDetailQueryImpl) historyService.createHistoricDetailQuery() .variableUpdates() .executionId(processInstance.getId()) .activityInstanceId(startActivityInstance.getId()); List<HistoricDetail> historicDetails = query .sequenceCounter(1) .list(); VariableMap variables = new VariableMapImpl(); for (HistoricDetail detail : historicDetails) { HistoricVariableUpdate variableUpdate = (HistoricVariableUpdate) detail; variables.putValueTyped(variableUpdate.getVariableName(), variableUpdate.getTypedValue()); } return variables; }
assertNull(variableUpdate.getErrorMessage()); ObjectValue typedValue = (ObjectValue) variableUpdate.getTypedValue(); assertNotNull(typedValue); assertFalse(typedValue.isDeserialized());
@Override protected TypedValue transformQueryResultIntoTypedValue(HistoricDetail queryResult) { if (!(queryResult instanceof HistoricVariableUpdate)) { throw new InvalidRequestException(Status.BAD_REQUEST, "Historic detail with Id '" + getId() + "' is not a variable update."); } HistoricVariableUpdate update = (HistoricVariableUpdate) queryResult; return update.getTypedValue(); }
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) public void testImplicitVariableUpdateAndScopeDestroyedInOneTransaction() { deployment(Bpmn.createExecutableProcess("process1") .startEvent("start") .serviceTask("task1").camundaExpression("${var.setValue(\"newValue\")}") .endEvent("end") .done()); processEngine.getRuntimeService().startProcessInstanceByKey("process1", Variables.createVariables().putValue("var", new CustomVar("initialValue"))); final HistoricVariableInstance historicVariableInstance = processEngine.getHistoryService().createHistoricVariableInstanceQuery().list().get(0); CustomVar var = (CustomVar) historicVariableInstance.getTypedValue().getValue(); assertEquals("newValue", var.getValue()); final List<HistoricDetail> historicDetails = processEngine.getHistoryService().createHistoricDetailQuery().orderPartiallyByOccurrence().desc().list(); HistoricDetail historicDetail = historicDetails.get(0); final CustomVar typedValue = (CustomVar) ((HistoricVariableUpdate) historicDetail).getTypedValue().getValue(); assertEquals("newValue", typedValue.getValue()); }
FileValue typedValue = (FileValue) fileVariableInstance.getTypedValue(); assertNull(typedValue.getValue());
protected static void fromHistoricVariableUpdate(HistoricVariableUpdateDto dto, HistoricVariableUpdate historicVariableUpdate) { dto.revision = historicVariableUpdate.getRevision(); dto.variableName = historicVariableUpdate.getVariableName(); dto.variableInstanceId = historicVariableUpdate.getVariableInstanceId(); if (historicVariableUpdate.getErrorMessage() == null) { try { VariableValueDto variableValueDto = VariableValueDto.fromTypedValue(historicVariableUpdate.getTypedValue()); dto.value = variableValueDto.getValue(); dto.variableType = variableValueDto.getType(); dto.valueInfo = variableValueDto.getValueInfo(); } catch (RuntimeException e) { dto.errorMessage = e.getMessage(); dto.variableType = VariableValueDto.toRestApiTypeName(historicVariableUpdate.getTypeName()); } } else { dto.errorMessage = historicVariableUpdate.getErrorMessage(); dto.variableType = VariableValueDto.toRestApiTypeName(historicVariableUpdate.getTypeName()); } }
protected VariableMap collectInitialVariables(CommandContext commandContext, HistoricProcessInstance processInstance) { HistoryService historyService = commandContext.getProcessEngineConfiguration().getHistoryService(); HistoricActivityInstance startActivityInstance = resolveStartActivityInstance(processInstance); HistoricDetailQueryImpl query = (HistoricDetailQueryImpl) historyService.createHistoricDetailQuery() .variableUpdates() .executionId(processInstance.getId()) .activityInstanceId(startActivityInstance.getId()); List<HistoricDetail> historicDetails = query .sequenceCounter(1) .list(); VariableMap variables = new VariableMapImpl(); for (HistoricDetail detail : historicDetails) { HistoricVariableUpdate variableUpdate = (HistoricVariableUpdate) detail; variables.putValueTyped(variableUpdate.getVariableName(), variableUpdate.getTypedValue()); } return variables; }
assertNull(variableUpdate.getErrorMessage()); ObjectValue typedValue = (ObjectValue) variableUpdate.getTypedValue(); assertNotNull(typedValue); assertFalse(typedValue.isDeserialized());
@RequiredHistoryLevel(ProcessEngineConfiguration.HISTORY_FULL) public void testImplicitVariableUpdateAndScopeDestroyedInOneTransaction() { deployment(Bpmn.createExecutableProcess("process1") .startEvent("start") .serviceTask("task1").camundaExpression("${var.setValue(\"newValue\")}") .endEvent("end") .done()); processEngine.getRuntimeService().startProcessInstanceByKey("process1", Variables.createVariables().putValue("var", new CustomVar("initialValue"))); final HistoricVariableInstance historicVariableInstance = processEngine.getHistoryService().createHistoricVariableInstanceQuery().list().get(0); CustomVar var = (CustomVar) historicVariableInstance.getTypedValue().getValue(); assertEquals("newValue", var.getValue()); final List<HistoricDetail> historicDetails = processEngine.getHistoryService().createHistoricDetailQuery().orderPartiallyByOccurrence().desc().list(); HistoricDetail historicDetail = historicDetails.get(0); final CustomVar typedValue = (CustomVar) ((HistoricVariableUpdate) historicDetail).getTypedValue().getValue(); assertEquals("newValue", typedValue.getValue()); }