@Test public void testLinkGenerationFailure() { Assertions.assertThatThrownBy(() -> DocumentDownloadLinkGenerator.generateDownloadLink(null, DOC_ID)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("ServerTemplateId cannot be null"); Assertions.assertThatThrownBy(() -> DocumentDownloadLinkGenerator.generateDownloadLink(TEMPLATE_ID, null)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("DocumentIdentifier cannot be null"); }
@Test public void testLinkGeneration() { Assertions.assertThat(DocumentDownloadLinkGenerator.generateDownloadLink(TEMPLATE_ID, DOC_ID)) .doesNotContain(DocumentDownloadLinkGenerator.TEMPLATE_ID_TOKEN) .doesNotContain(DocumentDownloadLinkGenerator.DOCUMENT_ID_TOKEN) .contains(TEMPLATE_ID) .contains(DOC_ID); } }
private List<DocumentSummary> getDocuments(QueryFilter filter) throws NumberFormatException { String serverTemplateId = (String) filter.getParams().get("serverTemplateId"); Collection<ProcessVariableSummary> processVariables = processVariablesService.getData(filter).getPageRowList(); SimpleDateFormat sdf = new SimpleDateFormat(Document.DOCUMENT_DATE_PATTERN); List<DocumentSummary> documents = new ArrayList<DocumentSummary>(); for (ProcessVariableSummary pv : processVariables) { if (JBPM_DOCUMENT.equals(pv.getType()) && pv.getNewValue() != null && !pv.getNewValue().isEmpty()) { String[] values = pv.getNewValue().split(Document.PROPERTIES_SEPARATOR); if (values.length == 4) { Date lastModified = null; try { lastModified = sdf.parse(values[2]); } catch (ParseException ex) { logger.error("Can not parse last modified date!", ex); } documents.add(new DocumentSummary(values[0], lastModified, Long.valueOf(values[1]), DocumentDownloadLinkGenerator.generateDownloadLink(serverTemplateId, values[3]))); } } } return documents; }
private List<DocumentSummary> getDocuments(QueryFilter filter) throws NumberFormatException { String serverTemplateId = (String) filter.getParams().get("serverTemplateId"); Collection<ProcessVariableSummary> processVariables = processVariablesService.getData(filter).getPageRowList(); SimpleDateFormat sdf = new SimpleDateFormat(Document.DOCUMENT_DATE_PATTERN); List<DocumentSummary> documents = new ArrayList<DocumentSummary>(); for (ProcessVariableSummary pv : processVariables) { if (JBPM_DOCUMENT.equals(pv.getType()) && pv.getNewValue() != null && !pv.getNewValue().isEmpty()) { String[] values = pv.getNewValue().split(Document.PROPERTIES_SEPARATOR); if (values.length == 4) { Date lastModified = null; try { lastModified = sdf.parse(values[2]); } catch (ParseException ex) { logger.error("Can not parse last modified date!", ex); } documents.add(new DocumentSummary(values[0], lastModified, Long.valueOf(values[1]), DocumentDownloadLinkGenerator.generateDownloadLink(serverTemplateId, values[3]))); } } } return documents; }
@Test public void testLinkGenerationFailure() { Assertions.assertThatThrownBy(() -> DocumentDownloadLinkGenerator.generateDownloadLink(null, DOC_ID)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("ServerTemplateId cannot be null"); Assertions.assertThatThrownBy(() -> DocumentDownloadLinkGenerator.generateDownloadLink(TEMPLATE_ID, null)) .isInstanceOf(IllegalArgumentException.class) .hasMessageContaining("DocumentIdentifier cannot be null"); }
@Override public DocumentData toFlatValue() { if (originalValue == null) { return null; } String templateId = (String) context.getAttributes().get(SERVER_TEMPLATE_ID); String link; if (!StringUtils.isEmpty(templateId) & !StringUtils.isEmpty(originalValue.getIdentifier())) { link = DocumentDownloadLinkGenerator.generateDownloadLink(templateId, originalValue.getIdentifier()); } else { link = originalValue.getLink(); } DocumentData data = new DocumentData(originalValue.getIdentifier(), originalValue.getName(), originalValue.getSize(), link); data.setStatus(DocumentStatus.STORED); return data; }
@Test public void testLinkGeneration() { Assertions.assertThat(DocumentDownloadLinkGenerator.generateDownloadLink(TEMPLATE_ID, DOC_ID)) .doesNotContain(DocumentDownloadLinkGenerator.TEMPLATE_ID_TOKEN) .doesNotContain(DocumentDownloadLinkGenerator.DOCUMENT_ID_TOKEN) .contains(TEMPLATE_ID) .contains(DOC_ID); } }
@Test public void testGetInputHTMLReadOnly() { String result = handler.getInputHTML(document, field, FIELD_NAME, NAMESPACE, true); Assertions.assertThat(result).isNotNull() .isNotEmpty() .contains(FILE_INPUT) .contains("disabled=\"disabled\"") .contains(DocumentDownloadLinkGenerator.generateDownloadLink(SERVER_TEMPLATE_ID, DOC_ID)); }
@Test public void testGetInputHTML() { String result = handler.getInputHTML(document, field, FIELD_NAME, NAMESPACE, false); Assertions.assertThat(result).isNotNull() .isNotEmpty() .contains(FILE_INPUT) .contains(DocumentDownloadLinkGenerator.generateDownloadLink(SERVER_TEMPLATE_ID, DOC_ID)); }
@Test public void testGetShowHTML() { String result = handler.getShowHTML(document, field, FIELD_NAME, NAMESPACE); Assertions.assertThat(result).isNotNull() .isNotEmpty() .doesNotContain(FILE_INPUT) .contains(DocumentDownloadLinkGenerator.generateDownloadLink(SERVER_TEMPLATE_ID, DOC_ID)); }
@Test public void testGetInputHTMLNullDocument() { String result = handler.getInputHTML(null, field, FIELD_NAME, NAMESPACE, false); Assertions.assertThat(result).isNotNull() .isNotEmpty() .contains(FILE_INPUT) .doesNotContain(DocumentDownloadLinkGenerator.generateDownloadLink(SERVER_TEMPLATE_ID, DOC_ID)); }
@Test public void testGetInputHTMLEmptyDocumentId() { document.setIdentifier(null); String result = handler.getInputHTML(document, field, FIELD_NAME, NAMESPACE, false); Assertions.assertThat(result).isNotNull() .isNotEmpty() .contains(FILE_INPUT) .doesNotContain(DocumentDownloadLinkGenerator.generateDownloadLink(SERVER_TEMPLATE_ID, DOC_ID)); }
@Test public void testGetShowHTMLNullDocument() { String result = handler.getShowHTML(null, field, FIELD_NAME, NAMESPACE); Assertions.assertThat(result).isNotNull() .isNotEmpty() .doesNotContain(FILE_INPUT) .doesNotContain(DocumentDownloadLinkGenerator.generateDownloadLink(SERVER_TEMPLATE_ID, DOC_ID)); }
@Test public void testGetShowHTMLEmptyDocumentId() { document.setIdentifier(null); String result = handler.getShowHTML(document, field, FIELD_NAME, NAMESPACE); Assertions.assertThat(result).isNotNull() .isNotEmpty() .doesNotContain(FILE_INPUT) .doesNotContain(DocumentDownloadLinkGenerator.generateDownloadLink(SERVER_TEMPLATE_ID, DOC_ID)); } }