SUPPORT-9212: fix
This commit is contained in:
parent
7bfd61e63e
commit
e0c6544e6c
5 changed files with 24 additions and 15 deletions
|
|
@ -2,6 +2,7 @@ package ervu_business_metrics.dao;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jooq.*;
|
||||
import org.jooq.impl.DSL;
|
||||
|
|
@ -54,12 +55,12 @@ public abstract class AbstractDataDao<T extends UpdatableRecord<T>> {
|
|||
.execute();
|
||||
}
|
||||
|
||||
protected <S, F> List<S> getValuesByField(Field<S> selectField, Field<F> filterField,
|
||||
protected <S, F> Set<S> getValuesByField(Field<S> selectField, Field<F> filterField,
|
||||
F filterValue) {
|
||||
return dsl.select(selectField)
|
||||
.from(getTable())
|
||||
.where(filterField.eq(filterValue))
|
||||
.fetch(selectField);
|
||||
.fetchSet(selectField);
|
||||
}
|
||||
|
||||
public void setActiveStatus(String id, boolean isActive) {
|
||||
|
|
@ -79,4 +80,5 @@ public abstract class AbstractDataDao<T extends UpdatableRecord<T>> {
|
|||
public void mergeRecords(List<T> records) {
|
||||
dsl.batchMerge(records).execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
package ervu_business_metrics.dao;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.Table;
|
||||
|
|
@ -19,7 +20,7 @@ public class AccountDataDao extends AbstractDataDao<AccountRecord> {
|
|||
super(dsl);
|
||||
}
|
||||
|
||||
public List<String> getAccountIdsByPersonId(String personId) {
|
||||
public Set<String> getAccountIdsByPersonId(String personId) {
|
||||
return getValuesByField(Tables.ACCOUNT.ID, Tables.ACCOUNT.PERSON_ID, personId);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ package ervu_business_metrics.dao;
|
|||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jooq.DSLContext;
|
||||
import org.jooq.Field;
|
||||
|
|
@ -22,7 +23,7 @@ public class AccountRoleDataDao extends AbstractDataDao<AccountRoleRecord> {
|
|||
super(dsl);
|
||||
}
|
||||
|
||||
public List<String> getRoleIdsByAccountId(String accountId) {
|
||||
public Set<String> getRoleIdsByAccountId(String accountId) {
|
||||
return getValuesByField(Tables.ACCOUNT_ROLE.ROLE_ID, Tables.ACCOUNT_ROLE.ACCOUNT_ID, accountId);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ public class AccountDataProcessor implements DataProcessor<AccountData, AccountR
|
|||
}
|
||||
|
||||
private void deleteAbsentAccounts(String personId, Set<String> incomingAccountIds) {
|
||||
List<String> existingAccountIds = dao.getAccountIdsByPersonId(personId);
|
||||
Set<String> existingAccountIds = dao.getAccountIdsByPersonId(personId);
|
||||
|
||||
List<String> toDelete = existingAccountIds.stream()
|
||||
.filter(id -> !incomingAccountIds.contains(id))
|
||||
|
|
|
|||
|
|
@ -49,11 +49,11 @@ public class AccountRoleDataProcessor implements LinkDataProcessor<AccountRoleDa
|
|||
}
|
||||
|
||||
public void upsertAccountRoles(List<AccountData> accounts) {
|
||||
List<AccountRoleRecord> allRoleRecords = new ArrayList<>();
|
||||
List<AccountRoleRecord> accountRoleRecords = new ArrayList<>();
|
||||
|
||||
for (AccountData account : accounts) {
|
||||
List<String> existingRoleIds = dao.getRoleIdsByAccountId(account.getId());
|
||||
|
||||
String accountId = account.getId();
|
||||
Set<String> existingRoleIds = dao.getRoleIdsByAccountId(accountId);
|
||||
Set<String> incomingRoleIds = account.getRoles() == null
|
||||
? Set.of()
|
||||
: account.getRoles()
|
||||
|
|
@ -66,18 +66,23 @@ public class AccountRoleDataProcessor implements LinkDataProcessor<AccountRoleDa
|
|||
.toList();
|
||||
|
||||
if (!toDelete.isEmpty()) {
|
||||
dao.deleteAccountRolesByAccountIdAndRoleIds(account.getId(), toDelete);
|
||||
dao.deleteAccountRolesByAccountIdAndRoleIds(accountId, toDelete);
|
||||
}
|
||||
|
||||
if (!incomingRoleIds.isEmpty()) {
|
||||
for (ReferenceEntity role : account.getRoles()) {
|
||||
allRoleRecords.add(mapToRecord(new AccountRoleData(account.getId(), role.getId())));
|
||||
}
|
||||
List<String> toAdd = incomingRoleIds.stream()
|
||||
.filter(roleId -> !existingRoleIds.contains(roleId))
|
||||
.toList();
|
||||
|
||||
if (!toAdd.isEmpty()) {
|
||||
List<AccountRoleRecord> newRecords = toAdd.stream()
|
||||
.map(roleId -> mapToRecord(new AccountRoleData(accountId, roleId)))
|
||||
.toList();
|
||||
accountRoleRecords.addAll(newRecords);
|
||||
}
|
||||
}
|
||||
|
||||
if (!allRoleRecords.isEmpty()) {
|
||||
dao.mergeRecords(allRoleRecords);
|
||||
if (!accountRoleRecords.isEmpty()) {
|
||||
dao.mergeRecords(accountRoleRecords);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue