Skip to content

Commit 3065eb9

Browse files
committed
1 parent 73f4abd commit 3065eb9

File tree

6 files changed

+216
-151
lines changed

6 files changed

+216
-151
lines changed

TNAtoolAPI-Webapp/src/main/java/com/model/database/queries/PgisEventManager.java

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6129,7 +6129,7 @@ public static Map<String,Agencyselect> setHiddenAgencies(int dbindex, String use
61296129
return Agencyget(dbindex, username);
61306130
}
61316131

6132-
public static Map<String,Agencyselect> removeHiddenAgencies(int dbindex, String username)
6132+
public static void removeHiddenAgencies(int dbindex, String username)
61336133
throws SQLException, FactoryException, TransformException {
61346134
DatabaseConfig db = DatabaseConfig.getConfig(dbindex);
61356135
Connection connection = db.getConnection();
@@ -6146,18 +6146,47 @@ public static Map<String,Agencyselect> removeHiddenAgencies(int dbindex, String
61466146
logger.error(e);
61476147
}
61486148
connection.close();
6149+
}
61496150

6150-
return Agencyget(dbindex, username);
6151+
public static void ensureDBSessionInitialized(int dbindex, String username) {
6152+
Connection connection = makeConnection(dbindex);
6153+
String query="";
6154+
PreparedStatement stmt = null;
6155+
6156+
query = ""
6157+
+ " INSERT INTO user_selected_agencies (username, agency_id, hidden) ("
6158+
+ " SELECT '" + username + "', gtfs_agencies.defaultid, false"
6159+
+ " FROM gtfs_agencies "
6160+
+ " ) ON CONFLICT (username, agency_id) DO NOTHING"
6161+
+ "";
6162+
6163+
logger.info("ensureDBSessionInitialized query: " + query);
6164+
6165+
try {
6166+
stmt = connection.prepareStatement(query);
6167+
stmt.executeUpdate();
6168+
stmt.close();
6169+
dropConnection(connection);
6170+
}
6171+
catch ( Exception e ) {
6172+
e.printStackTrace();
6173+
}
61516174
}
61526175

6176+
61536177
public static Map<String,Agencyselect> Agencyget(int dbindex, String username)
61546178
throws FactoryException, TransformException {
6179+
6180+
// Kind of a hack, but this is the only place I found that guarantees
6181+
// selected agencies are initialized and that has access to dbindex and username
6182+
// -- Annie
6183+
ensureDBSessionInitialized(dbindex, username);
61556184
Connection connection = makeConnection(dbindex);
61566185
String query="";
61576186
Statement stmt = null;
61586187

6159-
Map<String,Agencyselect> r = new LinkedHashMap<String,Agencyselect>();
6160-
// query ="select id,name,defaultid from gtfs_agencies";
6188+
Map<String,Agencyselect> r = new LinkedHashMap<String,Agencyselect>();
6189+
61616190
query = "SELECT a.id,a.name,a.defaultid,b.hidden,f.feedname,f.startdate,f.enddate FROM gtfs_agencies AS a LEFT OUTER JOIN user_selected_agencies AS b ON (b.username = '"+username+"' AND a.defaultid = b.agency_id) INNER JOIN gtfs_feed_info f ON f.defaultid = a.defaultid ORDER BY name";
61626191

61636192
try {

0 commit comments

Comments
 (0)