Skip to content

Commit 3c822af

Browse files
committed
0.4.4 Update
create table for operator blacklist exceptions add readonly frontend column for exceptions to operator blacklist create tables for storing trend data create page to search for trends create trend data collection function create button to toggle developer mode unregister PostgreSQL driver on contextDestroyed
1 parent 30fc66c commit 3c822af

20 files changed

+999
-108
lines changed

config/BUILD_DETAILS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ commonbaseutils-2.0.3
1919
commonexceptions-8.5.002
2020
core-8.5.002
2121
datatable-8.5.002
22+
directaccess-8.5.002
23+
directaccess-api-8.5.002
2224
extensionsupport-api-8.5.002
2325
jsch-0.2.11-sources
2426
postgresql-42.6.0-sources

config/RUNTIME_DEPS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,7 @@ file:core:modules\core
66
file:common:modules\common
77
file:commonexceptions:modules\commonexceptions
88
file:commonbaseutils:bin\lib
9+
file:directaccess:modules\directaccess
10+
file:directaccess-api:modules\directaccess
911
url:postgresql:https://repo1.maven.org/maven2/org/postgresql/postgresql/42.6.0/postgresql-42.6.0-sources.jar
1012
url:jsch:https://repo1.maven.org/maven2/com/github/mwiede/jsch/0.2.11/jsch-0.2.11-sources.jar

root/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<extension version="1">
22
<name>PostgreSQL_Connect</name>
33
<description>Periodically synchronizes data to an external PostgreSQL database.</description>
4-
<version>0.4.3</version>
4+
<version>0.4.4</version>
55
<vendor>Automatic Controls Equipment Systems, Inc.</vendor>
66
<system-menu-provider>aces.webctrl.postgresql.web.SystemMenuEditor</system-menu-provider>
77
</extension>

root/webapp/WEB-INF/web.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@
5555
<url-pattern>/LocalOperators</url-pattern>
5656
</servlet-mapping>
5757

58+
<servlet>
59+
<servlet-name>FindTrendsPage</servlet-name>
60+
<servlet-class>aces.webctrl.postgresql.web.FindTrendsPage</servlet-class>
61+
</servlet>
62+
<servlet-mapping>
63+
<servlet-name>FindTrendsPage</servlet-name>
64+
<url-pattern>/FindTrends</url-pattern>
65+
</servlet-mapping>
66+
5867
<security-constraint>
5968
<web-resource-collection>
6069
<web-resource-name>WEB</web-resource-name>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package aces.webctrl.postgresql.core;
2+
public class Container<T> {
3+
public volatile T x;
4+
public Container(){
5+
x = null;
6+
}
7+
public Container(T x){
8+
this.x = x;
9+
}
10+
}

src/aces/webctrl/postgresql/core/HelperAPI.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,24 @@ public static boolean logout(Set<String> usernames){
2727
}
2828
return false;
2929
}
30+
/**
31+
* Toggles developer mode for all sessions corresponding to the given user.
32+
* @return whether developer mode is enabled
33+
*/
34+
public static boolean toggleDevMode(String username) throws Throwable {
35+
boolean first = true;
36+
boolean dev = false;
37+
for (final UserSession session:UserSession.getAllUserSessions()){
38+
if (username.equalsIgnoreCase(session.getOperator().getLoginName())){
39+
if (first){
40+
first = false;
41+
dev = !session.getIsDeveloperEnabledFlag();
42+
}
43+
session.setIsDeveloper(dev);
44+
}
45+
}
46+
return dev;
47+
}
3048
/**
3149
* @return a collection of all local WebCTRL operators where usernames are mapped to display names, or {@code null} if an error occurs.
3250
*/

src/aces/webctrl/postgresql/core/Initializer.java

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
package aces.webctrl.postgresql.core;
22
import java.nio.file.*;
3+
import java.sql.*;
34
import javax.servlet.*;
5+
import java.util.*;
46
import java.util.concurrent.*;
57
import com.controlj.green.addonsupport.*;
8+
import com.controlj.green.addonsupport.access.*;
69
import com.controlj.green.common.CJProduct;
710
public class Initializer implements ServletContextListener {
811
/** Name of the addon used for auto udpates */
@@ -45,6 +48,8 @@ public class Initializer implements ServletContextListener {
4548
private volatile static long nextSave = 0;
4649
/** Stores log messages before sending them to the database. */
4750
public final static ConcurrentLinkedQueue<LogMessage> logCache = new ConcurrentLinkedQueue<LogMessage>();
51+
/** Root system connection to the database. */
52+
private volatile static SystemConnection con = null;
4853
/**
4954
* Entry point of this add-on.
5055
*/
@@ -119,13 +124,13 @@ public void run(){
119124
@Override public void contextDestroyed(ServletContextEvent sce){
120125
stop = true;
121126
if (mainThread==null){
122-
Config.save();
127+
handleDestruction();
123128
}else{
124129
mainThread.interrupt();
125130
synchronized (syncNotifier){
126131
syncNotifier.notifyAll();
127132
}
128-
Config.save();
133+
handleDestruction();
129134
//Wait for the primary processing thread to terminate.
130135
while (true){
131136
try{
@@ -137,6 +142,23 @@ public void run(){
137142
log("Execution terminated.");
138143
new Sync(Event.SHUTDOWN);
139144
}
145+
private static void handleDestruction(){
146+
Config.save();
147+
// We deregister the PostgreSQL driver so that Tomcat does not complain
148+
final ClassLoader cl = Thread.currentThread().getContextClassLoader();
149+
final Enumeration<Driver> drivers = DriverManager.getDrivers();
150+
Driver driver;
151+
while (drivers.hasMoreElements()) {
152+
driver = drivers.nextElement();
153+
if (driver.getClass().getClassLoader()==cl) {
154+
try{
155+
DriverManager.deregisterDriver(driver);
156+
}catch(Throwable t){
157+
log(t);
158+
}
159+
}
160+
}
161+
}
140162
/**
141163
* Tells the processing thread to invoke a synchronization event ASAP.
142164
*/
@@ -146,6 +168,15 @@ public static void syncNow(){
146168
syncNotifier.notifyAll();
147169
}
148170
}
171+
/**
172+
* @return the root system connection used by this application.
173+
*/
174+
public static SystemConnection getConnection(){
175+
if (con==null){
176+
con = DirectAccess.getDirectAccess().getRootSystemConnection();
177+
}
178+
return con;
179+
}
149180
/**
150181
* @return the name of this application.
151182
*/

0 commit comments

Comments
 (0)