@Override public Document attachDocument(final long processInstanceId, final String documentName, final String fileName, final String mimeType, final String url) throws DocumentAttachmentException { final DocumentValue documentValue = new DocumentValue(url); documentValue.setFileName(fileName); documentValue.setMimeType(mimeType); try { return addDocument(processInstanceId, documentName, null, documentValue); } catch (final BonitaException e) { throw new DocumentAttachmentException(e); } }
private SDocument buildSDocument(final DocumentValue documentValue) { if (documentValue.hasContent()) { return buildProcessDocument(documentValue.getFileName(), documentValue.getMimeType(), getUserId(), documentValue.getContent()); } return buildExternalProcessDocumentReference(documentValue.getFileName(), documentValue.getMimeType(), getUserId(), documentValue.getUrl()); }
public void setContent(final byte[] content) { hasContent = true; this.content = content; checkIfTheFileNameIsFilledForADocumentWithContent(); }
String getMimeTypeOrGuessIt(DocumentValue documentValue) { final String mimeType = documentValue.getMimeType(); final byte[] content = documentValue.getContent(); final String fileName = documentValue.getFileName(); if (mimeType != null && !mimeType.isEmpty() || content == null || fileName == null || fileName.isEmpty()) { return mimeType; } try { final File tempFile = File.createTempFile("tmp", fileName); IOUtil.write(tempFile, content); final String s = Files.probeContentType(tempFile.toPath()); tempFile.delete(); return s; } catch (Throwable e) { return mimeType; } }
/** * Test method for {@link org.bonitasoft.engine.bpm.document.DocumentValue#setFileName(java.lang.String)}. */ @Test public final void setFileName_should_set_content_with_filename_and_content() { // Given final DocumentValue documentValue = new DocumentValue("yujyt".getBytes(), "mimeType", "filename"); final String fileName = "new"; // When documentValue.setFileName(fileName); // Then assertEquals(fileName, documentValue.getFileName()); }
@Override public Document attachDocument(final long processInstanceId, final String documentName, final String fileName, final String mimeType, final byte[] documentContent) throws DocumentAttachmentException { final DocumentValue documentValue = new DocumentValue(documentContent, mimeType, fileName); try { return addDocument(processInstanceId, documentName, null, documentValue); } catch (final BonitaException e) { throw new DocumentAttachmentException(e); } }
/** * Test method for {@link org.bonitasoft.engine.bpm.document.DocumentValue#setContent(byte[])}. */ @Test public final void setContent_should_set_content_with_filename_and_content() { // Given final DocumentValue documentValue = new DocumentValue("yujyt".getBytes(), "mimeType", "filename"); final byte[] content = "plop".getBytes(); // When documentValue.setContent(content); // Then assertEquals(content, documentValue.getContent()); }
/** * Test method for {@link org.bonitasoft.engine.bpm.document.DocumentValue#setFileName(java.lang.String)}. */ @Test(expected = IllegalArgumentException.class) public final void setFileName_should_throw_exception_if_filename_is_empty_and_content_not() { // Given final DocumentValue documentValue = new DocumentValue("yujyt".getBytes(), "mimeType", "filename"); // When documentValue.setFileName(""); }
/** * Test method for {@link org.bonitasoft.engine.bpm.document.DocumentValue#setContent(byte[])}. */ @Test(expected = IllegalArgumentException.class) public final void setContent_should_throw_exception_if_filename_is_null_and_content_not() { // Given final DocumentValue documentValue = new DocumentValue(2); // When documentValue.setContent("plop".getBytes()); }
@Override public Object update(final SLeftOperand sLeftOperand, Map<String, Object> inputValues, final Object newValue, final long containerId, final String containerType) throws SOperationExecutionException { final DocumentValue documentValue = documentHelper.toCheckedDocumentValue(newValue); final String documentName = sLeftOperand.getName(); long processInstanceId; try { processInstanceId = getProcessInstanceId(containerId, containerType); if (newValue == null) { // we just delete the current version documentHelper.deleteDocument(documentName, processInstanceId); } else { if (documentValue.getDocumentId() != null && !documentValue.hasChanged()) { //do not update if the document value say it did not changed return newValue; } documentHelper.createOrUpdateDocument(documentValue, documentName, processInstanceId, getAuthorId(containerId, containerType), null); } return newValue; } catch (final SBonitaException e) { throw new SOperationExecutionException(e); } }
void updateExistingDocument(final SMappedDocument documentToUpdate, final int index, final DocumentValue documentValue, final long authorId) throws SObjectModificationException { if (documentValue.hasChanged()) { documentService.updateDocumentOfList(documentToUpdate, createDocumentObject(documentValue, authorId), index); } else { // update the index if needed if (documentToUpdate.getIndex() != index) { documentService.updateDocumentIndex(documentToUpdate, index); } } }
void processDocumentOnIndex(final DocumentValue documentValue, final String documentName, final long processInstanceId, final List<SMappedDocument> currentList, final int index, final long authorId) throws SObjectCreationException, SObjectAlreadyExistsException, SObjectNotFoundException, SObjectModificationException { if (documentValue.getDocumentId() != null) { // if hasChanged update final SMappedDocument documentToUpdate = getDocumentHavingDocumentIdAndRemoveFromList(currentList, documentValue.getDocumentId(), documentName, processInstanceId); updateExistingDocument(documentToUpdate, index, documentValue, authorId); } else { // create new element documentService.attachDocumentToProcessInstance(createDocumentObject(documentValue, authorId), processInstanceId, documentName, null, index); } }
tenantAccessor.getProcessInstanceService()); final SDocument sDocument = buildSDocument(documentValue); int index = documentValue.getIndex(); try { if (documentHelper.isListDefinedInDefinition(documentName, processInstanceId)) {
@Override public Document attachDocument(final long processInstanceId, final String documentName, final String fileName, final String mimeType, final byte[] documentContent) throws DocumentAttachmentException { final DocumentValue documentValue = new DocumentValue(documentContent, mimeType, fileName); try { return addDocument(processInstanceId, documentName, null, documentValue); } catch (final BonitaException e) { throw new DocumentAttachmentException(e); } }
String getMimeTypeOrGuessIt(DocumentValue documentValue) { final String mimeType = documentValue.getMimeType(); final byte[] content = documentValue.getContent(); final String fileName = documentValue.getFileName(); if (mimeType != null && !mimeType.isEmpty() || content == null || fileName == null || fileName.isEmpty()) { return mimeType; } try { final File tempFile = File.createTempFile("tmp", fileName); IOUtil.write(tempFile, content); final String s = Files.probeContentType(tempFile.toPath()); tempFile.delete(); return s; } catch (Throwable e) { return mimeType; } }
/** * Test method for {@link org.bonitasoft.engine.bpm.document.DocumentValue#setFileName(java.lang.String)}. */ @Test(expected = IllegalArgumentException.class) public final void setFileName_should_throw_exception_if_filename_is_null_and_content_not() { // Given final DocumentValue documentValue = new DocumentValue("yujyt".getBytes(), "mimeType", "filename"); // When documentValue.setFileName(null); }
/** * Test method for {@link org.bonitasoft.engine.bpm.document.DocumentValue#setContent(byte[])}. */ @Test(expected = IllegalArgumentException.class) public final void setContent_should_throw_exception_if_filename_is_empty_and_content_not() { // Given final DocumentValue documentValue = new DocumentValue(2); // When documentValue.setContent("plop".getBytes()); }
@Override public Object update(final SLeftOperand sLeftOperand, Map<String, Object> inputValues, final Object newValue, final long containerId, final String containerType) throws SOperationExecutionException { final DocumentValue documentValue = documentHelper.toCheckedDocumentValue(newValue); final String documentName = sLeftOperand.getName(); long processInstanceId; try { processInstanceId = getProcessInstanceId(containerId, containerType); if (newValue == null) { // we just delete the current version documentHelper.deleteDocument(documentName, processInstanceId); } else { if (documentValue.getDocumentId() != null && !documentValue.hasChanged()) { //do not update if the document value say it did not changed return newValue; } documentHelper.createOrUpdateDocument(documentValue, documentName, processInstanceId, getAuthorId(containerId, containerType), null); } return newValue; } catch (final SBonitaException e) { throw new SOperationExecutionException(e); } }
void updateExistingDocument(final SMappedDocument documentToUpdate, final int index, final DocumentValue documentValue, final long authorId) throws SObjectModificationException { if (documentValue.hasChanged()) { documentService.updateDocumentOfList(documentToUpdate, createDocumentObject(documentValue, authorId), index); } else { // update the index if needed if (documentToUpdate.getIndex() != index) { documentService.updateDocumentIndex(documentToUpdate, index); } } }
void processDocumentOnIndex(final DocumentValue documentValue, final String documentName, final long processInstanceId, final List<SMappedDocument> currentList, final int index, final long authorId) throws SObjectCreationException, SObjectAlreadyExistsException, SObjectNotFoundException, SObjectModificationException { if (documentValue.getDocumentId() != null) { // if hasChanged update final SMappedDocument documentToUpdate = getDocumentHavingDocumentIdAndRemoveFromList(currentList, documentValue.getDocumentId(), documentName, processInstanceId); updateExistingDocument(documentToUpdate, index, documentValue, authorId); } else { // create new element documentService.attachDocumentToProcessInstance(createDocumentObject(documentValue, authorId), processInstanceId, documentName, null, index); } }