Commit 8c24e32f authored by Matija Obreza's avatar Matija Obreza

Merge branch '31-hibernate-5' into 'master'

Resolve "Hibernate 5"

Closes #31

See merge request genesys-pgr/application-blocks!44
parents 87ca0951 e30abcca
......@@ -19,7 +19,7 @@
<parent>
<groupId>org.genesys-pgr</groupId>
<artifactId>application-blocks-parent</artifactId>
<version>1.6-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<artifactId>application-blocks-auditlog</artifactId>
......@@ -79,13 +79,13 @@
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>application-blocks-security</artifactId>
<version>1.6-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>application-blocks-core</artifactId>
<version>1.6-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
......@@ -112,7 +112,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
<scope>provided</scope>
</dependency>
......
......@@ -53,6 +53,7 @@ import org.hibernate.CallbackException;
import org.hibernate.EmptyInterceptor;
import org.hibernate.Transaction;
import org.hibernate.collection.spi.PersistentCollection;
import org.hibernate.resource.transaction.spi.TransactionStatus;
import org.hibernate.type.Type;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -746,7 +747,7 @@ public class AuditTrailInterceptor extends EmptyInterceptor implements Initializ
currentAuditLogs.stream().forEach(auditLog -> {
LOG.debug("Audit log to save: {}", auditLog);
});
if (tx.wasRolledBack()) {
if (tx.getStatus().equals(TransactionStatus.ROLLED_BACK)) {
LOG.warn("Transaction was rolled back. Audit logs likely won't be persisted");
}
this.auditTrailService.addAuditLogs(currentAuditLogs);
......@@ -773,9 +774,9 @@ public class AuditTrailInterceptor extends EmptyInterceptor implements Initializ
final long level = auditLogStack.get().size();
LOG.trace("afterTransactionCompletion transaction level={}", level);
if (tx.wasCommitted()) {
if (tx.getStatus().equals(TransactionStatus.COMMITTED)) {
LOG.trace("Transaction was committed, level={}", level);
} else if (tx.wasRolledBack()) {
} else if (tx.getStatus().equals(TransactionStatus.ROLLED_BACK)) {
LOG.trace("Transaction was rolled back, level={}", level);
}
......
......@@ -22,7 +22,7 @@ import org.genesys.blocks.auditlog.model.AuditLog;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.stereotype.Repository;
/**
......@@ -31,7 +31,7 @@ import org.springframework.stereotype.Repository;
* @author Matija Obreza
*/
@Repository
public interface AuditLogRepository extends AuditLogCustomRepository, JpaRepository<AuditLog, Long>, QueryDslPredicateExecutor<AuditLog> {
public interface AuditLogRepository extends AuditLogCustomRepository, JpaRepository<AuditLog, Long>, QuerydslPredicateExecutor<AuditLog> {
/**
* List audit log entries in descending order (most recent first).
......
......@@ -69,7 +69,7 @@ public class AuditLogRepositoryCustomImpl implements AuditLogCustomRepository {
*/
@Override
public AuditLog getLastAuditLog(final EntityId entity) {
final List<AuditLog> l = repository.listAuditLogs(entity.getClass().getName(), entity.getId(), new PageRequest(0, 1));
final List<AuditLog> l = repository.listAuditLogs(entity.getClass().getName(), entity.getId(), PageRequest.of(0, 1));
return (l == null) || l.isEmpty() ? null : l.get(0);
}
......@@ -80,7 +80,7 @@ public class AuditLogRepositoryCustomImpl implements AuditLogCustomRepository {
*/
@Override
public AuditLog getLastAuditLog(final EntityId entity, final String propertyName) {
final List<AuditLog> l = repository.listAuditLogs(entity.getClass().getName(), entity.getId(), propertyName, new PageRequest(0, 1));
final List<AuditLog> l = repository.listAuditLogs(entity.getClass().getName(), entity.getId(), propertyName, PageRequest.of(0, 1));
return (l == null) || l.isEmpty() ? null : l.get(0);
}
......
......@@ -72,7 +72,7 @@ public class AuditTrailServiceImpl implements AuditTrailService {
@Override
@Transactional(isolation = Isolation.READ_UNCOMMITTED, propagation = Propagation.REQUIRED)
public List<AuditLog> addAuditLogs(final Set<TransactionAuditLog> auditLogs) {
return auditLogRepository.save(auditLogs.stream().map(tlog -> toAuditLog(tlog)).collect(Collectors.toList()));
return auditLogRepository.saveAll(auditLogs.stream().map(tlog -> toAuditLog(tlog)).collect(Collectors.toList()));
}
/*
......
......@@ -15,6 +15,8 @@
*/
package org.genesys.blocks.auditlog.service.impl;
import java.util.Optional;
import javax.persistence.PersistenceException;
import org.genesys.blocks.auditlog.service.ClassPKService;
......@@ -96,8 +98,8 @@ public class ClassPKServiceImpl implements ClassPKService {
@Override
@Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRES_NEW)
public String getClassName(final Long id) {
final ClassPK classPK = classPkRepository.findOne(id);
return classPK.getClassname();
Optional<ClassPK> classPK = classPkRepository.findById(id);
return classPK.map(ClassPK::getClassname).orElse(null);
}
/*
......
......@@ -71,7 +71,7 @@ public class AuditLogEntityTest extends EntityTest<AuditLog, AuditLogRepository>
repository.save(log);
assertThat(log.getId(), not(nullValue()));
final AuditLog l = repository.findOne(log.getId());
final AuditLog l = repository.findById(log.getId()).orElse(null);
assertThat(l, not(nullValue()));
assertThat(l.getId(), equalTo(log.getId()));
assertThat(l.getClassPk(), not(nullValue()));
......
......@@ -16,6 +16,7 @@
package org.genesys.blocks.auditlog.model;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
import org.genesys.blocks.auditlog.test.EntityTest;
......@@ -60,7 +61,8 @@ public class ClassPKEntityTest extends EntityTest<ClassPK, ClassPKRepository> {
public void successfulPersist() {
final ClassPK cpk = repository.save(makeClassPK(Long.class));
final ClassPK l = repository.findOne(cpk.getId());
final ClassPK l = repository.findById(cpk.getId()).orElse(null);
assertThat(l, notNullValue());
assertThat(l.getId(), equalTo(cpk.getId()));
assertThat(l.getClassname(), equalTo(cpk.getClassname()));
}
......
......@@ -291,12 +291,12 @@ public class AuditTrailServiceTest extends ServiceTest {
other1 = otherEntityRepository.save(other1);
OtherEntity other2 = new OtherEntity("Other2");
other2 = otherEntityRepository.save(other2);
ExampleAuditedEntity entity = new ExampleAuditedEntity();
entity.setName("Test 1");
entity = exampleAuditedEntityService.save(entity);
assertThat(listAuditLogs(entity), hasSize(0));
entity.setOthers(Arrays.asList(other1));
entity = exampleAuditedEntityService.save(entity);
assertThat(listAuditLogs(entity), hasSize(1));
......
......@@ -64,7 +64,7 @@ public class ExampleAuditedEntityServiceImpl implements ExampleAuditedEntityServ
@Override
public ExampleAuditedEntity get(Long id) {
return exampleAuditedEntityRepository.findOne(id);
return exampleAuditedEntityRepository.findById(id).orElse(null);
}
}
......@@ -37,7 +37,7 @@ import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.core.JdbcTemplate;
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;
......@@ -140,7 +140,7 @@ public class DatabaseConfig {
// LOG.trace("JPA: " + key + " = " + jpaProperties.get(key));
// }
jpaProperties.put("hibernate.ejb.interceptor", new EmptyInterceptor() {
jpaProperties.put("hibernate.session_factory.interceptor", new EmptyInterceptor() {
private static final long serialVersionUID = 412280557897728434L;
// NOTE We're using the auditTrailInterceptor() to fetch the lazy-initialized
......
......@@ -24,3 +24,4 @@ hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFa
hibernate.cache.use_structured_entries=false
hibernate.generate_statistics=false
hibernate.id.new_generator_mappings=false
......@@ -19,7 +19,7 @@
<parent>
<groupId>org.genesys-pgr</groupId>
<artifactId>application-blocks-parent</artifactId>
<version>1.6-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<artifactId>application-blocks-core</artifactId>
......@@ -105,7 +105,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
<scope>provided</scope>
</dependency>
......
......@@ -26,7 +26,6 @@ import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldIndex;
import org.springframework.data.elasticsearch.annotations.FieldType;
import com.fasterxml.jackson.annotation.JsonProperty;
......@@ -48,7 +47,7 @@ public abstract class AuditedVersionedModel extends VersionedModel {
@CreatedBy
@Column(updatable = false)
@JsonSerialize(converter = JsonSidConverter.class)
@Field(type = FieldType.String, index = FieldIndex.not_analyzed)
@Field(type = FieldType.Text, index = false)
@JsonProperty(access = Access.READ_ONLY)
private Long createdBy;
......@@ -62,7 +61,7 @@ public abstract class AuditedVersionedModel extends VersionedModel {
@JsonView(JsonViews.Protected.class)
@LastModifiedBy
@JsonSerialize(converter = JsonSidConverter.class)
@Field(type = FieldType.String, index = FieldIndex.not_analyzed)
@Field(type = FieldType.Text, index = false)
@JsonProperty(access = Access.READ_ONLY)
private Long lastModifiedBy;
......
......@@ -26,7 +26,6 @@ import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldIndex;
import org.springframework.data.elasticsearch.annotations.FieldType;
import com.fasterxml.jackson.annotation.JsonProperty;
......@@ -48,7 +47,7 @@ public abstract class AuditedVersionedModelWithoutId extends VersionedModelWitho
@CreatedBy
@Column(updatable = false)
@JsonSerialize(converter = JsonSidConverter.class)
@Field(type = FieldType.String, index = FieldIndex.not_analyzed)
@Field(type = FieldType.Text, index = false)
@JsonProperty(access = Access.READ_ONLY)
private Long createdBy;
......@@ -62,7 +61,7 @@ public abstract class AuditedVersionedModelWithoutId extends VersionedModelWitho
@JsonView(JsonViews.Protected.class)
@LastModifiedBy
@JsonSerialize(converter = JsonSidConverter.class)
@Field(type = FieldType.String, index = FieldIndex.not_analyzed)
@Field(type = FieldType.Text, index = false)
@JsonProperty(access = Access.READ_ONLY)
private Long lastModifiedBy;
......
......@@ -23,7 +23,6 @@ import javax.persistence.PrePersist;
import org.hibernate.annotations.Type;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldIndex;
import org.springframework.data.elasticsearch.annotations.FieldType;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
......@@ -42,7 +41,7 @@ public abstract class UuidModel extends AuditedVersionedModel implements IdUUID
/** The uuid. */
@Column(unique = true, updatable = false, nullable = false)
@Type(type = "uuid-binary")
@Field(type = FieldType.String, store = false, index = FieldIndex.not_analyzed)
@Field(type = FieldType.Text, index = false)
protected UUID uuid;
/**
......
......@@ -28,7 +28,7 @@ import org.springframework.dao.support.PersistenceExceptionTranslator;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.core.JdbcTemplate;
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;
......
......@@ -19,7 +19,7 @@
<parent>
<groupId>org.genesys-pgr</groupId>
<artifactId>application-blocks</artifactId>
<version>1.6-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
</parent>
<artifactId>application-blocks-parent</artifactId>
<packaging>pom</packaging>
......@@ -40,17 +40,16 @@
<nexus-staging-maven-plugin.version>1.6.8</nexus-staging-maven-plugin.version>
<aspectj.version>1.7.2</aspectj.version>
<jackson.version>2.7.7</jackson.version>
<spring.version>4.3.2.RELEASE</spring.version>
<spring.data.version>1.10.4.RELEASE</spring.data.version>
<spring.security.oauth2.version>2.0.11.RELEASE</spring.security.oauth2.version>
<querydsl.version>4.1.4</querydsl.version>
<spring.security.version>4.1.3.RELEASE</spring.security.version>
<hibernate.version>4.3.11.Final</hibernate.version>
<hsqldb.version>2.4.0</hsqldb.version>
<jackson.version>2.10.1</jackson.version>
<spring.version>5.2.4.RELEASE</spring.version>
<spring.data.version>2.2.5.RELEASE</spring.data.version>
<spring.security.oauth2.version>2.3.4.RELEASE</spring.security.oauth2.version>
<querydsl.version>4.2.1</querydsl.version>
<spring.security.version>5.2.2.RELEASE</spring.security.version>
<!--<hibernate.version>5.3.15.Final</hibernate.version>-->
<hibernate.version>5.4.12.Final</hibernate.version>
<hsqldb.version>2.5.0</hsqldb.version>
<tomcat-jdbc.version>8.5.8</tomcat-jdbc.version>
<ehcache.version>2.7.4</ehcache.version>
</properties>
<repositories>
......@@ -185,7 +184,7 @@
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
<scope>provided</scope>
</dependency>
......@@ -221,7 +220,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>
......
......@@ -18,7 +18,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.genesys-pgr</groupId>
<artifactId>application-blocks</artifactId>
<version>1.6-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>Application Building Blocks</name>
<description>This is the shared project pom.</description>
......
......@@ -19,7 +19,7 @@
<parent>
<groupId>org.genesys-pgr</groupId>
<artifactId>application-blocks-parent</artifactId>
<version>1.6-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<artifactId>application-blocks-security</artifactId>
......@@ -80,12 +80,12 @@
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>application-blocks-core</artifactId>
<version>1.6-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
<scope>provided</scope>
</dependency>
......@@ -103,7 +103,14 @@
<version>${spring.security.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>${spring.security.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
......@@ -139,6 +146,13 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${spring.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-aspects</artifactId>
......@@ -155,7 +169,7 @@
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-hibernate4</artifactId>
<artifactId>jackson-datatype-hibernate5</artifactId>
<version>${jackson.version}</version>
<scope>test</scope>
</dependency>
......
......@@ -19,14 +19,14 @@ import org.genesys.blocks.oauth.model.OAuthClient;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.stereotype.Repository;
/**
* The Interface OAuthClientRepository.
*/
@Repository
public interface OAuthClientRepository extends JpaRepository<OAuthClient, Long>, QueryDslPredicateExecutor<OAuthClient> {
public interface OAuthClientRepository extends JpaRepository<OAuthClient, Long>, QuerydslPredicateExecutor<OAuthClient> {
/**
* Find by client id.
......
......@@ -44,6 +44,8 @@ import org.springframework.transaction.annotation.Transactional;
import com.querydsl.core.types.Predicate;
import javax.persistence.EntityNotFoundException;
/**
* The Class OAuthServiceImpl.
*/
......@@ -97,7 +99,7 @@ public class OAuthServiceImpl implements OAuthClientDetailsService {
*/
@Override
public List<OAuthClient> listClientDetails() {
return oauthClientRepository.findAll(new Sort("clientId"));
return oauthClientRepository.findAll(Sort.by("clientId"));
}
@Override
......@@ -212,14 +214,14 @@ public class OAuthServiceImpl implements OAuthClientDetailsService {
// description contains
.or(QOAuthClient.oAuthClient.description.contains(term));
return oauthClientRepository.findAll(predicate, new PageRequest(0, Math.min(100, limit), new Sort("title"))).getContent();
return oauthClientRepository.findAll(predicate, PageRequest.of(0, Math.min(100, limit), Sort.by("title"))).getContent();
}
@Override
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#oauthClient, 'ADMINISTRATION')")
public final String resetSecret(OAuthClient oauthClient) {
oauthClient = oauthClientRepository.findOne(oauthClient.getId());
oauthClient = oauthClientRepository.findById(oauthClient.getId()).orElseThrow(() -> new EntityNotFoundException("Record not found."));
String oldHash = oauthClient.getClientSecret();
String newHash = null;
......@@ -238,7 +240,7 @@ public class OAuthServiceImpl implements OAuthClientDetailsService {
@Transactional
@PreAuthorize("hasRole('ADMINISTRATOR') or hasPermission(#oauthClient, 'ADMINISTRATION')")
public final OAuthClient removeSecret(OAuthClient oauthClient) {
oauthClient = oauthClientRepository.findOne(oauthClient.getId());
oauthClient = oauthClientRepository.findById(oauthClient.getId()).orElseThrow(() -> new EntityNotFoundException("Record not found."));
if (oauthClient.getAuthorizedGrantTypes().contains("client_credentials")) {
throw new RuntimeException("OAuth Client with client_credentials grant must have a secret");
}
......
......@@ -15,6 +15,8 @@
*/
package org.genesys.blocks.security;
import java.util.Optional;
import org.genesys.blocks.security.model.AclSid;
import org.genesys.blocks.security.service.CustomAclService;
import org.slf4j.Logger;
......@@ -42,22 +44,22 @@ public class SpringSecurityAuditorAware implements AuditorAware<Long> {
* @see org.springframework.data.domain.AuditorAware#getCurrentAuditor()
*/
@Override
public Long getCurrentAuditor() {
public Optional<Long> getCurrentAuditor() {
final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication != null) {
Object principal = authentication.getPrincipal();
if (principal instanceof AclSid) {
return ((AclSid) principal).getId();
return Optional.of(((AclSid) principal).getId());
} else if (principal instanceof String) {
return aclService.getSidId((String) principal);
return Optional.of(aclService.getSidId((String) principal));
} else {
LOG.warn("Principal {} is not AclSid, but type {}. Auth of type {}", principal, principal.getClass(), authentication.getClass());
}
}
LOG.info("No security principal available.");
return null;
return Optional.empty();
}
}
......@@ -60,7 +60,7 @@ public class AclAssignerAspect {
* @param result the result
* @return the object
*/
@AfterReturning(pointcut = "execution(* org.springframework.data.repository.*.save(..)) || execution(* org.springframework.data.jpa.repository.*.save(..)) || execution(* org.springframework.data.jpa.repository.*.saveAndFlush(..))", returning = "result")
@AfterReturning(pointcut = "execution(* org.springframework.data.repository.*.save(..)) || execution(* org.springframework.data.repository.*.saveAll(..)) || execution(* org.springframework.data.jpa.repository.*.save(..)) || execution(* org.springframework.data.jpa.repository.*.saveAndFlush(..))", returning = "result")
public Object afterSaveAclObject(final Object result) {
final Authentication auth = SecurityContextHolder.getContext().getAuthentication();
......@@ -99,8 +99,11 @@ public class AclAssignerAspect {
*
* @param joinPoint the join point
*/
@Before("execution(* org.springframework.data.repository.*.delete(..)) || execution(* org.springframework.data.jpa.repository.*.deleteInBatch(..))")
@Before("execution(* org.springframework.data.repository.*.delete(..)) || execution(* org.springframework.data.repository.*.deleteAll(..)) || execution(* org.springframework.data.jpa.repository.*.deleteInBatch(..))")
public void afterDeleteAclObject(final JoinPoint joinPoint) {
if (joinPoint.getArgs().length == 0) {
return;
}
final Object arg0 = joinPoint.getArgs()[0];
try {
......
......@@ -21,13 +21,13 @@ import org.genesys.blocks.security.model.AclObjectIdentity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.querydsl.QuerydslPredicateExecutor;
import org.springframework.data.repository.query.Param;
/**
* The Interface AclObjectIdentityPersistence.
*/
public interface AclObjectIdentityPersistence extends JpaRepository<AclObjectIdentity, Long>, QueryDslPredicateExecutor<AclObjectIdentity> {
public interface AclObjectIdentityPersistence extends JpaRepository<AclObjectIdentity, Long>, QuerydslPredicateExecutor<AclObjectIdentity> {
/**
* Find by object id identity and class name.
......
......@@ -43,6 +43,8 @@ import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.transaction.annotation.Transactional;
import javax.persistence.EntityNotFoundException;
/**
* The Class BasicUserServiceImpl.
*
......@@ -174,7 +176,7 @@ public abstract class BasicUserServiceImpl<R extends GrantedAuthority, T extends
*/
@Override
public T getUser(final long id) {
final T user = _repository.findOne(id);
final T user = _repository.findById(id).orElse(null);
return deepLoad(user);
}
......@@ -203,7 +205,7 @@ public abstract class BasicUserServiceImpl<R extends GrantedAuthority, T extends
@PreAuthorize("hasRole('ADMINISTRATOR') || principal.id == #user.id")
public T updateUser(T user, final String email, final String fullName) throws NotUniqueUserException, UserException {
// reload
user = _repository.findOne(user.getId());
user = _repository.findById(user.getId()).orElseThrow(() -> new EntityNotFoundException("Record not found."));
if (!StringUtils.equals(email, user.getEmail()) && getUserByEmail(email) != null) {
throw new NotUniqueUserException("Email address already registered");
......@@ -237,7 +239,7 @@ public abstract class BasicUserServiceImpl<R extends GrantedAuthority, T extends
@Override
@Transactional
public T setRoles(T user, final Set<R> newRoles) {
user = _repository.findOne(user.getId());
user = _repository.findById(user.getId()).orElseThrow(() -> new EntityNotFoundException("Record not found."));
// Remove transient roles
newRoles.removeAll(getDefaultUserRoles());
......@@ -345,7 +347,7 @@ public abstract class BasicUserServiceImpl<R extends GrantedAuthority, T extends
@Override
@Transactional
public T setAccountType(T user, AccountType accountType) {
T u = _repository.findOne(user.getId());
T u = _repository.findById(user.getId()).orElseThrow(() -> new EntityNotFoundException("Record not found."));
u.setAccountType(accountType);