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);
}
}
}
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());
}
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();
}
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();
}
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());
}
Aggregations