1 | package unicon.matthews.oneroster.service.repository; |
||
2 | |||
3 | import java.io.Serializable; |
||
4 | |||
5 | import org.apache.commons.lang3.StringUtils; |
||
6 | import org.apache.commons.lang3.builder.ToStringBuilder; |
||
7 | import org.apache.commons.lang3.builder.ToStringStyle; |
||
8 | import org.springframework.data.annotation.Id; |
||
9 | import org.springframework.data.mongodb.core.mapping.Document; |
||
10 | |||
11 | import unicon.matthews.oneroster.Course; |
||
12 | |||
13 | @Document |
||
14 | public class MongoCourse implements Serializable { |
||
15 | private static final long serialVersionUID = 1L; |
||
16 | |||
17 | @Id private String id; |
||
18 | private String orgId; |
||
19 | private String tenantId; |
||
20 | private String courseSourcedId; |
||
21 | private Course course; |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
22 | |||
23 | private MongoCourse() {} |
||
24 | |||
25 | public String getId() { |
||
26 | return id; |
||
27 | } |
||
28 | public String getOrgId() { |
||
29 | return orgId; |
||
30 | } |
||
31 | public String getTenantId() { |
||
32 | return tenantId; |
||
33 | } |
||
34 | public String getCourseSourcedId() { |
||
35 | return courseSourcedId; |
||
36 | } |
||
37 | public Course getCourse() { |
||
38 | return course; |
||
39 | } |
||
40 | |||
41 | @Override |
||
42 | public String toString() { |
||
43 | return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); |
||
44 | } |
||
45 | |||
46 | @Override |
||
47 | public int hashCode() { |
||
48 | final int prime = 31; |
||
49 | int result = 1; |
||
50 | result = prime * result + ((course == null) ? 0 : course.hashCode()); |
||
51 | result = prime * result + ((courseSourcedId == null) ? 0 : courseSourcedId.hashCode()); |
||
52 | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
||
53 | result = prime * result + ((orgId == null) ? 0 : orgId.hashCode()); |
||
54 | result = prime * result + ((tenantId == null) ? 0 : tenantId.hashCode()); |
||
55 | return result; |
||
56 | } |
||
57 | |||
58 | @Override |
||
59 | public boolean equals(Object obj) { |
||
60 | if (this == obj) |
||
61 | return true; |
||
62 | if (obj == null) |
||
63 | return false; |
||
64 | if (getClass() != obj.getClass()) |
||
65 | return false; |
||
66 | MongoCourse other = (MongoCourse) obj; |
||
67 | if (course == null) { |
||
68 | if (other.course != null) |
||
69 | return false; |
||
70 | } else if (!course.equals(other.course)) |
||
71 | return false; |
||
72 | if (courseSourcedId == null) { |
||
73 | if (other.courseSourcedId != null) |
||
74 | return false; |
||
75 | } else if (!courseSourcedId.equals(other.courseSourcedId)) |
||
76 | return false; |
||
77 | if (id == null) { |
||
78 | if (other.id != null) |
||
79 | return false; |
||
80 | } else if (!id.equals(other.id)) |
||
81 | return false; |
||
82 | if (orgId == null) { |
||
83 | if (other.orgId != null) |
||
84 | return false; |
||
85 | } else if (!orgId.equals(other.orgId)) |
||
86 | return false; |
||
87 | if (tenantId == null) { |
||
88 | if (other.tenantId != null) |
||
89 | return false; |
||
90 | } else if (!tenantId.equals(other.tenantId)) |
||
91 | return false; |
||
92 | return true; |
||
93 | } |
||
94 | |||
95 | public static class Builder { |
||
96 | private MongoCourse _mongoCourse = new MongoCourse(); |
||
97 | |||
98 | public Builder withCourseSourcedId(String courseSourcedId) { |
||
99 | _mongoCourse.courseSourcedId = courseSourcedId; |
||
100 | return this; |
||
101 | } |
||
102 | |||
103 | public Builder withId(String id) { |
||
104 | _mongoCourse.id = id; |
||
105 | return this; |
||
106 | } |
||
107 | |||
108 | public Builder withCourse(Course course) { |
||
109 | _mongoCourse.course = course; |
||
110 | return this; |
||
111 | } |
||
112 | |||
113 | public Builder withOrgId(String orgId) { |
||
114 | _mongoCourse.orgId = orgId; |
||
115 | return this; |
||
116 | } |
||
117 | |||
118 | public Builder withTenantId(String tenantId) { |
||
119 | _mongoCourse.tenantId = tenantId; |
||
120 | return this; |
||
121 | } |
||
122 | |||
123 | public MongoCourse build() { |
||
124 | |||
125 | if (StringUtils.isBlank(_mongoCourse.orgId) |
||
126 | || StringUtils.isBlank(_mongoCourse.tenantId) |
||
127 | || StringUtils.isBlank(_mongoCourse.courseSourcedId) |
||
128 | || _mongoCourse.course == null) { |
||
129 | throw new IllegalStateException(_mongoCourse.toString()); |
||
130 | } |
||
131 | |||
132 | return _mongoCourse; |
||
133 | } |
||
134 | } |
||
135 | |||
136 | } |
||
137 |