Java Code Examples for com.rometools.rome.feed.atom.Feed#getEntries()

The following examples show how to use com.rometools.rome.feed.atom.Feed#getEntries() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AtomFeedHttpMessageConverterTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@Test
public void read() throws IOException {
	InputStream is = getClass().getResourceAsStream("atom.xml");
	MockHttpInputMessage inputMessage = new MockHttpInputMessage(is);
	inputMessage.getHeaders().setContentType(new MediaType("application", "atom+xml", StandardCharsets.UTF_8));
	Feed result = converter.read(Feed.class, inputMessage);
	assertEquals("title", result.getTitle());
	assertEquals("subtitle", result.getSubtitle().getValue());
	List<?> entries = result.getEntries();
	assertEquals(2, entries.size());

	Entry entry1 = (Entry) entries.get(0);
	assertEquals("id1", entry1.getId());
	assertEquals("title1", entry1.getTitle());

	Entry entry2 = (Entry) entries.get(1);
	assertEquals("id2", entry2.getId());
	assertEquals("title2", entry2.getTitle());
}
 
Example 2
Source File: AtomFeedHttpMessageConverterTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Test
public void read() throws IOException {
	InputStream is = getClass().getResourceAsStream("atom.xml");
	MockHttpInputMessage inputMessage = new MockHttpInputMessage(is);
	inputMessage.getHeaders().setContentType(new MediaType("application", "atom+xml", StandardCharsets.UTF_8));
	Feed result = converter.read(Feed.class, inputMessage);
	assertEquals("title", result.getTitle());
	assertEquals("subtitle", result.getSubtitle().getValue());
	List<?> entries = result.getEntries();
	assertEquals(2, entries.size());

	Entry entry1 = (Entry) entries.get(0);
	assertEquals("id1", entry1.getId());
	assertEquals("title1", entry1.getTitle());

	Entry entry2 = (Entry) entries.get(1);
	assertEquals("id2", entry2.getId());
	assertEquals("title2", entry2.getTitle());
}
 
Example 3
Source File: AtomClientTest.java    From microservice-atom with Apache License 2.0 6 votes vote down vote up
@Test
public void feedReturnsNewlyCreatedOrder() {
	Order order = new Order();
	order.setCustomer(customerRepository.findAll().iterator().next());
	orderRepository.save(order);
	Feed feed = retrieveFeed();
	boolean foundLinkToCreatedOrder = false;
	List<Entry> entries = feed.getEntries();
	for (Entry entry : entries) {
		for (Content content : entry.getContents()) {
			if (content.getSrc().contains(Long.toString(order.getId()))) {
				foundLinkToCreatedOrder = true;
			}
		}
	}
	assertTrue(foundLinkToCreatedOrder);
}
 
Example 4
Source File: AtomFeedHttpMessageConverterTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void read() throws IOException {
	InputStream is = getClass().getResourceAsStream("atom.xml");
	MockHttpInputMessage inputMessage = new MockHttpInputMessage(is);
	inputMessage.getHeaders().setContentType(new MediaType("application", "atom+xml", utf8));
	Feed result = converter.read(Feed.class, inputMessage);
	assertEquals("title", result.getTitle());
	assertEquals("subtitle", result.getSubtitle().getValue());
	List<?> entries = result.getEntries();
	assertEquals(2, entries.size());

	Entry entry1 = (Entry) entries.get(0);
	assertEquals("id1", entry1.getId());
	assertEquals("title1", entry1.getTitle());

	Entry entry2 = (Entry) entries.get(1);
	assertEquals("id2", entry2.getId());
	assertEquals("title2", entry2.getTitle());
}
 
Example 5
Source File: InvoicePoller.java    From microservice-atom with Apache License 2.0 5 votes vote down vote up
public void pollInternal() {
	HttpHeaders requestHeaders = new HttpHeaders();
	if (lastModified != null) {
		requestHeaders.set(HttpHeaders.IF_MODIFIED_SINCE, DateUtils.formatDate(lastModified));
	}
	HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
	ResponseEntity<Feed> response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, Feed.class);

	if (response.getStatusCode() != HttpStatus.NOT_MODIFIED) {
		log.trace("data has been modified");
		Feed feed = response.getBody();
		for (Entry entry : feed.getEntries()) {
			if ((lastModified == null) || (entry.getUpdated().after(lastModified))) {
				Invoice invoice = restTemplate
						.getForEntity(entry.getContents().get(0).getSrc(), Invoice.class).getBody();
				log.trace("saving invoice {}", invoice.getId());
				invoiceService.generateInvoice(invoice);
			}
		}
		if (response.getHeaders().getFirst(HttpHeaders.LAST_MODIFIED) != null) {
			lastModified = DateUtils.parseDate(response.getHeaders().getFirst(HttpHeaders.LAST_MODIFIED));
			log.trace("Last-Modified header {}", lastModified);
		}
	} else {
		log.trace("no new data");
	}
}
 
