Search in sources :

Example 1 with PortalEvent

use of org.apereo.portal.events.PortalEvent in project uPortal by Jasig.

the class PortalRawEventsAggregatorImplTest method aggregateRawEventsIncompleteByReturn.

@Test
public void aggregateRawEventsIncompleteByReturn() throws Exception {
    when(transactionOperations.execute(any(TransactionCallback.class))).then(new Answer<EventProcessingResult>() {

        @Override
        public EventProcessingResult answer(InvocationOnMock invocation) throws Throwable {
            final TransactionStatus status = mock(TransactionStatus.class);
            return ((TransactionCallback<EventProcessingResult>) invocation.getArguments()[0]).doInTransaction(status);
        }
    });
    when(clusterLockService.isLockOwner(PortalRawEventsAggregator.AGGREGATION_LOCK_NAME)).thenReturn(true);
    when(portalEventDimensionPopulator.isCheckedDimensions()).thenReturn(true);
    when(eventAggregationManagementDao.getEventAggregatorStatus(ProcessingType.AGGREGATION, true)).thenReturn(eventAggregatorStatus);
    when(portalInfoProvider.getUniqueServerName()).thenReturn("serverName_abcd");
    when(eventAggregatorStatus.getLastEventDate()).thenReturn(new DateTime(1325881376117l));
    when(portalEventDao.aggregatePortalEvents(any(DateTime.class), any(DateTime.class), (int) any(Integer.TYPE), (Function<PortalEvent, Boolean>) any(Function.class))).then(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            return false;
        }
    });
    final EventProcessingResult result = portalEventAggregator.doAggregateRawEvents();
    assertNotNull(result);
    assertEquals(0, result.getProcessed());
    assertEquals(false, result.isComplete());
}
Also used : TransactionCallback(org.springframework.transaction.support.TransactionCallback) PortalEvent(org.apereo.portal.events.PortalEvent) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TransactionStatus(org.springframework.transaction.TransactionStatus) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 2 with PortalEvent

use of org.apereo.portal.events.PortalEvent in project uPortal by Jasig.

the class PortalRawEventsAggregatorImplTest method aggregateRawEventsIncompleteByProcessCount.

@Test
public void aggregateRawEventsIncompleteByProcessCount() throws Exception {
    when(transactionOperations.execute(any(TransactionCallback.class))).then(new Answer<EventProcessingResult>() {

        @Override
        public EventProcessingResult answer(InvocationOnMock invocation) throws Throwable {
            final TransactionStatus status = mock(TransactionStatus.class);
            return ((TransactionCallback<EventProcessingResult>) invocation.getArguments()[0]).doInTransaction(status);
        }
    });
    when(clusterLockService.isLockOwner(PortalRawEventsAggregator.AGGREGATION_LOCK_NAME)).thenReturn(true);
    when(portalEventDimensionPopulator.isCheckedDimensions()).thenReturn(true);
    when(eventAggregationManagementDao.getEventAggregatorStatus(ProcessingType.AGGREGATION, true)).thenReturn(eventAggregatorStatus);
    when(portalInfoProvider.getUniqueServerName()).thenReturn("serverName_abcd");
    when(eventAggregatorStatus.getLastEventDate()).thenReturn(new DateTime(1325881376117l));
    when(portalEventDao.aggregatePortalEvents(any(DateTime.class), any(DateTime.class), (int) any(Integer.TYPE), (Function<PortalEvent, Boolean>) any(Function.class))).then(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            ((Function<PortalEvent, Boolean>) invocation.getArguments()[3]).apply(new MockPortalEvent(this, "serverName", "eventSessionId", person));
            return false;
        }
    });
    when(eventSessionDao.getEventSession(any(PortalEvent.class))).thenReturn(eventSession);
    this.portalEventAggregator.setEventAggregationBatchSize(1);
    final EventProcessingResult result = portalEventAggregator.doAggregateRawEvents();
    assertNotNull(result);
    assertEquals(1, result.getProcessed());
    assertEquals(false, result.isComplete());
    this.portalEventAggregator.setEventAggregationBatchSize(1000);
}
Also used : TransactionCallback(org.springframework.transaction.support.TransactionCallback) PortalEvent(org.apereo.portal.events.PortalEvent) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TransactionStatus(org.springframework.transaction.TransactionStatus) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 3 with PortalEvent

use of org.apereo.portal.events.PortalEvent in project uPortal by Jasig.

the class AnalyticsIncorporationComponent method serializePortletRenderExecutionEvents.

