Fixing user deleter not deleting contact info and credentials
This commit is contained in:
parent
30abd31974
commit
20ffacad0d
|
@ -1,5 +1,6 @@
|
|||
package gr.cite.notification.model.deleter;
|
||||
|
||||
import gr.cite.notification.common.enums.IsActive;
|
||||
import gr.cite.notification.data.TenantScopedEntityManager;
|
||||
import gr.cite.notification.data.UserContactInfoEntity;
|
||||
import gr.cite.notification.query.UserContactInfoQuery;
|
||||
|
@ -27,18 +28,16 @@ public class UserContactInfoDeleter implements Deleter {
|
|||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserContactInfoDeleter.class));
|
||||
|
||||
private final TenantScopedEntityManager entityManager;
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
private final DeleterFactory deleterFactory;
|
||||
|
||||
@Autowired
|
||||
public UserContactInfoDeleter(
|
||||
TenantScopedEntityManager entityManager,
|
||||
QueryFactory queryFactory,
|
||||
DeleterFactory deleterFactory
|
||||
QueryFactory queryFactory
|
||||
) {
|
||||
this.entityManager = entityManager;
|
||||
this.queryFactory = queryFactory;
|
||||
this.deleterFactory = deleterFactory;
|
||||
}
|
||||
|
||||
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
|
||||
|
@ -58,12 +57,15 @@ public class UserContactInfoDeleter implements Deleter {
|
|||
|
||||
public void delete(List<UserContactInfoEntity> data) throws InvalidApplicationException {
|
||||
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty()) return;
|
||||
if (data == null || data.isEmpty())
|
||||
return;
|
||||
|
||||
Instant now = Instant.now();
|
||||
|
||||
for (UserContactInfoEntity item : data) {
|
||||
logger.trace("deleting item {}", item);
|
||||
item.setIsActive(IsActive.Inactive);
|
||||
item.setUpdatedAt(now);
|
||||
logger.trace("updating item");
|
||||
this.entityManager.merge(item);
|
||||
logger.trace("updated item");
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
package gr.cite.notification.model.deleter;
|
||||
|
||||
import gr.cite.notification.common.enums.IsActive;
|
||||
import gr.cite.notification.data.TenantScopedEntityManager;
|
||||
import gr.cite.notification.data.UserCredentialEntity;
|
||||
import gr.cite.notification.query.UserCredentialQuery;
|
||||
import gr.cite.tools.data.deleter.Deleter;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import gr.cite.tools.logging.MapLogEntry;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.management.InvalidApplicationException;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class UserCredentialDeleter implements Deleter {
|
||||
|
||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserCredentialDeleter.class));
|
||||
|
||||
private final TenantScopedEntityManager entityManager;
|
||||
|
||||
private final QueryFactory queryFactory;
|
||||
|
||||
@Autowired
|
||||
public UserCredentialDeleter(
|
||||
TenantScopedEntityManager entityManager,
|
||||
QueryFactory queryFactory
|
||||
) {
|
||||
this.entityManager = entityManager;
|
||||
this.queryFactory = queryFactory;
|
||||
}
|
||||
|
||||
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
|
||||
logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids));
|
||||
List<UserCredentialEntity> data = this.queryFactory.query(UserCredentialQuery.class).ids(ids).collect();
|
||||
logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
this.deleteAndSave(data);
|
||||
}
|
||||
|
||||
public void deleteAndSave(List<UserCredentialEntity> data) throws InvalidApplicationException {
|
||||
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
this.delete(data);
|
||||
logger.trace("saving changes");
|
||||
this.entityManager.flush();
|
||||
logger.trace("changes saved");
|
||||
}
|
||||
|
||||
public void delete(List<UserCredentialEntity> data) throws InvalidApplicationException {
|
||||
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty())
|
||||
return;
|
||||
|
||||
Instant now = Instant.now();
|
||||
|
||||
for (UserCredentialEntity item : data) {
|
||||
logger.trace("deleting item {}", item);
|
||||
item.setIsActive(IsActive.Inactive);
|
||||
item.setUpdatedAt(now);
|
||||
logger.trace("updating item");
|
||||
this.entityManager.merge(item);
|
||||
logger.trace("updated item");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,13 +1,18 @@
|
|||
package gr.cite.notification.model.deleter;
|
||||
|
||||
import gr.cite.notification.common.enums.IsActive;
|
||||
import gr.cite.notification.data.*;
|
||||
import gr.cite.notification.query.*;
|
||||
import gr.cite.notification.data.UserContactInfoEntity;
|
||||
import gr.cite.notification.data.UserCredentialEntity;
|
||||
import gr.cite.notification.data.UserEntity;
|
||||
import gr.cite.notification.query.UserContactInfoQuery;
|
||||
import gr.cite.notification.query.UserCredentialQuery;
|
||||
import gr.cite.notification.query.UserQuery;
|
||||
import gr.cite.tools.data.deleter.Deleter;
|
||||
import gr.cite.tools.data.deleter.DeleterFactory;
|
||||
import gr.cite.tools.data.query.QueryFactory;
|
||||
import gr.cite.tools.logging.LoggerService;
|
||||
import gr.cite.tools.logging.MapLogEntry;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
@ -19,19 +24,23 @@ import java.time.Instant;
|
|||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
|
||||
public class UserDeleter implements Deleter {
|
||||
|
||||
private static final LoggerService logger = new LoggerService(LoggerFactory.getLogger(UserDeleter.class));
|
||||
|
||||
private final TenantScopedEntityManager entityManager;
|
||||
private final QueryFactory queryFactory;
|
||||
private final DeleterFactory deleterFactory;
|
||||
private final EntityManager entityManager;
|
||||
|
||||
protected final QueryFactory queryFactory;
|
||||
|
||||
protected final DeleterFactory deleterFactory;
|
||||
|
||||
@Autowired
|
||||
public UserDeleter(
|
||||
TenantScopedEntityManager entityManager,
|
||||
EntityManager entityManager,
|
||||
QueryFactory queryFactory,
|
||||
DeleterFactory deleterFactory
|
||||
) {
|
||||
|
@ -41,27 +50,52 @@ public class UserDeleter implements Deleter {
|
|||
}
|
||||
|
||||
public void deleteAndSaveByIds(List<UUID> ids) throws InvalidApplicationException {
|
||||
logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(e -> e.size()).orElse(0)).And("ids", ids));
|
||||
List<UserEntity> datas = this.queryFactory.query(UserQuery.class).ids(ids).collect();
|
||||
logger.trace("retrieved {} items", Optional.ofNullable(datas).map(e -> e.size()).orElse(0));
|
||||
this.deleteAndSave(datas);
|
||||
logger.debug(new MapLogEntry("collecting to delete").And("count", Optional.ofNullable(ids).map(List::size).orElse(0)).And("ids", ids));
|
||||
List<UserEntity> data = this.queryFactory.query(UserQuery.class).ids(ids).collect();
|
||||
logger.trace("retrieved {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
this.deleteAndSave(data);
|
||||
}
|
||||
|
||||
public void deleteAndSave(List<UserEntity> datas) throws InvalidApplicationException {
|
||||
logger.debug("will delete {} items", Optional.ofNullable(datas).map(e -> e.size()).orElse(0));
|
||||
this.delete(datas);
|
||||
public void deleteAndSave(List<UserEntity> data) throws InvalidApplicationException {
|
||||
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
this.delete(data);
|
||||
logger.trace("saving changes");
|
||||
this.entityManager.flush();
|
||||
logger.trace("changes saved");
|
||||
}
|
||||
|
||||
public void delete(List<UserEntity> datas) throws InvalidApplicationException {
|
||||
logger.debug("will delete {} items", Optional.ofNullable(datas).map(x -> x.size()).orElse(0));
|
||||
if (datas == null || datas.isEmpty()) return;
|
||||
|
||||
public void delete(List<UserEntity> data) throws InvalidApplicationException {
|
||||
logger.debug("will delete {} items", Optional.ofNullable(data).map(List::size).orElse(0));
|
||||
if (data == null || data.isEmpty())
|
||||
return;
|
||||
List<UUID> ids = data.stream().map(UserEntity::getId).distinct().collect(Collectors.toList());
|
||||
// {
|
||||
// logger.debug("checking related - {}", UserRoleEntity.class.getSimpleName());
|
||||
// List<UserRoleEntity> items = this.queryFactory.query(UserRoleQuery.class).userIds(ids).collect();
|
||||
// UserRoleDeleter deleter = this.deleterFactory.deleter(UserRoleDeleter.class);
|
||||
// deleter.delete(items);
|
||||
// }
|
||||
{
|
||||
logger.debug("checking related - {}", UserCredentialEntity.class.getSimpleName());
|
||||
List<UserCredentialEntity> items = this.queryFactory.query(UserCredentialQuery.class).userIds(ids).collect();
|
||||
UserCredentialDeleter deleter = this.deleterFactory.deleter(UserCredentialDeleter.class);
|
||||
deleter.delete(items);
|
||||
}
|
||||
{
|
||||
logger.debug("checking related - {}", UserContactInfoEntity.class.getSimpleName());
|
||||
List<UserContactInfoEntity> items = this.queryFactory.query(UserContactInfoQuery.class).userIds(ids).collect();
|
||||
UserContactInfoDeleter deleter = this.deleterFactory.deleter(UserContactInfoDeleter.class);
|
||||
deleter.delete(items);
|
||||
}
|
||||
// {
|
||||
// logger.debug("checking related - {}", TenantUserEntity.class.getSimpleName());
|
||||
// List<TenantUserEntity> items = this.queryFactory.query(TenantUserQuery.class).userIds(ids).collect();
|
||||
// TenantUserDeleter deleter = this.deleterFactory.deleter(TenantUserDeleter.class);
|
||||
// deleter.delete(items);
|
||||
// }
|
||||
Instant now = Instant.now();
|
||||
|
||||
for (UserEntity item : datas) {
|
||||
for (UserEntity item : data) {
|
||||
logger.trace("deleting item {}", item.getId());
|
||||
item.setIsActive(IsActive.Inactive);
|
||||
item.setUpdatedAt(now);
|
||||
|
|
Loading…
Reference in New Issue