Skip to content

Commit

Permalink
Merge pull request #422 from phuonghuynh/master
Browse files Browse the repository at this point in the history
Update changes
  • Loading branch information
phuonghuynh committed Sep 30, 2015
2 parents 65a09ac + 0d76f47 commit 9e76afd
Show file tree
Hide file tree
Showing 57 changed files with 20,991 additions and 640 deletions.
12 changes: 12 additions & 0 deletions src/main/java/com/techlooper/config/CoreConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,18 @@ public Template onBoardingMailTemplateVi(freemarker.template.Configuration freem
return template;
}

@Bean
public Template dailyChallengeSummaryMailTemplateEn(freemarker.template.Configuration freemakerConfig) throws IOException {
Template template = freemakerConfig.getTemplate("challengeDailySummary.en.ftl");
return template;
}

@Bean
public Template dailyChallengeSummaryMailTemplateVi(freemarker.template.Configuration freemakerConfig) throws IOException {
Template template = freemakerConfig.getTemplate("challengeDailySummary.vi.ftl");
return template;
}

@Bean
public JsonNode vietnamworksConfiguration() throws IOException {
return new ObjectMapper().readTree(vnwConfigRes.getInputStream());
Expand Down
40 changes: 23 additions & 17 deletions src/main/java/com/techlooper/cron/ChallengeTimelineNotifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.dozer.Mapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

Expand All @@ -28,26 +29,31 @@ public class ChallengeTimelineNotifier {
@Resource
private Mapper dozerMapper;

@Value("${jobAlert.enable}")
private Boolean enableJobAlert;

@Scheduled(cron = "${scheduled.cron.notifyChallengeTimeline}")
public void notifyRegistrantAboutChallengeTimeline() throws Exception {
List<ChallengePhaseEnum> challengePhases = Arrays.asList(ChallengePhaseEnum.REGISTRATION, ChallengePhaseEnum.IN_PROGRESS);

for (ChallengePhaseEnum challengePhase : challengePhases) {
List<ChallengeEntity> challengeEntities = challengeService.listChallengesByPhase(challengePhase);

for (ChallengeEntity challengeEntity : challengeEntities) {
Set<ChallengeRegistrantDto> challengeRegistrants = challengeService.findRegistrantsByOwner(
challengeEntity.getAuthorEmail(), challengeEntity.getChallengeId());

for (ChallengeRegistrantDto challengeRegistrant : challengeRegistrants) {
ChallengeRegistrantEntity challengeRegistrantEntity = dozerMapper.map(challengeRegistrant, ChallengeRegistrantEntity.class);
try {
if (StringUtils.isNotEmpty(challengeRegistrantEntity.getRegistrantEmail())) {
challengeService.sendEmailNotifyRegistrantAboutChallengeTimeline(
challengeEntity, challengeRegistrantEntity, challengePhase);
if (enableJobAlert) {
List<ChallengePhaseEnum> challengePhases = Arrays.asList(ChallengePhaseEnum.REGISTRATION, ChallengePhaseEnum.IN_PROGRESS);

for (ChallengePhaseEnum challengePhase : challengePhases) {
List<ChallengeEntity> challengeEntities = challengeService.listChallengesByPhase(challengePhase);

for (ChallengeEntity challengeEntity : challengeEntities) {
Set<ChallengeRegistrantDto> challengeRegistrants = challengeService.findRegistrantsByOwner(
challengeEntity.getAuthorEmail(), challengeEntity.getChallengeId());

for (ChallengeRegistrantDto challengeRegistrant : challengeRegistrants) {
ChallengeRegistrantEntity challengeRegistrantEntity = dozerMapper.map(challengeRegistrant, ChallengeRegistrantEntity.class);
try {
if (StringUtils.isNotEmpty(challengeRegistrantEntity.getRegistrantEmail())) {
challengeService.sendEmailNotifyRegistrantAboutChallengeTimeline(
challengeEntity, challengeRegistrantEntity, challengePhase);
}
} catch (Exception ex) {
LOGGER.error(ex.getMessage(), ex);
}
} catch (Exception ex) {
LOGGER.error(ex.getMessage(), ex);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.techlooper.cron;

import com.techlooper.entity.ChallengeEntity;
import com.techlooper.model.ChallengePhaseEnum;
import com.techlooper.service.ChallengeService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

@Service
public class DailyChallengeSummaryEmailSender {

private final static Logger LOGGER = LoggerFactory.getLogger(DailyChallengeSummaryEmailSender.class);

@Resource
private ChallengeService challengeService;

@Value("${jobAlert.enable}")
private Boolean enableJobAlert;

@Scheduled(cron = "${scheduled.cron.dailyChallengeSummary}")
public void notifyRegistrantAboutChallengeTimeline() throws Exception {
if (enableJobAlert) {
List<ChallengePhaseEnum> challengePhases = Arrays.asList(ChallengePhaseEnum.REGISTRATION, ChallengePhaseEnum.IN_PROGRESS);

for (ChallengePhaseEnum challengePhase : challengePhases) {
List<ChallengeEntity> challengeEntities = challengeService.listChallengesByPhase(challengePhase);

for (ChallengeEntity challengeEntity : challengeEntities) {
try {
challengeService.sendDailySummaryEmailToChallengeOwner(challengeEntity);
} catch (Exception ex) {
LOGGER.error(ex.getMessage(), ex);
}
}
}
}
}
}
Loading

0 comments on commit 9e76afd

Please sign in to comment.