Skip to content

Commit

Permalink
Merge pull request #440 from khoa-nd/master
Browse files Browse the repository at this point in the history
Merged
  • Loading branch information
khoa-nd committed Oct 28, 2015
2 parents b4f13cf + a949479 commit de6ec9f
Show file tree
Hide file tree
Showing 33 changed files with 2,378 additions and 1,511 deletions.
952 changes: 488 additions & 464 deletions src/main/java/com/techlooper/config/CoreConfiguration.java

Large diffs are not rendered by default.

246 changes: 139 additions & 107 deletions src/main/java/com/techlooper/controller/ChallengeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.techlooper.entity.vnw.VnwUser;
import com.techlooper.model.*;
import com.techlooper.repository.elasticsearch.ChallengeRegistrantRepository;
import com.techlooper.service.ChallengeRegistrantService;
import com.techlooper.service.ChallengeService;
import com.techlooper.service.EmployerService;
import com.techlooper.service.LeadAPIService;
Expand All @@ -20,130 +21,161 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

@RestController
public class ChallengeController {

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

@Resource
private ChallengeService challengeService;

@Resource
private EmployerService employerService;

@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 {
int responseCode = 0;
String employerEmail = servletRequest.getRemoteUser();
challengeDto.setAuthorEmail(employerEmail);
ChallengeEntity challengeEntity = challengeService.savePostChallenge(challengeDto);
boolean newEntity = challengeDto.getChallengeId() == null;
if (newEntity) {
if (challengeEntity != null) {
if (EmailValidator.validate(challengeEntity.getAuthorEmail())) {
challengeService.sendPostChallengeEmailToEmployer(challengeEntity);
}
challengeService.sendPostChallengeEmailToTechloopies(challengeEntity, Boolean.TRUE);
}

// Call Lead Management API to create new lead on CRM system
try {
VnwUser employer = employerService.findEmployerByUsername(employerEmail);
VnwCompany company = employerService.findCompanyById(employer.getCompanyId());
if (employer != null && company != null) {
responseCode = leadAPIService.createNewLead(
employer, company, LeadEventEnum.POST_CHALLENGE, challengeEntity.getChallengeName());

String logMessage = "Create Lead API Response Code : %d ,EmployerID : %d ,CompanyID : %d";
LOGGER.info(String.format(logMessage, responseCode, employer.getUserId(), company.getCompanyId()));
}
} catch (Exception ex) {
LOGGER.error(ex.getMessage(), ex);
}
} else {
challengeService.sendPostChallengeEmailToTechloopies(challengeEntity, Boolean.FALSE);
}
private final static Logger LOGGER = LoggerFactory.getLogger(ChallengeController.class);

return new ChallengeResponse(challengeEntity.getChallengeId(), responseCode);
}
@Resource
private ChallengeService challengeService;

@RequestMapping(value = "/challenge/{challengeId}", method = RequestMethod.GET)
public ChallengeDetailDto getChallengeDetail(@PathVariable Long challengeId, HttpServletRequest request, HttpServletResponse response) throws Exception {
ChallengeDetailDto challengeDetail = challengeService.getChallengeDetail(challengeId, request.getRemoteUser());
if (challengeDetail == null) response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return challengeDetail;
}
@Resource
private EmployerService employerService;

@RequestMapping(value = "/challenge/join", method = RequestMethod.POST)
public long joinChallenge(@RequestBody ChallengeRegistrantDto joinChallenge, HttpServletResponse response) throws Exception {
if (!EmailValidator.validate(joinChallenge.getRegistrantEmail())) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
return 0L;
}
return challengeService.joinChallenge(joinChallenge);
}
@Resource
private LeadAPIService leadAPIService;

@RequestMapping(value = "/challenge/list", method = RequestMethod.GET)
public List<ChallengeDetailDto> listChallenges() throws Exception {
return challengeService.listChallenges();
}
@Resource
private ChallengeRegistrantRepository challengeRegistrantRepository;

