Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
e23f7c6
Initial commit for assignment two
Jun 4, 2018
e5bdc8a
Stock code updates
Jun 5, 2018
8962d85
Updated Stock code with javadoc
Jun 5, 2018
895b4c8
Merge branch 'master' into assignment_two
connor1484 Jun 5, 2018
bee11b7
initial commit for assignment 3
Jun 12, 2018
085d0ce
updated submission
Jun 13, 2018
f993462
Assignment 4 submission
Jun 20, 2018
bc794f6
assignment 5 initial push
Jun 27, 2018
16d3b00
assignment 6 initial submission
Jul 4, 2018
93acd15
adding circleci config.yml
Jul 4, 2018
be10e80
adding circleci config.yml
Jul 4, 2018
0520eb9
adding circleci config.yml
Jul 4, 2018
ece29be
adding circleci config.yml
Jul 4, 2018
6284f4f
adding circleci config.yml
Jul 4, 2018
703ba21
initial assignment 7 commit
Jul 11, 2018
448eab4
updated for xml
Jul 14, 2018
c749124
updating circleci config
Jul 14, 2018
940454e
updating circleci config
Jul 14, 2018
5b66a7c
updating circleci config
Jul 14, 2018
b89450a
updating circleci config
Jul 14, 2018
dbbbe3e
updating circleci config
Jul 14, 2018
7aadb74
updating circleci config
Jul 14, 2018
8e104d1
updating circleci config
Jul 14, 2018
3d5fbfa
updating circleci config
Jul 14, 2018
14a547c
updating circleci config
Jul 14, 2018
b35de4a
initial assignment 8 submission
Jul 18, 2018
d828ca4
updated circleci
Jul 20, 2018
3cc8d33
updated config.yml
Jul 20, 2018
91a44b5
updated config.yml
Jul 20, 2018
98d6ee9
updated config.yml
Jul 20, 2018
1576e3b
updated config.yml
Jul 20, 2018
cc6a011
updated config.yml
Jul 20, 2018
dde93eb
Update config.yml
connor1484 Jul 20, 2018
a9da4cc
updated config.yml
Jul 20, 2018
c15b83f
Update config.yml
connor1484 Jul 20, 2018
29b5beb
Update config.yml
connor1484 Jul 20, 2018
41347d0
Update config.yml
connor1484 Jul 20, 2018
93d728c
Update config.yml
connor1484 Jul 20, 2018
6f25b4e
Update config.yml
connor1484 Jul 20, 2018
681d0ea
Update config.yml
connor1484 Jul 20, 2018
4475078
Update config.yml
connor1484 Jul 20, 2018
338bae3
Update config.yml
connor1484 Jul 20, 2018
4fafafa
Update config.yml
connor1484 Jul 20, 2018
2a8fc3c
Update config.yml
connor1484 Jul 20, 2018
cba8f05
Update config.yml
connor1484 Jul 20, 2018
b137840
Update config.yml
connor1484 Jul 20, 2018
b94aa70
Update config.yml
connor1484 Jul 20, 2018
fa2f5ff
Update config.yml
connor1484 Jul 20, 2018
f27af92
Update config.yml
connor1484 Jul 20, 2018
9feec90
Update config.yml
connor1484 Jul 20, 2018
099c660
initial assignment nine submission
Jul 25, 2018
f2066ba
updated assignment 9
Jul 25, 2018
341cc1b
initial assignment ten submission
Jul 29, 2018
3b0174c
updating StockQuote.jsp with proper link
Jul 29, 2018
6ad7178
updating circleci config
Jul 30, 2018
ad88731
removed unneeded files
Jul 30, 2018
74a188d
removed unneeded files
Jul 30, 2018
3b6e43a
adding logic for multiple sources
Jul 30, 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
12 changes: 12 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 1
jobs:
build:
docker:
- image: circleci/mysql:latest-ram
environment:
- MYSQL_ROOT_PASSWORD: some_pass
- MYSQL_DATABASE: stocks
- MYSQL_USER: monty
- MYSQL_PASSWORD: some_pass
steps:
- run: apt-get update -y && apt-get dist-upgrade -y && export DEBIAN_FRONTEND=noninteractive && apt-get -q install -y mysql-client
101 changes: 92 additions & 9 deletions pom.xml
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,23 +1,106 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.connor.advancedjava</groupId>
<artifactId>connor-app</artifactId>
<packaging>jar</packaging>
<groupId>com.origamisoftware</groupId>
<artifactId>ExampleWebApp</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>connor-app</name>
<name>ExampleWebApp Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>javax.servlet.jsp.jstl</groupId>
<artifactId>jstl-api</artifactId>
<version>1.2</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<type>jar</type>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.6</version>
</dependency>

