Process Center RESTfull Solutions and Examples

1 Introduction

1.1. Application Background

At any time, more and more IT systems are built in enterprises, and various independent systems are often formed in an enterprise. Each system is relatively independent and lacks process support. In order to provide process services to various application systems through the construction of process service centers, and The individual systems are linked by a twisted belt at the center of the process.

The process center is only used for background management, and users do not need to log in to this platform to manage related business operations. The process center acts as the server of the application system, and the application system acts as the client. The process center is a black box model relative to the front-end customers.

F2BPM Process Service Center (abbreviation: F2 Process Center) refers to the way that F2-BPM is independently deployed as a process platform as a process center, and other application systems call the F2 process service center for process flow usage scenarios.

Because each enterprise's own IT system application environment is very different, this document provides common application solutions for F2 process center to be applied to enterprises as process center.

At present, more and more enterprise architecture solutions tend to be based on the http protocol "micro-service" architecture, that is, interaction through RESTfull mode, lighter integration and calling are more convenient. The F2 process center application solution is also recommended to adopt a lightweight RESTfull solution.

1 Application scheme mode

Since the IT construction environment of the enterprise is not the same, the solution for building a process center will also be different. One of the biggest problems faced by independent deployment is the problem of user organizational structure and login authorization . Therefore, different enterprise IT environments will have different application solution models.

  • Scheme mode 1: The process center and the application system share the same database, and the program is independently deployed
  • Scheme mode 2: The database and program of the process center and the application system are all independently deployed
  • Scheme mode 3: There is a unified personnel system user authentication server, and the databases and programs of the process center and application system are independently deployed

 

2. Shared database schema

 

 

Shared database mode means that the process center and the application system use the same data, and all the tables in the process center, including the user organization table of the process center platform, are created in the database where the application system is located.

At this time, the user organization structure management of the process center is only the user organization used as the platform administrator of the process center, which is used to log in to maintain and manage the affairs related to the process center. The user organization of the process center has nothing to do with the user organization of the application system. When calling the process center to execute the process flow, the user organization is the user organization that accesses the configuration and reads the application system through the user organization structure of the engine, and still uses the user organization structure of the application system itself. The process engine uses the user organization structure of the application system itself, and the maintenance and management of the user organization structure is still managed by the application system itself.

For details on the data interaction mechanism of RESTfull, see Oauth2.0 Interface Interaction Authorization.

 

3. Standalone program and database deployment mode

 

Both the database and the program are deployed independently, which means that the process center and the application system use their own databases.

At this time, the user organization structure management in the process center's own database is only the user organization used by the process center platform administrator to log in to maintain and manage the affairs related to the process center. The user organization of the process center has nothing to do with the user organization of the application system.

When calling the process center to execute the process flow, the user organization reads the user organization structure of the application system by rewriting the F2 user organization structure interface, and still uses the user organization structure of the application system itself. The process engine uses the user organization structure that rewrites the application system that implements the organization interface. The maintenance and management of the user organization structure is still managed by the application system itself.

 

 

 

 

 

 

4. Use the unified personnel system user server mode

 

 

 

Using the unified personnel user system mode is the most complicated but also the best way for the overall enterprise informatization environment. It is generally used in relatively large group companies. Their characteristic is that the database and programs are deployed independently, and the process center and application system use their own. At the same time, each application system is a unified user organization structure of HR system.

At this time, the user organization structure management in the process center's own database is only the user organization used by the process center platform administrator to log in to maintain and manage the affairs related to the process center. The user organization of the process center has nothing to do with the user organization of the application system.

When calling the process center to execute the process flow, the user organization reads the user organization structure of the application system by rewriting the F2 user organization structure interface, and still uses the user organization structure of the application system itself. The process engine uses the user organization structure that rewrites the application system that implements the organization interface. The maintenance and management of the user organization structure is still managed by the application system itself.

Due to the large differences in the information environment of enterprises, this plan needs to be implemented jointly by all parties to achieve better results. We can collaborate on implementation.

5. OAuth2.0 identity authorization of RESTfull interface

5.1. What is OAuth2.0

OAuth2.0 is an open network standard for authorization, which is widely used all over the world. The current version is version 2.0. This article applies the design ideas and operating principles of OAuth 2.0 to the F2BPM platform. The goal is to prevent the interface from being used unsafely, and the interface call must have a secure authentication mechanism.

