Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d4b443d
add Thet Soe API endpoint
tpsoe Sep 19, 2018
b500d3d
Added "return size of User List" API
ChipuChipu Sep 19, 2018
a900883
Added Get Size of User List
ChipuChipu Sep 19, 2018
0a90842
Merge branch 'master' of https://github.com/Coding-Ronin/demo-web-pro…
ChipuChipu Sep 19, 2018
1850375
Fixed typo. Size of User List.
ChipuChipu Sep 19, 2018
888d1ec
Added Try Catch to Size of User List
ChipuChipu Sep 19, 2018
9a3d28c
Fixed Typo. Size of User List.
ChipuChipu Sep 19, 2018
a7b3f4c
Update WebController.java
ZetoMarui Sep 19, 2018
e0ecc80
Update WebController.java
ZetoMarui Sep 19, 2018
114b479
Update WebController.java
LYNNAM Sep 20, 2018
a59a614
Got help from aaron
warrenxie Sep 20, 2018
ce4a29f
Added name to comments for Size of User List
ChipuChipu Sep 20, 2018
c7a4a77
Added Independent Entry for A4 - Fixed Indents
ChipuChipu Sep 25, 2018
5cecc76
Added Independent Entry for A4 - Fixed Indents
ChipuChipu Sep 25, 2018
3be119d
Added Independent Entry for A4 - Commons IO
ChipuChipu Sep 25, 2018
26aae36
Update pom.xml
LYNNAM Sep 25, 2018
5dead2e
Update WebController.java
LYNNAM Sep 25, 2018
665ec2d
Finished Independent Code + Fixed Comments in Pom
ChipuChipu Sep 26, 2018
9323d35
Update pom.xml
warrenxie Sep 30, 2018
ac8f3cc
Update WebController.java
warrenxie Sep 30, 2018
783a754
Update WebController.java
warrenxie Sep 30, 2018
cff8dff
Update pom.xml
ZetoMarui Sep 30, 2018
42a0b70
Update WebController.java
ZetoMarui Sep 30, 2018
31eaa58
Update WebController.java
ZetoMarui Sep 30, 2018
393d31f
Update WebController.java
ZetoMarui Sep 30, 2018
b07114e
Update WebController.java
LYNNAM Oct 1, 2018
c3b7c16
Update WebController.java
LYNNAM Oct 1, 2018
5180d32
done
tpsoe Oct 2, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 71 additions & 34 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,47 +22,84 @@

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jetty</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>1.2.0.RELEASE</version>
<scope>test</scope>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>1.2.0.RELEASE</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.8.1</version>
</dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.8.1</version>
</dependency>

<!-- Joshua Yi - Commons IO -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>

<!-- Brandon Wong - Commons Text-->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.4</version>
</dependency>

<!-- YeukNam Lam - Commons Math -->
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-math3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.2</version>
</dependency>
<!-- Warren Xie - Google Guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>26.0-jre</version>

</dependency>

<!-- Thet Soe -->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.11.3</version>
</dependency>

</dependencies>

<reporting>
<plugins>
<!-- Normally, we take off the dependency report, saves time. -->
Expand Down Expand Up @@ -109,4 +146,4 @@
</plugins>
</build>

</project>
</project>
196 changes: 194 additions & 2 deletions src/main/java/edu/csupomona/cs480/controller/WebController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.BridgeMethodResolver;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
Expand All @@ -15,8 +16,31 @@
import edu.csupomona.cs480.data.User;
import edu.csupomona.cs480.data.provider.GpsProductManager;
import edu.csupomona.cs480.data.provider.UserManager;
// Warren Xie - Google Guava Library Import
import com.google.common.base.Optional;

// Joshua Yi - Commons IO Library Import
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import org.apache.commons.io.IOUtils;

//Brandon Wong - Commons Text
import org.apache.commons.text;

// YeukNam Lam - Commons Email
import org.apache.commons.mail
import org.apache.commons.mail.resolver
import org.apache.commons.mail.util

// Thet
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
/**
* This is the controller used by Spring framework.
* <p>
Expand All @@ -40,6 +64,32 @@ public class WebController {
private UserManager userManager;
@Autowired
private GpsProductManager gpsProductManager;

@RequestMapping(value = "/codingronin/thetsoe", method = RequestMethod.GET)
String tpsoeCheck() {
// You can replace this with other string,
// and run the application locally to check your changes
// with the URL: http://localhost:8080/
return "Thet Soe";
}

@RequestMapping(value ="/codingronin/warren", method = RequestMethod.GET)
String warrenRonin() {
return "One for All!";
}
@RequestMapping(value = "/codingronin/yo_its_brandon", method = RequestMethod.GET)
String namePrint2() {
//run with application locally to check your changes with the URL: http://localhost.8080/
return "Brandon's here!";

}

@RequestMapping(value = "/codingronin/YeukNam Lam", method = RequestMethod.GET)
String namePrint() {
//run with application locally to check your changes with the URL: http://localhost.8080/
return "This is YeukNam Lam, Did you guys fork the whole project to your PC?";
}


/**
* This is a simple example of how the HTTP API works.
Expand Down Expand Up @@ -116,7 +166,7 @@ void deleteUser(

/**
* This API lists all the users in the current database.
*
*
* @return
*/
@RequestMapping(value = "/cs480/users/list", method = RequestMethod.GET)
Expand All @@ -129,6 +179,121 @@ List<GpsProduct> listGpsProducts() {
return gpsProductManager.listAllGpsProducts();
}

