Merge branch 'johannes2' of Studium/Internet-Technologien into master
This commit is contained in:
commit
7d135725ff
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,4 @@
|
||||
*.iml
|
||||
/target
|
||||
.idea
|
||||
.idea
|
||||
config.json
|
||||
|
9
config.json.example
Normal file
9
config.json.example
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"database": {
|
||||
"hostname": "localhost",
|
||||
"port": 3306,
|
||||
"database": "itech",
|
||||
"username": "itech",
|
||||
"password": "123456"
|
||||
}
|
||||
}
|
1
pom.xml
1
pom.xml
@ -137,6 +137,7 @@
|
||||
<minimumTokens>100</minimumTokens>
|
||||
<sourceEncoding>${project.build.sourceEncoding}</sourceEncoding>
|
||||
<printFailingErrors>true</printFailingErrors>
|
||||
<failOnViolation>false</failOnViolation>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
|
42
src/main/java/de/hsel/itech/config/Configuration.java
Normal file
42
src/main/java/de/hsel/itech/config/Configuration.java
Normal file
@ -0,0 +1,42 @@
|
||||
package de.hsel.itech.config;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
*/
|
||||
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
public class Configuration {
|
||||
|
||||
private static final String filename = "config.json";
|
||||
|
||||
@Getter
|
||||
private Database database;
|
||||
|
||||
|
||||
|
||||
public static Configuration get() {
|
||||
Gson gson = new Gson();
|
||||
|
||||
FileReader reader = null;
|
||||
try {
|
||||
reader = new FileReader(new File(filename));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
assert reader != null;
|
||||
return gson.fromJson(reader, Configuration.class);
|
||||
}
|
||||
|
||||
}
|
23
src/main/java/de/hsel/itech/config/Database.java
Normal file
23
src/main/java/de/hsel/itech/config/Database.java
Normal file
@ -0,0 +1,23 @@
|
||||
package de.hsel.itech.config;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
public class Database {
|
||||
|
||||
String hostname;
|
||||
int port;
|
||||
String database;
|
||||
String username;
|
||||
String password;
|
||||
}
|
57
src/main/java/de/hsel/itech/db/Database.java
Normal file
57
src/main/java/de/hsel/itech/db/Database.java
Normal file
@ -0,0 +1,57 @@
|
||||
package de.hsel.itech.db;
|
||||
|
||||
import de.hsel.itech.config.Configuration;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.sql.*;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
*/
|
||||
public class Database {
|
||||
|
||||
public Database() {
|
||||
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Connection getConnection() {
|
||||
Configuration config = Configuration.get();
|
||||
try {
|
||||
return DriverManager.getConnection("jdbc:mariadb://" + config.getDatabase().getHostname() + ":" + config.getDatabase().getPort() + "/" + config.getDatabase().getDatabase(), config.getDatabase().getUsername(), config.getDatabase().getPassword());
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getHello() {
|
||||
Connection connection = getConnection();
|
||||
|
||||
String hello = "";
|
||||
try {
|
||||
assert connection != null;
|
||||
PreparedStatement statement = connection.prepareStatement("SELECT * FROM test WHERE id = 1");
|
||||
ResultSet resultSet = statement.executeQuery();
|
||||
resultSet.next();
|
||||
hello = resultSet.getString("hello");
|
||||
|
||||
connection.close();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return hello;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
23
src/main/java/de/hsel/itech/db/pojo/Address.java
Normal file
23
src/main/java/de/hsel/itech/db/pojo/Address.java
Normal file
@ -0,0 +1,23 @@
|
||||
package de.hsel.itech.db.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Address {
|
||||
|
||||
private Customer customer;
|
||||
private long id;
|
||||
private String name;
|
||||
private String street;
|
||||
private String number;
|
||||
private int zipCode;
|
||||
private String city;
|
||||
}
|
19
src/main/java/de/hsel/itech/db/pojo/Author.java
Normal file
19
src/main/java/de/hsel/itech/db/pojo/Author.java
Normal file
@ -0,0 +1,19 @@
|
||||
package de.hsel.itech.db.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Author {
|
||||
|
||||
private long id;
|
||||
private String name;
|
||||
|
||||
}
|
34
src/main/java/de/hsel/itech/db/pojo/Book.java
Normal file
34
src/main/java/de/hsel/itech/db/pojo/Book.java
Normal file
@ -0,0 +1,34 @@
|
||||
package de.hsel.itech.db.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.Year;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Book {
|
||||
|
||||
private int isbn;
|
||||
private Author author;
|
||||
private Publisher publisher;
|
||||
private Category category;
|
||||
private String title;
|
||||
private Year year;
|
||||
|
||||
/**
|
||||
* saved in cents
|
||||
*/
|
||||
private int price;
|
||||
private String description;
|
||||
private String image;
|
||||
|
||||
|
||||
|
||||
}
|
19
src/main/java/de/hsel/itech/db/pojo/Category.java
Normal file
19
src/main/java/de/hsel/itech/db/pojo/Category.java
Normal file
@ -0,0 +1,19 @@
|
||||
package de.hsel.itech.db.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Category {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
private String image;
|
||||
}
|
24
src/main/java/de/hsel/itech/db/pojo/CreditCardPayment.java
Normal file
24
src/main/java/de/hsel/itech/db/pojo/CreditCardPayment.java
Normal file
@ -0,0 +1,24 @@
|
||||
package de.hsel.itech.db.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
**/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class CreditCardPayment {
|
||||
|
||||
private long id;
|
||||
private Customer customer;
|
||||
private int number;
|
||||
private String owner;
|
||||
private LocalDate expiration;
|
||||
private int checksum;
|
||||
}
|
21
src/main/java/de/hsel/itech/db/pojo/Customer.java
Normal file
21
src/main/java/de/hsel/itech/db/pojo/Customer.java
Normal file
@ -0,0 +1,21 @@
|
||||
package de.hsel.itech.db.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Customer {
|
||||
|
||||
private long id;
|
||||
private String email;
|
||||
private String name;
|
||||
private String password;
|
||||
private boolean admin;
|
||||
}
|
21
src/main/java/de/hsel/itech/db/pojo/DebitCardPayment.java
Normal file
21
src/main/java/de/hsel/itech/db/pojo/DebitCardPayment.java
Normal file
@ -0,0 +1,21 @@
|
||||
package de.hsel.itech.db.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
**/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class DebitCardPayment {
|
||||
|
||||
private long id;
|
||||
private Customer customer;
|
||||
private String iban;
|
||||
private String bic;
|
||||
private String owner;
|
||||
}
|
18
src/main/java/de/hsel/itech/db/pojo/InvoicePayment.java
Normal file
18
src/main/java/de/hsel/itech/db/pojo/InvoicePayment.java
Normal file
@ -0,0 +1,18 @@
|
||||
package de.hsel.itech.db.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
**/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class InvoicePayment {
|
||||
|
||||
private long id;
|
||||
private Customer customer;
|
||||
}
|
29
src/main/java/de/hsel/itech/db/pojo/Order.java
Normal file
29
src/main/java/de/hsel/itech/db/pojo/Order.java
Normal file
@ -0,0 +1,29 @@
|
||||
package de.hsel.itech.db.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
**/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Order {
|
||||
|
||||
private long id;
|
||||
private LocalDateTime date;
|
||||
private Book book;
|
||||
|
||||
/**
|
||||
* price in cents
|
||||
*/
|
||||
private int price;
|
||||
private PaymentType paymentType;
|
||||
private Address address;
|
||||
}
|
20
src/main/java/de/hsel/itech/db/pojo/PayPalPayment.java
Normal file
20
src/main/java/de/hsel/itech/db/pojo/PayPalPayment.java
Normal file
@ -0,0 +1,20 @@
|
||||
package de.hsel.itech.db.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
**/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class PayPalPayment {
|
||||
|
||||
private long id;
|
||||
private Customer customer;
|
||||
private String email;
|
||||
private String authCode;
|
||||
}
|
18
src/main/java/de/hsel/itech/db/pojo/PaymentType.java
Normal file
18
src/main/java/de/hsel/itech/db/pojo/PaymentType.java
Normal file
@ -0,0 +1,18 @@
|
||||
package de.hsel.itech.db.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
**/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class PaymentType {
|
||||
|
||||
private long id;
|
||||
private String name;
|
||||
}
|
18
src/main/java/de/hsel/itech/db/pojo/Publisher.java
Normal file
18
src/main/java/de/hsel/itech/db/pojo/Publisher.java
Normal file
@ -0,0 +1,18 @@
|
||||
package de.hsel.itech.db.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
*/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Publisher {
|
||||
|
||||
private long id;
|
||||
private String name;
|
||||
}
|
20
src/main/java/de/hsel/itech/db/pojo/ShoppingCart.java
Normal file
20
src/main/java/de/hsel/itech/db/pojo/ShoppingCart.java
Normal file
@ -0,0 +1,20 @@
|
||||
package de.hsel.itech.db.pojo;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
**/
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class ShoppingCart {
|
||||
|
||||
private long id;
|
||||
private Customer customer;
|
||||
private Book article;
|
||||
private int count;
|
||||
}
|
40
src/main/java/de/hsel/itech/servlet/Database.java
Normal file
40
src/main/java/de/hsel/itech/servlet/Database.java
Normal file
@ -0,0 +1,40 @@
|
||||
package de.hsel.itech.servlet;
|
||||
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* @author Johannes Theiner
|
||||
* @version 0.1
|
||||
* @since 0.1
|
||||
**/
|
||||
public class Database extends HttpServlet {
|
||||
|
||||
private static final long serialVersionUID = 15679036734L;
|
||||
|
||||
/**
|
||||
* doGet.
|
||||
*
|
||||
* @param req Request
|
||||
* @param resp Response
|
||||
* @throws IOException failed
|
||||
*/
|
||||
@Override
|
||||
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
|
||||
throws IOException {
|
||||
|
||||
resp.setContentType("text/html");
|
||||
final PrintWriter out = resp.getWriter();
|
||||
out.println("<html>");
|
||||
out.println("<head>");
|
||||
out.println("<title>Hallo Welt!</title>");
|
||||
out.println("</head>");
|
||||
out.println("<body>");
|
||||
out.println("<h1>" + new de.hsel.itech.db.Database().getHello() + "</h1>");
|
||||
out.println("</body>");
|
||||
out.println("</html>");
|
||||
}
|
||||
}
|
@ -1,8 +1,9 @@
|
||||
package de.hsel.itech;
|
||||
package de.hsel.itech.servlet;
|
||||
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
|
||||
@ -30,12 +31,15 @@ public class HelloWorld extends HttpServlet {
|
||||
|
||||
resp.setContentType("text/html");
|
||||
final PrintWriter out = resp.getWriter();
|
||||
out.println("<!DOCTYPE html>");
|
||||
out.println("<html>");
|
||||
out.println("<head>");
|
||||
out.println("<title>Hallo Welt!</title>");
|
||||
out.println("</head>");
|
||||
out.println("<body>");
|
||||
out.println("<h1>Hallo Ostfriesland!</h1>");
|
||||
out.println("<h1>Hallo Ostfriesland!</h1><br>");
|
||||
out.println("<h3>" + System.getProperty("catalina.base") + "</h3><br>");
|
||||
out.println("<h4>" + new File("").getAbsolutePath() + "</h4>");
|
||||
out.println("</body>");
|
||||
out.println("</html>");
|
||||
}
|
@ -7,11 +7,21 @@
|
||||
<web-app>
|
||||
<servlet>
|
||||
<servlet-name>helloWorld</servlet-name>
|
||||
<servlet-class>de.hsel.itech.HelloWorld</servlet-class>
|
||||
<servlet-class>de.hsel.itech.servlet.HelloWorld</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>database</servlet-name>
|
||||
<servlet-class>de.hsel.itech.servlet.Database</servlet-class>
|
||||
</servlet>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>helloWorld</servlet-name>
|
||||
<url-pattern>/index</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
<servlet-mapping>
|
||||
<servlet-name>database</servlet-name>
|
||||
<url-pattern>/db</url-pattern>
|
||||
</servlet-mapping>
|
||||
</web-app>
|
Loading…
Reference in New Issue
Block a user