Skip to content

Commit

Permalink
Merge pull request #155 from khoa-nd/master
Browse files Browse the repository at this point in the history
Please pull the latest code
  • Loading branch information
chrisshayan committed Jan 29, 2015
2 parents efb618c + fe2aa91 commit 9640490
Show file tree
Hide file tree
Showing 34 changed files with 4,182 additions and 17 deletions.
38 changes: 38 additions & 0 deletions src/main/java/com/techlooper/bootcamp/BootcampController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.techlooper.bootcamp;

import com.google.common.io.Files;
import com.techlooper.util.JsonUtils;
import org.springframework.stereotype.Controller;
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.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

/**
* Created by phuonghqh on 1/29/15.
*/
@Controller
public class BootcampController {

@ResponseBody
@RequestMapping(value = "/bootcamp/users", method = RequestMethod.POST)
public void save(@RequestBody BootcampUserInfo bootcampUserInfo, HttpServletResponse httpServletResponse) throws IOException {
File jsonFile = new File("bootcamp-users.json");
StringBuilder jsonBuilder = new StringBuilder();
if (jsonFile.exists()) {
Files.readLines(jsonFile, StandardCharsets.UTF_8).stream().forEach(jsonBuilder::append);
}

List<BootcampUserInfo> users = JsonUtils.toList(jsonBuilder.toString(), BootcampUserInfo.class).orElse(new ArrayList<>());
users.add(bootcampUserInfo);
JsonUtils.getObjectMapper().writeValue(jsonFile, users);
httpServletResponse.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
}
60 changes: 60 additions & 0 deletions src/main/java/com/techlooper/bootcamp/BootcampUserInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.techlooper.bootcamp;

import com.fasterxml.jackson.annotation.JsonInclude;

/**
* Created by phuonghqh on 1/29/15.
*/
@JsonInclude(JsonInclude.Include.NON_EMPTY)
public class BootcampUserInfo {

private String firstName;

private String lastName;

private String currentJobTitle;

private String emailAddress;

private String phoneNumber;

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getCurrentJobTitle() {
return currentJobTitle;
}

public void setCurrentJobTitle(String currentJobTitle) {
this.currentJobTitle = currentJobTitle;
}

public String getEmailAddress() {
return emailAddress;
}

public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}

public String getPhoneNumber() {
return phoneNumber;
}

public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.techlooper.controller"})
@ComponentScan(basePackages = {"com.techlooper.controller", "com.techlooper.bootcamp"})
public class WebConfiguration extends WebMvcConfigurerAdapter {

@Resource
Expand All @@ -35,6 +35,8 @@ public ViewResolver viewResolver() {
}

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

registry.addResourceHandler("/**").addResourceLocations(environment.getProperty("webapp.resource.location"))
.resourceChain(true)
/*
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/com/techlooper/controller/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.techlooper.model.UserImportData;
import com.techlooper.model.UserInfo;
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.messaging.handler.annotation.MessageMapping;
Expand All @@ -16,6 +17,7 @@
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.Iterator;
import java.util.List;

/**
Expand All @@ -41,7 +43,7 @@ public void save(@RequestBody UserImportData userImportData, HttpServletResponse
@RequestMapping(value = "/api/users/addAll", method = RequestMethod.POST)
public void saveAll(@RequestBody List<UserImportData> users, HttpServletResponse httpServletResponse) {
//TODO : Temporarily adding fake email for user who is missing email address to pass validation
processMissingEmailUser(users);
processEmailUser(users);
httpServletResponse.setStatus(userService.addCrawledUserAll(users) > 0 ?
HttpServletResponse.SC_NO_CONTENT : HttpServletResponse.SC_NOT_ACCEPTABLE);
}
Expand Down Expand Up @@ -77,16 +79,14 @@ public void verifyUserLogin(@RequestBody SocialRequest searchRequest, @CookieVal
}
}

private void processMissingEmailUser(List<UserImportData> users) {
if (users != null && users.size() > 0) {
for (UserImportData user : users)
if (StringUtils.isEmpty(user.getEmail())) {
user.setEmail(user.getUsername() + "@missing.com");
} else {
user.setEmail(StringUtils.deleteWhitespace(user.getEmail())
.toLowerCase().replaceAll("\\[at\\]", "@").replaceAll("\\[dot\\]", "."));

}
private void processEmailUser(List<UserImportData> users) {
Iterator<UserImportData> iterator = users.iterator();
while (iterator.hasNext()) {
UserImportData user = iterator.next();
if (StringUtils.isEmpty(user.getEmail()) || !EmailValidator.validate(user.getEmail())) {
user.setOriginalEmail(user.getEmail());
user.setEmail(user.getUsername() + "@missing.com");
}
}
}
}
42 changes: 37 additions & 5 deletions src/main/java/com/techlooper/model/UserImportData.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.techlooper.model;

import java.util.List;

/**
* Created by khoa-nd on 27/01/15.
*/
public class UserImportData {

private String email;

private String originalEmail;

private String fullName;

private SocialProvider crawlerSource;
Expand All @@ -17,7 +21,11 @@ public class UserImportData {

private String location;

private String dateJoined;
private String dateJoin;

private String company;

private List<String> skills;

public String getEmail() {
return email;
Expand All @@ -27,6 +35,14 @@ 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;
}
Expand Down Expand Up @@ -67,11 +83,27 @@ public void setLocation(String location) {
this.location = location;
}

public String getDateJoined() {
return dateJoined;
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 List<String> getSkills() {
return skills;
}

public void setDateJoined(String dateJoined) {
this.dateJoined = dateJoined;
public void setSkills(List<String> skills) {
this.skills = skills;
}
}
23 changes: 23 additions & 0 deletions src/main/java/com/techlooper/util/EmailValidator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.techlooper.util;

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

/**
* Created by NguyenDangKhoa on 1/29/15.
*/
public class EmailValidator {

private static final String EMAIL_PATTERN =
"^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";

private static Pattern pattern = Pattern.compile(EMAIL_PATTERN);
private static Matcher matcher;

public static boolean validate(final String email) {
matcher = pattern.matcher(email);
return matcher.matches();
}

}
4 changes: 4 additions & 0 deletions src/main/webapp/bootcamp/css/font-awesome.min.css

Large diffs are not rendered by default.

Loading

0 comments on commit 9640490

Please sign in to comment.