Search in sources :

Example 36 with Event

use of org.osgi.service.event.Event in project ddf by codice.

the class PredicateTest method testContextualQuerySpecialMatch.

@Test
public void testContextualQuerySpecialMatch() throws IOException {
    for (String term : Arrays.asList(LEADING_TERM, TRAILING_TERM, EMBEDDED_TERM)) {
        for (Character specialChar : ContextualTokenizer.SPECIAL_CHARACTERS_SET) {
            String phrase = String.format(term, specialChar);
            String metadata = String.format(METADATA_FORMAT, StringEscapeUtils.escapeXml(phrase));
            Predicate predicate = getPredicate("\"" + phrase + "\"");
            Event testEvent = getEvent(metadata);
            assertThat(phrase + " not matched", predicate.matches(testEvent), is(equalTo(true)));
        }
    }
}
Also used : Event(org.osgi.service.event.Event) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate) Test(org.junit.Test)

Example 37 with Event

use of org.osgi.service.event.Event in project ddf by codice.

the class PredicateTest method testContextualQuerySurroundedByWildcards.

@Test
public void testContextualQuerySurroundedByWildcards() throws Exception {
    Predicate predicate = getPredicate("*test*");
    for (String term : Arrays.asList(LEADING_TERM, TRAILING_TERM, EMBEDDED_TERM)) {
        for (Character specialChar : ContextualTokenizer.SPECIAL_CHARACTERS_SET) {
            String phrase = String.format(term, specialChar);
            String metadata = String.format(METADATA_FORMAT, StringEscapeUtils.escapeXml(phrase));
            Event testEvent = getEvent(metadata);
            assertThat(phrase + " not matched", predicate.matches(testEvent), is(equalTo(true)));
        }
    }
}
Also used : Event(org.osgi.service.event.Event) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate) Test(org.junit.Test)

Example 38 with Event

use of org.osgi.service.event.Event in project ddf by codice.

the class ActivityControllerTest method testHandleEventThrowsIllegalArgumentExceptionOnEmptyUserAndSessionId.

/**
     * Test method for {@link ActivityController#handleEvent(org.osgi.service.event.Event)}
     *
     * Verifies that {@code IllegalArgumentException} is thrown when
     * {@code Event}'s {@link ActivityEvent#USER_ID_KEY} and
     * {@link ActivityEvent#SESSION_ID_KEY} properties are empty.
     */
@Test(expected = IllegalArgumentException.class)
public void testHandleEventThrowsIllegalArgumentExceptionOnEmptyUserAndSessionId() {
    testEventProperties.put(ActivityEvent.USER_ID_KEY, "");
    testEventProperties.put(ActivityEvent.SESSION_ID_KEY, "");
    activityController.handleEvent(new Event(ActivityEvent.EVENT_TOPIC, testEventProperties));
}
Also used : ActivityEvent(org.codice.ddf.activities.ActivityEvent) Event(org.osgi.service.event.Event) Test(org.junit.Test)

Example 39 with Event

use of org.osgi.service.event.Event in project ddf by codice.

the class ActivityControllerTest method testHandleEventThrowsIllegalArgumentExceptionOnEmptyMessage.

/**
     * Test method for {@link ActivityController#handleEvent(org.osgi.service.event.Event)}
     *
     * Verifies that {@code IllegalArgumentException} is thrown when
     * {@code Event}'s {@link ActivityEvent#MESSAGE_KEY} property is
     * empty.
     */
@Test(expected = IllegalArgumentException.class)
public void testHandleEventThrowsIllegalArgumentExceptionOnEmptyMessage() {
    testEventProperties.put(ActivityEvent.MESSAGE_KEY, "");
    activityController.handleEvent(new Event(ActivityEvent.EVENT_TOPIC, testEventProperties));
}
Also used : ActivityEvent(org.codice.ddf.activities.ActivityEvent) Event(org.osgi.service.event.Event) Test(org.junit.Test)

Example 40 with Event

use of org.osgi.service.event.Event in project ddf by codice.

the class NotificationController method getPersistedNotifications.

@Listener('/' + Notification.NOTIFICATION_TOPIC_ROOT)
public void getPersistedNotifications(final ServerSession remote, Message message) {
    Subject subject = null;
    try {
        subject = SecurityUtils.getSubject();
    } catch (Exception e) {
        LOGGER.debug("Couldn't grab user subject from Shiro.", e);
    }
    String userId = getUserId(remote, subject);
    if (null == userId) {
        throw new IllegalArgumentException("User ID is null");
    }
    Map<String, Object> data = message.getDataAsMap();
    if (MapUtils.isEmpty(data)) {
        List<Map<String, Object>> notifications = getNotificationsForUser(userId);
        if (CollectionUtils.isNotEmpty(notifications)) {
            queuePersistedMessages(remote, notifications, "/" + Notification.NOTIFICATION_TOPIC_BROADCAST);
        }
    } else {
        String id = UUID.randomUUID().toString().replaceAll("-", "");
        String sessionId = remote.getId();
        Notification notification = new Notification(id, sessionId, (String) data.get(Notification.NOTIFICATION_KEY_APPLICATION), (String) data.get(Notification.NOTIFICATION_KEY_TITLE), (String) data.get(Notification.NOTIFICATION_KEY_MESSAGE), (Long) data.get(Notification.NOTIFICATION_KEY_TIMESTAMP), userId);
        Event event = new Event(Notification.NOTIFICATION_TOPIC_PUBLISH, notification);
        eventAdmin.postEvent(event);
    }
}
Also used : Event(org.osgi.service.event.Event) HashMap(java.util.HashMap) Map(java.util.Map) Subject(org.apache.shiro.subject.Subject) PersistenceException(org.codice.ddf.persistence.PersistenceException) Notification(org.codice.ddf.notifications.Notification) Listener(org.cometd.annotation.Listener)

Aggregations

Event (org.osgi.service.event.Event)142 Test (org.junit.Test)79 HashMap (java.util.HashMap)48 Hashtable (java.util.Hashtable)44 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)23 ContentTypePredicate (ddf.catalog.pubsub.predicate.ContentTypePredicate)20 EventAdmin (org.osgi.service.event.EventAdmin)19 GeospatialPredicate (ddf.catalog.pubsub.predicate.GeospatialPredicate)18 Predicate (ddf.catalog.pubsub.predicate.Predicate)16 ArrayList (java.util.ArrayList)16 ActivityEvent (org.codice.ddf.activities.ActivityEvent)13 EventHandler (org.osgi.service.event.EventHandler)13 SubscriptionFilterVisitor (ddf.catalog.pubsub.internal.SubscriptionFilterVisitor)11 Date (java.util.Date)11 Job (org.apache.sling.event.jobs.Job)9 Map (java.util.Map)8 List (java.util.List)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 JobManager (org.apache.sling.event.jobs.JobManager)7 JobConsumer (org.apache.sling.event.jobs.consumer.JobConsumer)7