Skip to content

Commit

Permalink
add lab7 and lab10
Browse files Browse the repository at this point in the history
  • Loading branch information
Darkie20 committed Jun 2, 2024
1 parent 762d9cf commit a99f05a
Show file tree
Hide file tree
Showing 102 changed files with 14,323 additions and 106 deletions.
24 changes: 24 additions & 0 deletions Lab10/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Maven specific files
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.branch
release.properties
maven-metadata-*.xml
maven-archiver/
MANIFEST.MF


# IntelliJ IDEA files
.idea/
*.iml

# Eclipse files
.classpath
.project
.settings/

# NetBeans files
nb-configuration.xml
build/
nbactions.xml
3 changes: 3 additions & 0 deletions Lab10/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"java.configuration.updateBuildConfiguration": "interactive"
}
11 changes: 11 additions & 0 deletions Lab10/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM maven:3.9.6-eclipse-temurin-17-alpine AS build
WORKDIR /app
COPY pom.xml .
COPY src ./src
RUN mvn clean package -DskipTests

FROM maven:3.9.6-eclipse-temurin-17-alpine
WORKDIR /app
COPY --from=build /app/target/backend.jar backend.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "backend.jar"]
23 changes: 23 additions & 0 deletions Lab10/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Lab3 Project

This project is a small web application built using Java Servlets and JSP with Spring Boot framework. Maven is used for dependency management and project build.
As Spring boot framework already contains TomCat Server, no more further download needed.

## Prerequisites

Before you begin, ensure you have the following installed on your machine:
- Docker

## Getting Started

To get started with this project, follow these steps:

1. Clone or download this repository to your local machine.

2. Navigate to the project directory.

3. Build the project using Docker

```
docker-compose up -d
```
7 changes: 7 additions & 0 deletions Lab10/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
server:
build:
dockerfile: Dockerfile
container_name: backend
ports:
- "8080:8080"
107 changes: 107 additions & 0 deletions Lab10/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.5</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<groupId>library</groupId>
<artifactId>app</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-rest</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.3.0</version>
</dependency>

<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>4.0.2</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>3.1.5</version>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-maven-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>backend</finalName>
</build>
</project>
14 changes: 14 additions & 0 deletions Lab10/src/main/java/lab10/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package lab10;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class App {

public static void main(String[] args) {
SpringApplication.run(App.class, args);
}

}
21 changes: 21 additions & 0 deletions Lab10/src/main/java/lab10/entities/Book.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package lab10.entities;

import jakarta.persistence.Entity;
import lombok.Getter;
import lombok.Setter;

@Entity
@Getter
@Setter
public class Book {
private String title;
private String author;
private int year;
private String publisher;
private String language;
private int pages;
private long isbn10;
private long isbn13;
private String description;
private String category;
}
19 changes: 19 additions & 0 deletions Lab10/src/main/java/lab10/entities/Library.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package lab10.entities;
import java.util.List;
import jakarta.xml.bind.annotation.XmlElement;
import jakarta.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name = "library")
public class Library {

private List<Book> books;

@XmlElement(name = "book")
public List<Book> getBooks() {
return books;
}

public void setBooks(List<Book> books) {
this.books = books;
}
}
36 changes: 36 additions & 0 deletions Lab10/src/main/java/lab10/services/BookService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package lab10.services;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.List;

import org.springframework.core.io.ClassPathResource;
import org.springframework.stereotype.Service;
import jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBException;
import jakarta.xml.bind.Unmarshaller;
import org.springframework.core.io.Resource;
import lab10.entities.Book;
import lab10.entities.Library;

@Service
public class BookService {

public List<Book> getAllBooks() {
try {
Resource resource = new ClassPathResource("book.xml");
InputStream inputStream = resource.getInputStream();

JAXBContext jaxbContext = JAXBContext.newInstance(Library.class);
Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
Library library = (Library) jaxbUnmarshaller.unmarshal(inputStream);

return library.getBooks();
} catch (JAXBException | IOException e) {
e.printStackTrace();
}
return Collections.emptyList();
}
}
21 changes: 21 additions & 0 deletions Lab10/src/main/java/lab10/servlets/BookServlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package lab10.servlets;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import lab10.entities.Book;
import lab10.services.BookService;

import java.util.List;

@RestController
public class BookServlet {

@Autowired
private BookService bookService;

@GetMapping("/books")
public List<Book> getAllBooks() {
return bookService.getAllBooks();
}
}
13 changes: 13 additions & 0 deletions Lab10/src/main/java/lab10/servlets/Data.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package lab10.servlets;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class Data {
@GetMapping("/data")
public String getData() {
RestTemplate restTemplate = new RestTemplate();
return restTemplate.getForObject("http://localhost:8080/books", String.class);
}
}
22 changes: 22 additions & 0 deletions Lab10/src/main/resources/book.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<library>
<book>
<title>An Introduction to Support Vector Machines and Other Kernel-based Learning Methods</title>
<author>Nello Cristianini, John Shawe-Taylor</author>
<year>2013</year>
<publisher>Cambridge University Press</publisher>
<language>English</language>
<pages>204</pages>
<isbn10>0511801386</isbn10>
<isbn13>9780511801389</isbn13>
<description>
This is the first comprehensive introduction to Support Vector Machines (SVMs), a new generation learning system based on recent advances in statistical learning theory.
Students will find the book both stimulating and accessible, while practitioners will be guided smoothly through the material required for a good grasp of the theory and its applications.
The concepts are introduced gradually in accessible and self-contained stages, while the presentation is rigorous and thorough.
Pointers to relevant literature and web sites containing software make it an ideal starting point for further study.
</description>
<categories>
<category>Computers - Artificial Intelligence (AI)</category>
</categories>
</book>
</library>
26 changes: 26 additions & 0 deletions Lab10/src/main/resources/static/Ajax.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html>
<head>
<title>Books</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script src="javascript.js"></script>
</head>
<body>
<h1>Books</h1>
<table id="booksTable" border="1">
<thead>
<tr>
<th>Title</th>
<th>Author</th>
<th>Year</th>
<th>Language</th>
<th>Description</th>
<th>Publisher</th>
<th>ISBN-10</th>
<th>ISBN-13</th>
</tr>
</thead>
<tbody></tbody>
</table>
</body>
</html>
27 changes: 27 additions & 0 deletions Lab10/src/main/resources/static/javascript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
$(document).ready(() => {
$.ajax({
type: "GET",
url: "/data",
success: (response) => {
const books = JSON.parse(response);
const tableBody = $('#booksTable tbody');
books.forEach((book) => {
const { title, author, year, language, description, publisher, isbn10, isbn13 } = book;
const row = `<tr>
<td>${title}</td>
<td>${author}</td>
<td>${year}</td>
<td>${language}</td>
<td>${description}</td>
<td>${publisher}</td>
<td>${isbn10}</td>
<td>${isbn13}</td>
</tr>`;
tableBody.append(row);
});
},
error: () => {
alert('Error fetching data');
}
});
});
Empty file added Lab6/a.txt
Empty file.
Loading

0 comments on commit a99f05a

Please sign in to comment.