/** * Returns value of ReferenceData as a String. * @param dataSource for use in retrieving data stored for {@code referencedData} * @param referencedData the ReferencedData to retrieve value for * @return string representation of the value for provided {@code referencedData} */ public static String getContentAsStringEx(final DataSource dataSource, final ReferencedData referencedData) { try { return getContentAsString(dataSource, referencedData); } catch (DataSourceException dse) { throw new TaskFailedException("Failed to retrieve content from storage", dse); } catch (IOException ioe) { throw new TaskFailedException("Failed to read input stream from storage", ioe); } }
public <T> byte[] serialiseResult(final T result) { try { return codec.serialise(result); } catch (final CodecException e) { throw new TaskFailedException("Failed to serialise result", e); } }
/** * Extracts the signatures from the content of each field in the task. * * @param emailSegregation The email content segregation library. * @param signature The SelectedEmailSignature that specifies the sender of the email. * @return The BoilerplateWorkerResponse with the email signatures extracted and if RedactionType.REMOVE * was set on the task the content with the signatures removed. */ public BoilerplateWorkerResponse extractSignatures(EmailSegregation emailSegregation, SelectedEmailSignature signature) { Multimap<String, ReferencedData> sourceData = task.getSourceData(); DataSource dataSource = new DataStoreSource(dataStore, codec); BoilerplateWorkerResponse boilerplateWorkerResponse = new BoilerplateWorkerResponse(); boilerplateWorkerResponse.setTaskResults(new HashMap<>()); for (Map.Entry<String, ReferencedData> referencedDataEntry : sourceData.entries()) { try { String content = IOUtils.toString(referencedDataEntry.getValue().acquire(dataSource)); boilerplateWorkerResponse.getTaskResults().put(referencedDataEntry.getKey(), extractSignatureForField(content, signature, emailSegregation)); } catch (DataSourceException e) { throw new TaskFailedException("Failed to retrieve content from storage.", e); } catch (IOException e) { throw new TaskFailedException("Failed to read input stream from storage.", e); } catch (InterruptedException | ExecutionException e) { throw new TaskFailedException("Jep Python thread encountered an error.", e); } catch (DataStoreException e) { throw new TaskFailedException("Failed to store content to storage.", e); } } return boilerplateWorkerResponse; }
throw new TaskFailedException("Call to external Python Library failed.", e); } catch (EmailExpressionParserException e) { throw new TaskFailedException("Invalid SelectedEmail expression", e); } catch (InterruptedException | ExecutionException e) { throw new TaskFailedException("Python thread encountered an error.", e); } catch (DataStoreException e) { throw new TaskFailedException("Failed to store data.", e);
/** * Utility method for creating a WorkerReponse that represents a failed result with context data. * * @param result the result from the Worker * @param context the context entries to add to the published message * @return a WorkerResponse that represents a failed result containing the specified task-specific serialised message */ protected final WorkerResponse createFailureResult(final V result, final byte[] context) { try { byte[] data = (result != null ? getCodec().serialise(result) : new byte[]{}); return new WorkerResponse(getResultQueue(), TaskStatus.RESULT_FAILURE, data, getWorkerIdentifier(), getWorkerApiVersion(), context); } catch (CodecException e) { throw new TaskFailedException("Failed to serialise result", e); } }
/** * Utility method for creating a WorkerReponse that represents a successful result with context data. * * @param result the result from the Worker * @param context the context entries to add to the published message * @return a WorkerResponse that represents a successful result containing the specified task-specific serialised message */ protected final WorkerResponse createSuccessResult(final V result, final byte[] context) { try { byte[] data = (result != null ? getCodec().serialise(result) : new byte[]{}); return new WorkerResponse(getResultQueue(), TaskStatus.RESULT_SUCCESS, data, getWorkerIdentifier(), getWorkerApiVersion(), context); } catch (CodecException e) { throw new TaskFailedException("Failed to serialise result", e); } }
/** * Utility method for creating a WorkerReponse that represents a successful result and reports complete. * * @param result the result from the Worker * @return a WorkerResponse that represents a successful result containing the specified task-specific serialised message */ protected final WorkerResponse createSuccessAndCompleteResponse(final V result) { final String outputQueue = getResultQueue(); try { final byte[] data = (result != null ? getCodec().serialise(result) : new byte[]{}); return new WorkerResponse(outputQueue, TaskStatus.RESULT_SUCCESS, data, getWorkerIdentifier(), getWorkerApiVersion(), null, outputQueue); } catch (CodecException e) { throw new TaskFailedException("Failed to serialise result", e); } }