-
Notifications
You must be signed in to change notification settings - Fork 57
Expand file tree
/
Copy pathCodeTemplateLibrary.java
More file actions
235 lines (200 loc) · 8.2 KB
/
CodeTemplateLibrary.java
File metadata and controls
235 lines (200 loc) · 8.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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
168
169
170
171
172
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/*
* Copyright (c) Mirth Corporation. All rights reserved.
*
* http://www.mirthcorp.com
*
* The software in this package is published under the terms of the MPL license a copy of which has
* been included with this distribution in the LICENSE.txt file.
*/
package com.mirth.connect.model.codetemplates;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.TreeSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import com.mirth.connect.donkey.util.DonkeyElement;
import com.mirth.connect.donkey.util.migration.Migratable;
import com.mirth.connect.donkey.util.purge.Purgable;
import com.mirth.connect.donkey.util.purge.PurgeUtil;
import com.mirth.connect.model.Cacheable;
import com.thoughtworks.xstream.annotations.XStreamAlias;
@XStreamAlias("codeTemplateLibrary")
public class CodeTemplateLibrary implements Serializable, Migratable, Purgable, Cacheable<CodeTemplateLibrary> {
private String id;
private String name;
private Integer revision;
private Calendar lastModified;
private String description;
private boolean includeNewChannels;
private Set<String> enabledChannelIds;
private Set<String> disabledChannelIds;
private List<CodeTemplate> codeTemplates;
public CodeTemplateLibrary() {
id = UUID.randomUUID().toString();
enabledChannelIds = new TreeSet<String>();
disabledChannelIds = new TreeSet<String>();
codeTemplates = new ArrayList<CodeTemplate>();
}
public CodeTemplateLibrary(CodeTemplateLibrary library) {
id = library.getId();
name = library.getName();
revision = library.getRevision();
lastModified = library.getLastModified();
description = library.getDescription();
includeNewChannels = library.isIncludeNewChannels();
enabledChannelIds = new TreeSet<String>(library.getEnabledChannelIds());
disabledChannelIds = new TreeSet<String>(library.getDisabledChannelIds());
codeTemplates = new ArrayList<CodeTemplate>();
if (CollectionUtils.isNotEmpty(library.getCodeTemplates())) {
for (CodeTemplate codeTemplate : library.getCodeTemplates()) {
codeTemplates.add(new CodeTemplate(codeTemplate));
}
}
}
@Override
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@Override
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@Override
public Integer getRevision() {
return revision;
}
public void setRevision(Integer revision) {
this.revision = revision;
}
public Calendar getLastModified() {
return lastModified;
}
public void setLastModified(Calendar lastModified) {
this.lastModified = lastModified;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public boolean isIncludeNewChannels() {
return includeNewChannels;
}
public void setIncludeNewChannels(boolean includeNewChannels) {
this.includeNewChannels = includeNewChannels;
}
public Set<String> getEnabledChannelIds() {
return enabledChannelIds;
}
public void setEnabledChannelIds(Set<String> enabledChannelIds) {
this.enabledChannelIds = enabledChannelIds;
}
public Set<String> getDisabledChannelIds() {
return disabledChannelIds;
}
public void setDisabledChannelIds(Set<String> disabledChannelIds) {
this.disabledChannelIds = disabledChannelIds;
}
public List<CodeTemplate> getCodeTemplates() {
return codeTemplates;
}
public void setCodeTemplates(List<CodeTemplate> codeTemplates) {
this.codeTemplates = codeTemplates;
}
public void sortCodeTemplates() {
if (CollectionUtils.isNotEmpty(codeTemplates)) {
Collections.sort(codeTemplates, new Comparator<CodeTemplate>() {
@Override
public int compare(CodeTemplate o1, CodeTemplate o2) {
if (o1.getName() == null && o2.getName() != null) {
return -1;
} else if (o1.getName() != null && o2.getName() == null) {
return 1;
} else if (o1.getName() == null && o2.getName() == null) {
return 0;
} else {
return o1.getName().compareToIgnoreCase(o2.getName());
}
}
});
}
}
public void replaceCodeTemplatesWithIds() {
if (CollectionUtils.isNotEmpty(codeTemplates)) {
List<CodeTemplate> list = new ArrayList<CodeTemplate>();
for (CodeTemplate codeTemplate : codeTemplates) {
list.add(new CodeTemplate(codeTemplate.getId()));
}
codeTemplates = list;
}
}
@Override
public CodeTemplateLibrary cloneIfNeeded() {
return new CodeTemplateLibrary(this);
}
// @formatter:off
@Override public void migrate3_0_1(DonkeyElement element) {}
@Override public void migrate3_0_2(DonkeyElement element) {}
@Override public void migrate3_1_0(DonkeyElement element) {}
@Override public void migrate3_2_0(DonkeyElement element) {}
@Override public void migrate3_3_0(DonkeyElement element) {}
@Override public void migrate3_4_0(DonkeyElement element) {}
@Override public void migrate3_5_0(DonkeyElement element) {}
@Override public void migrate3_6_0(DonkeyElement element) {}
@Override public void migrate3_7_0(DonkeyElement element) {}
@Override public void migrate3_9_0(DonkeyElement element) {}
@Override public void migrate3_11_0(DonkeyElement element) {}
@Override public void migrate3_11_1(DonkeyElement element) {}
@Override public void migrate3_12_0(DonkeyElement element) {}// @formatter:on
@Override
public Map<String, Object> getPurgedProperties() {
Map<String, Object> purgedProperties = new HashMap<String, Object>();
purgedProperties.put("id", id);
purgedProperties.put("nameChars", PurgeUtil.countChars(name));
purgedProperties.put("lastModified", lastModified);
purgedProperties.put("descriptionChars", PurgeUtil.countChars(description));
purgedProperties.put("includeNewChannels", includeNewChannels);
purgedProperties.put("enabledChannelIdsCount", enabledChannelIds.size());
purgedProperties.put("disabledChannelIdsCount", disabledChannelIds.size());
List<Map<String, Object>> purgedCodeTemplates = new ArrayList<Map<String, Object>>();
for (CodeTemplate codeTemplate : codeTemplates) {
purgedCodeTemplates.add(codeTemplate.getPurgedProperties());
}
purgedProperties.put("codeTemplates", purgedCodeTemplates);
return purgedProperties;
}
@Override
public boolean equals(Object obj) {
return EqualsBuilder.reflectionEquals(this, obj, false, null, "UNASSIGNED_LIBRARY_ID", "UNASSIGNED_LIBRARY_DESCRIPTION");
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(getClass().getName()).append('[');
builder.append("id=").append(id).append(", ");
builder.append("name=").append(name).append(", ");
builder.append("revision=").append(revision).append(", ");
builder.append("lastModified=").append(lastModified).append(", ");
builder.append("description=").append(description).append(", ");
builder.append("includeNewChannels=").append(includeNewChannels).append(", ");
builder.append("enabledChannelIds=").append(enabledChannelIds).append(", ");
builder.append("disabledChannelIds=").append(disabledChannelIds).append(", ");
builder.append("codeTemplates=").append(codeTemplates).append(']');
return builder.toString();
}
}