@RequestMapping(value = "/challenge/stats", method = RequestMethod.GET)
public ChallengeStatsDto getChallengeStatistics() throws Exception {
ChallengeStatsDto challengeStatsDto = new ChallengeStatsDto();
challengeStatsDto.setNumberOfChallenges(challengeService.getTotalNumberOfChallenges());
challengeStatsDto.setNumberOfRegistrants(challengeService.getTotalNumberOfRegistrants());
challengeStatsDto.setTotalPrizeAmount(challengeService.getTotalAmountOfPrizeValues());
return challengeStatsDto;
}
@Resource
private ChallengeRegistrantService challengeRegistrantService;

@PreAuthorize("hasAuthority('EMPLOYER')")
@RequestMapping(value = "/challenge/{id}", method = RequestMethod.DELETE)
public void deleteChallengeById(@PathVariable Long id, HttpServletRequest request, HttpServletResponse response) {
if (!challengeService.delete(id, request.getRemoteUser())) {
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
@PreAuthorize("hasAuthority('EMPLOYER')")
@RequestMapping(value = "/challenge/publish", method = RequestMethod.POST)
public ChallengeResponse publishChallenge(@RequestBody ChallengeDto challengeDto, HttpServletRequest servletRequest) throws Exception {
int responseCode = 0;
String employerEmail = servletRequest.getRemoteUser();
challengeDto.setAuthorEmail(employerEmail);
ChallengeEntity challengeEntity = challengeService.savePostChallenge(challengeDto);
boolean newEntity = challengeDto.getChallengeId() == null;
if (newEntity) {
if (challengeEntity != null) {
if (EmailValidator.validate(challengeEntity.getAuthorEmail())) {
challengeService.sendPostChallengeEmailToEmployer(challengeEntity);
}
challengeService.sendPostChallengeEmailToTechloopies(challengeEntity, Boolean.TRUE);
}

// Call Lead Management API to create new lead on CRM system
try {
VnwUser employer = employerService.findEmployerByUsername(employerEmail);
VnwCompany company = employerService.findCompanyById(employer.getCompanyId());
if (employer != null && company != null) {
responseCode = leadAPIService.createNewLead(
employer, company, LeadEventEnum.POST_CHALLENGE, challengeEntity.getChallengeName());

String logMessage = "Create Lead API Response Code : %d ,EmployerID : %d ,CompanyID : %d";
LOGGER.info(String.format(logMessage, responseCode, employer.getUserId(), company.getCompanyId()));
}
}
catch (Exception ex) {
LOGGER.error(ex.getMessage(), ex);
}
}

@RequestMapping(value = "/challenges/{challengeId}", method = RequestMethod.GET)
public ChallengeDto findChallengeById(@PathVariable Long challengeId, HttpServletRequest request) throws Exception {
return challengeService.findChallengeById(challengeId, request.getRemoteUser());
else {
challengeService.sendPostChallengeEmailToTechloopies(challengeEntity, Boolean.FALSE);
}

@PreAuthorize("hasAuthority('EMPLOYER')")
@RequestMapping(value = "/challenges/{challengeId}/registrants", method = RequestMethod.POST)
public Set<ChallengeRegistrantDto> getRegistrantsById(@PathVariable Long challengeId, @RequestBody RegistrantFilterCondition condition,
HttpServletRequest request, HttpServletResponse response) throws ParseException {
String owner = request.getRemoteUser();
if (!challengeService.isOwnerOfChallenge(owner, challengeId)) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
return null;
}
condition.setAuthorEmail(owner);
return challengeService.findRegistrantsByOwner(condition);
return new ChallengeResponse(challengeEntity.getChallengeId(), responseCode);
}

@RequestMapping(value = "/challenge/{challengeId}", method = RequestMethod.GET)
public ChallengeDetailDto getChallengeDetail(@PathVariable Long challengeId, HttpServletRequest request, HttpServletResponse response) throws Exception {
ChallengeDetailDto challengeDetail = challengeService.getChallengeDetail(challengeId, request.getRemoteUser());
if (challengeDetail == null) response.setStatus(HttpServletResponse.SC_NOT_FOUND);
return challengeDetail;
}

@RequestMapping(value = "/challenge/join", method = RequestMethod.POST)
public long joinChallenge(@RequestBody ChallengeRegistrantDto joinChallenge, HttpServletResponse response) throws Exception {
if (!EmailValidator.validate(joinChallenge.getRegistrantEmail())) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
return 0L;
}


@PreAuthorize("hasAuthority('EMPLOYER')")
@RequestMapping(value = "/challengeDetail/registrant", method = RequestMethod.POST)
public ChallengeRegistrantDto saveRegistrant(@RequestBody ChallengeRegistrantDto dto, HttpServletRequest request) {
return challengeService.saveRegistrant(request.getRemoteUser(), dto);
return challengeService.joinChallenge(joinChallenge);
}

@RequestMapping(value = "/challenge/list", method = RequestMethod.GET)
public List<ChallengeDetailDto> listChallenges() throws Exception {
return challengeService.listChallenges();
}

@RequestMapping(value = "/challenge/stats", method = RequestMethod.GET)
public ChallengeStatsDto getChallengeStatistics() throws Exception {
ChallengeStatsDto challengeStatsDto = new ChallengeStatsDto();
challengeStatsDto.setNumberOfChallenges(challengeService.getTotalNumberOfChallenges());
challengeStatsDto.setNumberOfRegistrants(challengeService.getTotalNumberOfRegistrants());
challengeStatsDto.setTotalPrizeAmount(challengeService.getTotalAmountOfPrizeValues());
return challengeStatsDto;
}

@PreAuthorize("hasAuthority('EMPLOYER')")
@RequestMapping(value = "/challenge/{id}", method = RequestMethod.DELETE)
public void deleteChallengeById(@PathVariable Long id, HttpServletRequest request, HttpServletResponse response) {
if (!challengeService.delete(id, request.getRemoteUser())) {
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
}

@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();
}

@RequestMapping(value = "/challenges/{challengeId}", method = RequestMethod.GET)
public ChallengeDto findChallengeById(@PathVariable Long challengeId, HttpServletRequest request) throws Exception {
return challengeService.findChallengeById(challengeId, request.getRemoteUser());
}

@PreAuthorize("hasAuthority('EMPLOYER')")
@RequestMapping(value = "/challenges/{challengeId}/registrants", method = RequestMethod.POST)
public Set<ChallengeRegistrantDto> getRegistrantsById(@PathVariable Long challengeId, @RequestBody RegistrantFilterCondition condition,
HttpServletRequest request, HttpServletResponse response) throws ParseException {
String owner = request.getRemoteUser();
if (!challengeService.isOwnerOfChallenge(owner, challengeId)) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
return null;
}
condition.setAuthorEmail(owner);
return challengeService.findRegistrantsByOwner(condition);
}


@PreAuthorize("hasAuthority('EMPLOYER')")
@RequestMapping(value = "/challengeDetail/registrant", method = RequestMethod.POST)
public ChallengeRegistrantDto saveRegistrant(@RequestBody ChallengeRegistrantDto dto, HttpServletRequest request) {
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();
}

@PreAuthorize("hasAuthority('EMPLOYER')")
@RequestMapping(value = "/challenges/{challengeId}/registrantFunnel", method = RequestMethod.GET)
public List<ChallengeRegistrantFunnelItem> getChallengeRegistrantFunnel(@PathVariable Long challengeId,
HttpServletRequest request, HttpServletResponse response) {
List<ChallengeRegistrantFunnelItem> funnel = new ArrayList<>();
if (challengeService.isOwnerOfChallenge(request.getRemoteUser(), challengeId)) {
funnel = challengeService.getChallengeRegistrantFunnel(challengeId);
}
else {
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
}
return funnel;
}

@PreAuthorize("hasAuthority('EMPLOYER')")
@RequestMapping(value = "challenge/{challengeId}/registrants/{phase}", method = RequestMethod.GET)
public Set<ChallengeRegistrantDto> getChallengeRegistrantsByPhase(@PathVariable Long challengeId, @PathVariable ChallengePhaseEnum phase,
HttpServletRequest request, HttpServletResponse response) {
Set<ChallengeRegistrantDto> registrants = challengeRegistrantService.findRegistrantsByChallengeIdAndPhase(challengeId, phase, request.getRemoteUser());
if (registrants == null) {
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
}
return registrants;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.techlooper.controller;

import com.techlooper.entity.ChallengeRegistrantEntity;
import com.techlooper.entity.ChallengeSubmissionEntity;
import com.techlooper.model.ChallengePhaseEnum;
import com.techlooper.model.ChallengeSubmissionDto;
import com.techlooper.service.ChallengeService;
import com.techlooper.service.ChallengeSubmissionService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

Expand All @@ -16,12 +16,23 @@
@RestController
public class ChallengeSubmissionController {

@Resource
private ChallengeSubmissionService challengeSubmissionService;
@Resource
private ChallengeSubmissionService challengeSubmissionService;

@RequestMapping(value = "user/challengeSubmission", method = RequestMethod.POST)
public ChallengeSubmissionEntity submitMyResult(@RequestBody ChallengeSubmissionDto challengeSubmissionDto) {
return challengeSubmissionService.submitMyResult(challengeSubmissionDto);
}
@Resource
private ChallengeService challengeService;

@RequestMapping(value = "user/challengeSubmission", method = RequestMethod.POST)
public ChallengeSubmissionEntity submitMyResult(@RequestBody ChallengeSubmissionDto challengeSubmissionDto) {
return challengeSubmissionService.submitMyResult(challengeSubmissionDto);
}

@RequestMapping(value = "user/challengeSubmissionPhase/{registrantEmail}/{challengeId}", method = RequestMethod.GET)
public ChallengePhaseEnum challengeSubmissionPhase(@PathVariable String registrantEmail, @PathVariable Long challengeId) {
ChallengeRegistrantEntity registrantEntity =
challengeService.findRegistrantByChallengeIdAndEmail(challengeId, registrantEmail);
return (registrantEntity != null && registrantEntity.getActivePhase() != null) ?
registrantEntity.getActivePhase() : ChallengePhaseEnum.REGISTRATION;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
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;
Expand All @@ -23,7 +22,6 @@

import static com.techlooper.util.DateTimeUtils.*;

@Service
public class ChallengeTimelineNotifier {

private final static Logger LOGGER = LoggerFactory.getLogger(ChallengeTimelineNotifier.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
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;
Expand All @@ -18,7 +17,6 @@

import static com.techlooper.util.DateTimeUtils.*;

@Service
public class DailyChallengeSummaryEmailSender {

private final static Logger LOGGER = LoggerFactory.getLogger(DailyChallengeSummaryEmailSender.class);
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/techlooper/cron/JobAlertEmailSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
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.Date;
Expand All @@ -27,7 +26,6 @@
* @author Khoa Nguyen
* @version v0.0-beta9.Release39, 09/09/2015
*/
@Service
public class JobAlertEmailSender {

private final static Logger LOGGER = LoggerFactory.getLogger(JobAlertEmailSender.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

Expand All @@ -17,7 +16,6 @@
* @author Khoa Nguyen
* @version v0.0-beta9.Release39, 09/09/2015
*/
@Service
public class VietnamworksJobImporter {

private final static Logger LOGGER = LoggerFactory.getLogger(VietnamworksJobImporter.class);
Expand Down
Loading

0 comments on commit de6ec9f

Please sign in to comment.