protected String serializePortletRenderExecutionEvents(final Set<PortalEvent> portalEvents) {
    //Filter to include just portlet render events
    final Map<String, PortletRenderExecutionEvent> renderEvents = new HashMap<String, PortletRenderExecutionEvent>();
    for (final PortalEvent portalEvent : portalEvents) {
        if (portalEvent instanceof PortletRenderExecutionEvent) {
            final PortletRenderExecutionEvent portletRenderEvent = (PortletRenderExecutionEvent) portalEvent;
            //Don't write out info for minimized portlets
            if (!WindowState.MINIMIZED.equals(portletRenderEvent.getWindowState())) {
                final IPortletWindowId portletWindowId = portletRenderEvent.getPortletWindowId();
                final String eventKey = portletWindowId != null ? portletWindowId.getStringId() : portletRenderEvent.getFname();
                renderEvents.put(eventKey, portletRenderEvent);
            }
        }
    }
    try {
        return portletEventWriter.writeValueAsString(renderEvents);
    } catch (JsonParseException e) {
        logger.warn("Failed to convert this request's render events to JSON, no portlet level analytics will be included", e);
    } catch (JsonMappingException e) {
        logger.warn("Failed to convert this request's render events to JSON, no portlet level analytics will be included", e);
    } catch (IOException e) {
        logger.warn("Failed to convert this request's render events to JSON, no portlet level analytics will be included", e);
    }
    return "{}";
}
Also used : PortalEvent(org.apereo.portal.events.PortalEvent) HashMap(java.util.HashMap) PortletRenderExecutionEvent(org.apereo.portal.events.PortletRenderExecutionEvent) JsonMappingException(com.fasterxml.jackson.databind.JsonMappingException) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) IPortletWindowId(org.apereo.portal.portlet.om.IPortletWindowId)

Example 4 with PortalEvent

use of org.apereo.portal.events.PortalEvent in project uPortal by Jasig.

the class UserFilteringPortalEventHandler method supports.

@Override
public boolean supports(E event) {
    if (!(event instanceof PortalEvent)) {
        return false;
    }
    //Guest support check
    final IPerson person = event.getPerson();
    if (person != null && !this.supportGuest && person.isGuest()) {
        return false;
    }
    //userName check
    final String userName = event.getUserName();
    if (this.supportedUserNames != null && this.supportedUserNames.contains(userName)) {
        return true;
    }
    //ignored userName check
    if (this.ignoredUserNames != null && this.ignoredUserNames.contains(userName)) {
        return false;
    }
    //ignored userName pattern check
    if (this.ignoredUserNamePatterns != null) {
        for (final Pattern ignoredUserNamePattern : this.ignoredUserNamePatterns) {
            if (ignoredUserNamePattern.matcher(userName).matches()) {
                return false;
            }
        }
    }
    return this.supportedUserNames == null || this.supportedUserNames.isEmpty();
}
Also used : IPerson(org.apereo.portal.security.IPerson) Pattern(java.util.regex.Pattern) PortalEvent(org.apereo.portal.events.PortalEvent)

Example 5 with PortalEvent

use of org.apereo.portal.events.PortalEvent in project uPortal by Jasig.

the class PortalRawEventsAggregatorImplTest method aggregateRawEventsComplete.

@Test
public void aggregateRawEventsComplete() throws Exception {
    when(transactionOperations.execute(any(TransactionCallback.class))).then(new Answer<EventProcessingResult>() {

        @Override
        public EventProcessingResult answer(InvocationOnMock invocation) throws Throwable {
            final TransactionStatus status = mock(TransactionStatus.class);
            return ((TransactionCallback<EventProcessingResult>) invocation.getArguments()[0]).doInTransaction(status);
        }
    });
    when(clusterLockService.isLockOwner(PortalRawEventsAggregator.AGGREGATION_LOCK_NAME)).thenReturn(true);
    when(portalEventDimensionPopulator.isCheckedDimensions()).thenReturn(true);
    when(eventAggregationManagementDao.getEventAggregatorStatus(ProcessingType.AGGREGATION, true)).thenReturn(eventAggregatorStatus);
    when(portalInfoProvider.getUniqueServerName()).thenReturn("serverName_abcd");
    when(eventAggregatorStatus.getLastEventDate()).thenReturn(new DateTime(1325881376117l));
    when(portalEventDao.aggregatePortalEvents(any(DateTime.class), any(DateTime.class), (int) any(Integer.TYPE), (Function<PortalEvent, Boolean>) any(Function.class))).then(new Answer<Boolean>() {

        @Override
        public Boolean answer(InvocationOnMock invocation) throws Throwable {
            return true;
        }
    });
    final EventProcessingResult result = portalEventAggregator.doAggregateRawEvents();
    assertNotNull(result);
    assertEquals(0, result.getProcessed());
    assertEquals(true, result.isComplete());
}
Also used : TransactionCallback(org.springframework.transaction.support.TransactionCallback) PortalEvent(org.apereo.portal.events.PortalEvent) InvocationOnMock(org.mockito.invocation.InvocationOnMock) TransactionStatus(org.springframework.transaction.TransactionStatus) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Aggregations

PortalEvent (org.apereo.portal.events.PortalEvent)8 DateTime (org.joda.time.DateTime)4 Test (org.junit.Test)3 InvocationOnMock (org.mockito.invocation.InvocationOnMock)3 TransactionStatus (org.springframework.transaction.TransactionStatus)3 TransactionCallback (org.springframework.transaction.support.TransactionCallback)3 JsonParseException (com.fasterxml.jackson.core.JsonParseException)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ScrollableResults (org.hibernate.ScrollableResults)2 Session (org.hibernate.Session)2 Pattern (java.util.regex.Pattern)1 EntityManager (javax.persistence.EntityManager)1 PortletRenderExecutionEvent (org.apereo.portal.events.PortletRenderExecutionEvent)1 IPortletWindowId (org.apereo.portal.portlet.om.IPortletWindowId)1 IPerson (org.apereo.portal.security.IPerson)1