Skip to content

Commit

Permalink
#2698 Corrected cache pending events -
Browse files Browse the repository at this point in the history
- Update cached pending events for only logged user; (Limiting the number of database queries) - added spring bean org.scada_lts.login.LoggedUsers; corrected update permission without logout user; added test suite: LoggedUserTestsSuite (LoggedUsersMultiThreadTest, LoggedUsersTest), extends MultiThreadEngine and TestConcurrentUtils; removed deprecated methods: MangoEvent/EventService.getPendingSimpleEventsForDataSource, MangoEvent/EventService.getPendingSimpleEvents; removed deprecated class EventDao; added enum AlarmLevelType; refactor: PendingEventsDAO, PendingEventService;
- The current limited event analysis to the number of events within the limit, this has been corrected for cache mode; (Information about events could be false, e.g. an event that should have been displayed could be missing, on Alarm List Component) - added parameter event.pending.update.limit to env.properties, corrected AlarmListComponent, added method getEventPendingUpdateLimit in SystemSettingsUtils;
- By default, the Pending event cache is enabled; (This setting can be changed from SystemSettings) - set abilit.cacheEnable=true in env.properties
  • Loading branch information
Limraj committed Sep 14, 2023
1 parent 8e42f44 commit 3fb887a
Show file tree
Hide file tree
Showing 24 changed files with 1,448 additions and 332 deletions.
2 changes: 2 additions & 0 deletions WebContent/WEB-INF/applicationContext.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,4 +244,6 @@
<constructor-arg ref="pointEventDetectorCache"/>
</bean>
<!-- -->

<bean id="loggedUsers" class="org.scada_lts.login.LoggedUsers" />
</beans>
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,6 @@ test {
includeTestsMatching "org.scada_lts.dao.IsEventDetectorXidUniqueTest"
includeTestsMatching "com.serotonin.mango.view.export.CsvWriterTest"
includeTestsMatching "com.serotonin.mango.util.EmailValidatorTest"
includeTestsMatching "com.serotonin.mango.vo.LoggedUserTestsSuite"
}
}
2 changes: 1 addition & 1 deletion src/br/org/scadabr/view/component/AlarmListComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public String generateContent() {
WebContext webContext = WebContextFactory.get();
HttpServletRequest request = webContext.getHttpServletRequest();
List<EventInstance> toViewEvents = new EventService().getPendingEventsAlarmLevelMin(Common
.getUser().getId(), minAlarmLevel, maxListSize, true);
.getUser().getId(), minAlarmLevel, maxListSize);

model.put("nome", "marlon");
model.put("events",toViewEvents);
Expand Down
3 changes: 3 additions & 0 deletions src/br/org/scadabr/web/dwr/UsersProfilesDwr.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import javax.servlet.http.HttpServletRequest;

import com.serotonin.mango.vo.User;
import org.directwebremoting.WebContextFactory;

import br.org.scadabr.api.exception.DAOException;
Expand All @@ -33,6 +34,7 @@
import org.scada_lts.dao.model.ScadaObjectIdentifier;
import org.scada_lts.mango.service.UsersProfileService;
import org.scada_lts.mango.service.ViewService;
import org.scada_lts.web.beans.ApplicationBeans;

