Commit 65f1ab68 authored by Maxym Borodenko's avatar Maxym Borodenko Committed by Matija Obreza

Hibernate 5 and Spring Data JPA 2

parent 861da144
Pipeline #13630 failed with stage
in 18 seconds
......@@ -20,14 +20,13 @@
<parent>
<groupId>org.genesys-pgr</groupId>
<artifactId>file-repository</artifactId>
<version>2.0-SNAPSHOT</version>
<version>1.2-SNAPSHOT</version>
</parent>
<artifactId>file-repository-core</artifactId>
<name>Genesys File Repository</name>
<description>Simple DublinCore file repository</description>
<properties>
<commons.io.version>2.4</commons.io.version>
<tika.version>1.14</tika.version>
</properties>
......@@ -125,6 +124,13 @@
<version>${spring.security.version}</version>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>${org.hamcrest.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
......@@ -162,7 +168,7 @@
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-elasticsearch</artifactId>
<version>2.1.15.RELEASE</version>
<version>3.2.5.RELEASE</version>
<scope>provided</scope>
<exclusions>
<exclusion>
......@@ -175,7 +181,7 @@
<!-- Hibernate dependencies -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
......@@ -204,7 +210,7 @@
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>application-blocks-security</artifactId>
<version>2.0-SNAPSHOT</version>
<version>${application.blocks.version}</version>
</dependency>
<dependency>
<groupId>org.apache.tika</groupId>
......@@ -219,7 +225,12 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.8</version>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
......
......@@ -72,7 +72,7 @@ public class RepositoryFile extends AuditedVersionedModelWithoutId implements Ac
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -4816923593950502695L;
public static final Sort DEFAULT_SORT = new Sort("originalFilename");
public static final Sort DEFAULT_SORT = Sort.by("originalFilename");
/** The id. */
@Id
......
......@@ -61,7 +61,7 @@ public class RepositoryFolder extends UuidModel implements AclAwareModel {
/** The Constant serialVersionUID. */
private static final long serialVersionUID = -7947000802758739238L;
public static final Sort DEFAULT_SORT = new Sort("name");
public static final Sort DEFAULT_SORT = Sort.by("name");
/**
* Reference to parent Folder. Root folders have this set to null. This
......
......@@ -19,14 +19,14 @@ package org.genesys.filerepository.persistence;
import org.genesys.filerepository.model.ImageGallery;
import org.genesys.filerepository.model.RepositoryFolder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.stereotype.Repository;
/**
* The Interface ImageGalleryPersistence.
*/
@Repository
public interface ImageGalleryPersistence extends JpaRepository<ImageGallery, Long>, QueryDslPredicateExecutor<ImageGallery> {
public interface ImageGalleryPersistence extends JpaRepository<ImageGallery, Long>, QuerydslPredicateExecutor<ImageGallery> {
/**
* Find gallery for specified path.
......
......@@ -23,7 +23,7 @@ import org.genesys.filerepository.RepositoryPersistence;
import org.genesys.filerepository.model.RepositoryFile;
import org.genesys.filerepository.model.RepositoryFolder;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.stereotype.Repository;
/**
......@@ -34,7 +34,7 @@ import org.springframework.stereotype.Repository;
*
*/
@Repository
public interface RepositoryFilePersistence extends RepositoryPersistence<RepositoryFile>, QueryDslPredicateExecutor<RepositoryFile> {
public interface RepositoryFilePersistence extends RepositoryPersistence<RepositoryFile>, QuerydslPredicateExecutor<RepositoryFile> {
/**
* Find by uuid.
......
......@@ -22,14 +22,14 @@ import java.util.UUID;
import org.genesys.filerepository.RepositoryPersistence;
import org.genesys.filerepository.model.RepositoryFolder;
import org.springframework.data.domain.Pageable;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.stereotype.Repository;
/**
* JPA Repository for {@link RepositoryFolder}
*/
@Repository
public interface RepositoryFolderRepository extends RepositoryPersistence<RepositoryFolder>, QueryDslPredicateExecutor<RepositoryFolder> {
public interface RepositoryFolderRepository extends RepositoryPersistence<RepositoryFolder>, QuerydslPredicateExecutor<RepositoryFolder> {
/**
* Find by uuid.
......
......@@ -23,14 +23,14 @@ import org.genesys.filerepository.RepositoryPersistence;
import org.genesys.filerepository.model.RepositoryFolder;
import org.genesys.filerepository.model.RepositoryImage;
import org.springframework.data.domain.Sort;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.stereotype.Repository;
/**
* The Interface RepositoryImagePersistence.
*/
@Repository
public interface RepositoryImagePersistence extends RepositoryPersistence<RepositoryImage>, QueryDslPredicateExecutor<RepositoryImage> {
public interface RepositoryImagePersistence extends RepositoryPersistence<RepositoryImage>, QuerydslPredicateExecutor<RepositoryImage> {
/**
* Find by uuid.
......
......@@ -56,6 +56,8 @@ import org.springframework.util.CollectionUtils;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;
import javax.persistence.EntityNotFoundException;
/**
* Image Gallery service.
*/
......@@ -235,7 +237,7 @@ public class ImageGalleryServiceImpl implements ImageGalleryService {
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#imageGallery, 'write')")
public ImageGallery updateImageGalery(final ImageGallery imageGallery, final String title, final String description) {
final ImageGallery imageGallery2 = imageGalleryPersistence.findOne(imageGallery.getId());
final ImageGallery imageGallery2 = imageGalleryPersistence.findById(imageGallery.getId()).orElseThrow(() -> new EntityNotFoundException("Record not found."));
imageGallery2.setTitle(title);
imageGallery2.setDescription(description);
......@@ -254,7 +256,7 @@ public class ImageGalleryServiceImpl implements ImageGalleryService {
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#imageGallery, 'write')")
public ImageGallery saveImageOrder(final ImageGallery imageGallery) {
final ImageGallery imageGallery2 = imageGalleryPersistence.findOne(imageGallery.getId());
final ImageGallery imageGallery2 = imageGalleryPersistence.findById(imageGallery.getId()).orElseThrow(() -> new EntityNotFoundException("Record not found."));
imageGallery2.setImages(imageGallery.getImages());
imageGalleryPersistence.save(imageGallery2);
......@@ -266,7 +268,7 @@ public class ImageGalleryServiceImpl implements ImageGalleryService {
@Override
public void ensureThumbnails(final ImageGallery imageGallery) {
final ImageGallery imageGallery2 = imageGalleryPersistence.findOne(imageGallery.getId());
final ImageGallery imageGallery2 = imageGalleryPersistence.findById(imageGallery.getId()).orElseThrow(() -> new EntityNotFoundException("Record not found."));
if (CollectionUtils.isEmpty(imageGallery2.getImages())) {
LOG.debug("ImageGallery has no images, skipping thumbnail generation for path=" + imageGallery2.getPath());
......@@ -325,7 +327,7 @@ public class ImageGalleryServiceImpl implements ImageGalleryService {
@Override
public void ensureThumbnails(final ImageGallery imageGallery, final Integer width, final Integer height) {
final ImageGallery imageGallery2 = imageGalleryPersistence.findOne(imageGallery.getId());
final ImageGallery imageGallery2 = imageGalleryPersistence.findById(imageGallery.getId()).orElseThrow(() -> new EntityNotFoundException("Record not found."));
if (CollectionUtils.isEmpty(imageGallery2.getImages())) {
LOG.debug("ImageGallery has no images, skipping thumbnail generation for path=" + imageGallery2.getPath());
......
......@@ -33,7 +33,7 @@ import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.DriverManagerDataSource;
import org.springframework.orm.hibernate4.HibernateExceptionTranslator;
import org.springframework.orm.hibernate5.HibernateExceptionTranslator;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
......
......@@ -35,13 +35,11 @@ import org.genesys.filerepository.service.impl.S3StorageServiceImpl;
import org.genesys.filerepository.service.impl.ThumbnailGenerator1;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
// TODO: Auto-generated Javadoc
/**
......@@ -74,13 +72,13 @@ public class ServiceBeanConfig implements InitializingBean, DisposableBean {
* @return the property placeholder configurer
*/
@Bean
public static PropertyPlaceholderConfigurer propertyPlaceholderConfigurer() {
final PropertyPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertyPlaceholderConfigurer();
public static PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer() {
final PropertySourcesPlaceholderConfigurer propertyPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
// Need to ignore "genesys.properties" if not found
propertyPlaceholderConfigurer.setIgnoreResourceNotFound(true);
propertyPlaceholderConfigurer.setFileEncoding("utf-8");
propertyPlaceholderConfigurer.setLocations(new Resource[] { new ClassPathResource("spring/spring.properties") });
propertyPlaceholderConfigurer.setLocations(new ClassPathResource("spring/spring.properties"));
return propertyPlaceholderConfigurer;
}
......
......@@ -16,8 +16,9 @@
package org.genesys.filerepository.service;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.junit.Assert.fail;
import java.io.IOException;
import java.nio.file.Path;
......
......@@ -16,8 +16,8 @@
package org.genesys.filerepository.service;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import java.io.IOException;
import java.nio.file.Path;
......
......@@ -20,7 +20,7 @@ import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.CoreMatchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.IOException;
import java.io.InputStream;
......
......@@ -17,7 +17,7 @@
package org.genesys.filerepository.service;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.IOException;
import java.nio.file.Path;
......
......@@ -17,7 +17,7 @@
package org.genesys.filerepository.service;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.File;
import java.io.FileNotFoundException;
......
......@@ -17,7 +17,7 @@
package org.genesys.filerepository.service;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.IOException;
import java.nio.file.Path;
......@@ -26,6 +26,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import javax.persistence.EntityNotFoundException;
import javax.transaction.Transactional;
import org.genesys.filerepository.InvalidRepositoryFileDataException;
......@@ -150,7 +151,7 @@ public class ImageGalleryTest extends RepositoryServiceTest {
/**
* Update gallery blah null.
*/
@Test(expected = NullPointerException.class)
@Test(expected = EntityNotFoundException.class)
public void updateGalleryBlahNull() {
imageGalleryService.updateImageGalery(new ImageGallery(), null, null);
}
......@@ -409,19 +410,19 @@ public class ImageGalleryTest extends RepositoryServiceTest {
imageGalleryService.createImageGallery(initialPath.resolve("gallery2"), DEFAULT_GALLERY_TITLE, DEFAULT_GALLERY_DESCRIPTION);
imageGalleryService.createImageGallery(initialPath.resolve("sub/gallery3"), DEFAULT_GALLERY_TITLE, DEFAULT_GALLERY_DESCRIPTION);
Page<ImageGallery> page = imageGalleryService.listImageGalleries(new PageRequest(0, 3));
Page<ImageGallery> page = imageGalleryService.listImageGalleries(PageRequest.of(0, 3));
assertThat(page.getContent().size(), is(3));
assertThat(page.getTotalElements(), is(3l));
page = imageGalleryService.listImageGalleries(new PageRequest(0, 2));
page = imageGalleryService.listImageGalleries(PageRequest.of(0, 2));
assertThat(page.getContent().size(), is(2));
assertThat(page.getTotalElements(), is(3l));
page = imageGalleryService.listImageGalleries(initialPath, new PageRequest(0, 3));
page = imageGalleryService.listImageGalleries(initialPath, PageRequest.of(0, 3));
assertThat(page.getContent().size(), is(3));
assertThat(page.getTotalElements(), is(3l));
page = imageGalleryService.listImageGalleries(initialPath.resolve("sub"), new PageRequest(0, 3));
page = imageGalleryService.listImageGalleries(initialPath.resolve("sub"), PageRequest.of(0, 3));
assertThat(page.getContent().size(), is(1));
assertThat(page.getTotalElements(), is(1l));
}
......
......@@ -16,8 +16,8 @@
package org.genesys.filerepository.service;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
......
......@@ -17,7 +17,7 @@
package org.genesys.filerepository.service;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.IOException;
import java.nio.file.Path;
......
......@@ -17,7 +17,7 @@
package org.genesys.filerepository.service;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import java.nio.file.Path;
import java.nio.file.Paths;
......
......@@ -17,7 +17,7 @@
package org.genesys.filerepository.service;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.IOException;
import java.nio.file.Path;
......
package org.genesys.filerepository.service;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import java.nio.file.Path;
import java.nio.file.Paths;
......
......@@ -17,7 +17,7 @@
package org.genesys.filerepository.service;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import java.nio.charset.Charset;
import java.security.InvalidKeyException;
......
......@@ -17,7 +17,8 @@
package org.genesys.filerepository.service;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertArrayEquals;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
......
......@@ -20,7 +20,7 @@
<parent>
<groupId>org.genesys-pgr</groupId>
<artifactId>file-repository</artifactId>
<version>2.0-SNAPSHOT</version>
<version>1.2-SNAPSHOT</version>
</parent>
<artifactId>file-repository-ftpserver</artifactId>
<name>FTP/S for Genesys File Repository</name>
......@@ -79,24 +79,30 @@
<classifier>ftp</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>${org.hamcrest.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>application-blocks-security</artifactId>
<version>2.0-SNAPSHOT</version>
<version>${application.blocks.version}</version>
</dependency>
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>file-repository-core</artifactId>
<version>2.0-SNAPSHOT</version>
<version>1.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>file-repository-core</artifactId>
<type>test-jar</type>
<version>2.0-SNAPSHOT</version>
<version>1.2-SNAPSHOT</version>
<scope>test</scope>
</dependency>
......
......@@ -16,7 +16,7 @@
package org.genesys.filerepository.service.ftp;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
......
......@@ -66,19 +66,20 @@
<jdk.source>1.8</jdk.source>
<show.deprecations>false</show.deprecations>
<application.blocks.version>1.4-SNAPSHOT</application.blocks.version>
<application.blocks.version>2.0-SNAPSHOT</application.blocks.version>
<maven-gpg-plugin.version>1.6</maven-gpg-plugin.version>
<junit.version>4.12</junit.version>
<org.hamcrest.version>1.3</org.hamcrest.version>
<commons.io.version>2.4</commons.io.version>
<spring.version>4.3.2.RELEASE</spring.version>
<spring.security.version>4.1.3.RELEASE</spring.security.version>
<spring.data.version>1.10.4.RELEASE</spring.data.version>
<querydsl.version>4.1.4</querydsl.version>
<hibernate.version>4.3.11.Final</hibernate.version>
<hsqldb.version>2.3.3</hsqldb.version>
<junit.version>4.13</junit.version>
<org.hamcrest.version>2.2</org.hamcrest.version>
<commons.io.version>2.6</commons.io.version>
<spring.version>5.2.4.RELEASE</spring.version>
<spring.security.version>5.2.2.RELEASE</spring.security.version>
<spring.data.version>2.2.5.RELEASE</spring.data.version>
<querydsl.version>4.2.1</querydsl.version>
<hibernate.version>5.4.12.Final</hibernate.version>
<hsqldb.version>2.5.0</hsqldb.version>
<jackson.version>2.10.3</jackson.version>
</properties>
<repositories>
......@@ -120,12 +121,6 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>${org.hamcrest.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
......
Markdown is supported
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