Example 6
Source File: ShippingPoller.java    From microservice-atom with Apache License 2.0 5 votes vote down vote up
public void pollInternal() {
	HttpHeaders requestHeaders = new HttpHeaders();
	if (lastModified != null) {
		requestHeaders.set(HttpHeaders.IF_MODIFIED_SINCE, DateUtils.formatDate(lastModified));
	}
	HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
	ResponseEntity<Feed> response = restTemplate.exchange(url, HttpMethod.GET, requestEntity, Feed.class);

	if (response.getStatusCode() != HttpStatus.NOT_MODIFIED) {
		log.trace("data has been modified");
		Feed feed = response.getBody();
		for (Entry entry : feed.getEntries()) {
			if ((lastModified == null) || (entry.getUpdated().after(lastModified))) {
				Shipment shipping = restTemplate
						.getForEntity(entry.getContents().get(0).getSrc(), Shipment.class).getBody();
				log.trace("saving shipping {}", shipping.getId());
				shipmentService.ship(shipping);
			}
		}
		if (response.getHeaders().getFirst("Last-Modified") != null) {
			lastModified = DateUtils.parseDate(response.getHeaders().getFirst(HttpHeaders.LAST_MODIFIED));
			log.trace("Last-Modified header {}", lastModified);
		}
	} else {
		log.trace("no new data");
	}
}
 
Example 7
Source File: Atom03Generator.java    From rome with Apache License 2.0 5 votes vote down vote up
protected void addEntries(final Feed feed, final Element parent) throws FeedException {
    final List<Entry> entries = feed.getEntries();
    for (final Entry entry : entries) {
        addEntry(entry, parent);
    }
    checkEntriesConstraints(parent);
}
 
Example 8
Source File: Atom10Generator.java    From rome with Apache License 2.0 5 votes vote down vote up
protected void addEntries(final Feed feed, final Element parent) throws FeedException {
    final List<Entry> items = feed.getEntries();
    for (final Entry entry : items) {
        addEntry(entry, parent);
    }
    checkEntriesConstraints(parent);
}
 
Example 9
Source File: FileBasedCollection.java    From rome with Apache License 2.0 5 votes vote down vote up
private Entry findEntry(final String id, final Feed feed) {
    for (final Entry entry : feed.getEntries()) {
        if (id.equals(entry.getId())) {
            return entry;
        }
    }
    return null;
}
 
Example 10
Source File: CreditAgencyPoller.java    From ddd-with-spring with Apache License 2.0 4 votes vote down vote up
@Scheduled(fixedDelay = 30000)
public void poll() {

	HttpHeaders requestHeaders = new HttpHeaders();
	if (lastModified != null) {
		requestHeaders.set("If-Modified-Since", DateUtils.formatDate(lastModified));
	}
	HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
	log.info("Polling Credit Agency for new ratings");

	ResponseEntity<Feed> response = restTemplate.exchange(creditAgencyFeed, HttpMethod.GET, requestEntity, Feed.class);

	if (response.getStatusCode() != HttpStatus.NOT_MODIFIED) {
		Feed feed = response.getBody();
		Date lastUpdateInFeed = null;
		ObjectMapper mapper = new ObjectMapper();
		for (Entry entry : feed.getEntries()) {
			String ratingAsJson = entry.getSummary().getValue();
			if ((lastModified == null) || (entry.getUpdated().after(lastModified))) {
				log.info(entry.getTitle() + " is new, processing");
				try {
					AgencyRating agencyRating = mapper.readValue(ratingAsJson, AgencyRating.class);
					scoringApplicationService.scoreAgencyResult(agencyRating.getFirstName(),
																	agencyRating.getLastName(),
																agencyRating.getStreet(),
																agencyRating.getPostCode(),
																agencyRating.getCity(),
																agencyRating.getPoints());
					lastUpdateInFeed = entry.getUpdated();
				} catch (IOException e) {
					//we should handle this exception more properly
					e.printStackTrace();
				}

			}
		}
		if (response.getHeaders().getFirst("Last-Modified") != null) {
			lastModified = DateUtils.parseDate(response.getHeaders().getFirst("Last-Modified"));
			log.info("LastModified header {}", lastModified);
		} else {
			if (lastUpdateInFeed != null) {
				lastModified = lastUpdateInFeed;
				log.info("Last in feed {}", lastModified);
			}

		}
	}
}
 
Example 11
Source File: CreditDecisionPoller.java    From event-driven-spring-boot with Apache License 2.0 4 votes vote down vote up
@Scheduled(fixedDelay = 15000)
public void poll() {

	HttpHeaders requestHeaders = new HttpHeaders();
	if (lastModified != null) {
		requestHeaders.set("If-Modified-Since", DateUtils.formatDate(lastModified));
	}
	HttpEntity<?> requestEntity = new HttpEntity(requestHeaders);
	ResponseEntity<Feed> response = restTemplate.exchange(creditDecisionFeed, HttpMethod.GET, requestEntity, Feed.class);

	if (response.getStatusCode() != HttpStatus.NOT_MODIFIED) {
		Feed feed = response.getBody();
		Date lastUpdateInFeed = null;
		for (Entry entry : feed.getEntries()) {
			String applicationNumber = entry.getSummary().getValue();
			if ((lastModified == null) || (entry.getUpdated().after(lastModified))) {
				log.info(applicationNumber + " is new, updating the status");


				CreditApplicationStatus applicationStatus = repository.findByApplicationNumber(applicationNumber);
				if (applicationStatus != null) {
					applicationStatus.setApproved(true);
					repository.save(applicationStatus);
				}
				if ((lastUpdateInFeed == null) || (entry.getUpdated().after(lastUpdateInFeed))) {
					lastUpdateInFeed = entry.getUpdated();
				}
			}
		}
		if (response.getHeaders().getFirst("Last-Modified") != null) {
			lastModified = DateUtils.parseDate(response.getHeaders().getFirst("Last-Modified"));
			log.info("LastModified header {}", lastModified);
		} else {
			if (lastUpdateInFeed != null) {
				lastModified = lastUpdateInFeed;
				log.info("Last in feed {}", lastModified);
			}

		}
	}
}