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