use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.
the class TableDataResource method getTableData.
@RequestMapping(value = "/management/tables/{tableName}/data", method = RequestMethod.GET, produces = "application/json")
public DataResponse getTableData(@PathVariable String tableName, @RequestParam Map<String, String> allRequestParams) {
// Check if table exists before continuing
if (managementService.getTableMetaData(tableName) == null) {
throw new ActivitiObjectNotFoundException("Could not find a table with name '" + tableName + "'.", String.class);
}
String orderAsc = allRequestParams.get("orderAscendingColumn");
String orderDesc = allRequestParams.get("orderDescendingColumn");
if (orderAsc != null && orderDesc != null) {
throw new ActivitiIllegalArgumentException("Only one of 'orderAscendingColumn' or 'orderDescendingColumn' can be supplied.");
}
Integer start = null;
if (allRequestParams.containsKey("start")) {
start = Integer.valueOf(allRequestParams.get("start"));
}
if (start == null) {
start = 0;
}
Integer size = null;
if (allRequestParams.containsKey("size")) {
size = Integer.valueOf(allRequestParams.get("size"));
}
if (size == null) {
size = DEFAULT_RESULT_SIZE;
}
DataResponse response = new DataResponse();
TablePageQuery tablePageQuery = managementService.createTablePageQuery().tableName(tableName);
if (orderAsc != null) {
tablePageQuery.orderAsc(orderAsc);
response.setOrder("asc");
response.setSort(orderAsc);
}
if (orderDesc != null) {
tablePageQuery.orderDesc(orderDesc);
response.setOrder("desc");
response.setSort(orderDesc);
}
TablePage listPage = tablePageQuery.listPage(start, size);
response.setSize(((Long) listPage.getSize()).intValue());
response.setStart(((Long) listPage.getFirstResult()).intValue());
response.setTotal(listPage.getTotal());
response.setData(listPage.getRows());
return response;
}
use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.
the class BaseDeploymentResourceDataResource method getDeploymentResourceData.
protected byte[] getDeploymentResourceData(String deploymentId, String resourceId, HttpServletResponse response) {
if (deploymentId == null) {
throw new ActivitiIllegalArgumentException("No deployment id provided");
}
if (resourceId == null) {
throw new ActivitiIllegalArgumentException("No resource id provided");
}
// Check if deployment exists
Deployment deployment = repositoryService.createDeploymentQuery().deploymentId(deploymentId).singleResult();
if (deployment == null) {
throw new ActivitiObjectNotFoundException("Could not find a deployment with id '" + deploymentId + "'.", Deployment.class);
}
List<String> resourceList = repositoryService.getDeploymentResourceNames(deploymentId);
if (resourceList.contains(resourceId)) {
final InputStream resourceStream = repositoryService.getResourceAsStream(deploymentId, resourceId);
String contentType = contentTypeResolver.resolveContentType(resourceId);
response.setContentType(contentType);
try {
return IOUtils.toByteArray(resourceStream);
} catch (Exception e) {
throw new ActivitiException("Error converting resource stream", e);
}
} else {
// Resource not found in deployment
throw new ActivitiObjectNotFoundException("Could not find a resource with id '" + resourceId + "' in deployment '" + deploymentId + "'.", String.class);
}
}
use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.
the class DeploymentCollectionResource method uploadDeployment.
@RequestMapping(value = "/repository/deployments", method = RequestMethod.POST, produces = "application/json")
public DeploymentResponse uploadDeployment(@RequestParam(value = "tenantId", required = false) String tenantId, HttpServletRequest request, HttpServletResponse response) {
if (request instanceof MultipartHttpServletRequest == false) {
throw new ActivitiIllegalArgumentException("Multipart request is required");
}
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
if (multipartRequest.getFileMap().size() == 0) {
throw new ActivitiIllegalArgumentException("Multipart request with file content is required");
}
MultipartFile file = multipartRequest.getFileMap().values().iterator().next();
try {
DeploymentBuilder deploymentBuilder = repositoryService.createDeployment();
String fileName = file.getOriginalFilename();
if (StringUtils.isEmpty(fileName) || !(fileName.endsWith(".bpmn20.xml") || fileName.endsWith(".bpmn") || fileName.toLowerCase().endsWith(".bar") || fileName.toLowerCase().endsWith(".zip"))) {
fileName = file.getName();
}
if (fileName.endsWith(".bpmn20.xml") || fileName.endsWith(".bpmn")) {
deploymentBuilder.addInputStream(fileName, file.getInputStream());
} else if (fileName.toLowerCase().endsWith(".bar") || fileName.toLowerCase().endsWith(".zip")) {
deploymentBuilder.addZipInputStream(new ZipInputStream(file.getInputStream()));
} else {
throw new ActivitiIllegalArgumentException("File must be of type .bpmn20.xml, .bpmn, .bar or .zip");
}
deploymentBuilder.name(fileName);
if (tenantId != null) {
deploymentBuilder.tenantId(tenantId);
}
Deployment deployment = deploymentBuilder.deploy();
response.setStatus(HttpStatus.CREATED.value());
return restResponseFactory.createDeploymentResponse(deployment);
} catch (Exception e) {
if (e instanceof ActivitiException) {
throw (ActivitiException) e;
}
throw new ActivitiException(e.getMessage(), e);
}
}
use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.
the class ModelSourceExtraResource method setModelSource.
@RequestMapping(value = "/repository/models/{modelId}/source-extra", method = RequestMethod.PUT)
protected void setModelSource(@PathVariable String modelId, HttpServletRequest request, HttpServletResponse response) {
Model model = getModelFromRequest(modelId);
if (model != null) {
try {
if (request instanceof MultipartHttpServletRequest == false) {
throw new ActivitiIllegalArgumentException("Multipart request is required");
}
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
if (multipartRequest.getFileMap().size() == 0) {
throw new ActivitiIllegalArgumentException("Multipart request with file content is required");
}
MultipartFile file = multipartRequest.getFileMap().values().iterator().next();
repositoryService.addModelEditorSourceExtra(model.getId(), file.getBytes());
response.setStatus(HttpStatus.NO_CONTENT.value());
} catch (Exception e) {
throw new ActivitiException("Error adding model editor source extra", e);
}
}
}
use of org.activiti.engine.ActivitiIllegalArgumentException in project Activiti by Activiti.
the class ModelSourceResource method setModelSource.
@RequestMapping(value = "/repository/models/{modelId}/source", method = RequestMethod.PUT)
protected void setModelSource(@PathVariable String modelId, HttpServletRequest request, HttpServletResponse response) {
Model model = getModelFromRequest(modelId);
if (model != null) {
if (request instanceof MultipartHttpServletRequest == false) {
throw new ActivitiIllegalArgumentException("Multipart request is required");
}
MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
if (multipartRequest.getFileMap().size() == 0) {
throw new ActivitiIllegalArgumentException("Multipart request with file content is required");
}
MultipartFile file = multipartRequest.getFileMap().values().iterator().next();
try {
repositoryService.addModelEditorSource(modelId, file.getBytes());
response.setStatus(HttpStatus.NO_CONTENT.value());
} catch (Exception e) {
throw new ActivitiException("Error adding model editor source extra", e);
}
}
}
Aggregations