use of org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreview 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());
}
use of org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreview in project kie-wb-common by kiegroup.
the class DocumentUpload method render.
private DocumentPreview render(DocumentData documentData) {
DocumentPreview preview = instance.get();
preview.init(documentData);
preview.setEnabled(enabled);
previews.add(preview);
view.addDocument(preview);
return preview;
}
use of org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreview 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();
}
use of org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreview 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);
}
use of org.kie.workbench.common.forms.jbpm.client.rendering.documents.control.preview.DocumentPreview in project kie-wb-common by kiegroup.
the class DocumentUpload method setValue.
@Override
public void setValue(List<DocumentData> value, boolean fireEvents) {
if (value == null) {
value = new ArrayList<>();
}
if (getValue().containsAll(value)) {
return;
}
this.clear();
value.forEach(documentData -> {
DocumentPreview preview = render(documentData);
DocumentPreviewStateActionsHandlerImpl handler = new DocumentPreviewStateActionsHandlerImpl(DocumentPreviewState.STORED);
DocumentPreviewStateAction action = new DocumentPreviewStateAction(translationService.getTranslation(Constants.DocumentUploadViewImplRemove), () -> doRemove(preview));
handler.addStateActions(DocumentPreviewState.STORED, Collections.singletonList(action));
preview.setStateHandler(handler);
});
if (fireEvents) {
ValueChangeEvent.fire(this, value);
}
}
Aggregations