blob: aa3303843858e2e017ed8019cc35ae4e77864525 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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;
}
}
|