summaryrefslogtreecommitdiff
path: root/src/main/java/seu/se/User.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/seu/se/User.java')
1 files changed, 65 insertions, 0 deletions
diff --git a/src/main/java/seu/se/User.java b/src/main/java/seu/se/User.java
new file mode 100644
index 0000000..aa33038
--- /dev/null
+++ b/src/main/java/seu/se/User.java
@@ -0,0 +1,65 @@
+package seu.se;
+
+
+import com.fasterxml.jackson.annotation.JsonCreator;
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+import org.springframework.data.neo4j.core.schema.GeneratedValue;
+import org.springframework.data.neo4j.core.schema.Id;
+import org.springframework.data.neo4j.core.schema.Node;
+
+@Node
+public class User {
+ @Id
+ @GeneratedValue
+ private Long id;
+ private String name;
+ @JsonIgnore
+ private String password;
+
+ @JsonCreator
+ public User(@JsonProperty("name") String name, @JsonProperty("password") String password) throws UserException {
+ setName(name);
+ setPassword(password);
+ }
+
+ static public class UserException extends Exception {
+ public UserException() {
+ }
+
+ public UserException(String message) {
+ super(message);
+ }
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public Long getId() {
+ return id;
+ }
+
+ public String getPassword() {
+ return password;
+ }
+
+ @Override
+ public String toString() {
+ return String.format("User id: %d, name: %s", id, name);
+ }
+
+ public void setName(String name) throws UserException {
+ if (name.length() > 22)
+ throw new UserException("Username too long!");
+ this.name = name;
+ }
+
+ public void setPassword(String password) throws UserException {
+ if (password.length() < 8)
+ throw new UserException("Password too short!");
+ this.password = password;
+ }
+}
+