forked from JavaWebinar/masterjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3f4eea3
commit 62c1178
Showing
11 changed files
with
188 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
services/mail-service/src/main/java/ru/javaops/masterjava/service/mail/persist/MailCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package ru.javaops.masterjava.service.mail.persist; | ||
|
||
import com.bertoncelj.jdbi.entitymapper.Column; | ||
import com.google.common.base.Joiner; | ||
import lombok.*; | ||
import ru.javaops.masterjava.persist.model.BaseEntity; | ||
import ru.javaops.masterjava.service.mail.Addressee; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
@Data | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@EqualsAndHashCode(callSuper = false) // compare without id | ||
@ToString | ||
public class MailCase extends BaseEntity { | ||
private @Column("list_to") String listTo; | ||
private @Column("list_cc") String listCc; | ||
private String subject; | ||
private String state; | ||
private Date datetime; | ||
|
||
public static MailCase of(List<Addressee> to, List<Addressee> cc, String subject, String state){ | ||
return new MailCase(Joiner.on(", ").join(to), Joiner.on(", ").join(cc), subject, state, new Date()); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
...es/mail-service/src/main/java/ru/javaops/masterjava/service/mail/persist/MailCaseDao.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package ru.javaops.masterjava.service.mail.persist; | ||
|
||
import com.bertoncelj.jdbi.entitymapper.EntityMapperFactory; | ||
import org.skife.jdbi.v2.sqlobject.*; | ||
import org.skife.jdbi.v2.sqlobject.customizers.RegisterMapperFactory; | ||
import ru.javaops.masterjava.persist.dao.AbstractDao; | ||
|
||
import java.util.Date; | ||
import java.util.List; | ||
|
||
@RegisterMapperFactory(EntityMapperFactory.class) | ||
public abstract class MailCaseDao implements AbstractDao { | ||
|
||
@SqlUpdate("TRUNCATE mail_hist") | ||
@Override | ||
public abstract void clean(); | ||
|
||
@SqlQuery("SELECT * FROM mail_hist WHERE datetime >= :after ORDER BY datetime DESC") | ||
public abstract List<MailCase> getAfter(@Bind("after") Date date); | ||
|
||
@SqlUpdate("INSERT INTO mail_hist (list_to, list_cc, subject, state, datetime) VALUES (:listTo, :listCc, :subject, :state, :datetime)") | ||
@GetGeneratedKeys | ||
public abstract int insert(@BindBean MailCase mails); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,8 @@ public static void main(String[] args) throws MalformedURLException { | |
new QName("http://mail.service.masterjava.javaops.ru/", "MailServiceImplService")); | ||
|
||
MailService mailService = service.getPort(MailService.class); | ||
mailService.sendMail(ImmutableList.of(new Addressee("[email protected]", null)), null, "Subject", "Body"); | ||
mailService.sendMail(ImmutableList.of( | ||
new Addressee("[email protected]", null), | ||
new Addressee("Bad Email <bad_email.ru>")), null, "Subject", "Body"); | ||
} | ||
} |
7 changes: 3 additions & 4 deletions
7
...s/mail-service/src/test/java/ru/javaops/masterjava/service/mail/MailServicePublisher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,13 @@ | ||
package ru.javaops.masterjava.service.mail; | ||
|
||
import ru.javaops.masterjava.persist.DBITestProvider; | ||
|
||
import javax.xml.ws.Endpoint; | ||
|
||
/** | ||
* User: gkislin | ||
* Date: 28.05.2014 | ||
*/ | ||
public class MailServicePublisher { | ||
|
||
public static void main(String[] args) { | ||
DBITestProvider.initDBI(); | ||
Endpoint.publish("http://localhost:8080/mail/mailService", new MailServiceImpl()); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...ail-service/src/test/java/ru/javaops/masterjava/service/mail/persist/MailCaseDaoTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package ru.javaops.masterjava.service.mail.persist; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import ru.javaops.masterjava.persist.dao.AbstractDaoTest; | ||
|
||
public class MailCaseDaoTest extends AbstractDaoTest<MailCaseDao> { | ||
public MailCaseDaoTest() { | ||
super(MailCaseDao.class); | ||
} | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
MailCaseTestData.setUp(); | ||
} | ||
|
||
@Test | ||
public void getAll() throws Exception { | ||
Assert.assertEquals(MailCaseTestData.MAIL_CASES, dao.getAfter(MailCaseTestData.DATE_FROM)); | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
...il-service/src/test/java/ru/javaops/masterjava/service/mail/persist/MailCaseTestData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package ru.javaops.masterjava.service.mail.persist; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import ru.javaops.masterjava.persist.DBIProvider; | ||
import ru.javaops.masterjava.service.mail.Addressee; | ||
|
||
import java.time.Duration; | ||
import java.time.Instant; | ||
import java.util.Date; | ||
import java.util.List; | ||
|
||
public class MailCaseTestData { | ||
private static final Instant now = Instant.now(); | ||
static final Date DATE_FROM = Date.from(now.minus(Duration.ofDays(1))); | ||
|
||
static final List<MailCase> MAIL_CASES = ImmutableList.of( | ||
MailCase.of( | ||
ImmutableList.of( | ||
new Addressee("ИмяTo1 Фамилия1 <[email protected]>"), | ||
new Addressee("Имя2 Фамилия2 <[email protected]>")), | ||
ImmutableList.of( | ||
new Addressee("ИмяCc1 Фамилия1 <[email protected]>"), | ||
new Addressee("ИмяCc2 Фамилия2 <[email protected]>")), | ||
"subject1", "state1" | ||
), | ||
new MailCase("[email protected]", null, "subject2", "state2", | ||
Date.from(now.minus(Duration.ofMinutes(1)))), | ||
new MailCase(null, "[email protected]", "subject3", "state3", DATE_FROM) | ||
); | ||
|
||
private static final MailCase MAIL_CASE_EXCLUDED = | ||
new MailCase("[email protected]", "[email protected]", "subject4", "state4", | ||
Date.from(now.minus(Duration.ofDays(2)))); | ||
|
||
public static void setUp() { | ||
MailCaseDao dao = DBIProvider.getDao(MailCaseDao.class); | ||
dao.clean(); | ||
DBIProvider.getDBI().useTransaction((conn, status) -> { | ||
MAIL_CASES.forEach(dao::insert); | ||
dao.insert(MAIL_CASE_EXCLUDED); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters