Search in sources :

Example 1 with Feed

use of org.jboss.resteasy.plugins.providers.atom.Feed in project wildfly-camel by wildfly-extras.

the class AtomFeed method getFeed.

@GET
@Produces("application/atom+xml")
public Feed getFeed() throws URISyntaxException {
    Feed feed = new Feed();
    feed.setId(new URI("http://test.com/1"));
    feed.setTitle("WildFly Camel Test Feed");
    feed.setUpdated(new Date());
    Link link = new Link();
    link.setHref(new URI("http://localhost"));
    link.setRel("edit");
    feed.getLinks().add(link);
    feed.getAuthors().add(new Person("WildFly Camel"));
    Entry entry = new Entry();
    entry.setTitle("Hello Kermit");
    Content content = new Content();
    content.setType(MediaType.TEXT_HTML_TYPE);
    content.setText("Greeting Kermit");
    entry.setContent(content);
    feed.getEntries().add(entry);
    return feed;
}
Also used : Entry(org.jboss.resteasy.plugins.providers.atom.Entry) Content(org.jboss.resteasy.plugins.providers.atom.Content) URI(java.net.URI) Person(org.jboss.resteasy.plugins.providers.atom.Person) Date(java.util.Date) Link(org.jboss.resteasy.plugins.providers.atom.Link) Feed(org.jboss.resteasy.plugins.providers.atom.Feed) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with Feed

use of org.jboss.resteasy.plugins.providers.atom.Feed in project candlepin by candlepin.

the class EventAdapterImpl method toFeed.

@Override
public Feed toFeed(List<Event> events, String path) {
    String url = config.getString(ConfigProperties.CANDLEPIN_URL) + path + "/";
    Feed feed = new Feed();
    feed.setUpdated(new Date());
    feed.getAuthors().add(new Person("Red Hat, Inc."));
    try {
        feed.setId(new URI(url));
    } catch (Exception e) {
    // ignore, shouldn't happen
    }
    if (events == null) {
        return feed;
    }
    // Add the friendly message text
    this.addMessageText(events);
    for (Event e : events) {
        Entry entry = new Entry();
        entry.setTitle(e.getTarget().toString() + " " + e.getType().toString());
        entry.setPublished(e.getTimestamp());
        entry.setUpdated(e.getTimestamp());
        entry.getAuthors().add(new Person("Red Hat, Inc."));
        URI eventURI = null;
        try {
            eventURI = new URI(url + e.getId());
        } catch (Exception error) {
        // ignore, shouldn't happen
        }
        entry.setId(eventURI);
        entry.getLinks().add(new Link("alternate", eventURI, MediaType.APPLICATION_JSON_TYPE));
        Content content = new Content();
        content.setType(MediaType.APPLICATION_XML_TYPE);
        content.setJAXBObject(e);
        entry.setContent(content);
        entry.setSummary(e.getMessageText());
        feed.getEntries().add(entry);
    }
    // get modified, if they do then the feed published date could be inaccurate.
    if (events.size() > 0) {
        feed.setUpdated(events.get(0).getTimestamp());
    }
    return feed;
}
Also used : Entry(org.jboss.resteasy.plugins.providers.atom.Entry) Content(org.jboss.resteasy.plugins.providers.atom.Content) Person(org.jboss.resteasy.plugins.providers.atom.Person) URI(java.net.URI) Date(java.util.Date) Link(org.jboss.resteasy.plugins.providers.atom.Link) Feed(org.jboss.resteasy.plugins.providers.atom.Feed)

Example 3 with Feed

use of org.jboss.resteasy.plugins.providers.atom.Feed in project candlepin by candlepin.

the class OwnerResourceTest method ownersAtomFeed.

@Test
public void ownersAtomFeed() {
    Owner owner2 = new Owner("anotherOwner");
    ownerCurator.create(owner2);
    Event e1 = createConsumerCreatedEvent(owner);
    // Make an event from another owner:
    createConsumerCreatedEvent(owner2);
    // Make sure we're acting as the correct owner admin:
    setupPrincipal(owner, Access.ALL);
    securityInterceptor.enable();
    Feed feed = ownerResource.getOwnerAtomFeed(owner.getKey());
    assertEquals(1, feed.getEntries().size());
    Entry entry = feed.getEntries().get(0);
    assertEquals(e1.getTimestamp(), entry.getPublished());
}
Also used : Owner(org.candlepin.model.Owner) Entry(org.jboss.resteasy.plugins.providers.atom.Entry) Event(org.candlepin.audit.Event) Feed(org.jboss.resteasy.plugins.providers.atom.Feed) Test(org.junit.Test)

Example 4 with Feed

use of org.jboss.resteasy.plugins.providers.atom.Feed in project candlepin by candlepin.

the class EventAdapterTest method toFeed.

@Test
public void toFeed() {
    EventAdapter ea = new EventAdapterImpl(new ConfigForTesting(), i18n);
    List<Event> events = new LinkedList<>();
    events.add(mockEvent(Event.Target.CONSUMER, Event.Type.CREATED));
    events.add(mockEvent(Event.Target.ENTITLEMENT, Event.Type.DELETED));
    Feed f = ea.toFeed(events, "/test/path");
    assertNotNull(f);
    assertNotNull(f.getEntries());
    assertFalse(f.getEntries().isEmpty());
    assertEquals(2, f.getEntries().size());
    Entry e = f.getEntries().get(0);
    assertNotNull(e);
    assertNotNull(e.getTitle());
    assertTrue(e.getTitle().contains("CONSUMER"));
    assertTrue(e.getTitle().contains("CREATED"));
    assertTrue(e.getSummary().contains("unit"));
    assertTrue(e.getSummary().contains("created"));
    assertEquals(events.get(0).getTimestamp(), f.getUpdated());
}
Also used : Entry(org.jboss.resteasy.plugins.providers.atom.Entry) LinkedList(java.util.LinkedList) Feed(org.jboss.resteasy.plugins.providers.atom.Feed) Test(org.junit.Test)

Example 5 with Feed

use of org.jboss.resteasy.plugins.providers.atom.Feed in project candlepin by candlepin.

the class EventAdapterTest method nullList.

@Test
public void nullList() {
    EventAdapter ea = new EventAdapterImpl(new ConfigForTesting(), i18n);
    Feed f = ea.toFeed(null, null);
    assertNotNull(f);
    assertNotNull(f.getEntries());
    assertTrue(f.getEntries().isEmpty());
}
Also used : Feed(org.jboss.resteasy.plugins.providers.atom.Feed) Test(org.junit.Test)

Aggregations

Feed (org.jboss.resteasy.plugins.providers.atom.Feed)11 Test (org.junit.Test)6 GET (javax.ws.rs.GET)4 Produces (javax.ws.rs.Produces)4 Event (org.candlepin.audit.Event)4 Entry (org.jboss.resteasy.plugins.providers.atom.Entry)4 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)2 URI (java.net.URI)2 Date (java.util.Date)2 Path (javax.ws.rs.Path)2 CandlepinQuery (org.candlepin.model.CandlepinQuery)2 Owner (org.candlepin.model.Owner)2 Content (org.jboss.resteasy.plugins.providers.atom.Content)2 Link (org.jboss.resteasy.plugins.providers.atom.Link)2 Person (org.jboss.resteasy.plugins.providers.atom.Person)2 LinkedList (java.util.LinkedList)1 Consumer (org.candlepin.model.Consumer)1 DeletedConsumer (org.candlepin.model.DeletedConsumer)1