Messages.java 11.4 KB
Newer Older
R
test  
roo00 已提交
1 2
package com.x.base.core.project.config;

R
Ray 已提交
3 4 5 6
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
R
test  
roo00 已提交
7 8
import java.util.concurrent.ConcurrentSkipListMap;

R
Ray 已提交
9 10
import org.apache.commons.lang3.StringUtils;

R
Ray 已提交
11 12 13
import com.google.gson.Gson;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
R
Ray 已提交
14
import com.x.base.core.project.config.Message.ActivemqConsumer;
R
Ray 已提交
15
import com.x.base.core.project.config.Message.ApiConsumer;
R
Ray 已提交
16
import com.x.base.core.project.config.Message.CalendarConsumer;
R
Ray 已提交
17
import com.x.base.core.project.config.Message.Consumer;
R
Ray 已提交
18
import com.x.base.core.project.config.Message.DingdingConsumer;
R
Ray 已提交
19 20 21 22
import com.x.base.core.project.config.Message.HadoopConsumer;
import com.x.base.core.project.config.Message.JdbcConsumer;
import com.x.base.core.project.config.Message.KafkaConsumer;
import com.x.base.core.project.config.Message.MailConsumer;
R
Ray 已提交
23 24 25
import com.x.base.core.project.config.Message.MpweixinConsumer;
import com.x.base.core.project.config.Message.PmsinnerConsumer;
import com.x.base.core.project.config.Message.QiyeweixinConsumer;
R
Ray 已提交
26 27
import com.x.base.core.project.config.Message.RestfulConsumer;
import com.x.base.core.project.config.Message.TableConsumer;
R
Ray 已提交
28 29 30
import com.x.base.core.project.config.Message.WelinkConsumer;
import com.x.base.core.project.config.Message.WsConsumer;
import com.x.base.core.project.config.Message.ZhengwudingdingConsumer;
R
Ray 已提交
31
import com.x.base.core.project.gson.XGsonBuilder;
R
test  
roo00 已提交
32 33 34 35 36 37
import com.x.base.core.project.message.MessageConnector;

public class Messages extends ConcurrentSkipListMap<String, Message> {

	private static final long serialVersionUID = 1336172131736006743L;

R
Ray 已提交
38 39 40 41 42 43 44 45
	private static final Message MESSAGE_ALL = new Message(MessageConnector.CONSUME_WS,
			MessageConnector.CONSUME_PMS_INNER, MessageConnector.CONSUME_CALENDAR, MessageConnector.CONSUME_DINGDING,
			MessageConnector.CONSUME_WELINK, MessageConnector.CONSUME_ZHENGWUDINGDING,
			MessageConnector.CONSUME_QIYEWEIXIN, MessageConnector.CONSUME_MPWEIXIN, MessageConnector.CONSUME_KAFKA,
			MessageConnector.CONSUME_ACTIVEMQ, MessageConnector.CONSUME_RESTFUL, MessageConnector.CONSUME_MAIL,
			MessageConnector.CONSUME_API, MessageConnector.CONSUME_JDBC, MessageConnector.CONSUME_TABLE,
			MessageConnector.CONSUME_HADOOP);

R
Ray 已提交
46 47 48 49
	private static final Message MESSAGE_NOTICE = new Message(MessageConnector.CONSUME_WS,
			MessageConnector.CONSUME_PMS_INNER, MessageConnector.CONSUME_DINGDING, MessageConnector.CONSUME_WELINK,
			MessageConnector.CONSUME_ZHENGWUDINGDING, MessageConnector.CONSUME_QIYEWEIXIN,
			MessageConnector.CONSUME_MPWEIXIN);
R
Ray 已提交
50 51 52 53 54

