Skip to content
This repository has been archived by the owner on Jan 6, 2023. It is now read-only.

Commit

Permalink
Merge pull request #237 from mozilla-tw/develop
Browse files Browse the repository at this point in the history
merge develop to master
  • Loading branch information
Daisy-pliu authored Mar 19, 2020
2 parents cd556cb + 106d450 commit 8fbdc39
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 85 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ dependencyManagement {
}

// appengine versions for various environment
def gaeVersions = "0-26"
def gaeVersions = "0-27"

ext.getDeployConfig = { ->

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ import retrofit2.Call
import retrofit2.Retrofit
import retrofit2.converter.simplexml.SimpleXmlConverterFactory
import retrofit2.http.GET
import retrofit2.http.Path
import retrofit2.http.Url
import javax.inject.Inject
import javax.inject.Named

interface DetikRssFeedClient {

@GET("index.php/{topic}")
fun rss(@Path("topic") topic: String): Call<DetikRss>

@GET
fun fromUrl(@Url url: String): Call<DetikRss>
}

@Named
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class DetikRssFeedRepository @Inject constructor(private val detikRssFeedClient:

val log = logger()

fun news(topic: String): List<FeedItem>? {
fun news(detikUrl: String): List<FeedItem>? {

val rss = detikRssFeedClient.rss(topic).execute().body()
val rss = detikRssFeedClient.fromUrl(detikUrl).execute().body()
log.info("[NEWS]====loading indonesia news Liputan6 [${rss?.feedItems?.size}]")
return rss?.feedItems
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import retrofit2.Call
import retrofit2.Retrofit
import retrofit2.converter.simplexml.SimpleXmlConverterFactory
import retrofit2.http.GET
import retrofit2.http.Query
import retrofit2.http.Url
import javax.inject.Inject
import javax.inject.Named

interface Liputan6RssFeedClient {

@GET("mozilla?source=Digital%20Marketing&medium=Partnership")
fun rss(@Query("categories[]") topic: String): Call<Liputan6Rss>
interface Liputan6RssFeedClient {
@GET
fun fromUrl(@Url url: String?): Call<Liputan6Rss>
}

@Named
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ class Liputan6RssFeedRepository @Inject constructor(private val liputan6RssFeedC

val log = logger()

fun news(topic: String): List<FeedItem>? {
fun news(url: String): List<FeedItem>? {

val rss = liputan6RssFeedClient.rss(topic).execute().body()
val rss = liputan6RssFeedClient.fromUrl(url).execute().body()
log.info("[NEWS]====loading indonesia news Liputan6 [${rss?.feedItems?.size}]")
return rss?.feedItems
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.mozilla.msrp.platform.vertical.news

import com.google.common.cache.CacheBuilder
import com.google.common.cache.CacheLoader
import org.mozilla.msrp.platform.common.property.NewsProperties
import org.mozilla.msrp.platform.util.logger
import org.springframework.http.HttpStatus
import org.springframework.http.ResponseEntity
Expand All @@ -17,8 +16,7 @@ import javax.inject.Inject
@RestController
class NewsFeedController @Inject constructor(
private val googleNewsFeedService: GoogleNewsFeedService,
private val indonesiaNewsFeedService: IndonesiaNewsFeedService,
private val newsProperties: NewsProperties) {
private val indonesiaNewsFeedService: IndonesiaNewsFeedService) {

private val log = logger()

Expand Down Expand Up @@ -65,8 +63,8 @@ class NewsFeedController @Inject constructor(


private val cacheGoogleNews = CacheBuilder.newBuilder()
.maximumSize(newsProperties.cacheSize)
.refreshAfterWrite(newsProperties.cacheTtl, TimeUnit.MINUTES)
.maximumSize(NEWS_CACHE_SIZE)
.refreshAfterWrite(NEWS_CACHE_TTL, TimeUnit.MINUTES)
.recordStats()
.build(
object : CacheLoader<String, List<FeedItem>>() {
Expand All @@ -86,25 +84,38 @@ class NewsFeedController @Inject constructor(


private val cacheIndonesiaNews = CacheBuilder.newBuilder()
.maximumSize(newsProperties.cacheSize)
.refreshAfterWrite(newsProperties.cacheTtl, TimeUnit.MINUTES)
.maximumSize(NEWS_CACHE_SIZE)
.refreshAfterWrite(NEWS_CACHE_TTL, TimeUnit.MINUTES)
.recordStats()
.build(
object : CacheLoader<String, List<FeedItem>>() {
override fun load(topic: String): List<FeedItem> {
return indonesiaNewsFeedService.getNews(topic, detikTopic[topic]) ?: listOf()
val liputan6Url = toLiputan6Url(topic)
val detik6Url = toDetik6Url(topic)
if (liputan6Url == null && detik6Url == null) {
return listOf()
}
return indonesiaNewsFeedService.getNews(liputan6Url, detik6Url) ?: listOf()
}
})

private fun toDetik6Url(topic: String): String? {
return detikUrl[topic]

}

private fun toLiputan6Url(topic: String): String? {
return liputan6Url[topic]
}

@GetMapping("/api/v1/news/indonesia/topic/{topic}")
internal fun indonesiaNewsByTopic(
@PathVariable("topic") topic: String): ResponseEntity<in Any> {
val liputan6Topic = liputan6Topic[topic]
if (liputan6Topic == null) {
if (liputan6Url[topic] == null) {
log.info("[NEWS]====No news for topic $String")
return ResponseEntity("No such topic", HttpStatus.BAD_REQUEST)
}
val newsItems = cacheIndonesiaNews.get(liputan6Topic)
val newsItems = cacheIndonesiaNews.get(topic)
log.info("[NEWS]====loading indonesia news [${newsItems.size}]")
if (newsItems.isEmpty()) {
log.info("[NEWS]====No news for topic $String")
Expand All @@ -115,32 +126,36 @@ class NewsFeedController @Inject constructor(
}


private val liputan6Topic = mapOf(
"NEWS" to "17",
"TEKNO" to "8",
"GLOBAL" to "274",
"HEALTH INFO" to "9",
"BOLA" to "11",
"E-SPORTS" to "1071",
"RAGAM" to "486",
"INDONESIA" to "423",
"SHOWBIZ" to "13",
"FASHION" to "842",
"PARENTING" to "1065",
"LIFESTYLE" to "908")

private val detikTopic = mapOf(
"17" to "hot",
"8" to "inet",
"9" to "health",
"486" to "sport")

@GetMapping("/api/v1/news/indonesia/topics")
fun idNewsTopic() = liputan6Topic.keys
fun idNewsTopic() = liputan6Url.keys

companion object {

private const val delimiters = "=="
private const val TOPIC_GOOGLE_TOP_NEWS = "Top-news"
private const val NEWS_CACHE_TTL = 15L
private const val NEWS_CACHE_SIZE = 100L

private val liputan6Url = mapOf(
"NEWS" to "https://feed.liputan6.com/mozilla?categories[]=17&source=Digital%20Marketing&medium=Partnership",
"TEKNO" to "https://feed.liputan6.com/mozilla?categories[]=8&source=Digital%20Marketing&medium=Partnership",
"GLOBAL" to "https://feed.liputan6.com/mozilla?categories[]=274&source=Digital%20Marketing&medium=Partnership",
"HEALTH INFO" to "https://feed.liputan6.com/mozilla?categories[]=9&source=Digital%20Marketing&medium=Partnership",
"BOLA" to "https://feed.liputan6.com/mozilla?categories[]=11&source=Digital%20Marketing&medium=Partnership",
"E-SPORTS" to "https://feed.bola.com/mozilla?categories[]=1071&source=Digital%20Marketing&medium=Partnership",
"RAGAM" to "https://feed.bola.com/mozilla?categories[]=486&source=Digital%20Marketing&medium=Partnership",
"INDONESIA" to "https://feed.bola.com/mozilla?categories[]=423&source=Digital%20Marketing&medium=Partnership",
"SHOWBIZ" to "https://feed.liputan6.com/mozilla?categories[]=13&source=Digital%20Marketing&medium=Partnership",
"FASHION" to "https://feed.fimela.com/mozilla?categories[]=842&source=Digital%20Marketing&medium=Partnership",
"PARENTING" to "https://feed.fimela.com/mozilla?categories[]=1065&source=Digital%20Marketing&medium=Partnership",
"LIFESTYLE" to "https://feed.fimela.com/mozilla?categories[]=908&source=Digital%20Marketing&medium=Partnership",
"ZODIAK" to "https://feed.fimela.com/mozilla?categories[]=601&source=Digital%20Marketing&medium=Partnership")

private val detikUrl = mapOf(
"NEWS" to "http://rss.detik.com/index.php/hot",
"TEKNO" to "http://rss.detik.com/index.php/inet",
"HEALTH INFO" to "http://rss.detik.com/index.php/health",
"RAGAM" to "http://rss.detik.com/index.php/sport")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,13 @@ class IndonesiaNewsFeedService @Inject constructor(
private val liputan6RssFeedRepository: Liputan6RssFeedRepository,
private val detikRssFeedRepository: DetikRssFeedRepository) {

fun getNews(liputanTopicId: String, detikTopicId: String?): List<FeedItem>? {
val liputan6List = liputan6RssFeedRepository.news(liputanTopicId)?: emptyList()
fun getNews(liputan6Url: String?, detikUrl: String?): List<FeedItem>? {

val detikList = detikTopicId?.let {
val liputan6List = liputan6Url?.let {
liputan6RssFeedRepository.news(it)
} ?: emptyList()

val detikList = detikUrl?.let {
detikRssFeedRepository.news(it)
}?: emptyList()

Expand Down
12 changes: 0 additions & 12 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ logging.level:
org.mozilla.msrp: DEBUG
platform:
firebaseProjectId: msrp-dev01
news:
cache-size: 100
cache-ttl: 15
---
# Configuration to be enabled when the "stable" profile is active
spring:
Expand All @@ -30,9 +27,6 @@ logging.level:
org.mozilla.msrp: DEBUG
platform:
firebaseProjectId: rocket-dev01
news:
cache-size: 100
cache-ttl: 15
---
# Configuration to be enabled when the "nightly" profile is active
spring:
Expand All @@ -42,9 +36,6 @@ logging.level:
org.mozilla.msrp: DEBUG
platform:
firebaseProjectId: rocketnightly
news:
cache-size: 100
cache-ttl: 15
---

# Configuration to be enabled when the "prod" profile is active
Expand All @@ -56,6 +47,3 @@ logging.level:
org.mozilla.msrp: INFO
platform:
firebaseProjectId: zerda-dcf76
news:
cache-size: 100
cache-ttl: 15

0 comments on commit 8fbdc39

Please sign in to comment.