static public Contributions createContibutionHandler(ServletContext servletContext, Connection connection) { Contributions contributions = null; // Load up contribution properties file.... Properties props = new Properties(); { if( null != servletContext ) { Object propertiesObj = servletContext.getAttribute(PROPERTIES_SERVLET_ATTRIB_NAME); if( null != propertiesObj && propertiesObj instanceof Properties ) { props = (Properties)propertiesObj; } } } try { contributions = new Contributions(props, connection); } catch (Exception e) { logger.error("Contributions table problem - check that properties file definitions match database schema:", e); return(null); } return(contributions); } }
private void readProperties(Properties props) throws Exception { tableName = props.getProperty(PROPERTIES_KEY_TABLE_NAME, DEFAULT_TABLE_NAME); idColumnName = props.getProperty(PROPERTIES_KEY_ID_COLUMN_NAME, DEFAULT_ID_COLUMN_NAME); idSequenceName = props.getProperty(PROPERTIES_KEY_ID_SEQUENCE_NAME, DEFAULT_ID_SEQUENCE_NAME); String serverFieldList = props.getProperty(PROPERTIES_KEY_SERVER_SUPPORTED_COLUMNS, DEFAULT_SERVER_SUPPORTED_COLUMNS); String clientFieldList = props.getProperty(PROPERTIES_KEY_CLIENT_SIDE_COLUMNS, DEFAULT_CLIENT_SIDE_COLUMNS); createServerSupportedAndClientSideLists(serverFieldList, clientFieldList); allFieldsInDb(serverFieldList, true); // verify all fields in prop lists accounted for in db - throw exception otherwise allFieldsInDb(clientFieldList, false); if (serverSupported.includes(idColumnName)) { // mark that column as auto incremented serverSupported.setAutoIncrementSequence(idColumnName, idSequenceName); } else { throw new Exception(idColumnName + " must be included in the serverSupported field list."); } deleteSqlStatement = "DELETE FROM \""+tableName+"\" WHERE \""+idColumnName+"\" = ?;"; }
protected void performDelete(HttpServletRequest request, HttpServletResponse response) throws Exception { String[] ids = request.getParameterValues("id"); String[] placeIds = request.getParameterValues("placeId"); if( null == ids || ids.length < 1 ) { throw new Exception("Parameter 'id' not provided"); } if( ids.length > 1 ) { throw new Exception("Parameter 'id' provided multiple times"); } if( null == placeIds ) { placeIds = new String[0]; } if( placeIds.length > 1 ) { throw new Exception("Parameter 'place_id' provided multiple times"); } contributions.deleteContribution(ids[0], (placeIds.length > 0 ? placeIds[0] : null)); JSONObject result = new JSONObject(); result.put("id", ids[0]); if( placeIds.length > 0 ) { result.put("place_id", placeIds[0]); } sendJsonResponse(response, result); }
for (int loop=0; loop<count; ++loop) { String columnName = rsmd.getColumnName(loop+1); boolean isServerSupported = isColumnNameInList(columnName, serverFields); boolean isClientSide = isColumnNameInList(columnName, clientFields);
public void performDatabaseInsert(UploadedFileInfo fileInfo, Contributions cont) throws Exception { logger.info("Inserting contribution for user id: "+(userPrincipal==null?"unknown":userPrincipal.getName())); createServerGeneratedFields(fileInfo, cont, false); cont.insert(parameters); }
protected void performFromName(HttpServletRequest request, HttpServletResponse response) throws Exception { String[] names = request.getParameterValues("name"); if( null == names || names.length < 1 ) { throw new Exception("Parameter 'name' not provided"); } if( names.length > 1 ) { throw new Exception("Parameter 'name' provided multiple times"); } if (null != contributions) { JSONObject result = contributions.fromName(names[0], userRepository); sendJsonResponse(response, result); } else { throw new Exception("Contribution record access requests can not be fulfill because of failed initialization - look for earlier exceptions."); } }
public Contributions(Properties props, Connection connection) throws Exception { this.connection = connection; serverSupported = new ContributionServerSupportedFieldsImpl(); clientSide = new ContributionClientSideFieldsImpl(); readProperties(props); }
public JSONObject fromName(String intPlaceId, UserRepository userRepository) throws Exception { String queryString = "SELECT " + serverSupported.getFieldNamesList(); String clientFieldList = clientSide.getFieldNamesList(); /* * Assume there must be serverSupported fields but allow for no clientSide fields... */ if (clientFieldList != "") { queryString += "," + clientFieldList; } queryString += " FROM " + tableName + " WHERE place_id=?;"; PreparedStatement stmt = connection.prepareStatement(queryString); serverSupported.writeToPreparedStatement(stmt, "place_id", 1, intPlaceId); //logger.info(stmt.toString()); JSONArray contributions = executeContribSelectToJson(stmt, userRepository); JSONObject result = new JSONObject(); result.put("contributions", contributions); return(result); }
public void init(ServletConfig config) throws ServletException { super.init(config); try { connections = JdbcConnections.connectionsFromServletContext(config.getServletContext()); connection = connections.getDb(); } catch (Exception e) { throw new ServletException("Error while connecting to database",e); } userRepository = UserRepositorySingleton.getSingleton(); contributions = ContributionsUtils.createContibutionHandler(config.getServletContext(), connection); if (null == contributions) { return; } try { ContributionComet contComet = new ContributionCometImpl(config.getServletContext()); contributions.setContributionComet( contComet ); } catch(Exception e) { logger.error("Comet not available for contributions", e); } }
boolean first = true; for (int i=0; i<fullList_serverFields.length; i++) { if (!isColumnNameInList(fullList_serverFields[i], dontChange_serverSupported)) { if (fieldPairs.containsKey(fullList_serverFields[i])) { if (first) {