Skip to content

Commit

Permalink
Issues #1 and #2 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
rszturc committed Jan 11, 2016
1 parent 24a4cc4 commit 8849fde
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ public interface CrowdSourcingSchema {
String CONFIG_TAGS = "tags";
String CONFIG_MIME_TYPES = "mime_types";
String CONFIG_STATUSES = "statuses";
String CONFIG_PRIORITIES = "priorities";
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Collection;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
Expand All @@ -30,8 +31,6 @@ public ConfigServlet() {
super();
}

public static final String QUERY_GET_TAGS = "SELECT value FROM tag";

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
Expand All @@ -41,43 +40,23 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
Exception exception = null;
Connection connection = null;
Statement statement = null;
ResultSet result = null;

try {
JSONObject config = new JSONObject();

JSONArray tags = new JSONArray();

connection = openDatabaseConnection();
statement = connection.createStatement();
result = statement.executeQuery(QUERY_GET_TAGS);
while (result.next()) {
tags.add(result.getString(1));
}

if (tags.size() > 0)
config.put(CONFIG_TAGS, tags);

JSONArray mediaTypes = new JSONArray();
mediaTypes.add("image/jpeg");
mediaTypes.add("image/png");
config.put(CONFIG_MIME_TYPES, mediaTypes);
JSONObject config = new JSONObject();
addToConfig(config, CONFIG_TAGS, getAvailableTags(connection));
addToConfig(config, CONFIG_MIME_TYPES, getSupportedMimeTypes(connection));
addToConfig(config, CONFIG_STATUSES, getAvailableStatuses(connection));
addToConfig(config, CONFIG_PRIORITIES, getAvailablePriorities(connection));

JSONArray statuses = new JSONArray();
statuses.add("new");
statuses.add("assigned");
statuses.add("approved");
statuses.add("closed");
config.put(CONFIG_STATUSES, statuses);

PrintWriter writer = response.getWriter();
config.writeJSONString(writer);
}
catch (Exception e) {
exception = e;
}
finally {
closeQuietly(result);
closeQuietly(statement);
closeQuietly(connection);
}
Expand All @@ -88,6 +67,12 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response)
}
}

private void addToConfig(JSONObject config, String key, Collection<String> values) {
JSONArray array = new JSONArray();
array.addAll(values);
config.put(key, array);
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,6 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
double latitude = getDoubleOrThrow(location, LOCATION_LATITUDE);
int srid = getSRID(getString(location, LOCATION_CRS));

//
// statement = connection.prepareStatement(INSERT_LOCATION);
// statement.setDouble(1, longitude);
// statement.setDouble(2, latitude);
// statement.setString(3, crs);
// result = statement.executeQuery();
// result.next();
// int locationId = result.getInt(1);
// result.close();
// statement.close();

statement = connection.prepareStatement(SELECT_USER);
statement.setString(1, userId);
result = statement.executeQuery();
Expand Down

0 comments on commit 8849fde

Please sign in to comment.