From Domain-Driven Design to Domain-Specific Languages: an example
-
Upload
phil-calcado -
Category
Technology
-
view
3.290 -
download
2
description
Transcript of From Domain-Driven Design to Domain-Specific Languages: an example
![Page 1: From Domain-Driven Design to Domain-Specific Languages: an example](https://reader033.fdocuments.us/reader033/viewer/2022052505/555680f2d8b42abc5a8b54be/html5/thumbnails/1.jpg)
from: domain-driven-designto: domain-specific language--An Example.
phillip calçadohttp://fragmental.twhttp://www.thoughtworks.com
![Page 2: From Domain-Driven Design to Domain-Specific Languages: an example](https://reader033.fdocuments.us/reader033/viewer/2022052505/555680f2d8b42abc5a8b54be/html5/thumbnails/2.jpg)
JavaMail Usage
![Page 3: From Domain-Driven Design to Domain-Specific Languages: an example](https://reader033.fdocuments.us/reader033/viewer/2022052505/555680f2d8b42abc5a8b54be/html5/thumbnails/3.jpg)
I want this CSV report delivered
as an e-mailattachment
![Page 4: From Domain-Driven Design to Domain-Specific Languages: an example](https://reader033.fdocuments.us/reader033/viewer/2022052505/555680f2d8b42abc5a8b54be/html5/thumbnails/4.jpg)
ClassicExample
![Page 5: From Domain-Driven Design to Domain-Specific Languages: an example](https://reader033.fdocuments.us/reader033/viewer/2022052505/555680f2d8b42abc5a8b54be/html5/thumbnails/5.jpg)
public class Mail {
public void sendEmailWithCsvFile(String from, String to, String subject, String body, List<String> csvFileLines) {
Properties props = new Properties(); props.put("mail.smtp.host", "localhost");
Session session = Session.getDefaultInstance(props);
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
InternetAddress[] address = { new InternetAddress(to) }; msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject(subject); msg.setSentDate(new Date());
MimeBodyPart part1 = new MimeBodyPart(); part1.setText(body);
MimeBodyPart part2 = new MimeBodyPart(); StringBuffer buffer = new StringBuffer(); for (String line : csvFileLines) buffer.append(line + "\n"); part2.setContent(buffer.toString(), "text/csv"); part2.setFileName("file.csv");
Multipart mp = new MimeMultipart(); mp.addBodyPart(part1); mp.addBodyPart(part2);
msg.setContent(mp);
Transport.send(msg); }}
![Page 6: From Domain-Driven Design to Domain-Specific Languages: an example](https://reader033.fdocuments.us/reader033/viewer/2022052505/555680f2d8b42abc5a8b54be/html5/thumbnails/6.jpg)
RemovingsomeNoise
![Page 7: From Domain-Driven Design to Domain-Specific Languages: an example](https://reader033.fdocuments.us/reader033/viewer/2022052505/555680f2d8b42abc5a8b54be/html5/thumbnails/7.jpg)
public class Mail {
public void sendEmailWithCsvFile(String from, String to, String subject, String body, List<String> csvFileLines) {
Properties props = new Properties(); props.put("mail.smtp.host", "localhost"); MailService mailService = new MailService(props); MailMessage message = mailService.newMessage(); message.setFrom(from); message.setTo(to); message.setSubject(subject); message.setBody(body);
StringBuffer buffer = new StringBuffer(); for (String line : csvFileLines) buffer.append(line + "\n"); Attachment csvFile = new Attachment("file.csv", buffer.toString()); message.attach(csvFile);
mailService.send(message); }}
![Page 8: From Domain-Driven Design to Domain-Specific Languages: an example](https://reader033.fdocuments.us/reader033/viewer/2022052505/555680f2d8b42abc5a8b54be/html5/thumbnails/8.jpg)
MakingitFlow
![Page 9: From Domain-Driven Design to Domain-Specific Languages: an example](https://reader033.fdocuments.us/reader033/viewer/2022052505/555680f2d8b42abc5a8b54be/html5/thumbnails/9.jpg)
public class Mail {
public void sendEmailWithCsvFile(String from, String to, String subject, String body, List<String> csvFileLines) {
StringBuffer buffer = new StringBuffer(); for (String line : csvFileLines) buffer.append(line + "\n"); Properties props = new Properties(); props.put("mail.smtp.host", "localhost"); MailService mailService = new MailService(props); mailService.newMessage() .from(from) .to(to) .subject(subject) .body(body) .attachTextFile("file3.csv", buffer.toString()) .send(); }}
![Page 10: From Domain-Driven Design to Domain-Specific Languages: an example](https://reader033.fdocuments.us/reader033/viewer/2022052505/555680f2d8b42abc5a8b54be/html5/thumbnails/10.jpg)
SpeakingtheLanguage
![Page 11: From Domain-Driven Design to Domain-Specific Languages: an example](https://reader033.fdocuments.us/reader033/viewer/2022052505/555680f2d8b42abc5a8b54be/html5/thumbnails/11.jpg)
send_message do to '[email protected]' from '[email protected]' subject 'Testing via JRuby'
body %{ Hi, Please do not forget the milk. Bye! }
attach('file4.csv') { ['Sk. Milk', '$1.33'] ['Avocado', '$3.00'] }end
![Page 12: From Domain-Driven Design to Domain-Specific Languages: an example](https://reader033.fdocuments.us/reader033/viewer/2022052505/555680f2d8b42abc5a8b54be/html5/thumbnails/12.jpg)
Thanks
![Page 13: From Domain-Driven Design to Domain-Specific Languages: an example](https://reader033.fdocuments.us/reader033/viewer/2022052505/555680f2d8b42abc5a8b54be/html5/thumbnails/13.jpg)
Pictures• http://www.flickr.com/photos/bitzi/293673587/
• http://www.flickr.com/photos/sage/2143086954/
• http://www.flickr.com/photos/brianmitchell/2113553867/
• http://www.flickr.com/photos/kamaski/186266747/
• http://www.flickr.com/photos/tosawyer/43691981/
• http://www.flickr.com/photos/helderfontenele/2134684620/
• http://www.flickr.com/photos/sotto1/808195510/