package edu.cmu.sv.ws.ssnoc.common.utils;

import edu.cmu.sv.ws.ssnoc.data.nosql.dao.DAOFactory;
import edu.cmu.sv.ws.ssnoc.data.po.StatusPO;
import edu.cmu.sv.ws.ssnoc.data.po.UserPO;
import edu.cmu.sv.ws.ssnoc.dto.Status;
import edu.cmu.sv.ws.ssnoc.dto.User;

/**
 * This is a utility class used to convert PO (Persistent Objects) and View
 * Objects into DTO (Data Transfer Objects) objects, and vice versa. <br/>
 * Rather than having the conversion code in all classes in the rest package,
 * they are maintained here for code re-usability and modularity.
 * 
 */
public class ConverterUtils {
	/**
	 * Convert UserPO to User DTO object.
	 * 
	 * @param po
	 *            - User PO object
	 * 
	 * @return - User DTO Object
	 */
	public static final User convert(UserPO po) {
		if (po == null) {
			return null;
		}

		User dto = new User();
		dto.setUserName(po.getUserName());
		StatusPO statusPO =DAOFactory.getInstance().getStatusDAO().findStatusById(po.getLastStatusID());
		Status statusDTO = new Status();
		statusDTO.setLocation(statusPO.getLocation());
		statusDTO.setStatusCode(statusPO.getStatusCode());
		statusDTO.setUpdatedAtDate(statusPO.getUpdatedAt());
		dto.setLastStatusCode(statusDTO);
		dto.setCreateAt(po.getCreateAt());

		return dto;
	}

	/**
	 * Convert User DTO to UserPO object
	 * 
	 * @param dto
	 *            - User DTO object
	 * 
	 * @return - UserPO object
	 */
	public static final UserPO convert(User dto) {
		if (dto == null) {
			return null;
		}

		UserPO po = new UserPO();
		po.setUserName(dto.getUserName());
		po.setPassword(dto.getPassword());
		po.setCreateAt(dto.getCreateAt());

		return po;
	}
}

@@ -873,24 +873,101 @@
 serName());%0A
+%09%09if(po.getLastStatusID() == null)%0A%09%09%09dto.setLastStatusCode(null);%0A%09%09else%7B%0A%0A%09
 %09%09StatusPO s
@@ -1055,16 +1055,17 @@
 D());%0A%09%09
+%09
 Status s
@@ -1089,16 +1089,17 @@
 atus();%0A
+%09
 %09%09status
@@ -1137,24 +1137,25 @@
 ation());%0A%09%09
+%09
 statusDTO.se
@@ -1193,16 +1193,17 @@
 ode());%0A
+%09
 %09%09status
@@ -1249,16 +1249,17 @@
 dAt());%0A
+%09
 %09%09dto.se
@@ -1286,16 +1286,24 @@
 usDTO);%0A
+%09%09%09%0A%09%09%7D%0A
 %09%09dto.se

add null checker on ConverterUtils