Merge pull request #31 from RS7-SECIOTSRK/server
[platform/core/security/suspicious-activity-monitor.git] / servers / dsm / src / main / java / com / samsung / dsm / rule / parser / RuleConfig.java
1 /*
2  * In Samsung Ukraine R&D Center (SRK under a contract between)
3  * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
4  * Copyright (C) 2017 Samsung Electronics Co., Ltd. All rights reserved.
5  */
6 package com.samsung.dsm.rule.parser;
7
8 import java.util.Arrays;
9
10 import org.apache.commons.lang3.builder.EqualsBuilder;
11 import org.apache.commons.lang3.builder.HashCodeBuilder;
12
13 import com.google.common.base.Objects;
14
15 /**
16  * The type Rule config.
17  * 
18  * @author <A HREF="mailto:y.zozulia@samsung.com">Yevhen Zozulia</A>
19  * @version 1.0
20  * @file RuleConfig.java
21  * @brief The type Rule config.
22  * @date Created : 10/6/2017
23  * @date Modified : 11/2/2017
24  * @copyright In Samsung Ukraine R&D Center (SRK under a contract between)
25  * @par LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
26  * @par Copyright : (c) Samsung Electronics Co, Ltd 2017. All rights reserved.
27  */
28 public class RuleConfig {
29
30     private Rule[] rules;
31
32     /**
33      * Instantiates a new Rule config.
34      *
35      * @param rules the rules
36      */
37     RuleConfig(Rule[] rules) {
38         this.rules = Arrays.copyOf(rules, rules.length);
39     }
40
41     /**
42      * Get rules rule [ ].
43      *
44      * @return the rule [ ]
45      */
46     public Rule[] getRules() {
47         return rules;
48     }
49
50     /**
51      * The type Rule.
52      */
53     public static class Rule {
54
55         private String message;
56         private String title;
57         private String code;
58         private String fields;
59         private String find;
60         private String reportType;
61         private String ruleType;
62         private String priority;
63         private String look;
64         private String used;
65         private Policy[] policies;
66
67         /**
68          * Gets message.
69          *
70          * @return the message
71          */
72         public String getMessage() {
73             return message;
74         }
75
76         /**
77          * Sets message.
78          *
79          * @param message the message
80          */
81         public void setMessage(String message) {
82             this.message = message;
83         }
84
85         /**
86          * Gets title.
87          *
88          * @return the title
89          */
90         public String getTitle() {
91             return title;
92         }
93
94         /**
95          * Sets title.
96          *
97          * @param title the title
98          */
99         public void setTitle(String title) {
100             this.title = title;
101         }
102
103         /**
104          * Gets code.
105          *
106          * @return the code
107          */
108         public String getCode() {
109             return code;
110         }
111
112         /**
113          * Sets code.
114          *
115          * @param code the code
116          */
117         public void setCode(String code) {
118             this.code = code;
119         }
120
121         /**
122          * Gets fields.
123          *
124          * @return the fields
125          */
126         public String getFields() {
127             return fields;
128         }
129
130         /**
131          * Sets fields.
132          *
133          * @param fields the fields
134          */
135         public void setFields(String fields) {
136             this.fields = fields;
137         }
138
139         /**
140          * Gets find.
141          *
142          * @return the find
143          */
144         public String getFind() {
145             return find;
146         }
147
148         /**
149          * Sets find.
150          *
151          * @param find the find
152          */
153         public void setFind(String find) {
154             this.find = find;
155         }
156
157         /**
158          * Gets report type.
159          *
160          * @return the report type
161          */
162         public String getReportType() {
163             return reportType;
164         }
165
166         /**
167          * Sets report type.
168          *
169          * @param reportType the report type
170          */
171         public void setReportType(String reportType) {
172             this.reportType = reportType;
173         }
174
175         /**
176          * Gets rule type.
177          *
178          * @return the rule type
179          */
180         public String getRuleType() {
181             return ruleType;
182         }
183
184         /**
185          * Sets rule type.
186          *
187          * @param ruleType the rule type
188          */
189         public void setRuleType(String ruleType) {
190             this.ruleType = ruleType;
191         }
192
193         /**
194          * Gets priority.
195          *
196          * @return the priority
197          */
198         public String getPriority() {
199             return priority;
200         }
201
202         /**
203          * Sets priority.
204          *
205          * @param priority the priority
206          */
207         public void setPriority(String priority) {
208             this.priority = priority;
209         }
210
211         /**
212          * Gets look.
213          *
214          * @return the look
215          */
216         public String getLook() {
217             return look;
218         }
219
220         /**
221          * Sets look.
222          *
223          * @param look the look
224          */
225         public void setLook(String look) {
226             this.look = look;
227         }
228
229         /**
230          * Gets used.
231          *
232          * @return the used
233          */
234         public String getUsed() {
235             return used;
236         }
237
238         /**
239          * Sets used.
240          *
241          * @param used the used
242          */
243         public void setUsed(String used) {
244             this.used = used;
245         }
246
247         /**
248          * Get policies policy [ ].
249          *
250          * @return the policy [ ]
251          */
252         public Policy[] getPolicies() {
253             return policies;
254         }
255
256         /**
257          * Sets policies.
258          *
259          * @param policies the policies
260          */
261         public void setPolicies(Policy[] policies) {
262             this.policies = Arrays.copyOf(policies, policies.length);
263         }
264
265         // CHECKSTYLE_OFF:Magic Number
266         @Override
267         public int hashCode() {
268             return new HashCodeBuilder(1, 31).append(code).append(fields).append(find).append(look).append(message)
269                     .append(priority).append(reportType).append(ruleType).append(title).append(used).append(policies)
270                     .toHashCode();
271         }
272         // CHECKSTYLE_ON:Magic Number
273
274         @Override
275         public boolean equals(Object obj) {
276             if (this == obj) {
277                 return true;
278             }
279             if (obj == null) {
280                 return false;
281             }
282             if (getClass() != obj.getClass()) {
283                 return false;
284             }
285             Rule rule = (Rule) obj;
286
287             return new EqualsBuilder().append(code, rule.code).append(fields, rule.fields).append(find, rule.find)
288                     .append(look, rule.look).append(message, rule.message).append(priority, rule.priority)
289                     .append(reportType, rule.reportType).append(ruleType, rule.ruleType).append(title, rule.title)
290                     .append(used, rule.used).append(policies, rule.policies).isEquals();
291
292         }
293
294         @Override
295         public String toString() {
296             return "Rule [message=" + message + ", title=" + title + ", code=" + code + ", fields=" + fields + ", find="
297                 + find + ", reportType=" + reportType + ", ruleType=" + ruleType + ", priority=" + priority + ", look="
298                 + look + ", used=" + used + "]";
299         }
300
301         /**
302          * The type Policy.
303          */
304         public static class Policy {
305
306             private String name;
307             private int state;
308             private String[] items;
309
310             /**
311              * Instantiates a new Policy.
312              *
313              * @param name  the name
314              * @param state the state
315              * @param items the items
316              */
317             public Policy(String name, int state, String[] items) {
318                 this.name = name;
319                 this.state = state;
320                 this.items = Arrays.copyOf(items, items.length);
321             }
322
323             /**
324              * Gets name.
325              *
326              * @return the name
327              */
328             public String getName() {
329                 return name;
330             }
331
332             /**
333              * Gets state.
334              *
335              * @return the state
336              */
337             public int getState() {
338                 return state;
339             }
340
341             /**
342              * Get items string [ ].
343              *
344              * @return the string [ ]
345              */
346             public String[] getItems() {
347                 return items;
348             }
349
350             /**
351              * Sets name.
352              *
353              * @param name the name
354              */
355             public void setName(String name) {
356                 this.name = name;
357             }
358
359             /**
360              * Sets state.
361              *
362              * @param state the state
363              */
364             public void setState(int state) {
365                 this.state = state;
366             }
367
368             /**
369              * Sets items.
370              *
371              * @param items the items
372              */
373             public void setItems(String[] items) {
374                 this.items = Arrays.copyOf(items, items.length);
375             }
376
377             @Override
378             public boolean equals(Object o) {
379                 if (this == o) {
380                     return true;
381                 }
382                 if (!(o instanceof Policy)) {
383                     return false;
384                 }
385                 Policy policy = (Policy) o;
386
387                 return new EqualsBuilder().append(state, policy.state).append(name, policy.name)
388                         .append(items, policy.items).isEquals();
389             }
390
391             // CHECKSTYLE_OFF:Magic Number
392             @Override
393             public int hashCode() {
394                 return new HashCodeBuilder(17, 37).append(name).append(state).append(items).toHashCode();
395             }
396             // CHECKSTYLE_ON:Magic Number
397
398             @Override
399             public String toString() {
400                 return Objects.toStringHelper(this).add("name", name).add("state", state).add("items", "skipped...")
401                         .toString();
402             }
403         }
404     }
405 }