Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f4c5ad6

Browse files
committed
1_App_layers patch
1 parent 0b8cec0 commit f4c5ad6

18 files changed

+430
-1
lines changed

config/tomcat/setenv.bat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
rem run tomcat with JMX ability
2+
rem Run Tomcat as admin
3+
rem for remote connection add -Djava.rmi.server.hostname=TomcatServer_IP
4+
set CATALINA_OPTS=-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=1099 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package ru.javawebinar.topjava;
2+
3+
import ru.javawebinar.topjava.model.Role;
4+
5+
import java.util.Set;
6+
7+
/**
8+
* GKislin
9+
* 06.03.2015.
10+
*/
11+
public class LoggedUser {
12+
13+
public static int id() {
14+
return 1;
15+
}
16+
}

src/main/java/ru/javawebinar/topjava/LoggerWrapper.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
5+
import ru.javawebinar.topjava.util.exception.NotFoundException;
56

67
/**
78
* User: gkislin
@@ -69,4 +70,9 @@ public UnsupportedOperationException getUnsupportedOperationException(String msg
6970
logger.error(msg);
7071
return new UnsupportedOperationException(msg);
7172
}
72-
}
73+
74+
public NotFoundException getNotFoundException(String reason) {
75+
logger.error("No data found");
76+
return new NotFoundException(reason);
77+
}
78+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package ru.javawebinar.topjava.model;
2+
3+
/**
4+
* User: gkislin
5+
* Date: 22.08.2014
6+
*/
7+
public class BaseEntity {
8+
9+
protected Integer id;
10+
11+
public BaseEntity() {
12+
}
13+
14+
protected BaseEntity(Integer id) {
15+
this.id = id;
16+
}
17+
18+
public void setId(Integer id) {
19+
this.id = id;
20+
}
21+
22+
public Integer getId() {
23+
return id;
24+
}
25+
26+
public boolean isNew() {
27+
return (this.id == null);
28+
}
29+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package ru.javawebinar.topjava.model;
2+
3+
/**
4+
* User: gkislin
5+
* Date: 22.08.2014
6+
*/
7+
public class NamedEntity extends BaseEntity {
8+
9+
protected String name;
10+
11+
public NamedEntity() {
12+
}
13+
14+
protected NamedEntity(Integer id, String name) {
15+
super(id);
16+
this.name = name;
17+
}
18+
19+
public void setName(String name) {
20+
this.name = name;
21+
}
22+
23+
public String getName() {
24+
return this.name;
25+
}
26+
27+
@Override
28+
public String toString() {
29+
return name;
30+
}
31+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package ru.javawebinar.topjava.model;
2+
3+
/**
4+
* User: gkislin
5+
* Date: 22.08.2014
6+
*/
7+
public enum Role {
8+
ROLE_USER,
9+
ROLE_ADMIN
10+
}
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package ru.javawebinar.topjava.model;
2+
3+
import java.util.Date;
4+
import java.util.EnumSet;
5+
import java.util.Set;
6+
7+
/**
8+
* User: gkislin
9+
* Date: 22.08.2014
10+
*/
11+
public class User extends NamedEntity {
12+
13+
private String email;
14+
15+
private String password;
16+
17+
private boolean enabled = true;
18+
19+
private Date registered;
20+
21+
private Set<Role> roles;
22+
23+
public User() {
24+
}
25+
26+
public User(Integer id, String name, String email, String password, Role role, Role... roles) {
27+
super(id, name);
28+
this.email = email;
29+
this.password = password;
30+
this.enabled = true;
31+
this.roles = EnumSet.of(role, roles);
32+
}
33+
34+
public String getEmail() {
35+
return email;
36+
}
37+
38+
public void setEmail(String email) {
39+
this.email = email;
40+
}
41+
42+
public void setPassword(String password) {
43+
this.password = password;
44+
}
45+
46+
public Date getRegistered() {
47+
return registered;
48+
}
49+
50+
public void setRegistered(Date registered) {
51+
this.registered = registered;
52+
}
53+
54+
public void setEnabled(boolean enabled) {
55+
this.enabled = enabled;
56+
}
57+
58+
public boolean isEnabled() {
59+
return enabled;
60+
}
61+
62+
public Set<Role> getRoles() {
63+
return roles;
64+
}
65+
66+
public String getPassword() {
67+
return password;
68+
}
69+
70+
@Override
71+
public String toString() {
72+
return "User (" +
73+
"id=" + id +
74+
", email=" + email +
75+
", name=" + name +
76+
", enabled=" + enabled +
77+
", roles=" + roles +
78+
')';
79+
}
80+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package ru.javawebinar.topjava.repository;
2+
3+
/**
4+
* GKislin
5+
* 06.03.2015.
6+
*/
7+
public interface UserMealRepository {
8+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package ru.javawebinar.topjava.repository;
2+
3+
import ru.javawebinar.topjava.model.User;
4+
5+
import java.util.List;
6+
7+
/**
8+
* User: gkislin
9+
* Date: 22.08.2014
10+
*/
11+
public interface UserRepository {
12+
User save(User user);
13+
14+
// false if not found
15+
boolean delete(int id);
16+
17+
// null if not found
18+
User get(int id);
19+
20+
// null if not found
21+
User getByEmail(String email);
22+
23+
List<User> getAll();
24+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package ru.javawebinar.topjava.service;
2+
3+
/**
4+
* GKislin
5+
* 15.06.2015.
6+
*/
7+
public interface UserMealService {
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package ru.javawebinar.topjava.service;
2+
3+
import ru.javawebinar.topjava.repository.UserMealRepository;
4+
5+
/**
6+
* GKislin
7+
* 06.03.2015.
8+
*/
9+
public class UserMealServiceImpl implements UserMealService {
10+
11+
private UserMealRepository repository;
12+
13+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ru.javawebinar.topjava.service;
2+
3+
4+
import ru.javawebinar.topjava.model.User;
5+
import ru.javawebinar.topjava.util.exception.NotFoundException;
6+
7+
import java.util.List;
8+
9+
/**
10+
* User: gkislin
11+
* Date: 22.08.2014
12+
*/
13+
public interface UserService {
14+
15+
public User save(User user);
16+
17+
public void delete(int id) throws NotFoundException;
18+
19+
public User get(int id) throws NotFoundException;
20+
21+
public User getByEmail(String email) throws NotFoundException;
22+
23+
public List<User> getAll();
24+
25+
public void update(User user) throws NotFoundException;
26+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package ru.javawebinar.topjava.service;
2+
3+
import ru.javawebinar.topjava.model.User;
4+
import ru.javawebinar.topjava.repository.UserRepository;
5+
import ru.javawebinar.topjava.util.exception.ExceptionUtil;
6+
import ru.javawebinar.topjava.util.exception.NotFoundException;
7+
8+
import java.util.List;
9+
10+
/**
11+
* GKislin
12+
* 06.03.2015.
13+
*/
14+
public class UserServiceImpl implements UserService {
15+
16+
private UserRepository repository;
17+
18+
public User save(User user) {
19+
return repository.save(user);
20+
}
21+
22+
public void delete(int id) {
23+
ExceptionUtil.check(repository.delete(id), id);
24+
}
25+
26+
public User get(int id) throws NotFoundException {
27+
return ExceptionUtil.check(repository.get(id), id);
28+
}
29+
30+
public User getByEmail(String email) throws NotFoundException {
31+
return ExceptionUtil.check(repository.getByEmail(email), "email=" + email);
32+
}
33+
34+
public List<User> getAll() {
35+
return repository.getAll();
36+
}
37+
38+
public void update(User user) throws NotFoundException {
39+
ExceptionUtil.check(repository.save(user), user.getId());
40+
}
41+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package ru.javawebinar.topjava.util.exception;
2+
3+
4+
import ru.javawebinar.topjava.LoggerWrapper;
5+
6+
/**
7+
* User: gkislin
8+
* Date: 14.05.2014
9+
*/
10+
public class ExceptionUtil {
11+
private static final LoggerWrapper LOG = LoggerWrapper.get(ExceptionUtil.class);
12+
13+
public static void check(boolean found, int id) {
14+
check(found, "id=" + id);
15+
}
16+
17+
public static <T> T check(T object, int id) {
18+
return check(object, "id=" + id);
19+
}
20+
21+
public static <T> T check(T object, String msg) {
22+
check(object != null, msg);
23+
return object;
24+
}
25+
26+
public static void check(boolean found, String msg) {
27+
if (!found) throw LOG.getNotFoundException("Not found entity with " + msg);
28+
}
29+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package ru.javawebinar.topjava.util.exception;
2+
3+
/**
4+
* User: gkislin
5+
* Date: 19.08.2014
6+
*/
7+
public class NotFoundException extends RuntimeException {
8+
public NotFoundException(String message) {
9+
super(message);
10+
}
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package ru.javawebinar.topjava.web.meal;
2+
3+
import ru.javawebinar.topjava.service.UserMealServiceImpl;
4+
5+
/**
6+
* GKislin
7+
* 06.03.2015.
8+
*/
9+
public class UserMealRestController {
10+
private UserMealServiceImpl service;
11+
12+
}

0 commit comments

Comments
 (0)