Skip to content

Commit

Permalink
Merge pull request #166 from khoa-nd/master
Browse files Browse the repository at this point in the history
Merged
  • Loading branch information
khoa-nd committed Feb 11, 2015
2 parents ef33657 + 71d4a5c commit 4d7ef31
Show file tree
Hide file tree
Showing 16 changed files with 1,608 additions and 80 deletions.
27 changes: 9 additions & 18 deletions src/main/java/com/techlooper/controller/UserController.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package com.techlooper.controller;

import com.techlooper.entity.userimport.UserImportEntity;
import com.techlooper.model.SocialProvider;
import com.techlooper.model.SocialRequest;
import com.techlooper.model.UserImportData;
import com.techlooper.model.UserInfo;
import com.techlooper.service.SocialService;
import com.techlooper.service.UserImportDataProcessor;
import com.techlooper.service.UserService;
import com.techlooper.util.EmailValidator;
import org.apache.commons.lang3.StringUtils;
import org.jasypt.util.text.TextEncryptor;
import org.springframework.context.ApplicationContext;
import org.springframework.messaging.handler.annotation.MessageMapping;
Expand All @@ -21,7 +19,7 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Iterator;
import java.util.Arrays;
import java.util.List;

/**
Expand All @@ -42,7 +40,11 @@ public class UserController {
@ResponseBody
@RequestMapping(value = "/api/users/add", method = RequestMethod.POST)
public void save(@RequestBody UserImportData userImportData, HttpServletResponse httpServletResponse) {
httpServletResponse.setStatus(userService.addCrawledUser(userImportData) ?
SocialProvider provider = userImportData.getCrawlerSource();
UserImportDataProcessor dataProcessor = applicationContext.getBean(provider + "UserImportDataProcessor", UserImportDataProcessor.class);
// process raw user data before import into ElasticSearch
List<UserImportEntity> userImportEntities = dataProcessor.process(Arrays.asList(userImportData));
httpServletResponse.setStatus(userService.addCrawledUser(userImportEntities.get(0), provider) ?
HttpServletResponse.SC_NO_CONTENT : HttpServletResponse.SC_NOT_ACCEPTABLE);
}

Expand All @@ -53,19 +55,8 @@ public void saveAll(@RequestBody List<UserImportData> users, HttpServletResponse
SocialProvider provider = users.get(0).getCrawlerSource();
UserImportDataProcessor dataProcessor = applicationContext.getBean(provider + "UserImportDataProcessor", UserImportDataProcessor.class);
// process raw user data before import into ElasticSearch
dataProcessor.process(users);
httpServletResponse.setStatus(userService.addCrawledUserAll(users) == users.size() ?
HttpServletResponse.SC_NO_CONTENT : HttpServletResponse.SC_NOT_ACCEPTABLE);
} else {
httpServletResponse.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE);
}
}

@ResponseBody
@RequestMapping(value = "/api/users/import", method = RequestMethod.POST)
public void importUser(@RequestBody List<UserImportData> users, HttpServletResponse httpServletResponse) {
if (!users.isEmpty()) {
httpServletResponse.setStatus(userService.importUserAll(users) > 0 ?
List<UserImportEntity> userImportEntities = dataProcessor.process(users);
httpServletResponse.setStatus(userService.addCrawledUserAll(userImportEntities, provider) == users.size() ?
HttpServletResponse.SC_NO_CONTENT : HttpServletResponse.SC_NOT_ACCEPTABLE);
} else {
httpServletResponse.setStatus(HttpServletResponse.SC_NOT_ACCEPTABLE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.techlooper.entity.userimport;

import com.techlooper.model.SocialProvider;

import java.util.ArrayList;
import java.util.List;

/**
* Created by NguyenDangKhoa on 2/11/15.
*/
public class AboutMeUserImportProfile implements UserImportProfile {

private String profile;

private String bio;

private String username;

private String email;

private String fullName;

private SocialProvider crawlerSource;

public String getProfile() {
return profile;
}

public void setProfile(String profile) {
this.profile = profile;
}

public String getBio() {
return bio;
}

public void setBio(String bio) {
this.bio = bio;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public SocialProvider getCrawlerSource() {
return crawlerSource;
}

public void setCrawlerSource(SocialProvider crawlerSource) {
this.crawlerSource = crawlerSource;
}

public String getFullName() {
return fullName;
}

public void setFullName(String fullName) {
this.fullName = fullName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
package com.techlooper.entity.userimport;

import com.techlooper.model.SocialProvider;

import java.util.ArrayList;
import java.util.List;

/**
* Created by NguyenDangKhoa on 2/11/15.
*/
public class GithubUserImportProfile implements UserImportProfile {

private String email;

private String originalEmail;

private String fullName;

private SocialProvider crawlerSource;

private String username;

private String imageUrl;

private String location;

private String dateJoin;

private String company;

private String website;

private String description;

private String followers;

private String following;

private List<String> organizations;

private List<String> popularRepositories;

private List<String> contributedRepositories;

private String contributedLongestStreakTotal;

private String lastContributedDateTime;

private String contributeNumberLastYear;

private String contributeNumberLastYearPeriod;

private String contributeLongestStreakPeriod;

private String contributeCurrentStreakTotal;

private List<String> skills = new ArrayList<>();

private int numberOfRepositories;

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getOriginalEmail() {
return originalEmail;
}

public void setOriginalEmail(String originalEmail) {
this.originalEmail = originalEmail;
}

public String getFullName() {
return fullName;
}

public void setFullName(String fullName) {
this.fullName = fullName;
}

public SocialProvider getCrawlerSource() {
return crawlerSource;
}

public void setCrawlerSource(SocialProvider crawlerSource) {
this.crawlerSource = crawlerSource;
}

public String getUsername() {
return username;
}

public void setUsername(String username) {
this.username = username;
}

public String getImageUrl() {
return imageUrl;
}

public void setImageUrl(String imageUrl) {
this.imageUrl = imageUrl;
}

public String getLocation() {
return location;
}

public void setLocation(String location) {
this.location = location;
}

public String getDateJoin() {
return dateJoin;
}

public void setDateJoin(String dateJoin) {
this.dateJoin = dateJoin;
}

public String getCompany() {
return company;
}

public void setCompany(String company) {
this.company = company;
}

public String getWebsite() {
return website;
}

public void setWebsite(String website) {
this.website = website;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getFollowers() {
return followers;
}

public void setFollowers(String followers) {
this.followers = followers;
}

public String getFollowing() {
return following;
}

public void setFollowing(String following) {
this.following = following;
}

public List<String> getOrganizations() {
return organizations;
}

public void setOrganizations(List<String> organizations) {
this.organizations = organizations;
}

public List<String> getPopularRepositories() {
return popularRepositories;
}

public void setPopularRepositories(List<String> popularRepositories) {
this.popularRepositories = popularRepositories;
}

public List<String> getContributedRepositories() {
return contributedRepositories;
}

public void setContributedRepositories(List<String> contributedRepositories) {
this.contributedRepositories = contributedRepositories;
}

public String getContributedLongestStreakTotal() {
return contributedLongestStreakTotal;
}

public void setContributedLongestStreakTotal(String contributedLongestStreakTotal) {
this.contributedLongestStreakTotal = contributedLongestStreakTotal;
}

public String getLastContributedDateTime() {
return lastContributedDateTime;
}

public void setLastContributedDateTime(String lastContributedDateTime) {
this.lastContributedDateTime = lastContributedDateTime;
}

public String getContributeNumberLastYear() {
return contributeNumberLastYear;
}

public void setContributeNumberLastYear(String contributeNumberLastYear) {
this.contributeNumberLastYear = contributeNumberLastYear;
}

public String getContributeNumberLastYearPeriod() {
return contributeNumberLastYearPeriod;
}

public void setContributeNumberLastYearPeriod(String contributeNumberLastYearPeriod) {
this.contributeNumberLastYearPeriod = contributeNumberLastYearPeriod;
}

public String getContributeLongestStreakPeriod() {
return contributeLongestStreakPeriod;
}

public void setContributeLongestStreakPeriod(String contributeLongestStreakPeriod) {
this.contributeLongestStreakPeriod = contributeLongestStreakPeriod;
}

public String getContributeCurrentStreakTotal() {
return contributeCurrentStreakTotal;
}

public void setContributeCurrentStreakTotal(String contributeCurrentStreakTotal) {
this.contributeCurrentStreakTotal = contributeCurrentStreakTotal;
}

public List<String> getSkills() {
return skills;
}

public void setSkills(List<String> skills) {
this.skills = skills;
}

public int getNumberOfRepositories() {
return numberOfRepositories;
}

public void setNumberOfRepositories(int numberOfRepositories) {
this.numberOfRepositories = numberOfRepositories;
}
}
Loading

0 comments on commit 4d7ef31

Please sign in to comment.