Skip to content

Commit

Permalink
Merge pull request #438 from phuonghuynh/master
Browse files Browse the repository at this point in the history
Update changes
  • Loading branch information
phuonghuynh committed Oct 22, 2015
2 parents eb919a8 + 19e5ae1 commit 9e93937
Show file tree
Hide file tree
Showing 76 changed files with 1,053 additions and 1,240 deletions.
3 changes: 2 additions & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@
"angular-strap": "latest",
"datetimepicker": "latest",
"angular-summernote": "latest",
"underscore": "latest"
"underscore": "latest",
"numeral": "latest"
},
"overrides": {
"jquery": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.techlooper.config;

import org.elasticsearch.client.transport.TransportClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -28,8 +26,6 @@ public class ElasticsearchUserImportConfiguration {
@Resource
private TransportClient transportClientUserImport;

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

@Bean
public FactoryBean<TransportClient> transportClientUserImport() throws Exception {
TransportClientFactoryBean factory = new TransportClientFactoryBean();
Expand Down
44 changes: 20 additions & 24 deletions src/main/java/com/techlooper/config/web/WebConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.techlooper.config.web;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
Expand All @@ -17,39 +16,36 @@
@ComponentScan(basePackages = {"com.techlooper.controller"})
public class WebConfiguration extends WebMvcConfigurerAdapter {

@Resource
private Environment environment;
@Resource
private Environment environment;

@Resource
private ApplicationContext applicationContext;
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}

public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("index.html");
}

public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("index.html");
}
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setSuffix("");
return viewResolver;
}

@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setSuffix("");
return viewResolver;
}
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/talentsearch/**").addResourceLocations("/rs/");

public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/talentsearch/**").addResourceLocations("/rs/");

registry.addResourceHandler("/**")
.addResourceLocations(environment.getProperty("webapp.resource.location"))
.resourceChain(true).addResolver(new GzipResourceResolver());
registry.addResourceHandler("/**")
.addResourceLocations(environment.getProperty("webapp.resource.location"))
.resourceChain(true).addResolver(new GzipResourceResolver());

// CacheManager cacheManager = applicationContext.getBean(CacheManager.class);
// if (ArrayUtils.contains(environment.getActiveProfiles(), "prod")) {
// resourceChainRegistration.addResolver(new CachingResourceResolver(cacheManager, "default"))
// .addTransformer(new CachingResourceTransformer(cacheManager, "default"))
// .addTransformer(new CssLinkResourceTransformer());
// }
}
}
}
214 changes: 111 additions & 103 deletions src/main/java/com/techlooper/controller/ChallengeController.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,114 +26,122 @@
@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);

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

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);
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) throws Exception {
return challengeService.findChallengeById(challengeId);
}

@PreAuthorize("hasAuthority('EMPLOYER')")
@RequestMapping(value = "/challenges/{challengeId}/registrants", method = RequestMethod.POST)
public Set<ChallengeRegistrantDto> getRegistrantsById(@PathVariable Long challengeId, @RequestBody RegistrantFilterCondition condition, HttpServletRequest request) throws ParseException {
condition.setAuthorEmail(request.getRemoteUser());
return challengeService.findRegistrantsByOwner(condition);
else {
challengeService.sendPostChallengeEmailToTechloopies(challengeEntity, Boolean.FALSE);
}


@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 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 = "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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
import com.techlooper.model.ChallengeRegistrantCriteriaDto;
import com.techlooper.service.ChallengeCriteriaService;
import org.springframework.security.access.prepost.PreAuthorize;
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;
import javax.servlet.http.HttpServletRequest;
Expand All @@ -19,29 +16,38 @@
@RestController
public class ChallengeCriteriaController {

@Resource
private ChallengeCriteriaService challengeCriteriaService;

@PreAuthorize("hasAuthority('EMPLOYER')")
@RequestMapping(value = "challenge/criteria", method = RequestMethod.POST)
public ChallengeCriteriaDto saveChallengeCriteria(@RequestBody ChallengeCriteriaDto challengeCriteriaDto, HttpServletRequest request, HttpServletResponse response) {
ChallengeCriteriaDto result = challengeCriteriaService.saveChallengeCriteria(challengeCriteriaDto, request.getRemoteUser());
if (result == null) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
@Resource
private ChallengeCriteriaService challengeCriteriaService;

@PreAuthorize("hasAuthority('EMPLOYER')")
@RequestMapping(value = "challenge/criteria", method = RequestMethod.POST)
public ChallengeCriteriaDto saveChallengeCriteria(@RequestBody ChallengeCriteriaDto challengeCriteriaDto, HttpServletRequest request, HttpServletResponse response) {
ChallengeCriteriaDto result = challengeCriteriaService.saveChallengeCriteria(challengeCriteriaDto, request.getRemoteUser());
if (result == null) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
return result;
}
return result;
}

@PreAuthorize("hasAuthority('EMPLOYER')")
@RequestMapping(value = "challengeRegistrant/criteria", method = RequestMethod.POST)
public ChallengeRegistrantCriteriaDto saveChallengeRegistrantCriteria(@RequestBody ChallengeRegistrantCriteriaDto registrantCriteriaDto,
HttpServletRequest request, HttpServletResponse response) {
ChallengeRegistrantCriteriaDto result = challengeCriteriaService.saveScoreChallengeRegistrantCriteria(registrantCriteriaDto, request.getRemoteUser());
if (result == null) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
@PreAuthorize("hasAuthority('EMPLOYER')")
@RequestMapping(value = "challengeRegistrant/criteria", method = RequestMethod.POST)
public ChallengeRegistrantCriteriaDto saveChallengeRegistrantCriteria(@RequestBody ChallengeRegistrantCriteriaDto registrantCriteriaDto,
HttpServletRequest request, HttpServletResponse response) {
ChallengeRegistrantCriteriaDto result = challengeCriteriaService.saveScoreChallengeRegistrantCriteria(registrantCriteriaDto, request.getRemoteUser());
if (result == null) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
return result;
}
return result;
}


@PreAuthorize("hasAuthority('EMPLOYER')")
@RequestMapping(value = "challengeRegistrant/{registrantId}/criteria", method = RequestMethod.GET)
public ChallengeRegistrantCriteriaDto findByChallengeRegistrantId(@PathVariable Long registrantId, HttpServletRequest request, HttpServletResponse response) {
String ownerEmail = request.getRemoteUser();
ChallengeRegistrantCriteriaDto result = challengeCriteriaService.findByChallengeRegistrantId(registrantId, ownerEmail);
if (result == null) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
}
return result;
}
}
Loading

0 comments on commit 9e93937

Please sign in to comment.