Skip to content

Commit

Permalink
Merge pull request #392 from phuonghuynh/master
Browse files Browse the repository at this point in the history
Update changes
  • Loading branch information
phuonghuynh committed Sep 3, 2015
2 parents cd332e7 + ca9c837 commit 8bb3078
Show file tree
Hide file tree
Showing 32 changed files with 1,927 additions and 1,286 deletions.
17 changes: 16 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,20 @@ module.exports = function (grunt) {
dest: '<%=pkg.public%>images'
}]
}
},

cache_control: {
build: {
source: "<%=pkg.public%>index.html",
options: {
version: timestamp,
links: true,
scripts: true,
replace: false,
outputDest: "<%=pkg.public%>index.html",
dojoCacheBust: true
}
}
}
});

Expand All @@ -262,7 +276,8 @@ module.exports = function (grunt) {
"copy:font",
"clean:release",
"replace:cssConcat",
"rename:build"
"rename:build",
"cache_control:build"
]);

grunt.registerTask("local", [
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"grunt-text-replace": "latest",
"matchdep": "latest",
"grunt-contrib-imagemin": "latest",
"grunt-contrib-rename": "latest"
"grunt-contrib-rename": "latest",
"grunt-cache-control": "latest"
},
"assets": "src/main/webapp/assets/",
"public": "src/main/webapp/public/"
Expand Down
754 changes: 380 additions & 374 deletions src/main/java/com/techlooper/config/CoreConfiguration.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.techlooper.config;

import com.techlooper.model.JobResponse;
import com.zaxxer.hikari.HikariDataSource;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVRecord;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand All @@ -16,16 +19,22 @@

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
* Created by phuonghqh on 6/25/15.
*/
@Profile("has-db")
@Profile("prod")
@Configuration
@EnableJpaAuditing
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = "com.techlooper.repository.vnw")
public class VmwDbConfiguration {
public class VnwDbConfiguration {

@Value("${vietnamworks.db.driverClass}")
private String driverClass;
Expand All @@ -42,17 +51,12 @@ public class VmwDbConfiguration {
@Value("${vietnamworks.db.pool.size}")
private Integer size;


@Value("classpath:topPriorityJobId.csv")
private org.springframework.core.io.Resource topPriorityJobIdResource;

@Bean
public DataSource dataSource() throws Exception {
// BasicDataSource dataSource = new BasicDataSource();
// dataSource.setDriverClassName(driverClass);
// dataSource.setUrl(jdbcUrl);
// dataSource.setUsername(user);
// dataSource.setPassword(password);
// if (dataSource.getConnection() == null) {
// throw new SQLException();
// }
// return dataSource;

HikariDataSource dataSource = new HikariDataSource();
dataSource.setJdbcUrl(jdbcUrl);
Expand All @@ -65,6 +69,17 @@ public DataSource dataSource() throws Exception {
return dataSource;
}

//TODO refactor top job priority
@Bean
public Set<String> topPriorityJobIds() throws IOException {
Iterable<CSVRecord> records = CSVFormat.DEFAULT.parse(new FileReader(topPriorityJobIdResource.getFile()));
Set<String> ids = new HashSet<>();
for (CSVRecord record : records) {
ids.add(record.get(0));
}
return ids;
}

@Bean
public JpaTransactionManager transactionManager(EntityManagerFactory emf) {
return new JpaTransactionManager(emf);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,10 @@
package com.techlooper.config.web;

import com.techlooper.config.CoreConfiguration;
import com.techlooper.config.VmwDbConfiguration;
import com.techlooper.config.VnwDbConfiguration;
import com.techlooper.config.web.sec.SecurityConfiguration;
import org.omg.CORBA.Environment;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.ObjectUtils;
import org.springframework.util.SystemPropertyUtils;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;

public class DispatcherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
Expand All @@ -47,7 +38,7 @@ protected Class<?>[] getRootConfigClasses() {
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[]{
CoreConfiguration.class,
VmwDbConfiguration.class,
VnwDbConfiguration.class,
WebConfiguration.class,
SecurityConfiguration.class
};
Expand Down
29 changes: 20 additions & 9 deletions src/main/java/com/techlooper/config/web/WebConfiguration.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
package com.techlooper.config.web;

import org.apache.commons.lang.ArrayUtils;
import org.springframework.cache.CacheManager;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import org.springframework.core.env.Environment;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.resource.CachingResourceResolver;
import org.springframework.web.servlet.resource.CachingResourceTransformer;
import org.springframework.web.servlet.resource.CssLinkResourceTransformer;
import org.springframework.web.servlet.resource.GzipResourceResolver;
import org.springframework.web.servlet.view.InternalResourceViewResolver;

Expand All @@ -19,6 +26,9 @@ public class WebConfiguration extends WebMvcConfigurerAdapter {
@Resource
private Environment environment;

@Resource
private ApplicationContext applicationContext;

public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
Expand All @@ -37,14 +47,15 @@ public ViewResolver viewResolver() {
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/talentsearch/**").addResourceLocations("/rs/");

registry.addResourceHandler("/**").addResourceLocations(environment.getProperty("webapp.resource.location"))
.resourceChain(true)
/*
* .addResolver(new CachingResourceResolver(cacheManager,
* "default"))
*/.addResolver(new GzipResourceResolver());
// .addTransformer(new CachingResourceTransformer(cacheManager,
// "default"))
// .addTransformer(new CssLinkResourceTransformer());
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());
// }
}
}
143 changes: 75 additions & 68 deletions src/main/java/com/techlooper/controller/JobListingController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.techlooper.service.JobAlertService;
import com.techlooper.service.JobSearchService;
import com.techlooper.service.ScrapeJobService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -19,73 +21,78 @@
@Controller
public class JobListingController {

private final static String JOB_CATEGORY_IT = "35,55,57";

@Resource
private JobAlertService jobAlertService;

@Resource
private ScrapeJobService scrapeJobService;

@Resource
private JobSearchService vietnamWorksJobSearchService;

@ResponseBody
@RequestMapping(value = "/jobListing", method = RequestMethod.POST)
public JobListingModel list(@RequestBody JobListingCriteria criteria) throws Exception {
JobListingModel jobListing = new JobListingModel();
Long totalJob = jobAlertService.countJob(criteria);
List<JobResponse> jobs = jobAlertService.listJob(criteria);

Long totalPage = totalJob % NUMBER_OF_ITEMS_PER_PAGE == 0 ?
totalJob / NUMBER_OF_ITEMS_PER_PAGE : totalJob / NUMBER_OF_ITEMS_PER_PAGE + 1;
jobListing.setPage(criteria.getPage());
jobListing.setTotalPage(totalPage);
jobListing.setTotalJob(totalJob);
jobListing.setJobs(jobs);
return jobListing;
}

@Scheduled(cron = "${scheduled.cron.indexVietnamworksJob}")
public void indexJobFromVietnamworks() throws Exception {
VNWJobSearchRequest vnwJobSearchRequest = getTopPriorityJobSearchRequest();
VNWJobSearchResponse vnwJobSearchResponse;
do {
vnwJobSearchResponse = vietnamWorksJobSearchService.searchJob(vnwJobSearchRequest);
if (vnwJobSearchResponse.hasData()) {
scrapeJobService.save(vnwJobSearchResponse.getData().getJobs(), Boolean.TRUE);
vnwJobSearchRequest.setPageNumber(vnwJobSearchRequest.getPageNumber() + 1);
}
} while (vnwJobSearchResponse.hasData());

VNWJobSearchRequest vnwNormalJobSearchRequest = getNormalJobSearchRequest();
VNWJobSearchResponse vnwNormalJobSearchResponse;
do {
vnwNormalJobSearchResponse = vietnamWorksJobSearchService.searchJob(vnwNormalJobSearchRequest);
if (vnwNormalJobSearchResponse.hasData()) {
scrapeJobService.save(vnwNormalJobSearchResponse.getData().getJobs(), null);
vnwNormalJobSearchRequest.setPageNumber(vnwNormalJobSearchRequest.getPageNumber() + 1);
}
} while (vnwNormalJobSearchResponse.hasData());

}

private VNWJobSearchRequest getTopPriorityJobSearchRequest() {
VNWJobSearchRequest vnwJobSearchRequest = new VNWJobSearchRequest();
vnwJobSearchRequest.setJobCategories(JOB_CATEGORY_IT);
vnwJobSearchRequest.setTechlooperJobType(1);
vnwJobSearchRequest.setPageNumber(1);
vnwJobSearchRequest.setPageSize(20);
return vnwJobSearchRequest;
}

private VNWJobSearchRequest getNormalJobSearchRequest() {
VNWJobSearchRequest vnwJobSearchRequest = new VNWJobSearchRequest();
vnwJobSearchRequest.setJobCategories(JOB_CATEGORY_IT);
vnwJobSearchRequest.setTechlooperJobType(2);
vnwJobSearchRequest.setPageNumber(1);
vnwJobSearchRequest.setPageSize(20);
return vnwJobSearchRequest;
}
private final static String JOB_CATEGORY_IT = "35,55,57";

@Resource
private JobAlertService jobAlertService;

@Resource
private ScrapeJobService scrapeJobService;

@Resource
private JobSearchService vietnamWorksJobSearchService;

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

@ResponseBody
@RequestMapping(value = "/jobListing", method = RequestMethod.POST)
public JobListingModel list(@RequestBody JobListingCriteria criteria) throws Exception {
JobListingModel jobListing = new JobListingModel();
Long totalJob = jobAlertService.countJob(criteria);
List<JobResponse> jobs = jobAlertService.listJob(criteria);

Long totalPage = totalJob % NUMBER_OF_ITEMS_PER_PAGE == 0 ?
totalJob / NUMBER_OF_ITEMS_PER_PAGE : totalJob / NUMBER_OF_ITEMS_PER_PAGE + 1;
jobListing.setPage(criteria.getPage());
jobListing.setTotalPage(totalPage);
jobListing.setTotalJob(totalJob);
jobListing.setJobs(jobs);
return jobListing;
}

@Scheduled(cron = "${scheduled.cron.indexVietnamworksJob}")
@RequestMapping(value = "/indexJobFromVietnamworks", method = RequestMethod.GET)
public void indexJobFromVietnamworks() throws Exception {
LOGGER.info("START doing index job from vnw");
VNWJobSearchRequest vnwJobSearchRequest = getTopPriorityJobSearchRequest();
VNWJobSearchResponse vnwJobSearchResponse;
do {
vnwJobSearchResponse = vietnamWorksJobSearchService.searchJob(vnwJobSearchRequest);
if (vnwJobSearchResponse.hasData()) {
scrapeJobService.save(vnwJobSearchResponse.getData().getJobs(), Boolean.TRUE);
vnwJobSearchRequest.setPageNumber(vnwJobSearchRequest.getPageNumber() + 1);
}
} while (vnwJobSearchResponse.hasData());

VNWJobSearchRequest vnwNormalJobSearchRequest = getNormalJobSearchRequest();
VNWJobSearchResponse vnwNormalJobSearchResponse;
do {
vnwNormalJobSearchResponse = vietnamWorksJobSearchService.searchJob(vnwNormalJobSearchRequest);
if (vnwNormalJobSearchResponse.hasData()) {
scrapeJobService.save(vnwNormalJobSearchResponse.getData().getJobs(), null);
vnwNormalJobSearchRequest.setPageNumber(vnwNormalJobSearchRequest.getPageNumber() + 1);
}
} while (vnwNormalJobSearchResponse.hasData());

LOGGER.info("DONE doing index job from vnw!!!");
}

private VNWJobSearchRequest getTopPriorityJobSearchRequest() {
VNWJobSearchRequest vnwJobSearchRequest = new VNWJobSearchRequest();
vnwJobSearchRequest.setJobCategories(JOB_CATEGORY_IT);
vnwJobSearchRequest.setTechlooperJobType(1);
vnwJobSearchRequest.setPageNumber(1);
vnwJobSearchRequest.setPageSize(20);
return vnwJobSearchRequest;
}

private VNWJobSearchRequest getNormalJobSearchRequest() {
VNWJobSearchRequest vnwJobSearchRequest = new VNWJobSearchRequest();
vnwJobSearchRequest.setJobCategories(JOB_CATEGORY_IT);
vnwJobSearchRequest.setTechlooperJobType(2);
vnwJobSearchRequest.setPageNumber(1);
vnwJobSearchRequest.setPageSize(20);
return vnwJobSearchRequest;
}

}
14 changes: 7 additions & 7 deletions src/main/java/com/techlooper/controller/JobSearchController.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public VNWJobSearchResponse searchJobAlert(SalaryReviewEntity salaryReviewEntity
// return new VNWJobSearchRequest(jobSearchRequest.getTerms(), category, jobSearchRequest.getPageNumber());
// }

private JobSearchResponse convertToJobSearchResponse(VNWJobSearchResponse vnwJobSearchResponse) {
final JobSearchResponse jobSearchResponse = new JobSearchResponse();
jobSearchResponse.setTotal(vnwJobSearchResponse.getData().getTotal());
final Stream<VNWJobSearchResponseDataItem> responseDataItemStream = vnwJobSearchResponse.getData().getJobs().stream();
jobSearchResponse.setJobs(responseDataItemStream.map(VNWJobSearchResponseDataItem::toJobResponse).collect(Collectors.toSet()));
return jobSearchResponse;
}
// private JobSearchResponse convertToJobSearchResponse(VNWJobSearchResponse vnwJobSearchResponse) {
// final JobSearchResponse jobSearchResponse = new JobSearchResponse();
// jobSearchResponse.setTotal(vnwJobSearchResponse.getData().getTotal());
// final Stream<VNWJobSearchResponseDataItem> responseDataItemStream = vnwJobSearchResponse.getData().getJobs().stream();
// jobSearchResponse.setJobs(responseDataItemStream.map(VNWJobSearchResponseDataItem::toJobResponse).collect(Collectors.toSet()));
// return jobSearchResponse;
// }
}
Loading

0 comments on commit 8bb3078

Please sign in to comment.