Skip to content

Commit

Permalink
Merge pull request #376 from khoa-nd/master
Browse files Browse the repository at this point in the history
Merged
  • Loading branch information
khoa-nd committed Aug 27, 2015
2 parents fe144c2 + e1f907c commit 0ee9a53
Show file tree
Hide file tree
Showing 30 changed files with 316 additions and 157 deletions.
49 changes: 9 additions & 40 deletions src/main/java/com/techlooper/config/CoreConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,6 @@ public class CoreConfiguration implements ApplicationContextAware {

@Value("classpath:google-auth/techLooper.p12")
private org.springframework.core.io.Resource googleApiAuthResource;
// @Value("classpath:google-auth")
// private org.springframework.core.io.Resource googleApiAuthResource;

private ApplicationContext applicationContext;

Expand Down Expand Up @@ -392,13 +390,18 @@ public JsonNode vietnamworksConfiguration() throws IOException {

@Bean
@DependsOn("jsonConfigRepository")
public SocialConfig googleSocialConfig() {
return applicationContext.getBean(JsonConfigRepository.class).getSocialConfig().stream()
.filter(socialConfig -> socialConfig.getProvider() == SocialProvider.GOOGLE)
.findFirst().get();
}

@Bean
public Calendar googleCalendar() throws GeneralSecurityException, IOException {
JacksonFactory jsonFactory = JacksonFactory.getDefaultInstance();
HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport();

SocialConfig googleConfig = applicationContext.getBean(JsonConfigRepository.class).getSocialConfig().stream()
.filter(socialConfig -> socialConfig.getProvider() == SocialProvider.GOOGLE)
.findFirst().get();
SocialConfig googleConfig = googleSocialConfig();

// GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(transport, jsonFactory,
// googleConfig.getApiKey(), googleConfig.getSecretKey(),
Expand All @@ -417,45 +420,11 @@ public Calendar googleCalendar() throws GeneralSecurityException, IOException {
.setServiceAccountId(googleConfig.getServiceAccountEmail())
.setServiceAccountPrivateKeyFromP12File(googleApiAuthResource.getFile())
.setServiceAccountScopes(Collections.singleton(CalendarScopes.CALENDAR))
.setServiceAccountUser("[email protected]")
.setServiceAccountUser(googleConfig.getCalendarOwner())
.build();

// boolean bool = credential.refreshToken();
// String token = credential.getAccessToken();
// System.out.println(bool);
// System.out.println(token);

return new Calendar.Builder(transport, jsonFactory, credential)
.setApplicationName("Techlooper").build();

// Event event = new Event()
// .setSummary("Google I/O 2015")
// .setLocation("800 Howard St., San Francisco, CA 94103")
// .setDescription("A chance to hear more about Google's developer products.");
//
// DateTime startDateTime = new DateTime("2015-09-28T09:00:00-07:00");
// EventDateTime start = new EventDateTime()
// .setDateTime(startDateTime)
// .setTimeZone("America/Los_Angeles");
// event.setStart(start);
//
// DateTime endDateTime = new DateTime("2015-09-28T17:00:00-07:00");
// EventDateTime end = new EventDateTime()
// .setDateTime(endDateTime)
// .setTimeZone("America/Los_Angeles");
// event.setEnd(end);
//
// EventAttendee[] attendees = new EventAttendee[]{
// new EventAttendee().setEmail("[email protected]"),
// new EventAttendee().setEmail("[email protected]"),
// };
// event.setAttendees(Arrays.asList(attendees));
//
// String calendarId = "[email protected]";
// event = calendar.events().insert(calendarId, event).setSendNotifications(true).execute();
// System.out.printf("Event created: %s\n", event.getHtmlLink());
// event.getHangoutLink()
// return calendar;
}

public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Authentication authenticate(Authentication authentication) throws Authent
}
}
catch (Exception ex) {
LOGGER.debug(ex.getMessage(), ex);
LOGGER.debug(ex.getMessage());
}

return providers.get(SocialProvider.VIETNAMWORKS).authenticate(authentication);
Expand Down
49 changes: 46 additions & 3 deletions src/main/java/com/techlooper/controller/JobListingController.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.techlooper.controller;

import com.techlooper.model.JobListingCriteria;
import com.techlooper.model.JobListingModel;
import com.techlooper.model.JobResponse;
import com.techlooper.model.*;
import com.techlooper.service.JobAlertService;
import com.techlooper.service.JobSearchService;
import com.techlooper.service.ScrapeJobService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
Expand All @@ -18,9 +19,17 @@
@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 {
Expand All @@ -37,4 +46,38 @@ public JobListingModel list(@RequestBody JobListingCriteria criteria) throws Exc
return jobListing;
}

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

vnwJobSearchRequest = getNormalJobSearchRequest();
vnwJobSearchResponse = vietnamWorksJobSearchService.searchJob(vnwJobSearchRequest);
if (vnwJobSearchResponse.hasData()) {
scrapeJobService.save(vnwJobSearchResponse.getData().getJobs(), Boolean.FALSE);
}

}

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ public WebinarInfoDto findWebinarById(@PathVariable Long id) {
}

@RequestMapping(value = "user/webinar/join", method = RequestMethod.POST)
public WebinarInfoDto joinWebinar(@RequestBody JoinBySocialDto joinBySocialDto) {
public WebinarInfoDto joinWebinar(@RequestBody JoinBySocialDto joinBySocialDto) throws IOException {
return webinarService.joinWebinar(joinBySocialDto);
}
}
39 changes: 39 additions & 0 deletions src/main/java/com/techlooper/entity/CalendarInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.techlooper.entity;

