Merge remote-tracking branch 'origin/master'

This commit is contained in:
snoop 2017-08-29 16:43:28 +09:00
commit bf85817e8b
9 changed files with 128 additions and 98 deletions

View File

@ -0,0 +1,15 @@
package com.loafle.overflow.commons.model;
import io.grpc.Context;
import io.grpc.Metadata;
import static io.grpc.Metadata.ASCII_STRING_MARSHALLER;
public class SessionMetadata {
public static final Context.Key<String> CTX_EMAIL_KEY = Context.key("email");
public static final Metadata.Key<String> METADATA_EMAIL_KEY = Metadata.Key.of("email", ASCII_STRING_MARSHALLER);
public static String getEmail() {
return CTX_EMAIL_KEY.get();
}
}

View File

@ -1,5 +1,6 @@
package com.loafle.overflow.module.member.service;
import com.loafle.overflow.commons.model.SessionMetadata;
import com.loafle.overflow.module.email.service.EmailAuthService;
import com.loafle.overflow.module.member.dao.MemberDAO;
import com.loafle.overflow.module.member.exception.*;
@ -68,6 +69,7 @@ public class MemberService {
}
public Member modify(Member member, String pw) {
String email = SessionMetadata.getEmail();
Member preMember = this.memberDAO.findByEmail(member.getEmail());
@ -87,7 +89,6 @@ public class MemberService {
}
public Member confirmPw(String signinId, String signinPw) {
Member preMember = this.memberDAO.findByEmail(signinId);
String encodePw = passwordEncoder.encode(signinPw);
@ -125,6 +126,8 @@ public class MemberService {
}
public void withdrawal(Member member) {
String email = SessionMetadata.getEmail();
// Todo DB delete?
}

View File

@ -19,4 +19,7 @@ public interface NotificationDAO extends JpaRepository<Notification, Long> {
@Query("SELECT n FROM Notification n WHERE n.member.id = :#{#member.id} and n.confirmDate IS NULL")
Page<Notification> findAllUnconfirmedByMember(@Param("member") Member member, Pageable pageRequest);
@Query("SELECT COUNT(n) FROM Notification n WHERE n.member.id = :#{#member.id} and n.confirmDate IS NULL")
int findAllUnconfirmedCountByMember(@Param("member") Member member);
}

View File

@ -67,7 +67,7 @@ public class Notification {
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "CREATE_DATE", nullable = true)
@Column(name = "CONFIRM_DATE", nullable = true)
public Date getConfirmDate() {
return confirmDate;
}

View File

@ -1,13 +1,12 @@
package com.loafle.overflow.module.notification.service;
import com.loafle.overflow.commons.model.PageParams;
import com.loafle.overflow.commons.utils.PageUtil;
import com.loafle.overflow.module.member.model.Member;
import com.loafle.overflow.module.notification.dao.NotificationDAO;
import com.loafle.overflow.module.notification.model.Notification;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;
/**
@ -23,15 +22,15 @@ public class NotificationService {
return this.notificationDAO.save(notification);
}
public Page<Notification> readAllByMember(Member member, int pageNo, int countPerPage) {
Pageable pageRequest =
new PageRequest(pageNo, countPerPage, new Sort(Sort.Direction.DESC, "id"));
return this.notificationDAO.findAllByMember(member, pageRequest);
public Page<Notification> readAllByMember(Member member, PageParams pageParams) {
return this.notificationDAO.findAllByMember(member, PageUtil.getPageRequest(pageParams));
}
public Page<Notification> readAllUnconfirmedByMember(Member member, int pageNo, int countPerPage) {
Pageable pageRequest =
new PageRequest(pageNo, countPerPage, new Sort(Sort.Direction.DESC, "id"));
return this.notificationDAO.findAllUnconfirmedByMember(member, pageRequest);
public Page<Notification> readAllUnconfirmedByMember(Member member, PageParams pageParams) {
return this.notificationDAO.findAllUnconfirmedByMember(member, PageUtil.getPageRequest(pageParams));
}
public int readUnconfirmedCount(Member member) {
return this.notificationDAO.findAllUnconfirmedCountByMember(member);
}
}

View File

@ -0,0 +1,15 @@
package com.loafle.overflow.proxy;
import com.loafle.overflow.commons.model.SessionMetadata;
import io.grpc.*;
public class ProxyServerInterceptor implements ServerInterceptor {
@Override
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
String email = headers.get(SessionMetadata.METADATA_EMAIL_KEY);
Context ctx = Context.current().withValue(SessionMetadata.CTX_EMAIL_KEY, email);
return Contexts.interceptCall(ctx, call, headers, next);
}
}

View File

@ -5,10 +5,7 @@ import com.loafle.overflow.api.ServerInput;
import com.loafle.overflow.api.ServerOutput;
import com.loafle.overflow.commons.exception.OverflowException;
import com.loafle.overflow.commons.exception.OverflowRuntimeException;
import io.grpc.ServerBuilder;
import io.grpc.Status;
import io.grpc.StatusException;
import io.grpc.StatusRuntimeException;
import io.grpc.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@ -27,9 +24,10 @@ public class ServiceProxy {
public void start(int port) throws IOException {
ctx = new AnnotationConfigApplicationContext("com.loafle.overflow");
ProxyServerInterceptor proxyServerInterceptor = new ProxyServerInterceptor();
server = ServerBuilder.forPort(port)
.addService(new ServiceImpl(new ServiceInvoker(ctx)))
.addService(ServerInterceptors.intercept(new ServiceImpl(new ServiceInvoker(ctx)), proxyServerInterceptor))
.build()
.start();
logger.info("Server started, listening on " + port);

View File

@ -1246,66 +1246,67 @@ INSERT INTO public.history (id,create_date,message,domain_id,member_id,probe_id,
INSERT INTO public.history (id,create_date,message,domain_id,member_id,probe_id,type_id) VALUES (
100,'2017-08-24 18:33:27.217','Test History 99',1,1,1,3);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
1,'2017-08-25 16:58:48.430','Message0','Title0',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
2,NULL,'Message1','Title1',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
3,'2017-08-25 16:58:48.520','Message2','Title2',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
4,NULL,'Message3','Title3',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
5,'2017-08-25 16:58:48.540','Message4','Title4',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
6,NULL,'Message5','Title5',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
7,'2017-08-25 16:58:48.566','Message6','Title6',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
8,NULL,'Message7','Title7',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
9,'2017-08-25 16:58:48.596','Message8','Title8',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
10,NULL,'Message9','Title9',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
11,'2017-08-25 16:58:48.628','Message10','Title10',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
12,NULL,'Message11','Title11',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
13,'2017-08-25 16:58:48.661','Message12','Title12',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
14,NULL,'Message13','Title13',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
15,'2017-08-25 16:58:48.682','Message14','Title14',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
16,NULL,'Message15','Title15',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
17,'2017-08-25 16:58:48.710','Message16','Title16',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
18,NULL,'Message17','Title17',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
19,'2017-08-25 16:58:48.734','Message18','Title18',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
20,NULL,'Message19','Title19',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
21,'2017-08-25 16:58:48.755','Message20','Title20',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
22,NULL,'Message21','Title21',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
23,'2017-08-25 16:58:48.778','Message22','Title22',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
24,NULL,'Message23','Title23',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
25,'2017-08-25 16:58:48.804','Message24','Title24',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
26,NULL,'Message25','Title25',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
27,'2017-08-25 16:58:48.829','Message26','Title26',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
28,NULL,'Message27','Title27',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
29,'2017-08-25 16:58:48.850','Message28','Title28',1);
INSERT INTO public.notification (id,create_date,message,title,member_id) VALUES (
30,NULL,'Message29','Title29',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
1,'2017-08-29 16:39:16.198','2017-08-29 16:39:17.756','Message0','Title0',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
2,'2017-08-29 16:39:16.285','2017-08-29 16:39:17.789','Message1','Title1',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
3,'2017-08-29 16:39:16.306','2017-08-29 16:39:17.807','Message2','Title2',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
4,'2017-08-29 16:39:16.322','2017-08-29 16:39:17.822','Message3','Title3',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
5,'2017-08-29 16:39:16.336','2017-08-29 16:39:17.837','Message4','Title4',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
6,'2017-08-29 16:39:16.350','2017-08-29 16:39:17.852','Message5','Title5',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
7,'2017-08-29 16:39:16.365','2017-08-29 16:39:17.864','Message6','Title6',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
8,'2017-08-29 16:39:16.377','2017-08-29 16:39:17.877','Message7','Title7',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
9,'2017-08-29 16:39:16.391','2017-08-29 16:39:17.890','Message8','Title8',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
10,'2017-08-29 16:39:16.403','2017-08-29 16:39:17.904','Message9','Title9',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
11,'2017-08-29 16:39:16.417','2017-08-29 16:39:17.916','Message10','Title10',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
12,'2017-08-29 16:39:16.430','2017-08-29 16:39:17.929','Message11','Title11',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
13,'2017-08-29 16:39:16.442','2017-08-29 16:39:17.941','Message12','Title12',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
14,'2017-08-29 16:39:16.454','2017-08-29 16:39:17.953','Message13','Title13',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
15,'2017-08-29 16:39:16.467','2017-08-29 16:39:17.966','Message14','Title14',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
16,'2017-08-29 16:39:16.479','2017-08-29 16:39:17.979','Message15','Title15',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
17,'2017-08-29 16:39:16.493','2017-08-29 16:39:17.994','Message16','Title16',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
18,'2017-08-29 16:39:16.508','2017-08-29 16:39:18.008','Message17','Title17',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
19,'2017-08-29 16:39:16.522','2017-08-29 16:39:18.020','Message18','Title18',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
20,'2017-08-29 16:39:16.533','2017-08-29 16:39:18.031','Message19','Title19',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
21,NULL,'2017-08-29 16:39:18.042','Message20','Title20',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
22,NULL,'2017-08-29 16:39:18.051','Message21','Title21',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
23,NULL,'2017-08-29 16:39:18.062','Message22','Title22',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
24,NULL,'2017-08-29 16:39:18.072','Message23','Title23',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
25,NULL,'2017-08-29 16:39:18.083','Message24','Title24',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
26,NULL,'2017-08-29 16:39:18.096','Message25','Title25',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
27,NULL,'2017-08-29 16:39:18.108','Message26','Title26',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
28,NULL,'2017-08-29 16:39:18.118','Message27','Title27',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
29,NULL,'2017-08-29 16:39:18.130','Message28','Title28',1);
INSERT INTO public.notification (id,confirm_date,create_date,message,title,member_id) VALUES (
30,NULL,'2017-08-29 16:39:18.143','Message29','Title29',1);

View File

@ -3,12 +3,9 @@ package com.loafle.overflow.module.notification.service;
import com.loafle.overflow.module.member.model.Member;
import com.loafle.overflow.module.notification.model.Notification;
import com.loafle.overflow.spring.AppConfigTest;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@ -24,33 +21,32 @@ public class NotificationServiceTest {
private NotificationService notificationService;
@Test
@Ignore
public void testRegist() {
for (int i=0; i<30; i++) {
Notification n = new Notification();
n.setMember(new Member(1));
n.setTitle("Title"+i);
n.setMessage("Message"+i);
if((i%2)==0) {
if(i<20) {
n.setConfirmDate(new Date());
}
this.notificationService.regist(n);
}
}
@Test
@Ignore
public void testReadAll() {
this.testRegist();
Page<Notification> notis = this.notificationService.readAllByMember(new Member(1), 0, 10);
Assert.assertEquals(30, notis.getTotalElements());
}
@Test
@Ignore
public void testReadAllUnread() {
this.testRegist();
Page<Notification> notis = this.notificationService.readAllUnconfirmedByMember(new Member(1), 0, 10);
Assert.assertEquals(15, notis.getTotalElements());
}
// @Test
// @Ignore
// public void testReadAll() {
// this.testRegist();
// Page<Notification> notis = this.notificationService.readAllByMember(new Member(1), 0, 10);
// Assert.assertEquals(30, notis.getTotalElements());
// }
//
// @Test
// @Ignore
// public void testReadAllUnread() {
// this.testRegist();
// Page<Notification> notis = this.notificationService.readAllUnconfirmedByMember(new Member(1), 0, 10);
// Assert.assertEquals(15, notis.getTotalElements());
// }
}