Skip to content

Commit

Permalink
Merge pull request #439 from khoa-nd/master
Browse files Browse the repository at this point in the history
Merged
  • Loading branch information
khoa-nd committed Oct 23, 2015
2 parents 9e93937 + 350d50a commit b4f13cf
Show file tree
Hide file tree
Showing 12 changed files with 159 additions and 123 deletions.
224 changes: 113 additions & 111 deletions src/main/java/com/techlooper/controller/ChallengeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,122 +26,124 @@
@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);
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);
}
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;
}
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);
}
}
catch (Exception ex) {
LOGGER.error(ex.getMessage(), ex);
}
}
else {
challengeService.sendPostChallengeEmailToTechloopies(challengeEntity, Boolean.FALSE);

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

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) throws Exception {
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);
}

@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();
}
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();
}
}
5 changes: 5 additions & 0 deletions src/main/java/com/techlooper/util/EmailValidator.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.techlooper.util;

import org.apache.commons.lang3.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -20,6 +22,9 @@ public class EmailValidator {
private static Matcher matcher;

public static boolean validate(final String email) {
if (StringUtils.isEmpty(email)) {
return false;
}
matcher = pattern.matcher(email);
return matcher.matches();
}
Expand Down
3 changes: 1 addition & 2 deletions src/main/webapp/assets/modules/common/apiService.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ techlooper.factory("apiService", function ($rootScope, $location, jsonValue, $ht
getProjects: function () {
return $http.get("project/list");
},

joinNowByFB: function () {
$('.loading-data').css("height", $(window).height());
$('body').addClass('noscroll');
Expand All @@ -86,7 +85,7 @@ techlooper.factory("apiService", function ($rootScope, $location, jsonValue, $ht
localStorageService.set("lastFoot", $location.url());
localStorageService.set("joinNow", true);
window.location = url;
});
})
},

joinProject: function (projectId, firstName, lastName, email, phoneNumber, resumeLink, lang) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
translate="requiredThisField" />
</div>
<div class="evaluation-criteria-weight">
<input name="weight" type="text" class="input-style" ng-model="cri.weight" ng-required="true" input-number=""/>
<input name="weight" type="text" class="input-style"
ng-class="{'input-error': cri.weight > 100}"
ng-model="cri.weight" ng-required="true" input-number="" maxlength="3"/>
<button data-auto-close="true" ng-show="cri.weight >= 0"
data-placement="top" class="btn btn-primary btn-flat gray"
data-template-url="modules/contest-detail/remove-criteria-item.html" bs-popover>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ <h3 translate="currentPhase"/>
<div class="alert alert-success" ng-show="!status('already-join')">
<p translate="congratulationsForJoinContest"></p>
</div>
<div class="alert alert-danger" ng-show="failJoin == true">
<p translate="errorSystem"></p>
</div>
<div class="row registration-count">
<div class="col-md-12">
<p translate="registerNumber"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ techlooper.controller('contestDetailController', function ($scope, apiService, l
title = utils.toAscii(title);
return $location.url(sprintf("/challenge-detail/%s-%s-id", title, contestId));
}

$scope.failJoin = false;
$scope.action = '';
$scope.actionContent = '';
$scope.status = function (type, id) {
Expand All @@ -33,6 +33,7 @@ techlooper.controller('contestDetailController', function ($scope, apiService, l
var joinContests = localStorageService.get("joinContests") || "";
var email = localStorageService.get("email") || "";
var hasJoined = (joinContests.indexOf(contestId) >= 0) && (email.length > 0);
failJoin = false;
return !hasJoined;

case "contest-in-progress":
Expand Down Expand Up @@ -100,6 +101,9 @@ techlooper.controller('contestDetailController', function ($scope, apiService, l
localStorageService.set("joinContests", joinContests.join(","));
$filter("progress")($scope.contestDetail, "challenge");
$scope.filterContestant();
})
.error(function(){
$scope.failJoin = true;
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</li>
<li ng-repeat="cri in registrant.criteriaLoop()">
<div class="points-name">
<label class="label-col" translate="criteriaName"></label>
<label class="label-col name" translate="criteriaName"></label>
{{cri.name}}
</div>
<div class="weight-input">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<p translate="evaluationCriteriaDes"></p>

<div class="alert alert-success" ng-show="contestDetail.$savedCriteria">
<p translate="emailSettingSuccessfully"></p>
<p translate="updateEvaluationCriteria"></p>
</div>
<!--<div class="alert alert-danger" ng-show="!contestDetail.$savedCriteria">-->
<!--<p translate="errorSystem"></p>-->
Expand All @@ -12,7 +12,7 @@
<p translate="criteriaName"></p>
</div>
<div class="evaluation-criteria-weight">
<p translate="criteriaWeight"></p>
<p translate="criteriaWeight1"></p>
</div>
</div>
<div class="evaluation-criteria-body">
Expand Down
6 changes: 4 additions & 2 deletions src/main/webapp/assets/modules/translation/messages_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -792,6 +792,7 @@
"evaluationCriteria": "Evaluation Criteria",
"criteriaName": "Criteria Name",
"criteriaWeight": "Weight %",
"criteriaWeight1": "Weight <br/>0% - 100%",
"criteriaTotalWeight": "Total weight %",
"maximumScore": "Maximum Score",
"emailSetting": "Email Setting",
Expand All @@ -808,9 +809,10 @@
"errorSystem": "Error system. Please try again later.",
"errorTotalWeight": "Total weight must be 100%.",
"replyEmailTooltip": "This email address will be displayed as 'Reply-To' of emails which are sent to contestants by Feedback feature of your challenges.",
"emailSignatureTooltip": "You can define your own signature of emails sent to contestants by Feedback feature of your challenges. The signature is displayed at where variable [[mail_signature]] appears in email body.",
"emailSignatureTooltip": "You can define your own signature of emails sent to contestants by Feedback feature of your challenges. The signature is displayed at where variable {mail_signature} appears in email body.",
"noEvaluationCriteria": "No criteria found. Please go to “<strong>Evaluation Criteria</strong>” tab to define your scoring criteria.
",
"removeConfirmation": "Removing this criteria will impact all contestants' scores you gave already. <br/><strong>Are you sure you want to remove it?</strong>",
"totalScoreIs": "Total score is",
"emailSettingDescription": "Configure settings to personalize emails to tech talents"
"emailSettingDescription": "Configure settings to personalize emails to tech talents",
"updateEvaluationCriteria": "Scoring criteria are updated."
}
Loading

0 comments on commit b4f13cf

Please sign in to comment.