1 package com.trendmicro.grid.acl.metadata;
2
3 import net.sf.tinyjee.util.Assert;
4
5 import java.io.Serializable;
6 import java.util.Collection;
7 import java.util.Collections;
8
9
10
11
12
13
14
15 public class ValidationInstructions implements Serializable {
16
17 private static final long serialVersionUID = 1935531867355113339L;
18
19 private String activeProfileName;
20 private Collection<String> roles;
21 private AccessLevel level;
22
23 public ValidationInstructions(String activeProfileName, AccessLevel level, Collection<String> roles) {
24 Assert.assertNotNull("activeProfileName", activeProfileName);
25 this.activeProfileName = activeProfileName;
26 this.level = level == null ? AccessLevel.PUBLIC : level;
27 this.roles = roles == null ? Collections.<String>emptySet() : roles;
28 }
29
30 public String getActiveProfileName() {
31 return activeProfileName;
32 }
33
34 public Collection<String> getRoles() {
35 return roles;
36 }
37
38 public AccessLevel getLevel() {
39 return level;
40 }
41
42
43
44
45
46
47
48
49 public boolean isElementVisible(AccessLevel elementLevel) {
50 if (elementLevel == null)
51 elementLevel = AccessLevel.PRIVATE;
52 return level.ordinal() <= elementLevel.ordinal();
53 }
54
55
56
57
58 @Override
59 public boolean equals(Object o) {
60 if (this == o) return true;
61 if (!(o instanceof ValidationInstructions)) return false;
62 ValidationInstructions that = (ValidationInstructions) o;
63 if (!activeProfileName.equals(that.activeProfileName)) return false;
64 return level == that.level && roles.equals(that.roles);
65 }
66
67
68
69
70 @Override
71 public int hashCode() {
72 int result = activeProfileName.hashCode();
73 result = 31 * result + roles.hashCode();
74 result = 31 * result + level.hashCode();
75 return result;
76 }
77
78
79
80
81 @Override
82 public String toString() {
83 return "ValidationInstructions{" +
84 "activeProfileName='" + activeProfileName + '\'' +
85 ", roles=" + roles +
86 ", level=" + level +
87 '}';
88 }
89 }