use of org.kie.server.api.model.instance.DocumentInstanceList in project droolsjbpm-integration by kiegroup.
the class DocumentResource method listDocuments.
@ApiOperation(value = "Returns all documents from KIE Server.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 200, response = DocumentInstanceList.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_DOCUMENTS_RESPONSE_JSON) })) })
@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response listDocuments(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "optional pagination - at which page to start, defaults to 0 (meaning first)", required = false) @QueryParam("page") @DefaultValue("0") Integer page, @ApiParam(value = "optional pagination - size of the result, defaults to 10", required = false) @QueryParam("pageSize") @DefaultValue("10") Integer pageSize) {
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 {
DocumentInstanceList documents = documentServiceBase.listDocuments(page, pageSize);
return createCorrectVariant(documents, headers, Response.Status.OK, conversationIdHeader);
} 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.DocumentInstanceList in project droolsjbpm-integration by kiegroup.
the class DocumentServicesClientImpl method listDocuments.
@Override
public List<DocumentInstance> listDocuments(Integer page, Integer pageSize) {
DocumentInstanceList result = null;
if (config.isRest()) {
Map<String, Object> valuesMap = new HashMap<String, Object>();
String queryString = getPagingQueryString("", page, pageSize);
result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), DOCUMENT_URI, valuesMap) + queryString, DocumentInstanceList.class);
} else {
CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("DocumentService", "listDocuments", new Object[] { page, pageSize })));
ServiceResponse<DocumentInstanceList> response = (ServiceResponse<DocumentInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
throwExceptionOnFailure(response);
if (shouldReturnWithNullResponse(response)) {
return null;
}
result = response.getResult();
}
return result.getItems();
}
use of org.kie.server.api.model.instance.DocumentInstanceList 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.DocumentInstanceList 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