@Test public void test_AllExtractionReturnsNull() throws Exception{ final String fileUrl = GitHubUrl_PREFIX + Image1; subTasks.add(metaInfoExtractionSubTask); subTasks.add(colorExtractionSubTask); subTasks.add(mediumThumbnailExtractionSubTask); subTasks.add(largeThumbnailExtractionSubTask); MediaMetaInfoExtractor mediaMetaInfoExtractorFail = mock(MediaMetaInfoExtractor.class); ColorExtractor colorExtractorFail = mock(ColorExtractor.class); MediaStorageClient mediaStorageClientFail = mock(FileSystemMediaStorageClientImpl.class); ThumbnailImageGenerator thumbnailImageGeneratorFail = mock(ThumbnailImageGenerator.class); doReturn(null).when(mediaMetaInfoExtractorFail).extract(anyString()); doReturn(null).when(colorExtractorFail).colorExtraction(anyString()); doReturn(PATH_COLORMAP).when(thumbnailImageGeneratorFail).getColorMapPath(); doReturn(null).when(thumbnailImageGeneratorFail).createMediaFileWithThumbnail(anyInt(), anyInt(), anyString(), anyString(), any(new byte[]{}.getClass()), anyString()); SlaveProcessor slaveProcessorAlwaysFail = new SlaveProcessor(mediaMetaInfoExtractorFail, colorExtractorFail, mediaStorageClientFail, PATH_COLORMAP); ProcessingResultTuple tuple = slaveProcessorAlwaysFail.process(taskDocumentReference, PATH_DOWNLOADED + Image1, fileUrl, new byte[]{0}, ResponseType.DISK_STORAGE, new ReferenceOwner("", "", "", "")) ; assertEquals(ProcessingJobSubTaskState.FAILED, tuple.getProcessingJobSubTaskStats().getMetaExtractionState()); assertEquals(ProcessingJobSubTaskState.NEVER_EXECUTED, tuple.getProcessingJobSubTaskStats().getColorExtractionState()); assertEquals(ProcessingJobSubTaskState.NEVER_EXECUTED, tuple.getProcessingJobSubTaskStats().getThumbnailGenerationState()); assertEquals(ProcessingJobSubTaskState.NEVER_EXECUTED, tuple.getProcessingJobSubTaskStats().getThumbnailStorageState()); }
public ProcessingResultTuple process(final ProcessingJobTaskDocumentReference task, String originalFilePath, String originalFileUrl, byte[] originalFileContent, ResponseType responseType, ReferenceOwner referenceOwner) { final ProcessingJobSubTask colorExtractionProcessingTask = locateColorExtractionProcessingTask(task); final ProcessingJobSubTask metaExtractionProcessingTask = SlaveProcessorHack.artificialMetaInfoTask(locateMetaInfoExtractionProcessingTask(task),colorExtractionProcessingTask); final List<ProcessingJobSubTask> thumbnailGenerationProcessingTasks = locateThumbnailExtractionProcessingTask(task); ProcessingJobSubTaskStats stats = new ProcessingJobSubTaskStats(); MediaMetaInfoTuple mediaMetaInfoTuple = null; ImageMetaInfo imageColorMetaInfo = null; Map<ProcessingJobSubTask, MediaFile> generatedThumbnails = new HashMap<>(); if (null != metaExtractionProcessingTask) { try { mediaMetaInfoTuple = extractMetaInfo(originalFilePath, originalFileUrl, responseType, metaExtractionProcessingTask); if (null != mediaMetaInfoTuple && mediaMetaInfoTuple.isValid()) { stats = stats.withMetaExtractionState(ProcessingJobSubTaskState.SUCCESS); } else { stats = stats.withMetaExtractionState(ProcessingJobSubTaskState.FAILED, new Exception("mediaMetaInfoTuple is null OR mediaMetaInfoTuple is not valid")); } } catch (Exception e) { stats = stats.withMetaExtractionState(ProcessingJobSubTaskState.ERROR, e); } } if (!MediaMetaDataUtils.classifyUrl(originalFilePath).equals(ContentType.IMAGE)) { stats = stats.withColorExtractionState(ProcessingJobSubTaskState.NEVER_EXECUTED); } else if ((null != colorExtractionProcessingTask)) { try { imageColorMetaInfo = extractColor(originalFilePath); if (null != imageColorMetaInfo && null != imageColorMetaInfo.getColorPalette() && imageColorMetaInfo.getColorPalette().length > 0) { stats = stats.withColorExtractionState(ProcessingJobSubTaskState.SUCCESS); } else { stats = stats.withColorExtractionState(ProcessingJobSubTaskState.FAILED, new Exception("imageColorMetaInfo is null OR imageColorMetaInfo.colorPalette is null OR imageColorMetaInfo.colorPalette is empty")); } } catch (Exception e) { stats = stats.withColorExtractionState(ProcessingJobSubTaskState.ERROR, e); } } if (imageColorMetaInfo != null) { if (mediaMetaInfoTuple == null) mediaMetaInfoTuple = new MediaMetaInfoTuple(imageColorMetaInfo, null, null, null); else mediaMetaInfoTuple = mediaMetaInfoTuple.withImageMetaInfo(mediaMetaInfoTuple.getImageMetaInfo().withColorPalette(imageColorMetaInfo.getColorPalette())); } if ((null != thumbnailGenerationProcessingTasks) && !thumbnailGenerationProcessingTasks.isEmpty()) { if ((MediaMetaDataUtils.classifyUrl(originalFilePath).equals(ContentType.IMAGE) && (imageColorMetaInfo != null)) || MediaMetaDataUtils.classifyUrl(originalFilePath).equals(ContentType.PDF)) { try { generatedThumbnails = generateThumbnails(originalFilePath, originalFileUrl, originalFileContent, referenceOwner, thumbnailGenerationProcessingTasks); if (null != generatedThumbnails && generatedThumbnails.size() == thumbnailGenerationProcessingTasks.size()) { stats = stats.withThumbnailGenerationState(ProcessingJobSubTaskState.SUCCESS); } else { stats = stats.withThumbnailGenerationState(ProcessingJobSubTaskState.FAILED, new Exception("thumbnailGenerationProcessingTasks is null OR empty OR imageColorMetaInfo is null")); } } catch (Exception e) { stats = stats.withThumbnailGenerationState(ProcessingJobSubTaskState.ERROR, e); } } } if (imageColorMetaInfo != null) { for (final Map.Entry<ProcessingJobSubTask, MediaFile> thumbnailEntry : generatedThumbnails.entrySet()) { generatedThumbnails.put(thumbnailEntry.getKey(), thumbnailEntry.getValue().withColorPalette(imageColorMetaInfo.getColorPalette())); } } SlaveMetrics.Worker.Slave.Processing.thumbnailStorageCounter.inc(); final Timer.Context thumbnailStorageDurationContext = SlaveMetrics.Worker.Slave.Processing.thumbnailStorageDuration.time(); try { for (final Map.Entry<ProcessingJobSubTask, MediaFile> thumbnailEntry : generatedThumbnails.entrySet()) { mediaStorageClient.createOrModify(thumbnailEntry.getValue()); } if (null == generatedThumbnails || generatedThumbnails.isEmpty()) { stats = stats.withThumbnailStorageState(ProcessingJobSubTaskState.NEVER_EXECUTED); } else { stats = stats.withThumbnailStorageState(ProcessingJobSubTaskState.SUCCESS); } } catch (Exception e) { stats = stats.withThumbnailStorageState(ProcessingJobSubTaskState.ERROR, e); } finally { thumbnailStorageDurationContext.stop(); try { } catch (Exception e) { stats = stats.withThumbnailStorageState(ProcessingJobSubTaskState.ERROR, e); } } return new ProcessingResultTuple(stats, mediaMetaInfoTuple, generatedThumbnails.values() ); }
SlaveProcessor { public ProcessingResultTuple process(final ProcessingJobTaskDocumentReference task, String originalFilePath, String originalFileUrl, byte[] originalFileContent, ResponseType responseType, ReferenceOwner referenceOwner) { final ProcessingJobSubTask colorExtractionProcessingTask = locateColorExtractionProcessingTask(task); final ProcessingJobSubTask metaExtractionProcessingTask = SlaveProcessorHack.artificialMetaInfoTask(locateMetaInfoExtractionProcessingTask(task),colorExtractionProcessingTask); final List<ProcessingJobSubTask> thumbnailGenerationProcessingTasks = locateThumbnailExtractionProcessingTask(task); ProcessingJobSubTaskStats stats = new ProcessingJobSubTaskStats(); MediaMetaInfoTuple mediaMetaInfoTuple = null; ImageMetaInfo imageColorMetaInfo = null; Map<ProcessingJobSubTask, MediaFile> generatedThumbnails = new HashMap<>(); if (null != metaExtractionProcessingTask) { try { mediaMetaInfoTuple = extractMetaInfo(originalFilePath, originalFileUrl, responseType, metaExtractionProcessingTask); if (null != mediaMetaInfoTuple && mediaMetaInfoTuple.isValid()) { stats = stats.withMetaExtractionState(ProcessingJobSubTaskState.SUCCESS); } else { stats = stats.withMetaExtractionState(ProcessingJobSubTaskState.FAILED, new Exception("mediaMetaInfoTuple is null OR mediaMetaInfoTuple is not valid")); } } catch (Exception e) { stats = stats.withMetaExtractionState(ProcessingJobSubTaskState.ERROR, e); } } if (!MediaMetaDataUtils.classifyUrl(originalFilePath).equals(ContentType.IMAGE)) { stats = stats.withColorExtractionState(ProcessingJobSubTaskState.NEVER_EXECUTED); } else if ((null != colorExtractionProcessingTask)) { try { imageColorMetaInfo = extractColor(originalFilePath); if (null != imageColorMetaInfo && null != imageColorMetaInfo.getColorPalette() && imageColorMetaInfo.getColorPalette().length > 0) { stats = stats.withColorExtractionState(ProcessingJobSubTaskState.SUCCESS); } else { stats = stats.withColorExtractionState(ProcessingJobSubTaskState.FAILED, new Exception("imageColorMetaInfo is null OR imageColorMetaInfo.colorPalette is null OR imageColorMetaInfo.colorPalette is empty")); } } catch (Exception e) { stats = stats.withColorExtractionState(ProcessingJobSubTaskState.ERROR, e); } } if (imageColorMetaInfo != null) { if (mediaMetaInfoTuple == null) mediaMetaInfoTuple = new MediaMetaInfoTuple(imageColorMetaInfo, null, null, null); else mediaMetaInfoTuple = mediaMetaInfoTuple.withImageMetaInfo(mediaMetaInfoTuple.getImageMetaInfo().withColorPalette(imageColorMetaInfo.getColorPalette())); } if ((null != thumbnailGenerationProcessingTasks) && !thumbnailGenerationProcessingTasks.isEmpty()) { if ((MediaMetaDataUtils.classifyUrl(originalFilePath).equals(ContentType.IMAGE) && (imageColorMetaInfo != null)) || MediaMetaDataUtils.classifyUrl(originalFilePath).equals(ContentType.PDF)) { try { generatedThumbnails = generateThumbnails(originalFilePath, originalFileUrl, originalFileContent, referenceOwner, thumbnailGenerationProcessingTasks); if (null != generatedThumbnails && generatedThumbnails.size() == thumbnailGenerationProcessingTasks.size()) { stats = stats.withThumbnailGenerationState(ProcessingJobSubTaskState.SUCCESS); } else { stats = stats.withThumbnailGenerationState(ProcessingJobSubTaskState.FAILED, new Exception("thumbnailGenerationProcessingTasks is null OR empty OR imageColorMetaInfo is null")); } } catch (Exception e) { stats = stats.withThumbnailGenerationState(ProcessingJobSubTaskState.ERROR, e); } } } if (imageColorMetaInfo != null) { for (final Map.Entry<ProcessingJobSubTask, MediaFile> thumbnailEntry : generatedThumbnails.entrySet()) { generatedThumbnails.put(thumbnailEntry.getKey(), thumbnailEntry.getValue().withColorPalette(imageColorMetaInfo.getColorPalette())); } } SlaveMetrics.Worker.Slave.Processing.thumbnailStorageCounter.inc(); final Timer.Context thumbnailStorageDurationContext = SlaveMetrics.Worker.Slave.Processing.thumbnailStorageDuration.time(); try { for (final Map.Entry<ProcessingJobSubTask, MediaFile> thumbnailEntry : generatedThumbnails.entrySet()) { mediaStorageClient.createOrModify(thumbnailEntry.getValue()); } if (null == generatedThumbnails || generatedThumbnails.isEmpty()) { stats = stats.withThumbnailStorageState(ProcessingJobSubTaskState.NEVER_EXECUTED); } else { stats = stats.withThumbnailStorageState(ProcessingJobSubTaskState.SUCCESS); } } catch (Exception e) { stats = stats.withThumbnailStorageState(ProcessingJobSubTaskState.ERROR, e); } finally { thumbnailStorageDurationContext.stop(); try { } catch (Exception e) { stats = stats.withThumbnailStorageState(ProcessingJobSubTaskState.ERROR, e); } } return new ProcessingResultTuple(stats, mediaMetaInfoTuple, generatedThumbnails.values() ); } }
SlaveProcessor { public ProcessingResultTuple process(final ProcessingJobTaskDocumentReference task, String originalFilePath, String originalFileUrl, byte[] originalFileContent, ResponseType responseType, ReferenceOwner referenceOwner) { final ProcessingJobSubTask colorExtractionProcessingTask = locateColorExtractionProcessingTask(task); final ProcessingJobSubTask metaExtractionProcessingTask = SlaveProcessorHack.artificialMetaInfoTask(locateMetaInfoExtractionProcessingTask(task),colorExtractionProcessingTask); final List<ProcessingJobSubTask> thumbnailGenerationProcessingTasks = locateThumbnailExtractionProcessingTask(task); ProcessingJobSubTaskStats stats = new ProcessingJobSubTaskStats(); MediaMetaInfoTuple mediaMetaInfoTuple = null; ImageMetaInfo imageColorMetaInfo = null; Map<ProcessingJobSubTask, MediaFile> generatedThumbnails = new HashMap<>(); if (null != metaExtractionProcessingTask) { try { mediaMetaInfoTuple = extractMetaInfo(originalFilePath, originalFileUrl, responseType, metaExtractionProcessingTask); if (null != mediaMetaInfoTuple && mediaMetaInfoTuple.isValid()) { stats = stats.withMetaExtractionState(ProcessingJobSubTaskState.SUCCESS); } else { stats = stats.withMetaExtractionState(ProcessingJobSubTaskState.FAILED, new Exception("mediaMetaInfoTuple is null OR mediaMetaInfoTuple is not valid")); } } catch (Exception e) { stats = stats.withMetaExtractionState(ProcessingJobSubTaskState.ERROR, e); } } if (!MediaMetaDataUtils.classifyUrl(originalFilePath).equals(ContentType.IMAGE)) { stats = stats.withColorExtractionState(ProcessingJobSubTaskState.NEVER_EXECUTED); } else if ((null != colorExtractionProcessingTask)) { try { imageColorMetaInfo = extractColor(originalFilePath); if (null != imageColorMetaInfo && null != imageColorMetaInfo.getColorPalette() && imageColorMetaInfo.getColorPalette().length > 0) { stats = stats.withColorExtractionState(ProcessingJobSubTaskState.SUCCESS); } else { stats = stats.withColorExtractionState(ProcessingJobSubTaskState.FAILED, new Exception("imageColorMetaInfo is null OR imageColorMetaInfo.colorPalette is null OR imageColorMetaInfo.colorPalette is empty")); } } catch (Exception e) { stats = stats.withColorExtractionState(ProcessingJobSubTaskState.ERROR, e); } } if (imageColorMetaInfo != null) { if (mediaMetaInfoTuple == null) mediaMetaInfoTuple = new MediaMetaInfoTuple(imageColorMetaInfo, null, null, null); else mediaMetaInfoTuple = mediaMetaInfoTuple.withImageMetaInfo(mediaMetaInfoTuple.getImageMetaInfo().withColorPalette(imageColorMetaInfo.getColorPalette())); } if ((null != thumbnailGenerationProcessingTasks) && !thumbnailGenerationProcessingTasks.isEmpty()) { if ((MediaMetaDataUtils.classifyUrl(originalFilePath).equals(ContentType.IMAGE) && (imageColorMetaInfo != null)) || MediaMetaDataUtils.classifyUrl(originalFilePath).equals(ContentType.PDF)) { try { generatedThumbnails = generateThumbnails(originalFilePath, originalFileUrl, originalFileContent, referenceOwner, thumbnailGenerationProcessingTasks); if (null != generatedThumbnails && generatedThumbnails.size() == thumbnailGenerationProcessingTasks.size()) { stats = stats.withThumbnailGenerationState(ProcessingJobSubTaskState.SUCCESS); } else { stats = stats.withThumbnailGenerationState(ProcessingJobSubTaskState.FAILED, new Exception("thumbnailGenerationProcessingTasks is null OR empty OR imageColorMetaInfo is null")); } } catch (Exception e) { stats = stats.withThumbnailGenerationState(ProcessingJobSubTaskState.ERROR, e); } } } if (imageColorMetaInfo != null) { for (final Map.Entry<ProcessingJobSubTask, MediaFile> thumbnailEntry : generatedThumbnails.entrySet()) { generatedThumbnails.put(thumbnailEntry.getKey(), thumbnailEntry.getValue().withColorPalette(imageColorMetaInfo.getColorPalette())); } } SlaveMetrics.Worker.Slave.Processing.thumbnailStorageCounter.inc(); final Timer.Context thumbnailStorageDurationContext = SlaveMetrics.Worker.Slave.Processing.thumbnailStorageDuration.time(); try { for (final Map.Entry<ProcessingJobSubTask, MediaFile> thumbnailEntry : generatedThumbnails.entrySet()) { mediaStorageClient.createOrModify(thumbnailEntry.getValue()); } if (null == generatedThumbnails || generatedThumbnails.isEmpty()) { stats = stats.withThumbnailStorageState(ProcessingJobSubTaskState.NEVER_EXECUTED); } else { stats = stats.withThumbnailStorageState(ProcessingJobSubTaskState.SUCCESS); } } catch (Exception e) { stats = stats.withThumbnailStorageState(ProcessingJobSubTaskState.ERROR, e); } finally { thumbnailStorageDurationContext.stop(); try { } catch (Exception e) { stats = stats.withThumbnailStorageState(ProcessingJobSubTaskState.ERROR, e); } } return new ProcessingResultTuple(stats, mediaMetaInfoTuple, generatedThumbnails.values() ); } SlaveProcessor(MediaMetaInfoExtractor metaInfoExtractor, ColorExtractor colorExtractor, MediaStorageClient mediaStorageClient, String colorMapPath); }
SlaveProcessor { public ProcessingResultTuple process(final ProcessingJobTaskDocumentReference task, String originalFilePath, String originalFileUrl, byte[] originalFileContent, ResponseType responseType, ReferenceOwner referenceOwner) { final ProcessingJobSubTask colorExtractionProcessingTask = locateColorExtractionProcessingTask(task); final ProcessingJobSubTask metaExtractionProcessingTask = SlaveProcessorHack.artificialMetaInfoTask(locateMetaInfoExtractionProcessingTask(task),colorExtractionProcessingTask); final List<ProcessingJobSubTask> thumbnailGenerationProcessingTasks = locateThumbnailExtractionProcessingTask(task); ProcessingJobSubTaskStats stats = new ProcessingJobSubTaskStats(); MediaMetaInfoTuple mediaMetaInfoTuple = null; ImageMetaInfo imageColorMetaInfo = null; Map<ProcessingJobSubTask, MediaFile> generatedThumbnails = new HashMap<>(); if (null != metaExtractionProcessingTask) { try { mediaMetaInfoTuple = extractMetaInfo(originalFilePath, originalFileUrl, responseType, metaExtractionProcessingTask); if (null != mediaMetaInfoTuple && mediaMetaInfoTuple.isValid()) { stats = stats.withMetaExtractionState(ProcessingJobSubTaskState.SUCCESS); } else { stats = stats.withMetaExtractionState(ProcessingJobSubTaskState.FAILED, new Exception("mediaMetaInfoTuple is null OR mediaMetaInfoTuple is not valid")); } } catch (Exception e) { stats = stats.withMetaExtractionState(ProcessingJobSubTaskState.ERROR, e); } } if (!MediaMetaDataUtils.classifyUrl(originalFilePath).equals(ContentType.IMAGE)) { stats = stats.withColorExtractionState(ProcessingJobSubTaskState.NEVER_EXECUTED); } else if ((null != colorExtractionProcessingTask)) { try { imageColorMetaInfo = extractColor(originalFilePath); if (null != imageColorMetaInfo && null != imageColorMetaInfo.getColorPalette() && imageColorMetaInfo.getColorPalette().length > 0) { stats = stats.withColorExtractionState(ProcessingJobSubTaskState.SUCCESS); } else { stats = stats.withColorExtractionState(ProcessingJobSubTaskState.FAILED, new Exception("imageColorMetaInfo is null OR imageColorMetaInfo.colorPalette is null OR imageColorMetaInfo.colorPalette is empty")); } } catch (Exception e) { stats = stats.withColorExtractionState(ProcessingJobSubTaskState.ERROR, e); } } if (imageColorMetaInfo != null) { if (mediaMetaInfoTuple == null) mediaMetaInfoTuple = new MediaMetaInfoTuple(imageColorMetaInfo, null, null, null); else mediaMetaInfoTuple = mediaMetaInfoTuple.withImageMetaInfo(mediaMetaInfoTuple.getImageMetaInfo().withColorPalette(imageColorMetaInfo.getColorPalette())); } if ((null != thumbnailGenerationProcessingTasks) && !thumbnailGenerationProcessingTasks.isEmpty()) { if ((MediaMetaDataUtils.classifyUrl(originalFilePath).equals(ContentType.IMAGE) && (imageColorMetaInfo != null)) || MediaMetaDataUtils.classifyUrl(originalFilePath).equals(ContentType.PDF)) { try { generatedThumbnails = generateThumbnails(originalFilePath, originalFileUrl, originalFileContent, referenceOwner, thumbnailGenerationProcessingTasks); if (null != generatedThumbnails && generatedThumbnails.size() == thumbnailGenerationProcessingTasks.size()) { stats = stats.withThumbnailGenerationState(ProcessingJobSubTaskState.SUCCESS); } else { stats = stats.withThumbnailGenerationState(ProcessingJobSubTaskState.FAILED, new Exception("thumbnailGenerationProcessingTasks is null OR empty OR imageColorMetaInfo is null")); } } catch (Exception e) { stats = stats.withThumbnailGenerationState(ProcessingJobSubTaskState.ERROR, e); } } } if (imageColorMetaInfo != null) { for (final Map.Entry<ProcessingJobSubTask, MediaFile> thumbnailEntry : generatedThumbnails.entrySet()) { generatedThumbnails.put(thumbnailEntry.getKey(), thumbnailEntry.getValue().withColorPalette(imageColorMetaInfo.getColorPalette())); } } SlaveMetrics.Worker.Slave.Processing.thumbnailStorageCounter.inc(); final Timer.Context thumbnailStorageDurationContext = SlaveMetrics.Worker.Slave.Processing.thumbnailStorageDuration.time(); try { for (final Map.Entry<ProcessingJobSubTask, MediaFile> thumbnailEntry : generatedThumbnails.entrySet()) { mediaStorageClient.createOrModify(thumbnailEntry.getValue()); } if (null == generatedThumbnails || generatedThumbnails.isEmpty()) { stats = stats.withThumbnailStorageState(ProcessingJobSubTaskState.NEVER_EXECUTED); } else { stats = stats.withThumbnailStorageState(ProcessingJobSubTaskState.SUCCESS); } } catch (Exception e) { stats = stats.withThumbnailStorageState(ProcessingJobSubTaskState.ERROR, e); } finally { thumbnailStorageDurationContext.stop(); try { } catch (Exception e) { stats = stats.withThumbnailStorageState(ProcessingJobSubTaskState.ERROR, e); } } return new ProcessingResultTuple(stats, mediaMetaInfoTuple, generatedThumbnails.values() ); } SlaveProcessor(MediaMetaInfoExtractor metaInfoExtractor, ColorExtractor colorExtractor, MediaStorageClient mediaStorageClient, String colorMapPath); ProcessingResultTuple process(final ProcessingJobTaskDocumentReference task,
                                         String originalFilePath,
                                         String originalFileUrl,
                                         byte[] originalFileContent,
                                         ResponseType responseType,
                                         ReferenceOwner referenceOwner); }
