Search in sources :

Example 1 with DocumentData

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

the class DocumentFieldRendererViewImpl method onSubmit.

public void onSubmit(String results) {
    initForm();
    JavaScriptObject jsResponse = JsonUtils.safeEval(results);
    if (jsResponse != null) {
        JSONObject response = new JSONObject(jsResponse);
        if (response.get("document") != null) {
            JSONObject document = response.get("document").isObject();
            DocumentData data = new DocumentData(document.get("contentId").isString().stringValue(), document.get("fileName").isString().stringValue(), new Double(document.get("size").isNumber().doubleValue()).longValue(), null, new Double(document.get("lastModified").isNumber().doubleValue()).longValue());
            setValue(data, true);
        } else if (response.get("error").isNull() != null) {
            setValue(null, true);
        }
    }
}
Also used : DocumentData(org.kie.workbench.common.forms.jbpm.model.document.DocumentData) JSONObject(com.google.gwt.json.client.JSONObject) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Example 2 with DocumentData

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

the class DocumentUpload method doUpload.

@Override
public void doUpload(final Document document, File file) {
    if (!enabled) {
        return;
    }
    DocumentData documentData = new DocumentData(document.getId(), document.getName(), document.getSize(), document.getUrl(), (long) document.getLastModified());
    DocumentPreview preview = render(documentData);
    DocumentPreviewStateActionsHandlerImpl handler = new DocumentPreviewStateActionsHandlerImpl(DocumentPreviewState.PENDING);
    DocumentPreviewStateAction abortAction = new DocumentPreviewStateAction(translationService.getTranslation(Constants.DocumentUploadViewImplAbort), () -> uploader.remove(document.getId(), () -> doRemove(preview)));
    handler.addStateActions(DocumentPreviewState.UPLOADING, Collections.singletonList(abortAction));
    DocumentPreviewStateAction removeAction = new DocumentPreviewStateAction(translationService.getTranslation(Constants.DocumentUploadViewImplRemove), () -> uploader.remove(document.getId(), () -> doRemove(preview)));
    handler.addStateActions(DocumentPreviewState.PENDING, Collections.singletonList(removeAction));
    handler.addStateActions(DocumentPreviewState.UPLOADED, Collections.singletonList(removeAction));
    final Command startUploadCallback = () -> handler.notifyStateChange(DocumentPreviewState.UPLOADING);
    final ParameterizedCommand<Boolean> onFinishUpload = success -> {
        if (success) {
            handler.notifyStateChange(DocumentPreviewState.UPLOADED);
        } else {
            handler.notifyStateChange(DocumentPreviewState.ERROR);
        }
    };
    DocumentPreviewStateAction retryAction = new DocumentPreviewStateAction(translationService.getTranslation(Constants.DocumentUploadViewImplRetry), () -> {
        uploader.remove(document.getId(), () -> uploader.upload(document.getId(), file, startUploadCallback, onFinishUpload));
    });
    handler.addStateActions(DocumentPreviewState.ERROR, Arrays.asList(removeAction, retryAction));
    preview.setStateHandler(handler);
    uploader.upload(document.getId(), file, startUploadCallback, onFinishUpload);
    ValueChangeEvent.fire(DocumentUpload.this, getValue());
}
Also used : ValueChangeHandler(com.google.gwt.event.logical.shared.ValueChangeHandler) ParameterizedCommand(org.uberfire.mvp.ParameterizedCommand) ValueChangeEvent(com.google.gwt.event.logical.shared.ValueChangeEvent) Arrays(java.util.Arrays) ManagedInstance(org.jboss.errai.ioc.client.api.ManagedInstance) Document(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.js.Document) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HandlerRegistration(com.google.gwt.event.shared.HandlerRegistration) PreDestroy(javax.annotation.PreDestroy) DocumentData(org.kie.workbench.common.forms.jbpm.model.document.DocumentData) GwtEvent(com.google.gwt.event.shared.GwtEvent) IsWidget(com.google.gwt.user.client.ui.IsWidget) DocumentPreview(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreview) Command(org.uberfire.mvp.Command) DocumentUploadManager(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.upload.DocumentUploadManager) TranslationService(org.jboss.errai.ui.client.local.spi.TranslationService) DocumentPreviewStateActionsHandlerImpl(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.handlers.DocumentPreviewStateActionsHandlerImpl) Collection(java.util.Collection) File(elemental2.dom.File) DocumentPreviewStateAction(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreviewStateAction) Collectors(java.util.stream.Collectors) Constants(org.kie.workbench.common.forms.jbpm.client.resources.i18n.Constants) List(java.util.List) Widget(com.google.gwt.user.client.ui.Widget) Dependent(javax.enterprise.context.Dependent) PostConstruct(javax.annotation.PostConstruct) DocumentPreviewState(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreviewState) Collections(java.util.Collections) DocumentData(org.kie.workbench.common.forms.jbpm.model.document.DocumentData) 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) DocumentPreviewStateActionsHandlerImpl(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.handlers.DocumentPreviewStateActionsHandlerImpl)