public class UsersProfilesDwr {

Expand Down Expand Up @@ -122,6 +124,7 @@ public DwrResponseI18n saveUserAdmin(int id, String name,

try {
usersProfileService.saveUsersProfile(profile);
ApplicationBeans.getLoggedUsersBean().updateUsers(profile);
} catch (DAOException e) {
response.addMessage(new LocalizableMessage(
"userProfiles.validate.nameUnique"));
Expand Down
221 changes: 0 additions & 221 deletions src/com/serotonin/mango/db/dao/EventDao.java

This file was deleted.

32 changes: 32 additions & 0 deletions src/com/serotonin/mango/rt/event/type/AlarmLevelType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.serotonin.mango.rt.event.type;

import com.serotonin.mango.rt.event.AlarmLevels;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public enum AlarmLevelType {

NONE(AlarmLevels.NONE),
INFORMATION(AlarmLevels.INFORMATION),
URGENT(AlarmLevels.URGENT),
CRITICAL(AlarmLevels.CRITICAL),
LIFE_SAFETY(AlarmLevels.LIFE_SAFETY);
private final int code;
AlarmLevelType(int code) {
this.code = code;
}

public int getCode() {
return code;
}

public static List<AlarmLevelType> getAlarmLevels() {
return Stream.of(AlarmLevelType.values()).collect(Collectors.toList());
}

public static List<AlarmLevelType> getAlarmLevelsWithoutNone() {
return Stream.of(AlarmLevelType.values()).filter(a -> a != AlarmLevelType.NONE).collect(Collectors.toList());
}
}
28 changes: 16 additions & 12 deletions src/com/serotonin/mango/vo/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;

import br.org.scadabr.vo.exporter.ZIPProjectManager;
Expand Down Expand Up @@ -51,6 +52,7 @@
import com.serotonin.web.i18n.LocalizableMessage;
import org.scada_lts.dao.UsersProfileDAO;
import org.scada_lts.mango.service.UsersProfileService;
import org.scada_lts.web.beans.ApplicationBeans;

@JsonRemoteEntity
public class User implements SetPointSource, HttpSessionBindingListener,
Expand Down Expand Up @@ -123,18 +125,6 @@ public class User implements SetPointSource, HttpSessionBindingListener,

public User() { }

@Deprecated
public User(int id, String username, String email, String phone, boolean admin, boolean disabled, String homeUrl, long lastLogin) {
this.id = id;
this.username = username;
this.email = email;
this.phone = phone;
this.admin = admin;
this.disabled = disabled;
this.homeUrl = homeUrl;
this.lastLogin = lastLogin;
}

public User(int id, String username, String firstName, String lastName, String email, String phone, boolean admin, boolean disabled, String homeUrl, long lastLogin) {
this.id = id;
this.username = username;
Expand Down Expand Up @@ -231,6 +221,16 @@ public void raiseRecursionFailureEvent() {
throw new ShouldNeverHappenException("");
}

@Override
public void valueBound(HttpSessionBindingEvent event) {
ApplicationBeans.getLoggedUsersBean().addUser(this, event.getSession());
}

@Override
public void valueUnbound(HttpSessionBindingEvent event) {
ApplicationBeans.getLoggedUsersBean().removeUser(this, event.getSession());
}

// Convenience method for JSPs
@JsonIgnore
public boolean isDataSourcePermission() {
Expand Down Expand Up @@ -674,6 +674,10 @@ public int getUserProfile() {

public void resetUserProfile() {
this.userProfile = Common.NEW_ID;
this.dataPointProfilePermissions.clear();
this.dataSourceProfilePermissions.clear();
this.watchListProfilePermissions.clear();
this.viewProfilePermissions.clear();
}

@Override
Expand Down
7 changes: 4 additions & 3 deletions src/com/serotonin/mango/web/dwr/UsersDwr.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import org.scada_lts.mango.service.SystemSettingsService;
import org.scada_lts.mango.service.UserService;
import org.scada_lts.mango.service.UsersProfileService;
import org.scada_lts.web.beans.ApplicationBeans;
import org.scada_lts.web.mvc.api.json.JsonSettingsMisc;

import static com.serotonin.mango.util.LoggingUtils.userInfo;
Expand Down Expand Up @@ -215,10 +216,10 @@ else if (dupUser != null && id != dupUser.getId())
// set permission on all watchlists
}

if (currentUser.getId() == id)
/*if (currentUser.getId() == id)
// Update the user object in session too. Why not?
Common.updateUserInSession(request, user);

Common.updateUserInSession(request, user);*/
ApplicationBeans.getLoggedUsersBean().updateUser(user);
response.addData("userId", user.getId());
}

Expand Down
Loading

0 comments on commit 3fb887a

Please sign in to comment.