<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.0.0.GA</version>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.9.5</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4</version>
</dependency>

<dependency>
<groupId>org.apache.ibatis</groupId>
<artifactId>ibatis-sqlmap</artifactId>
<version>2.3.4.726</version>
</dependency>

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.2.6.Final</version>
</dependency>

<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>com.yahoofinance-api</groupId>
<artifactId>YahooFinanceAPI</artifactId>
<version>3.12.3</version>
</dependency>

</dependencies>
<build>
<finalName>ExampleWebApp</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
74 changes: 74 additions & 0 deletions src/main/java/com.origami.teach.servlet/StockSearchServlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package com.origami.teach.servlet;

import com.origami.teach.model.StockQuote;
import com.origami.teach.services.StockService;
import com.origami.teach.services.ServiceFactory;
import com.origami.teach.model.StockQuery;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Calendar;

/**
* Simple Example of how a servlet can access form submission data
* and act on it accordingly.
*/

public class StockSearchServlet extends HttpServlet {

private StockService stockService;

private static final String SYMBOL = "symbol";
private static final String FROM = "from";
private static final String UNTIL = "until";
private static final String SOURCE = "source";

// use this guy to instantiate a class of the service factory and pass params? Get params?

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {

String symbol = request.getParameter(SYMBOL);
String from = request.getParameter(FROM);
String until = request.getParameter(UNTIL);
String source = request.getParameter(SOURCE);
StockQuery stockQuery = null;

HttpSession session = request.getSession();


try {
stockQuery = new StockQuery(symbol, from, until);
} catch (ParseException e) {
e.printStackTrace();
}

if (source.equals("yahoo")) {
stockService = ServiceFactory.getStockService();
} else if (source.equals("database")) {
stockService = ServiceFactory.getDatabaseStockService();
}


session.setAttribute("symbol", SYMBOL);
session.setAttribute("from", FROM);
session.setAttribute("until", UNTIL);

ServletContext servletContext = getServletContext();
RequestDispatcher dispatcher =
servletContext.getRequestDispatcher("/StockQuoteResults.jsp");
dispatcher.forward(request, response);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package com.origami.teach.apps.stockquote;

import com.origami.teach.model.StockQuery;
import com.origami.teach.model.StockQuote;
import com.origami.teach.services.StockService;
import com.origami.teach.services.StockServiceException;
import com.origami.teach.services.ServiceFactory;
import com.origami.teach.util.Interval;

import java.text.ParseException;
import java.util.List;

/**
* A simple application that shows the StockService in action.
*/
public class BasicStockQuoteApplication {

private StockService stockService;

// an example of how to use enum - not part of assignment 3 but useful for assignment 4

/**
* An enumeration that indicates how the program terminates (ends)
*/
private enum ProgramTerminationStatusEnum {

// for now, we just have normal or abnormal but could more specific ones as needed.
NORMAL(0),
ABNORMAL(-1);

// when the program exits, this value will be reported to underlying OS
private int statusCode;

/**
* Create a new ProgramTerminationStatusEnum
*
* @param statusCodeValue the value to return the OS. A value of 0
* indicates success or normal termination.
* non 0 numbers indicate abnormal termination.
*/
private ProgramTerminationStatusEnum(int statusCodeValue) {
this.statusCode = statusCodeValue;
}

/**
* @return The value sent to OS when the program ends.
*/
private int getStatusCode() {
return statusCode;
}
}

/**
* Create a new Application.
*
* @param stockService the StockService this application instance should use for
* stock queries.
* <p/>
* NOTE: this is a example of Dependency Injection in action.
*/
public BasicStockQuoteApplication(StockService stockService) {
this.stockService = stockService;
}

/**
* Given a <CODE>stockQuery</CODE> get back a the info about the stock to display to th user.
*
* @param stockQuery the stock to get data for.
* @return a String with the stock data in it.
* @throws StockServiceException If data about the stock can't be retrieved. This is a
* fatal error.
*/
public String displayStockQuotes(StockQuery stockQuery) throws StockServiceException {
StringBuilder stringBuilder = new StringBuilder();

List<StockQuote> stockQuotes =
stockService.getQuote(stockQuery.getSymbol(),
stockQuery.getFrom(),
stockQuery.getUntil(),
Interval.DAY); // get one quote for each day in the from until date range.

stringBuilder.append("Stock quotes for: " + stockQuery.getSymbol() + "\n");
for (StockQuote stockQuote : stockQuotes) {
stringBuilder.append(stockQuote.toString());
}

return stringBuilder.toString();
}

/**
* Terminate the application.
*
* @param statusCode an enum value that indicates if the program terminated ok or not.
* @param diagnosticMessage A message to display to the user when the program ends.
* This should be an error message in the case of abnormal termination
* <p/>
* NOTE: This is an example of DRY in action.
* A program should only have one exit point. This makes it easy to do any clean up
* operations before a program quits from just one place in the code.
* It also makes for a consistent user experience.
*/
private static void exit(ProgramTerminationStatusEnum statusCode, String diagnosticMessage) {
if (statusCode == ProgramTerminationStatusEnum.NORMAL) {
System.out.println(diagnosticMessage);
} else if (statusCode == ProgramTerminationStatusEnum.ABNORMAL) {
System.err.println(diagnosticMessage);
} else {
throw new IllegalStateException("Unknown ProgramTerminationStatusEnum.");
}
System.exit(statusCode.getStatusCode());
}

/**
* Run the StockTicker application.
* <p/>
*
* @param args one or more stock symbols
*/
public static void main(String[] args) {

StockQuery stockQuery = null;

// be optimistic init to positive values
ProgramTerminationStatusEnum exitStatus = ProgramTerminationStatusEnum.NORMAL;
String programTerminationMessage = "Normal program termination.";
if (args.length != 3) {
exit(ProgramTerminationStatusEnum.ABNORMAL,
"Please supply 3 arguments a stock symbol, a start date (MM/DD/YYYY) and end date (MM/DD/YYYY)");
}
try {

stockQuery = new StockQuery(args[0], args[1], args[2]);
StockService stockService = ServiceFactory.getStockService();
BasicStockQuoteApplication basicStockQuoteApplication =
new BasicStockQuoteApplication(stockService);
basicStockQuoteApplication.displayStockQuotes(stockQuery);

} catch (ParseException e) {
exitStatus = ProgramTerminationStatusEnum.ABNORMAL;
programTerminationMessage = "Invalid date data: " + e.getMessage();
} catch (StockServiceException e) {
exitStatus = ProgramTerminationStatusEnum.ABNORMAL;
programTerminationMessage = "StockService failed: " + e.getMessage();
} catch (Throwable t) {
exitStatus = ProgramTerminationStatusEnum.ABNORMAL;
System.out.println(stockQuery.getSymbol() + stockQuery.getFrom().getTime() + stockQuery.getUntil());
programTerminationMessage = "General application error: " + t.getMessage();
}

exit(exitStatus, programTerminationMessage);
System.out.println("Oops could not parse a date");
}
}
Loading