@Test public void executeTask() throws Exception { TranscribeConfiguration configuration = new TranscribeConfiguration(); configuration.setNumberOfFilesForProcessing(10); configuration.setProvider(TranscribeServiceProvider.AWS); Transcribe serviceProviderTranscribe = new Transcribe(); serviceProviderTranscribe.setStatus(TranscribeStatusType.PROCESSING.toString()); Transcribe transcribe1 = new Transcribe(); transcribe1.setProcessId("123"); transcribe1.setStatus(TranscribeStatusType.PROCESSING.toString()); Transcribe transcribe2 = new Transcribe(); transcribe2.setProcessId("456"); transcribe2.setStatus(TranscribeStatusType.PROCESSING.toString()); Transcribe transcribe3 = new Transcribe(); transcribe3.setProcessId("789"); transcribe3.setStatus(TranscribeStatusType.PROCESSING.toString()); Transcribe transcribe4 = new Transcribe(); transcribe4.setProcessId("789"); transcribe4.setStatus(TranscribeStatusType.PROCESSING.toString()); List<Transcribe> transcribes = new ArrayList<>(); transcribes.add(transcribe1); transcribes.add(transcribe2); transcribes.add(transcribe3); transcribes.add(transcribe4); String variableKey = TranscribeBusinessProcessVariableKey.STATUS.toString(); String variableValue = TranscribeStatusType.QUEUED.toString(); ProcessInstance processInstance1 = new ProcessInstanceTest("1", processVariables1); ProcessInstance processInstance2 = new ProcessInstanceTest("2", processVariables2); ProcessInstance processInstance3 = new ProcessInstanceTest("3", processVariables3); ProcessInstance processInstance4 = new ProcessInstanceTest("4", processVariables4); ProcessInstance processInstance5 = new ProcessInstanceTest("5", processVariables5); List<ProcessInstance> processInstances = new ArrayList<>(); processInstances.add(processInstance5); processInstances.add(processInstance2); processInstances.add(processInstance4); processInstances.add(processInstance1); processInstances.add(processInstance3); when(arkCaseTranscribeService.getConfiguration()).thenReturn(configuration); when(arkCaseTranscribeService.getAllByStatus(TranscribeStatusType.PROCESSING.toString())).thenReturn(transcribes); when(activitiRuntimeService.createProcessInstanceQuery()).thenReturn(processInstanceQuery); when(processInstanceQuery.variableValueEqualsIgnoreCase(variableKey, variableValue)).thenReturn(processInstanceQuery); when(processInstanceQuery.includeProcessVariables()).thenReturn(processInstanceQuery); when(processInstanceQuery.list()).thenReturn(processInstances); when(arkCaseTranscribeService.get(105l)).thenReturn(transcribe1); when(arkCaseTranscribeService.getTranscribeServiceFactory()).thenReturn(transcribeServiceFactory); when(transcribeServiceFactory.getService(TranscribeServiceProvider.AWS)).thenReturn(transcribeService); when(transcribeService.create(transcribe1)).thenReturn(serviceProviderTranscribe); doNothing().when(arkCaseTranscribeService).signal(processInstance1, TranscribeStatusType.PROCESSING.toString(), TranscribeActionType.PROCESSING.toString()); doNothing().when(auditPropertyEntityAdapter).setUserId("TRANSCRIBE_SERVICE"); transcribeQueueJob.executeTask(); verify(arkCaseTranscribeService).getConfiguration(); verify(arkCaseTranscribeService).getAllByStatus(TranscribeStatusType.PROCESSING.toString()); verify(activitiRuntimeService).createProcessInstanceQuery(); verify(processInstanceQuery).variableValueEqualsIgnoreCase(variableKey, variableValue); verify(processInstanceQuery).list(); verify(arkCaseTranscribeService).get(105L); verify(arkCaseTranscribeService).getTranscribeServiceFactory(); verify(transcribeServiceFactory).getService(TranscribeServiceProvider.AWS); verify(transcribeService).create(transcribe1); verify(arkCaseTranscribeService).signal(processInstance1, TranscribeStatusType.PROCESSING.toString(), TranscribeActionType.PROCESSING.toString()); verify(auditPropertyEntityAdapter).setUserId("TRANSCRIBE_SERVICE"); }
@Override public void executeTask() { try { getAuditPropertyEntityAdapter().setUserId("TRANSCRIBE_SERVICE"); TranscribeConfiguration configuration = getArkCaseTranscribeService().getConfiguration(); List<Transcribe> processingTranscribeObjects = getArkCaseTranscribeService() .getAllByStatus(TranscribeStatusType.PROCESSING.toString()); List<Transcribe> processingTranscribeAutomaticObjects = processingTranscribeObjects.stream() .filter(t -> TranscribeType.AUTOMATIC.toString().equalsIgnoreCase(t.getType())).collect(Collectors.toList()); List<Transcribe> processingTranscribeObjectsDistinctByProcessId = processingTranscribeAutomaticObjects.stream() .filter(TranscribeUtils.distinctByProperty(Transcribe::getProcessId)).collect(Collectors.toList()); if (configuration.getNumberOfFilesForProcessing() > processingTranscribeObjectsDistinctByProcessId.size()) { String key = TranscribeBusinessProcessVariableKey.STATUS.toString(); String value = TranscribeStatusType.QUEUED.toString(); List<ProcessInstance> processInstances = getActivitiRuntimeService().createProcessInstanceQuery().includeProcessVariables() .variableValueEqualsIgnoreCase(key, value).list(); if (processInstances != null && processInstances.size() > 0) { processInstances.sort(new TranscribeProcessInstanceCreatedDateComparator()); ProcessInstance processInstance = processInstances.get(0); List<Long> ids = (List<Long>) processInstance.getProcessVariables().get("IDS"); if (ids != null && ids.size() > 0) { Transcribe transcribe = getArkCaseTranscribeService().get(ids.get(0)); if (transcribe != null) { getArkCaseTranscribeService().getTranscribeServiceFactory().getService(configuration.getProvider()) .create(transcribe); getArkCaseTranscribeService().signal(processInstance, TranscribeStatusType.PROCESSING.toString(), TranscribeActionType.PROCESSING.toString()); } } } } } catch (GetConfigurationException | GetTranscribeException | CreateTranscribeException | TranscribeServiceProviderNotFoundException e) { LOG.error("Could not move Transcribe from the queue. REASON=[{}]", e.getMessage(), e); } }
TranscribeQueueJob implements AcmSchedulableBean { @Override public void executeTask() { try { getAuditPropertyEntityAdapter().setUserId("TRANSCRIBE_SERVICE"); TranscribeConfiguration configuration = getArkCaseTranscribeService().getConfiguration(); List<Transcribe> processingTranscribeObjects = getArkCaseTranscribeService() .getAllByStatus(TranscribeStatusType.PROCESSING.toString()); List<Transcribe> processingTranscribeAutomaticObjects = processingTranscribeObjects.stream() .filter(t -> TranscribeType.AUTOMATIC.toString().equalsIgnoreCase(t.getType())).collect(Collectors.toList()); List<Transcribe> processingTranscribeObjectsDistinctByProcessId = processingTranscribeAutomaticObjects.stream() .filter(TranscribeUtils.distinctByProperty(Transcribe::getProcessId)).collect(Collectors.toList()); if (configuration.getNumberOfFilesForProcessing() > processingTranscribeObjectsDistinctByProcessId.size()) { String key = TranscribeBusinessProcessVariableKey.STATUS.toString(); String value = TranscribeStatusType.QUEUED.toString(); List<ProcessInstance> processInstances = getActivitiRuntimeService().createProcessInstanceQuery().includeProcessVariables() .variableValueEqualsIgnoreCase(key, value).list(); if (processInstances != null && processInstances.size() > 0) { processInstances.sort(new TranscribeProcessInstanceCreatedDateComparator()); ProcessInstance processInstance = processInstances.get(0); List<Long> ids = (List<Long>) processInstance.getProcessVariables().get("IDS"); if (ids != null && ids.size() > 0) { Transcribe transcribe = getArkCaseTranscribeService().get(ids.get(0)); if (transcribe != null) { getArkCaseTranscribeService().getTranscribeServiceFactory().getService(configuration.getProvider()) .create(transcribe); getArkCaseTranscribeService().signal(processInstance, TranscribeStatusType.PROCESSING.toString(), TranscribeActionType.PROCESSING.toString()); } } } } } catch (GetConfigurationException | GetTranscribeException | CreateTranscribeException | TranscribeServiceProviderNotFoundException e) { LOG.error("Could not move Transcribe from the queue. REASON=[{}]", e.getMessage(), e); } } }
TranscribeQueueJob implements AcmSchedulableBean { @Override public void executeTask() { try { getAuditPropertyEntityAdapter().setUserId("TRANSCRIBE_SERVICE"); TranscribeConfiguration configuration = getArkCaseTranscribeService().getConfiguration(); List<Transcribe> processingTranscribeObjects = getArkCaseTranscribeService() .getAllByStatus(TranscribeStatusType.PROCESSING.toString()); List<Transcribe> processingTranscribeAutomaticObjects = processingTranscribeObjects.stream() .filter(t -> TranscribeType.AUTOMATIC.toString().equalsIgnoreCase(t.getType())).collect(Collectors.toList()); List<Transcribe> processingTranscribeObjectsDistinctByProcessId = processingTranscribeAutomaticObjects.stream() .filter(TranscribeUtils.distinctByProperty(Transcribe::getProcessId)).collect(Collectors.toList()); if (configuration.getNumberOfFilesForProcessing() > processingTranscribeObjectsDistinctByProcessId.size()) { String key = TranscribeBusinessProcessVariableKey.STATUS.toString(); String value = TranscribeStatusType.QUEUED.toString(); List<ProcessInstance> processInstances = getActivitiRuntimeService().createProcessInstanceQuery().includeProcessVariables() .variableValueEqualsIgnoreCase(key, value).list(); if (processInstances != null && processInstances.size() > 0) { processInstances.sort(new TranscribeProcessInstanceCreatedDateComparator()); ProcessInstance processInstance = processInstances.get(0); List<Long> ids = (List<Long>) processInstance.getProcessVariables().get("IDS"); if (ids != null && ids.size() > 0) { Transcribe transcribe = getArkCaseTranscribeService().get(ids.get(0)); if (transcribe != null) { getArkCaseTranscribeService().getTranscribeServiceFactory().getService(configuration.getProvider()) .create(transcribe); getArkCaseTranscribeService().signal(processInstance, TranscribeStatusType.PROCESSING.toString(), TranscribeActionType.PROCESSING.toString()); } } } } } catch (GetConfigurationException | GetTranscribeException | CreateTranscribeException | TranscribeServiceProviderNotFoundException e) { LOG.error("Could not move Transcribe from the queue. REASON=[{}]", e.getMessage(), e); } }  }
TranscribeQueueJob implements AcmSchedulableBean { @Override public void executeTask() { try { getAuditPropertyEntityAdapter().setUserId("TRANSCRIBE_SERVICE"); TranscribeConfiguration configuration = getArkCaseTranscribeService().getConfiguration(); List<Transcribe> processingTranscribeObjects = getArkCaseTranscribeService() .getAllByStatus(TranscribeStatusType.PROCESSING.toString()); List<Transcribe> processingTranscribeAutomaticObjects = processingTranscribeObjects.stream() .filter(t -> TranscribeType.AUTOMATIC.toString().equalsIgnoreCase(t.getType())).collect(Collectors.toList()); List<Transcribe> processingTranscribeObjectsDistinctByProcessId = processingTranscribeAutomaticObjects.stream() .filter(TranscribeUtils.distinctByProperty(Transcribe::getProcessId)).collect(Collectors.toList()); if (configuration.getNumberOfFilesForProcessing() > processingTranscribeObjectsDistinctByProcessId.size()) { String key = TranscribeBusinessProcessVariableKey.STATUS.toString(); String value = TranscribeStatusType.QUEUED.toString(); List<ProcessInstance> processInstances = getActivitiRuntimeService().createProcessInstanceQuery().includeProcessVariables() .variableValueEqualsIgnoreCase(key, value).list(); if (processInstances != null && processInstances.size() > 0) { processInstances.sort(new TranscribeProcessInstanceCreatedDateComparator()); ProcessInstance processInstance = processInstances.get(0); List<Long> ids = (List<Long>) processInstance.getProcessVariables().get("IDS"); if (ids != null && ids.size() > 0) { Transcribe transcribe = getArkCaseTranscribeService().get(ids.get(0)); if (transcribe != null) { getArkCaseTranscribeService().getTranscribeServiceFactory().getService(configuration.getProvider()) .create(transcribe); getArkCaseTranscribeService().signal(processInstance, TranscribeStatusType.PROCESSING.toString(), TranscribeActionType.PROCESSING.toString()); } } } } } catch (GetConfigurationException | GetTranscribeException | CreateTranscribeException | TranscribeServiceProviderNotFoundException e) { LOG.error("Could not move Transcribe from the queue. REASON=[{}]", e.getMessage(), e); } }  @Override void executeTask(); ArkCaseTranscribeService getArkCaseTranscribeService(); void setArkCaseTranscribeService(ArkCaseTranscribeService arkCaseTranscribeService); RuntimeService getActivitiRuntimeService(); void setActivitiRuntimeService(RuntimeService activitiRuntimeService); AuditPropertyEntityAdapter getAuditPropertyEntityAdapter(); void setAuditPropertyEntityAdapter(AuditPropertyEntityAdapter auditPropertyEntityAdapter); }
TranscribeQueueJob implements AcmSchedulableBean { @Override public void executeTask() { try { getAuditPropertyEntityAdapter().setUserId("TRANSCRIBE_SERVICE"); TranscribeConfiguration configuration = getArkCaseTranscribeService().getConfiguration(); List<Transcribe> processingTranscribeObjects = getArkCaseTranscribeService() .getAllByStatus(TranscribeStatusType.PROCESSING.toString()); List<Transcribe> processingTranscribeAutomaticObjects = processingTranscribeObjects.stream() .filter(t -> TranscribeType.AUTOMATIC.toString().equalsIgnoreCase(t.getType())).collect(Collectors.toList()); List<Transcribe> processingTranscribeObjectsDistinctByProcessId = processingTranscribeAutomaticObjects.stream() .filter(TranscribeUtils.distinctByProperty(Transcribe::getProcessId)).collect(Collectors.toList()); if (configuration.getNumberOfFilesForProcessing() > processingTranscribeObjectsDistinctByProcessId.size()) { String key = TranscribeBusinessProcessVariableKey.STATUS.toString(); String value = TranscribeStatusType.QUEUED.toString(); List<ProcessInstance> processInstances = getActivitiRuntimeService().createProcessInstanceQuery().includeProcessVariables() .variableValueEqualsIgnoreCase(key, value).list(); if (processInstances != null && processInstances.size() > 0) { processInstances.sort(new TranscribeProcessInstanceCreatedDateComparator()); ProcessInstance processInstance = processInstances.get(0); List<Long> ids = (List<Long>) processInstance.getProcessVariables().get("IDS"); if (ids != null && ids.size() > 0) { Transcribe transcribe = getArkCaseTranscribeService().get(ids.get(0)); if (transcribe != null) { getArkCaseTranscribeService().getTranscribeServiceFactory().getService(configuration.getProvider()) .create(transcribe); getArkCaseTranscribeService().signal(processInstance, TranscribeStatusType.PROCESSING.toString(), TranscribeActionType.PROCESSING.toString()); } } } } } catch (GetConfigurationException | GetTranscribeException | CreateTranscribeException | TranscribeServiceProviderNotFoundException e) { LOG.error("Could not move Transcribe from the queue. REASON=[{}]", e.getMessage(), e); } }  @Override void executeTask(); ArkCaseTranscribeService getArkCaseTranscribeService(); void setArkCaseTranscribeService(ArkCaseTranscribeService arkCaseTranscribeService); RuntimeService getActivitiRuntimeService(); void setActivitiRuntimeService(RuntimeService activitiRuntimeService); AuditPropertyEntityAdapter getAuditPropertyEntityAdapter(); void setAuditPropertyEntityAdapter(AuditPropertyEntityAdapter auditPropertyEntityAdapter);  }