Search in sources :

Example 6 with DocumentData

use of org.kie.workbench.common.forms.jbpm.model.document.DocumentData in project kie-wb-common by kiegroup.

the class FormsDocumentServlet method doPost.

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    Map<String, Object> response = new HashMap<>();
    try {
        FileItem fileItem = getFileItem(req);
        String id = UUID.randomUUID().toString();
        String content = Base64.getEncoder().encodeToString(fileItem.get());
        DocumentUploadChunk chunk = new DocumentUploadChunk(id, fileItem.getName(), 0, 1, content);
        DocumentUploadSession session = new DocumentUploadSession(chunk.getDocumentId(), chunk.getDocumentName(), chunk.getMaxChunks());
        session.add(chunk);
        storage.uploadContentChunk(chunk);
        session.setState(DocumentUploadSession.State.MERGING);
        storage.merge(session);
        DocumentData data = new DocumentData(id, fileItem.getName(), fileItem.getSize(), "", System.currentTimeMillis());
        response.put("document", data);
    } catch (Exception e) {
        response.put("error", "error");
    } finally {
        writeResponse(resp, response);
    }
}
Also used : FileItem(org.apache.commons.fileupload.FileItem) DocumentData(org.kie.workbench.common.forms.jbpm.model.document.DocumentData) DocumentUploadSession(org.kie.workbench.common.forms.jbpm.server.service.impl.documents.DocumentUploadSession) HashMap(java.util.HashMap) DocumentUploadChunk(org.kie.workbench.common.forms.jbpm.service.shared.documents.DocumentUploadChunk) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 7 with DocumentData

use of org.kie.workbench.common.forms.jbpm.model.document.DocumentData in project kie-wb-common by kiegroup.

the class DocumentFieldValueMarshallerTest method testNull2FlatValue.

@Test
public void testNull2FlatValue() {
    marshaller.init(null, field, form, context);
    DocumentData documentData = marshaller.toFlatValue();
    assertNull("DocumentData must be null!", documentData);
}
Also used : DocumentData(org.kie.workbench.common.forms.jbpm.model.document.DocumentData) Test(org.junit.Test)

Example 8 with DocumentData

use of org.kie.workbench.common.forms.jbpm.model.document.DocumentData in project kie-wb-common by kiegroup.

the class DocumentFieldValueMarshallerTest method testDocument2FlatValue.

@Test
public void testDocument2FlatValue() {
    Document doc = spy(new DocumentImpl(DOCUMENT_ID, "docName", 1024, new Date()));
    Map result = new HashMap();
    result.put(DocumentFieldValueMarshaller.SERVER_TEMPLATE_ID, SERVER_TEMPLATE_ID);
    when(context.getAttributes()).thenReturn(result);
    marshaller.init(doc, field, form, context);
    DocumentData documentData = marshaller.toFlatValue();
    verify(doc, never()).getLink();
    assertNotNull(documentData);
    assertEquals(doc.getName(), documentData.getFileName());
    assertEquals(doc.getSize(), documentData.getSize());
    assertEquals(EXPECTED_DOWNLOAD_LINK, documentData.getLink());
}
Also used : DocumentData(org.kie.workbench.common.forms.jbpm.model.document.DocumentData) HashMap(java.util.HashMap) Document(org.jbpm.document.Document) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date) Test(org.junit.Test)

Example 9 with DocumentData

use of org.kie.workbench.common.forms.jbpm.model.document.DocumentData in project kie-wb-common by kiegroup.

the class DocumentCollectionFieldValueMarshallerTest method testDocuments2FlatValue.

@Test
public void testDocuments2FlatValue() {
    Document doc = spy(new DocumentImpl(DOCUMENT_ID, "docName", 1024, new Date()));
    Map result = new HashMap();
    result.put(DocumentFieldValueMarshaller.SERVER_TEMPLATE_ID, SERVER_TEMPLATE_ID);
    when(context.getAttributes()).thenReturn(result);
    documentCollection.addDocument(doc);
    marshaller.init(documentCollection, field, form, context);
    Collection<DocumentData> documents = marshaller.toFlatValue();
    Assertions.assertThat(documents).isNotNull().hasSize(1);
    Assertions.assertThat(documents.iterator().next()).isNotNull().hasFieldOrPropertyWithValue("status", DocumentStatus.STORED).hasFieldOrPropertyWithValue("contentId", DOCUMENT_ID).hasFieldOrPropertyWithValue("fileName", doc.getName()).hasFieldOrPropertyWithValue("size", doc.getSize()).hasFieldOrPropertyWithValue("link", EXPECTED_DOWNLOAD_LINK);
}
Also used : DocumentData(org.kie.workbench.common.forms.jbpm.model.document.DocumentData) HashMap(java.util.HashMap) Document(org.jbpm.document.Document) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) HashMap(java.util.HashMap) Map(java.util.Map) Date(java.util.Date) Test(org.junit.Test)

Example 10 with DocumentData

use of org.kie.workbench.common.forms.jbpm.model.document.DocumentData in project kie-wb-common by kiegroup.

the class DocumentCollectionFieldValueMarshallerTest method testNewFlatValue2Documents.

@Test
public void testNewFlatValue2Documents() {
    marshaller.init(null, field, form, context);
    DocumentData data = new DocumentData(DOCUMENT_ID, 1024, null);
    data.setContentId("content");
    DocumentCollection<Document> documents = marshaller.toRawValue(Collections.singletonList(data));
    verify(documentStorage).getContent(Mockito.<String>any());
    verify(documentStorage).removeContent(Mockito.<String>any());
    Assertions.assertThat(documents).isNotNull().isInstanceOf(expectedType);
    Assertions.assertThat(documents.getDocuments()).isNotNull().hasSize(1);
}
Also used : DocumentData(org.kie.workbench.common.forms.jbpm.model.document.DocumentData) Document(org.jbpm.document.Document) Test(org.junit.Test)

Aggregations

DocumentData (org.kie.workbench.common.forms.jbpm.model.document.DocumentData)18 Test (org.junit.Test)13 Document (org.jbpm.document.Document)10 Date (java.util.Date)8 DocumentImpl (org.jbpm.document.service.impl.DocumentImpl)8 HashMap (java.util.HashMap)3 List (java.util.List)3 DocumentPreview (org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreview)3 File (elemental2.dom.File)2 Map (java.util.Map)2 Document (org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.js.Document)2 DocumentPreviewStateAction (org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreviewStateAction)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 ValueChangeEvent (com.google.gwt.event.logical.shared.ValueChangeEvent)1 ValueChangeHandler (com.google.gwt.event.logical.shared.ValueChangeHandler)1 GwtEvent (com.google.gwt.event.shared.GwtEvent)1 HandlerRegistration (com.google.gwt.event.shared.HandlerRegistration)1 JSONObject (com.google.gwt.json.client.JSONObject)1 IsWidget (com.google.gwt.user.client.ui.IsWidget)1 Widget (com.google.gwt.user.client.ui.Widget)1