F2BPM 开发Api与RESTfull应用服务Api 层次关系及示例
目前越来越多的企业架构解决方案更加趋向于基于http协议“微服务”访问跨系统调用,而不使用统传的WebService调用,即通过RESTfull方式进行交互,更加轻量整合调用更加方便。本文档中所有F2BPM开发接口API都可以发布成RESTfull对外应用服务接口
RESTfull参数方式:
authorJson:主要是接口身份的认证相关参数,校验访问者的来源合法性
parmJson:请求业务数据的参数,比如分页参数,查询参数等
所有RESTfull都统一只有这两个Json参数
API开发接口与RestFull API服务发布代码示例
SmartFormRESTfullApi 在线表单的RestFull API服务
package com.f2bpm.controller.restfullapi; import java.util.List; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONObject; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest; import com.f2bpm.base.core.entity.AuthorEntity;
import com.f2bpm.base.core.entity.MyInteger;
import com.f2bpm.base.core.entity.PageParams;
import com.f2bpm.base.core.enums.ExtensionValidateType;
import com.f2bpm.base.core.utils.AppUtil;
import com.f2bpm.base.core.utils.ExtensionValidate;
import com.f2bpm.base.core.utils.FileDownUtil;
import com.f2bpm.base.core.utils.FileUtil;
import com.f2bpm.base.core.utils.JsonHelper;
import com.f2bpm.base.core.utils.string.StringUtil;
import com.f2bpm.base.core.utils.time.DateUtil;
import com.f2bpm.system.admin.impl.model.Users;
import com.f2bpm.system.security.utils.LogUtil;
import com.f2bpm.system.security.web.WebHelper;
import com.f2bpm.workflow.engine.api.entity.WorkflowInstanceContext;
import com.f2bpm.workflow.engine.api.model.TaskInstance;
import com.f2bpm.workflow.engine.api.model.TaskInstanceInfo;
import com.f2bpm.workflow.engine.api.model.WorkflowForm;
import com.f2bpm.workflow.engine.api.wapi.IWorkflowWAPIService;
import com.f2bpm.workflow.engine.helper.WfWebHelper;
import com.f2bpm.workflow.org.api.imodel.IUser;
import com.f2bpm.workflow.org.api.iservice.IUserService;
import com.f2bpm.workflow.smartForm.api.entity.BusObjectData; /*
* 在线表单RestFull API服务接口
*/
@Controller
@RequestMapping("/restfullapi/smartForm/")
public class SmartFormRESTfullApi {
@Resource
IUserService userService;
public IWorkflowWAPIService WorkflowAPI = (IWorkflowWAPIService) AppUtil.getBean("WorkflowAPI"); /**
* 获取在线表单数据
*
* @param parmJson
* @param authorJson
* @param response
*/
@RequestMapping(value = "getOnlineFormData", method = RequestMethod.POST)
public void getOnlineFormData(String parmJson, String authorJson, HttpServletResponse response) {
String jsonResult = "";
try {
JSONObject jsonJSONObject = JSONObject.fromObject(parmJson);
AuthorEntity authorEntity = JsonHelper.jsonToObject(authorJson, AuthorEntity.class);
String loginAccount = authorEntity.getLoginAccount();
// 流程实例ID
String wiid = JsonHelper.getString(jsonJSONObject, "wiid");
// 表单业务键
String businessKey = JsonHelper.getString(jsonJSONObject, "businessKey");
List<BusObjectData> data = WorkflowAPI.getSmartFormApiManager().getBusObjectListData(wiid, businessKey);
jsonResult = JsonHelper.objectToJSON(data);
} catch (Exception ex) {
jsonResult = JsonHelper.outResult(false, ex.toString());
}
JsonHelper.write(response, jsonResult);
} /**
* 获取表单应用定义
*
* @param parmJson
* @param authorJson
* @param response
*/
@RequestMapping(value = "getWorkflowForm", method = RequestMethod.POST)
public void getWorkflowForm(String parmJson, String authorJson, HttpServletResponse response) {
String jsonResult = "";
try {
JSONObject jsonJSONObject = JSONObject.fromObject(parmJson);
AuthorEntity authorEntity = JsonHelper.jsonToObject(authorJson, AuthorEntity.class);
String loginAccount = authorEntity.getLoginAccount();
String wid = JsonHelper.getString(jsonJSONObject, "wid");
String appId = JsonHelper.getString(jsonJSONObject, "appId");
WorkflowForm form = null;
if (StringUtil.isEmpty(wid)) {
// 启动时
form = WorkflowAPI.getProcessDefManager().getWorkflowInfo(appId).getWorkflowFormRunned();
} else {
// 运行时
form = WorkflowAPI.getProcessDefManager().getWorkflowInfo(wid, appId).getWorkflowFormRunned(); }
jsonResult = JsonHelper.objectToJSON(form);
} catch (Exception ex) {
jsonResult = JsonHelper.outResult(false, ex.toString());
}
JsonHelper.write(response, jsonResult);
} /**
* 获取表单手机端Html模板
*
* @param parmJson wid:启动时可为空
* @param authorJson
* @param response
*/
@RequestMapping(value = "getWorkflowFormMobileHtml", method = RequestMethod.POST)
public void getWorkflowFormMobileHtml(String parmJson, String authorJson, HttpServletResponse response) {
String jsonResult = "";
try {
JSONObject jsonJSONObject = JSONObject.fromObject(parmJson);
AuthorEntity authorEntity = JsonHelper.jsonToObject(authorJson, AuthorEntity.class);
String loginAccount = authorEntity.getLoginAccount();
String wid = JsonHelper.getString(jsonJSONObject, "wid");//启用时可为空
String appId = JsonHelper.getString(jsonJSONObject, "appId");
String html= null;
if (StringUtil.isEmpty(wid)) {
// 启动时
html = WorkflowAPI.getProcessDefManager().getWorkflowInfo(appId).getWorkflowFormRunned().getMobileTemplateContent();
} else {
// 运行时
html = WorkflowAPI.getProcessDefManager().getWorkflowInfo(wid, appId).getWorkflowFormRunned().getMobileTemplateContent(); }
jsonResult = html;
} catch (Exception ex) {
jsonResult = JsonHelper.outResult(false, ex.toString());
}
JsonHelper.write(response, jsonResult);
}
}
WorkflowBusinessRESTfullApi 流程运行相关的服务接口
package com.f2bpm.controller.restfullapi; import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import net.sf.json.JSONObject; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest; import com.f2bpm.base.core.entity.AuthorEntity;
import com.f2bpm.base.core.entity.MyInteger;
import com.f2bpm.base.core.entity.PageParams;
import com.f2bpm.base.core.enums.ExtensionValidateType;
import com.f2bpm.base.core.utils.AppUtil;
import com.f2bpm.base.core.utils.ExtensionValidate;
import com.f2bpm.base.core.utils.FileDownUtil;
import com.f2bpm.base.core.utils.FileUtil;
import com.f2bpm.base.core.utils.JsonHelper;
import com.f2bpm.base.core.utils.string.StringUtil;
import com.f2bpm.base.core.utils.time.DateUtil;
import com.f2bpm.system.admin.impl.model.Users;
import com.f2bpm.system.security.utils.LogUtil;
import com.f2bpm.system.security.web.WebHelper;
import com.f2bpm.workflow.engine.api.entity.WorkflowInstanceContext;
import com.f2bpm.workflow.engine.api.model.ActivityInfo;
import com.f2bpm.workflow.engine.api.model.TaskInstance;
import com.f2bpm.workflow.engine.api.model.TaskInstanceInfo;
import com.f2bpm.workflow.engine.api.wapi.IWorkflowWAPIService;
import com.f2bpm.workflow.engine.helper.WfWebHelper;
import com.f2bpm.workflow.org.api.imodel.IUser;
import com.f2bpm.workflow.org.api.iservice.IUserService;
/*
* 流程运行相关 RestFull API服务接口
*/
@Controller
@RequestMapping("/restfullapi/workflowBusiness/")
public class WorkflowBusinessRESTfullApi {
@Resource
IUserService userService; public IWorkflowWAPIService WorkflowAPI = (IWorkflowWAPIService) AppUtil.getBean("WorkflowAPI"); /**
* 查找任务实例
* @param id
* @param request
* @param response
* @return
* @throws IOException
*/
@ResponseBody
@RequestMapping(value = "getTask", method = RequestMethod.GET)
public TaskInstance getTask(String id, HttpServletRequest request, HttpServletResponse response) throws IOException {
TaskInstance task = new TaskInstance();
id = "031d2404-94d1-4566-8ade-21126b620904";
task = WorkflowAPI.getWorkTaskManager().getTaskInstanceByTaskId(id);
return task;
} /**
* 获取待办列表
* @param authorJson
* @param parmJson
* @param request
* @param response
* @throws Exception
*/
@RequestMapping(value = "getTodoList", method = RequestMethod.GET)
public void getTodoList(String authorJson, String parmJson, HttpServletRequest request, HttpServletResponse response) throws Exception {
JSONObject jsonJSONObject = JSONObject.fromObject(parmJson);
PageParams pageParams = JsonHelper.jsonToObject(parmJson, PageParams.class);
AuthorEntity authorEntity = JsonHelper.jsonToObject(authorJson, AuthorEntity.class);
String loginAccount = authorEntity.getLoginAccount();
MyInteger recordCount = new MyInteger(0);
MyInteger pageCount = new MyInteger(0);
String whereStr = JsonHelper.getString(jsonJSONObject, "whereStr");
IUser user = userService.getUserByAccount(loginAccount);
List<TaskInstanceInfo> list = WorkflowAPI.getWorkTaskManager().getTodoList(user.getUserId(), whereStr.toString(), pageParams.getOrderBy(), pageParams.getPageIndex(), pageParams.getPageSize(), pageCount, recordCount, true);
String jsonString = JsonHelper.listToJSON(list);
String jsonResult = JsonHelper.convertToEasyUIJsonResult(jsonString, pageParams.getPageSize(), pageParams.getPageIndex(), recordCount.getValue(), pageCount.getValue());
JsonHelper.write(response, jsonResult);
} /**
* 已办列表
* @param authorJson
* @param parmJson
* @param request
* @param response
* @throws Exception
*/
@RequestMapping(value = "getDoneList", method = RequestMethod.POST)
public void getDoneList(String authorJson, String parmJson, HttpServletRequest request, HttpServletResponse response) throws Exception {
JSONObject jsonJSONObject = JSONObject.fromObject(parmJson);
PageParams pageParams = JsonHelper.jsonToObject(parmJson, PageParams.class);
AuthorEntity authorEntity = JsonHelper.jsonToObject(authorJson, AuthorEntity.class);
String loginAccount = authorEntity.getLoginAccount();
MyInteger recordCount = new MyInteger(0);
MyInteger pageCount = new MyInteger(0);
String whereStr = JsonHelper.getString(jsonJSONObject, "whereStr");
int isHistory = JsonHelper.getInt(jsonJSONObject, "isHistory");
IUser user = userService.getUserByAccount(loginAccount);
List<TaskInstanceInfo> list = null;
if (isHistory == 1) {
// 归档中的列表
list = WorkflowAPI.getHistoryDataManager().getHistoryDoneList(user.getUserId(), whereStr.toString(), pageParams.getOrderBy(), pageParams.getPageIndex(), pageParams.getPageSize(), pageCount, recordCount, true);
} else {
// 进行中的已办
list = WorkflowAPI.getWorkTaskManager().getDoneList(user.getUserId(), whereStr.toString(), pageParams.getOrderBy(), pageParams.getPageIndex(), pageParams.getPageSize(), pageCount, recordCount, true);
} String jsonString = JsonHelper.listToJSON(list);
String jsonResult = JsonHelper.convertToEasyUIJsonResult(jsonString, pageParams.getPageSize(), pageParams.getPageIndex(), recordCount.getValue(), pageCount.getValue());
JsonHelper.write(response, jsonResult);
} /**
* 响应发起流程
* @param authorJson
* @param parmJson
* @param request
* @param response
* @throws IOException
*/
@RequestMapping(value = "startWorkflow", method = RequestMethod.POST)
public void startWorkflow(String authorJson, String parmJson, HttpServletRequest request, HttpServletResponse response) throws IOException {
JSONObject jsonJSONObject = JSONObject.fromObject(parmJson);
AuthorEntity authorEntity = JsonHelper.jsonToObject(authorJson, AuthorEntity.class);
String loginAccount = authorEntity.getLoginAccount();
// IUser user = userService.getUserByAccount(loginAccount);
String appId = JsonHelper.getString(jsonJSONObject, "appId");
String wiid = JsonHelper.getString(jsonJSONObject, "wiid");
String businessKey = JsonHelper.getString(jsonJSONObject, "businessKey");
String title = JsonHelper.getString(jsonJSONObject, "title");
String opinion = JsonHelper.getString(jsonJSONObject, "opinion");
String jsonFormData = JsonHelper.getString(jsonJSONObject, "jsonFormData");
StringBuilder message = new StringBuilder();
boolean success = WorkflowAPI.getWorkflowEnactmentManager().startWorkflow(appId, wiid, businessKey, title, opinion, loginAccount, null, message, jsonFormData, null, 0, 0);
String jsonResult = JsonHelper.outResult(success, message.toString());
JsonHelper.write(response, jsonResult);
} /**
* 驳回流程
* @param parmJson
* @param authorJson
* @param response
*/
@RequestMapping(value = "rejectFlow", method = RequestMethod.POST)
public void rejectFlow(String parmJson, String authorJson, HttpServletResponse response) {
JSONObject jsonJSONObject = JSONObject.fromObject(parmJson);
AuthorEntity authorEntity = JsonHelper.jsonToObject(authorJson, AuthorEntity.class);
String loginAccount = authorEntity.getLoginAccount();
String taskId = JsonHelper.getString(jsonJSONObject, "taskId");
String opinion = JsonHelper.getString(jsonJSONObject, "opinion");
StringBuilder message = new StringBuilder();
boolean success = WorkflowAPI.getWorkflowEnactmentManager().rejectWorkflow(taskId, loginAccount, opinion, true, null, message);
String jsonResult = JsonHelper.outResult(success, message.toString());
JsonHelper.write(response, jsonResult);
} /**
* 作废流程实例
*
* @param parmJson
* @param authorJson
* @param response
*/
@RequestMapping(value = "invalidFlow", method = RequestMethod.POST)
public void invalidFlow(String parmJson, String authorJson, HttpServletResponse response) {
JSONObject jsonJSONObject = JSONObject.fromObject(parmJson);
AuthorEntity authorEntity = JsonHelper.jsonToObject(authorJson, AuthorEntity.class);
String loginAccount = authorEntity.getLoginAccount();
String taskId = JsonHelper.getString(jsonJSONObject, "taskId");
String opinion = JsonHelper.getString(jsonJSONObject, "opinion");
TaskInstance taskInstance = WorkflowAPI.getWorkTaskManager().getTaskInstanceByTaskId(taskId);
String wiid = taskInstance.getWorkflowInstanceId();
StringBuilder message = new StringBuilder();
IUser user = WorkflowAPI.getOrgEngineManager().getUserService().getUserByAccount(loginAccount);
boolean success = WorkflowAPI.getWorkflowEnactmentManager().invalidWorkflowInstance(wiid, opinion, user);
String jsonResult = JsonHelper.outResult(success, message.toString());
JsonHelper.write(response, jsonResult);
} /**
* 审批执行代办任务
* @param authorJson
* @param parmJson
* @param response
*/
@RequestMapping(value = "approvalTask", method = RequestMethod.POST)
public void approvalTask(String authorJson, String parmJson, HttpServletResponse response) {
JSONObject jsonJSONObject = JSONObject.fromObject(parmJson);
AuthorEntity authorEntity = JsonHelper.jsonToObject(authorJson, AuthorEntity.class);
String loginAccount = authorEntity.getLoginAccount();
String taskId = JsonHelper.getString(jsonJSONObject, "taskId");
String opinion = JsonHelper.getString(jsonJSONObject, "opinion");
StringBuilder message = new StringBuilder();
boolean success = WorkflowAPI.getWorkflowEnactmentManager().sendWorkflowByTaskId(taskId, loginAccount, opinion, message);
String jsonResult = JsonHelper.outResult(success, message.toString());
JsonHelper.write(response, jsonResult);
} /**
* 获取任务指定节点的供选择人(计算出节点参与者)
* @param authorJson
* @param parmJson
* @param response
*/
@RequestMapping(value = "getActivityUsers", method = RequestMethod.POST)
public void getActivityUsers(String authorJson, String parmJson, HttpServletResponse response) {
JSONObject jsonJSONObject = JSONObject.fromObject(parmJson);
AuthorEntity authorEntity = JsonHelper.jsonToObject(authorJson, AuthorEntity.class);
String loginAccount = authorEntity.getLoginAccount();
String taskId = JsonHelper.getString(jsonJSONObject, "taskId");
String activityId = JsonHelper.getString(jsonJSONObject, "activityId");
StringBuilder message = new StringBuilder();
WorkflowInstanceContext wfContext=WorkflowAPI.getWorkflowEnactmentManager().getWorkflowInstanceContextOnTodo(taskId, loginAccount);
TaskInstance task = WorkflowAPI.getWorkTaskManager().getTaskInstanceByTaskId(taskId);
ActivityInfo activityInfo=WorkflowAPI.getProcessDefManager().getActivityInfo(task.getWorkflowId(), activityId);
List<IUser> list= WorkflowAPI.getWorkflowEnactmentManager().getListActorUserResultByActivityInfo(wfContext,activityInfo);
String jsonResult =JsonHelper.objectToJSON(list);
JsonHelper.write(response, jsonResult);
} /**
* 上传在线表单附件 上传在线表单附件, 返回字段值单个附件值,表单附件的字段值格式:
* [{filePathName:"/attachments/workflow/files/20170714215409547.txt"
* ,fileName:"TestClient.txt"}]
*
* @param request
* @param response
*/
@RequestMapping("uploadFile")
public void uploadFile(HttpServletRequest request, HttpServletResponse response) {
String jsonResult = "";
MultipartHttpServletRequest mRequest = (MultipartHttpServletRequest) request;
MultipartFile fileUpload = mRequest.getFile("FileUpload");
if (!fileUpload.isEmpty()) { try {
String uploadType = WfWebHelper.query("UploadType", ""); String path = FileDownUtil.getWorkflowFilePath();
String uploadFileName = fileUpload.getOriginalFilename();
String fileExtension = uploadFileName.substring(uploadFileName.lastIndexOf(".")); if (!StringUtil.isNullOrWhiteSpace(uploadType)) {
path = path + uploadType + "/";
if (!FileUtil.isExistDirectory(path)) {
FileUtil.createFolder(path);
}
} if (!ExtensionValidate.validateExtension(fileExtension, ExtensionValidateType.FileExtension)) {
jsonResult = JsonHelper.outResult(false, fileExtension + ",文件类型不允许上传!");
JsonHelper.write(response, jsonResult);
return;
}
uploadFileName = DateUtil.getCurrentDateTime("yyyyMMddHHmmssSSS") + fileExtension;
String filePathName = path + uploadFileName;
if (FileUtil.isExistFile(filePathName)) {
FileUtil.deleteFile(filePathName);
}
File filePath = new File(filePathName);// 上传地址
fileUpload.transferTo(filePath); int index = filePathName.indexOf("attachments");
String downfielNamePath = filePathName.substring(index);
jsonResult = JsonHelper.outResult(true, "{filePathName:\"/" + downfielNamePath + "\",fileName:\"" + fileUpload.getOriginalFilename() + "\"}"); } catch (RuntimeException | IOException ex) {
jsonResult = JsonHelper.outResult(false, "上传失败");
LogUtil.writeLog(ex.toString());
}
} else {
jsonResult = JsonHelper.outResult(false, "请选择要上传的文件");
}
JsonHelper.write(response, jsonResult);
} /**
* 附件下载
* @param authorJson
* @param parmJson
* @param request
* @param response
*/
@RequestMapping("downloadFile")
public void downloadFile(String authorJson, String parmJson, HttpServletRequest request, HttpServletResponse response) {
try {
JSONObject jsonJSONObject = JSONObject.fromObject(parmJson);
AuthorEntity authorEntity = JsonHelper.jsonToObject(authorJson, AuthorEntity.class);
// String fileName = JsonHelper.getString(jsonJSONObject,
// "fileName");
String filePath = JsonHelper.getString(jsonJSONObject, "filePath");
String path = AppUtil.getWebRootPath() + filePath;
String fileName = new String(path.getBytes("iso8859-1"), "UTF-8");
File file = new File(fileName);
if (!file.exists()) {
response.setStatus(404);
String jsonResult = JsonHelper.outResult(false, "404 file not found!");
JsonHelper.write(response, jsonResult);
return;
}
// response.setCharacterEncoding("utf-8");
// response.setContentType("multipart/form-data");
// response.setHeader("Content-Disposition", "attachment;fileName="
// + fileName);
InputStream inputStream = new FileInputStream(file);
OutputStream os = response.getOutputStream();
byte[] b = new byte[1024];
int length;
while ((length = inputStream.read(b)) > 0) {
os.write(b, 0, length);
}
inputStream.close();
} catch (Exception ex) {
LogUtil.writeLog(ex.toString());
response.setStatus(500);
ex.printStackTrace();
String jsonResult = JsonHelper.outResult(false, "500 err "+ex.getMessage());
JsonHelper.write(response, jsonResult);
}
}
}
客户端调用示例
package com.f2bpm.restfullapi; import java.util.HashMap;
import java.util.Map; import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient; import com.f2bpm.base.core.utils.Guid;
import com.f2bpm.base.core.utils.HttpClientUtil;
import com.f2bpm.base.core.utils.string.StringUtil; public class WorkflowBusinessTestClient { String webApiUrl = "http://localhost:8081/f2bpm/restfullapi"; /**
* get请求 get只适合参数相对简单的请求,如果参数过长或参数字符复杂,则使用Post 来传参请求
* 这里仅是一个get示例,不建议使用get统一使用Post来做 不建议使用get统一使用Post来做 不建议使用get统一使用Post来做
* 不建议使用get统一使用Post来做
*/
public void getTask() {
String url = webApiUrl + "/workflowBusiness/getTask?";
String queryString="id=123";
String param = HttpClientUtil.urlEncode(queryString.toString()); // 特殊字符进行转义
url = url + param;
String jsonRes = HttpClientUtil.get(url);
System.out.println(jsonRes);
} // public void getTodoList() {
// String urlString = webApiUrl + "/workflowBusiness/getTodoList/?";
// StringBuilder queryString = new StringBuilder();
// queryString.append(StringUtil.format("authorJson={loginAccount:\"{0}\"}", "admin"));
// queryString.append(StringUtil.format("&parmJson={pageIndex:{0},pageSize:{1},sort:\"{2}\",order:\"{3}\"}", 1, 2, "CreatedTime", "desc"));
// String param = HttpClientUtil.urlEncode(queryString.toString()); // 特殊字符进行转义
// urlString = urlString + param;
// String jsonRes = HttpClientUtil.get(urlString);
// System.out.println(jsonRes);
// } /**
* 获取待办列表
*/
public void getTodoList() {
String url= webApiUrl + "/workflowBusiness/getTodoList/";
Map<String, String> params = new HashMap<String, String>();
StringBuilder queryString = new StringBuilder();
params.put("authorJson", StringUtil.format("{loginAccount:\"{0}\"}", "admin"));
params.put("parmJson", StringUtil.format("{pageIndex:{0},pageSize:{1},sort:\"{2}\",order:\"{3}\",whereStr:\"{4}\",}", 1, 2, "CreatedTime", "desc", ""));
String jsonRes = HttpClientUtil.post(url, params);
System.out.println(jsonRes);
}
/**
* 获取已办列表
*/
public void getDoneList() {
String urlString = webApiUrl + "/workflowBusiness/getDoneList/";
Map<String, String> params = new HashMap<String, String>();
StringBuilder queryString = new StringBuilder();
params.put("authorJson", StringUtil.format("{loginAccount:\"{0}\"}", "admin"));
// isHistory:0 进行中的已办,isHistory:1流程已结束并归档的已办
params.put("parmJson", StringUtil.format("{isHistory:0,pageIndex:{0},pageSize:{1},sort:\"{2}\",order:\"{3}\",whereStr:\"{4}\",}", 1, 2, "CreatedTime", "desc", ""));
String jsonRes = HttpClientUtil.post(urlString, params);
System.out.println(jsonRes);
} /**
* 发起流程
*/
public void startWorkflow() {
String urlString = webApiUrl + "/workflowBusiness/startWorkflow/";
Map<String, String> params = new HashMap<String, String>();
String onlineFormData = StringUtil.format("[{\"mainTable\":\"csb\",\"data\":[{\"name\":\"csb.nl\",\"value\":\"22\"},{\"name\":\"csb.MyId\",\"value\":\"\"},{\"name\":\"csb.zz\",\"value\":\"RestFull测试\"},{\"name\":\"csb.xm\",\"value\":\"RestFull姓名\"}],\"subTables\":[]}]");
params.put("authorJson", StringUtil.format("{loginAccount:\"{0}\"}", "admin"));
params.put("parmJson", StringUtil.format("{appId:\"{0}\",wiid:\"{1}\",businessKey:\"{2}\",title:\"{3}\",opinion:\"{4}\",jsonFormData:{5}}", "ZX", Guid.getGuid(), Guid.getGuid(), "应用端RestFull请求测试", "同意", onlineFormData));
// String param = HttpClientUtil.urlEncode(queryString.toString());
// //特殊字符进行转义
String jsonRes = HttpClientUtil.post(urlString, params);
System.out.println(jsonRes);
} /**
* 驳回到提单
*/
public void rejectFlow() {
String urlString = webApiUrl + "/workflowBusiness/rejectFlow/";
Map<String, String> params = new HashMap<String, String>();
params.put("authorJson", StringUtil.format("{loginAccount:\"{0}\"}", "admin"));
params.put("parmJson", StringUtil.format("{taskId:\"{0}\",opinion:\"{1}\"}", "d212c718-b6ea-481e-b7cc-1f44a9d47fd0", "驳回"));
String jsonRes = HttpClientUtil.post(urlString, params);
System.out.println(jsonRes);
} /**
* 作废工单
*/
public void invalidFlow() {
String urlString = webApiUrl + "/workflowBusiness/invalidFlow/";
Map<String, String> params = new HashMap<String, String>();
params.put("authorJson", StringUtil.format("{loginAccount:\"{0}\"}", "admin"));
params.put("parmJson", StringUtil.format("{taskId:\"{0}\",opinion:\"{1}\"}", "eac4e893-822c-46ec-9ba6-a1c028a1cef3", "作废"));
String jsonRes = HttpClientUtil.post(urlString, params);
System.out.println(jsonRes);
} /**
* 审批执行代办任务
*/
public void approvalTask() {
String urlString = webApiUrl + "/workflowBusiness/approvalTask/";
Map<String, String> params = new HashMap<String, String>();
params.put("authorJson", StringUtil.format("{loginAccount:\"{0}\"}", "admin"));
params.put("parmJson", StringUtil.format("{taskId:\"{0}\",opinion:\"{1}\"}", "5f267057-ddd4-470a-bca4-a797caac3e09", "原则同意"));
String jsonRes = HttpClientUtil.post(urlString, params);
System.out.println(jsonRes);
} /**
*上传在线表单附件,返回字段值单个附件值
/表单附件的字段值格式:
/#[{"value":"/attachments/workflow/files/20170714215204767.txt","text":"TestClient.txt"}]#
*/
public void uploadFormFile() {
String urlString = webApiUrl + "/workflowBusiness/uploadFile/?loginAccount=admin";
String filepath = "C:\\Users\\Administrator\\Desktop\\TestClient.txt";
String jsonRes = HttpClientUtil.postFile(urlString, filepath);
System.out.println(jsonRes);
}
/**
* 下载表单附件
*/
public void downLoadFile() {
String urlString = webApiUrl + "/workflowBusiness/downloadFile/";
//保存到本地的地址
String filepath = "C:\\Users\\Administrator\\Desktop\\TestClient.txt"; Map<String, String> params = new HashMap<String, String>();
params.put("authorJson", StringUtil.format("{login Account:\"{0}\"}", "admin"));
params.put("parmJson", StringUtil.format("{filePath:\"{0}\"}", "/attachments/workflow/files/20170714215204767.txt"));
String jsonRes = HttpClientUtil.downLoadFile(urlString,filepath, params);
System.out.println(jsonRes); } public static void main(String[] args) {
WorkflowBusinessTestClient client = new WorkflowBusinessTestClient();
client.downLoadFile();
System.out.print("结束");
} }
F2BPM 开发Api与RESTfull应用服务Api 层次关系及示例的更多相关文章
- AutoCAD开发选择----ObjectARX还是.net API(转载)
本文基于AutoCAD 2006新推出的.NET API为工具,介绍了在.NET平台下对AutoCAD进行二次开发的技术,并与目前常用的VBA.ObjectARX作了对比.同时讨论了如何弥补.NET ...
- 使用.NET 6开发TodoList应用(21)——实现API版本控制
系列导航及源代码 使用.NET 6开发TodoList应用文章索引 需求 API接口版本管理,对于一些规模稍大的企业应用来说,是经常需要关注的一大需求.尽管我们的示例程序TodoList很简单,但是我 ...
- 基于Node和Electron开发了轻量版API接口请求调试工具——Post-Tool
Electron 是一个使用 JavaScript.HTML 和 CSS 构建桌面应用程序的框架. 嵌入 Chromium 和 Node.js 到 二进制的 Electron 允许您保持一个 Java ...
- web开发如何使用百度地图API(一)判断点是否在范围内
准备工作 注册开发者 创建应用 拿到百度地图ak 前端实现方案 引入百度地图API和工具类库 <script type="text/javascript" src=" ...
- 使用 WSO2 API Manager 管理 Rest API
WSO2 API Manager 简介 随着软件工程的增多,越来越多的软件提供各种不同格式.不同定义的 Rest API 作为资源共享,而由于这些 API 资源的异构性,很难对其进行复用.WSO2 A ...
- [Web API] 如何让 Web API 统一回传格式以及例外处理[转]
[Web API] 如何让 Web API 统一回传格式以及例外处理 前言 当我们在开发 Web API 时,一般的情况下每个 API 回传的数据型态或格式都不尽相同,如果你的项目从头到尾都是由你一个 ...
- [Web API] 如何让 Web API 统一回传格式以及例外处理
[Web API] 如何让 Web API 统一回传格式以及例外处理 前言 当我们在开发 Web API 时,一般的情况下每个 API 回传的数据型态或格式都不尽相同,如果你的项目从头到尾都是由你一个 ...
- Google API Design Guide (谷歌API设计指南)中文版
面向资源的设计 这份设计指南的目标是帮助开发人员设计简单.一致.易用的网络API.同时,它也有助于收敛基于socket的API和(注:原文是with,这里翻译为“和”)基于HTTP的REST API. ...
- web API简介(一):API,Ajax和Fetch
概述 今天逛MDN,无意中看到了web API简介,觉得挺有意思的,就认真读了一下. 下面是我在读的时候对感兴趣的东西的总结,供自己开发时参考,相信对其他人也有用. 什么是API API (Appli ...
随机推荐
- go 学习成长之路
一.go的搭建 二.初识go 三.混个脸熟--go 四.go的语言结构 五.go的常量与变量 六.go基础数据类型 七.go 条件语句 八.go 运算符 九.go条件语句switch 十.go循环语句 ...
- ZOJ3714JavaBeans
#!/usr/bin/env python # encoding: utf-8 t = int(raw_input()) for i in range(t): n,k = [int(x) for x ...
- 【BZOJ2762】[JLOI2011]不等式组(树状数组)
题目: BZOJ2762 分析: 加入的不等式分三种情况 当\(a>0\),可以变成\(x>\lfloor \frac{c-b}{a}\rfloor\) 当\(a=0\),若\(b> ...
- ACM_寻找第N小序列
寻找第N小序列 Time Limit: 2000/1000ms (Java/Others) Problem Description: Now our hero finds the door to th ...
- OFDM同步算法之Minn算法
minn算法代码 算法原理 训练序列结构 T=[B B -B -B],其中B表示由长度为N/4的复伪随机序列PN,ifft变换得到的符号序列 (原文解释):B represent samples of ...
- CSS——tab导航demo
问题总结: 1.ul要比外套div宽度的值大一点 2.ul需要往左移动1px 3.外套的div设置overflow隐藏 解决抖动: 1.li宽度设置98px,padding左右值1px,hover之后 ...
- 学习随笔-Java WebService
webService 可以将应用程序转换成网络应用程序.是简单的可共同操作的消息收发框架. 基本的webService平台是 XML 和 HTTP. HTTP 是最常用的互联网协议: XML 是 we ...
- Java_Web三大框架之Hibernate+jsp+selvect+HQL登入验证
刚开始接触Hibernate有些举手无措,觉得配置信息太多.经过一个星期的适应,Hibernate比sql简单方便多了.下面做一下Hibernate+jsp+selvect+HQL登入验证. 第一步: ...
- 12、scala函数式编程集合
1.Scala的集合体系结构 2.List 3.LikedList 4.Set 5.集合的函数式编程 6.函数式编程综合案例:统计单词总数 1.Scala的集合体系结构 Scala中集合体系主要包括: ...
- java设计模式03装饰者者模式
动态地给一个对象添加一些额外的职责.就增加功能来说, Decorator模式相比生成子类更为灵活.该模式以对客 户端透明的方式扩展对象的功能. (1)在不影响其他对象的情况下,以动态.透明的方式给单个 ...