This repository was archived by the owner on Feb 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
WIP: feat: ability to consume non-standard xml feeds #17
Open
Doug-Reed
wants to merge
15
commits into
master
Choose a base branch
from
wud
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
936000c
Adds endpoint for non-rss xml
Doug-Reed 00548f9
Initial work
Doug-Reed fe7ec14
initial development
c5a4783
initial development
c3c42d4
more development
78e70bd
parses feed
0cf0ab8
feat custom filtering
b79fdfe
feat documentation
8d80712
refactor cleanup
d890934
refactor cleanup
dd231ce
feat: preliminary unit test
Doug-Reed 2fbc277
Merge branch 'specialChar' of github.com:UW-Madison-DoIT/rssToJson in…
c0e8c35
fix: resolve merge conflicts
Doug-Reed bb9f3c8
fix: interim commit
Doug-Reed 77cda0a
fix: update pom
Doug-Reed File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| .vscode/* | ||
| /target/ | ||
| /logs/* | ||
| .project | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| package edu.wisc.my.rssToJson.dao; | ||
|
|
||
| import com.rometools.rome.feed.synd.SyndFeed; | ||
|
|
||
| import org.json.JSONObject; | ||
| public interface RssToJsonDao{ | ||
|
|
||
| public JSONObject getXMLFeed(String feedEndpoint); | ||
| public SyndFeed getRssFeed(String feedEndpoint); | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package edu.wisc.my.rssToJson.filter; | ||
|
|
||
| import java.util.Iterator; | ||
|
|
||
| import org.json.JSONArray; | ||
| import org.json.JSONObject; | ||
|
|
||
| import java.util.ArrayList; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import com.fasterxml.jackson.core.JsonParser; | ||
| import com.fasterxml.jackson.databind.JsonNode; | ||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
|
||
| public class WudFilter implements iFilter{ | ||
| protected final Logger logger = LoggerFactory.getLogger(getClass()); | ||
|
|
||
| public WudFilter(){ | ||
| } | ||
|
|
||
| public JSONObject getFilteredJSON(JSONObject rawJSON){ | ||
| ObjectMapper om = new ObjectMapper(); | ||
| JSONObject responseObj = new JSONObject(); | ||
| JSONObject feedInfo = new JSONObject(); | ||
|
|
||
| try{ | ||
| JsonNode rootNode = om.readTree(rawJSON.toString()); | ||
| feedInfo.put("title", rootNode.findValue("title").asText()); | ||
| feedInfo.put("link", "https://union.wisc.edu/events-and-activities/event-calendar/"); | ||
| feedInfo.put("description", rootNode.findValue("description").asText()); | ||
| feedInfo.put("pubDate", rootNode.findValue("lastBuildDate").asText()); | ||
|
|
||
|
|
||
| JsonNode events = rootNode.findValue("event"); | ||
|
|
||
| Iterator<JsonNode> iter = events.elements(); | ||
| ArrayList<JSONObject> eventNodes = new ArrayList(); | ||
|
|
||
| while(iter.hasNext()){ | ||
| JSONObject item = new JSONObject(); | ||
| JsonNode anEvent = iter.next(); | ||
| item.put("title", anEvent.findValue("event_title").asText()); | ||
| item.put("link", anEvent.findValue("url").asText()); | ||
| item.put("description",anEvent.findValue("short_description").asText()); | ||
| JSONObject thisItem = new JSONObject(); | ||
| thisItem.put("item", item); | ||
| eventNodes.add(thisItem); | ||
| } | ||
|
|
||
| JSONArray allEvents = new JSONArray(eventNodes); | ||
| feedInfo.put("items",allEvents); | ||
|
|
||
|
|
||
| }catch(Exception e){ | ||
| logger.error(e.getMessage()); | ||
| }; | ||
|
|
||
| return feedInfo; | ||
| } | ||
|
|
||
| public String healthCheck(){ | ||
| return "WudFilter health check"; | ||
| } | ||
|
|
||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| package edu.wisc.my.rssToJson.filter; | ||
|
|
||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| public class XmlFilter { | ||
|
|
||
| protected final Logger logger = LoggerFactory.getLogger(getClass()); | ||
|
|
||
|
|
||
| public static iFilter getXmlFilter(String filterName){ | ||
| try{ | ||
| String filterClass = XmlFilter.toTitleCase(filterName) + "Filter"; | ||
| String pkg = new CurrentClassGetter().getPackageName(); | ||
| iFilter filter = (iFilter) Class.forName(pkg + "." +filterClass).newInstance(); | ||
| return filter; | ||
| } catch (Exception e){ | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| public static class CurrentClassGetter extends SecurityManager { | ||
| public String getPackageName() { | ||
| return getClassContext()[1].getPackage().getName(); | ||
| } | ||
| } | ||
|
|
||
| private static String toTitleCase(String filterNameIn){ | ||
| StringBuilder titleCase = new StringBuilder(); | ||
| boolean nextTitleCase = true; | ||
| for (char c : filterNameIn.toCharArray()) { | ||
| if (nextTitleCase) { | ||
| c = Character.toTitleCase(c); | ||
| nextTitleCase = false; | ||
| } | ||
|
|
||
| titleCase.append(c); | ||
| } | ||
| String filterNameOut = titleCase.toString().trim(); | ||
| return filterNameOut; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package edu.wisc.my.rssToJson.filter; | ||
|
|
||
| import org.json.JSONObject; | ||
|
|
||
| public interface iFilter{ | ||
|
|
||
| public JSONObject getFilteredJSON(JSONObject rawJSON); | ||
| public String healthCheck(); | ||
|
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| server.port = 8090 | ||
| server.port = 8090 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer
IFilter?