@Test public void executeTask() throws Exception { OCRConfiguration configuration = new OCRConfiguration(); configuration.setNumberOfFilesForProcessing(10); configuration.setProvider(OCRServiceProvider.TESSERACT); AcmObjectLock lock = new AcmObjectLock(); lock.setCreator(OCRConstants.OCR_SYSTEM_USER); OCR serviceProviderOCR = new OCR(); serviceProviderOCR.setStatus(OCRStatusType.PROCESSING.toString()); EcmFile file = new EcmFile(); file.setFileId(1L); EcmFileVersion version = new EcmFileVersion(); version.setFile(file); version.setId(1L); EcmFileVersion version1 = new EcmFileVersion(); version1.setFile(file); version1.setId(2L); List<EcmFileVersion> versions = new ArrayList<>(); versions.add(version); versions.add(version1); file.setVersions(versions); OCR ocr = new OCR(); ocr.setProcessId("123"); ocr.setStatus(OCRStatusType.PROCESSING.toString()); ocr.setEcmFileVersion(version); OCR ocr1 = new OCR(); ocr1.setProcessId("456"); ocr1.setStatus(OCRStatusType.PROCESSING.toString()); ocr1.setEcmFileVersion(version1); List<OCR> ocrs = new ArrayList<>(); ocrs.add(ocr); ocrs.add(ocr1); String variableKey = OCRBusinessProcessVariableKey.STATUS.toString(); String variableValue = OCRStatusType.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(arkCaseOCRService.getConfiguration()).thenReturn(configuration); when(arkCaseOCRService.getAllByStatus(OCRStatusType.PROCESSING.toString())).thenReturn(ocrs); when(activitiRuntimeService.createProcessInstanceQuery()).thenReturn(processInstanceQuery); when(processInstanceQuery.variableValueEqualsIgnoreCase(variableKey, variableValue)).thenReturn(processInstanceQuery); when(processInstanceQuery.includeProcessVariables()).thenReturn(processInstanceQuery); when(processInstanceQuery.list()).thenReturn(processInstances); when(arkCaseOCRService.get(105l)).thenReturn(ocr); when(arkCaseOCRService.getOCRServiceFactory()).thenReturn(ocrServiceFactory); when(ocrServiceFactory.getService(OCRServiceProvider.TESSERACT)).thenReturn(ocrService); when(ocrService.create(ocr)).thenReturn(serviceProviderOCR); doNothing().when(arkCaseOCRService).signal(processInstance1, OCRStatusType.PROCESSING.toString(), OCRActionType.PROCESSING.toString()); doNothing().when(auditPropertyEntityAdapter).setUserId(OCRConstants.OCR_SYSTEM_USER); when(ocrQueueJob.getObjectLockService().findLock(any(), any())).thenReturn(lock); expect(acmObjectLockingManager.acquireObjectLock(eq(1L), eq("FILE"), eq(OCRConstants.OCR_SYSTEM_USER), eq(null), eq(true), eq(OCRConstants.OCR_SYSTEM_USER))) .andAnswer(() -> { AcmObjectLock lock1 = new AcmObjectLock(); lock.setCreator(OCRConstants.OCR_SYSTEM_USER); lock.setId(1l); lock.setObjectId(1L); lock.setObjectType("FILE"); lock.setExpiry(null); return lock; }); ocrQueueJob.executeTask(); verify(arkCaseOCRService).getConfiguration(); verify(arkCaseOCRService).getAllByStatus(OCRStatusType.PROCESSING.toString()); verify(activitiRuntimeService).createProcessInstanceQuery(); verify(processInstanceQuery).variableValueEqualsIgnoreCase(variableKey, variableValue); verify(processInstanceQuery).list(); verify(arkCaseOCRService).get(105L); verify(arkCaseOCRService).getOCRServiceFactory(); verify(ocrServiceFactory).getService(OCRServiceProvider.TESSERACT); verify(ocrService).create(ocr); verify(arkCaseOCRService).signal(processInstance1, OCRStatusType.PROCESSING.toString(), OCRActionType.PROCESSING.toString()); verify(auditPropertyEntityAdapter).setUserId(OCRConstants.OCR_SYSTEM_USER); }
@Override public void executeTask() { try { getAuditPropertyEntityAdapter().setUserId(OCRConstants.OCR_SYSTEM_USER); OCRConfiguration configuration = getArkCaseOCRService().getConfiguration(); List<OCR> processingOCRObjects = getArkCaseOCRService() .getAllByStatus(OCRStatusType.PROCESSING.toString()); List<OCR> processingOCRAutomaticObjects = processingOCRObjects.stream() .filter(t -> OCRType.AUTOMATIC.toString().equalsIgnoreCase(t.getType())).collect(Collectors.toList()); List<OCR> processingOCRObjectsDistinctByProcessId = processingOCRAutomaticObjects.stream() .filter(OCRUtils.distinctByProperty(OCR::getProcessId)).collect(Collectors.toList()); if (configuration.getNumberOfFilesForProcessing() > processingOCRObjectsDistinctByProcessId.size()) { String key = OCRBusinessProcessVariableKey.STATUS.toString(); String value = OCRStatusType.QUEUED.toString(); List<ProcessInstance> processInstances = getActivitiRuntimeService().createProcessInstanceQuery().includeProcessVariables() .variableValueEqualsIgnoreCase(key, value).list(); if (processInstances != null && !processInstances.isEmpty()) { processInstances.sort(new OCRProcessInstanceCreatedDateComparator()); for (ProcessInstance processInstance : processInstances) { List<Long> ids = (List<Long>) processInstance.getProcessVariables().get("IDS"); if (ids != null && !ids.isEmpty()) { OCR ocr = getArkCaseOCRService().get(ids.get(0)); AcmObjectLock lock = objectLockService.findLock(ocr.getEcmFileVersion().getFile().getId(), "FILE"); if (ocr != null && (lock == null || lock.getCreator().equalsIgnoreCase(OCRConstants.OCR_SYSTEM_USER))) { objectLockingManager.acquireObjectLock(ocr.getEcmFileVersion().getFile().getId(), "FILE", "WRITE", null, true, OCRConstants.OCR_SYSTEM_USER); getArkCaseOCRService().getOCRServiceFactory().getService(configuration.getProvider()).create(ocr); getArkCaseOCRService().save(ocr); getArkCaseOCRService().signal(processInstance, OCRStatusType.PROCESSING.toString(), OCRActionType.PROCESSING.toString()); break; } } } } } } catch (GetConfigurationException | SaveOCRException | GetOCRException | CreateOCRException | AcmObjectLockException | OCRServiceProviderNotFoundException e) { LOG.error("Could not move OCR from the queue. REASON=[{}]", e.getMessage(), e); } }
OCRQueueJob implements AcmSchedulableBean { @Override public void executeTask() { try { getAuditPropertyEntityAdapter().setUserId(OCRConstants.OCR_SYSTEM_USER); OCRConfiguration configuration = getArkCaseOCRService().getConfiguration(); List<OCR> processingOCRObjects = getArkCaseOCRService() .getAllByStatus(OCRStatusType.PROCESSING.toString()); List<OCR> processingOCRAutomaticObjects = processingOCRObjects.stream() .filter(t -> OCRType.AUTOMATIC.toString().equalsIgnoreCase(t.getType())).collect(Collectors.toList()); List<OCR> processingOCRObjectsDistinctByProcessId = processingOCRAutomaticObjects.stream() .filter(OCRUtils.distinctByProperty(OCR::getProcessId)).collect(Collectors.toList()); if (configuration.getNumberOfFilesForProcessing() > processingOCRObjectsDistinctByProcessId.size()) { String key = OCRBusinessProcessVariableKey.STATUS.toString(); String value = OCRStatusType.QUEUED.toString(); List<ProcessInstance> processInstances = getActivitiRuntimeService().createProcessInstanceQuery().includeProcessVariables() .variableValueEqualsIgnoreCase(key, value).list(); if (processInstances != null && !processInstances.isEmpty()) { processInstances.sort(new OCRProcessInstanceCreatedDateComparator()); for (ProcessInstance processInstance : processInstances) { List<Long> ids = (List<Long>) processInstance.getProcessVariables().get("IDS"); if (ids != null && !ids.isEmpty()) { OCR ocr = getArkCaseOCRService().get(ids.get(0)); AcmObjectLock lock = objectLockService.findLock(ocr.getEcmFileVersion().getFile().getId(), "FILE"); if (ocr != null && (lock == null || lock.getCreator().equalsIgnoreCase(OCRConstants.OCR_SYSTEM_USER))) { objectLockingManager.acquireObjectLock(ocr.getEcmFileVersion().getFile().getId(), "FILE", "WRITE", null, true, OCRConstants.OCR_SYSTEM_USER); getArkCaseOCRService().getOCRServiceFactory().getService(configuration.getProvider()).create(ocr); getArkCaseOCRService().save(ocr); getArkCaseOCRService().signal(processInstance, OCRStatusType.PROCESSING.toString(), OCRActionType.PROCESSING.toString()); break; } } } } } } catch (GetConfigurationException | SaveOCRException | GetOCRException | CreateOCRException | AcmObjectLockException | OCRServiceProviderNotFoundException e) { LOG.error("Could not move OCR from the queue. REASON=[{}]", e.getMessage(), e); } } }
OCRQueueJob implements AcmSchedulableBean { @Override public void executeTask() { try { getAuditPropertyEntityAdapter().setUserId(OCRConstants.OCR_SYSTEM_USER); OCRConfiguration configuration = getArkCaseOCRService().getConfiguration(); List<OCR> processingOCRObjects = getArkCaseOCRService() .getAllByStatus(OCRStatusType.PROCESSING.toString()); List<OCR> processingOCRAutomaticObjects = processingOCRObjects.stream() .filter(t -> OCRType.AUTOMATIC.toString().equalsIgnoreCase(t.getType())).collect(Collectors.toList()); List<OCR> processingOCRObjectsDistinctByProcessId = processingOCRAutomaticObjects.stream() .filter(OCRUtils.distinctByProperty(OCR::getProcessId)).collect(Collectors.toList()); if (configuration.getNumberOfFilesForProcessing() > processingOCRObjectsDistinctByProcessId.size()) { String key = OCRBusinessProcessVariableKey.STATUS.toString(); String value = OCRStatusType.QUEUED.toString(); List<ProcessInstance> processInstances = getActivitiRuntimeService().createProcessInstanceQuery().includeProcessVariables() .variableValueEqualsIgnoreCase(key, value).list(); if (processInstances != null && !processInstances.isEmpty()) { processInstances.sort(new OCRProcessInstanceCreatedDateComparator()); for (ProcessInstance processInstance : processInstances) { List<Long> ids = (List<Long>) processInstance.getProcessVariables().get("IDS"); if (ids != null && !ids.isEmpty()) { OCR ocr = getArkCaseOCRService().get(ids.get(0)); AcmObjectLock lock = objectLockService.findLock(ocr.getEcmFileVersion().getFile().getId(), "FILE"); if (ocr != null && (lock == null || lock.getCreator().equalsIgnoreCase(OCRConstants.OCR_SYSTEM_USER))) { objectLockingManager.acquireObjectLock(ocr.getEcmFileVersion().getFile().getId(), "FILE", "WRITE", null, true, OCRConstants.OCR_SYSTEM_USER); getArkCaseOCRService().getOCRServiceFactory().getService(configuration.getProvider()).create(ocr); getArkCaseOCRService().save(ocr); getArkCaseOCRService().signal(processInstance, OCRStatusType.PROCESSING.toString(), OCRActionType.PROCESSING.toString()); break; } } } } } } catch (GetConfigurationException | SaveOCRException | GetOCRException | CreateOCRException | AcmObjectLockException | OCRServiceProviderNotFoundException e) { LOG.error("Could not move OCR from the queue. REASON=[{}]", e.getMessage(), e); } }  }
OCRQueueJob implements AcmSchedulableBean { @Override public void executeTask() { try { getAuditPropertyEntityAdapter().setUserId(OCRConstants.OCR_SYSTEM_USER); OCRConfiguration configuration = getArkCaseOCRService().getConfiguration(); List<OCR> processingOCRObjects = getArkCaseOCRService() .getAllByStatus(OCRStatusType.PROCESSING.toString()); List<OCR> processingOCRAutomaticObjects = processingOCRObjects.stream() .filter(t -> OCRType.AUTOMATIC.toString().equalsIgnoreCase(t.getType())).collect(Collectors.toList()); List<OCR> processingOCRObjectsDistinctByProcessId = processingOCRAutomaticObjects.stream() .filter(OCRUtils.distinctByProperty(OCR::getProcessId)).collect(Collectors.toList()); if (configuration.getNumberOfFilesForProcessing() > processingOCRObjectsDistinctByProcessId.size()) { String key = OCRBusinessProcessVariableKey.STATUS.toString(); String value = OCRStatusType.QUEUED.toString(); List<ProcessInstance> processInstances = getActivitiRuntimeService().createProcessInstanceQuery().includeProcessVariables() .variableValueEqualsIgnoreCase(key, value).list(); if (processInstances != null && !processInstances.isEmpty()) { processInstances.sort(new OCRProcessInstanceCreatedDateComparator()); for (ProcessInstance processInstance : processInstances) { List<Long> ids = (List<Long>) processInstance.getProcessVariables().get("IDS"); if (ids != null && !ids.isEmpty()) { OCR ocr = getArkCaseOCRService().get(ids.get(0)); AcmObjectLock lock = objectLockService.findLock(ocr.getEcmFileVersion().getFile().getId(), "FILE"); if (ocr != null && (lock == null || lock.getCreator().equalsIgnoreCase(OCRConstants.OCR_SYSTEM_USER))) { objectLockingManager.acquireObjectLock(ocr.getEcmFileVersion().getFile().getId(), "FILE", "WRITE", null, true, OCRConstants.OCR_SYSTEM_USER); getArkCaseOCRService().getOCRServiceFactory().getService(configuration.getProvider()).create(ocr); getArkCaseOCRService().save(ocr); getArkCaseOCRService().signal(processInstance, OCRStatusType.PROCESSING.toString(), OCRActionType.PROCESSING.toString()); break; } } } } } } catch (GetConfigurationException | SaveOCRException | GetOCRException | CreateOCRException | AcmObjectLockException | OCRServiceProviderNotFoundException e) { LOG.error("Could not move OCR from the queue. REASON=[{}]", e.getMessage(), e); } }  @Override void executeTask(); ArkCaseOCRService getArkCaseOCRService(); void setArkCaseOCRService(ArkCaseOCRService arkCaseOCRService); RuntimeService getActivitiRuntimeService(); void setActivitiRuntimeService(RuntimeService activitiRuntimeService); AuditPropertyEntityAdapter getAuditPropertyEntityAdapter(); void setAuditPropertyEntityAdapter(AuditPropertyEntityAdapter auditPropertyEntityAdapter); AcmObjectLockService getObjectLockService(); void setObjectLockService(AcmObjectLockService objectLockService); void setObjectLockingManager(AcmObjectLockingManager objectLockingManager); AcmObjectLockingManager getObjectLockingManager(); }
OCRQueueJob implements AcmSchedulableBean { @Override public void executeTask() { try { getAuditPropertyEntityAdapter().setUserId(OCRConstants.OCR_SYSTEM_USER); OCRConfiguration configuration = getArkCaseOCRService().getConfiguration(); List<OCR> processingOCRObjects = getArkCaseOCRService() .getAllByStatus(OCRStatusType.PROCESSING.toString()); List<OCR> processingOCRAutomaticObjects = processingOCRObjects.stream() .filter(t -> OCRType.AUTOMATIC.toString().equalsIgnoreCase(t.getType())).collect(Collectors.toList()); List<OCR> processingOCRObjectsDistinctByProcessId = processingOCRAutomaticObjects.stream() .filter(OCRUtils.distinctByProperty(OCR::getProcessId)).collect(Collectors.toList()); if (configuration.getNumberOfFilesForProcessing() > processingOCRObjectsDistinctByProcessId.size()) { String key = OCRBusinessProcessVariableKey.STATUS.toString(); String value = OCRStatusType.QUEUED.toString(); List<ProcessInstance> processInstances = getActivitiRuntimeService().createProcessInstanceQuery().includeProcessVariables() .variableValueEqualsIgnoreCase(key, value).list(); if (processInstances != null && !processInstances.isEmpty()) { processInstances.sort(new OCRProcessInstanceCreatedDateComparator()); for (ProcessInstance processInstance : processInstances) { List<Long> ids = (List<Long>) processInstance.getProcessVariables().get("IDS"); if (ids != null && !ids.isEmpty()) { OCR ocr = getArkCaseOCRService().get(ids.get(0)); AcmObjectLock lock = objectLockService.findLock(ocr.getEcmFileVersion().getFile().getId(), "FILE"); if (ocr != null && (lock == null || lock.getCreator().equalsIgnoreCase(OCRConstants.OCR_SYSTEM_USER))) { objectLockingManager.acquireObjectLock(ocr.getEcmFileVersion().getFile().getId(), "FILE", "WRITE", null, true, OCRConstants.OCR_SYSTEM_USER); getArkCaseOCRService().getOCRServiceFactory().getService(configuration.getProvider()).create(ocr); getArkCaseOCRService().save(ocr); getArkCaseOCRService().signal(processInstance, OCRStatusType.PROCESSING.toString(), OCRActionType.PROCESSING.toString()); break; } } } } } } catch (GetConfigurationException | SaveOCRException | GetOCRException | CreateOCRException | AcmObjectLockException | OCRServiceProviderNotFoundException e) { LOG.error("Could not move OCR from the queue. REASON=[{}]", e.getMessage(), e); } }  @Override void executeTask(); ArkCaseOCRService getArkCaseOCRService(); void setArkCaseOCRService(ArkCaseOCRService arkCaseOCRService); RuntimeService getActivitiRuntimeService(); void setActivitiRuntimeService(RuntimeService activitiRuntimeService); AuditPropertyEntityAdapter getAuditPropertyEntityAdapter(); void setAuditPropertyEntityAdapter(AuditPropertyEntityAdapter auditPropertyEntityAdapter); AcmObjectLockService getObjectLockService(); void setObjectLockService(AcmObjectLockService objectLockService); void setObjectLockingManager(AcmObjectLockingManager objectLockingManager); AcmObjectLockingManager getObjectLockingManager();  }