DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
  • submit to reddit
Deon Thomas11/07/14
24071 views
11 replies

A Good Programmer: Why You Need to Avoid Being One

I’ve worked with what I consider to be good software programmers but are they really good programmers? What makes them so good? (and maybe, are they just average?)

Ian Skerrett11/06/14
1661 views
0 replies

The Importance of Testing Interoperability: MQTT Test Day

A lot of work is being done developing standards for the Internet of Things (IoT), standards like MQTT, CoAP, etc. However, as most people appreciate, the implementation of a specific standard can be open for interpretation so testing for interoperability is the only way end-users can achieve this benefit. This is why I am pleased that we will be once again hosting an MQTT Interoperability Test Day.

Rob Galanakis11/06/14
7747 views
1 replies

Technical Debt Takes Many Forms

Most people are familiar with “technical debt” in terms of code or architectural problems that slow down development. There are other forms of technical debt, though, that can be overlooked.

Erich Styger11/06/14
11145 views
0 replies

Engineering Joke of the Week: The Tunnel

I’m a believer that engineers not only need to act in a professional and ethical way, but they have to have a sense of humor too. For that reason I have the tradition to tell my class (almost) every semester week a joke or fun story with an engineering background. I have been asked to share the fun story from this week, so here we go...

Paul Hammant11/05/14
1850 views
0 replies

Presenting on Trunk-based Development at the Perforce MERGE Conference

This was a month ago at Perforce’s MERGE 2014 conference, but the videos are up now, so you can watch it too. Of many case studies that I have, I detailed one where a hedge-bet on the order of releases paid off. Not that the client knew they were hedge-betting at the outset, that’s just the reality of Trunk Based Development, Feature Toggles / build switches, and Branch by Abstraction.

John Walter11/05/14
14982 views
0 replies

Dev of the Week: Markus Eisele

Every week here and in our newsletter, we feature a new developer/blogger from the DZone community to catch up and find out what he or she is working on now and what's coming next. This week we're talking to Markus Eisele, Developer Advocate at Red Hat.

John Walter11/05/14
15296 views
0 replies

The Best of DZone: Oct. 28 - Nov. 4

If you missed anything on DZone this week, now's your chance to catch up! This week's best include a glimpse to the future in IoT, an overview of the Lollipop API change, a tutorial for converting your legacy code, and the details of W3C's HTML5 recommendation.

Allan Kelly11/05/14
4605 views
0 replies

Dialogue Sheets Update (1 of 2)

It has been a while since I’ve written about Dialogue Sheets here - or indeed anywhere else. So here is a quick update and a request for some guinea pigs - I have ideas for new sheets but I need some teams to try them out.

David Mai11/05/14
1325 views
0 replies

Salesforce Enters BI & Analytics Market. Will They Create a Wave or Just a Ripple?

Salesforce the world’s largest enterprise cloud computing company has recently unveiled “Wave”, their new enterprise business intelligence solution.

Ayende Rahien11/04/14
3380 views
1 replies

Career planning: What is your path?

As discussed in the previous post, a lot of developers move to management positions at some point in their careers. Now let's turn this around, instead of asking what is going on in the industry, let’s check what is going on with you. In particular, do you have a career plan at all?

Mike Bushong11/04/14
3032 views
0 replies

Making the World a Better Place with Big Data

While there is certainly much feel-good hyperbole about the “making the world a better place” nature of big data, that is more than offset with actual real-world details of how data is being used to solve more day-to-day business problems.

Robert Nyman11/04/14
2576 views
1 replies

The editors I've been using--which one is your favorite?

The other day when I wrote about Vim and how to get started with it, I got a bit nostalgic with the editors I’ve been using over the years. Therefore, I thought I’d list the editors I’ve been using over the years. It would be very interesting and great if you’d like to share in the comments which editor you are using, and why you prefer it! Or with which editor you started your developer career!

import java.net.URI;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import microsoft.exchange.webservices.data.Appointment;
import microsoft.exchange.webservices.data.AppointmentSchema;
import microsoft.exchange.webservices.data.CalendarFolder;
import microsoft.exchange.webservices.data.CalendarView;
import microsoft.exchange.webservices.data.EmailMessage;
import microsoft.exchange.webservices.data.ExchangeCredentials;
import microsoft.exchange.webservices.data.ExchangeService;
import microsoft.exchange.webservices.data.ExchangeVersion;
import microsoft.exchange.webservices.data.FindItemsResults;
import microsoft.exchange.webservices.data.Folder;
import microsoft.exchange.webservices.data.Item;
import microsoft.exchange.webservices.data.ItemId;
import microsoft.exchange.webservices.data.ItemView;
import microsoft.exchange.webservices.data.PropertySet;
import microsoft.exchange.webservices.data.ServiceLocalException;
import microsoft.exchange.webservices.data.WebCredentials;
import microsoft.exchange.webservices.data.WellKnownFolderName;

