1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.itracker.model;
20
21 import java.util.ArrayList;
22 import java.util.Arrays;
23 import java.util.Comparator;
24 import java.util.List;
25
26 import org.apache.commons.lang.builder.CompareToBuilder;
27 import org.apache.commons.lang.builder.ToStringBuilder;
28 import org.itracker.services.util.SystemConfigurationUtilities;
29
30
31
32
33 public class SystemConfiguration extends AbstractEntity {
34
35
36 public static final Comparator<SystemConfiguration> VERSION_COMPARATOR = new SystemConfigurationComparator();
37
38
39
40 private static final long serialVersionUID = 1L;
41
42 private String version;
43
44 private List<CustomField> customFields = new ArrayList<CustomField>();
45
46 private List<Configuration> resolutions = new ArrayList<Configuration>();
47 private List<Configuration> severities = new ArrayList<Configuration>();
48 private List<Configuration> statuses = new ArrayList<Configuration>();
49
50 public SystemConfiguration() {
51 }
52
53 public String getVersion() {
54 return (version == null ? "" : version);
55 }
56
57 public void setVersion(String value) {
58 version = value;
59 }
60
61 public List<CustomField> getCustomFields() {
62 return customFields;
63 }
64
65 public void setCustomFields(List<CustomField> value) {
66 if (value != null) {
67 customFields = value;
68 }
69 }
70
71 public List<Configuration> getResolutions() {
72 return (resolutions == null ? new ArrayList<Configuration>()
73 : resolutions);
74 }
75
76 public void setResolutions(List<Configuration> value) {
77 if (value != null) {
78 resolutions = value;
79 }
80 }
81
82 public List<Configuration> getSeverities() {
83 return (severities == null ? new ArrayList<Configuration>()
84 : severities);
85 }
86
87 public void setSeverities(List<Configuration> value) {
88 if (value != null) {
89 severities = value;
90 }
91 }
92
93 public List<Configuration> getStatuses() {
94 return (statuses == null ? new ArrayList<Configuration>() : statuses);
95 }
96
97 public void setStatuses(List<Configuration> value) {
98 if (value != null) {
99 statuses = value;
100 }
101 }
102
103 public void addConfiguration(Configuration configuration) {
104 if (configuration != null) {
105 Configuration[] newArray;
106
107 if (configuration.getType() == SystemConfigurationUtilities.TYPE_RESOLUTION) {
108 newArray = new Configuration[getResolutions().size() + 1];
109 if (getResolutions().size() > 0) {
110 System.arraycopy((Object) resolutions, 0,
111 (Object) newArray, 0, resolutions.size());
112 }
113 newArray[getResolutions().size()] = configuration;
114 setResolutions(Arrays.asList(newArray));
115 } else if (configuration.getType() == SystemConfigurationUtilities.TYPE_SEVERITY) {
116 newArray = new Configuration[getSeverities().size() + 1];
117 if (getSeverities().size() > 0) {
118 System.arraycopy((Object) severities, 0, (Object) newArray,
119 0, severities.size());
120 }
121 newArray[getSeverities().size()] = configuration;
122 setSeverities(Arrays.asList(newArray));
123 } else if (configuration.getType() == SystemConfigurationUtilities.TYPE_STATUS) {
124 newArray = new Configuration[getStatuses().size() + 1];
125 if (getStatuses().size() > 0) {
126 System.arraycopy((Object) statuses, 0, (Object) newArray,
127 0, statuses.size());
128 }
129 newArray[getStatuses().size()] = configuration;
130 setStatuses(Arrays.asList(newArray));
131 }
132 }
133 }
134
135 public String toString() {
136
137 return new ToStringBuilder(this).append("id", getId()).append("version", getVersion()).toString();
138
139 }
140
141 private static final class SystemConfigurationComparator implements
142 Comparator<SystemConfiguration> {
143 public int compare(SystemConfiguration o1, SystemConfiguration o2) {
144 return new CompareToBuilder().append(o1.getVersion(),
145 o2.getVersion()).append(o1.getId(), o2.getId())
146 .toComparison();
147 }
148 }
149 }