use of com.serotonin.m2m2.rt.event.type.EventTypeMatcher in project ma-core-public by infiniteautomation.
the class EmailEventHandlerServiceTest method newVO.
@Override
EmailEventHandlerVO newVO(User user) {
EmailEventHandlerVO vo = (EmailEventHandlerVO) ModuleRegistry.getEventHandlerDefinition(EmailEventHandlerDefinition.TYPE_NAME).baseCreateEventHandlerVO();
vo.setXid(UUID.randomUUID().toString());
vo.setName(UUID.randomUUID().toString());
ScriptPermissions permissions = new ScriptPermissions(Collections.singleton(readRole));
vo.setScriptRoles(permissions);
List<EventTypeMatcher> eventTypes = Collections.singletonList(new EventTypeMatcher(new MockEventType(readRole)));
vo.setEventTypes(eventTypes);
return vo;
}
use of com.serotonin.m2m2.rt.event.type.EventTypeMatcher in project ma-core-public by infiniteautomation.
the class EmailEventHandlerServiceTest method assertVoEqual.
@Override
void assertVoEqual(AbstractEventHandlerVO expected, AbstractEventHandlerVO actual) {
assertEquals(expected.getId(), actual.getId());
assertEquals(expected.getXid(), actual.getXid());
assertEquals(expected.getName(), actual.getName());
assertPermission(expected.getReadPermission(), actual.getReadPermission());
assertPermission(expected.getEditPermission(), actual.getEditPermission());
assertRoles(((EmailEventHandlerVO) expected).getScriptRoles().getRoles(), ((EmailEventHandlerVO) actual).getScriptRoles().getRoles());
List<EventTypeMatcher> actualEventTypes = actual.getEventTypes();
List<EventTypeMatcher> expectedEventTypes = expected.getEventTypes();
assertEquals(expectedEventTypes.size(), actualEventTypes.size());
for (int i = 0; i < expectedEventTypes.size(); i++) {
EventTypeMatcher actualEventMatcher = actualEventTypes.get(i);
EventTypeMatcher expectedEventMatcher = expectedEventTypes.get(i);
assertEquals(expectedEventMatcher.getEventType(), actualEventMatcher.getEventType());
assertEquals(expectedEventMatcher.getEventSubtype(), actualEventMatcher.getEventSubtype());
assertEquals(expectedEventMatcher.getReferenceId1(), actualEventMatcher.getReferenceId1());
assertEquals(expectedEventMatcher.getReferenceId2(), actualEventMatcher.getReferenceId2());
}
// TODO assert remaining
}
use of com.serotonin.m2m2.rt.event.type.EventTypeMatcher in project ma-core-public by infiniteautomation.
the class EmailEventHandlerDaoTest method assertVoEqual.
@Override
void assertVoEqual(EmailEventHandlerVO expected, EmailEventHandlerVO actual) {
assertEquals(expected.getId(), actual.getId());
assertEquals(expected.getXid(), actual.getXid());
assertEquals(expected.getName(), actual.getName());
assertPermission(expected.getReadPermission(), actual.getReadPermission());
assertPermission(expected.getEditPermission(), actual.getEditPermission());
assertRoles(((EmailEventHandlerVO) expected).getScriptRoles().getRoles(), ((EmailEventHandlerVO) actual).getScriptRoles().getRoles());
List<EventTypeMatcher> actualEventTypes = actual.getEventTypes();
List<EventTypeMatcher> expectedEventTypes = expected.getEventTypes();
assertEquals(expectedEventTypes.size(), actualEventTypes.size());
for (int i = 0; i < expectedEventTypes.size(); i++) {
EventTypeMatcher actualEventMatcher = actualEventTypes.get(i);
EventTypeMatcher expectedEventMatcher = expectedEventTypes.get(i);
assertEquals(expectedEventMatcher.getEventType(), actualEventMatcher.getEventType());
assertEquals(expectedEventMatcher.getEventSubtype(), actualEventMatcher.getEventSubtype());
assertEquals(expectedEventMatcher.getReferenceId1(), actualEventMatcher.getReferenceId1());
assertEquals(expectedEventMatcher.getReferenceId2(), actualEventMatcher.getReferenceId2());
}
// TODO assert remaining
}
use of com.serotonin.m2m2.rt.event.type.EventTypeMatcher in project ma-core-public by infiniteautomation.
the class EventHandlerService method commonValidation.
private ProcessResult commonValidation(AbstractEventHandlerVO vo) {
ProcessResult result = super.validate(vo);
// TODO is this true?
// eventTypes are not validated because it assumed they
// must be valid to be created and make it into this list
// Ensure that no 2 are the same
Set<EventTypeMatcher> types = new HashSet<>(vo.getEventTypes());
if (vo.getEventTypes().size() != types.size()) {
// Now find the ones missing from types
for (EventTypeMatcher type : vo.getEventTypes()) {
if (!types.contains(type)) {
result.addContextualMessage("eventTypes", "eventHandlers.validate.duplicateEventTypes", type.getEventType());
}
}
}
return result;
}
use of com.serotonin.m2m2.rt.event.type.EventTypeMatcher in project ma-core-public by infiniteautomation.
the class EventHandlerService method enabledHandlersForType.
public List<AbstractEventHandlerVO> enabledHandlersForType(EventType type) {
EventHandlerKey key = new EventHandlerKey(type.getEventType(), type.getEventSubtype());
List<AbstractEventHandlerVO> results = cache.get(key);
PermissionHolder user = Common.getUser();
return Collections.unmodifiableList(results.stream().filter(eh -> {
boolean hasPermission = permissionService.hasPermission(user, eh.getReadPermission());
List<EventTypeMatcher> types = eh.getEventTypes();
return hasPermission && types.stream().anyMatch(t -> t.matches(type));
}).collect(Collectors.toList()));
}
Aggregations