use of org.kie.server.api.model.instance.DocumentInstance in project droolsjbpm-integration by kiegroup.
the class DocumentServiceBase method updateDocument.
public void updateDocument(String documentId, String documentPayload, String marshallingType) {
logger.debug("About to unmarshal document payload '{}' with marshaling type {}", documentPayload, marshallingType);
DocumentInstance documentInstance = marshallerHelper.unmarshal(documentPayload, marshallingType, DocumentInstance.class);
logger.debug("Document created from payload {}", documentInstance);
Document document = documentStorageService.getDocument(documentId);
logger.debug("Document found {}", documentInstance != null);
if (document == null) {
throw new KieServerRuntimeException("No document found with id " + documentId);
}
documentStorageService.saveDocument(document, documentInstance.getContent());
logger.debug("Document {} updated successfully", document);
}
use of org.kie.server.api.model.instance.DocumentInstance in project droolsjbpm-integration by kiegroup.
the class DocumentServiceIntegrationTest method testListDocuments.
@Test
public void testListDocuments() {
List<DocumentInstance> docs = documentClient.listDocuments(0, 10);
assertNotNull(docs);
assertEquals(0, docs.size());
String documentId = documentClient.createDocument(document);
assertNotNull(documentId);
docs = documentClient.listDocuments(0, 10);
assertNotNull(docs);
assertEquals(1, docs.size());
DocumentInstance fromServer = docs.get(0);
assertEquals(documentId, fromServer.getIdentifier());
assertDocumentInstances(document, fromServer, false);
}
use of org.kie.server.api.model.instance.DocumentInstance in project droolsjbpm-integration by kiegroup.
the class JbpmRestIntegrationTest method testUploadListDownloadDocument.
@Test
public void testUploadListDownloadDocument() throws Exception {
KieServerUtil.deleteDocumentStorageFolder();
Marshaller marshaller = MarshallerFactory.getMarshaller(new HashSet<Class<?>>(extraClasses.values()), marshallingFormat, client.getClassLoader());
DocumentInstance documentInstance = DocumentInstance.builder().name("test file.txt").size(50).content("test content".getBytes()).lastModified(new Date()).build();
String documentEntity = marshaller.marshall(documentInstance);
Map<String, Object> empty = new HashMap<>();
Response response = null;
try {
// create document
WebTarget clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), DOCUMENT_URI, empty));
logger.info("[POST] " + clientRequest.getUri());
response = clientRequest.request(acceptHeadersByFormat.get(marshallingFormat)).post(createEntity(documentEntity));
Assert.assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus());
String documentId = response.readEntity(JaxbString.class).unwrap();
assertNotNull(documentId);
// list available documents without paging info
Map<String, Object> valuesMap = new HashMap<String, Object>();
valuesMap.put(DOCUMENT_ID, documentId);
clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), DOCUMENT_URI, valuesMap));
logger.info("[GET] " + clientRequest.getUri());
response = clientRequest.request(getMediaType()).get();
Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
DocumentInstanceList docList = marshaller.unmarshall(response.readEntity(String.class), DocumentInstanceList.class);
assertNotNull(docList);
List<DocumentInstance> docs = docList.getItems();
assertNotNull(docs);
assertEquals(1, docs.size());
DocumentInstance doc = docs.get(0);
assertNotNull(doc);
assertEquals(documentInstance.getName(), doc.getName());
assertEquals(documentId, doc.getIdentifier());
// download document content
valuesMap = new HashMap<String, Object>();
valuesMap.put(DOCUMENT_ID, documentId);
clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), DOCUMENT_URI + "/" + DOCUMENT_INSTANCE_CONTENT_GET_URI, valuesMap));
logger.info("[GET] " + clientRequest.getUri());
response = clientRequest.request(getMediaType()).accept(MediaType.APPLICATION_OCTET_STREAM_TYPE).get();
Assert.assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
String contentDisposition = response.getHeaderString("Content-Disposition");
assertTrue(contentDisposition.contains(documentInstance.getName()));
byte[] content = response.readEntity(byte[].class);
assertNotNull(content);
String stringContent = new String(content);
assertEquals("test content", stringContent);
response.close();
// delete document
valuesMap = new HashMap<String, Object>();
valuesMap.put(DOCUMENT_ID, documentId);
clientRequest = newRequest(build(TestConfig.getKieServerHttpUrl(), DOCUMENT_URI + "/" + DOCUMENT_INSTANCE_DELETE_URI, valuesMap));
logger.info("[DELETE] " + clientRequest.getUri());
response = clientRequest.request(getMediaType()).delete();
int noContentStatusCode = Response.Status.NO_CONTENT.getStatusCode();
int okStatusCode = Response.Status.OK.getStatusCode();
assertTrue("Wrong status code returned: " + response.getStatus(), response.getStatus() == noContentStatusCode || response.getStatus() == okStatusCode);
} finally {
if (response != null) {
response.close();
}
}
}
use of org.kie.server.api.model.instance.DocumentInstance in project droolsjbpm-integration by kiegroup.
the class DocumentServiceBase method convertDocument.
protected DocumentInstance convertDocument(Document document, boolean withContent) {
if (document == null) {
return null;
}
Builder documentBuilder = DocumentInstance.builder();
documentBuilder.id(document.getIdentifier()).name(document.getName()).link(document.getLink()).size(document.getSize()).lastModified(document.getLastModified());
if (withContent) {
documentBuilder.content(document.getContent());
}
DocumentInstance documentInstance = documentBuilder.build();
return documentInstance;
}
use of org.kie.server.api.model.instance.DocumentInstance in project droolsjbpm-integration by kiegroup.
the class DocumentServiceBase method listDocuments.
public DocumentInstanceList listDocuments(Integer page, Integer pageSize) {
logger.debug("About to list documents with page {} and pageSize {}", page, pageSize);
final List<Document> documents = documentStorageService.listDocuments(page, pageSize);
logger.debug("Documents loaded from repository {}", documents);
DocumentInstanceList result = new DocumentInstanceList(Collections.emptyList());
if (documents == null) {
return result;
}
List<DocumentInstance> list = convertDocumentList(documents);
result.setDocumentInstances(list.toArray(new DocumentInstance[list.size()]));
return result;
}
Aggregations