Skip to content

Commit

Permalink
Merge pull request #441 from khoa-nd/master
Browse files Browse the repository at this point in the history
Merged
  • Loading branch information
khoa-nd committed Oct 29, 2015
2 parents de6ec9f + 1ed4b65 commit cad9f17
Show file tree
Hide file tree
Showing 20 changed files with 353 additions and 416 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,35 @@ public class DispatcherServletInitializer extends AbstractAnnotationConfigDispat
// @Value("${spring.profiles.active}")
// private String profile;

public void onStartup(ServletContext servletContext) throws ServletException {
super.onStartup(servletContext);
servletContext.getSessionCookieConfig().setMaxAge(15770000);
servletContext.addListener(new SessionListener());
}

protected Class<?>[] getRootConfigClasses() {
return null;
}

protected Class<?>[] getServletConfigClasses() {
return new Class<?>[]{
CoreConfiguration.class,
VnwDbConfiguration.class,
WebConfiguration.class,
SecurityConfiguration.class
};
}

protected String[] getServletMappings() {
return new String[]{"/"};
}

protected void customizeRegistration(Dynamic registration) {
registration.setInitParameter("dispatchOptionsRequest", "true");
}
public void onStartup(ServletContext servletContext) throws ServletException {
super.onStartup(servletContext);
servletContext.getSessionCookieConfig().setMaxAge(15770000);
servletContext.addListener(new SessionListener());
}

protected Class<?>[] getRootConfigClasses() {
return null;
}

protected Class<?>[] getServletConfigClasses() {
return new Class<?>[]{
CoreConfiguration.class,
VnwDbConfiguration.class,
WebConfiguration.class,
SecurityConfiguration.class
};
}

protected String[] getServletMappings() {
return new String[]{"/"};
}

protected void customizeRegistration(Dynamic registration) {
registration.setInitParameter("dispatchOptionsRequest", "true");
}

@Override
protected void registerContextLoaderListener(ServletContext servletContext) {

}
}
276 changes: 137 additions & 139 deletions src/main/java/com/techlooper/controller/ChallengeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,154 +28,152 @@
@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;

@Resource
private ChallengeRegistrantService challengeRegistrantService;

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

@Resource
private ChallengeRegistrantService challengeRegistrantService;

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

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;
}
}
catch (Exception ex) {
LOGGER.error(ex.getMessage(), ex);
}
return challengeService.joinChallenge(joinChallenge);
}
else {
challengeService.sendPostChallengeEmailToTechloopies(challengeEntity, Boolean.FALSE);

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

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;
@RequestMapping(value = "/challenges/{challengeId}", method = RequestMethod.GET)
public ChallengeDto findChallengeById(@PathVariable Long challengeId, HttpServletRequest request) throws Exception {
return challengeService.findChallengeById(challengeId, request.getRemoteUser());
}
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 = "/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);
}
}

@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;


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

@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();
}
else {
response.setStatus(HttpServletResponse.SC_FORBIDDEN);

@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<>();
String ownerEmail = request.getRemoteUser();
if (challengeService.isOwnerOfChallenge(ownerEmail, challengeId)) {
funnel = challengeService.getChallengeRegistrantFunnel(challengeId, ownerEmail);
} else {
response.setStatus(HttpServletResponse.SC_FORBIDDEN);
}
return funnel;
}
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);

@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;
}
return registrants;
}
}
10 changes: 10 additions & 0 deletions src/main/java/com/techlooper/model/ChallengeSubmissionDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ public class ChallengeSubmissionDto implements Serializable {

private String submissionDateTime;

private ChallengePhaseEnum submissionPhase;

public ChallengePhaseEnum getSubmissionPhase() {
return submissionPhase;
}

public void setSubmissionPhase(ChallengePhaseEnum submissionPhase) {
this.submissionPhase = submissionPhase;
}

public Long getChallengeSubmissionId() {
return challengeSubmissionId;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/techlooper/service/ChallengeService.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,5 +107,5 @@ List<ChallengeSubmissionEntity> findChallengeSubmissionWithinPeriod(

ChallengeRegistrantEntity findRegistrantByChallengeIdAndEmail(Long challengeId, String email);

List<ChallengeRegistrantFunnelItem> getChallengeRegistrantFunnel(Long challengeId);
List<ChallengeRegistrantFunnelItem> getChallengeRegistrantFunnel(Long challengeId, String ownerEmail);
}
Loading

0 comments on commit cad9f17

Please sign in to comment.