import java.io.Serializable;

/**
* Created by phuonghqh on 8/27/15.
*/
public class CalendarInfo implements Serializable {

private String id;

private String htmlLink;

private String hangoutLink;

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getHtmlLink() {
return htmlLink;
}

public void setHtmlLink(String htmlLink) {
this.htmlLink = htmlLink;
}

public String getHangoutLink() {
return hangoutLink;
}

public void setHangoutLink(String hangoutLink) {
this.hangoutLink = hangoutLink;
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/techlooper/entity/ScrapeJobEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@

import java.util.List;

import static org.springframework.data.elasticsearch.annotations.FieldType.Boolean;
import static org.springframework.data.elasticsearch.annotations.FieldType.Long;
import static org.springframework.data.elasticsearch.annotations.FieldType.*;
import static org.springframework.data.elasticsearch.annotations.FieldType.String;

@Document(indexName = "techlooper", type = "job")
public class ScrapeJobEntity {

@Id
private String jobId;

@Field(type = String, index = FieldIndex.not_analyzed)
private String jobTitleUrl;

@Field(type = String)
Expand Down Expand Up @@ -50,6 +56,14 @@ public class ScrapeJobEntity {
@Field(type = Nested)
private List<JobSkill> skills;

public String getJobId() {
return jobId;
}

public void setJobId(String jobId) {
this.jobId = jobId;
}

public String getJobTitleUrl() {
return jobTitleUrl;
}
Expand Down
45 changes: 22 additions & 23 deletions src/main/java/com/techlooper/entity/WebinarEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import java.util.Collection;
import java.util.Date;
import java.util.Set;

/**
* Created by phuonghqh on 8/18/15.
Expand All @@ -29,23 +30,37 @@ public class WebinarEntity {
private String description;

@Field(type = FieldType.Nested)
private Collection<UserProfileDto> attendees;
private Set<UserProfileDto> attendees;

@Field(type = FieldType.Nested)
private UserProfileDto organiser;

@Field(type = FieldType.String, index = FieldIndex.not_analyzed)
private String where = "Google Hangout";

@Field(type = FieldType.String, index = FieldIndex.not_analyzed)
private String calendarUrl;
@Field(type = FieldType.Nested)
private CalendarInfo calendarInfo;

@Field(type = FieldType.String, index = FieldIndex.not_analyzed)
private String hangoutLink;
// @Field(type = FieldType.String, index = FieldIndex.not_analyzed)
// private String calendarUrl;
//
// @Field(type = FieldType.String, index = FieldIndex.not_analyzed)
// private String hangoutLink;
//
// @Field(type = FieldType.String, index = FieldIndex.not_analyzed)
// private String eventId;

@Field(type = FieldType.String)
private String whatEvent;

public CalendarInfo getCalendarInfo() {
return calendarInfo;
}

public void setCalendarInfo(CalendarInfo calendarInfo) {
this.calendarInfo = calendarInfo;
}

public Long getCreatedDateTime() {
return createdDateTime;
}
Expand Down Expand Up @@ -86,11 +101,11 @@ public void setDescription(String description) {
this.description = description;
}

public Collection<UserProfileDto> getAttendees() {
public Set<UserProfileDto> getAttendees() {
return attendees;
}

public void setAttendees(Collection<UserProfileDto> attendees) {
public void setAttendees(Set<UserProfileDto> attendees) {
this.attendees = attendees;
}

Expand All @@ -110,22 +125,6 @@ public void setWhere(String where) {
this.where = where;
}

public String getCalendarUrl() {
return calendarUrl;
}

public void setCalendarUrl(String calendarUrl) {
this.calendarUrl = calendarUrl;
}

public String getHangoutLink() {
return hangoutLink;
}

public void setHangoutLink(String hangoutLink) {
this.hangoutLink = hangoutLink;
}

public String getWhatEvent() {
return whatEvent;
}
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/com/techlooper/model/SocialConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ public class SocialConfig {

private String serviceAccountEmail;

private String calendarId;

private String calendarOwner;

public String getCalendarOwner() {
return calendarOwner;
}

public void setCalendarOwner(String calendarOwner) {
this.calendarOwner = calendarOwner;
}

public String getCalendarId() {
return calendarId;
}

public void setCalendarId(String calendarId) {
this.calendarId = calendarId;
}

public String getServiceAccountEmail() {
return serviceAccountEmail;
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/techlooper/model/UserProfileDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import com.techlooper.entity.vnw.RoleName;

import java.io.Serializable;

/**
* Created by NguyenDangKhoa on 7/30/15.
*/
public class UserProfileDto {
public class UserProfileDto implements Serializable {

private String username;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class VNWJobSearchResponseDataItem {

public static final String JOB_LEVEL = "top_level";

@JsonProperty(value = "job_id")
private Long jobId;

@JsonProperty(value = "job_detail_url")
private String url;

Expand Down Expand Up @@ -51,6 +54,14 @@ public class VNWJobSearchResponseDataItem {
@JsonProperty(value = "skills")
private List<JobSkill> skills;

public Long getJobId() {
return jobId;
}

public void setJobId(Long jobId) {
this.jobId = jobId;
}

public String getUrl() {
return url;
}
Expand Down
Loading

0 comments on commit 0ee9a53

Please sign in to comment.