@@ -0,0 +1,2155 @@
+package edu.ucla.cens.awserver.domain;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0Aimport org.json.JSONArray;%0Aimport org.json.JSONObject;%0A%0Aimport edu.ucla.cens.awserver.domain.PromptDataPacket.PromptResponseDataPacket;%0Aimport edu.ucla.cens.awserver.util.JsonUtils;%0A%0A/**%0A * Builder of DataPackets representing a prompt response upload.%0A * %0A * @author selsky%0A */%0Apublic class PromptDataPacketBuilder extends AbstractDataPacketBuilder %7B%0A//%09private static Logger logger = Logger.getLogger(PromptDataPacketBuilder.class);%0A%09%0A%09/**%0A%09 * Creates a DataPacket for a prompt response upload. The DataPacket will contain the JSON message metadata and each prompt%0A%09 * response. Assumes that the prompt upload message is valid.%0A%09 */%0A%09public DataPacket createDataPacketFrom(JSONObject source) %7B%0A%09%09PromptDataPacket promptDataPacket = new PromptDataPacket();%0A%09%09createCommonFields(source, promptDataPacket);%0A%09%09List%3CDataPacket%3E _responsePackets = new ArrayList%3CDataPacket%3E();%0A%09%09 %0A%09%09JSONArray responses = JsonUtils.getJsonArrayFromJsonObject(source, %22responses%22);%0A%09%09int arrayLength = responses.length();%09%0A%09%09%0A%09%09for(int i = 0; i %3C arrayLength; i++) %7B%0A%09%09%09PromptResponseDataPacket promptResponseDataPacket = promptDataPacket.new PromptResponseDataPacket();%0A%09%09%09JSONObject fullResponseObject = JsonUtils.getJsonObjectFromJsonArray(responses, i);%0A%09%09%09%0A%09%09%09promptResponseDataPacket.setPromptConfigId(JsonUtils.getIntegerFromJsonObject(fullResponseObject, %22prompt_id%22));%0A%09%09%09%0A%09%09%09Object response = JsonUtils.getObjectFromJsonObject(fullResponseObject, %22response%22);%0A%09%09%09%0A%09%09%09// Create a new JSON object containing only the response. The data type of the response is variable.%0A%09%09%09Map%3CString, Object%3E responseOnlyMap = new HashMap%3CString, Object%3E();%0A%09%09%09responseOnlyMap.put(%22response%22, response);%0A%09%09%09JSONObject responseOnlyObject = new JSONObject(responseOnlyMap); %0A%09%09%09promptResponseDataPacket.setResponse(responseOnlyObject.toString());%0A%09%09%09%0A%09%09%09// logger.info(promptResponseDataPacket);%0A%09%09%09%0A%09    %09_responsePackets.add(promptResponseDataPacket);%0A%09%09%7D%0A%09%09%0A%09%09promptDataPacket.setResponses(_responsePackets);%0A%09%09%0A%09%09return promptDataPacket;%0A%09%7D%0A%0A%7D%0A

use of the builder pattern from prompt messages