// Path: autocompleteServer/src/main/java/de/metalcon/autocompleteServer/Helper/ContextListener.java
// public class ContextListener {
// 
// 	public static SuggestTree getIndex(String indexName, ServletContext context) {
// 		return (SuggestTree) context
// 				.getAttribute(ProtocolConstants.INDEX_PARAMETER + indexName);
// 	}
// 
// 	public static void setIndex(String indexName, SuggestTree index,
// 			ServletContext context) {
// 		context.setAttribute(ProtocolConstants.INDEX_PARAMETER + indexName,
// 				index);
// 	}
// 
// 	public static HashMap<String, String> getImageIndex(ServletContext context) {
// 		return (HashMap<String, String>) context
// 				.getAttribute(ProtocolConstants.IMAGE_SERVER_CONTEXT_KEY);
// 	}
// 
// 	public static void setImageIndex(HashMap<String, String> imageIndex,
// 			ServletContext context) {
// 		context.setAttribute(ProtocolConstants.IMAGE_SERVER_CONTEXT_KEY,
// 				imageIndex);
// 	}
// 
// }
// 
// Path: autocompleteServer/src/main/java/de/metalcon/autocompleteServer/Helper/ProtocolConstants.java
// public class ProtocolConstants {
// 	public static final String QUERY_PARAMETER = "term";
// 	public static final String INDEX_PARAMETER = "indexName";
// 	public static final String NUM_ITEMS = "numItems";
// 
// 	/**
// 	 * parameters for the response JSON of the retrieval request
// 	 */
// 	public static final String RESP_JSON_FIELD_SUGGESTION_LIST = "suggestionList";
// 	public static final String RESP_JSON_FIELD_SUGGESTION = "suggestion";
// 	public static final String RESP_JSON_FIELD_SUGGESTION_KEY = "key";
// 	public static final String RESP_JSON_FIELD_SUGGESTION_IMAGE = "image";
// 
// 	/**
// 	 * form parameter names for the create request of the ASTP
// 	 */
// 	public static final String SUGGESTION_WEIGHT = "weight";
// 	public static final String SUGGESTION_KEY = "key";
// 	public static final String SUGGESTION_STRING = "term";
// 	public static final int MAX_SUGGESTION_LENGTH = 80;
// 	public static final int MAX_KEY_LENGTH = 64;
// 	public static final String IMAGE = "image";
// 	public static final int IMAGE_WIDTH = 64;
// 	public static final int IMAGE_HEIGHT = 64;
// 	public static final long MAX_IMAGE_FILE_LENGTH = 3000000;
// 	public static final String STATUS_OK = "Status:OK";
// 	public static final String STATUS_NO_QUERY = "Error:queryNameNotGiven";
// 	public static final String STATUS_QUERY_TOO_LONG = "Error:queryNameTooLong";
// 	public static final String STATUS_DEFAULT_INDEX = "Warning:DefaultIndex";
// 	public static final String STATUS_NO_IMAGE = "Warning:noImage";
// 	public static final String STATUS_REQUEST_NOT_MULTIPART = "Error:RequestNotMultipart";
// 	public static final String STATUS_NO_WEIGHT = "Error:WeightNotGiven";
// 	public static final String STATUS_WEIGHT_NOT_A_NUMBER = "Error:WeightNotANumber";
// 	public static final String STATUS_NO_KEY = "Warning:KeyNotGiven";
// 	public static final String STATUS_KEY_TOO_LONG = "Warning:KeyTooLong";
// 
// 	/**
// 	 * the default Number of Items which can be retrieved from the Suggest
// 	 * Server
// 	 */
// 	public static final Integer MAX_NUMBER_OF_SUGGESTIONS = 7;
// 	public static final String DEFAULT_INDEX_NAME = "generalindex";
// 	public static final String IMAGE_SERVER_CONTEXT_KEY = "image-index-hashMap";
// }


import java.util.ArrayList;
import java.util.HashMap;
import javax.servlet.ServletContext;
import org.json.simple.JSONObject;
import de.metalcon.autocompleteServer.Helper.ContextListener;
import de.metalcon.autocompleteServer.Helper.ProtocolConstants;
package de.metalcon.autocompleteServer.Retrieve;





/**
 * The ProcessRetrieveResponse class handles the data that are send to the client
 * after a retrieve request has been sent. 
 * This can be the actual content as well as meta information (like error messages
 * and warnings) 
 * 
 * TODO: This class needs to be implemented. All functions are just empty functions. 
 * @author Rene Pickhardt
 *
 */
public class ProcessRetrieveResponse {
	private ServletContext context;
	private JSONObject jsonResponse;
	private ArrayList<HashMap<String, String>> suggestionsResponseList;
	
	/**
	 * @param context
	 */
	
	public ProcessRetrieveResponse(ServletContext context) {
		//TODO:what happens if the provided context is null? 
		this.context = context;
		jsonResponse = new JSONObject();
		suggestionsResponseList = new ArrayList<HashMap<String, String>>();
	}

	/**
	 * @param numitemsNotGiven
	 */
	public void addNumItemsWarning(String message) {
		if (jsonResponse==null){
			jsonResponse = new JSONObject();
		}
		jsonResponse.put("warning:numItems", message);		
	}

	/**
	 * not implemented yet
	 * @param noIndexGiven
	 */
	public void addIndexWarning(String noIndexGiven) {
		if (jsonResponse==null){
			jsonResponse = new JSONObject();
		}
		jsonResponse.put("warning:noIndexGiven", noIndexGiven);		
	}

	/**
	 * @param noIndexAvailable
	 */
	public void addError(String message) {
		// TODO Errors should really stop the request and send the answer away
		if (jsonResponse==null){
			jsonResponse = new JSONObject();
		}
		jsonResponse.put("error", message);
	}

	/**
	 * @param suggestString
	 * @param key
	 */
	public void addSuggestion(String suggestString, String key) {
		// also retrieve image from the image index
// Path: autocompleteServer/src/main/java/de/metalcon/autocompleteServer/Helper/ContextListener.java
// public class ContextListener {
// 
// 	public static SuggestTree getIndex(String indexName, ServletContext context) {
// 		return (SuggestTree) context
// 				.getAttribute(ProtocolConstants.INDEX_PARAMETER + indexName);
// 	}
// 
// 	public static void setIndex(String indexName, SuggestTree index,
// 			ServletContext context) {
// 		context.setAttribute(ProtocolConstants.INDEX_PARAMETER + indexName,
// 				index);
// 	}
// 
// 	public static HashMap<String, String> getImageIndex(ServletContext context) {
// 		return (HashMap<String, String>) context
// 				.getAttribute(ProtocolConstants.IMAGE_SERVER_CONTEXT_KEY);
// 	}
// 
// 	public static void setImageIndex(HashMap<String, String> imageIndex,
// 			ServletContext context) {
// 		context.setAttribute(ProtocolConstants.IMAGE_SERVER_CONTEXT_KEY,
// 				imageIndex);
// 	}
// 
// }
// 
// Path: autocompleteServer/src/main/java/de/metalcon/autocompleteServer/Helper/ProtocolConstants.java
// public class ProtocolConstants {
// 	public static final String QUERY_PARAMETER = "term";
// 	public static final String INDEX_PARAMETER = "indexName";
// 	public static final String NUM_ITEMS = "numItems";
// 
// 	/**
// 	 * parameters for the response JSON of the retrieval request
// 	 */
// 	public static final String RESP_JSON_FIELD_SUGGESTION_LIST = "suggestionList";
// 	public static final String RESP_JSON_FIELD_SUGGESTION = "suggestion";
// 	public static final String RESP_JSON_FIELD_SUGGESTION_KEY = "key";
// 	public static final String RESP_JSON_FIELD_SUGGESTION_IMAGE = "image";
// 
// 	/**
// 	 * form parameter names for the create request of the ASTP
// 	 */
// 	public static final String SUGGESTION_WEIGHT = "weight";
// 	public static final String SUGGESTION_KEY = "key";
// 	public static final String SUGGESTION_STRING = "term";
// 	public static final int MAX_SUGGESTION_LENGTH = 80;
// 	public static final int MAX_KEY_LENGTH = 64;
// 	public static final String IMAGE = "image";
// 	public static final int IMAGE_WIDTH = 64;
// 	public static final int IMAGE_HEIGHT = 64;
// 	public static final long MAX_IMAGE_FILE_LENGTH = 3000000;
// 	public static final String STATUS_OK = "Status:OK";
// 	public static final String STATUS_NO_QUERY = "Error:queryNameNotGiven";
// 	public static final String STATUS_QUERY_TOO_LONG = "Error:queryNameTooLong";
// 	public static final String STATUS_DEFAULT_INDEX = "Warning:DefaultIndex";
// 	public static final String STATUS_NO_IMAGE = "Warning:noImage";
// 	public static final String STATUS_REQUEST_NOT_MULTIPART = "Error:RequestNotMultipart";
// 	public static final String STATUS_NO_WEIGHT = "Error:WeightNotGiven";
// 	public static final String STATUS_WEIGHT_NOT_A_NUMBER = "Error:WeightNotANumber";
// 	public static final String STATUS_NO_KEY = "Warning:KeyNotGiven";
// 	public static final String STATUS_KEY_TOO_LONG = "Warning:KeyTooLong";
// 
// 	/**
// 	 * the default Number of Items which can be retrieved from the Suggest
// 	 * Server
// 	 */
// 	public static final Integer MAX_NUMBER_OF_SUGGESTIONS = 7;
// 	public static final String DEFAULT_INDEX_NAME = "generalindex";
// 	public static final String IMAGE_SERVER_CONTEXT_KEY = "image-index-hashMap";
// }


// Path: autocompleteServer/src/main/java/de/metalcon/autocompleteServer/Retrieve/ProcessRetrieveResponse.java
import java.util.ArrayList;
import java.util.HashMap;
import javax.servlet.ServletContext;
import org.json.simple.JSONObject;
import de.metalcon.autocompleteServer.Helper.ContextListener;
import de.metalcon.autocompleteServer.Helper.ProtocolConstants;

package de.metalcon.autocompleteServer.Retrieve;





/**
 * The ProcessRetrieveResponse class handles the data that are send to the client
 * after a retrieve request has been sent. 
 * This can be the actual content as well as meta information (like error messages
 * and warnings) 
 * 
 * TODO: This class needs to be implemented. All functions are just empty functions. 
 * @author Rene Pickhardt
 *
 */
public class ProcessRetrieveResponse {
	private ServletContext context;
	private JSONObject jsonResponse;
	private ArrayList<HashMap<String, String>> suggestionsResponseList;
	
	/**
	 * @param context
	 */
	
	public ProcessRetrieveResponse(ServletContext context) {
		//TODO:what happens if the provided context is null? 
		this.context = context;
		jsonResponse = new JSONObject();
		suggestionsResponseList = new ArrayList<HashMap<String, String>>();
	}

	/**
	 * @param numitemsNotGiven
	 */
	public void addNumItemsWarning(String message) {
		if (jsonResponse==null){
			jsonResponse = new JSONObject();
		}
		jsonResponse.put("warning:numItems", message);		
	}

	/**
	 * not implemented yet
	 * @param noIndexGiven
	 */
	public void addIndexWarning(String noIndexGiven) {
		if (jsonResponse==null){
			jsonResponse = new JSONObject();
		}
		jsonResponse.put("warning:noIndexGiven", noIndexGiven);		
	}

	/**
	 * @param noIndexAvailable
	 */
	public void addError(String message) {
		// TODO Errors should really stop the request and send the answer away
		if (jsonResponse==null){
			jsonResponse = new JSONObject();
		}
		jsonResponse.put("error", message);
	}

	/**
	 * @param suggestString
	 * @param key
	 */
	public void addSuggestion(String suggestString, String key) {
		// also retrieve image from the image index
		HashMap<String, String> suggestionJsonEntry = new HashMap<String, String>();