Skip to content

Commit

Permalink
Merge pull request #1525 from SCADA-LTS/bug/#1517_notification_list_p…
Browse files Browse the repository at this point in the history
…lc_fix

Bug/#1517 notification list plc fix
  • Loading branch information
Limraj authored Feb 1, 2021
2 parents c1bbf8f + 3ac63b8 commit 0c1fb27
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 94 deletions.
182 changes: 101 additions & 81 deletions scadalts-ui/src/views/AlarmNotifications/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -282,80 +282,87 @@ export default {
* If there is any change (config !== active) take steps to delete
* or update that handler.
*/
async updateHandler(id, config, recipientLists, type) {
let eventHandler = this.getEventHandler(config, type);
if (!!eventHandler) {
let requestChange = [];
recipientLists.forEach((m) => {
if (m.config !== m.active) {
requestChange.push(m.mlId);
if (m.active) {
// Add Mailing List to recipients list
eventHandler.recipients.push({
recipientType: 1,
referenceAddress: null,
referenceId: m.mlId,
});
} else {
// Remove Mailing List from recipients list
eventHandler.recipients = eventHandler.recipients.filter((e) => {
return e.referenceId !== m.mlId;
});
updateHandler(id, config, recipientLists, type) {
return new Promise(async (resolve) => {
let eventHandler = this.getEventHandler(config, type);
if (!!eventHandler) {
let requestChange = [];
recipientLists.forEach((m) => {
if (m.config !== m.active) {
requestChange.push(m.mlId);
if (m.active) {
// Add Mailing List to recipients list
eventHandler.recipients.push({
recipientType: 1,
referenceAddress: null,
referenceId: m.mlId,
});
} else {
// Remove Mailing List from recipients list
eventHandler.recipients = eventHandler.recipients.filter((e) => {
return e.referenceId !== m.mlId;
});
}
}
}
});
});
if (requestChange.length !== 0) {
if (eventHandler.recipients.length === 0) {
await this.$store.dispatch('deleteEventHandler', eventHandler.id);
config = config.filter((e) => {
return e.id !== eventHandler.id;
});
if (config.length === 0) {
this.$store.dispatch('deleteEventDetector', {
datapointId: id,
pointEventDetectorId: eventHandler.eventTypeRef2,
if (requestChange.length !== 0) {
if (eventHandler.recipients.length === 0) {
await this.$store.dispatch('deleteEventHandler', eventHandler.id);
config = config.filter((e) => {
return e.id !== eventHandler.id;
});
}
this.saveDatapoint(id, config);
} else {
let resp = await this.$store.dispatch('updateEventHandlerV2', eventHandler);
if (!!resp) {
let index = config.findIndex((x) => x.id === id);
config[index] = eventHandler;
this.saveDatapoint(id, config);
if (config.length === 0) {
this.$store.dispatch('deleteEventDetector', {
datapointId: id,
pointEventDetectorId: eventHandler.eventTypeRef2,
});
}
this.saveDatapoint(id, config, type);
resolve(config);
} else {
let resp1 = await this.$store.dispatch(
'createEventHandler',
this.createEventHandlerData(id, requestChange, type, false),
);
config.push(resp1);
this.saveDatapoint(id, config);
let resp = await this.$store.dispatch('updateEventHandlerV2', eventHandler);
if (!!resp) {
let index = config.findIndex((x) => x.id === id);
config[index] = eventHandler;
this.saveDatapoint(id, config, type);
resolve(config);
} else {
let resp1 = await this.$store.dispatch(
'createEventHandler',
this.createEventHandlerData(id, requestChange, type, false),
);
config.push(resp1);
this.saveDatapoint(id, config, type);
resolve(config);
}
}
}
}
} else {
let creationRequests = [];
recipientLists.forEach((m) => {
if (m.config !== m.active) {
creationRequests.push(m.mlId);
}
});
} else {
let creationRequests = [];
recipientLists.forEach((m) => {
if (m.config !== m.active) {
creationRequests.push(m.mlId);
}
});
if (creationRequests.length !== 0) {
let resp = await this.$store.dispatch(
'createEventHandler',
this.createEventHandlerData(
id,
creationRequests,
type,
creationRequests.length === 2,
),
);
config.push(resp);
this.saveDatapoint(id, config);
if (creationRequests.length !== 0) {
let resp = await this.$store.dispatch(
'createEventHandler',
this.createEventHandlerData(
id,
creationRequests,
type,
creationRequests.length === 2,
),
);
config.push(resp);
this.saveDatapoint(id, config, type);
resolve(config);
}
}
}
resolve("nochange");
})
},
/**
Expand Down Expand Up @@ -383,17 +390,25 @@ export default {
* Save PLC Notification configuration. This method is invoked after
* clicking Save button by User on the UI. Save data to database.
*/
saveConfiguration() {
async saveConfiguration() {
if (this.modified.length > 0) {
this.modified.forEach((change) => {
this.updateHandler(
change.id,
change.configuration,
change.mail,
for(let i = 0; i< this.modified.length; i++) {
let x = await this.updateHandler(
this.modified[i].id,
this.modified[i].configuration,
this.modified[i].mail,
this.TYPE_MAIL,
);
this.updateHandler(change.id, change.configuration, change.sms, this.TYPE_SMS);
});
if(x !== "nochange") {
this.modified[i].configuration = x;
}
await this.updateHandler(
this.modified[i].id,
this.modified[i].configuration,
this.modified[i].sms,
this.TYPE_SMS
);
}
this.modified = [];
if (this.isError) {
Expand All @@ -411,22 +426,27 @@ export default {
* Save DataPoint
* @param {number} id - DataPoint ID number
* @param {object} config - DataPoint EventHandler configuration
* @param {number} type - Type of EventHandler (SMS or Mail)
*
* Save specific data point after change. Add EventHandler configuration
* and update the UI checkbox status.
*/
saveDatapoint(id, config) {
saveDatapoint(id, config, type) {
this.items.forEach((item) => {
if (!!item.children) {
item.children.forEach((datapoint) => {
if (datapoint.id === id) {
datapoint.configuration = config;
datapoint.mail.forEach((mail) => {
mail.config = mail.active;
});
datapoint.sms.forEach((sms) => {
sms.config = sms.active;
});
if(type === this.TYPE_MAIL) {
datapoint.mail.forEach((mail) => {
mail.config = mail.active;
});
}
if (type === this.TYPE_SMS) {
datapoint.sms.forEach((sms) => {
sms.config = sms.active;
});
}
}
});
}
Expand Down
17 changes: 4 additions & 13 deletions src/org/scada_lts/web/mvc/api/EventDetectorAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* Controller for EventDetector
Expand All @@ -34,7 +34,6 @@
public class EventDetectorAPI {

private static final Log LOG = LogFactory.getLog(EventDetectorAPI.class);
private static AtomicInteger atomicInteger = new AtomicInteger(0);

@Resource
private DataPointService dataPointService;
Expand Down Expand Up @@ -151,15 +150,7 @@ private JsonPointEventDetector createEventDetector(DataPointVO dataPointVO, Poin
}
dataPointVO.getEventDetectors().add(pointEventDetectorVO);
dataPointService.saveEventDetectors(dataPointVO);
if(atomicInteger.getAndDecrement() == 0) {
try {
Common.ctx.getRuntimeManager().saveDataPoint(dataPointVO);
} finally {
atomicInteger.set(0);
}
}


Common.ctx.getRuntimeManager().saveDataPoint(dataPointVO);
int pedID = dataPointService.getDetectorId(pointEventDetectorVO.getXid(), dataPointVO.getId());
return new JsonPointEventDetector(pedID, pointEventDetectorVO.getXid(), pointEventDetectorVO.getAlias());
}
Expand Down

0 comments on commit 0c1fb27

Please sign in to comment.