Search in sources :

Example 11 with DocumentData

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

the class DocumentCollectionFieldValueMarshallerTest method testExistingFlatValue2Documents.

@Test
public void testExistingFlatValue2Documents() {
    Document doc = new DocumentImpl(DOCUMENT_ID, "docName", 1024, new Date(), "aLink");
    documentCollection.addDocument(doc);
    marshaller.init(documentCollection, field, form, context);
    DocumentData data = new DocumentData(doc.getName(), doc.getSize(), doc.getLink());
    data.setStatus(DocumentStatus.STORED);
    DocumentCollection<Document> rawDocuments = marshaller.toRawValue(Collections.singletonList(data));
    Assertions.assertThat(rawDocuments).isSameAs(documentCollection).isInstanceOf(expectedType);
    verify(documentStorage, never()).getContent(Mockito.<String>any());
    verify(documentStorage, never()).removeContent(Mockito.<String>any());
}
Also used : DocumentData(org.kie.workbench.common.forms.jbpm.model.document.DocumentData) Document(org.jbpm.document.Document) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) Date(java.util.Date) Test(org.junit.Test)

Example 12 with DocumentData

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

the class DocumentFieldValueMarshaller method fromDocument.

static DocumentData fromDocument(Document document, String templateId) {
    String link;
    if (!StringUtils.isEmpty(templateId) && !StringUtils.isEmpty(document.getIdentifier())) {
        link = DocumentDownloadLinkGenerator.generateDownloadLink(templateId, document.getIdentifier());
    } else {
        link = document.getLink();
    }
    DocumentData data = new DocumentData(document.getIdentifier(), document.getName(), document.getSize(), link, document.getLastModified().getTime());
    data.setStatus(DocumentStatus.STORED);
    return data;
}
Also used : DocumentData(org.kie.workbench.common.forms.jbpm.model.document.DocumentData)

Example 13 with DocumentData

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

the class DocumentUploadTest method testDrop.

@Test
public void testDrop() {
    Document doc = mock(Document.class);
    when(doc.getId()).thenReturn(DOC_1);
    when(doc.getName()).thenReturn(DOC_1);
    when(doc.getSize()).thenReturn(1024);
    when(doc.getLastModified()).thenReturn((double) System.currentTimeMillis());
    File file = mock(File.class);
    documentUpload.doUpload(doc, file);
    verify(instance).get();
    verify(view).addDocument(any());
    List<DocumentPreview> previews = (List<DocumentPreview>) documentUpload.getCurrentPreviews();
    Assertions.assertThat(previews).isNotNull().hasSize(1);
    ArgumentCaptor<DocumentData> documentDataArgumentCaptor = ArgumentCaptor.forClass(DocumentData.class);
    DocumentPreview preview = previews.get(0);
    verify(preview).init(documentDataArgumentCaptor.capture());
    DocumentData documentData = documentDataArgumentCaptor.getValue();
    Assertions.assertThat(documentData).isNotNull().hasFieldOrPropertyWithValue("contentId", DOC_1).hasFieldOrPropertyWithValue("fileName", DOC_1).hasFieldOrPropertyWithValue("size", Long.valueOf(1024));
    ArgumentCaptor<DocumentPreviewStateActionsHandler> handlerCaptor = ArgumentCaptor.forClass(DocumentPreviewStateActionsHandler.class);
    verify(preview).setStateHandler(handlerCaptor.capture());
    DocumentPreviewStateActionsHandler handler = handlerCaptor.getValue();
    ArgumentCaptor<Command> startUploadCaptor = ArgumentCaptor.forClass(Command.class);
    ArgumentCaptor<ParameterizedCommand> uploadResultCaptor = ArgumentCaptor.forClass(ParameterizedCommand.class);
    verify(uploader).upload(eq(DOC_1), any(), startUploadCaptor.capture(), uploadResultCaptor.capture());
    startUploadCaptor.getValue().execute();
    verify(preview).setState(DocumentPreviewState.UPLOADING);
    uploadResultCaptor.getValue().execute(false);
    verify(preview).setState(DocumentPreviewState.ERROR);
    DocumentPreviewStateAction action = ((List<DocumentPreviewStateAction>) handler.getCurrentStateActions()).get(1);
    action.execute();
    verify(uploader).remove(eq(DOC_1), any());
    uploadResultCaptor.getValue().execute(true);
    verify(preview).setState(DocumentPreviewState.UPLOADED);
}
Also used : Document(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.js.Document) DocumentData(org.kie.workbench.common.forms.jbpm.model.document.DocumentData) DocumentPreviewStateActionsHandler(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreviewStateActionsHandler) DocumentPreview(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreview) DocumentPreviewStateAction(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreviewStateAction) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) Command(org.uberfire.mvp.Command) List(java.util.List) File(elemental2.dom.File) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) Test(org.junit.Test)

Example 14 with DocumentData

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

the class DocumentFieldValueMarshallerTest method testExistingFlatValue2Document.

@Test
public void testExistingFlatValue2Document() {
    Document doc = new DocumentImpl(DOCUMENT_ID, "docName", 1024, new Date(), "aLink");
    marshaller.init(doc, field, form, context);
    DocumentData data = new DocumentData(doc.getName(), doc.getSize(), doc.getLink());
    data.setStatus(DocumentStatus.STORED);
    Document rawDoc = marshaller.toRawValue(data);
    assertEquals("Documents must be equal!", doc, rawDoc);
    verify(documentStorage, never()).getContent(Mockito.<String>any());
    verify(documentStorage, never()).removeContent(Mockito.<String>any());
}
Also used : DocumentData(org.kie.workbench.common.forms.jbpm.model.document.DocumentData) Document(org.jbpm.document.Document) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) Date(java.util.Date) Test(org.junit.Test)

Example 15 with DocumentData

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

the class DocumentCollectionFieldValueMarshallerTest method testAddingAndRemovingDocuments.

@Test
public void testAddingAndRemovingDocuments() {
    Document doc = new DocumentImpl(DOCUMENT_ID, "docName", 1024, new Date(), "aLink");
    documentCollection.addDocument(doc);
    marshaller.init(documentCollection, field, form, context);
    DocumentData data1 = new DocumentData(DOCUMENT_ID2, DOCUMENT_ID2, 1024, "", System.currentTimeMillis());
    DocumentData data2 = new DocumentData(DOCUMENT_ID3, DOCUMENT_ID3, 1024, "", System.currentTimeMillis());
    DocumentCollection<Document> rawDocuments = marshaller.toRawValue(Arrays.asList(data1, data2));
    verify(documentStorage, times(2)).getContent(Mockito.<String>any());
    verify(documentStorage, times(2)).removeContent(Mockito.<String>any());
    Assertions.assertThat(rawDocuments).isNotSameAs(documentCollection).isInstanceOf(expectedType);
    Assertions.assertThat(rawDocuments.getDocuments()).isNotNull().hasSize(2);
    compareDoc(rawDocuments.getDocuments().get(0), data1);
    compareDoc(rawDocuments.getDocuments().get(1), data2);
}
Also used : DocumentData(org.kie.workbench.common.forms.jbpm.model.document.DocumentData) Document(org.jbpm.document.Document) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) Date(java.util.Date) 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