public void updateDocument(String documentId, String documentPayload, String marshallingType) { logger.debug("About to unmarshal document payload '{}' with marshaling type {}", documentPayload, marshallingType); DocumentInstance documentInstance = marshallerHelper.unmarshal(documentPayload, marshallingType, DocumentInstance.class); logger.debug("Document created from payload {}", documentInstance); Document document = documentStorageService.getDocument(documentId); logger.debug("Document found {}", documentInstance != null); if (document == null) { throw new KieServerRuntimeException("No document found with id " + documentId); } documentStorageService.saveDocument(document, documentInstance.getContent()); logger.debug("Document {} updated successfully", document); }
public String storeDocument(String documentPayload, String marshallingType) { logger.debug("About to unmarshal document payload '{}' with marshaling type {}", documentPayload, marshallingType); DocumentInstance documentInstance = marshallerHelper.unmarshal(documentPayload, marshallingType, DocumentInstance.class); logger.debug("Document created from payload {}", documentInstance); Document document = documentStorageService.buildDocument(documentInstance.getName(), documentInstance.getSize(), documentInstance.getLastModified(), new HashMap<String, String>()); logger.debug("Document created by the service {}", document); documentStorageService.saveDocument(document, documentInstance.getContent()); logger.debug("Document {} stored successfully", document); return document.getIdentifier(); }
response.setHeader("Content-Disposition", "attachment; filename=\"" + documentInstance.getName() + "\""); response.getOutputStream().write(documentInstance.getContent()); } else { logger.error(MessageFormat.format(INVALID_DOCUMENT,
response.setHeader("Content-Disposition", "attachment; filename=\"" + documentInstance.getName() + "\""); response.getOutputStream().write(documentInstance.getContent()); } else { logger.error(MessageFormat.format(INVALID_DOCUMENT,
@Test public void testRetrieveValidDocument() throws Exception { when(kieServerIntegration.getServerClient(anyString())).thenReturn(kieServicesClient); when(kieServicesClient.getServicesClient(any())).thenReturn(documentServicesClient); when(documentServicesClient.getDocument(anyString())).thenReturn(documentInstance); when(documentInstance.getName()).thenReturn("testdoc.properties"); when(documentInstance.getContent()).thenReturn("sampleContent".getBytes()); HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); when(request.getParameter("templateid")).thenReturn("kie-server-id"); when(request.getParameter("docid")).thenReturn("AAAA-BBBB-CCCC-DDDD"); ProcessDocumentServletTest.StubServletOutputStream stubServletOutputStream = new ProcessDocumentServletTest.StubServletOutputStream(); when(response.getOutputStream()).thenReturn(stubServletOutputStream); ProcessDocumentServlet processDocServlet = new ProcessDocumentServlet(); processDocServlet.setKieServerIntegration(kieServerIntegration); processDocServlet.doGet(request, response); assertNotNull(response.getOutputStream()); assertEquals("sampleContent", new String(((ProcessDocumentServletTest.StubServletOutputStream) response.getOutputStream()).getContent())); }
@Test public void testRetrieveValidDocument() throws Exception { when(kieServerIntegration.getServerClient(anyString())).thenReturn(kieServicesClient); when(kieServicesClient.getServicesClient(any())).thenReturn(documentServicesClient); when(documentServicesClient.getDocument(anyString())).thenReturn(documentInstance); when(documentInstance.getName()).thenReturn("testdoc.properties"); when(documentInstance.getContent()).thenReturn("sampleContent".getBytes()); HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); when(request.getParameter("templateid")).thenReturn("kie-server-id"); when(request.getParameter("docid")).thenReturn("AAAA-BBBB-CCCC-DDDD"); ProcessDocumentServletTest.StubServletOutputStream stubServletOutputStream = new ProcessDocumentServletTest.StubServletOutputStream(); when(response.getOutputStream()).thenReturn(stubServletOutputStream); ProcessDocumentServlet processDocServlet = new ProcessDocumentServlet(); processDocServlet.setKieServerIntegration(kieServerIntegration); processDocServlet.doGet(request, response); assertNotNull(response.getOutputStream()); assertEquals("sampleContent", new String(((ProcessDocumentServletTest.StubServletOutputStream) response.getOutputStream()).getContent())); }
private void assertDocumentInstances(DocumentInstance expected, DocumentInstance actual, boolean assertContent) { assertNotNull(actual); assertNotNull(actual.getIdentifier()); assertNotNull(actual.getName()); assertNotNull(actual.getLastModified()); assertNotNull(actual.getSize()); assertEquals(expected.getName(), actual.getName()); assertEquals(expected.getSize(), actual.getSize()); if (assertContent) { assertEquals(new String(expected.getContent()), new String(actual.getContent())); } }
docToTranslate.setContent(document.getContent()); docToTranslate.setLastModified(document.getLastModified()); docToTranslate.setName(document.getName());