	private static final Message MESSAGE_OUTER = new Message(MessageConnector.CONSUME_KAFKA,
			MessageConnector.CONSUME_ACTIVEMQ, MessageConnector.CONSUME_RESTFUL, MessageConnector.CONSUME_MAIL,
			MessageConnector.CONSUME_API, MessageConnector.CONSUME_JDBC, MessageConnector.CONSUME_TABLE,
			MessageConnector.CONSUME_HADOOP);
R
update  
roo00 已提交
55

R
Ray 已提交
56
	public Messages() {
R
test  
roo00 已提交
57 58 59
		super();
	}

R
Ray 已提交
60
	public static Messages defaultInstance() {
R
test  
roo00 已提交
61
		Messages o = new Messages();
R
Ray 已提交
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
		o.put(MessageConnector.TYPE_APPLICATION_CREATE, MESSAGE_OUTER.cloneThenSetDescription("创建应用"));
		o.put(MessageConnector.TYPE_APPLICATION_UPDATE, MESSAGE_OUTER.cloneThenSetDescription("更新应用"));
		o.put(MessageConnector.TYPE_APPLICATION_DELETE, MESSAGE_OUTER.cloneThenSetDescription("删除应用"));
		o.put(MessageConnector.TYPE_PROCESS_CREATE, MESSAGE_OUTER.cloneThenSetDescription("创建流程"));
		o.put(MessageConnector.TYPE_PROCESS_UPDATE, MESSAGE_OUTER.cloneThenSetDescription("创建流程"));
		o.put(MessageConnector.TYPE_PROCESS_DELETE, MESSAGE_OUTER.cloneThenSetDescription("删除流程"));
		o.put(MessageConnector.TYPE_ACTIVITY_MESSAGE, MESSAGE_OUTER.cloneThenSetDescription("有新的工作通过消息节点"));
		o.put(MessageConnector.TYPE_WORK_TO_WORKCOMPLETED, MESSAGE_OUTER.cloneThenSetDescription("工作完成转已完成工作"));
		o.put(MessageConnector.TYPE_WORK_CREATE, MESSAGE_OUTER.cloneThenSetDescription("创建工作"));
		o.put(MessageConnector.TYPE_WORK_DELETE, MESSAGE_OUTER.cloneThenSetDescription("删除工作"));
		o.put(MessageConnector.TYPE_WORKCOMPLETED_CREATE, MESSAGE_OUTER.cloneThenSetDescription("创建已完成工作"));
		o.put(MessageConnector.TYPE_WORKCOMPLETED_DELETE, MESSAGE_OUTER.cloneThenSetDescription("删除已完成工作"));
		o.put(MessageConnector.TYPE_TASK_TO_TASKCOMPLETED, MESSAGE_OUTER.cloneThenSetDescription("待办完成转已办"));
		o.put(MessageConnector.TYPE_TASK_CREATE, MESSAGE_ALL.cloneThenSetDescription("创建待办"));
		o.put(MessageConnector.TYPE_TASK_DELETE, MESSAGE_OUTER.cloneThenSetDescription("删除待办"));
		o.put(MessageConnector.TYPE_TASK_URGE, MESSAGE_ALL.cloneThenSetDescription("待办即将过期催办"));
		o.put(MessageConnector.TYPE_TASK_EXPIRE, MESSAGE_ALL.cloneThenSetDescription("待办过期"));
		o.put(MessageConnector.TYPE_TASK_PRESS, MESSAGE_ALL.cloneThenSetDescription("待办提醒"));
		o.put(MessageConnector.TYPE_TASKCOMPLETED_CREATE, MESSAGE_OUTER.cloneThenSetDescription("已办创建"));
		o.put(MessageConnector.TYPE_TASKCOMPLETED_DELETE, MESSAGE_OUTER.cloneThenSetDescription("删除已办"));
		o.put(MessageConnector.TYPE_READ_TO_READCOMPLETED, MESSAGE_OUTER.cloneThenSetDescription("待阅转已阅"));
		o.put(MessageConnector.TYPE_READ_CREATE, MESSAGE_ALL.cloneThenSetDescription("待阅创建"));
		o.put(MessageConnector.TYPE_READ_DELETE, MESSAGE_OUTER.cloneThenSetDescription("待阅删除"));
		o.put(MessageConnector.TYPE_READCOMPLETED_CREATE, MESSAGE_OUTER.cloneThenSetDescription("已阅创建"));
		o.put(MessageConnector.TYPE_READCOMPLETED_DELETE, MESSAGE_OUTER.cloneThenSetDescription("已阅删除"));
		o.put(MessageConnector.TYPE_REVIEW_CREATE, MESSAGE_OUTER.cloneThenSetDescription("创建参阅"));
		o.put(MessageConnector.TYPE_REVIEW_DELETE, MESSAGE_OUTER.cloneThenSetDescription("删除参阅"));
		o.put(MessageConnector.TYPE_MEETING_INVITE, MESSAGE_ALL.cloneThenSetDescription("会议邀请"));
		o.put(MessageConnector.TYPE_MEETING_DELETE, MESSAGE_OUTER.cloneThenSetDescription("会议删除"));
		o.put(MessageConnector.TYPE_MEETING_ACCEPT, MESSAGE_ALL.cloneThenSetDescription("会议邀请接受"));
		o.put(MessageConnector.TYPE_MEETING_REJECT, MESSAGE_ALL.cloneThenSetDescription("会议邀请拒绝"));
		o.put(MessageConnector.TYPE_ATTACHMENT_CREATE, MESSAGE_OUTER.cloneThenSetDescription("创建附件"));
		o.put(MessageConnector.TYPE_ATTACHMENT_DELETE, MESSAGE_OUTER.cloneThenSetDescription("删除附件"));
		o.put(MessageConnector.TYPE_ATTACHMENT_SHARE, MESSAGE_ALL.cloneThenSetDescription("附件分享"));
		o.put(MessageConnector.TYPE_ATTACHMENT_SHARECANCEL, MESSAGE_ALL.cloneThenSetDescription("附件取消分享"));
		o.put(MessageConnector.TYPE_ATTACHMENT_EDITOR, MESSAGE_OUTER.cloneThenSetDescription("附件可编辑设置"));
		o.put(MessageConnector.TYPE_ATTACHMENT_EDITORCANCEL, MESSAGE_OUTER.cloneThenSetDescription("附件可编辑取消"));
		o.put(MessageConnector.TYPE_ATTACHMENT_EDITORMODIFY, MESSAGE_OUTER.cloneThenSetDescription("附件可编辑修改"));
		o.put(MessageConnector.TYPE_CALENDAR_ALARM, MESSAGE_ALL.cloneThenSetDescription("日历通知"));
		o.put(MessageConnector.TYPE_CUSTOM_CREATE, MESSAGE_OUTER.cloneThenSetDescription("自定义消息创建"));
		o.put(MessageConnector.TYPE_TEAMWORK_TASKCREATE, MESSAGE_ALL.cloneThenSetDescription("工作管理任务创建"));
		o.put(MessageConnector.TYPE_TEAMWORK_TASKUPDATE, MESSAGE_ALL.cloneThenSetDescription("工作管理任务更新"));
		o.put(MessageConnector.TYPE_TEAMWORK_TASKDELETE, MESSAGE_ALL.cloneThenSetDescription("工作管理任务删除"));
		o.put(MessageConnector.TYPE_TEAMWORK_TASKOVERTIME, MESSAGE_ALL.cloneThenSetDescription("工作管理任务超时"));
R
Ray 已提交
106
		o.put(MessageConnector.TYPE_TEAMWORK_CHAT, MESSAGE_NOTICE.cloneThenSetDescription("工作管理聊天"));
R
Ray 已提交
107
		o.put(MessageConnector.TYPE_CMS_PUBLISH, MESSAGE_OUTER.cloneThenSetDescription("内容管理发布"));
R
Ray 已提交
108
		o.put(MessageConnector.TYPE_CMS_PUBLISH_TO_CREATOR, MESSAGE_NOTICE.cloneThenSetDescription("内容管理发布创建者通知"));
R
Ray 已提交
109 110 111 112
		o.put(MessageConnector.TYPE_BBS_SUBJECTCREATE, MESSAGE_ALL.cloneThenSetDescription("论坛创建贴子"));
		o.put(MessageConnector.TYPE_BBS_REPLYCREATE, MESSAGE_ALL.cloneThenSetDescription("论坛创建回复"));
		o.put(MessageConnector.TYPE_MIND_FILESEND, MESSAGE_ALL.cloneThenSetDescription("脑图发送"));
		o.put(MessageConnector.TYPE_MIND_FILESHARE, MESSAGE_ALL.cloneThenSetDescription("脑图分享"));
R
test  
roo00 已提交
113 114 115
		return o;
	}

R
Ray 已提交
116
	public Map<String, String> getConsumersV2(String type) {
R
roo00 已提交
117
		Message o = this.get(type);
R
Ray 已提交
118 119 120 121
		Map<String, String> map = new HashMap<>();
		// 这里必须复制内容,在消息处理中会对列表进行删除操作
		if ((o != null) && (o.getConsumersV2() != null)) {
			map.putAll(o.getConsumersV2());
R
roo00 已提交
122 123 124 125
		}
		return map;
	}

R
Ray 已提交
126
	public List<Consumer> getConsumers(String type) {
R
Ray 已提交
127
		Message o = this.get(type);
R
Ray 已提交
128
		Gson gson = XGsonBuilder.instance();
R
Ray 已提交
129
		List<Consumer> list = new ArrayList<>();
R
Ray 已提交
130 131 132 133
		if ((null != o) && (null != o.getConsumers())) {
			for (JsonElement jsonElement : o.getConsumers()) {
				jsonToConsumer(gson, jsonElement, list);
			}
R
Ray 已提交
134 135 136 137
		}
		return list;
	}

R
Ray 已提交
138 139 140 141 142
	private void jsonToConsumer(Gson gson, JsonElement jsonElement, List<Consumer> list) {
		if ((null != jsonElement) && jsonElement.isJsonObject()) {
			JsonObject jsonObject = jsonElement.getAsJsonObject();
			JsonElement typeElement = jsonObject.get(Message.Consumer.FIELD_TYPE);
			if (null != typeElement && typeElement.isJsonPrimitive()) {
R
Ray 已提交
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
				switch (StringUtils.lowerCase(typeElement.getAsString())) {
				case MessageConnector.CONSUME_WS:
					list.add(gson.fromJson(jsonElement, WsConsumer.class));
					break;
				case MessageConnector.CONSUME_PMS_INNER:
					list.add(gson.fromJson(jsonElement, PmsinnerConsumer.class));
					break;
				case MessageConnector.CONSUME_CALENDAR:
					list.add(gson.fromJson(jsonElement, CalendarConsumer.class));
					break;
				case MessageConnector.CONSUME_DINGDING:
					list.add(gson.fromJson(jsonElement, DingdingConsumer.class));
					break;
				case MessageConnector.CONSUME_WELINK:
					list.add(gson.fromJson(jsonElement, WelinkConsumer.class));
					break;
				case MessageConnector.CONSUME_ZHENGWUDINGDING:
					list.add(gson.fromJson(jsonElement, ZhengwudingdingConsumer.class));
					break;
				case MessageConnector.CONSUME_QIYEWEIXIN:
					list.add(gson.fromJson(jsonElement, QiyeweixinConsumer.class));
					break;
				case MessageConnector.CONSUME_MPWEIXIN:
					list.add(gson.fromJson(jsonElement, MpweixinConsumer.class));
					break;
R
Ray 已提交
168 169 170 171
				case MessageConnector.CONSUME_KAFKA:
					list.add(gson.fromJson(jsonElement, KafkaConsumer.class));
					break;
				case MessageConnector.CONSUME_ACTIVEMQ:
R
Ray 已提交
172
					list.add(gson.fromJson(jsonElement, ActivemqConsumer.class));
R
Ray 已提交
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
					break;
				case MessageConnector.CONSUME_RESTFUL:
					list.add(gson.fromJson(jsonElement, RestfulConsumer.class));
					break;
				case MessageConnector.CONSUME_MAIL:
					list.add(gson.fromJson(jsonElement, MailConsumer.class));
					break;
				case MessageConnector.CONSUME_API:
					list.add(gson.fromJson(jsonElement, ApiConsumer.class));
					break;
				case MessageConnector.CONSUME_JDBC:
					list.add(gson.fromJson(jsonElement, JdbcConsumer.class));
					break;
				case MessageConnector.CONSUME_TABLE:
					list.add(gson.fromJson(jsonElement, TableConsumer.class));
					break;
				case MessageConnector.CONSUME_HADOOP:
					list.add(gson.fromJson(jsonElement, HadoopConsumer.class));
					break;
				default:
					list.add(gson.fromJson(jsonElement, Consumer.class));
					break;
				}
			}
		}
	}
}