5.2. OAuth2.0 and F2-BPM Platform

Because the F2-BPM platform is to be used as a process service center, the F2-BPM platform will deal with multiple application systems, and multiple application systems need to be verified by calling the RESTfull interface to drive the process or obtain process-related data. Carrying out the interface affects the return of the correct data result.

The F2-BPM process center has built an OAuth2.0 identity authentication mechanism. The authentication of this identity should be at the system level. The purpose is to verify whether the system from the legitimate registration should call the RESTfull interface of the process center. (The user of the data association is determined when the application system develops and calls the process center interface).

The OAuthor in the process center is not used for third-party login authentication of users, of course, it can also be extended, but because F2-BPM is not a unified user management center of the personnel system.

5.3. F2-BPM process center OAUTH2.0 authentication sequence diagram

 

The data that each interface must pass: {token:,corpId:,timeStamp:,nonce:,signature:,loginAccount:}

parameter name

Value example

illustrate

token

oa_token

System token, a fixed value configured in the process center

corpId

app255e7feb2645dd23

The ID of the application system, the ID generated when the application access is added in the process center

timeStamp

1706261844

Timestamp, generated by the client during delivery, format: yymmddHHmm, the error between client time and F2-PBM process center system time is allowed to be within 10 minutes

nonce

6723

Anytime, generated by the client with at least 4 digits of anytime

signature

ZDlUMYZeJKXrAZ3ofbZQnXgSPqjHw9xw2lZhj0hPwF5VUG0yMhknJ-8Ql8zK8tXK

Signature encrypted string, the client encrypts timeStamp and nonce to get this signed encrypted string

loginAccount

zs

The account of the current login, which is used as the identity of the current login when the process engine is running the process engine by calling the RESTfull interface.

 

Interaction parameters between the client and the process center interface:

authorJson: mainly the authentication-related parameters of the interface identity, to verify the legitimacy of the source of the visitor


parmJson:请求业务数据的参数,比如分页参数,查询参数等 所有RESTfull都统一只有这两个Json参数 一般情况

 

get只适合参数相对简单的请求,如果参数过长或参数字符复杂,则使用Post 来传参请求。

 

F2BPM接口强大的特点:服务端可以利用F2BPM非常丰富的流程引擎WAPI进行发布成RESTfull服务接口供应用端系统调用。而且接口可以是无状态的请求

客户端Get请求  

/**
	 * get请求 get只适合参数相对简单的请求,如果参数过长或参数字符复杂,则使用Post 来传参请求
	 */
	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);
	} 

对应的流程中心服务端

// 获取待办列表
	@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);
	}

 

Post请求来获取已办列表

	/**
	 * post请求,参数复杂的建议使用Post来请求
	 */
	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);
	}
// 流程中心服务-已办列表
	@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);
	}
	

 输出响应结果到客户端

