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