Search in sources :

Example 1 with DocumentData

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

the class DocumentFieldValueProcessor method toFlatValue.

@Override
public DocumentData toFlatValue(DocumentFieldDefinition field, Document document, BackendFormRenderingContext context) {
    if (document == null) {
        return null;
    }
    String templateId = (String) context.getAttributes().get(SERVER_TEMPLATE_ID);
    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);
    data.setStatus(DocumentStatus.STORED);
    return data;
}
Also used : DocumentData(org.kie.workbench.common.forms.dynamic.model.document.DocumentData)

Example 2 with DocumentData

use of org.kie.workbench.common.forms.dynamic.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 {
        String id = UUID.randomUUID().toString();
        FileItem fileItem = getFileItem(req);
        File file = File.createTempFile(id, ".tmp");
        file.deleteOnExit();
        fileItem.write(file);
        manager.uploadFile(id, file);
        DocumentData data = new DocumentData(fileItem.getName(), fileItem.getSize(), null);
        data.setContentId(id);
        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.dynamic.model.document.DocumentData) HashMap(java.util.HashMap) File(java.io.File) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 3 with DocumentData

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

the class DocumentFieldValueProcessorTest method testExistingFlatValue2Document.

@Test
public void testExistingFlatValue2Document() {
    Document doc = new DocumentImpl(DOCUMENT_ID, "docName", 1024, new Date(), "aLink");
    DocumentData data = new DocumentData(doc.getName(), doc.getSize(), doc.getLink());
    data.setStatus(DocumentStatus.STORED);
    Document rawDoc = processor.toRawValue(field, data, doc, context);
    assertEquals("Documents must be equal!", doc, rawDoc);
    verify(uploadedDocumentManager, never()).getFile(anyString());
    verify(uploadedDocumentManager, never()).removeFile(anyString());
}
Also used : DocumentData(org.kie.workbench.common.forms.dynamic.model.document.DocumentData) Document(org.jbpm.document.Document) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) Date(java.util.Date) Test(org.junit.Test)

Example 4 with DocumentData

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

the class DocumentFieldValueProcessorTest method testDocument2FlatValueEmptyLinkPattern.

@Test
public void testDocument2FlatValueEmptyLinkPattern() {
    Document doc = spy(new DocumentImpl(DOCUMENT_ID, "docName", 1024, new Date()));
    DocumentData documentData = processor.toFlatValue(field, doc, context);
    verify(doc).getLink();
    assertNotNull(documentData);
    assertEquals(doc.getName(), documentData.getFileName());
    assertEquals(doc.getSize(), documentData.getSize());
    assertEquals("", documentData.getLink());
}
Also used : DocumentData(org.kie.workbench.common.forms.dynamic.model.document.DocumentData) Document(org.jbpm.document.Document) DocumentImpl(org.jbpm.document.service.impl.DocumentImpl) Date(java.util.Date) Test(org.junit.Test)

Example 5 with DocumentData

use of org.kie.workbench.common.forms.dynamic.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("fileName").isString().stringValue(), new Double(document.get("size").isNumber().doubleValue()).longValue(), null);
            data.setContentId(document.get("contentId").isString().stringValue());
            setValue(data, true);
        } else if (response.get("error").isNull() != null) {
            setValue(null, true);
        }
    }
}
Also used : DocumentData(org.kie.workbench.common.forms.dynamic.model.document.DocumentData) JSONObject(com.google.gwt.json.client.JSONObject) JavaScriptObject(com.google.gwt.core.client.JavaScriptObject)

Aggregations

DocumentData (org.kie.workbench.common.forms.dynamic.model.document.DocumentData)8 Test (org.junit.Test)5 Document (org.jbpm.document.Document)4 Date (java.util.Date)3 DocumentImpl (org.jbpm.document.service.impl.DocumentImpl)3 HashMap (java.util.HashMap)2 JavaScriptObject (com.google.gwt.core.client.JavaScriptObject)1 JSONObject (com.google.gwt.json.client.JSONObject)1 File (java.io.File)1 IOException (java.io.IOException)1 Map (java.util.Map)1 ServletException (javax.servlet.ServletException)1 FileItem (org.apache.commons.fileupload.FileItem)1