SlaveProcessor { public ProcessingResultTuple process(final ProcessingJobTaskDocumentReference task, String originalFilePath, String originalFileUrl, byte[] originalFileContent, ResponseType responseType, ReferenceOwner referenceOwner) { final ProcessingJobSubTask colorExtractionProcessingTask = locateColorExtractionProcessingTask(task); final ProcessingJobSubTask metaExtractionProcessingTask = SlaveProcessorHack.artificialMetaInfoTask(locateMetaInfoExtractionProcessingTask(task),colorExtractionProcessingTask); final List<ProcessingJobSubTask> thumbnailGenerationProcessingTasks = locateThumbnailExtractionProcessingTask(task); ProcessingJobSubTaskStats stats = new ProcessingJobSubTaskStats(); MediaMetaInfoTuple mediaMetaInfoTuple = null; ImageMetaInfo imageColorMetaInfo = null; Map<ProcessingJobSubTask, MediaFile> generatedThumbnails = new HashMap<>(); if (null != metaExtractionProcessingTask) { try { mediaMetaInfoTuple = extractMetaInfo(originalFilePath, originalFileUrl, responseType, metaExtractionProcessingTask); if (null != mediaMetaInfoTuple && mediaMetaInfoTuple.isValid()) { stats = stats.withMetaExtractionState(ProcessingJobSubTaskState.SUCCESS); } else { stats = stats.withMetaExtractionState(ProcessingJobSubTaskState.FAILED, new Exception("mediaMetaInfoTuple is null OR mediaMetaInfoTuple is not valid")); } } catch (Exception e) { stats = stats.withMetaExtractionState(ProcessingJobSubTaskState.ERROR, e); } } if (!MediaMetaDataUtils.classifyUrl(originalFilePath).equals(ContentType.IMAGE)) { stats = stats.withColorExtractionState(ProcessingJobSubTaskState.NEVER_EXECUTED); } else if ((null != colorExtractionProcessingTask)) { try { imageColorMetaInfo = extractColor(originalFilePath); if (null != imageColorMetaInfo && null != imageColorMetaInfo.getColorPalette() && imageColorMetaInfo.getColorPalette().length > 0) { stats = stats.withColorExtractionState(ProcessingJobSubTaskState.SUCCESS); } else { stats = stats.withColorExtractionState(ProcessingJobSubTaskState.FAILED, new Exception("imageColorMetaInfo is null OR imageColorMetaInfo.colorPalette is null OR imageColorMetaInfo.colorPalette is empty")); } } catch (Exception e) { stats = stats.withColorExtractionState(ProcessingJobSubTaskState.ERROR, e); } } if (imageColorMetaInfo != null) { if (mediaMetaInfoTuple == null) mediaMetaInfoTuple = new MediaMetaInfoTuple(imageColorMetaInfo, null, null, null); else mediaMetaInfoTuple = mediaMetaInfoTuple.withImageMetaInfo(mediaMetaInfoTuple.getImageMetaInfo().withColorPalette(imageColorMetaInfo.getColorPalette())); } if ((null != thumbnailGenerationProcessingTasks) && !thumbnailGenerationProcessingTasks.isEmpty()) { if ((MediaMetaDataUtils.classifyUrl(originalFilePath).equals(ContentType.IMAGE) && (imageColorMetaInfo != null)) || MediaMetaDataUtils.classifyUrl(originalFilePath).equals(ContentType.PDF)) { try { generatedThumbnails = generateThumbnails(originalFilePath, originalFileUrl, originalFileContent, referenceOwner, thumbnailGenerationProcessingTasks); if (null != generatedThumbnails && generatedThumbnails.size() == thumbnailGenerationProcessingTasks.size()) { stats = stats.withThumbnailGenerationState(ProcessingJobSubTaskState.SUCCESS); } else { stats = stats.withThumbnailGenerationState(ProcessingJobSubTaskState.FAILED, new Exception("thumbnailGenerationProcessingTasks is null OR empty OR imageColorMetaInfo is null")); } } catch (Exception e) { stats = stats.withThumbnailGenerationState(ProcessingJobSubTaskState.ERROR, e); } } } if (imageColorMetaInfo != null) { for (final Map.Entry<ProcessingJobSubTask, MediaFile> thumbnailEntry : generatedThumbnails.entrySet()) { generatedThumbnails.put(thumbnailEntry.getKey(), thumbnailEntry.getValue().withColorPalette(imageColorMetaInfo.getColorPalette())); } } SlaveMetrics.Worker.Slave.Processing.thumbnailStorageCounter.inc(); final Timer.Context thumbnailStorageDurationContext = SlaveMetrics.Worker.Slave.Processing.thumbnailStorageDuration.time(); try { for (final Map.Entry<ProcessingJobSubTask, MediaFile> thumbnailEntry : generatedThumbnails.entrySet()) { mediaStorageClient.createOrModify(thumbnailEntry.getValue()); } if (null == generatedThumbnails || generatedThumbnails.isEmpty()) { stats = stats.withThumbnailStorageState(ProcessingJobSubTaskState.NEVER_EXECUTED); } else { stats = stats.withThumbnailStorageState(ProcessingJobSubTaskState.SUCCESS); } } catch (Exception e) { stats = stats.withThumbnailStorageState(ProcessingJobSubTaskState.ERROR, e); } finally { thumbnailStorageDurationContext.stop(); try { } catch (Exception e) { stats = stats.withThumbnailStorageState(ProcessingJobSubTaskState.ERROR, e); } } return new ProcessingResultTuple(stats, mediaMetaInfoTuple, generatedThumbnails.values() ); } SlaveProcessor(MediaMetaInfoExtractor metaInfoExtractor, ColorExtractor colorExtractor, MediaStorageClient mediaStorageClient, String colorMapPath); ProcessingResultTuple process(final ProcessingJobTaskDocumentReference task,
                                         String originalFilePath,
                                         String originalFileUrl,
                                         byte[] originalFileContent,
                                         ResponseType responseType,
                                         ReferenceOwner referenceOwner);  }