LabWork3 is done with extra task.
This commit is contained in:
parent
8946fad520
commit
67a097458c
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,2 +1,2 @@
|
||||
#Thu Feb 10 13:21:42 GMT+04:00 2022
|
||||
#Tue Mar 21 10:03:06 GMT+04:00 2023
|
||||
gradle.version=7.3.3
|
||||
|
Binary file not shown.
Binary file not shown.
3
.idea/.gitignore
generated
vendored
3
.idea/.gitignore
generated
vendored
@ -1,3 +0,0 @@
|
||||
# Default ignored files
|
||||
/shelf/
|
||||
/workspace.xml
|
1
.idea/.name
generated
Normal file
1
.idea/.name
generated
Normal file
@ -0,0 +1 @@
|
||||
sbapp
|
2
.idea/compiler.xml
generated
2
.idea/compiler.xml
generated
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="17" />
|
||||
<bytecodeTargetLevel target="11" />
|
||||
</component>
|
||||
</project>
|
5
.idea/misc.xml
generated
5
.idea/misc.xml
generated
@ -1,8 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" default="true" project-jdk-name="17" project-jdk-type="JavaSDK" />
|
||||
<component name="ProjectType">
|
||||
<option name="id" value="jpab" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="17" project-jdk-type="JavaSDK" />
|
||||
</project>
|
2
.idea/vcs.xml
generated
2
.idea/vcs.xml
generated
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
BIN
data.mv.db
BIN
data.mv.db
Binary file not shown.
@ -19,7 +19,7 @@ public class Customer
|
||||
@Column()
|
||||
private String middle_name;
|
||||
|
||||
@ManyToMany
|
||||
@OneToMany(fetch = FetchType.EAGER)
|
||||
private List<Movie> movies;
|
||||
|
||||
|
||||
@ -49,9 +49,10 @@ public class Customer
|
||||
return first_name;
|
||||
}
|
||||
|
||||
public void setFirst_name(String first_name)
|
||||
public void setFirst_name(String fullName)
|
||||
{
|
||||
this.first_name = first_name;
|
||||
String[] partsName = fullName.split(" ");
|
||||
this.first_name = partsName[0];
|
||||
}
|
||||
|
||||
public String getLast_name()
|
||||
@ -59,9 +60,10 @@ public class Customer
|
||||
return last_name;
|
||||
}
|
||||
|
||||
public void setLast_name(String last_name)
|
||||
public void setLast_name(String fullName)
|
||||
{
|
||||
this.last_name = last_name;
|
||||
String[] partsName = fullName.split(" ");
|
||||
this.last_name = partsName[1];
|
||||
}
|
||||
|
||||
public String getMiddle_name()
|
||||
@ -70,11 +72,12 @@ public class Customer
|
||||
return middle_name.isBlank() ? null : middle_name;
|
||||
}
|
||||
|
||||
public void setMiddle_name(String middle_name)
|
||||
public void setMiddle_name(String fullName)
|
||||
{
|
||||
if(!middle_name.isBlank())
|
||||
String[] partsName = fullName.split(" ");
|
||||
if(partsName.length == 3)
|
||||
{
|
||||
this.middle_name = middle_name;
|
||||
this.middle_name = partsName[2];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,8 +21,6 @@ public class Movie
|
||||
@JoinColumn(name = "genre_fk")
|
||||
private Genre genre;
|
||||
|
||||
@ManyToMany(mappedBy = "movies")
|
||||
private List<Customer> customers;
|
||||
|
||||
public Movie()
|
||||
{
|
||||
@ -34,7 +32,6 @@ public class Movie
|
||||
this.length = length;
|
||||
this.score = score;
|
||||
this.genre = genre;
|
||||
this.customers = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Long getId()
|
||||
@ -82,10 +79,6 @@ public class Movie
|
||||
this.genre = genre;
|
||||
}
|
||||
|
||||
public List<Customer> getCustomers()
|
||||
{
|
||||
return customers;
|
||||
}
|
||||
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
@ -46,16 +46,16 @@ public class CustomerService
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public Customer updateCustomer(Long id, String firstName, String lastName, String middleName)
|
||||
public Customer updateCustomer(Long id, String fullName)
|
||||
{
|
||||
if(!StringUtils.hasText(firstName) || !StringUtils.hasText(lastName))
|
||||
if(!StringUtils.hasText(fullName))
|
||||
{
|
||||
throw new IllegalArgumentException("Customer's name or surname is missing");
|
||||
}
|
||||
final Customer specificCustomer = findCustomer(id);
|
||||
specificCustomer.setFirst_name(firstName);
|
||||
specificCustomer.setLast_name(lastName);
|
||||
specificCustomer.setMiddle_name(middleName);
|
||||
specificCustomer.setFirst_name(fullName);
|
||||
specificCustomer.setLast_name(fullName);
|
||||
specificCustomer.setMiddle_name(fullName);
|
||||
return em.merge(specificCustomer);
|
||||
}
|
||||
|
||||
|
@ -48,7 +48,7 @@ public class GenreService
|
||||
@Transactional
|
||||
public Genre updateGenre(Long id, String name)
|
||||
{
|
||||
if(StringUtils.hasText(name))
|
||||
if(!StringUtils.hasText(name))
|
||||
{
|
||||
throw new IllegalArgumentException("Genre's name is missing");
|
||||
}
|
||||
|
@ -11,8 +11,6 @@ import javax.persistence.EntityManager;
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
public class MovieService
|
||||
@ -77,6 +75,12 @@ public class MovieService
|
||||
return specificMovie;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public List<Movie> findAllSpecificMovies(Genre specGenre)
|
||||
{
|
||||
return em.createQuery("SELECT m FROM Movie m WHERE m.genre = :genre",Movie.class).setParameter("genre",specGenre).getResultList();
|
||||
}
|
||||
|
||||
@Transactional
|
||||
public void deleteAllMovies()
|
||||
{
|
||||
|
@ -67,4 +67,27 @@ public class JpaCustomerTests
|
||||
log.info(customers.toString());
|
||||
Assertions.assertEquals(customers.size(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomerChanges()
|
||||
{
|
||||
customerService.deleteAllCustomers();
|
||||
final Customer customer = customerService.addCustomer("Nikita Lisov");
|
||||
log.info(customer.toString());
|
||||
final Customer changedCustomer = customerService.updateCustomer(customer.getId(),"Evelina Potter");
|
||||
log.info(changedCustomer.toString());
|
||||
Assertions.assertEquals("Evelina",changedCustomer.getFirst_name());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeleteSpecificCustomer()
|
||||
{
|
||||
customerService.deleteAllCustomers();
|
||||
|
||||
final Customer customer1 = customerService.addCustomer("Nikita Lisov");
|
||||
final Customer customer2 = customerService.addCustomer("Evelina Potter");
|
||||
customerService.deleteCustomer(customer1.getId());
|
||||
Assertions.assertThrows(EntityNotFoundException.class, () -> customerService.findCustomer(customer1.getId()));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import ru.ulstu.is.sbapp.Models.Customer;
|
||||
import ru.ulstu.is.sbapp.Models.Genre;
|
||||
import ru.ulstu.is.sbapp.Services.GenreService;
|
||||
|
||||
@ -66,4 +67,27 @@ public class JpaGenreTests
|
||||
log.info(customers.toString());
|
||||
Assertions.assertEquals(customers.size(), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenreChanges()
|
||||
{
|
||||
genreService.deleteAllGenres();
|
||||
final Genre genre = genreService.addGenre("Fantasy");
|
||||
log.info(genre.toString());
|
||||
final Genre changedGenre = genreService.updateGenre(genre.getId(),"Sci-Fi");
|
||||
log.info(changedGenre.toString());
|
||||
Assertions.assertEquals("Sci-Fi",changedGenre.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDeleteSpecificGenre()
|
||||
{
|
||||
genreService.deleteAllGenres();
|
||||
|
||||
final Genre genre1 = genreService.addGenre("Nikita Lisov");
|
||||
final Genre genre2 = genreService.addGenre("Evelina Potter");
|
||||
genreService.deleteGenre(genre1.getId());
|
||||
Assertions.assertThrows(EntityNotFoundException.class, () -> genreService.findGenre(genre1.getId()));
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ import ru.ulstu.is.sbapp.Models.Genre;
|
||||
import ru.ulstu.is.sbapp.Services.GenreService;
|
||||
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SpringBootTest
|
||||
@ -45,6 +46,7 @@ public class JpaMovieTests
|
||||
log.info(movie.toString());
|
||||
|
||||
Assertions.assertNotNull(movie.getId());
|
||||
Assertions.assertTrue(customer.getMovies().contains(movie));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -164,4 +166,39 @@ public class JpaMovieTests
|
||||
Assertions.assertEquals(movies.size(),0);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGetAllGenreMovies()
|
||||
{
|
||||
movieService.deleteAllMovies();
|
||||
customerService.deleteAllCustomers();
|
||||
genreService.deleteAllGenres();
|
||||
|
||||
final Genre genre1 = genreService.addGenre("Fantasy");
|
||||
log.info(genre1.toString());
|
||||
|
||||
final Genre genre2 = genreService.addGenre("Sci-Fi");
|
||||
log.info(genre2.toString());
|
||||
|
||||
final Customer customer = customerService.addCustomer("Nikita Lisov");
|
||||
log.info(customer.toString());
|
||||
|
||||
final Movie movie1 = movieService.addMovie("Arcane",36,4.5, genre1, customer);
|
||||
log.info(movie1.toString());
|
||||
|
||||
final Movie movie2 = movieService.addMovie("Harry Potter",128,10.0, genre1, customer);
|
||||
log.info(movie2.toString());
|
||||
|
||||
final Movie movie3 = movieService.addMovie("Interstellar",2,9.5, genre2, customer);
|
||||
log.info(movie3.toString());
|
||||
|
||||
List<Movie> movies = new ArrayList<>(){};
|
||||
movies.add(movie1);
|
||||
movies.add(movie2);
|
||||
|
||||
List<Movie> expectedMovies = movieService.findAllSpecificMovies(genre1);
|
||||
log.info(expectedMovies.toString());
|
||||
|
||||
Assertions.assertArrayEquals(movies.toArray(),expectedMovies.toArray());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user