/**
 * @author Shantanu Sikdar 
 *
 */

public class MSExchangeEmailService {
			
	private static ExchangeService service;
	private static Integer NUMBER_EMAILS_FETCH =5; // only latest 5 emails/appointments are fetched.
			
	/**
	 * Firstly check, whether "https://webmail.xxxx.com/ews/Services.wsdl" and "https://webmail.xxxx.com/ews/Exchange.asmx"
	 * is accessible, if yes that means the Exchange Webservice is enabled on your MS Exchange.
	 */
	static{
		try{						
			service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
			//service = new ExchangeService(ExchangeVersion.Exchange2007_SP1); //depending on the version of your Exchange. 
			service.setUrl(new URI("https://webmail.xxxx.com/ews/Exchange.asmx"));		
		}catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * Initialize the Exchange Credentials. 
	 * 	Don't forget to replace the "USRNAME","PWD","DOMAIN_NAME" variables. 
	 */
	public MSExchangeEmailService() {
		ExchangeCredentials credentials = new WebCredentials("USRNAME","PWD","DOMAIN_NAME");		
		service.setCredentials(credentials);
	}
	
	/**
	 * Reading one email at a time. Using Item ID of the email.
	 * Creating a message data map as a return value.   
	 */
	public Map<String, Object> readEmailItem(ItemId itemId){
		Map<String, Object> messageData = new HashMap<String, Object>();
		try{				
			Item itm = Item.bind(service, itemId, PropertySet.FirstClassProperties);
			EmailMessage emailMessage = EmailMessage.bind(service, itm.getId());			
			messageData.put("emailItemId", emailMessage.getId().toString());			
			messageData.put("subject", emailMessage.getSubject().toString());
			messageData.put("fromAddress",emailMessage.getFrom().getAddress().toString());
			messageData.put("senderName",emailMessage.getSender().getName().toString());
			Date dateTimeCreated = emailMessage.getDateTimeCreated();
			messageData.put("SendDate",dateTimeCreated.toString());			
			Date dateTimeRecieved = emailMessage.getDateTimeReceived();
			messageData.put("RecievedDate",dateTimeRecieved.toString());			
			messageData.put("Size",emailMessage.getSize()+"");						
			messageData.put("emailBody",emailMessage.getBody().toString());			
		}catch (Exception e) {
			e.printStackTrace();
		}
		return messageData;
	}
	
	/**
	 * Number of email we want to read is defined as NUMBER_EMAILS_FETCH, 
	 */
	public List<Map<String, Object>> readEmails(){
		List<Map<String, Object>> msgDataList = new ArrayList<Map<String, Object>>();
		try{
			Folder folder = Folder.bind( service, WellKnownFolderName.Inbox );
			FindItemsResults<Item> results = service.findItems(folder.getId(), new ItemView(NUMBER_EMAILS_FETCH));		
			int i =1;
			for (Item item : results){				
				Map<String, Object> messageData = new HashMap<String, Object>();
				messageData = readEmailItem(item.getId());
				System.out.println("\nEmails #" + (i++ ) + ":" );
				System.out.println("subject : " + messageData.get("subject").toString());
				System.out.println("Sender : " + messageData.get("senderName").toString());
				msgDataList.add(messageData);
			}			
		}catch (Exception e) { 	e.printStackTrace();		}
		return msgDataList;
	}

	/**
	 * Reading one appointment at a time. Using Appointment ID of the email.
	 * Creating a message data map as a return value.   
	 */
	public Map<String, Object> readAppointment(Appointment appointment){
		Map<String, Object> appointmentData = new HashMap<String, Object>();
		try {			
			appointmentData.put("appointmentItemId", appointment.getId().toString());
			appointmentData.put("appointmentSubject", appointment.getSubject());
			appointmentData.put("appointmentStartTime", appointment.getStart()+"");
			appointmentData.put("appointmentEndTime", appointment.getEnd()+"");
			//appointmentData.put("appointmentBody", appointment.getBody().toString());
		} catch (ServiceLocalException e) {
			e.printStackTrace();
		}		
		return appointmentData;
	}

	/**
 	 *	Number of Appointments we want to read is defined as NUMBER_EMAILS_FETCH,
 	 *  Here I also considered the start data and end date which is a 30 day span.
 	 *  We need to set the CalendarView property depending upon the need of ours.   
	 */
	public List<Map<String, Object>> readAppointments(){		
		List<Map<String, Object>> apntmtDataList = new ArrayList<Map<String, Object>>();		
		Calendar now = Calendar.getInstance();
		Date startDate = Calendar.getInstance().getTime();
		now.add(Calendar.DATE, 30);
        Date endDate = now.getTime();  
		try{
			CalendarFolder calendarFolder = CalendarFolder.bind(service, WellKnownFolderName.Calendar, new PropertySet());			
			CalendarView cView = new CalendarView(startDate, endDate, 5);			
			cView.setPropertySet(new PropertySet(AppointmentSchema.Subject, AppointmentSchema.Start, AppointmentSchema.End));	// we can set other properties as well depending upon our need.		
			FindItemsResults<Appointment> appointments = calendarFolder.findAppointments(cView);			
			
			int i =1;
			List<Appointment> appList = appointments.getItems();			
			for (Appointment appointment : appList) {
				System.out.println("\nAPPOINTMENT #" + (i++ ) + ":" );
				Map<String, Object> appointmentData = new HashMap<String, Object>();
				appointmentData = readAppointment(appointment);
				System.out.println("subject : " + appointmentData.get("appointmentSubject").toString());
				System.out.println("On : " + appointmentData.get("appointmentStartTime").toString());
				apntmtDataList.add(appointmentData);
			}			
		}catch (Exception e) {
			e.printStackTrace();
		}
		return apntmtDataList;
	}	
	
	public static void main(String[] args) {		
		MSExchangeEmailService msees = new MSExchangeEmailService();
		msees.readEmails();
		msees.readAppointments();		
	}
}
Benjamin Ball11/02/14
4838 views
0 replies

The Best of the Week (Oct 24): Agile Zone

Make sure you didn't miss anything with this list of the Best of the Week in the Agile Zone (October 24 - October 31). This week's topics include agile contracts, partial commits with Git, experts and professional opinions, prudent alternatives to today's Agile, and an Agile modeling exercise.

Gil Zilberfeld10/31/14
2218 views
0 replies

"The New Agile" Slides

I had a great time presenting at the Agile Practitioners meet-up. Good feedback, and felt like a keynote. Here are the slides.

Johanna Rothman10/31/14
5632 views
0 replies

Is Your Culture Working the Way You Think it Is?

One day, the Big Bosses, the CEO and the VP Engineering spoke at an all-hands meeting. “You are empowered,” they said. They had a vision. They just knew what the future would hold. I managed to keep my big mouth shut.

Lorna Mitchell10/31/14
934 views
0 replies

Announcing the Git Workbook

I'm very pleasedtitle_page to announce the immediate availability of my new book Git Workbook, costing $20 from LeanPub. This is a book that you "do" rather than "read"; it's a series of chapters (30 ish so far) each covering one specific git skill.

Ayende Rahien10/30/14
7188 views
0 replies

Modeling Exercise: The Grocery Store's Checkout Model

The grocery store checkout model exercise deals with the following scenario. You have a customer that is scanning products in a self-checkout lane, and you need to process the order. The end result might be a Git repository that allows you to see the full approach that was used and how it changed over time. Ideally, you should see a lot of churn in the beginning, but then you’ll have a lot less work to do as your architecture settles down.

Mike Bushong10/30/14
6410 views
0 replies

Outcome bias and the psychology that prevents sustained success

Ultimately, anyone in the tech space is going to have to make a number of product and market decisions. But make sure you apply the same logic to your personal career decisions as well. It is easy to celebrate or lament a particular decision based on the outcome. But understand that the best you can ever do is make the best possible decision based on the information you have at the time.

Allan Kelly10/30/14
649 views
0 replies

#NoProjects / #BeyondProjects - Agile Tour & Lean Kanban UK conference

The next few weeks sees me delivering my #NoProjects/#BeyondProjects presentation at two London conference - Agile Tour London (Friday this week) and Lean Kanban UK (3 & 4 November).