Anul 3 Semestrul 2

This commit is contained in:
2025-07-03 20:56:38 +03:00
parent 184f3bd92e
commit 3b7fb85767
269 changed files with 20955 additions and 0 deletions
@@ -0,0 +1,39 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store
allure-results/
@@ -0,0 +1,3 @@
sha,filename,url,lines,title,comment,priority,category,additional,id,private
"","\src\main\java\curent\Curent.java","","28:8-28:52","Move hardcoded value to a config file","","0","Best Practices","","d6456668-ad58-4a3f-a01c-5567aa06405b","0"
"","\src\main\java\curent\Curent.java","","33:10-35:9","Catch-Throw Bad Practice","","0","Best Practices","","6074a0bd-1291-4e9a-829a-f94f9cdad443","1"
1 sha filename url lines title comment priority category additional id private
2 \src\main\java\curent\Curent.java 28:8-28:52 Move hardcoded value to a config file 0 Best Practices d6456668-ad58-4a3f-a01c-5567aa06405b 0
3 \src\main\java\curent\Curent.java 33:10-35:9 Catch-Throw Bad Practice 0 Best Practices 6074a0bd-1291-4e9a-829a-f94f9cdad443 1
@@ -0,0 +1,124 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Code Review</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
/* basic style */
body {
font-family: Helvetica;
}
h1 {
font-size: 24px;
}
h2 {
font-size: 20px;
color: green;
}
h3 {
font-size: 16px;
padding-left: 5px;
margin-bottom: 5px;
}
p {
white-space: pre-wrap;
margin: 0;
}
pre {
margin: 0
}
code {
border: 1px solid #999;
display: block;
white-space: pre-wrap;
}
/* links in headlines */
h3.lines-headline>a {
color: #005bbb;
text-decoration: none;
}
h3.lines-headline>a:hover {
text-decoration: underline;
}
/* table style */
table.review-table {
font-size: 14px;
padding-left: 10px;
}
table.review-table .caption {
font-weight: bold;
vertical-align: top;
}
table.review-table tr>td:first-child {
width: 120px
}
/* priority indicator */
.text>span:before {
content: "";
width: 10px;
height: 10px;
border-radius: 50%;
display: inline-block;
margin-right: 5px;
margin-left: -15px;
}
.text>span.prio-high:before {
background: #FF4500;
}
.text>span.prio-medium:before {
background: #FFD700;
}
.text>span.prio-low:before {
background: #9ACD32;
}
.text>span.prio-none:before {
background: #D3D3D3;
}
</style>
</head>
<body>
<h1 class="main-headline">Code Review Results</h1>
<section class="file-section">
<h2 class="file-section-headline">\src\main\java\curent\Curent.java</h2>
<h3 class="lines-headline">
<a href="">Position: 28:8-28:52</a>
</h3>
<table class="review-table">
<tr class="row-priority">
<td class="caption">Priority</td>
<td class="text">
<span class="prio-0">0</span>
</td>
</tr>
<tr class="row-title">
<td class="caption">Title</td>
<td class="text">Move hardcoded value to a config file</td>
</tr>
<tr class="row-category">
<td class="caption">Category</td>
<td class="text">Best Practices</td>
</tr>
</table>
</section>
</body>
</html>
@@ -0,0 +1,30 @@
Tema: 1111
Nota: 9.5
Predata in saptamana: 1
Deadline: 1
Feedback: Amazing work
Tema: 1111
Nota: 9.5
Predata in saptamana: 1
Deadline: 1
Feedback: Amazing work
Tema: 1111
Nota: 9.5
Predata in saptamana: 1
Deadline: 1
Feedback: Amazing work
Tema: 1111
Nota: 9.5
Predata in saptamana: 1
Deadline: 1
Feedback: Amazing work
Tema: 1111
Nota: 9.5
Predata in saptamana: 1
Deadline: 1
Feedback: Amazing work
@@ -0,0 +1 @@
2018,10,1
@@ -0,0 +1,9 @@
1,1,9.5,2018-10-07
1,2,10.0,2018-10-14
2,3,7.0,2018-10-28
55,5,3.5,2018-11-22
6,5,10.0,2018-11-15
55,4,5.5,2018-11-10
6,13,10.0,2018-11-16
55,13,10.0,2018-11-16
55,14,7.5,2018-11-16
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><inbox><nota><idStudent>1</idStudent><idTema>1</idTema><notaProf>10.0</notaProf><dataCurenta>2018-10-10</dataCurenta></nota></inbox>
@@ -0,0 +1,8 @@
1,Marginean Diana,225,mdir2356@scs.ubbcluj.ro
2,Militon Rares,224,mrir1356@scs.ubbcluj.ro
3,Pop Diana,227,pdir5424@scs.ubbcluj.ro
4,Danciu Razvan,221,drir3456@scs.ubbcluj.ro
1003,Razvan Cu O,221,raz3456@scs.ubbcluj.ro
5,mama,222,la
55,eu,222,eu@gmail.com
6,la,112,la@la.com
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><inbox><student idStudent="1"><nume>a</nume><grupa>1</grupa><email>a</email></student><student idStudent="2"><nume>test</nume><grupa>231312</grupa><email>test@test.com</email></student><student idStudent="500"><nume>Test</nume><grupa>100</grupa><email>test@test.com</email></student><student idStudent="1002"><nume>Dia</nume><grupa>224</grupa><email>dia@yahoo.com</email></student><student idStudent="1001"><nume>Arina</nume><grupa>222</grupa><email>arina@yahoo.com</email></student></inbox>
@@ -0,0 +1,11 @@
1,Tema numarul 1,2,1
2,Tema numarul 2,3,2
3,Tema numarul 3,4,34
4,Tema numarul 4,5,10
5,Tema numarul 5,7,6
9,Tema cu numarul 9,8,5
10,Tema numarul 10,12,5
11,Tema numarul 11,8,5
12,Tema numarul 12,8,7
13,Tema numarul 13,7,6
14,Nr 14,6,5
@@ -0,0 +1 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><inbox><nrTema nrTema="1"><descriere>file repository</descriere><deadline>2</deadline><primire>1</primire></nrTema><nrTema nrTema="100"><descriere>test</descriere><deadline>6</deadline><primire>4</primire></nrTema><nrTema nrTema="2"><descriere>laborator crud repo</descriere><deadline>3</deadline><primire>2</primire></nrTema><nrTema nrTema="3"><descriere>abstract repository</descriere><deadline>4</deadline><primire>3</primire></nrTema><nrTema nrTema="300"><descriere>Test Homework</descriere><deadline>2</deadline><primire>1</primire></nrTema><nrTema nrTema="4"><descriere>service+consola</descriere><deadline>6</deadline><primire>5</primire></nrTema><nrTema nrTema="5"><descriere>repo in fisier</descriere><deadline>7</deadline><primire>6</primire></nrTema><nrTema nrTema="16"><descriere>16</descriere><deadline>14</deadline><primire>10</primire></nrTema><nrTema nrTema="6"><descriere>adaugare nota</descriere><deadline>8</deadline><primire>7</primire></nrTema></inbox>
@@ -0,0 +1,30 @@
Tema: 1
Nota: 10.0
Predata in saptamana: 2
Deadline: 2
Feedback: ok
Tema: 1
Nota: 10.0
Predata in saptamana: 2
Deadline: 2
Feedback: ok
Tema: 1
Nota: 10.0
Predata in saptamana: 2
Deadline: 2
Feedback: ok
Tema: 1
Nota: 10.0
Predata in saptamana: 2
Deadline: 2
Feedback: ok
Tema: 1
Nota: 9.5
Predata in saptamana: 2
Deadline: 2
Feedback: Amazing work
@@ -0,0 +1,24 @@
Tema: 5
Nota: 3.5
Predata in saptamana: 8
Deadline: 7
Feedback: repository
Tema: 4
Nota: 5.5
Predata in saptamana: 6
Deadline: 5
Feedback: este
Tema: 13
Nota: 10.0
Predata in saptamana: 7
Deadline: 7
Feedback: este ok!
Tema: 14
Nota: 7.5
Predata in saptamana: 7
Deadline: 6
Feedback: ok
@@ -0,0 +1,12 @@
Tema: 5
Nota: 10.0
Predata in saptamana: 7
Deadline: 7
Feedback: foarte
Tema: 13
Nota: 10.0
Predata in saptamana: 7
Deadline: 7
Feedback: nu necesita imbunatatiri!
@@ -0,0 +1,74 @@
<?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>
<groupId>org.example</groupId>
<artifactId>project</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.10.0</junit.version>
<allure.version>2.24.0</allure.version>
</properties>
<dependencies>
<!-- JUnit 5 -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<!-- Allure JUnit 5 Integration -->
<dependency>
<groupId>io.qameta.allure</groupId>
<artifactId>allure-junit5</artifactId>
<version>${allure.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>5.5.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Surefire Plugin for Running JUnit 5 Tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M7</version>
<configuration>
<systemPropertyVariables>
<allure.results.directory>${project.build.directory}/allure-results</allure.results.directory>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,41 @@
package app;
import repository.NotaFileRepository;
import repository.StudentFileRepository;
import repository.StudentXMLRepo;
import repository.TemaXMLRepo;
import repository.NotaXMLRepo;
import repository.TemaFileRepository;
import service.Service;
import validation.NotaValidator;
import validation.StudentValidator;
import validation.TemaValidator;
import view.UI;
public class MainApplication {
public static void main(String[] args) {
StudentValidator studentValidator = new StudentValidator();
TemaValidator temaValidator = new TemaValidator();
String filenameStudent = "fisiere/Studenti.xml";
String filenameTema = "fisiere/Teme.xml";
String filenameNota = "fisiere/Note.xml";
//StudentFileRepository studentFileRepository = new StudentFileRepository(filenameStudent);
//TemaFileRepository temaFileRepository = new TemaFileRepository(filenameTema);
//NotaValidator notaValidator = new NotaValidator(studentFileRepository, temaFileRepository);
//NotaFileRepository notaFileRepository = new NotaFileRepository(filenameNota);
StudentXMLRepo studentXMLRepository = new StudentXMLRepo(filenameStudent);
TemaXMLRepo temaXMLRepository = new TemaXMLRepo(filenameTema);
NotaValidator notaValidator = new NotaValidator(studentXMLRepository, temaXMLRepository);
NotaXMLRepo notaXMLRepository = new NotaXMLRepo(filenameNota);
Service service = new Service(studentXMLRepository, studentValidator, temaXMLRepository, temaValidator, notaXMLRepository, notaValidator);
UI ui = new UI(service);
ui.run();
}
}
@@ -0,0 +1,37 @@
package curent;
import validation.ValidationException;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.time.LocalDate;
import static java.time.temporal.ChronoUnit.DAYS;
public class Curent {
/**
* @return the current week from the starting of university
*/
public static int getCurrentWeek(){
LocalDate startDate = Curent.getStartDate();
LocalDate today = LocalDate.now();
long days = DAYS.between(startDate, today);
double diff = Math.ceil((double)days/7);
return (int)diff;
}
/**
* @return the date when university have started
*/
public static LocalDate getStartDate() {
String filename = "fisiere/DataInceput.txt";
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(filename))) {
String line = bufferedReader.readLine();
String[] words = line.split(",");
return LocalDate.of(Integer.parseInt(words[0]), Integer.parseInt(words[1]), Integer.parseInt(words[2]));
} catch (IOException exception) {
throw new ValidationException(exception.getMessage());
}
}
}
@@ -0,0 +1,103 @@
package domain;
import repository.HasID;
import java.time.LocalDate;
public class Nota implements HasID<String> {
private String id;
private String idStudent;
private String idTema;
private double nota;
private LocalDate data;
/**
* Class Constructor
* @param id - id-ul notei
* @param idStudent - id-ul studentului
* @param idTema - id-ul temei
* @param nota - valoarea notei
* @param data - data in care a fost predata tema
*/
public Nota(String id, String idStudent, String idTema, double nota, LocalDate data){
this.id = id;
this.idStudent = idStudent;
this.idTema = idTema;
this.nota = nota;
this.data = data;
}
/**
* @return id-ul studentului
*/
public String getIdStudent() {
return idStudent;
}
/**
* @return id-ul temei
*/
public String getIdTema() {
return idTema;
}
/**
* @return valoarea notei
*/
public double getNota() {
return nota;
}
/**
* Modifica valoarea unei note
* @param nota - noua valoarea a notei
*/
public void setNota(double nota) {
this.nota = nota;
}
/**
* @return data in care a fost predata nota
*/
public LocalDate getData() {
return data;
}
@Override
public String toString() {
return idStudent + "," + idTema + "," + nota + "," + data;
}
/**
* @return id-ul notei
*/
@Override
public String getID() {
return this.id;
}
/**
* modifica id-ul notei
* @param id - noul id
*/
@Override
public void setID(String id) {
this.id = id;
}
/**
* modifica id-ul studentului
* @param idStudent - noul id
*/
public void setIdStudent(String idStudent) {
this.idStudent = idStudent;
}
/**
* modifica id-ul temei
* @param idTema - noul id
*/
public void setIdTema(String idTema) {
this.idTema = idTema;
}
}
@@ -0,0 +1,92 @@
package domain;
import repository.HasID;
public class Student implements HasID<String> {
private String idStudent;
private String nume;
private int grupa;
private String email;
/**
* Class Constructor
* @param idStudent - id-ul studentului
* @param nume - numele studentului
* @param grupa - grupa studentului
* @param email - emailul unui student
*/
public Student(String idStudent, String nume, int grupa, String email) {
this.idStudent = idStudent;
this.nume = nume;
this.grupa = grupa;
this.email = email;
}
/**
* @return id-ul unui student
*/
public String getID() {
return idStudent;
}
/**
* modifica id-ul unui student
* @param ID - noul id al studentului
*/
public void setID(String ID) {
this.idStudent = ID;
}
/**
* @return numele studentului
*/
public String getNume() {
return nume;
}
/**
* modifica numele studentului
* @param nume - noul nume
*/
public void setNume(String nume) {
this.nume = nume;
}
/**
* @return grupa studentului
*/
public int getGrupa() {
return grupa;
}
/**
* modifica grupa studentului
* @param grupa - noua grupa
*/
public void setGrupa(int grupa) {
this.grupa = grupa;
}
/**
* @return emai-ul studentului
*/
public String getEmail() {
return email;
}
/**
* modifica emailul studentului
* @param email - noul email
*/
public void setEmail(String email) {
this.email = email;
}
/**
* @return un obiect de tip Student sub forma de string
*/
@Override
public String toString() {
return idStudent + "," + nume + "," + grupa + "," + email;
}
}
@@ -0,0 +1,96 @@
package domain;
import repository.HasID;
public class Tema implements HasID<String> {
private String nrTema;
private String descriere;
private int deadline;
private int primire;
/**
*
* @param nrTema - numarul temei
* @param descriere - descrierea unei teme
* @param deadline - deadlineul unei teme
* @param primire - saptamana de primirea unei teme
* Class Constructor
*/
public Tema(String nrTema, String descriere, int deadline, int primire) {
this.nrTema = nrTema;
this.descriere = descriere;
this.deadline = deadline;
this.primire = primire;
}
/**
* @return descrierea unei teme
*/
public String getDescriere() {
return descriere;
}
/**
* modifica descrierea unei teme
* @param descriere - noua descriere
*/
public void setDescriere(String descriere) {
this.descriere = descriere;
}
/**
* @return deadlineul unei teme
*/
public int getDeadline() {
return deadline;
}
/**
* modifica deadlineul unei note
*/
public void setDeadline(int deadline) {
this.deadline = deadline;
}
/**
* @return saptamana primirii unei teme
*/
public int getPrimire() {
return primire;
}
/**
* modifica saptamana primirii unei teme
* @param primire - noua saptamana de primire
*/
public void setPrimire(int primire) {
this.primire = primire;
}
/**
* @return numarul unei teme
*/
@Override
public String getID() {
return this.nrTema;
}
/**
* schimba numarul unei teme
* @param nrTema - noul numar al temei
*/
@Override
public void setID(String nrTema) {
this.nrTema = nrTema;
}
/**
* @return un obiect de tip Tema sub forma unui string
*/
@Override
public String toString() {
return nrTema + "," + descriere + "," + deadline + "," + primire;
}
}
@@ -0,0 +1,86 @@
package repository;
import java.util.HashMap;
import java.util.Map;
public abstract class AbstractCrudRepository <ID, E extends HasID<ID>> implements CrudRepository<ID, E> {
private Map<ID, E> elemente;
/**
* Class constructor
*/
AbstractCrudRepository(){
this.elemente = new HashMap<>();
}
/**
*
* @param id -the id of the entity to be returned
* id must not be null
* @return obiectul cu id-ul respectiv sau null daca obiectul nu exista
*/
@Override
public E findOne(ID id) {
return this.elemente.get(id);
}
/**
*
* @return toate obiectele
*/
@Override
public Iterable<E> findAll() {
return this.elemente.values();
}
/**
* Salveaza un obiect in memorie
* @param entity - obiectul pe care il salveaza
* entity must be not null
* @return null daca obiectul a fost salvat sau obiectul daca acesta exista deja
*/
@Override
public E save(E entity) {
/*
for(ID id: elemente.keySet()){
if(id == entity.getID()){
return elemente.get(id);
}
}
*/
E el = this.findOne(entity.getID());
if (el==null){
this.elemente.put(entity.getID(), entity);
return null;
}
else return entity;
}
/**
* sterge un obiect din memorie
* @param id - id-ul obiectului
* id must be not null
* @return obiectul sters
*/
@Override
public E delete(ID id) {
return this.elemente.remove(id);
}
/**
* modifica un obiect
* @param entity - noul obiect
* entity must not be null
* @return null daca obiectul a fost modificat sau obiectul daca acesta nu exista in memorie
*/
@Override
public E update(E entity) {
if(this.elemente.get(entity.getID()) == null){
return entity;
}
this.elemente.replace(entity.getID(), entity);
return null;
}
}
@@ -0,0 +1,110 @@
package repository;
import validation.ValidationException;
import java.io.*;
public abstract class AbstractFileRepository<ID, E extends HasID<ID>> extends AbstractCrudRepository<ID, E> implements FileRepository<ID, E> {
private String filename;
/**
* Class constructor
* @param filename - numele fisierului
*/
AbstractFileRepository(String filename) {
this.filename = filename;
loadFromFile();
}
/**
* Extrage un obiect dintr-un String
* @param linie - String-ul din care extrage obiectul
* @return - obiectul
*/
public abstract E extractEntity(String linie);
/**
* Incarca datele din fisier
*/
public void loadFromFile(){
try (BufferedReader bufferedReader = new BufferedReader(new FileReader(filename))) {
String linie;
while ((linie = bufferedReader.readLine()) != null) {
E entity = extractEntity(linie);
super.save(entity);
}
} catch (IOException exception) {
throw new ValidationException(exception.getMessage());
}
}
/**
* Scrie un obiect nou in fisier
* @param entity - obiectul pe care il scrie
*/
public void saveToFile(E entity){
try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(filename, true))) {
bufferedWriter.write(entity.toString());
bufferedWriter.newLine();
} catch (IOException exception) {
throw new ValidationException(exception.getMessage());
}
}
/**
* Rescrie fisierul cu toate obiectele din memorie
*/
public void writeToFile(){
try (PrintWriter b = new PrintWriter(this.filename)) {
//Iterable<E> all = super.findAll();
super.findAll().forEach(e -> b.println(e.toString()));
}
catch (IOException exception) {
throw new ValidationException(exception.getMessage());
}
}
/**
* Salveaza un obiect
* @param entity - obiectul pe care il salveaza
* @return null daca obiectul s-a salvat cu succes sau obiectul daca acesta exista deja in memorie
*/
@Override
public E save(E entity) {
E entity1 = super.save(entity);
if (entity1 == null) {
saveToFile(entity);
}
return entity1;
}
/**
* Sterge un obiect
* @param id - id-ul obiectului
* @return obiectul daca s-a reusit stergerea sau null daca obiectul nu exista
*/
@Override
public E delete(ID id) {
E entity = super.delete(id);
if(entity != null){
writeToFile();
}
return entity;
}
/**
* Modifica un obiect
* @param entity - noul obiect
* @return null daca obiectul a fost modificat sau obiectul, daca acesta nu exista
*/
@Override
public E update(E entity) {
E entity1 = super.update(entity);
if(entity == null){
writeToFile();
}
return entity1;
}
}
@@ -0,0 +1,165 @@
package repository;
import domain.Student;
import validation.ValidationException;
import java.io.*;
import java.util.Optional;
//import javafx.scene.input.DataFormat;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
public abstract class AbstractXMLRepository<ID, E extends HasID<ID>> extends AbstractCrudRepository<ID, E> implements FileRepository<ID, E> {
private String filename;
private DocumentBuilderFactory builderFactory;
/**
* Class constructor
* @param filename - numele fisierului
*/
AbstractXMLRepository(String filename) {
this.filename = filename;
builderFactory=DocumentBuilderFactory.newInstance();
loadFromFile();
}
/**
* Incarca datele din fisier
*/
public void loadFromFile(){
try {
Document document = DocumentBuilderFactory
.newInstance()
.newDocumentBuilder()
.parse(this.filename);
Element root = document.getDocumentElement();
NodeList children = root.getChildNodes();
for(int i=0; i < children.getLength(); i++) {
Node entityElement = children.item(i);
if(entityElement.getNodeType()==Node.ELEMENT_NODE) {
E entity = extractEntity((Element)entityElement);
super.save(entity);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Creeaza un elemenT XML dintr o entitate
* @param document
* @param entity
* @return
*/
public abstract Element createElementfromEntity(Document document, E entity);
/**
* Extrage un obiect dintr-un XML
* @param element - String-ul din care extrage obiectul
* @return - obiectul
*/
public abstract E extractEntity(Element element);
/**
* Salveaza un obiect
* @param entity - obiectul pe care il salveaza
* @return null daca obiectul s-a salvat cu succes sau obiectul daca acesta exista deja in memorie
*/
@Override
public E save(E entity) {
E entity1 = super.save(entity);
if (entity1 == null) {
//saveToFile(entity);
writeToFile();
}
return entity1;
}
/**
* Rescrie fisierul cu toate obiectele din memorie
*/
public void writeToFile(){
try {
Document document = DocumentBuilderFactory
.newInstance()
.newDocumentBuilder()
.newDocument();
Element root = document.createElement("inbox");
document.appendChild(root);
super.findAll().forEach(e->{
Element elem = createElementfromEntity(document,e);
root.appendChild(elem);
});
//write Document to file
Transformer transformer = TransformerFactory.
newInstance().newTransformer();
transformer.transform(new DOMSource(document),
new StreamResult(this.filename));
}catch(Exception e){
e.printStackTrace();
}
}
/**
* Scrie un obiect nou in fisier
* @param entity - obiectul pe care il scrie
*/
public void saveToFile(E entity)
{
//E e = super.save(entity);
//if(e==null){writeToFile();
//}
//return e;
}
/**
* Sterge un obiect
* @param id - id-ul obiectului
* @return obiectul daca s-a reusit stergerea sau null daca obiectul nu exista
*/
@Override
public E delete(ID id) {
E entity = super.delete(id);
if(entity != null){
writeToFile();
}
return entity;
}
/**
* Modifica un obiect
* @param entity - noul obiect
* @return null daca obiectul a fost modificat sau obiectul, daca acesta nu exista
*/
@Override
public E update(E entity) {
E entity1 = super.update(entity);
if(entity == null){
writeToFile();
}
return entity1;
}
}
@@ -0,0 +1,58 @@
package repository;
import validation.ValidationException;
/**
* CRUD operations repository interface
* @param <ID> - type E must have an attribute of type ID
* @param <E> - type of entities saved in repository
*/
public interface CrudRepository<ID, E> {
/**
*
* @param id -the id of the entity to be returned
* id must not be null
* @return the entity with the specified id
* or null - if there is no entity with the given id
* @throws IllegalArgumentException
* if id is null.
*/
E findOne(ID id);
/**
*
* @return all entities
*/
Iterable<E> findAll();
/**
*
* @param entity
* entity must be not null
* @return null- if the given entity is saved
* otherwise returns the entity (id already exists)
* @throws ValidationException
* if the entity is not valid
* @throws IllegalArgumentException
* if the given entity is null. *
*/
E save(E entity) throws ValidationException;
/**
* removes the entity with the specified id
* @param id
* id must be not null
* @return the removed entity or null if there is no entity with the given id
* @throws IllegalArgumentException
* if the given id is null.
*/
E delete(ID id);
/**
*
* @param entity
* entity must not be null
* @return null - if the entity is updated,
* otherwise returns the entity - (e.g id does not exist).
* @throws IllegalArgumentException
* if the given entity is null.
* @throws ValidationException
* if the entity is not valid.
*/
E update(E entity);
}
@@ -0,0 +1,25 @@
package repository;
/**
* CRUD operations file repository interface
* @param <ID> - type E must have an attribute of type ID
* @param <E> - type of entities saved in repository
*/
public interface FileRepository<ID, E extends HasID<ID>> {
/**
* Incarca datele din fisier
*/
void loadFromFile();
/**
* Scrie un obiect nou in fisier
* @param entity - obiectul pe care il scrie
*/
void saveToFile(E entity);
/**
* Rescrie fisierul
*/
void writeToFile();
}
@@ -0,0 +1,16 @@
package repository;
public interface HasID<ID> {
/**
*
* @return id-ul unui obiect
*/
ID getID();
/**
* Modifica id-ul unul obiect
* @param id - noul id
*/
void setID(ID id);
}
@@ -0,0 +1,28 @@
package repository;
import domain.Nota;
import java.time.LocalDate;
public class NotaFileRepository extends AbstractFileRepository<String, Nota> {
/**
* Class constructor
* @param filename - numele fisierului
*/
public NotaFileRepository(String filename) {
super( filename);
}
/**
* Extrage informatia despre nota dintr-un string
* @param line - stringul din care ia datele notei
* @return nota
*/
@Override
public Nota extractEntity(String line) {
String[] words = line.split(",");
String[] data = words[3].split("-");
LocalDate date = LocalDate.of(Integer.parseInt(data[0]), Integer.parseInt(data[1]), Integer.parseInt(data[2]));
return new Nota(words[0]+"#"+words[1], words[0], words[1], Double.parseDouble(words[2]), date);
}
}
@@ -0,0 +1,78 @@
package repository;
import domain.Nota;
import java.time.LocalDate;
import domain.Nota;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
public class NotaXMLRepo extends AbstractXMLRepository<String, Nota> {
/**
* Class constructor
* @param filename - numele fisierului
*/
public NotaXMLRepo(String filename) {
super( filename);
}
@Override
public Element createElementfromEntity(Document document, Nota entity) {
Element e = document.createElement("nota");
Element idStudent = document.createElement("idStudent");
idStudent.setTextContent(entity.getIdStudent());
e.appendChild(idStudent);
Element idTema = document.createElement("idTema");
idTema.setTextContent(entity.getIdTema());
e.appendChild(idTema);
Element notaProf = document.createElement("notaProf");
Double i=entity.getNota();
notaProf.setTextContent(i.toString());
e.appendChild(notaProf);
Element data = document.createElement("dataCurenta");
LocalDate d = entity.getData();
data.setTextContent(d.toString());
e.appendChild(data);
return e;
}
/**
* Extrage informatia despre nota dintr-un XML
* @param element - elem XML din care ia datele notei
* @return nota
*/
@Override
public Nota extractEntity(Element element) {
String id = element.getAttribute("id");
NodeList nods = element.getChildNodes();
String studentId =element.getElementsByTagName("idStudent")
.item(0)
.getTextContent();
String temaId =element.getElementsByTagName("idTema")
.item(0)
.getTextContent();
String notaProf =element.getElementsByTagName("notaProf")
.item(0)
.getTextContent();
String data =element.getElementsByTagName("dataCurenta")
.item(0)
.getTextContent();
String[] d = data.split("-");
LocalDate dat = LocalDate.of(Integer.parseInt(d[0]), Integer.parseInt(d[1]), Integer.parseInt(d[2]));
return new Nota(id,studentId,temaId,Double.parseDouble(notaProf),dat);
}
}
@@ -0,0 +1,25 @@
package repository;
import domain.Student;
public class StudentFileRepository extends AbstractFileRepository<String, Student> {
/**
* Class constructor
* @param filename - numele fisierului
*/
public StudentFileRepository(String filename) {
super(filename);
}
/**
* Extrage informatia despre student dintr-un string
* @param linie - stringul din care ia datele studentului
* @return studentul
*/
@Override
public Student extractEntity(String linie) {
String[] cuvinte = linie.split(",");
return new Student(cuvinte[0], cuvinte[1], Integer.parseInt(cuvinte[2]), cuvinte[3]);
}
}
@@ -0,0 +1,62 @@
package repository;
import domain.Student;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
public class StudentXMLRepo extends AbstractXMLRepository<String, Student> {
/**
* Class constructor
* @param filename - numele fisierului
*/
public StudentXMLRepo(String filename) {
super(filename);
}
/**
* Extrage informatia despre student dintr-un element XML
* @param element - XML-ul din care ia datele studentului
* @return studentul
*/
@Override
public Student extractEntity(Element element) {
String studentId = element.getAttribute("idStudent");
NodeList nods = element.getChildNodes();
String nume =element.getElementsByTagName("nume")
.item(0)
.getTextContent();
String grupa =element.getElementsByTagName("grupa")
.item(0)
.getTextContent();
String email =element.getElementsByTagName("email")
.item(0)
.getTextContent();
return new Student(studentId, nume, Integer.parseInt(grupa), email);
}
@Override
public Element createElementfromEntity(Document document, Student entity) {
Element e = document.createElement("student");
e.setAttribute("idStudent", entity.getID());
Element nume = document.createElement("nume");
nume.setTextContent(entity.getNume());
e.appendChild(nume);
Element grupa = document.createElement("grupa");
Integer g=entity.getGrupa();
grupa.setTextContent(g.toString());
e.appendChild(grupa);
Element email = document.createElement("email");
email.setTextContent(entity.getEmail());
e.appendChild(email);
return e;
}
}
@@ -0,0 +1,25 @@
package repository;
import domain.Tema;
public class TemaFileRepository extends AbstractFileRepository<String, Tema> {
/**
* Class constructor
* @param filename - numele fisierului
*/
public TemaFileRepository(String filename){
super(filename);
}
/**
* Extrage informatia despre tema dintr-un string
* @param linie - stringul din care ia datele temei
* @return tema
*/
@Override
public Tema extractEntity(String linie) {
String[] cuvinte = linie.split(",");
return new Tema(cuvinte[0], cuvinte[1], Integer.parseInt(cuvinte[2]), Integer.parseInt(cuvinte[3]));
}
}
@@ -0,0 +1,67 @@
package repository;
import domain.Tema;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
public class TemaXMLRepo extends AbstractXMLRepository<String, Tema> {
/**
* Class constructor
* @param filename - numele fisierului
*/
public TemaXMLRepo(String filename){
super(filename);
}
/**
* Extrage informatia despre tema dintr-un elem XML
* @param element - stringul din care ia datele temei
* @return tema
*/
@Override
public Tema extractEntity(Element element) {
String nrTema = element.getAttribute("nrTema");
NodeList nods = element.getChildNodes();
String descriere =element.getElementsByTagName("descriere")
.item(0)
.getTextContent();
String deadline =element.getElementsByTagName("deadline")
.item(0)
.getTextContent();
String primire =element.getElementsByTagName("primire")
.item(0)
.getTextContent();
return new Tema(nrTema, descriere, Integer.parseInt(deadline), Integer.parseInt(primire));
}
/**
* Creeaza un element XML dintr o entitate Tema
* @param document
* @param entity
* @return
*/
@Override
public Element createElementfromEntity(Document document, Tema entity) {
Element e = document.createElement("nrTema");
e.setAttribute("nrTema", entity.getID());
Element descriere = document.createElement("descriere");
descriere.setTextContent(entity.getDescriere());
e.appendChild(descriere);
Element deadline = document.createElement("deadline");
Integer g=entity.getDeadline();
deadline.setTextContent(g.toString());
e.appendChild(deadline);
Element primire = document.createElement("primire");
Integer p=entity.getPrimire();
primire.setTextContent(p.toString());
e.appendChild(primire);
return e;
}
}
@@ -0,0 +1,278 @@
package service;
import curent.Curent;
import domain.Nota;
import domain.Student;
import domain.Tema;
import repository.*;
import validation.NotaValidator;
import validation.StudentValidator;
import validation.TemaValidator;
import validation.ValidationException;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDate;
import static java.time.temporal.ChronoUnit.DAYS;
/**
* Clasa Service
*/
public class Service {
// private StudentFileRepository studentFileRepository;
private StudentXMLRepo studentFileRepository;
private StudentValidator studentValidator;
// private TemaFileRepository temaFileRepository;
private TemaXMLRepo temaFileRepository;
private TemaValidator temaValidator;
// private NotaFileRepository notaFileRepository;
private NotaXMLRepo notaFileRepository;
private NotaValidator notaValidator;
/**
* Class Constructor
*
* @param studentFileRepository - repository student
* @param studentValidator - validator student
* @param temaFileRepository - repository tema
* @param temaValidator - validator tema
* @param notaFileRepository - repository nota
* @param notaValidator - validator nota
*/
// public Service(StudentFileRepository studentFileRepository, StudentValidator
// studentValidator, TemaFileRepository temaFileRepository, TemaValidator
// temaValidator, NotaFileRepository notaFileRepository, NotaValidator
// notaValidator) {
public Service(StudentXMLRepo studentFileRepository, StudentValidator studentValidator,
TemaXMLRepo temaFileRepository, TemaValidator temaValidator, NotaXMLRepo notaFileRepository,
NotaValidator notaValidator) {
this.studentFileRepository = studentFileRepository;
this.studentValidator = studentValidator;
this.temaFileRepository = temaFileRepository;
this.temaValidator = temaValidator;
this.notaFileRepository = notaFileRepository;
this.notaValidator = notaValidator;
}
/**
* adauga un Student in memorie
*
* @param student - studentul pe care il adauga
* @return null daca studentul a fost adaugat cu succes sau studentul din
* memorie daca acesta exista deja
*/
public Student addStudent(Student student) {
studentValidator.validate(student);
if (this.findStudent(student.getID()) != null) {
throw new ValidationException("Studentul exista!");
}
return studentFileRepository.save(student);
}
/**
* Sterge un student
*
* @param id - id-ul studentului
* @return studentul daca acesta a fost sters sau null daca studentul nu exista
*/
public Student deleteStudent(String id) {
if (id == null || id.equals("")) {
throw new ValidationException("Id-ul nu poate fi null!");
}
return studentFileRepository.delete(id);
}
/**
* Cauta un student dupa id
*
* @param id - id-ul studentului
* @return studentul daca acesta exista sau null altfel
*/
public Student findStudent(String id) {
if (id == null || id.equals("")) {
throw new ValidationException("Id-ul nu poate fi null!");
}
return studentFileRepository.findOne(id);
}
/**
* Modifica un student
*
* @param student - noul student
* @return noul student daca s-a facut modificarea sau null daca acesta nu
* exista
*/
public Student updateStudent(Student student) {
studentValidator.validate(student);
return studentFileRepository.update(student);
}
/**
* @return toti studentii din memorie
*/
public Iterable<Student> getAllStudenti() {
return studentFileRepository.findAll();
}
/**
* Adauga o tema noua
*
* @param tema - tema pe care o adauga
* @return null daca s-a facut adaugarea sau tema daca aceasta exista deja
*/
public Tema addTema(Tema tema) {
temaValidator.validate(tema);
if (this.findTema(tema.getID()) != null) {
throw new ValidationException("Tema exista!");
}
return temaFileRepository.save(tema);
}
/**
* Sterge o tema
*
* @param nrTema - nr-ul temei
* @return tema daca aceasta a fost stearsa sau null daca tema nu exista
*/
public Tema deleteTema(String nrTema) {
if (nrTema == null || nrTema.equals("")) {
throw new ValidationException("Id-ul nu poate fi null!");
}
return temaFileRepository.delete(nrTema);
}
/**
* Cauta o tema
*
* @param id - id-ul temei
* @return tema sau null daca aceasta nu exista
*/
public Tema findTema(String id) {
if (id == null || id.equals("")) {
throw new ValidationException("Id-ul nu poate fi null!");
}
return temaFileRepository.findOne(id);
}
/**
* Modifica o tema
*
* @param tema - noua tema
* @return tema daca s-a facut modificarea sau null daca acesta nu exisra
*/
public Tema updateTema(Tema tema) {
temaValidator.validate(tema);
return temaFileRepository.update(tema);
}
/**
* @return toate temele din memorie
*/
public Iterable<Tema> getAllTeme() {
return temaFileRepository.findAll();
}
/**
* Adauga o nota
*
* @param nota - nota
* @param feedback - feedback-ul notei
* @return null daca nota a fost adaugata sau nota daca aceasta exista deja
*/
public double addNota(Nota nota, String feedback) {
notaValidator.validate(nota);
Student student = studentFileRepository.findOne(nota.getIdStudent());
Tema tema = temaFileRepository.findOne(nota.getIdTema());
int predare = calculeazaSPredare(nota.getData());
if (predare != tema.getDeadline()) {
if (predare - tema.getDeadline() == 1) {
nota.setNota(nota.getNota() - 2.5);
} else {
throw new ValidationException("Studentul nu mai poate preda aceasta tema!");
}
}
notaFileRepository.save(nota);
String filename = "fisiere/" + student.getNume() + ".txt";
try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(filename, true))) {
bufferedWriter.write("\nTema: " + tema.getID());
bufferedWriter.write("\nNota: " + nota.getNota());
bufferedWriter.write("\nPredata in saptamana: " + predare);
bufferedWriter.write("\nDeadline: " + tema.getDeadline());
bufferedWriter.write("\nFeedback: " + feedback);
bufferedWriter.newLine();
} catch (IOException exception) {
throw new ValidationException(exception.getMessage());
}
return nota.getNota();
}
/**
* Sterge o nota
*
* @param id - id-ul notei
* @return nota daca aceasta a fost stearsa sau null daca nota nu exista
*/
public Nota deleteNota(String id) {
if (id == null || id.equals("")) {
throw new ValidationException("Id-ul nu poate fi null!");
}
return notaFileRepository.delete(id);
}
/**
* Cauta o nota
*
* @param id - id-ul notei
* @return nota sau null daca aceasta nu exista
*/
public Nota findNota(String id) {
if (id == null || id.equals("")) {
throw new ValidationException("Id-ul nu poate fi null!");
}
return notaFileRepository.findOne(id);
}
/**
* @return toate notele
*/
public Iterable<Nota> getAllNote() {
return notaFileRepository.findAll();
}
/**
* Prelungeste deadline-ul unei teme
*
* @param nrTema - nr-ul temei
* @param deadline - noul deadline
*/
public void prelungireDeadline(String nrTema, int deadline) {
int diff = Curent.getCurrentWeek();
Tema tema = temaFileRepository.findOne(nrTema);
if (tema == null) {
throw new ValidationException("Tema inexistenta!");
}
if (tema.getDeadline() >= diff) {
tema.setDeadline(deadline);
temaFileRepository.writeToFile();
} else {
throw new ValidationException("Nu se mai poate prelungi deadline-ul!");
}
}
/**
* Calculeaza saptamana de predare
*
* @param predare - data predarii unei teme
* @return saptamana in care a fost predata tema
*/
private int calculeazaSPredare(LocalDate predare) {
LocalDate startDate = Curent.getStartDate();
long days = DAYS.between(startDate, predare);
double saptamanaPredare = Math.ceil((double) days / 7);
return (int) saptamanaPredare;
}
}
@@ -0,0 +1,43 @@
package validation;
import domain.Nota;
import domain.Student;
import domain.Tema;
import repository.*;
public class NotaValidator implements Validator<Nota> {
private StudentXMLRepo studentFileRepository;
private TemaXMLRepo temaFileRepository;
/**
* Class constructor
* @param studentFileRepository - repository student
* @param temaFileRepository - repository tema
*/
public NotaValidator(StudentXMLRepo studentFileRepository, TemaXMLRepo temaFileRepository) {
this.studentFileRepository = studentFileRepository;
this.temaFileRepository = temaFileRepository;
}
/**
* Valideaza o nota
* @param nota - nota pe care o valideaza
* @throws ValidationException daca nota nu e valida
*/
@Override
public void validate(Nota nota) throws ValidationException {
Student student = studentFileRepository.findOne(nota.getIdStudent());
if (student== null){
throw new ValidationException("Studentul nu exista!");
}
Tema tema = temaFileRepository.findOne(nota.getIdTema());
if(tema == null){
throw new ValidationException("Tema nu exista!");
}
double notaC = nota.getNota();
if(notaC > 10.00 || notaC < 0.00){
throw new ValidationException("Valoarea notei nu este corecta!");
}
}
}
@@ -0,0 +1,37 @@
package validation;
import domain.Student;
public class StudentValidator implements Validator<Student> {
/**
* Valideaza un student
*
* @param entity - studentul pe care il valideaza
* @throws ValidationException - daca studentul nu e valid
*/
@Override
public void validate(Student entity) throws ValidationException {
if (entity.getID() == null) {
throw new ValidationException("Id incorect!");
}
if (entity.getID().equals("")) {
throw new ValidationException("Id incorect!");
}
if (entity.getNume() == "") {
throw new ValidationException("Nume incorect!");
}
if (entity.getGrupa() < 0) {
throw new ValidationException("Grupa incorecta!");
}
if (entity.getEmail() == null) {
throw new ValidationException("Email incorect!");
}
if (entity.getNume() == null) {
throw new ValidationException("Nume incorect!");
}
if (entity.getEmail().equals("")) {
throw new ValidationException("Email incorect!");
}
}
}
@@ -0,0 +1,27 @@
package validation;
import domain.Tema;
public class TemaValidator implements Validator<Tema> {
/**
* Valideaza o tema
* @param entity - tema pe care o valideaza
* @throws ValidationException daca tema nu e valida
*/
@Override
public void validate(Tema entity) throws ValidationException {
if(entity.getID().equals("") || entity.getID() == null) {
throw new ValidationException("Numar tema invalid!");
}
if(entity.getDescriere().equals("")){
throw new ValidationException("Descriere invalida!");
}
if(entity.getDeadline() < 1 || entity.getDeadline() > 14) {
throw new ValidationException("Deadlineul trebuie sa fie intre 1-14.");
}
if(entity.getPrimire() < 1 || entity.getPrimire() > 14) {
throw new ValidationException("Saptamana primirii trebuie sa fie intre 1-14.");
}
}
}
@@ -0,0 +1,11 @@
package validation;
public class ValidationException extends RuntimeException {
/**
* Clasa pentru exceptii
* @param exception - exceptia pe care o arunca
*/
public ValidationException(String exception){
super(exception);
}
}
@@ -0,0 +1,10 @@
package validation;
public interface Validator<E> {
/**
* valideaza o entitate
* @param entity - entitatea pe care o valideaza
* @throws ValidationException daca entitatea nu e valida
*/
void validate(E entity) throws ValidationException;
}
@@ -0,0 +1,431 @@
package view;
import domain.Nota;
import domain.Student;
import domain.Tema;
import service.Service;
import validation.ValidationException;
import java.time.LocalDate;
import java.util.InputMismatchException;
import java.util.Scanner;
/**
* Interfata utilizator de tip consola
*/
public class UI {
private Service service;
/**
* Class constructor
* @param service - service-ul clasei
*/
public UI(Service service) {
this.service = service;
}
/**
* Metoda care ruleaza aplicatia
*/
public void run() {
System.out.println("Bine ati venit!");
while (true) {
try {
System.out.println("Meniu comenzi: ");
System.out.println("0.Exit");
System.out.println("1.Comenzi student");
System.out.println("2.Comenzi teme");
System.out.println("3.Comenzi note");
Scanner scanner = new Scanner(System.in);
System.out.print("Introduceti comanda: ");
int comanda = scanner.nextInt();
if (comanda == 0) {
System.out.println("La revedere!");
break;
} else if (comanda == 1) {
meniuStudent();
} else if (comanda == 2) {
meniuTeme();
} else if (comanda == 3) {
meniuNote();
} else {
System.out.println("Comanda invalida!");
}
} catch (ValidationException exception) {
System.out.println(exception.getMessage());
} catch (InputMismatchException exception) {
System.out.println("Date introduse gresit!");
} catch (ArrayIndexOutOfBoundsException exception) {
System.out.println("Eroare la introducerea datelor!");
}
}
}
/**
* Afiseaza meniul de comenzi asupra studentilor
*/
private void meniuStudent() {
while (true) {
System.out.println("\n0.Iesire meniu student");
System.out.println("1.Introducere student");
System.out.println("2.Stergere student");
System.out.println("3.Cautare student");
System.out.println("4.Modificare student");
System.out.println("5.Afisare lista studenti");
Scanner scanner = new Scanner(System.in);
System.out.print("Introduceti comanda: ");
int comanda = scanner.nextInt();
if (comanda == 0) {
break;
} else if (comanda == 1) {
adaugaStudent();
} else if (comanda == 2) {
stergeStudent();
} else if (comanda == 3) {
cautareStudent();
} else if (comanda == 4) {
updateStudent();
} else if (comanda == 5) {
afisareStudenti();
} else {
System.out.println("Comanda invalida!");
}
}
}
/**
* Adauga un student
* @throws ValidationException daca datele studentul exista deja
*/
private void adaugaStudent() throws ValidationException {
Scanner scanner = new Scanner(System.in);
System.out.print("Introduceti id student: ");
String idStudent = scanner.next();
if (service.findStudent(idStudent) != null) {
throw new ValidationException("Studentul exista!");
}
System.out.print("Introduceti numele: ");
scanner.nextLine();
String numeStudent = scanner.nextLine();
System.out.print("Introduceti grupa: ");
int grupa = scanner.nextInt();
System.out.print("Introduceti email: ");
String email = scanner.next();
Student student = new Student(idStudent, numeStudent, grupa, email);
Student student1 = service.addStudent(student);
if (student1 == null) {
System.out.println("Student adaugat cu succes!");
} else {
System.out.println("Studentul deja exista" + student1);
}
}
/**
* Sterge un student
*/
private void stergeStudent() {
Scanner scanner = new Scanner(System.in);
System.out.print("Introduceti id-ul student: pe care doriti sa il stergeti: ");
String id = scanner.next();
Student student = service.deleteStudent(id);
if (student == null) {
System.out.println("Studentul nu exista!");
} else {
System.out.println("Student sters cu succes!");
}
}
/**
* Cauta un student
*/
private void cautareStudent() {
Scanner scanner = new Scanner(System.in);
System.out.print("Introduceti id-ul studentului: ");
String id = scanner.next();
Student student = service.findStudent(id);
if (student == null) {
System.out.println("Studentul nu exista!");
} else {
System.out.println(student);
}
}
/**
* Modifica datele unui student
*/
private void updateStudent() {
Scanner scanner = new Scanner(System.in);
System.out.print("Introduceti id-ul studentului pe care doriti sa il modificati: ");
String id = scanner.next();
System.out.println("Introduceti datele noi");
System.out.print("Introduceti numele: ");
scanner.nextLine();
String nume = scanner.nextLine();
System.out.print("Introduceti grupa: ");
int grupa = scanner.nextInt();
System.out.print("Introduceti email: ");
String email = scanner.next();
Student student = new Student(id, nume, grupa, email);
Student student1 = service.updateStudent(student);
if (student1 == null) {
System.out.print("Studentul nu exista!");
} else {
System.out.println("Student modificat cu succes!" + student1);
}
}
/**
* Afiseaza lista studentilor
*/
private void afisareStudenti() {
Iterable<Student> all = service.getAllStudenti();
all.forEach(student ->
System.out.println(student)
);
}
/**
* Afiseaza comenzile pentru teme
*/
private void meniuTeme() {
while (true) {
System.out.println("\n0.Iesire meniu teme");
System.out.println("1.Introducere tema");
System.out.println("2.Prelungire deadline");
System.out.println("3.Stergere tema");
System.out.println("4.Cautare tema");
System.out.println("5.Modificare tema");
System.out.println("6.Afisare lista teme");
Scanner scanner = new Scanner(System.in);
System.out.print("Introduceti comanda: ");
int comanda = scanner.nextInt();
if (comanda == 0) {
break;
} else if (comanda == 1) {
adaugaTema();
}
else if(comanda==2) {
prelungireDeadline();
}
else if (comanda == 3) {
stergeTema();
} else if (comanda == 4) {
cautareTema();
} else if (comanda == 5) {
updateTema();
} else if (comanda == 6) {
afisareTeme();
} else {
System.out.println("Comanda invalida!");
}
}
}
/**
* Adauga o tema
* @throws ValidationException daca tema exista deja
*/
private void adaugaTema() throws ValidationException{
Scanner scanner = new Scanner(System.in);
System.out.print("Introduceti nr tema: ");
String nrTema = scanner.next();
if (service.findTema(nrTema) != null) {
throw new ValidationException("Tema exista deja!");
}
System.out.print("Introduceti descrierea: ");
scanner.nextLine();
String descriere = scanner.nextLine();
System.out.print("Introduceti deadline-ul(nr saptamanii): ");
int deadline = scanner.nextInt();
System.out.print("Introduceti saptamana primirii: ");
int primire = scanner.nextInt();
Tema tema = new Tema(nrTema, descriere, deadline, primire);
tema = service.addTema(tema);
if (tema == null) {
System.out.println("Tema adaugata cu succes!");
} else {
System.out.println("Tema deja exista" + tema);
}
}
/**
* Prelungeste deadline-ul unei teme
*/
private void prelungireDeadline(){
Scanner scanner = new Scanner(System.in);
System.out.print("Introduceti id tema: ");
String nrTema = scanner.next();
System.out.print("Introduceti deadline nou: ");
int deadline = scanner.nextInt();
service.prelungireDeadline(nrTema, deadline);
System.out.println("Dealine prelungit!");
}
/**
* Sterge o tema
*/
private void stergeTema() {
Scanner scanner = new Scanner(System.in);
System.out.print("Introduceti id-ul temei: pe care doriti sa o stergeti: ");
String id = scanner.next();
Tema tema = service.deleteTema(id);
if (tema == null) {
System.out.println("Tema nu exista!");
} else {
System.out.println("Tema stearsa cu succes!");
}
}
/**
* Cauta o tema
*/
private void cautareTema() {
Scanner scanner = new Scanner(System.in);
System.out.print("Introduceti id-ul temei: ");
String id = scanner.next();
Tema tema = service.findTema(id);
if (tema == null) {
System.out.println("Tema nu exista!");
} else {
System.out.println(tema);
}
}
/**
* Modifica o tema
*/
private void updateTema() {
Scanner scanner = new Scanner(System.in);
System.out.print("Introduceti id-ul temei pe care doriti sa o modificati: ");
String id = scanner.next();
System.out.println("Introduceti datele noi");
System.out.print("Introduceti descrierea: ");
scanner.nextLine();
String descriere = scanner.nextLine();
System.out.print("Introduceti deadline: ");
int deadline = scanner.nextInt();
System.out.print("Introduceti saptamana primire: ");
int primire = scanner.nextInt();
Tema tema = new Tema(id, descriere, deadline, primire);
Tema tema1 = service.updateTema(tema);
if (tema1 == null) {
System.out.println("Tema nu exista!");
} else {
System.out.println("Tema modificata cu succes!" + tema1);
}
}
/**
* Afiseaza toate temele
*/
private void afisareTeme(){
Iterable<Tema> all = service.getAllTeme();
//for(Tema tema: all){
// System.out.println(tema);
//}
all.forEach(tema -> System.out.println(tema));
}
/**
* Afiseaza comenzile disponibile pentru note
*/
private void meniuNote() {
while (true) {
System.out.println("\n0.Iesire meniu note");
System.out.println("1.Introducere nota");
System.out.println("2.Stergere nota");
System.out.println("3.Cautare nota");
System.out.println("4.Afisare lista note");
Scanner scanner = new Scanner(System.in);
System.out.print("Introduceti comanda: ");
int comanda = scanner.nextInt();
if (comanda == 0) {
break;
} else if (comanda == 1) {
adaugaNota();
} else if (comanda == 2) {
stergeNota();
} else if (comanda == 3) {
cautareNota();
} else if (comanda == 4) {
afisareNote();
} else {
System.out.println("Comanda invalida!");
}
}
}
/**
* Adauga o nota
* @throws ValidationException daca nota exista deja
*/
private void adaugaNota() throws ValidationException {
Scanner scanner = new Scanner(System.in);
System.out.print("Introduceti id student: ");
String idStudent = scanner.next();
System.out.print("Introduceti numarul temei: ");
String nrTema = scanner.next();
String idNota = idStudent + "#" + nrTema;
if (service.findNota(idNota) != null) {
throw new ValidationException("Nota exista deja!");
}
System.out.print("Introduceti nota: ");
Double nota = scanner.nextDouble();
System.out.print("Introduceti data predarii temei(format: an-luna-data): ");
String data = scanner.next();
String[] date = data.split("-");
LocalDate dataPredare = LocalDate.of(Integer.parseInt(date[0]), Integer.parseInt(date[1]), Integer.parseInt(date[2]));
System.out.print("Introduceti feedback: ");
scanner.nextLine();
String feedback = scanner.nextLine(); //System.out.println(feedback);
Nota notaCatalog = new Nota(idNota, idStudent, nrTema, nota, dataPredare);
double notaFinala = service.addNota(notaCatalog, feedback);
System.out.println("Nota maxima pe care o poate primi studentul este: " + notaFinala);
}
/**
* Sterge o nota
*/
private void stergeNota() {
Scanner scanner = new Scanner(System.in);
System.out.print("Introduceti id-ul studentului: ");
String idStudent = scanner.next();
System.out.print("Introduceti nr-ul temei: ");
String nrTema = scanner.next();
String idNota = idStudent + "#" + nrTema;
Nota nota = service.deleteNota(idNota);
if (nota == null) {
System.out.println("Nota nu exista!");
} else {
System.out.println("Nota stearsa cu succes!");
}
}
/**
* Cauta o nota
*/
private void cautareNota() {
Scanner scanner = new Scanner(System.in);
System.out.print("Introduceti id-ul studentului: ");
String idStudent = scanner.next();
System.out.print("Introduceti nr-ul temei: ");
String nrTema = scanner.next();
String idNota = idStudent + "#" + nrTema;
Nota nota = service.findNota(idNota);
if (nota == null) {
System.out.println("Nota nu exista!");
} else {
System.out.println(nota);
}
}
/**
* Afiseaza toate notele
*/
private void afisareNote() {
Iterable<Nota> all = service.getAllNote();
all.forEach(nota ->
System.out.println(nota)
);
}
}
@@ -0,0 +1,85 @@
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import domain.Student;
import domain.Tema;
import repository.NotaXMLRepo;
import repository.StudentXMLRepo;
import repository.TemaXMLRepo;
import service.Service;
import validation.NotaValidator;
import validation.StudentValidator;
import validation.TemaValidator;
import validation.ValidationException;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Tag("AddAssignmentTest")
class AddAssignmentTest {
StudentValidator studentValidator = new StudentValidator();
TemaValidator temaValidator = new TemaValidator();
String filenameStudent = "fisiere/Studenti.xml";
String filenameTema = "fisiere/Teme.xml";
String filenameNota = "fisiere/Note.xml";
StudentXMLRepo studentXMLRepository = new StudentXMLRepo(filenameStudent);
TemaXMLRepo temaXMLRepository = new TemaXMLRepo(filenameTema);
NotaValidator notaValidator = new NotaValidator(studentXMLRepository, temaXMLRepository);
NotaXMLRepo notaXMLRepository = new NotaXMLRepo(filenameNota);
Service service = new Service(studentXMLRepository, studentValidator, temaXMLRepository, temaValidator,
notaXMLRepository, notaValidator);
@Test
void AddAssignment_T1() {
// Arrange
Tema testAssignment = new Tema("1111", "Test Assignment", 12, 6);
// Act
service.addTema(testAssignment);
// Assert
assertTrue(service.findTema("1111") != null);
service.deleteTema("1111");
}
@Test
void AddAssignment_T2() {
// Arrange
Tema testAssignment = new Tema("", "Test Assignment", 12, 6);
// Act
var expetion = assertThrows(ValidationException.class, () -> service.addTema(testAssignment));
// Assert
assertTrue(expetion.getMessage().equals("Numar tema invalid!"));
}
@Test
void AddAssignment_T3() {
// Arrange
Tema testAssignment = new Tema("1111", "", 12, 6);
// Act
var expetion = assertThrows(ValidationException.class, () -> service.addTema(testAssignment));
// Assert
assertTrue(expetion.getMessage().equals("Descriere invalida!"));
}
@Test
void AddAssignment_T4() {
// Arrange
Tema testAssignment = new Tema("1111", "Test Assignment", 15, 6);
// Act
var expetion = assertThrows(ValidationException.class, () -> service.addTema(testAssignment));
// Assert
assertTrue(expetion.getMessage().equals("Deadlineul trebuie sa fie intre 1-14."));
}
@Test
void AddAssignment_T5() {
// Arrange
Tema testAssignment = new Tema("1111", "Test Assignment", 12, 15);
// Act
var expetion = assertThrows(ValidationException.class, () -> service.addTema(testAssignment));
// Assert
assertTrue(expetion.getMessage().equals("Saptamana primirii trebuie sa fie intre 1-14."));
}
}
@@ -0,0 +1,170 @@
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import domain.Student;
import repository.NotaXMLRepo;
import repository.StudentXMLRepo;
import repository.TemaXMLRepo;
import service.Service;
import validation.NotaValidator;
import validation.StudentValidator;
import validation.TemaValidator;
import validation.ValidationException;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Tag("AddStudentsTest")
class AddStudentsTest {
StudentValidator studentValidator = new StudentValidator();
TemaValidator temaValidator = new TemaValidator();
String filenameStudent = "fisiere/Studenti.xml";
String filenameTema = "fisiere/Teme.xml";
String filenameNota = "fisiere/Note.xml";
StudentXMLRepo studentXMLRepository = new StudentXMLRepo(filenameStudent);
TemaXMLRepo temaXMLRepository = new TemaXMLRepo(filenameTema);
NotaValidator notaValidator = new NotaValidator(studentXMLRepository, temaXMLRepository);
NotaXMLRepo notaXMLRepository = new NotaXMLRepo(filenameNota);
Service service = new Service(studentXMLRepository, studentValidator, temaXMLRepository, temaValidator,
notaXMLRepository, notaValidator);
@Test
void AddStudents_ValidId_WillSucceed() {
// Arrange
Student testStudent = new Student("1004", "Andrei", 932, "andrei@test.com");
// Act
service.addStudent(testStudent);
// Assert
assertTrue(service.findStudent("1004") != null);
service.deleteStudent("1004");
}
@Test
void AddStudents_NullId_WillFail() {
// Arrange
Student testStudent = new Student(null, "Andrei", 932, "andrei@test.com");
// Act
var expetion = assertThrows(ValidationException.class, () -> service.addStudent(testStudent));
// Assert
assertTrue(expetion.getMessage().equals("Id incorect!"));
}
@Test
void AddStudents_EmptyId_WillFail() {
// Arrange
Student testStudent = new Student("", "Andrei", 932, "andrei@test.com");
// Act
var expetion = assertThrows(ValidationException.class, () -> service.addStudent(testStudent));
// Assert
assertTrue(expetion.getMessage().equals("Id incorect!"));
}
@Test
void AddStudents_ValidName_WillSucceed() {
// Arrange
Student testStudent = new Student("1004", "Andrei", 932, "andrei@test.com");
// Act
service.addStudent(testStudent);
// Assert
assertTrue(service.findStudent("1004") != null);
service.deleteStudent("1004");
}
@Test
void AddStudents_NullName_WillFail() {
// Arrange
Student testStudent = new Student("1004", null, 932, "andrei@test.com");
// Act
var expetion = assertThrows(ValidationException.class, () -> service.addStudent(testStudent));
// Assert
assertTrue(expetion.getMessage().equals("Nume incorect!"));
}
@Test
void AddStudents_EmptyName_WillFail() {
// Arrange
Student testStudent = new Student("1004", "", 932, "andrei@test.com");
// Act
var expetion = assertThrows(ValidationException.class, () -> service.addStudent(testStudent));
// Assert
assertTrue(expetion.getMessage().equals("Nume incorect!"));
}
@Test
void AddStudents_ValidPositiveGroup_WillSucceed() {
// Arrange
Student testStudent = new Student("1004", "Andrei", 1, "andrei@test.com");
// Act
service.addStudent(testStudent);
// Assert
assertTrue(service.findStudent("1004") != null);
service.deleteStudent("1004");
}
@Test
void AddStudents_ZeroGroup_WillSucceed() {
// Arrange
Student testStudent = new Student("1004", "Andrei", 0, "andrei@test.com");
// Act
service.addStudent(testStudent);
// Assert
assertTrue(service.findStudent("1004") != null);
service.deleteStudent("1004");
}
@Test
void AddStudents_NegativeGroup_WillFail() {
// Arrange
Student testStudent = new Student("1004", "Andrei", -1, "andrei@test.com");
// Act
var expetion = assertThrows(ValidationException.class, () -> service.addStudent(testStudent));
// Assert
assertTrue(expetion.getMessage().equals("Grupa incorecta!"));
}
@Test
void AddStudents_ValidEmail_WillSucceed() {
// Arrange
Student testStudent = new Student("1004", "Andrei", 932, "andrei@test.com");
// Act
service.addStudent(testStudent);
// Assert
assertTrue(service.findStudent("1004") != null);
service.deleteStudent("1004");
}
@Test
void AddStudents_NullEmail_WillFail() {
// Arrange
Student testStudent = new Student("1004", "Andrei", 932, null);
// Act
var expetion = assertThrows(ValidationException.class, () -> service.addStudent(testStudent));
// Assert
assertTrue(expetion.getMessage().equals("Email incorect!"));
}
@Test
void AddStudents_EmptyEmail_WillFail() {
// Arrange
Student testStudent = new Student("1004", "Andrei", 932, "");
// Act
var expetion = assertThrows(ValidationException.class, () -> service.addStudent(testStudent));
// Assert
assertTrue(expetion.getMessage().equals("Email incorect!"));
}
@Test
void AddStudents_DuplicateId_WillFail() {
// Arrange
Student testStudent = new Student("1004", "Andrei", 932, "andrei@test.com");
// Act
service.addStudent(testStudent);
var expetion = assertThrows(ValidationException.class, () -> service.addStudent(testStudent));
// Assert
assertTrue(expetion.getMessage().equals("Studentul exista!"));
service.deleteStudent("1004");
}
}
@@ -0,0 +1,14 @@
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Tag("ExamplePack")
class ExampleTest {
@Test
void exampleTestCase() {
System.out.println("Running an example test...");
assertTrue(true, "Example assertion passed");
}
}
@@ -0,0 +1,95 @@
import domain.Nota;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import domain.Student;
import domain.Tema;
import repository.NotaXMLRepo;
import repository.StudentXMLRepo;
import repository.TemaXMLRepo;
import service.Service;
import validation.NotaValidator;
import validation.StudentValidator;
import validation.TemaValidator;
import validation.ValidationException;
import static org.mockito.Mockito.*;
import java.time.LocalDate;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Tag("IncrementalIntegrationTest")
class IncrementalIntegrationTest {
StudentValidator studentValidator = new StudentValidator();
TemaValidator temaValidator = new TemaValidator();
String filenameStudent = "fisiere/Studenti.xml";
String filenameTema = "fisiere/Teme.xml";
String filenameNota = "fisiere/Note.xml";
StudentXMLRepo studentXMLRepository = mock(StudentXMLRepo.class);
TemaXMLRepo temaXMLRepository = mock(TemaXMLRepo.class);
NotaValidator notaValidator = new NotaValidator(studentXMLRepository, temaXMLRepository);
NotaXMLRepo notaXMLRepository = new NotaXMLRepo(filenameNota);
Service service = new Service(studentXMLRepository, studentValidator, temaXMLRepository, temaValidator,
notaXMLRepository, notaValidator);
@Test
void AddStudent() {
// Arrange
Student testStudent = new Student("1004", "Andrei", 932, "andrei@test.com");
when(studentXMLRepository.findOne("1004")).thenReturn(null).thenReturn(testStudent);
// Act
service.addStudent(testStudent);
// Assert
assertTrue(service.findStudent("1004") != null);
verify(studentXMLRepository).save(testStudent);
service.deleteStudent("1004");
}
@Test
void AddStudentAndAssignment() {
// Arrange
Student testStudent = new Student("1004", "Andrei", 932, "andrei@test.com");
Tema testAssignment = new Tema("1111", "Test Assignment", 12, 6);
when(studentXMLRepository.findOne("1004")).thenReturn(null).thenReturn(testStudent);
when(temaXMLRepository.findOne("1111")).thenReturn(null).thenReturn(testAssignment);
// Act
service.addTema(testAssignment);
service.addStudent(testStudent);
// Assert
assertTrue(service.findStudent("1004") != null);
assertTrue(service.findTema("1111") != null);
verify(studentXMLRepository).save(testStudent);
verify(temaXMLRepository).save(testAssignment);
service.deleteTema("1111");
service.deleteStudent("1004");
}
@Test
void IntegrationTest() {
service.deleteNota("1234");
service.deleteTema("1111");
service.deleteStudent("1004");
Student testStudent = new Student("1004", "Andrei", 932, "andrei@test.com");
when(studentXMLRepository.findOne("1004")).thenReturn(null).thenReturn(testStudent);
service.addStudent(testStudent);
verify(studentXMLRepository).save(testStudent);
Tema testAssignment = new Tema("1111", "Test Assignment", 1, 6);
when(temaXMLRepository.findOne("1111")).thenReturn(null).thenReturn(testAssignment);
service.addTema(testAssignment);
verify(temaXMLRepository).save(testAssignment);
Nota testNota = new Nota("1234", "1004", "1111", 9.5, LocalDate.of(2018, 10, 2));
service.addNota(testNota, "Amazing work");
assertTrue(service.findNota("1234") != null);
service.deleteNota("1234");
service.deleteTema("1111");
service.deleteStudent("1004");
}
}
@@ -0,0 +1,90 @@
import domain.Nota;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import domain.Student;
import domain.Tema;
import repository.NotaXMLRepo;
import repository.StudentXMLRepo;
import repository.TemaXMLRepo;
import service.Service;
import validation.NotaValidator;
import validation.StudentValidator;
import validation.TemaValidator;
import validation.ValidationException;
import java.time.LocalDate;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
@Tag("IntegrationTest")
class IntegrationTest {
StudentValidator studentValidator = new StudentValidator();
TemaValidator temaValidator = new TemaValidator();
String filenameStudent = "fisiere/Studenti.xml";
String filenameTema = "fisiere/Teme.xml";
String filenameNota = "fisiere/Note.xml";
StudentXMLRepo studentXMLRepository = new StudentXMLRepo(filenameStudent);
TemaXMLRepo temaXMLRepository = new TemaXMLRepo(filenameTema);
NotaValidator notaValidator = new NotaValidator(studentXMLRepository, temaXMLRepository);
NotaXMLRepo notaXMLRepository = new NotaXMLRepo(filenameNota);
Service service = new Service(studentXMLRepository, studentValidator, temaXMLRepository, temaValidator,
notaXMLRepository, notaValidator);
@Test
void AddStudent() {
// Arrange
Student testStudent = new Student("1004", "Andrei", 932, "andrei@test.com");
// Act
service.addStudent(testStudent);
// Assert
assertTrue(service.findStudent("1004") != null);
service.deleteStudent("1004");
}
@Test
void AddAssignment() {
// Arrange
Tema testAssignment = new Tema("1111", "Test Assignment", 12, 6);
// Act
service.addTema(testAssignment);
// Assert
assertTrue(service.findTema("1111") != null);
service.deleteTema("1111");
}
@Test
void AddGrade() {
Nota testNota = new Nota("1234", "1", "1", 9.5, LocalDate.of(2018, 10, 9));
service.addNota(testNota, "Amazing work");
assertTrue(service.findNota("1234") != null);
service.deleteNota("1234");
}
@Test
void IntegrationTest() {
service.deleteNota("1234");
service.deleteTema("1111");
service.deleteStudent("1004");
Student testStudent = new Student("1004", "Andrei", 932, "andrei@test.com");
service.addStudent(testStudent);
Tema testAssignment = new Tema("1111", "Test Assignment", 1, 6);
service.addTema(testAssignment);
Nota testNota = new Nota("1234", "1004", "1111", 9.5, LocalDate.of(2018, 10, 2));
service.addNota(testNota, "Amazing work");
assertTrue(service.findNota("1234") != null);
service.deleteNota("1234");
service.deleteTema("1111");
service.deleteStudent("1004");
}
}