Skip to content

Commit

Permalink
Merge pull request #423 from khoa-nd/master
Browse files Browse the repository at this point in the history
Merged
  • Loading branch information
khoa-nd committed Oct 1, 2015
2 parents 9e76afd + faa63cc commit 96f1508
Show file tree
Hide file tree
Showing 30 changed files with 953 additions and 792 deletions.
18 changes: 17 additions & 1 deletion src/main/java/com/techlooper/config/CoreConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ protected void configure() {
mapping(ChallengeEntity.class, ChallengeDto.class)
.fields("startDateTime", "startDate")
.fields("submissionDateTime", "submissionDate")
.fields("registrationDateTime", "registrationDate");
.fields("registrationDateTime", "registrationDate")
.fields("ideaSubmissionDateTime", "ideaSubmissionDate")
.fields("uxSubmissionDateTime", "uxSubmissionDate")
.fields("prototypeSubmissionDateTime", "prototypeSubmissionDate");

}
});
Expand Down Expand Up @@ -504,6 +507,7 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
public MimeMessage fromTechlooperMailMessage(JavaMailSender mailSender) throws MessagingException, UnsupportedEncodingException {
MimeMessage mailMessage = mailSender.createMimeMessage();
mailMessage.setFrom(new InternetAddress(mailTechlooperForm, "TechLooper", "UTF-8"));
mailMessage.setReplyTo(InternetAddress.parse(mailTechlooperReplyTo));
return mailMessage;
}

Expand All @@ -513,4 +517,16 @@ private ClientHttpRequestFactory clientHttpRequestFactory() {
factory.setConnectTimeout(5000);
return factory;
}

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

