Commit 8d8d626a authored by Adrián Piaček's avatar Adrián Piaček
Browse files

Added gaming-sample-data module

parent 0e491906
Pipeline #141025 passed with stage
in 1 minute and 6 seconds
......@@ -13,8 +13,15 @@ The goal of the system is to manage teams of users participating to eSports comp
## Building instructions
You can run the Online Gaming Management System with maven:
- ` mvn clean install ` compile sources
### Milestone 3
#### Web Application
- start in the root directory `online-gaming-management-system`
- use `mvn clean install` to compile sources
- `cd gaming-spring-mvc` move to the module of the web app
- execute `mvn cargo:run` to start the server
- UI - open `http://localhost:8080/pa165/` in the browser
## Diagrams for assignment
### Class diagram
......
......@@ -2,7 +2,9 @@ package cz.muni.fi.pa165.entity;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.Cascade;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
......@@ -19,11 +21,11 @@ import java.util.Set;
@Entity
public class PlayerEntity extends PersonEntity {
@ManyToOne
@ManyToOne(cascade = CascadeType.PERSIST)
@JoinColumn(name = "team_id_player")
private TeamEntity team;
@ManyToMany(mappedBy = "players")
@ManyToMany(mappedBy = "players",cascade = CascadeType.PERSIST)
private Set<MatchEntity> matches = new HashSet<>();
private int killStat;
......
......@@ -4,6 +4,7 @@ import cz.muni.fi.pa165.enums.CountryEnum;
import lombok.Getter;
import lombok.Setter;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
......@@ -24,16 +25,16 @@ public class TeamEntity extends BaseEntity {
private String name;
private CountryEnum country;
@OneToMany(mappedBy = "team")
@OneToMany(mappedBy = "team", cascade = CascadeType.PERSIST)
private Set<PlayerEntity> playerList = new HashSet<>();
@OneToMany(mappedBy = "team")
@OneToMany(mappedBy = "team", cascade = CascadeType.PERSIST)
private Set<TeamCoachEntity> coachList = new HashSet<>();
@ManyToMany(mappedBy = "teamsEnrolled")
@ManyToMany(mappedBy = "teamsEnrolled", cascade = CascadeType.PERSIST)
private Set<TournamentEntity> completedTournaments = new HashSet<>();
@ManyToMany(mappedBy = "teamsSigned")
@ManyToMany(mappedBy = "teamsSigned", cascade = CascadeType.PERSIST)
private Set<TournamentEntity> plannedTournaments = new HashSet<>();
@ManyToMany
......
<?xml version="1.0" encoding="UTF-8"?>
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>online-gaming-management-system</artifactId>
<groupId>cz.muni.fi.pa165</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>gaming-sample-data</artifactId>
<packaging>jar</packaging>
<name>Sample data</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spring.security.version>5.0.0.RELEASE</spring.security.version>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<scope>test</scope><!-- logging implementation should not be part of a library, but is needed for tests -->
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>jakarta.el</artifactId>
<scope>test</scope><!-- conflicts with tomcat libraries, but needed for tests -->
</dependency>
<dependency>
<groupId>cz.muni.fi.pa165</groupId>
<artifactId>gaming-service</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
package cz.muni.fi.pa165.sampledata;
import cz.muni.fi.pa165.config.ServiceConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import javax.annotation.PostConstruct;
import java.io.IOException;
/**
* Takes ServiceConfiguration and adds the SampleDataLoadingFacade bean.
*
* @author Martin Kuba makub@ics.muni.cz
*/
@Configuration
@Import(ServiceConfiguration.class)
@ComponentScan(basePackageClasses = {SampleDataLoadingFacadeImpl.class})
public class ManagementSystemSampleDataConfiguration {
final static Logger log = LoggerFactory.getLogger(ManagementSystemSampleDataConfiguration.class);
@Autowired
SampleDataLoadingFacade sampleDataLoadingFacade;
@PostConstruct
public void dataLoading() throws IOException {
log.debug("dataLoading()");
sampleDataLoadingFacade.loadData();
}
}
package cz.muni.fi.pa165.sampledata;
import java.io.IOException;
public interface SampleDataLoadingFacade {
void loadData() throws IOException;
}
package cz.muni.fi.pa165.sampledata;
import cz.muni.fi.pa165.entity.PlayerEntity;
import cz.muni.fi.pa165.entity.TeamEntity;
import cz.muni.fi.pa165.enums.CountryEnum;
import cz.muni.fi.pa165.services.player.PlayerService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import java.io.IOException;
import java.time.LocalDate;
/**
* Loads some sample data to populate the eshop database.
*
* @author Martin Kuba makub@ics.muni.cz
*/
@Component
@Transactional //transactions are handled on facade layer
public class SampleDataLoadingFacadeImpl implements SampleDataLoadingFacade {
final static Logger log = LoggerFactory.getLogger(SampleDataLoadingFacadeImpl.class);
@Autowired
private PlayerService playerService;
@Override
@SuppressWarnings("unused")
public void loadData() throws IOException {
TeamEntity team = new TeamEntity();
team.setName("Autisti");
PlayerEntity crimsix = player("Ian Porter", LocalDate.of(1990,2,4), CountryEnum.AFGHANISTAN, team
,5,6,7);
PlayerEntity JJoNak = player("Bang Seong-hyun ", LocalDate.of(1995,2,4), CountryEnum.AFGHANISTAN, team
,5,6,7);
log.info("Loaded eShop orders.");
}
private PlayerEntity player(String name, LocalDate dateOfBirth, CountryEnum country, TeamEntity team,
int killStat, int deathStat, int assistStat) {
PlayerEntity player = new PlayerEntity();
player.setName(name);
player.setDateOfBirth(dateOfBirth);
player.setCountry(country);
player.setTeam(team);
player.setKillStat(killStat);
player.setDeathStat(deathStat);
player.setAssistStat(assistStat);
playerService.create(player);
return player;
}
}
......@@ -23,17 +23,6 @@
<version>4.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cz.muni.fi.pa165</groupId>
<artifactId>gaming-persistence</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>cz.muni.fi.pa165</groupId>
<artifactId>gaming-api</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
......@@ -51,6 +40,12 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>cz.muni.fi.pa165</groupId>
<artifactId>gaming-api</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<properties>
......
......@@ -113,19 +113,21 @@
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>cz.muni.fi.pa165</groupId>
<artifactId>gaming-api</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>cz.muni.fi.pa165</groupId>
<artifactId>gaming-service</artifactId>
<artifactId>gaming-sample-data</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<!-- <dependency>-->
<!-- <groupId>cz.muni.fi.pa165</groupId>-->
<!-- <artifactId>gaming-service</artifactId>-->
<!-- <version>1.0-SNAPSHOT</version>-->
<!-- <scope>compile</scope>-->
<!-- </dependency>-->
</dependencies>
<!--
......
......@@ -23,6 +23,8 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver;
@ComponentScan(basePackages = { "cz.muni.fi.pa165.mvc.controllers" })
public class MyConfig implements WebMvcConfigurer {
private static final String TEXTS = "Texts";
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("index");
......@@ -50,7 +52,7 @@ public class MyConfig implements WebMvcConfigurer {
// It should not be necessary in the newer Java versions but for some reason even when converted to UTF-8, it still loads
// the Texts*.properties as ISO-8859-1
messageSource.setDefaultEncoding("UTF-8");
//messageSource.setBasename(TEXTS);
messageSource.setBasename(TEXTS);
return messageSource;
}
......
package cz.muni.fi.pa165.mvc.controllers;
import cz.muni.fi.pa165.dto.PlayerDTO;
import cz.muni.fi.pa165.facade.PlayerFacade;
import cz.muni.fi.pa165.facade.TournamentFacade;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.util.List;
import java.util.UUID;
/**
* @author Marek Kadlečík
*/
@Controller
@RequestMapping("/player")
public class PlayerController {
@Autowired
private PlayerFacade playerFacade;
@RequestMapping(value = "/list", method = RequestMethod.GET)
public String list(Model model) {
List<PlayerDTO> players = playerFacade.findAllPlayers();
model.addAttribute("players", players);
return "player/list";
}
@RequestMapping(value = "/new", method = RequestMethod.GET)
public String newPlayer(Model model) {
// TODO model.addAttribute("tournamentsCreate", new CreateTournamentDTO() ...);
return "player/new";
}
@RequestMapping(value = "/view/{id}", method = RequestMethod.GET)
public String view(@PathVariable UUID id, Model model) {
// TODO model.addAttribute("tournament", tournamentFacade.getTournamentWithId(id));
return "player/view";
}
// TODO delete
}
......@@ -8,9 +8,9 @@ import org.springframework.web.bind.annotation.GetMapping;
*/
@Controller
public class SampleController {
@GetMapping("/sample")
@GetMapping("/")
public String showForm() {
return "sample";
return "home";
}
}
#ResourceBundle for default language - English
# Navigation menu
navigation.project=PA165 Online Gaming Managment System
navigation.admin=Administration
navigation.admin.tournaments=Tournaments
navigation.eshop=eShop
navigation.project= Online Gaming Management System
navigation.admin= Admin
navigation.tournaments = Tournaments
navigation.teams = Teams
navigation.players = Players
navigation.coaches = Coaches
navigation.matches = Matches
navigation.ranklist.players = Ranklist Players
navigation.ranklist.teams= Ranklist Teams
# ResourceBundle for Czech localisation
# Navigation menu
navigation.project=PA165 SpringMVC eShop
navigation.admin=Správa
navigation.eshop=Nákupy
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="utf-8" trimDirectiveWhitespaces="false" session="false" %>
<%@ taglib tagdir="/WEB-INF/tags" prefix="my" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<my:pagetemplate title="Players">
<jsp:attribute name="body">
<my:a href="/player/new" class="btn btn-primary">
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
New Player
</my:a>
<table class="table">
<thead>
<tr>
<th>id</th>
<th>name</th>
<th>dateOfBirth</th>
<th>county</th>
<th>team</th>
<th>killStat</th>
<th>deathStat</th>
<th>assistStat</th>
</tr>
</thead>
<tbody>
<c:forEach items="${players}" var="player">
<tr>
<td>${player.id}</td>
<td><c:out value="${player.id}"/></td>
<td><c:out value="${player.name}"/></td>
<td><c:out value="${player.dateOfBirth}"/></td>
<td><c:out value="${player.county}"/></td>
<td><c:out value="${player.team}"/></td>
<td><c:out value="${player.killStat}"/></td>
<td><c:out value="${player.deathStat}"/></td>
<td><c:out value="${player.assistStat}"/></td>
</tr>
</c:forEach>
</tbody>
</table>
</jsp:attribute>
</my:pagetemplate>
\ No newline at end of file
......@@ -28,17 +28,27 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="${pageContext.request.contextPath}"><f:message key="navigation.project"/></a>
<a class="navbar-brand" href="${pageContext.request.contextPath}/"><f:message key="navigation.project"/></a>
</div>
<div id="navbar" class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><my:a href="/shopping/show"><f:message key="navigation.eshop"/></my:a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><f:message key="navigation.teams"/><b class="caret"></b></a>
<ul class="dropdown-menu">
<li><my:a href="/tournament/list"><f:message key="navigation.coaches"/></my:a></li>
<li><my:a href="/tournament/list"><f:message key="navigation.ranklist.teams"/></my:a></li>
</ul>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><f:message key="navigation.admin"/><b class="caret"></b></a>
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><f:message key="navigation.players"/><b class="caret"></b></a>
<ul class="dropdown-menu">
<li><my:a href="/tournament/list"><f:message key="navigation.admin.tournaments"/></my:a></li>
<li><my:a href="/player/list"><f:message key="navigation.players"/></my:a></li>
<li><my:a href="/tournament/list"><f:message key="navigation.ranklist.players"/></my:a></li>
</ul>
</li>
<li><my:a href="/tournament/list"><f:message key="navigation.tournaments"/></my:a></li>
<li><my:a href="/tournament/list"><f:message key="navigation.matches"/></my:a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
......
......@@ -8,6 +8,7 @@
<module>gaming-service</module>
<module>gaming-persistence</module>
<module>gaming-spring-mvc</module>
<module>gaming-sample-data</module>
</modules>
<groupId>cz.muni.fi.pa165</groupId>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment