Community Board of Realtors® : One of the key use cases for the Multiple Listing
ID: 3603695 • Letter: C
Question
Community Board of Realtors® :
One of the key use cases for the Multiple Listing Service system is Create new listing, where the realtor enters all the important information about a new listing he or she has obtained.
Realtors want to be able to create a new listing as soon as possible so other realtors and potential buyers will find the listing online. Some like to enter the information while talking with the owner or while inspecting the property. Realtors are rarely in their offices these days, so being able to create a new listing on a mobile device is a key feature of the Multiple Listing Service system. Consider the information that must be entered when creating a new listing, and list the dialogue steps that are necessary. Keep in mind that when designing for a smartphone, less information can be entered in each step compared with a full screen Web application. Also keep in mind that typing is error-prone and awkward for many users, so think about opportunities to use check boxes, radio buttons, and list boxes to aid selection. Create a storyboard of this use case for a mobile device, showing each step of the dialogue that maximizes the use of check boxes, radio buttons, and list boxes.
Explanation / Answer
ANSWER::
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.CookieHandler;
import java.net.CookieManager;
import java.net.CookiePolicy;
import java.net.HttpURLConnection;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.zip.GZIPInputStream;
public class MDSClientHandler
{
// The user credentials
private String userId;
private String password;
// The user agent
private String userAgent;
// The endpoint
private String endpoint;
// Use gzip
private boolean requestGZip = false;
// Debug mode
private boolean debug = false;
// The logger for this class
Logger logger = Logger.getLogger(this.getClass().getCanonicalName());
public MDSClientHandler(String userId, String password, String userAgent, String endpoint)
{
this.userId = userId;
this.password = password;
this.userAgent = userAgent;
this.endpoint = endpoint;
if (endpoint.endsWith("/") == false)
{
// Ensure that the endpoint has a trailing "/"
endpoint += "/";
}
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(cookieManager);
Authenticator.setDefault(new MDSAuthenticator());
}
public void logout()
{
processRequest(getResourceUrl("Logout"));
}
public String getUserSessionInfo()
{
return processRequest(getResourceUrl("UserSessionInfo"));
}
public void requestGZip(boolean value)
{
this.requestGZip = value;
}
/**
* This method is used to indicate the debugging mode.
*
* @param value if true, debugging will be turned on
*/
public void setDebuggingOn(boolean value)
{
this.debug = value;
}
public String executeRequest(String resourcePath, String query, Boolean count, Integer limit)
{
String url = getResourceUrl(resourcePath);
url += "/?Query=" + query;
if (count != null && count == Boolean.TRUE)
{
url += "&Count=1";
}
if (limit != null)
{
url += "&Limit=" + limit;
}
return processRequest(url);
}
public String executeRequest(String resourcePath, String[] resourceKeys, String selectFields)
{
String url = getResourceUrl(resourcePath);
if (resourceKeys != null)
{
String resourceKeyList = null;
for (String resourceKey : resourceKeys)
{
if (resourceKeyList == null)
{
resourceKeyList = resourceKey;
}
else
{
resourceKeyList += "," + resourceKey;
}
}
url += "/" + resourceKeyList;
}
if (selectFields != null)
{
url += "?Select=" + selectFields;
}
return processRequest(url);
}
private String processRequest(String url)
{
HttpURLConnection conn = null;
try
{
conn = createRequest(url);
if (debug)
{
logger.info("Authentication Succeeded");
String headerInfo = "The following headers were received in the response: ";
Map<String,List<String>> headers = conn.getHeaderFields();
for (String headerName : headers.keySet())
{
List<String> headerValueList = headers.get(headerName);
for (String headerValue : headerValueList)
{
headerInfo += " " + headerName + ": " + headerValue + " ";
}
}
logger.info(headerInfo);
}
}
catch(IOException e)
{
logger.log(Level.SEVERE, "Failed to create connection.", e);
return null;
}
try
{
String contentEncoding = conn.getContentEncoding();
StringBuffer content = new StringBuffer();
InputStream is = (InputStream) conn.getInputStream();
if (contentEncoding != null && contentEncoding.equals("gzip"))
{
is = new GZIPInputStream(is);
}
if (debug) logger.info("Response stream received.");
BufferedReader in = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = in.readLine()) != null)
{
content.append(line + " ");
if (debug) logger.info(line);
}
in.close();
return content.toString();
}
catch (IOException e)
{
logger.log(Level.SEVERE, "Request failed.", e);
return null;
}
}
private HttpURLConnection createRequest(String url)
throws IOException
{
HttpURLConnection conn = null;
URL _url = new URL(url);
conn = (HttpURLConnection)_url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("User-Agent", userAgent);
if (this.requestGZip)
{
conn.setRequestProperty("Accept-Encoding", "gzip");
}
conn.connect();
return conn;
}
private String getResourceUrl(String resourcePath)
{
if (resourcePath.startsWith("/"))
{
resourcePath = resourcePath.substring(1, resourcePath.length() - 1);
}
return endpoint + resourcePath;
}
private class MDSAuthenticator extends Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
return (new PasswordAuthentication(userId, password.toCharArray()));
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.