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 #148 from mozilla-tw/develop
Browse files Browse the repository at this point in the history
Merge 0.8 to master
  • Loading branch information
cnevinc authored Oct 22, 2019
2 parents c71fb1d + f312e5e commit 7603caa
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 32 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ dependencyManagement {

// appengine versions for various environment
def gaeVersions = [
dev: "0-7", stable: "0-7", nightly: "0-7", prod: "0-7"
dev: "0-8", stable: "0-8", nightly: "0-8", prod: "0-8"
]

ext.getDeployConfig = { ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@ package org.mozilla.msrp.platform.user

import com.fasterxml.jackson.annotation.JsonIgnoreProperties


@JsonIgnoreProperties(ignoreUnknown = true)
class FxaTokenResponse(
val access_token: String? = null,
val token_type: String? = null,
val scope: String? = null,
val expires_in: Int? = null,
val auth_at: Long? = null
val access_token: String? = null
)

class FxaTokenRequest(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ void login(@RequestParam(value = "code") String code,
@RequestParam(value = "state") String state,
HttpServletResponse httpResponse) { // need HttpServletResponse to redirect

log.info("[login][/api/v1/login][" + state + "] ");

try {
FxaTokenRequest fxaTokenRequest = firefoxAccountService.genFxaTokenRequest(code);
String fxaAccessToken = firefoxAccountService.token(fxaTokenRequest);
Expand All @@ -58,7 +60,7 @@ void login(@RequestParam(value = "code") String code,

String fxUid = profileResponse.getUid();
String fxEmail = profileResponse.getEmail();

log.info("[login] User[" + fxUid + "] login with email:" + fxEmail);
if (fxUid == null || fxEmail == null) {
log.error("[login][" + state + "] No such user in fxa");
httpResponse.sendRedirect("/api/v1/done?login_success=false&msg=no_Fxa_user");
Expand Down Expand Up @@ -87,12 +89,16 @@ void login(@RequestParam(value = "code") String code,
String customToken = userRepository.createCustomToken(oldFbUid, additionalClaims);
// log are handled in the repository
if (loginResponse instanceof LoginResponse.Success) {
log.info("[login]bind FxA success: login for the fist time");
httpResponse.sendRedirect("/api/v1/done?jwt=" + customToken + "&login_success=true&disabled=false&times=1");
} else if (loginResponse instanceof LoginResponse.SuspiciousWarning) {
log.info("[login]bind success: login for the second time");
httpResponse.sendRedirect("/api/v1/done?jwt=" + customToken + "&login_success=true&disabled=false&times=2");
} else if (loginResponse instanceof LoginResponse.UserSuspended) {
log.info("[login]bind success: login more than three times. User suspended");
httpResponse.sendRedirect("/api/v1/done?jwt=" + customToken + "&login_success=true&disabled=true&times=3");
} else if (loginResponse instanceof LoginResponse.Fail) {
log.info("[login]bind fail:" + ((LoginResponse.Fail) loginResponse).getMessage());
httpResponse.sendRedirect("/api/v1/done?login_success=false");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class NewsFeedController @Inject constructor(
log.info("[NEWS]====No news for topic $String")
return ResponseEntity("No news for topic", HttpStatus.NO_CONTENT)
}
log.info("[NEWS]====found [${newsItems.size}] news item for topic $String")
log.info("[NEWS]====found [${newsItems.size}] news item for topic $topic")
return ResponseEntity(newsItems, HttpStatus.OK)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import org.simpleframework.xml.ElementList
import org.simpleframework.xml.Path
import org.simpleframework.xml.Root
import org.simpleframework.xml.Text
import java.text.ParseException
import java.text.SimpleDateFormat


open class Rss<T> {
Expand Down Expand Up @@ -42,7 +44,12 @@ class GoogleRss : Rss<GoogleFeedItem>() {
override var feedItems: List<GoogleFeedItem>? = null
}

open class FeedItem {
open class FeedItem : Comparable<FeedItem> {

companion object {
private val sharedRssDateFormat = SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz")
}

open var pubDate: String? = ""

open var title: String? = ""
Expand All @@ -55,6 +62,20 @@ open class FeedItem {

open var source: String = ""

override fun compareTo(other: FeedItem): Int {
return try {
val formatter = sharedRssDateFormat
val o1Date = formatter.parse(this.pubDate)
val o2Date = formatter.parse(other.pubDate)
if (o1Date.before(o2Date)) {
1
} else {
-1
}
} catch (e: ParseException) {
1
}
}
}

@Root(name = "item", strict = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ class GoogleNewsFeedService @Inject constructor(private val googleRssFeedReposit

fun getNews(language: String) = googleRssFeedRepository.news(language)

fun getNews(topic: String, hl: String, gl: String, ceid: String) = googleRssFeedRepository.news(topic, hl, gl, ceid)
fun getNews(topic: String, hl: String, gl: String, ceid: String): List<FeedItem>? {
val list = googleRssFeedRepository.news(topic, hl, gl, ceid)
return list?.sorted()
}

}

Expand All @@ -30,26 +33,7 @@ class IndonesiaNewsFeedService @Inject constructor(
val allNewsList = liputan6List.toMutableList().apply {
addAll(detikList)
}

allNewsList.sortWith(Comparator<FeedItem> { o1, o2 ->
val grater = o1?.let {
try {
val formatter = SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz")
val o1Date = formatter.parse(it.pubDate)
val o2Date = formatter.parse(o2.pubDate)
o1Date.before(o2Date)
} catch (e: ParseException) {
false
}
} ?: false
if (grater) {
1
} else {
-1
}
})

return allNewsList
return allNewsList.sorted()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class FirefoxAccountServiceTest {
val accessToken = "token"

onRetrofitExecute(authClient.token(fxaTokenRequest))
?.thenReturn(Response.success(FxaTokenResponse(accessToken, "")))
?.thenReturn(Response.success(FxaTokenResponse(accessToken)))

val response = firefoxAccountService.token(fxaTokenRequest)

Expand Down

0 comments on commit 7603caa

Please sign in to comment.