@Bean
public Template challengeEmployerMailTemplateVi(freemarker.template.Configuration freemakerConfig) throws IOException {
Template template = freemakerConfig.getTemplate("challengeEmployerEmail.vi.ftl");
return template;
}
}
12 changes: 11 additions & 1 deletion src/main/java/com/techlooper/controller/ChallengeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import com.techlooper.entity.ChallengeEntity;
import com.techlooper.entity.ChallengeRegistrantDto;
import com.techlooper.entity.ChallengeRegistrantEntity;
import com.techlooper.entity.vnw.VnwCompany;
import com.techlooper.entity.vnw.VnwUser;
import com.techlooper.model.*;
import com.techlooper.repository.elasticsearch.ChallengeRegistrantRepository;
import com.techlooper.service.ChallengeService;
import com.techlooper.service.EmployerService;
import com.techlooper.service.LeadAPIService;
Expand Down Expand Up @@ -34,6 +36,9 @@ public class ChallengeController {
@Resource
private LeadAPIService leadAPIService;

@Resource
private ChallengeRegistrantRepository challengeRegistrantRepository;

@PreAuthorize("hasAuthority('EMPLOYER')")
@RequestMapping(value = "/challenge/publish", method = RequestMethod.POST)
public ChallengeResponse publishChallenge(@RequestBody ChallengeDto challengeDto, HttpServletRequest servletRequest) throws Exception {
Expand Down Expand Up @@ -125,5 +130,10 @@ public ChallengeRegistrantDto saveRegistrant(@RequestBody ChallengeRegistrantDto
return challengeService.saveRegistrant(request.getRemoteUser(), dto);
}


@PreAuthorize("hasAuthority('EMPLOYER')")
@RequestMapping(value = "challengeRegistrant/fullName/{registrantId}", method = RequestMethod.GET)
public String getChallengeRegistrant(@PathVariable Long registrantId) {
ChallengeRegistrantEntity registrantEntity = challengeRegistrantRepository.findOne(registrantId);
return registrantEntity.getRegistrantFirstName() + " " + registrantEntity.getRegistrantLastName();
}
}
34 changes: 34 additions & 0 deletions src/main/java/com/techlooper/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.techlooper.dto.DashBoardInfo;
import com.techlooper.dto.JoinBySocialDto;
import com.techlooper.dto.WebinarInfoDto;
import com.techlooper.entity.ChallengeRegistrantEntity;
import com.techlooper.entity.GetPromotedEntity;
import com.techlooper.entity.PriceJobEntity;
import com.techlooper.entity.SalaryReviewEntity;
Expand Down Expand Up @@ -33,6 +34,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toSet;
Expand Down Expand Up @@ -373,4 +375,36 @@ public WebinarInfoDto findWebinarById(@PathVariable Long id) {
public WebinarInfoDto joinWebinar(@RequestBody JoinBySocialDto joinBySocialDto) throws Exception {
return webinarService.joinWebinar(joinBySocialDto);
}

@PreAuthorize("hasAuthority('EMPLOYER')")
@RequestMapping(value = "user/challengeRegistrantNames/{challengeId}/{now}", method = RequestMethod.GET)
public List<String> getDailyChallengeRegistrantNames(HttpServletRequest request, HttpServletResponse response,
@PathVariable Long challengeId, @PathVariable Long now) {
if (challengeService.isOwnerOfChallenge(request.getRemoteUser(), challengeId)) {
List<ChallengeRegistrantEntity> registrants = challengeService.findChallengeRegistrantWithinPeriod(challengeId, now, TimePeriodEnum.TWENTY_FOUR_HOURS);
return registrants.stream()
.map(registrant -> registrant.getRegistrantFirstName() + " " + registrant.getRegistrantLastName())
.collect(Collectors.toList());
}
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
return null;
}

@PreAuthorize("hasAuthority('EMPLOYER')")
@RequestMapping(value = "user/challenge/sendMailToDaily/{challengeId}/{now}", method = RequestMethod.POST)
public void sendEmailToDailyChallengeRegistrants(HttpServletRequest request, HttpServletResponse response,
@PathVariable Long challengeId, @PathVariable Long now, @RequestBody EmailContent emailContent) {
if (!challengeService.sendEmailToDailyChallengeRegistrants(request.getRemoteUser(), challengeId, now, emailContent)) {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
}
}

@PreAuthorize("hasAuthority('EMPLOYER')")
@RequestMapping(value = "user/challenge/feedback/{challengeId}/{registrantId}", method = RequestMethod.POST)
public void sendFeedbackToRegistrant(HttpServletRequest request, HttpServletResponse response,
@PathVariable Long challengeId, @PathVariable Long registrantId, @RequestBody EmailContent emailContent) {
if (!challengeService.sendEmailToRegistrant(request.getRemoteUser(), challengeId, registrantId, emailContent)) {
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void notifyRegistrantAboutChallengeTimeline() throws Exception {
if (enableJobAlert) {
List<ChallengePhaseEnum> challengePhases = Arrays.asList(ChallengePhaseEnum.REGISTRATION, ChallengePhaseEnum.IN_PROGRESS);

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

Expand All @@ -50,13 +51,15 @@ public void notifyRegistrantAboutChallengeTimeline() throws Exception {
if (StringUtils.isNotEmpty(challengeRegistrantEntity.getRegistrantEmail())) {
challengeService.sendEmailNotifyRegistrantAboutChallengeTimeline(
challengeEntity, challengeRegistrantEntity, challengePhase);
count++;
}
} catch (Exception ex) {
LOGGER.error(ex.getMessage(), ex);
}
}
}
}
LOGGER.info("There are " + count + " emails has been sent to notify challenge timeline");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,24 @@ public class DailyChallengeSummaryEmailSender {
private Boolean enableJobAlert;

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

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

for (ChallengeEntity challengeEntity : challengeEntities) {
try {
challengeService.sendDailySummaryEmailToChallengeOwner(challengeEntity);
count++;
} catch (Exception ex) {
LOGGER.error(ex.getMessage(), ex);
}
}
}
LOGGER.info("There are " + count + " daily emails has been sent about challenge summary");
}
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/techlooper/cron/JobAlertEmailSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import com.techlooper.model.JobSearchResponse;
import com.techlooper.service.JobAggregatorService;
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 @@ -25,6 +27,8 @@
@Service
public class JobAlertEmailSender {

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

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

Expand All @@ -48,16 +52,19 @@ public void sendJobAlertEmail() throws Exception {
jobAggregatorService.findJobAlertRegistration(JobAlertPeriodEnum.WEEKLY);

if (!jobAlertRegistrationEntities.isEmpty()) {
int count = 0;
for (JobAlertRegistrationEntity jobAlertRegistrationEntity : jobAlertRegistrationEntities) {
JobSearchCriteria criteria = dozerMapper.map(jobAlertRegistrationEntity, JobSearchCriteria.class);
JobSearchResponse jobSearchResponse = jobAggregatorService.findJob(criteria);
if (jobSearchResponse.getTotalJob() > 0) {
jobAggregatorService.sendEmail(jobAlertRegistrationEntity, jobSearchResponse);
jobAggregatorService.updateSendEmailResultCode(jobAlertRegistrationEntity, EMAIL_SENT);
count++;
} else {
jobAggregatorService.updateSendEmailResultCode(jobAlertRegistrationEntity, JOB_NOT_FOUND);
}
}
LOGGER.info("There are " + count + " job alert emails has been sent");
}
}
}
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/com/techlooper/model/EmailContent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.techlooper.model;

import javax.mail.Address;
import java.io.Serializable;

/**
* Created by phuonghqh on 10/1/15.
*/
public class EmailContent implements Serializable {

private String subject;

private String content;

private Address[] recipients;

private Language language;

public Language getLanguage() {
return language;
}

public void setLanguage(Language language) {
this.language = language;
}

public Address[] getRecipients() {
return recipients;
}

public void setRecipients(Address[] recipients) {
this.recipients = recipients;
}

public String getSubject() {
return subject;
}

public void setSubject(String subject) {
this.subject = subject;
}

public String getContent() {
return content;
}

public void setContent(String content) {
this.content = content;
}
}
78 changes: 41 additions & 37 deletions src/main/java/com/techlooper/service/ChallengeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import com.techlooper.entity.ChallengeRegistrantDto;
import com.techlooper.entity.ChallengeRegistrantEntity;
import com.techlooper.entity.ChallengeSubmissionEntity;
import com.techlooper.model.ChallengeDetailDto;
import com.techlooper.model.ChallengeDto;
import com.techlooper.model.ChallengePhaseEnum;
import com.techlooper.model.TimePeriodEnum;
import com.techlooper.model.*;
import freemarker.template.TemplateException;

import javax.mail.MessagingException;
Expand All @@ -22,64 +19,71 @@
*/
public interface ChallengeService {

ChallengeEntity savePostChallenge(ChallengeDto challengeDto) throws Exception;
ChallengeEntity savePostChallenge(ChallengeDto challengeDto) throws Exception;

void sendPostChallengeEmailToEmployer(ChallengeEntity challengeEntity)
throws MessagingException, IOException, TemplateException;
void sendPostChallengeEmailToEmployer(ChallengeEntity challengeEntity)
throws MessagingException, IOException, TemplateException;

void sendPostChallengeEmailToTechloopies(ChallengeEntity challengeEntity, Boolean isNewChallenge)
throws MessagingException, IOException, TemplateException;
void sendPostChallengeEmailToTechloopies(ChallengeEntity challengeEntity, Boolean isNewChallenge)
throws MessagingException, IOException, TemplateException;

void sendEmailNotifyRegistrantAboutChallengeTimeline(ChallengeEntity challengeEntity,
ChallengeRegistrantEntity challengeRegistrantEntity, ChallengePhaseEnum challengePhase) throws Exception;
void sendEmailNotifyRegistrantAboutChallengeTimeline(ChallengeEntity challengeEntity,
ChallengeRegistrantEntity challengeRegistrantEntity, ChallengePhaseEnum challengePhase) throws Exception;

ChallengeDetailDto getChallengeDetail(Long challengeId);
ChallengeDetailDto getChallengeDetail(Long challengeId);

Long getNumberOfRegistrants(Long challengeId);
Long getNumberOfRegistrants(Long challengeId);

void sendApplicationEmailToContestant(ChallengeEntity challengeEntity, ChallengeRegistrantEntity challengeRegistrantEntity)
throws MessagingException, IOException, TemplateException;
void sendApplicationEmailToContestant(ChallengeEntity challengeEntity, ChallengeRegistrantEntity challengeRegistrantEntity)
throws MessagingException, IOException, TemplateException;

void sendApplicationEmailToEmployer(ChallengeEntity challengeEntity, ChallengeRegistrantEntity challengeRegistrantEntity)
throws MessagingException, IOException, TemplateException;
void sendApplicationEmailToEmployer(ChallengeEntity challengeEntity, ChallengeRegistrantEntity challengeRegistrantEntity)
throws MessagingException, IOException, TemplateException;

long joinChallenge(ChallengeRegistrantDto challengeRegistrantDto) throws MessagingException, IOException, TemplateException;
long joinChallenge(ChallengeRegistrantDto challengeRegistrantDto) throws MessagingException, IOException, TemplateException;

List<ChallengeDetailDto> listChallenges();
List<ChallengeDetailDto> listChallenges();

List<ChallengeDetailDto> listChallenges(String ownerEmail);
List<ChallengeDetailDto> listChallenges(String ownerEmail);

List<ChallengeEntity> listChallengesByPhase(ChallengePhaseEnum challengePhase);
List<ChallengeEntity> listChallengesByPhase(ChallengePhaseEnum challengePhase);

Long getTotalNumberOfChallenges();
Long getTotalNumberOfChallenges();

Double getTotalAmountOfPrizeValues();
Double getTotalAmountOfPrizeValues();

Long getTotalNumberOfRegistrants();
Long getTotalNumberOfRegistrants();

ChallengeDetailDto getTheLatestChallenge();
ChallengeDetailDto getTheLatestChallenge();

Collection<ChallengeDetailDto> findByOwnerAndCondition(String owner, Predicate<? super ChallengeEntity> condition);
Collection<ChallengeDetailDto> findByOwnerAndCondition(String owner, Predicate<? super ChallengeEntity> condition);

Collection<ChallengeDetailDto> findInProgressChallenges(String owner);
Collection<ChallengeDetailDto> findInProgressChallenges(String owner);

// Collection<ChallengeRegistrantDto> findRegistrantsByChallengeId(Long challengeId);

Long countRegistrantsByChallengeId(Long challengeId);
Long countRegistrantsByChallengeId(Long challengeId);

boolean delete(Long id, String ownerEmail);
boolean delete(Long id, String ownerEmail);

ChallengeDto findChallengeById(Long id);
ChallengeDto findChallengeById(Long id);

Set<ChallengeRegistrantDto> findRegistrantsByOwner(String ownerEmail, Long challengeId);
Set<ChallengeRegistrantDto> findRegistrantsByOwner(String ownerEmail, Long challengeId);

ChallengeRegistrantDto saveRegistrant(String ownerEmail, ChallengeRegistrantDto challengeRegistrantDto);
ChallengeRegistrantDto saveRegistrant(String ownerEmail, ChallengeRegistrantDto challengeRegistrantDto);

List<ChallengeRegistrantEntity> findChallengeRegistrantWithinPeriod(
Long challengeId, Long currentDateTime, TimePeriodEnum period);
List<ChallengeRegistrantEntity> findChallengeRegistrantWithinPeriod(
Long challengeId, Long currentDateTime, TimePeriodEnum period);

List<ChallengeSubmissionEntity> findChallengeSubmissionWithinPeriod(
Long challengeId, Long currentDateTime, TimePeriodEnum period);
List<ChallengeSubmissionEntity> findChallengeSubmissionWithinPeriod(
Long challengeId, Long currentDateTime, TimePeriodEnum period);

void sendDailySummaryEmailToChallengeOwner(ChallengeEntity challengeEntity) throws Exception;

boolean isOwnerOfChallenge(String ownerEmail, Long challengeId);

boolean sendEmailToDailyChallengeRegistrants(String challengeOwner, Long challengeId, Long now, EmailContent emailContent);

boolean sendEmailToRegistrant(String challengeOwner, Long challengeId, Long registrantId, EmailContent emailContent);

void sendDailySummaryEmailToChallengeOwner(ChallengeEntity challengeEntity) throws Exception;
}
11 changes: 11 additions & 0 deletions src/main/java/com/techlooper/service/EmailService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.techlooper.service;

import com.techlooper.model.EmailContent;

/**
* Created by phuonghqh on 10/1/15.
*/
public interface EmailService {

boolean sendEmail(EmailContent emailContent);
}
Loading

0 comments on commit 96f1508

Please sign in to comment.