From da34f5932e1c7a8b129815a080576b4751bee57b Mon Sep 17 00:00:00 2001 From: geek Date: Mon, 3 Jul 2017 15:03:00 +0900 Subject: [PATCH 1/9] EmailAuth Service method added --- .../email/service/EmailAuthService.java | 56 +++++++++++++++---- 1 file changed, 46 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java b/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java index 69ba19f..1f1c33b 100644 --- a/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java +++ b/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java @@ -1,11 +1,16 @@ package com.loafle.overflow.module.email.service; +import com.loafle.overflow.module.email.dao.EmailAuthDAO; +import com.loafle.overflow.module.email.model.EmailAuth; +import com.loafle.overflow.module.member.model.Member; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.mail.MailException; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; import org.springframework.stereotype.Service; +import java.util.List; + /** * Created by geek on 17. 6. 28. */ @@ -15,19 +20,50 @@ public class EmailAuthService { @Autowired private JavaMailSender mailSender; + @Autowired + private EmailAuthDAO emailAuthDAO; - public void sendEmail(String to, String sub, String message) { - + public EmailAuth sendEmailByMemberId(long memberId, String memberEmail) { try { - SimpleMailMessage message1 = new SimpleMailMessage(); - message1.setTo(to); - message1.setSubject(sub); - message1.setText(message); - message1.setFrom("geek@loafle.com"); - - mailSender.send(message1); - } catch (MailException e) { + this.sendEmail(memberEmail, "Test Spring Mail", "Confirm Email"); + }catch (MailException e) { e.printStackTrace(); } + + EmailAuth auth = new EmailAuth(); + auth.setMember(new Member(memberId)); + // Todo AuthKey Generation + auth.setEmailAuthKey("djdjdjdjeiejdikdjki"); + + this.emailAuthDAO.save(auth); + + return auth; + } + + public EmailAuth read(long id) { + return this.emailAuthDAO.findOne(id); + } + + public EmailAuth readByAuthKey(String authKey) { + return this.emailAuthDAO.findByEmailAuthKey(authKey); + } + + public List readByMember(long memberId) { + return this.emailAuthDAO.findByMember(new Member(memberId)); + } + + public EmailAuth modify(EmailAuth emailAuth) { + return this.emailAuthDAO.save(emailAuth); + } + + public void sendEmail(String to, String sub, String message) throws MailException { + + SimpleMailMessage message1 = new SimpleMailMessage(); + message1.setTo(to); + message1.setSubject(sub); + message1.setText(message); + message1.setFrom("geek@loafle.com"); + + mailSender.send(message1); } } From b7d0ac08cfc53d8f8155c744db5326328521faac Mon Sep 17 00:00:00 2001 From: geek Date: Mon, 3 Jul 2017 15:21:01 +0900 Subject: [PATCH 2/9] EmailAuth Timestamp -> Date --- .../overflow/module/email/model/EmailAuth.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/loafle/overflow/module/email/model/EmailAuth.java b/src/main/java/com/loafle/overflow/module/email/model/EmailAuth.java index c46f672..83705fc 100644 --- a/src/main/java/com/loafle/overflow/module/email/model/EmailAuth.java +++ b/src/main/java/com/loafle/overflow/module/email/model/EmailAuth.java @@ -3,7 +3,7 @@ package com.loafle.overflow.module.email.model; import com.loafle.overflow.module.member.model.Member; import javax.persistence.*; -import java.sql.Timestamp; +import java.util.Date; /** * Created by root on 17. 6. 22. @@ -13,8 +13,8 @@ import java.sql.Timestamp; public class EmailAuth { private long id; private String emailAuthKey; - private Timestamp createDate; - private Timestamp authConfirmDate; + private Date createDate; + private Date authConfirmDate; private Member member; @Id @@ -39,21 +39,21 @@ public class EmailAuth { @Basic @Column(name = "CREATE_DATE", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP", insertable = false, updatable = false) - public Timestamp getCreateDate() { + public Date getCreateDate() { return createDate; } - public void setCreateDate(Timestamp createDate) { + public void setCreateDate(Date createDate) { this.createDate = createDate; } @Basic @Column(name = "AUTH_CONFIRM_DATE", nullable = true, insertable = true, updatable = false) - public Timestamp getAuthConfirmDate() { + public Date getAuthConfirmDate() { return authConfirmDate; } - public void setAuthConfirmDate(Timestamp authConfirmDate) { + public void setAuthConfirmDate(Date authConfirmDate) { this.authConfirmDate = authConfirmDate; } From 45d41cfd1896f678ba476ecf71c378f41245d3eb Mon Sep 17 00:00:00 2001 From: geek Date: Mon, 3 Jul 2017 18:45:05 +0900 Subject: [PATCH 3/9] email attach send method added --- pom.xml | 22 +++++++++++++++++ .../email/service/EmailAuthService.java | 24 +++++++++++++++++-- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 6451413..866e1b2 100644 --- a/pom.xml +++ b/pom.xml @@ -173,6 +173,28 @@ + + cz.habarta.typescript-generator + typescript-generator-maven-plugin + 1.25.322 + + + generate + + generate + + process-classes + + + + jackson2 + + com.loafle.overflow.module.**.model.* + + module + implementationFile + + diff --git a/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java b/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java index 1f1c33b..c52bc2e 100644 --- a/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java +++ b/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java @@ -4,11 +4,16 @@ import com.loafle.overflow.module.email.dao.EmailAuthDAO; import com.loafle.overflow.module.email.model.EmailAuth; import com.loafle.overflow.module.member.model.Member; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.io.FileSystemResource; import org.springframework.mail.MailException; import org.springframework.mail.SimpleMailMessage; import org.springframework.mail.javamail.JavaMailSender; +import org.springframework.mail.javamail.MimeMessageHelper; import org.springframework.stereotype.Service; +import javax.mail.MessagingException; +import javax.mail.internet.MimeMessage; +import java.io.File; import java.util.List; /** @@ -25,7 +30,7 @@ public class EmailAuthService { public EmailAuth sendEmailByMemberId(long memberId, String memberEmail) { try { - this.sendEmail(memberEmail, "Test Spring Mail", "Confirm Email"); + this.sendSimpleEmail(memberEmail, "Test Spring Mail", "Confirm Email"); }catch (MailException e) { e.printStackTrace(); } @@ -56,7 +61,7 @@ public class EmailAuthService { return this.emailAuthDAO.save(emailAuth); } - public void sendEmail(String to, String sub, String message) throws MailException { + public void sendSimpleEmail(String to, String sub, String message) throws MailException { SimpleMailMessage message1 = new SimpleMailMessage(); message1.setTo(to); @@ -66,4 +71,19 @@ public class EmailAuthService { mailSender.send(message1); } + + public void sendMailWithAttachment(String to, String sub, String text, String path) throws MessagingException { + MimeMessage message = mailSender.createMimeMessage(); + // pass 'true' to the constructor to create a multipart message + MimeMessageHelper helper = new MimeMessageHelper(message, true); + + helper.setTo(to); + helper.setSubject(sub); + helper.setText(text); + helper.setFrom("geek@loafle.com"); + FileSystemResource file = new FileSystemResource(new File(path)); + helper.addAttachment("Invoice", file); + + mailSender.send(message); + } } From d086d61ad77566c74eb3a71ea08a9ff2ed8e9305 Mon Sep 17 00:00:00 2001 From: snoop Date: Tue, 4 Jul 2017 11:09:33 +0900 Subject: [PATCH 4/9] added java to ts --- pom.xml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/pom.xml b/pom.xml index 6451413..f840d92 100644 --- a/pom.xml +++ b/pom.xml @@ -173,6 +173,36 @@ + + cz.habarta.typescript-generator + typescript-generator-maven-plugin + 1.27.339 + + + generate + + generate + + process-classes + + + + jackson2 + + + + + + com.loafle.overflow.module.**.model.* + + module + + + + + + + From 07f043f277dd4ad2a307336b5dd6a179ed3c097c Mon Sep 17 00:00:00 2001 From: geek Date: Tue, 4 Jul 2017 12:33:34 +0900 Subject: [PATCH 5/9] email attach send method added --- .../loafle/overflow/module/email/service/EmailAuthService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java b/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java index c52bc2e..ec9a4f9 100644 --- a/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java +++ b/src/main/java/com/loafle/overflow/module/email/service/EmailAuthService.java @@ -28,7 +28,7 @@ public class EmailAuthService { @Autowired private EmailAuthDAO emailAuthDAO; - public EmailAuth sendEmailByMemberId(long memberId, String memberEmail) { + public EmailAuth sendEmailByMember(long memberId, String memberEmail) { try { this.sendSimpleEmail(memberEmail, "Test Spring Mail", "Confirm Email"); }catch (MailException e) { From 88eda2b5e6e121179070a08ce221fd0b0c5d9252 Mon Sep 17 00:00:00 2001 From: insanity Date: Tue, 4 Jul 2017 17:17:26 +0900 Subject: [PATCH 6/9] probe modify --- .../module/probe/service/ProbeService.java | 4 ++-- .../module/probe/service/ProbeTaskService.java | 4 ++-- .../module/probe/type/ProbeStatusType.java | 18 ------------------ 3 files changed, 4 insertions(+), 22 deletions(-) delete mode 100644 src/main/java/com/loafle/overflow/module/probe/type/ProbeStatusType.java diff --git a/src/main/java/com/loafle/overflow/module/probe/service/ProbeService.java b/src/main/java/com/loafle/overflow/module/probe/service/ProbeService.java index f3903ce..3b78f8a 100644 --- a/src/main/java/com/loafle/overflow/module/probe/service/ProbeService.java +++ b/src/main/java/com/loafle/overflow/module/probe/service/ProbeService.java @@ -17,8 +17,8 @@ public class ProbeService { @Autowired private ProbeDAO probeDAO; - public void regist(Probe probe) { - this.probeDAO.save(probe); + public Probe regist(Probe probe) { + return this.probeDAO.save(probe); } public List readAllByDomain(Domain domain) { diff --git a/src/main/java/com/loafle/overflow/module/probe/service/ProbeTaskService.java b/src/main/java/com/loafle/overflow/module/probe/service/ProbeTaskService.java index d3d3929..8198f79 100644 --- a/src/main/java/com/loafle/overflow/module/probe/service/ProbeTaskService.java +++ b/src/main/java/com/loafle/overflow/module/probe/service/ProbeTaskService.java @@ -17,8 +17,8 @@ public class ProbeTaskService { @Autowired private ProbeTaskDAO probeTaskDAO; - public void regist(ProbeTask probeTask) { - this.probeTaskDAO.save(probeTask); + public ProbeTask regist(ProbeTask probeTask) { + return this.probeTaskDAO.save(probeTask); } public List readAllByProbe(Probe probe) { diff --git a/src/main/java/com/loafle/overflow/module/probe/type/ProbeStatusType.java b/src/main/java/com/loafle/overflow/module/probe/type/ProbeStatusType.java deleted file mode 100644 index 1e4c602..0000000 --- a/src/main/java/com/loafle/overflow/module/probe/type/ProbeStatusType.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.loafle.overflow.module.probe.type; - -/** - * Created by root on 17. 6. 23. - */ -public enum ProbeStatusType { - I("INITIAL"), - N("NORMAL"); - - - private String stringValue; - ProbeStatusType(String string) {stringValue = string;} - - @Override - public String toString() { - return stringValue; - } -} From 87a4a2f5183c987bba77a9b070af79e809bcdc50 Mon Sep 17 00:00:00 2001 From: snoop Date: Tue, 4 Jul 2017 17:28:43 +0900 Subject: [PATCH 7/9] return model --- .../service/NoAuthProbeService.java | 5 +++-- .../module/noauthprobe/type/AuthType.java | 19 ------------------- 2 files changed, 3 insertions(+), 21 deletions(-) delete mode 100644 src/main/java/com/loafle/overflow/module/noauthprobe/type/AuthType.java diff --git a/src/main/java/com/loafle/overflow/module/noauthprobe/service/NoAuthProbeService.java b/src/main/java/com/loafle/overflow/module/noauthprobe/service/NoAuthProbeService.java index 512e210..7067b6a 100644 --- a/src/main/java/com/loafle/overflow/module/noauthprobe/service/NoAuthProbeService.java +++ b/src/main/java/com/loafle/overflow/module/noauthprobe/service/NoAuthProbeService.java @@ -18,8 +18,9 @@ public class NoAuthProbeService { private NoAuthProbeDAO noAuthProbeDAO; - public void regist(NoAuthProbe noAuthProbe) { - this.noAuthProbeDAO.save(noAuthProbe); + public NoAuthProbe regist(NoAuthProbe noAuthProbe) { + + return this.noAuthProbeDAO.save(noAuthProbe); } public List readAllByDomain(Domain domain) { diff --git a/src/main/java/com/loafle/overflow/module/noauthprobe/type/AuthType.java b/src/main/java/com/loafle/overflow/module/noauthprobe/type/AuthType.java deleted file mode 100644 index 1d58a0f..0000000 --- a/src/main/java/com/loafle/overflow/module/noauthprobe/type/AuthType.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.loafle.overflow.module.noauthprobe.type; - -/** - * Created by root on 17. 5. 31. - */ -public enum AuthType { - A("ACCEPT"), - D("DENY"), - P("PROCESS"); - - private String stringValue; - AuthType(String string) {stringValue = string;} - - @Override - public String toString() { - return stringValue; - } - -} From 3badd6426b71cf17a1f9885397868b517f04b383 Mon Sep 17 00:00:00 2001 From: snoop Date: Tue, 4 Jul 2017 18:09:34 +0900 Subject: [PATCH 8/9] added --- .../overflow/module/apikey/service/ApiKeyService.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/loafle/overflow/module/apikey/service/ApiKeyService.java b/src/main/java/com/loafle/overflow/module/apikey/service/ApiKeyService.java index ba3148a..b9e8919 100644 --- a/src/main/java/com/loafle/overflow/module/apikey/service/ApiKeyService.java +++ b/src/main/java/com/loafle/overflow/module/apikey/service/ApiKeyService.java @@ -2,6 +2,7 @@ package com.loafle.overflow.module.apikey.service; import com.loafle.overflow.module.apikey.dao.ApiKeyDAO; import com.loafle.overflow.module.apikey.model.ApiKey; +import com.loafle.overflow.module.domain.model.Domain; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -16,9 +17,13 @@ public class ApiKeyService { private ApiKeyDAO apiKeyDAO; - public void regist(ApiKey apiKey) { + public ApiKey regist(ApiKey apiKey) { - this.apiKeyDAO.save(apiKey); + return this.apiKeyDAO.save(apiKey); + } + + public ApiKey readByDomain(Domain domain) { + return this.apiKeyDAO.findByDomain(domain); } public boolean check(String apiKey) { From 0736723c745b7f5d7d3b26b75f41a26ae6aa4dea Mon Sep 17 00:00:00 2001 From: snoop Date: Tue, 4 Jul 2017 18:13:00 +0900 Subject: [PATCH 9/9] added test --- .../apikey/service/ApiKeyServiceTest.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/loafle/overflow/module/apikey/service/ApiKeyServiceTest.java b/src/test/java/com/loafle/overflow/module/apikey/service/ApiKeyServiceTest.java index fc01b92..be07583 100644 --- a/src/test/java/com/loafle/overflow/module/apikey/service/ApiKeyServiceTest.java +++ b/src/test/java/com/loafle/overflow/module/apikey/service/ApiKeyServiceTest.java @@ -4,6 +4,7 @@ import com.loafle.overflow.module.apikey.model.ApiKey; import com.loafle.overflow.module.domain.model.Domain; import com.loafle.overflow.spring.AppConfig; import com.loafle.overflow.spring.JdbcConfiguration; +import com.loafle.overflow.spring.MailConfiguration; import org.junit.Assert; import org.junit.Ignore; import org.junit.Test; @@ -18,8 +19,7 @@ import static org.junit.Assert.*; * Created by snoop on 17. 6. 28. */ @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {AppConfig.class, JdbcConfiguration.class}) - +@ContextConfiguration(classes = {AppConfig.class, JdbcConfiguration.class, MailConfiguration.class}) public class ApiKeyServiceTest { @Autowired @@ -57,4 +57,17 @@ public class ApiKeyServiceTest { Assert.assertNotEquals(result, false); } + @Ignore + @Test + public void findByDomain() { + + Domain domain = new Domain(); + domain.setId(1); + + ApiKey apiKey = this.apiKeyService.readByDomain(domain); + + Assert.assertNotEquals(apiKey, null); + + } + } \ No newline at end of file