use of com.serotonin.m2m2.vo.mailingList.MailingList in project ma-modules-public by infiniteautomation.
the class M2MRecipientListEntryBean method createEmailRecipient.
public EmailRecipient createEmailRecipient() {
switch(recipientType) {
case EmailRecipient.TYPE_MAILING_LIST:
MailingList ml = new MailingList();
ml.setId(referenceId);
return ml;
case EmailRecipient.TYPE_USER:
UserEntry u = new UserEntry();
u.setUserId(referenceId);
return u;
case EmailRecipient.TYPE_ADDRESS:
AddressEntry a = new AddressEntry();
a.setAddress(referenceAddress);
return a;
}
throw new ShouldNeverHappenException("Unknown email recipient type: " + recipientType);
}
use of com.serotonin.m2m2.vo.mailingList.MailingList in project ma-modules-public by infiniteautomation.
the class MailingListRestController method get.
@ApiOperation(value = "Get Mailing List by XID", notes = "Returns a Mailing List")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv" }, value = "/{xid}")
public ResponseEntity<MailingListModel> get(@ApiParam(value = "Valid mailing list xid", required = true, allowMultiple = false) @PathVariable String xid, HttpServletRequest request) {
RestProcessResult<MailingListModel> result = new RestProcessResult<MailingListModel>(HttpStatus.OK);
this.checkUser(request, result);
if (result.isOk()) {
MailingList list = this.dao.getMailingList(xid);
if (list != null) {
MailingListModel model = new MailingListModel(list);
return result.createResponseEntity(model);
} else {
result.addRestMessage(getDoesNotExistMessage());
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.mailingList.MailingList in project ma-modules-public by infiniteautomation.
the class MailingListRestController method getAll.
@ApiOperation(value = "Get Mailing List", notes = "Returns all Mailing Lists, eventually will be RQL endpoint")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv" })
public ResponseEntity<List<MailingListModel>> getAll(HttpServletRequest request) {
RestProcessResult<List<MailingListModel>> result = new RestProcessResult<List<MailingListModel>>(HttpStatus.OK);
this.checkUser(request, result);
if (result.isOk()) {
List<MailingList> lists = this.dao.getMailingLists();
if (lists != null) {
List<MailingListModel> models = new ArrayList<MailingListModel>();
for (MailingList list : lists) {
models.add(new MailingListModel(list));
}
return result.createResponseEntity(models);
} else {
result.addRestMessage(getDoesNotExistMessage());
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.vo.mailingList.MailingList in project ma-core-public by infiniteautomation.
the class EventManagerImpl method raiseEvent.
//
//
// Basic event management.
//
/**
* Raise Event
* @param type
* @param time
* @param rtnApplicable - does this event return to normal?
* @param alarmLevel
* @param message
* @param context
*/
public void raiseEvent(EventType type, long time, boolean rtnApplicable, int alarmLevel, TranslatableMessage message, Map<String, Object> context) {
if (state != RUNNING)
return;
if (alarmLevel == AlarmLevels.IGNORE)
return;
// Check if there is an event for this type already active.
EventInstance dup = get(type);
if (dup != null) {
// Check the duplicate handling.
boolean discard = canDiscard(type, message);
if (discard)
return;
// Otherwise we just continue...
} else if (!rtnApplicable) {
// Check if we've already seen this type recently.
boolean recent = isRecent(type, message);
if (recent)
return;
}
// Determine if the event should be suppressed.
TranslatableMessage autoAckMessage = null;
for (EventManagerListenerDefinition l : listeners) {
autoAckMessage = l.autoAckEventWithMessage(type);
if (autoAckMessage != null)
break;
}
EventInstance evt = new EventInstance(type, time, rtnApplicable, alarmLevel, message, context);
if (autoAckMessage == null)
setHandlers(evt);
// Check to see if we are Not Logging these
if (alarmLevel != AlarmLevels.DO_NOT_LOG) {
eventDao.saveEvent(evt);
}
// Create user alarm records for all applicable users
List<Integer> eventUserIds = new ArrayList<Integer>();
Set<String> emailUsers = new HashSet<String>();
for (User user : userDao.getActiveUsers()) {
// user should be skipped.
if (type.excludeUser(user))
continue;
if (Permissions.hasEventTypePermission(user, type)) {
eventUserIds.add(user.getId());
if (user.getReceiveAlarmEmails() > AlarmLevels.IGNORE && alarmLevel >= user.getReceiveAlarmEmails() && !StringUtils.isEmpty(user.getEmail()))
emailUsers.add(user.getEmail());
// Notify All User Event Listeners of the new event
if ((alarmLevel != AlarmLevels.DO_NOT_LOG) && (!evt.getEventType().getEventType().equals(EventType.EventTypeNames.AUDIT))) {
for (UserEventListener l : this.userEventListeners) {
if (l.getUserId() == user.getId()) {
Common.backgroundProcessing.addWorkItem(new EventNotifyWorkItem(user, l, evt, true, false, false, false));
}
}
// Add to the UserEventCache if the user has recently accessed their events
this.userEventCache.addEvent(user.getId(), evt);
}
}
}
DateTime now = new DateTime(Common.timer.currentTimeMillis());
for (MailingList ml : MailingListDao.instance.getAlarmMailingLists(alarmLevel)) {
ml.appendAddresses(emailUsers, now);
}
// No Audit or Do Not Log events are User Events
if ((eventUserIds.size() > 0) && (alarmLevel != AlarmLevels.DO_NOT_LOG) && (!evt.getEventType().getEventType().equals(EventType.EventTypeNames.AUDIT))) {
eventDao.insertUserEvents(evt.getId(), eventUserIds, true);
if (autoAckMessage == null)
lastAlarmTimestamp = Common.timer.currentTimeMillis();
}
if (evt.isRtnApplicable()) {
activeEventsLock.writeLock().lock();
try {
activeEvents.add(evt);
} finally {
activeEventsLock.writeLock().unlock();
}
} else if (evt.getEventType().isRateLimited()) {
recentEventsLock.writeLock().lock();
try {
recentEvents.add(evt);
} finally {
recentEventsLock.writeLock().unlock();
}
}
if ((autoAckMessage != null) && (alarmLevel != AlarmLevels.DO_NOT_LOG) && (!evt.getEventType().getEventType().equals(EventType.EventTypeNames.AUDIT)))
this.acknowledgeEvent(evt, time, null, autoAckMessage);
else {
if (evt.isRtnApplicable()) {
if (alarmLevel > highestActiveAlarmLevel) {
int oldValue = highestActiveAlarmLevel;
highestActiveAlarmLevel = alarmLevel;
SystemEventType.raiseEvent(new SystemEventType(SystemEventType.TYPE_MAX_ALARM_LEVEL_CHANGED), time, false, getAlarmLevelChangeMessage("event.alarmMaxIncreased", oldValue));
}
}
// Call raiseEvent handlers.
handleRaiseEvent(evt, emailUsers);
if (log.isDebugEnabled())
log.trace("Event raised: type=" + type + ", message=" + message.translate(Common.getTranslations()));
}
}
use of com.serotonin.m2m2.vo.mailingList.MailingList in project ma-core-public by infiniteautomation.
the class EmailRecipientModel method createBean.
/**
* Create a bean from a model
* @param model
* @return
*/
public static RecipientListEntryBean createBean(EmailRecipientModel<?> model) {
EmailRecipient r = model.getData();
RecipientListEntryBean bean = new RecipientListEntryBean();
bean.setRecipientType(r.getRecipientType());
switch(r.getRecipientType()) {
case EmailRecipient.TYPE_ADDRESS:
bean.setReferenceAddress(r.getReferenceAddress());
break;
case EmailRecipient.TYPE_MAILING_LIST:
// This only comes back with an XID from the page
MailingList list = MailingListDao.instance.getMailingList(((MailingList) r).getXid());
if (list != null)
bean.setReferenceId(list.getId());
break;
case EmailRecipient.TYPE_USER:
User u = UserDao.instance.getUser(((UserEntry) r).getUserId());
if (u != null)
bean.setReferenceId(u.getId());
break;
}
return bean;
}
Aggregations