Apereo-Learning-Analytics-Initiative /
OpenLRW
| 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.Class; |
||
| 12 | |||
| 13 | @Document |
||
| 14 | public class MongoClass 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 Class klass; |
||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
| 21 | private String classSourcedId; |
||
| 22 | |||
| 23 | private MongoClass() {} |
||
| 24 | |||
| 25 | public String getId() { |
||
| 26 | return id; |
||
| 27 | } |
||
| 28 | |||
| 29 | public String getOrgId() { |
||
| 30 | return orgId; |
||
| 31 | } |
||
| 32 | |||
| 33 | public String getTenantId() { |
||
| 34 | return tenantId; |
||
| 35 | } |
||
| 36 | |||
| 37 | public Class getKlass() { |
||
| 38 | return klass; |
||
| 39 | } |
||
| 40 | |||
| 41 | public String getClassSourcedId() { |
||
| 42 | return classSourcedId; |
||
| 43 | } |
||
| 44 | |||
| 45 | @Override |
||
| 46 | public String toString() { |
||
| 47 | return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE); |
||
| 48 | } |
||
| 49 | |||
| 50 | @Override |
||
| 51 | public int hashCode() { |
||
| 52 | final int prime = 31; |
||
| 53 | int result = 1; |
||
| 54 | result = prime * result + ((classSourcedId == null) ? 0 : classSourcedId.hashCode()); |
||
| 55 | result = prime * result + ((id == null) ? 0 : id.hashCode()); |
||
| 56 | result = prime * result + ((klass == null) ? 0 : klass.hashCode()); |
||
| 57 | result = prime * result + ((orgId == null) ? 0 : orgId.hashCode()); |
||
| 58 | result = prime * result + ((tenantId == null) ? 0 : tenantId.hashCode()); |
||
| 59 | return result; |
||
| 60 | } |
||
| 61 | |||
| 62 | @Override |
||
| 63 | public boolean equals(Object obj) { |
||
| 64 | if (this == obj) |
||
| 65 | return true; |
||
| 66 | if (obj == null) |
||
| 67 | return false; |
||
| 68 | if (getClass() != obj.getClass()) |
||
| 69 | return false; |
||
| 70 | MongoClass other = (MongoClass) obj; |
||
| 71 | if (classSourcedId == null) { |
||
| 72 | if (other.classSourcedId != null) |
||
| 73 | return false; |
||
| 74 | } else if (!classSourcedId.equals(other.classSourcedId)) |
||
| 75 | return false; |
||
| 76 | if (id == null) { |
||
| 77 | if (other.id != null) |
||
| 78 | return false; |
||
| 79 | } else if (!id.equals(other.id)) |
||
| 80 | return false; |
||
| 81 | if (klass == null) { |
||
| 82 | if (other.klass != null) |
||
| 83 | return false; |
||
| 84 | } else if (!klass.equals(other.klass)) |
||
| 85 | return false; |
||
| 86 | if (orgId == null) { |
||
| 87 | if (other.orgId != null) |
||
| 88 | return false; |
||
| 89 | } else if (!orgId.equals(other.orgId)) |
||
| 90 | return false; |
||
| 91 | if (tenantId == null) { |
||
| 92 | if (other.tenantId != null) |
||
| 93 | return false; |
||
| 94 | } else if (!tenantId.equals(other.tenantId)) |
||
| 95 | return false; |
||
| 96 | return true; |
||
| 97 | } |
||
| 98 | |||
| 99 | public static class Builder { |
||
| 100 | private MongoClass _mongoClass = new MongoClass(); |
||
| 101 | |||
| 102 | public Builder withClassSourcedId(String classSourcedId) { |
||
| 103 | _mongoClass.classSourcedId = classSourcedId; |
||
| 104 | return this; |
||
| 105 | } |
||
| 106 | |||
| 107 | public Builder withId(String id) { |
||
| 108 | _mongoClass.id = id; |
||
| 109 | return this; |
||
| 110 | } |
||
| 111 | |||
| 112 | public Builder withKlass(Class klass) { |
||
| 113 | _mongoClass.klass = klass; |
||
| 114 | return this; |
||
| 115 | } |
||
| 116 | |||
| 117 | public Builder withOrgId(String orgId) { |
||
| 118 | _mongoClass.orgId = orgId; |
||
| 119 | return this; |
||
| 120 | } |
||
| 121 | |||
| 122 | public Builder withTenantId(String tenantId) { |
||
| 123 | _mongoClass.tenantId = tenantId; |
||
| 124 | return this; |
||
| 125 | } |
||
| 126 | |||
| 127 | public MongoClass build() { |
||
| 128 | |||
| 129 | if (StringUtils.isBlank(_mongoClass.orgId) |
||
| 130 | || StringUtils.isBlank(_mongoClass.tenantId) |
||
| 131 | || StringUtils.isBlank(_mongoClass.classSourcedId) |
||
| 132 | || _mongoClass.klass == null) { |
||
| 133 | throw new IllegalStateException(_mongoClass.toString()); |
||
| 134 | } |
||
| 135 | |||
| 136 | return _mongoClass; |
||
| 137 | } |
||
| 138 | } |
||
| 139 | |||
| 140 | |||
| 141 | } |
||
| 142 |