{"success":true,"msg":"","total":4,"pageCount":2,"pageSize":2,"pageIndex":1, "rows":[{"isDelegateDone":false,"workflowTitle":"[系统管理员费用报销申请","directBackAct":"","expectFinishedTime":
{"time":0,"minutes":0,"seconds":0,"hours":8,"month":0,"year":70,"timezoneOffset":-480,"day":4,"date":1},"businessKey":"","delegatorUserId":"","respondType":"","delegatorRealName":"",
"wiState":0,"taskExpireTime":null,"mainActivityInstanceId":"","urgency":1,"activityId":"","extStr":"","formId":"bdd11478-97ab-4612-beb9-575a3b3d9e83","description":"","userId":"3c1df0b3-a4d9-4731-b143-02e81bce17ce",
"delegatorName":"","userName":"","opinion":"","taskDealHours":0,"appType":"表单规则2.0","isCirculated":false,"isContainDelegator":false,"currentActors":"","fromCreatorID":"","taskCreateType":"","currentActivityName":"",
"openBizDate":"","isReferred":false,"delegatorMobile":"","importance":1,"workflowInstanceState":2,"activityShowName":"","userMobile":"","creatorRealName":"系统管理员","userDpId":"","taskState":0,"isValid":false,"userDpName":"",
"appId":"AI","formType":"","workflowInstanceId":"5e2cfc5b-3fcb-4ae5-ae1d-fbdb27b4980e","creatorDepartId":"ZhiBoRuanJian","fromTaskId":"","activityInstanceId":"","taskSeq":"","creator":"admin","realTime":null,
"isCompleter":false,"completedType":"","delegatorDpName":"","finishedTime":null,"isMobileApproval":true,"stepId":0,"delegatorDpId":"","isMobileStart":true,"taskId":"","requirement":"",
"createdTime":{"time":1499268876000,"minutes":34,"seconds":36,"hours":23,"month":6,"year":117,"timezoneOffset":-480,"day":3,"date":5},"logs":"","creatorId":"3c1df0b3-a4d9-4731-b143-02e81bce17ce",
"taskRemark":"","secrecy":0,"commentCount":0,"mainWorkflowInstanceId":"","appName":"费用报销申请","sheetId":"AI20170705233435818","completedTime":null,"isDelegatorCompleted":false,"workflowId":"3944ea6b-0c56-4c74-8b0e-af82d128f772",
"urgeTimes":0,"creatorDpName":"致博软件","fromCreator":"","realName":"","activityName":"","startedTime":{"time":1499268876000,"minutes":34,"seconds":36,"hours":23,"month":6,"year":117,
"timezoneOffset":-480,"day":3,"date":5}},{"isDelegateDone":false,"workflowTitle":"系统管理员请假申请","directBackAct":"","expectFinishedTime":{"time":0,"minutes":0,"seconds":0,"hours":8,"month":0,"year":70,"timezoneOffset":-480,"day":4,"date":1},"businessKey":"","delegatorUserId":"","respondType":"","delegatorRealName":"",
"wiState":0,"taskExpireTime":null,"mainActivityInstanceId":"","urgency":1,"activityId":"","extStr":"","formId":"26eaad7d-ccfb-4b6a-96c0-4efc796f5d47","description":"","userId":"3c1df0b3-a4d9-4731-b143-02e81bce17ce","delegatorName":"","userName":"","opinion":"","taskDealHours":0,"appType":"表单规则2.0","isCirculated":false,"isContainDelegator":false,"currentActors":"","fromCreatorID":"","taskCreateType":"","currentActivityName":"","openBizDate":"","isReferred":false,"delegatorMobile":"","importance":1,"workflowInstanceState":2,"activityShowName":"","userMobile":"",
"creatorRealName":"系统管理员","userDpId":"","taskState":0,"isValid":false,"userDpName":"",
"appId":"AB","formType":"","workflowInstanceId":"a4d02561-7dc0-4a01-9368-687363081395","creatorDepartId":"ZhiBoRuanJian","fromTaskId":"",
"activityInstanceId":"","taskSeq":"","creator":"admin","realTime":null,"isCompleter":false,"completedType":"","delegatorDpName":"","finishedTime":null,"isMobileApproval":true,"stepId":0,"delegatorDpId":"","isMobileStart":true,"taskId":"","requirement":"","createdTime":{"time":1499268669000,"minutes":31,"seconds":9,"hours":23,"month":6,"year":117,"timezoneOffset":-480,"day":3,"date":5},"logs":"","creatorId":"3c1df0b3-a4d9-4731-b143-02e81bce17ce","taskRemark":"","secrecy":0,"commentCount":0,"mainWorkflowInstanceId":"",
"appName":"请假申请","sheetId":"AB20170705233109293","completedTime":null,"isDelegatorCompleted":false,
"workflowId":"4ae848a4-70f7-4e76-bd35-8f33f5bbac1e","urgeTimes":0,"creatorDpName":"致博软件","fromCreator":"","realName":"","activityName":"",
"startedTime":{"time":1499268669000,"minutes":31,"seconds":9,"hours":23,"month":6,"year":117,"timezoneOffset":-480,"day":3,"date":5}}]}
 

 

发起流程示例:

客户端

/**
     * post请求
     */
    public void startWorkflow() {
        String urlString = webApiUrl + "/workflowBusiness/startWorkflow/";
        Map<String, String> params = new HashMap<String, String>();
        StringBuilder queryString = new StringBuilder();
        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);
    }

 

流程中心处理发起请求

    //响应发起流程
    @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);
    }

 

  

  

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326261407&siteId=291194637