Skip to content

Commit

Permalink
Merge pull request #1522 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
radek2s authored Feb 1, 2021
2 parents 0b58108 + 6e1bee5 commit c1bbf8f
Show file tree
Hide file tree
Showing 9 changed files with 447 additions and 344 deletions.
23 changes: 23 additions & 0 deletions doc/EventsAPI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,29 @@ paths:
schema:
$ref: '#/components/schemas/EventHandlerVO'
headers: {}
/eventHandler/get/plc/datapoint/{id}:
get:
tags:
- EventHandler API
summary: 'Get Event Handler by DataPoint ID'
description: 'Get Event Handler by Data point ID'
operationId: 'eventHandlerGetByDataPointId'
parameters:
- name: 'id'
in: 'path'
required: true
schema:
type: 'number'
responses:
'200':
description: "Get successful"
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/EventHandlerPlcDTO'
headers: {}
/eventHandler/set/{typeId}/{typeRef1}/{typeRef2}/1:
post:
tags:
Expand Down
144 changes: 37 additions & 107 deletions scadalts-ui/src/store/alarms/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,31 @@ const storeAlarmsNotifications = {
},

//Event Handlers
getPlcEventHandlers({ dispatch }) {
return dispatch('requestGet', '/eventHandler/getAllPlc');
_getPlcEventHandlerById({ dispatch }, eventHandlerId) {
return dispatch('requestGet', `/eventHandler/get/id/${eventHandlerId}`);
},

getPlcEventHandlerById({ dispatch }, eventHandlerId) {
return dispatch('requestGet', `/eventHandler/get/id/${eventHandlerId}`);
getPlcDataPointConfiguration({ dispatch }, datapointId) {
return dispatch('requestGet', `/eventHandler/get/plc/datapoint/${datapointId}`);
},

deleteEventHandler({ dispatch }, eventHandlerId) {
return dispatch('requestDelete', `/eventHandler/delete/id/${eventHandlerId}`);
},

async updateEventHandlerV2({ dispatch }, payload) {
let eventHandler = await dispatch('_getPlcEventHandlerById', payload.id);
if (!!eventHandler) {
eventHandler.activeRecipients = payload.recipients;
return dispatch('requestPut', {
url: `/eventHandler/update/1/${payload.eventTypeRef1}/${payload.eventTypeRef2}`,
data: eventHandler,
});
} else {
return null;
}
},

//Mailing Lists
getAllMailingLists({ dispatch }) {
return dispatch('requestGet', '/mailingList/getAll');
Expand All @@ -70,73 +83,15 @@ const storeAlarmsNotifications = {
deleteEventDetector({ dispatch }, payload) {
return dispatch(
'requestDelete',
`/eventDetector/delete/${payload.dpId}/${payload.edId}`,
);
},

deleteMailingListFromEventHandler(context, payload) {
payload.eventHandler.activeRecipients = payload.eventHandler.activeRecipients.filter(
(e) => {
return e.referenceId !== payload.activeMailingList;
},
`/eventDetector/delete/${payload.datapointId}/${payload.pointEventDetectorId}`,
);
return payload.eventHandler;
},

addMailingListToEventHandler(context, payload) {
if (!payload.eventHandler.activeRecipients) {
payload.eventHandler.activeRecipients = [];
}
let mailingList = {
recipientType: 1,
referenceId: payload.activeMailingList,
referenceAddress: null,
};
payload.eventHandler.activeRecipients.push(mailingList);
console.log(payload.eventHandler);
return payload.eventHandler;
},

async updateEventHandler({ dispatch }, payload) {
let eventHandler = await dispatch('getPlcEventHandlerById', payload.ehId);

if(eventHandler.handlerType !== payload.handlerType) {
let createData = {
datapointId: payload.typeRef1,
mailingListId: payload.activeMailingList,
handlerType: payload.handlerType,
};
return await dispatch('createEventHandler', createData);
}

if (payload.method === 'add') {
eventHandler = await dispatch('addMailingListToEventHandler', {
eventHandler: eventHandler,
activeMailingList: payload.activeMailingList,
});
} else if (payload.method === 'delete') {
eventHandler = await dispatch('deleteMailingListFromEventHandler', {
eventHandler: eventHandler,
activeMailingList: payload.activeMailingList,
});
}

if (eventHandler.activeRecipients.length === 0) {
let ehStatus = await dispatch('deleteEventHandler', eventHandler.id);
return ehStatus;
} else {
return dispatch('requestPut', {
url: `/eventHandler/update/1/${payload.typeRef1}/${payload.typeRef2}`,
data: eventHandler,
});
}
},

async createEventHandler({ state, dispatch }, payload) {
let pedId = await dispatch('createPointEventDetector', payload.datapointId);
let edId = pedId.id;
let dpId = payload.datapointId;
let mlId = payload.mailingListId;
let mlId = payload.mailingListId[0];

let requestData = JSON.parse(JSON.stringify(state.ehTemplate));
let type = payload.handlerType === 2 ? 'mail' : 'sms';
Expand All @@ -151,6 +106,13 @@ const storeAlarmsNotifications = {
referenceAddress: null,
},
];
if (payload.dual) {
recipientList.push({
recipientType: 1,
referenceId: payload.mailingListId[1],
referenceAddress: null,
});
}

requestData.activeRecipients = recipientList;
let eventHandler;
Expand All @@ -163,50 +125,18 @@ const storeAlarmsNotifications = {
} catch (error) {
throw 'POST request failed!';
}
return { edId, ehId: eventHandler.id };
let response = {
eventTypeId: 1,
eventTypeRef1: dpId,
eventTypeRef2: edId,
id: eventHandler.id,
xid: eventHandler.xid,
alias: eventHandler.alias,
handlerType: eventHandler.handlerType,
recipients: eventHandler.activeRecipients,
};
return response;
},

async createDualEventHandler({state, dispatch}, payload) {
let pedId = await dispatch('createPointEventDetector', payload.datapointId);
let edId = pedId.id;
let dpId = payload.datapointId;
let mlId = payload.mailingListId;

let requestDataMail = JSON.parse(JSON.stringify(state.ehTemplate));
let requestDataSms = JSON.parse(JSON.stringify(state.ehTemplate));

requestDataMail.xid = 'EH_' + requestDataMail.xid + `_mail_${dpId}_${edId}_${mlId}`;
requestDataMail.alias = requestDataMail.alias + `_mail_${dpId}_${edId}_${mlId}`;

requestDataSms.xid = 'EH_' + requestDataSms.xid + `_sms_${dpId}_${edId}_${mlId}`;
requestDataSms.alias = requestDataSms.alias + `_sms_${dpId}_${edId}_${mlId}`;

let recipientList = [
{
recipientType: 1,
referenceId: mlId,
referenceAddress: null,
},
];

requestDataMail.activeRecipients = recipientList;
requestDataSms.activeRecipients = recipientList;
let eventHandler;

try {
eventHandler = await dispatch('requestPost', {
url: `/eventHandler/set/1/${dpId}/${edId}/2`,
data: requestDataMail,
});
eventHandler = await dispatch('requestPost', {
url: `/eventHandler/set/1/${dpId}/${edId}/5`,
data: requestDataSms,
});
} catch (error) {
throw 'POST request failed!';
}
return { edId, ehId: eventHandler.id };
}
},

getters: {},
Expand Down
7 changes: 3 additions & 4 deletions scadalts-ui/src/views/AlarmNotifications/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ New component for preparing a Notification Configuration that allow Scada-LTS us

- Create a mailing list and assign users to it.
_(if you want to receive notification about Events that was taking place druring inactive period select **Collect inactive msg** and set up **cron** pattern for example like this one "0 */1 * \* \* ?" that will try to send past emails every one minute)_

- Create **alarm** ( AL )_ or **warning** ( ST )_ **BINARY** datapoints that will handle information about specific event.
_\*(it could be any name of data point but must contain this uppercase expresion AL|ST with spaces around them. For example "Test AL Datapoint" or "Point-0 ST ". Underscores are not allowed - here are examples that are not valid: "Test_AL\_", "DP ST" or "Point-0_AL")_

Expand All @@ -28,13 +27,13 @@ New component for preparing a Notification Configuration that allow Scada-LTS us
- In EventHandlers page check that valid Event Handlers has been created.

### Important notes

- It works only for BINARY data points. (Other types are not suppeorted)
- When event detector exisit the new one Event Handler tries to attach to it.
- Event detector templates works only when event detector for data ponit do not exists.
- Scada use Mail2SMS function. It does not send pure SMS but Mail formatted as SMS.
It requires addtional SMS Gateway Server that will handle and proceed text message.
Server addess can be changed using System Settings page.

It requires addtional SMS Gateway Server that will handle and proceed text message.
Server addess can be changed using System Settings page.

## Known bugs

Expand Down
Loading

0 comments on commit c1bbf8f

Please sign in to comment.