/**
* This API returns the size of the User List
* http://localhost:8080/cs480/users/size
* Author: Joshua Yi - ChipuChipu
* @return
*/
@RequestMapping(value = "/cs480/users/size", method = RequestMethod.GET)
int getNumOfUsers() {
try
{
return userManager.listAllUsers().size();
}
catch (Exception e) {return -1;}
}

@RequestMapping(value = "/cs480/gps/size", method = RequestMethod.GET)
int getNumOfGpsProducts() {
try
{
return gpsProductManager.listAllGpsProducts().size();
}
catch (Exception e) {return -1;}
}

/**
* This API returns a string read in from Google.com
* Uses Apache Commons IO Library
* http://localhost:8080/cs480/users/readGoogleUrl
* Author: Joshua Yi - ChipuChipu
* @return
*/
@RequestMapping(value = "/cs480/users/readGoogleUrl", method = RequestMethod.GET)
String readGoogleUrl()
{
try
{
InputStream in = new URL("https://google.com").openStream();
InputStreamReader inR = new InputStreamReader(in);
BufferedReader br = new BufferedReader(inR);
String line = br.readLine();
int index = line.indexOf("<head>");
int endIndex = line.indexOf("name");
String subLine = line.substring(index, endIndex);

System.out.println("Size of subLine:" + subLine.length());
return "SUCCESS!";

} catch(Exception e)
{
e.printStackTrace();
return "FAILED!";
}
}

/*
* Warren Xie
*/
@RequestMapping(value = "cs480/users/readWarren", method = RequestMethod.GET)
Integer guavaTesting() {
Integer value1 = null;
Integer value2 = new Integer(10);



Optional<Integer> a = Optional.fromNullable(value1);
Optional<Integer> b = Optional.of(value2);

return sum(a,b);
}

/*
* Brandon Wong
* http://localhost:8080/cs480/users/RandomText
* Uses Commons Text Library
*/
@RequestMapping(value = "cs480/users/RandomText", method = RequestMethod.GET)
String randString() {
String s;
s = s.generate(10);
return s;
}

public Integer sum( Optional<Integer>a,Optional<Integer>b) {
System.out.println("A is: "+ a.isPresent());

System.out.println("B is: "+b.isPresent());

Integer value1 = a.or(new Integer(0));

Integer value2 = b.get();

return value1 + value2;
}

/*
* Create a basic email message to "John Doe" and send it through your Google Mail (GMail) account.
* Uses Apache Commons Email Library
* http://localhost:8080/cs480/users/email
* Author: YeukNam Lam
*/
@RequestMapping(value = "/cs480/users/email", method = RequestMethod.GET)
void email()
{
Email email = new SimpleEmail();
email.setHostName("smtp.googlemail.com");
email.setSmtpPort(465);
email.setAuthenticator(new DefaultAuthenticator("username", "password"));
email.setSSLOnConnect(true);
email.setFrom("user@gmail.com");
email.setSubject("TestMail");
email.setMsg("This is a test mail ... :-)");
email.addTo("foo@bar.com");
email.send();
}

/*********** Web UI Test Utility **********/
/**
* This method provide a simple web UI for you to test the different
Expand All @@ -140,5 +305,32 @@ ModelAndView getUserHomepage() {
modelAndView.addObject("users", listAllUsers());
return modelAndView;
}

/**
* This is a simple example of how to use a HTML parser
* to retrieve the data and return it as an HTTP response.
*
* This will print the name of recipes along with their hyperlinks.
* Try it in your web browser:
* http://localhost:8080/cs480/Recipes
*/
// Thet Soe
@RequestMapping(value = "/cs480/Recipes", method = RequestMethod.GET)
String Recipes()
{
String result = "";
Document doc;
try {
doc = Jsoup.connect("http://pinchmysalt.com/recipe-list/").get();
Elements links = doc.select("a[href]");
for (Element link : links) {
result+=link.text()+": "+link.attr("href")+" ...... ";
}
} catch (IOException e) {
e.printStackTrace();
}
return result;

}

}
}