use of org.kie.server.api.model.instance.DocumentInstance in project droolsjbpm-integration by kiegroup.
the class DocumentResource method getDocumentContent.
@ApiOperation(value = "Retrieves document's content identified by given documentId", response = byte[].class, code = 200, responseHeaders = { @ResponseHeader(name = "Content-Disposition", description = "provides file name of the document") })
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Document with given id not found") })
@GET
@Path(DOCUMENT_INSTANCE_CONTENT_GET_URI)
@Produces({ MediaType.APPLICATION_OCTET_STREAM })
public Response getDocumentContent(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "document id of a document that content should be retruned from", required = true, example = "xxx-yyy-zzz") @PathParam("documentId") String documentId) {
Variant v = getVariant(headers);
// no container id available so only used to transfer conversation id if given by client
Header conversationIdHeader = buildConversationIdHeader("", context, headers);
try {
final DocumentInstance document = documentServiceBase.getDocument(documentId);
if (document == null) {
return notFound("Document with id " + documentId + " not found", v, conversationIdHeader);
}
String fileName = MimeUtility.encodeWord(document.getName(), "utf-8", "Q");
StreamingOutput entity = new StreamingOutput() {
@Override
public void write(OutputStream output) throws IOException, WebApplicationException {
output.write(document.getContent());
}
};
if (conversationIdHeader != null) {
return Response.ok().entity(entity).header(conversationIdHeader.getName(), conversationIdHeader.getValue()).header("Content-Disposition", "attachment; filename=\"" + fileName + "\"").build();
}
return Response.ok().entity(entity).header("Content-Disposition", "attachment; filename=\"" + fileName + "\"").build();
} catch (Exception e) {
logger.error("Unexpected error during processing {}", e.getMessage(), e);
return internalServerError(errorMessage(e), v, conversationIdHeader);
}
}
use of org.kie.server.api.model.instance.DocumentInstance in project droolsjbpm-integration by kiegroup.
the class DocumentServiceIntegrationTest method testCreateLoadDeleteDocument.
@Test
@Category(Smoke.class)
public void testCreateLoadDeleteDocument() throws Exception {
String documentId = documentClient.createDocument(document);
assertNotNull(documentId);
DocumentInstance fromServer = documentClient.getDocument(documentId);
assertEquals(documentId, fromServer.getIdentifier());
assertDocumentInstances(document, fromServer, true);
documentClient.deleteDocument(documentId);
try {
documentClient.getDocument(documentId);
fail("Document with id " + documentId + " was deleted so should not be found anymore");
} catch (KieServicesException e) {
// expected
}
}
use of org.kie.server.api.model.instance.DocumentInstance in project droolsjbpm-integration by kiegroup.
the class DocumentServiceIntegrationTest method testUpdateDocument.
@Test
public void testUpdateDocument() {
String documentId = documentClient.createDocument(document);
assertNotNull(documentId);
DocumentInstance fromServer = documentClient.getDocument(documentId);
assertEquals(documentId, fromServer.getIdentifier());
assertDocumentInstances(document, fromServer, true);
String udpatedDoc = "here comes the update";
byte[] updateDocBytes = udpatedDoc.getBytes();
fromServer.setContent(updateDocBytes);
fromServer.setSize(updateDocBytes.length);
fromServer.setLastModified(new Date());
documentClient.updateDocument(fromServer);
DocumentInstance updatedFromServer = documentClient.getDocument(documentId);
assertEquals(documentId, updatedFromServer.getIdentifier());
assertDocumentInstances(fromServer, updatedFromServer, true);
}
use of org.kie.server.api.model.instance.DocumentInstance in project droolsjbpm-integration by kiegroup.
the class DocumentServiceIntegrationTest method testCreateEmptyDocument.
@Test
public void testCreateEmptyDocument() {
content = "";
contentBytes = content.getBytes();
document = DocumentInstance.builder().name("first document").size(contentBytes.length).lastModified(new Date()).content(contentBytes).build();
String documentId = documentClient.createDocument(document);
assertNotNull(documentId);
DocumentInstance fromServer = documentClient.getDocument(documentId);
assertEquals(documentId, fromServer.getIdentifier());
assertDocumentInstances(document, fromServer, true);
}
use of org.kie.server.api.model.instance.DocumentInstance in project droolsjbpm-integration by kiegroup.
the class DocumentServiceIntegrationTest method testDeleteDocument.
@Test
public void testDeleteDocument() throws Exception {
String documentId = documentClient.createDocument(document);
assertNotNull(documentId);
DocumentInstance fromServer = documentClient.getDocument(documentId);
assertNotNull(fromServer);
documentClient.deleteDocument(documentId);
try {
documentClient.getDocument(documentId);
fail("Document with id " + documentId + " was deleted so should not be found anymore");
} catch (KieServicesException e) {
// expected
}
}
Aggregations