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 #142 from mozilla-tw/prod-0.7
Browse files Browse the repository at this point in the history
Prod 0.7
  • Loading branch information
cnevinc authored Oct 21, 2019
2 parents c11ce4e + b8e980a commit c71fb1d
Show file tree
Hide file tree
Showing 16 changed files with 82 additions and 28 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ dependencyManagement {

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

ext.getDeployConfig = { ->

def mode = project.hasProperty('mode') ? project.property('mode') : "staging"
def mode = project.hasProperty('mode') ? project.property('mode') : "dev"
def deployConfig = [mode: mode]

if (mode == 'dev') {
Expand All @@ -118,7 +118,7 @@ ext.getDeployConfig = { ->
deployConfig.promote = true
deployConfig.version = gaeVersions.nightly
} else if (mode == 'prod') {
deployConfig.gaeProjId = "rocket"
deployConfig.gaeProjId = "zerda-dcf76"
deployConfig.stopPreviousVersion = false
deployConfig.promote = false
deployConfig.version = gaeVersions.prod
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/mozilla/msrp/platform/common/MessageSource.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.mozilla.msrp.platform.common

import org.springframework.context.MessageSource
import org.springframework.context.NoSuchMessageException
import java.util.*

fun MessageSource.getMessageOrNull(id: String, locale: Locale, vararg args: String = emptyArray()): String? {
return try {
getMessage(id, args, locale)
} catch (e: NoSuchMessageException){
null
}
}

fun MessageSource.getMessageOrEmpty(id: String, locale: Locale, vararg args: String = emptyArray()): String {
return try {
getMessage(id, args, locale)
} catch (e: NoSuchMessageException){
""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public ResponseEntity createMissionForm(
@RequestParam String joinStartDate,
@RequestParam String joinEndDate,
@RequestParam String expiredDate,
@RequestParam String redeemEndDate,
@RequestParam String pings,
@RequestParam(value = "messages[]") String[] messages,
@RequestParam int minVersion) {
Expand Down Expand Up @@ -168,6 +169,7 @@ public ResponseEntity createMissionForm(
joinStartDate,
joinEndDate,
expiredDate,
redeemEndDate,
minVersion,
params,
rewardType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ data class MissionCreateData(
val joinStartDate: String,
val joinEndDate: String,
val expiredDate: String,
val redeemEndDate: String,
val minVersion: Int,
val missionParams: Map<String, Any>?,
val rewardType: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ data class MissionCreateResultItem(
val joinStartDate: String,
val joinEndDate: String,
val expiredDate: String,
val redeemEndDate: String,
val events: List<String>,
val endpoint: String,
val minVersion: Int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ data class MissionDoc(
val joinStartDate: String = "",
val joinEndDate: String = "",
var expiredDate: String = "",
var redeemEndDate: String = "",
var minVersion: Int = 0,
val missionParams: Map<String, Any> = emptyMap(),
var rewardType: String = "", // the Firestore collection for reward inventory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ data class MissionListItem(
val redeemEndpoint: String,
val events: List<String>,
val expiredDate: Long,
val redeemEndDate: Long,
val status: JoinStatus,
val minVersion: Int,
var progress: Map<String, Any>,
val important: Boolean,
val missionType: String,
val joinEndDate: Long,
val imageUrl: String
val imageUrl: String,
val rewardExpiredDate: Long
)
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class MissionRepositoryFirestore @Inject internal constructor(
joinStartDate = createData.joinStartDate,
joinEndDate = createData.joinEndDate,
expiredDate = createData.expiredDate,
redeemEndDate = createData.redeemEndDate,
interestPings = createData.pings,
minVersion = createData.minVersion,
missionParams = createData.missionParams ?: emptyMap(),
Expand Down
38 changes: 21 additions & 17 deletions src/main/java/org/mozilla/msrp/platform/mission/MissionService.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.mozilla.msrp.platform.mission

import org.mozilla.msrp.platform.common.getMessageOrEmpty
import org.mozilla.msrp.platform.common.getMessageOrNull
import org.mozilla.msrp.platform.common.isProd
import org.mozilla.msrp.platform.firestore.stringToLocalDateTime
import org.mozilla.msrp.platform.mission.qualifier.MissionProgressDoc
import org.mozilla.msrp.platform.mission.qualifier.MissionQualifier
import org.mozilla.msrp.platform.redward.RewardRepository
import org.mozilla.msrp.platform.util.logger
import org.slf4j.Logger
import org.springframework.context.MessageSource
import org.springframework.context.NoSuchMessageException
import org.springframework.core.env.Environment
import org.springframework.http.HttpStatus
import java.time.Clock
Expand All @@ -21,7 +23,8 @@ import javax.inject.Named

@Named
class MissionService @Inject constructor(
private val missionRepository: MissionRepository
private val missionRepository: MissionRepository,
private val rewardRepository: RewardRepository
) {

// TODO: Verify user status
Expand Down Expand Up @@ -129,13 +132,7 @@ class MissionService @Inject constructor(
}

private fun hasString(resId: String): Boolean {
return try {
getStringById(resId, Locale.getDefault())
true

} catch (e: NoSuchMessageException) {
false
}
return missionMessageSource.getMessageOrNull(resId, Locale.getDefault()) != null
}

private fun getMissionTitle(mission: MissionDoc, locale: Locale): String {
Expand All @@ -151,11 +148,8 @@ class MissionService @Inject constructor(
val name = getMissionTitle(missionDoc, locale)
val description = getStringById(missionDoc.descriptionId, locale)

val joinStatus = missionRepository.getJoinStatus(
uid,
missionDoc.missionType,
missionDoc.mid
)?.let { it } ?: JoinStatus.New
val joinDoc = missionRepository.getMissionJoinDoc(uid, missionDoc.missionType, missionDoc.mid)
val joinStatus = joinDoc?.status?.let { it } ?: JoinStatus.New

val progress = missionQualifier.getProgress(
uid,
Expand All @@ -167,14 +161,21 @@ class MissionService @Inject constructor(

val expiredInstant: Instant
val joinEndInstant: Instant
val redeemEndInstant: Instant
if (missionDoc.isUtcBasedMission()) {
expiredInstant = stringToLocalDateTime(missionDoc.expiredDate).toInstant(ZoneOffset.UTC)
joinEndInstant = stringToLocalDateTime(missionDoc.joinEndDate).toInstant(ZoneOffset.UTC)
redeemEndInstant = stringToLocalDateTime(missionDoc.redeemEndDate).toInstant(ZoneOffset.UTC)
} else {
expiredInstant = stringToLocalDateTime(missionDoc.expiredDate).atZone(zone).toInstant()
joinEndInstant = stringToLocalDateTime(missionDoc.joinEndDate).atZone(zone).toInstant()
redeemEndInstant = stringToLocalDateTime(missionDoc.redeemEndDate).atZone(zone).toInstant()
}

val rewardExpiredDate = joinDoc?.rewardDocId?.let { rewardDocId ->
rewardRepository.getRewardExpiredDate(missionDoc.rewardType, rewardDocId)
} ?: Long.MIN_VALUE

return MissionListItem(
mid = missionDoc.mid,
title = name,
Expand All @@ -183,13 +184,15 @@ class MissionService @Inject constructor(
redeemEndpoint = "/api/v1/redeem/${missionDoc.missionType}?mid=${missionDoc.mid}",
events = missionDoc.interestPings,
expiredDate = expiredInstant.toEpochMilli(),
redeemEndDate = redeemEndInstant.toEpochMilli(),
status = joinStatus,
minVersion = missionDoc.minVersion,
progress = progress?.toProgressResponse() ?: emptyMap(),
important = important,
missionType = missionDoc.missionType,
joinEndDate = joinEndInstant.toEpochMilli(),
imageUrl = missionDoc.imageUrl
imageUrl = missionDoc.imageUrl,
rewardExpiredDate = rewardExpiredDate
)
}

Expand All @@ -198,8 +201,8 @@ class MissionService @Inject constructor(
* @param id string id
* @return localized string (if any)
*/
private fun getStringById(id: String, locale: Locale, vararg args: String = emptyArray()): String {
return missionMessageSource.getMessage(id, args, locale)
private fun getStringById(id: String, locale: Locale): String {
return missionMessageSource.getMessageOrEmpty(id, locale)
}

fun createMissions(missionList: List<MissionCreateData>): MissionCreateResult {
Expand All @@ -222,6 +225,7 @@ class MissionService @Inject constructor(
joinStartDate = mission.joinStartDate,
joinEndDate = mission.joinEndDate,
expiredDate = mission.expiredDate,
redeemEndDate = mission.redeemEndDate,
events = mission.interestPings,
endpoint = mission.endpoint,
minVersion = mission.minVersion,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.mozilla.msrp.platform.mission.qualifier

import org.mozilla.msrp.platform.common.getMessageOrEmpty
import org.mozilla.msrp.platform.common.isProd
import org.mozilla.msrp.platform.mission.JoinStatus
import org.mozilla.msrp.platform.mission.MissionRepository
Expand Down Expand Up @@ -50,7 +51,7 @@ class DailyMissionQualifier(private val clock: Clock = Clock.systemUTC()) {
val messages = params["message"] as? ArrayList<*>
val messageId = messages?.getOrNull(newProgress.currentDayCount - 1)
val message = messageId?.let {
missionMessageSource.getMessage(it.toString(), null, locale)
missionMessageSource.getMessageOrEmpty(it.toString(), locale)
}
newProgress.dailyMessage = message ?: ""
newProgress.totalDays = totalDays
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ open class RewardRepository @Inject constructor(
}
}

fun getRewardExpiredDate(rewardType: String, rewardDocId: String): Long? {
val doc = getRewardDoc(rewardType, rewardDocId)
return doc?.expire_date
}

private fun info(missionJoinDoc: MissionJoinDoc) =
"[INFO: mission ${missionJoinDoc.mid}, user ${missionJoinDoc.uid}]"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
import retrofit2.Retrofit;
import retrofit2.converter.jackson.JacksonConverterFactory;

import javax.inject.Inject;
import javax.inject.Named;

@Log4j2
@Named
public class FirefoxAccountClientConfiguration {
@Inject
FirefoxAccountServiceInfo firefoxAccountServiceInfo;


@Bean("FxaAuth")
Expand All @@ -24,7 +27,7 @@ public FirefoxAccountClient authFirefoxAccountClient() {


return new Retrofit.Builder()
.baseUrl("https://oauth-stable.dev.lcip.org")
.baseUrl(firefoxAccountServiceInfo.getApiToken())
.client(client)
.addConverterFactory(JacksonConverterFactory.create())
.build()
Expand All @@ -40,7 +43,7 @@ public FirefoxAccountClient profileFirefoxAccountClientFactory() {


return new Retrofit.Builder()
.baseUrl("https://stable.dev.lcip.org/profile/")
.baseUrl(firefoxAccountServiceInfo.getApiProfile())
.client(client)
.addConverterFactory(JacksonConverterFactory.create())
.build().create(FirefoxAccountClient.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public FirefoxAccountServiceInfo firefoxAccountServiceInfo(Firestore firestore)
String token = document.getString("fxa_api_token");
String profile = document.getString("fxa_api_profile");

log.info("Get FirefoxAccount settings --- success ---");
log.info("Get FirefoxAccount settings --- success ---:" + id);
return new FirefoxAccountServiceInfo(id, secret, token, profile);
}
} catch (InterruptedException | ExecutionException e) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ logging.level:
root: WARN
org.mozilla.msrp: INFO
platform:
firebaseProjectId: rocket
firebaseProjectId: zerda-dcf76
news:
cache-size: 100
cache-ttl: 15
12 changes: 11 additions & 1 deletion src/main/resources/templates/msrp.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ <h1>Create Mission</h1>
</td>
<td>
<input type="text" name="expiredDate">2019-12-30T10:00:00, After this moment, those didn't join nor complete the mission will not see this mission anymore
</td>
</tr>
<tr>
<td>
redeemEndDate
</td>
<td>
<input type="text" name="redeemEndDate">2019-12-30T10:00:00, After this moment, reward can't be redeemed
</td>
</tr>
<tr>
<td>
pings
Expand Down Expand Up @@ -241,7 +251,7 @@ <h1>Upload Reward</h1>
<td>
expiredDate
</td>
<td><input type="text" name="expiredDate">After this moment, user won't be able to redeem this coupon
<td><input type="text" name="expiredDate">After this moment, user won't be able to use this coupon
</td>
</tr>
<tr>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.mozilla.msrp.platform.mission
import org.junit.Assert.assertEquals
import org.junit.Test
import org.mockito.Mockito.mock
import org.mozilla.msrp.platform.redward.RewardRepository
import java.time.Clock
import java.time.Instant
import java.time.LocalDateTime
Expand All @@ -26,7 +27,8 @@ class MissionJoinableTest {
private val afterExpiredUtc = LocalDateTime.ofInstant(afterExpiredJakarta.atZone(zoneJakarta).toInstant(), zoneUtc)

private val missionRepo = mock(MissionRepository::class.java)
private val service = MissionService(missionRepo)
private val rewardRepo = mock(RewardRepository::class.java)
private val service = MissionService(missionRepo, rewardRepo)

@Test
fun `test getMissionJoinState()`() {
Expand Down

0 comments on commit c71fb1d

Please sign in to comment.