Example 3 with DocumentData

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

the class DocumentPreviewTest method testInit.

private void testInit(DocumentStatus status) {
    DocumentData data = spy(new DocumentData(DOC, DOC, 1024, DOC, System.currentTimeMillis()));
    data.setStatus(status);
    preview.init(data);
    verify(view).render(any());
    assertSame(data, preview.getDocumentData());
    preview.getDocumentName();
    verify(data, times(2)).getFileName();
    preview.getDocumentLink();
    verify(data).getLink();
}
Also used : DocumentData(org.kie.workbench.common.forms.jbpm.model.document.DocumentData)

Example 4 with DocumentData

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

the class DocumentUploadTest method testSetValues.

@Test
public void testSetValues() {
    DocumentData doc1 = new DocumentData(DOC_1, DOC_1, 1024, DOC_1, System.currentTimeMillis());
    DocumentData doc2 = new DocumentData(DOC_2, DOC_2, 1024, DOC_2, System.currentTimeMillis());
    DocumentData doc3 = new DocumentData(DOC_3, DOC_3, 1024, DOC_3, System.currentTimeMillis());
    documentUpload.setValue(Arrays.asList(doc1, doc2, doc3), false);
    verify(view).clear();
    verify(instance).destroyAll();
    verify(instance, times(3)).get();
    verify(view, times(3)).addDocument(any());
    List<DocumentPreview> previews = (List<DocumentPreview>) documentUpload.getCurrentPreviews();
    Assertions.assertThat(previews).isNotNull().hasSize(3);
    verifyPreview(previews.get(0), doc1, true);
    verifyPreview(previews.get(1), doc2, true);
    verifyPreview(previews.get(2), doc3, true);
    documentUpload.getValue();
    verify(previews.get(0)).getDocumentData();
    verify(previews.get(1)).getDocumentData();
    verify(previews.get(2)).getDocumentData();
}
Also used : DocumentData(org.kie.workbench.common.forms.jbpm.model.document.DocumentData) DocumentPreview(org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreview) List(java.util.List) Test(org.junit.Test)

Example 5 with DocumentData

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

the class DocumentFieldValueMarshallerTest method testNewFlatValue2Document.

@Test
public void testNewFlatValue2Document() {
    marshaller.init(null, field, form, context);
    DocumentData data = new DocumentData(DOCUMENT_ID, 1024, null);
    data.setContentId("content");
    Document doc = marshaller.toRawValue(data);
    verify(documentStorage).getContent(Mockito.<String>any());
    verify(documentStorage).removeContent(Mockito.<String>any());
    assertNotNull("Document cannot be null!", doc);
    assertEquals("Names are not equal", data.getFileName(), doc.getName());
    assertEquals("Sizes are not equal", data.getSize(), doc.getSize());
}
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