Search in sources :

Example 11 with EventTypeMatcher

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;
}
Also used : EventTypeMatcher(com.serotonin.m2m2.rt.event.type.EventTypeMatcher) EmailEventHandlerVO(com.serotonin.m2m2.vo.event.EmailEventHandlerVO) ScriptPermissions(com.infiniteautomation.mango.util.script.ScriptPermissions) MockEventType(com.serotonin.m2m2.rt.event.type.MockEventType)

Example 12 with EventTypeMatcher

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
}
Also used : EventTypeMatcher(com.serotonin.m2m2.rt.event.type.EventTypeMatcher) EmailEventHandlerVO(com.serotonin.m2m2.vo.event.EmailEventHandlerVO)

Example 13 with EventTypeMatcher

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
}
Also used : EventTypeMatcher(com.serotonin.m2m2.rt.event.type.EventTypeMatcher) EmailEventHandlerVO(com.serotonin.m2m2.vo.event.EmailEventHandlerVO)

Example 14 with EventTypeMatcher

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;
}
Also used : EventTypeMatcher(com.serotonin.m2m2.rt.event.type.EventTypeMatcher) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) HashSet(java.util.HashSet)

Example 15 with EventTypeMatcher

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()));
}
Also used : Autowired(org.springframework.beans.factory.annotation.Autowired) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) EventType(com.serotonin.m2m2.rt.event.type.EventType) DaoEventType(com.infiniteautomation.mango.spring.events.DaoEventType) HashSet(java.util.HashSet) EventTypeMatcher(com.serotonin.m2m2.rt.event.type.EventTypeMatcher) Service(org.springframework.stereotype.Service) RoleVO(com.serotonin.m2m2.vo.role.RoleVO) EventHandlerCreatePermission(com.serotonin.m2m2.module.definitions.permissions.EventHandlerCreatePermission) AbstractEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractEventDetectorVO) Caffeine(com.github.benmanes.caffeine.cache.Caffeine) Common(com.serotonin.m2m2.Common) LoadingCache(com.github.benmanes.caffeine.cache.LoadingCache) Set(java.util.Set) EventListener(org.springframework.context.event.EventListener) EventHandlerDao(com.serotonin.m2m2.db.dao.EventHandlerDao) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) PermissionDefinition(com.serotonin.m2m2.module.PermissionDefinition) AbstractEventHandlerVO(com.serotonin.m2m2.vo.event.AbstractEventHandlerVO) DaoEvent(com.infiniteautomation.mango.spring.events.DaoEvent) List(java.util.List) Collections(java.util.Collections) EventTypeMatcher(com.serotonin.m2m2.rt.event.type.EventTypeMatcher) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) AbstractEventHandlerVO(com.serotonin.m2m2.vo.event.AbstractEventHandlerVO)

Aggregations

EventTypeMatcher (com.serotonin.m2m2.rt.event.type.EventTypeMatcher)20 AbstractEventHandlerVO (com.serotonin.m2m2.vo.event.AbstractEventHandlerVO)8 EmailEventHandlerVO (com.serotonin.m2m2.vo.event.EmailEventHandlerVO)8 HashSet (java.util.HashSet)8 DataSourceService (com.infiniteautomation.mango.spring.service.DataSourceService)4 EventHandlerService (com.infiniteautomation.mango.spring.service.EventHandlerService)4 PermissionService (com.infiniteautomation.mango.spring.service.PermissionService)4 ScriptPermissions (com.infiniteautomation.mango.util.script.ScriptPermissions)4 ExtendedJdbcTemplate (com.serotonin.db.spring.ExtendedJdbcTemplate)4 Common (com.serotonin.m2m2.Common)4 DatabaseProxy (com.serotonin.m2m2.db.DatabaseProxy)4 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)4 ProcessEventHandlerDefinition (com.serotonin.m2m2.module.definitions.event.handlers.ProcessEventHandlerDefinition)4 DataSourceEventType (com.serotonin.m2m2.rt.event.type.DataSourceEventType)4 EventType (com.serotonin.m2m2.rt.event.type.EventType)4 MockEventType (com.serotonin.m2m2.rt.event.type.MockEventType)4 RoleVO (com.serotonin.m2m2.vo.role.RoleVO)4 Collections (java.util.Collections)4 List (java.util.List)4 Set (java.util.Set)4