mirror of
https://github.com/valitydev/dominator.git
synced 2024-11-06 01:45:16 +00:00
FIN-33: Add ContractAdjustment using (#19)
This commit is contained in:
parent
e39f729ace
commit
5764dbea2e
2
pom.xml
2
pom.xml
@ -155,7 +155,7 @@
|
||||
<dependency>
|
||||
<groupId>dev.vality</groupId>
|
||||
<artifactId>dominator-proto</artifactId>
|
||||
<version>1.4-68a8678</version>
|
||||
<version>1.5-b9788c2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>dev.vality</groupId>
|
||||
|
@ -1,22 +1,14 @@
|
||||
package com.empayre.dominator.converter;
|
||||
|
||||
import com.empayre.dominator.dao.party.iface.TermSetHierarchyDao;
|
||||
import com.empayre.dominator.data.ShopTermSetDataObject;
|
||||
import com.empayre.dominator.domain.tables.pojos.TermSetHierarchy;
|
||||
import dev.vality.damsel.domain.TermSetHierarchyObject;
|
||||
import com.empayre.dominator.service.TermSetGettingService;
|
||||
import dev.vality.dominator.ShopTermSet;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.thrift.TDeserializer;
|
||||
import org.apache.thrift.TException;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.empayre.dominator.util.TermSetConverterUtils.createEmptyTermSetHierarchyObject;
|
||||
import static com.empayre.dominator.util.TermSetConverterUtils.replaceNull;
|
||||
|
||||
@Slf4j
|
||||
@ -24,40 +16,22 @@ import static com.empayre.dominator.util.TermSetConverterUtils.replaceNull;
|
||||
@RequiredArgsConstructor
|
||||
public class ShopTermSetConverter implements Converter<ShopTermSetDataObject, ShopTermSet> {
|
||||
|
||||
private final TDeserializer deserializer;
|
||||
private final TermSetHierarchyDao termSetHierarchyDao;
|
||||
private final TermSetGettingService termSetGettingService;
|
||||
|
||||
@Override
|
||||
public ShopTermSet convert(ShopTermSetDataObject source) {
|
||||
Long contractRecordId = source.getContractRecordId();
|
||||
TermSetHierarchy currentTermSet =
|
||||
termSetGettingService.getCurrentTermSet(contractRecordId, source.getTermSetId());
|
||||
return new ShopTermSet()
|
||||
.setOwnerId(replaceNull(source.getPartyId()))
|
||||
.setShopId(replaceNull(source.getShopId()))
|
||||
.setContractId(replaceNull(source.getContractId()))
|
||||
.setShopName(replaceNull(source.getShopName()))
|
||||
.setTermSetName(replaceNull(source.getTermSetName()))
|
||||
.setTermSetName(replaceNull(currentTermSet.getName()))
|
||||
.setCurrency(replaceNull(source.getCurrency()))
|
||||
.setCurrentTermSet(deserializeTermSet(source.getCurrentTermSetHierarchyObject()))
|
||||
.setTermSetHistory(deserializeTermSets(
|
||||
termSetHierarchyDao.getTermSetHierarchyHistory(source.getTermSetId())));
|
||||
}
|
||||
|
||||
private List<TermSetHierarchyObject> deserializeTermSets(List<TermSetHierarchy> termSetHierarchies) {
|
||||
return CollectionUtils.isEmpty(termSetHierarchies) ? new ArrayList<>() : termSetHierarchies.stream()
|
||||
.map(termSet -> deserializeTermSet(termSet.getTermSetHierarchyObject()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
private TermSetHierarchyObject deserializeTermSet(byte[] object) {
|
||||
try {
|
||||
if (object == null || object.length == 0) {
|
||||
return createEmptyTermSetHierarchyObject();
|
||||
}
|
||||
TermSetHierarchyObject termSetHierarchyObject = new TermSetHierarchyObject();
|
||||
deserializer.deserialize(termSetHierarchyObject, object);
|
||||
return termSetHierarchyObject;
|
||||
} catch (TException e) {
|
||||
log.error("TermSetHierarchyObject deserialization exception", e);
|
||||
return createEmptyTermSetHierarchyObject();
|
||||
}
|
||||
.setCurrentTermSet(
|
||||
termSetGettingService.getTermSetFromObject(currentTermSet.getTermSetHierarchyObject()))
|
||||
.setTermSetHistory(termSetGettingService.getTermSetHistory(contractRecordId));
|
||||
}
|
||||
}
|
||||
|
@ -3,12 +3,12 @@ package com.empayre.dominator.converter;
|
||||
import com.empayre.dominator.dao.dominant.iface.TerminalDao;
|
||||
import com.empayre.dominator.data.TerminalTermSetDataObject;
|
||||
import com.empayre.dominator.domain.tables.pojos.Terminal;
|
||||
import com.empayre.dominator.exception.SerializationException;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import dev.vality.damsel.domain.ProviderRef;
|
||||
import dev.vality.damsel.domain.ProvisionTermSet;
|
||||
import dev.vality.damsel.domain.TerminalRef;
|
||||
import dev.vality.dominator.ProvisionTermSetHistory;
|
||||
import dev.vality.dominator.TerminalTermSet;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@ -48,9 +48,10 @@ public class TerminalTermSetConverter implements Converter<TerminalTermSetDataOb
|
||||
.setTermSetHistory(deserializeTermSets(terminalDao.getTreminals(source.getTerminalId())));
|
||||
}
|
||||
|
||||
private List<ProvisionTermSet> deserializeTermSets(List<Terminal> termSetHierarchies) {
|
||||
private List<ProvisionTermSetHistory> deserializeTermSets(List<Terminal> termSetHierarchies) {
|
||||
return CollectionUtils.isEmpty(termSetHierarchies) ? new ArrayList<>() : termSetHierarchies.stream()
|
||||
.map(terminal -> deserializeTermSet(terminal.getTermsObject()))
|
||||
.map(terminal -> new ProvisionTermSetHistory()
|
||||
.setTermSet(deserializeTermSet(terminal.getTermsObject())))
|
||||
.toList();
|
||||
}
|
||||
|
||||
|
@ -1,23 +1,15 @@
|
||||
package com.empayre.dominator.converter;
|
||||
|
||||
import com.empayre.dominator.dao.party.iface.TermSetHierarchyDao;
|
||||
import com.empayre.dominator.data.WalletTermSetDataObject;
|
||||
import com.empayre.dominator.domain.tables.pojos.TermSetHierarchy;
|
||||
import com.empayre.dominator.service.TermSetGettingService;
|
||||
import dev.vality.damsel.domain.IdentityProviderRef;
|
||||
import dev.vality.damsel.domain.TermSetHierarchyObject;
|
||||
import dev.vality.dominator.WalletTermSet;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.thrift.TDeserializer;
|
||||
import org.apache.thrift.TException;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static com.empayre.dominator.util.TermSetConverterUtils.createEmptyTermSetHierarchyObject;
|
||||
import static com.empayre.dominator.util.TermSetConverterUtils.replaceNull;
|
||||
|
||||
@Slf4j
|
||||
@ -25,41 +17,23 @@ import static com.empayre.dominator.util.TermSetConverterUtils.replaceNull;
|
||||
@RequiredArgsConstructor
|
||||
public class WalletTermSetConverter implements Converter<WalletTermSetDataObject, WalletTermSet> {
|
||||
|
||||
private final TDeserializer deserializer;
|
||||
private final TermSetHierarchyDao termSetHierarchyDao;
|
||||
private final TermSetGettingService termSetGettingService;
|
||||
|
||||
@Override
|
||||
public WalletTermSet convert(WalletTermSetDataObject source) {
|
||||
Long contractRecordId = source.getContractRecordId();
|
||||
TermSetHierarchy currentTermSet =
|
||||
termSetGettingService.getCurrentTermSet(contractRecordId, source.getTermSetId());
|
||||
return new WalletTermSet()
|
||||
.setOwnerId(source.getPartyId())
|
||||
.setIdentityId(new IdentityProviderRef().setId(source.getIdentityId()))
|
||||
.setContractId(replaceNull(source.getContractId()))
|
||||
.setWalletId(replaceNull(source.getWalletId()))
|
||||
.setWalletName(replaceNull(source.getWalletName()))
|
||||
.setTermSetName(replaceNull(source.getTermSetName()))
|
||||
.setTermSetName(replaceNull(currentTermSet.getName()))
|
||||
.setCurrency(replaceNull(source.getCurrency()))
|
||||
.setCurrentTermSet(deserializeTermSet(source.getCurrentTermSetHierarchyObject()))
|
||||
.setTermSetHistory(deserializeTermSets(
|
||||
termSetHierarchyDao.getTermSetHierarchyHistory(source.getTermSetId())));
|
||||
}
|
||||
|
||||
private List<TermSetHierarchyObject> deserializeTermSets(List<TermSetHierarchy> termSetHierarchies) {
|
||||
return CollectionUtils.isEmpty(termSetHierarchies) ? new ArrayList<>() : termSetHierarchies.stream()
|
||||
.map(termSet -> deserializeTermSet(termSet.getTermSetHierarchyObject()))
|
||||
.toList();
|
||||
}
|
||||
|
||||
private TermSetHierarchyObject deserializeTermSet(byte[] object) {
|
||||
try {
|
||||
if (object == null || object.length == 0) {
|
||||
return createEmptyTermSetHierarchyObject();
|
||||
}
|
||||
TermSetHierarchyObject termSetHierarchyObject = new TermSetHierarchyObject();
|
||||
deserializer.deserialize(termSetHierarchyObject, object);
|
||||
return termSetHierarchyObject;
|
||||
} catch (TException e) {
|
||||
log.error("TermSetHierarchyObject deserialization exception", e);
|
||||
return createEmptyTermSetHierarchyObject();
|
||||
}
|
||||
.setCurrentTermSet(
|
||||
termSetGettingService.getTermSetFromObject(currentTermSet.getTermSetHierarchyObject()))
|
||||
.setTermSetHistory(termSetGettingService.getTermSetHistory(contractRecordId));
|
||||
}
|
||||
}
|
||||
|
@ -18,9 +18,7 @@ public class ShopTermSetDataObjectRowMapper implements RecordMapper<Record, Shop
|
||||
.currency(record.get(SHOP.ACCOUNT_CURRENCY_CODE))
|
||||
.shopName(record.get(SHOP.DETAILS_NAME))
|
||||
.termSetId(record.get(CONTRACT.TERMS_ID))
|
||||
.termSetName(record.get(TERM_SET_HIERARCHY.NAME))
|
||||
.currentTermSetJson(record.get(TERM_SET_HIERARCHY.TERM_SETS_JSON))
|
||||
.currentTermSetHierarchyObject(record.get(TERM_SET_HIERARCHY.TERM_SET_HIERARCHY_OBJECT))
|
||||
.contractRecordId(record.get(CONTRACT.ID))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
@ -19,9 +19,7 @@ public class WalletTermSetDataObjectRowMapper implements RecordMapper<Record, Wa
|
||||
.walletId(record.get(WALLET.WALLET_ID))
|
||||
.walletName(record.get(WALLET.WALLET_NAME))
|
||||
.termSetId(record.get(CONTRACT.TERMS_ID))
|
||||
.termSetName(record.get(TERM_SET_HIERARCHY.NAME))
|
||||
.currentTermSetJson(record.get(TERM_SET_HIERARCHY.TERM_SETS_JSON))
|
||||
.currentTermSetHierarchyObject(record.get(TERM_SET_HIERARCHY.TERM_SET_HIERARCHY_OBJECT))
|
||||
.contractRecordId(record.get(CONTRACT.ID))
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
@ -10,4 +10,6 @@ public interface ContractAdjustmentDao {
|
||||
void save(List<ContractAdjustment> contractAdjustmentList) throws DaoException;
|
||||
|
||||
List<ContractAdjustment> getByContractId(Long contractId) throws DaoException;
|
||||
|
||||
ContractAdjustment getLastByContractId(Long contractId) throws DaoException;
|
||||
}
|
||||
|
@ -12,5 +12,9 @@ public interface TermSetHierarchyDao extends DomainObjectDao<TermSetHierarchy, I
|
||||
|
||||
void updateNotCurrent(Integer termSetHierarchyId) throws DaoException;
|
||||
|
||||
List<TermSetHierarchy> getTermSetHierarchyHistory(Integer refId);
|
||||
TermSetHierarchy getCurrentTermSet(Integer refId);
|
||||
|
||||
List<TermSetHierarchy> getTermSetHierarchyHistory(Integer refId, boolean current);
|
||||
|
||||
byte[] getTermSetHierarchyObject(Integer refId, boolean current);
|
||||
}
|
||||
|
@ -29,7 +29,9 @@ public class ContractAdjustmentDaoImpl extends AbstractDao implements ContractAd
|
||||
.insertInto(CONTRACT_ADJUSTMENT)
|
||||
.set(contractAdjustmentRecord))
|
||||
.collect(Collectors.toList());
|
||||
getDslContext().batch(queries).execute();
|
||||
getDslContext()
|
||||
.batch(queries)
|
||||
.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -41,4 +43,14 @@ public class ContractAdjustmentDaoImpl extends AbstractDao implements ContractAd
|
||||
.fetch()
|
||||
.into(ContractAdjustment.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ContractAdjustment getLastByContractId(Long contractId) throws DaoException {
|
||||
return getDslContext()
|
||||
.selectFrom(CONTRACT_ADJUSTMENT)
|
||||
.where(CONTRACT_ADJUSTMENT.CONTRACT_ID.eq(contractId))
|
||||
.orderBy(CONTRACT_ADJUSTMENT.ID.desc())
|
||||
.limit(1)
|
||||
.fetchOneInto(ContractAdjustment.class);
|
||||
}
|
||||
}
|
||||
|
@ -39,8 +39,7 @@ public class TermSetDaoImpl extends AbstractDao implements TermSetDao {
|
||||
public List<ShopTermSetDataObject> getShopTermSets(Condition condition, int limit) {
|
||||
var fetch = getDslContext()
|
||||
.select(SHOP.ID, SHOP.PARTY_ID, SHOP.SHOP_ID, SHOP.CONTRACT_ID, SHOP.ACCOUNT_CURRENCY_CODE,
|
||||
SHOP.DETAILS_NAME, CONTRACT.TERMS_ID, TERM_SET_HIERARCHY.NAME,
|
||||
TERM_SET_HIERARCHY.TERM_SETS_JSON, TERM_SET_HIERARCHY.TERM_SET_HIERARCHY_OBJECT)
|
||||
SHOP.DETAILS_NAME, CONTRACT.TERMS_ID, CONTRACT.ID)
|
||||
.from(SHOP)
|
||||
.join(CONTRACT)
|
||||
.on(CONTRACT.CONTRACT_ID.eq(SHOP.CONTRACT_ID).and(CONTRACT.CURRENT))
|
||||
@ -58,8 +57,7 @@ public class TermSetDaoImpl extends AbstractDao implements TermSetDao {
|
||||
public List<WalletTermSetDataObject> getWalletTermSets(Condition condition, int limit) {
|
||||
var fetch = getDslContext()
|
||||
.select(WALLET.PARTY_ID, WALLET.IDENTITY_ID, IDENTITY.PARTY_CONTRACT_ID, WALLET.CURRENCY_CODE,
|
||||
WALLET.WALLET_ID, WALLET.WALLET_NAME, CONTRACT.TERMS_ID, TERM_SET_HIERARCHY.NAME,
|
||||
TERM_SET_HIERARCHY.TERM_SETS_JSON, WALLET.ID, TERM_SET_HIERARCHY.TERM_SET_HIERARCHY_OBJECT)
|
||||
WALLET.WALLET_ID, WALLET.WALLET_NAME, CONTRACT.TERMS_ID, CONTRACT.ID, WALLET.ID)
|
||||
.from(WALLET)
|
||||
.join(IDENTITY)
|
||||
.on(WALLET.IDENTITY_ID.eq(IDENTITY.IDENTITY_ID).and(IDENTITY.CURRENT))
|
||||
|
@ -43,12 +43,32 @@ public class TermSetHierarchyDaoImpl extends AbstractDao implements TermSetHiera
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TermSetHierarchy> getTermSetHierarchyHistory(Integer refId) {
|
||||
public TermSetHierarchy getCurrentTermSet(Integer refId) {
|
||||
return getDslContext()
|
||||
.selectFrom(TERM_SET_HIERARCHY)
|
||||
.where(TERM_SET_HIERARCHY.TERM_SET_HIERARCHY_REF_ID.eq(refId))
|
||||
.and(TERM_SET_HIERARCHY.CURRENT.isFalse())
|
||||
.and(TERM_SET_HIERARCHY.CURRENT.isTrue())
|
||||
.orderBy(TERM_SET_HIERARCHY.ID.desc())
|
||||
.fetchOneInto(TermSetHierarchy.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<TermSetHierarchy> getTermSetHierarchyHistory(Integer refId, boolean current) {
|
||||
return getDslContext()
|
||||
.selectFrom(TERM_SET_HIERARCHY)
|
||||
.where(TERM_SET_HIERARCHY.TERM_SET_HIERARCHY_REF_ID.eq(refId))
|
||||
.and(TERM_SET_HIERARCHY.CURRENT.eq(current))
|
||||
.orderBy(TERM_SET_HIERARCHY.ID.desc())
|
||||
.fetchInto(TermSetHierarchy.class);
|
||||
}
|
||||
|
||||
public byte[] getTermSetHierarchyObject(Integer refId, boolean current) {
|
||||
return getDslContext()
|
||||
.select(TERM_SET_HIERARCHY.TERM_SET_HIERARCHY_OBJECT)
|
||||
.from(TERM_SET_HIERARCHY)
|
||||
.where(TERM_SET_HIERARCHY.TERM_SET_HIERARCHY_REF_ID.eq(refId))
|
||||
.and(TERM_SET_HIERARCHY.CURRENT.eq(current))
|
||||
.fetchOne()
|
||||
.value1();
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,5 @@ public class ShopTermSetDataObject {
|
||||
private String currency;
|
||||
private String shopName;
|
||||
private Integer termSetId;
|
||||
private String termSetName;
|
||||
private String currentTermSetJson;
|
||||
private byte[] currentTermSetHierarchyObject;
|
||||
private Long contractRecordId;
|
||||
}
|
||||
|
@ -15,7 +15,5 @@ public class WalletTermSetDataObject {
|
||||
private String walletId;
|
||||
private String walletName;
|
||||
private Integer termSetId;
|
||||
private String termSetName;
|
||||
private String currentTermSetJson;
|
||||
private byte[] currentTermSetHierarchyObject;
|
||||
private Long contractRecordId;
|
||||
}
|
||||
|
@ -26,22 +26,20 @@ public class GetShopTermSetsHandler implements GetTermSetsHandler<ShopSearchQuer
|
||||
@Override
|
||||
public ShopTermSetsResponse handle(ShopSearchQuery query) {
|
||||
log.info("Start ShopTermSets getting (query: {})", query);
|
||||
List<ShopTermSetDataObject> shopTermSets = termSetDao.getShopTermSets(
|
||||
createShopCondition(query),
|
||||
query.getCommonSearchQueryParams().getLimit()
|
||||
);
|
||||
int limit = query.getCommonSearchQueryParams().getLimit();
|
||||
List<ShopTermSetDataObject> shopTermSets = termSetDao.getShopTermSets(createShopCondition(query), limit);
|
||||
|
||||
ShopTermSetsResponse response = new ShopTermSetsResponse()
|
||||
.setTerms(shopTermSets.stream().map(termSet -> shopTermSetConverter.convert(termSet)).toList())
|
||||
.setContinuationToken(createContinuationToken(shopTermSets));
|
||||
.setContinuationToken(createContinuationToken(shopTermSets, limit));
|
||||
log.info("Finish ShopTermSets getting (query: {}, terms.size: {}, token: {})",
|
||||
query, response.getTerms().size(), response.getContinuationToken());
|
||||
log.debug("Result ShopTermSetsResponse: {}", response);
|
||||
return response;
|
||||
}
|
||||
|
||||
private String createContinuationToken(List<ShopTermSetDataObject> shopTermSets) {
|
||||
return CollectionUtils.isEmpty(shopTermSets)
|
||||
private String createContinuationToken(List<ShopTermSetDataObject> shopTermSets, int limit) {
|
||||
return CollectionUtils.isEmpty(shopTermSets) || shopTermSets.size() < limit
|
||||
? null : String.valueOf(shopTermSets.get(shopTermSets.size() - 1).getId());
|
||||
}
|
||||
}
|
||||
|
@ -26,22 +26,21 @@ public class GetTerminalTermSetsHandler implements GetTermSetsHandler<TerminalSe
|
||||
@Override
|
||||
public TerminalTermSetsResponse handle(TerminalSearchQuery query) {
|
||||
log.info("Start TerminalTermSets getting (query: {})", query);
|
||||
List<TerminalTermSetDataObject> terminalTermSets = termSetDao.getTerminalTermSets(
|
||||
createTerminalCondition(query),
|
||||
query.getCommonSearchQueryParams().getLimit()
|
||||
);
|
||||
int limit = query.getCommonSearchQueryParams().getLimit();
|
||||
List<TerminalTermSetDataObject> terminalTermSets =
|
||||
termSetDao.getTerminalTermSets(createTerminalCondition(query), limit);
|
||||
|
||||
TerminalTermSetsResponse response = new TerminalTermSetsResponse()
|
||||
.setTerms(terminalTermSets.stream().map(set -> terminalTermSetConverter.convert(set)).toList())
|
||||
.setContinuationToken(createContinuationToken(terminalTermSets));
|
||||
.setContinuationToken(createContinuationToken(terminalTermSets, limit));
|
||||
log.info("Finish TerminalTermSets getting (query: {}, terms.size: {}, token: {})",
|
||||
query, response.getTerms().size(), response.getContinuationToken());
|
||||
log.debug("Result TerminalTermSetsResponse: {}", response);
|
||||
return response;
|
||||
}
|
||||
|
||||
private String createContinuationToken(List<TerminalTermSetDataObject> terminalTermSets) {
|
||||
return CollectionUtils.isEmpty(terminalTermSets)
|
||||
private String createContinuationToken(List<TerminalTermSetDataObject> terminalTermSets, int limit) {
|
||||
return CollectionUtils.isEmpty(terminalTermSets) || terminalTermSets.size() < limit
|
||||
? null : String.valueOf(terminalTermSets.get(terminalTermSets.size() - 1).getId());
|
||||
}
|
||||
}
|
||||
|
@ -26,22 +26,21 @@ public class GetWalletTermSetsHandler implements GetTermSetsHandler<WalletSearch
|
||||
@Override
|
||||
public WalletTermSetsResponse handle(WalletSearchQuery query) {
|
||||
log.info("Start WalletTermSets getting (query: {})", query);
|
||||
List<WalletTermSetDataObject> walletTermSets = termSetDao.getWalletTermSets(
|
||||
createWalletCondition(query),
|
||||
query.getCommonSearchQueryParams().getLimit()
|
||||
);
|
||||
int limit = query.getCommonSearchQueryParams().getLimit();
|
||||
List<WalletTermSetDataObject> walletTermSets =
|
||||
termSetDao.getWalletTermSets(createWalletCondition(query), limit);
|
||||
|
||||
WalletTermSetsResponse response = new WalletTermSetsResponse()
|
||||
.setTerms(walletTermSets.stream().map(set -> walletTermSetConverter.convert(set)).toList())
|
||||
.setContinuationToken(createContinuationToken(walletTermSets));
|
||||
.setContinuationToken(createContinuationToken(walletTermSets, limit));
|
||||
log.info("Finish WalletTermSets getting (query: {}, terms.size: {}, token: {})",
|
||||
query, response.getTerms().size(), response.getContinuationToken());
|
||||
log.debug("Result WalletTermSetsResponse: {}", response);
|
||||
return response;
|
||||
}
|
||||
|
||||
private String createContinuationToken(List<WalletTermSetDataObject> walletTermSets) {
|
||||
return CollectionUtils.isEmpty(walletTermSets)
|
||||
private String createContinuationToken(List<WalletTermSetDataObject> walletTermSets, int limit) {
|
||||
return CollectionUtils.isEmpty(walletTermSets) || walletTermSets.size() < limit
|
||||
? null : String.valueOf(walletTermSets.get(walletTermSets.size() - 1).getId());
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,58 @@
|
||||
package com.empayre.dominator.service;
|
||||
|
||||
import com.empayre.dominator.dao.party.iface.ContractAdjustmentDao;
|
||||
import com.empayre.dominator.dao.party.iface.TermSetHierarchyDao;
|
||||
import com.empayre.dominator.domain.tables.pojos.ContractAdjustment;
|
||||
import com.empayre.dominator.domain.tables.pojos.TermSetHierarchy;
|
||||
import dev.vality.damsel.domain.TermSetHierarchyObject;
|
||||
import dev.vality.dominator.TermSetHistory;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.thrift.TDeserializer;
|
||||
import org.apache.thrift.TException;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.empayre.dominator.util.TermSetConverterUtils.createEmptyTermSetHierarchyObject;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class TermSetGettingService {
|
||||
|
||||
private final TDeserializer deserializer;
|
||||
private final TermSetHierarchyDao termSetHierarchyDao;
|
||||
private final ContractAdjustmentDao contractAdjustmentDao;
|
||||
|
||||
public TermSetHierarchy getCurrentTermSet(Long contractRecordId, Integer defaultTermSetId) {
|
||||
ContractAdjustment lastAdjustment = contractAdjustmentDao.getLastByContractId(contractRecordId);
|
||||
Integer currentTermSetId = lastAdjustment == null ? defaultTermSetId : lastAdjustment.getTermsId();
|
||||
return termSetHierarchyDao.getCurrentTermSet(currentTermSetId);
|
||||
}
|
||||
|
||||
public List<TermSetHistory> getTermSetHistory(long contractRecordId) {
|
||||
return contractAdjustmentDao.getByContractId(contractRecordId).stream()
|
||||
.map(
|
||||
adj -> new TermSetHistory()
|
||||
.setTermSet(getTermSetFromObject(
|
||||
termSetHierarchyDao.getTermSetHierarchyObject(adj.getTermsId(), true)))
|
||||
.setAppliedAt(adj.getCreatedAt().toString())
|
||||
)
|
||||
.toList();
|
||||
}
|
||||
|
||||
public TermSetHierarchyObject getTermSetFromObject(byte[] object) {
|
||||
try {
|
||||
if (object == null || object.length == 0) {
|
||||
return createEmptyTermSetHierarchyObject();
|
||||
}
|
||||
TermSetHierarchyObject termSetHierarchyObject = new TermSetHierarchyObject();
|
||||
deserializer.deserialize(termSetHierarchyObject, object);
|
||||
return termSetHierarchyObject;
|
||||
} catch (TException e) {
|
||||
log.error("TermSetHierarchyObject deserialization exception", e);
|
||||
return createEmptyTermSetHierarchyObject();
|
||||
}
|
||||
}
|
||||
}
|
@ -59,6 +59,9 @@ public class DaoTests {
|
||||
@Test
|
||||
public void dominantDaoTest() {
|
||||
Provider provider = RandomBeans.random(Provider.class);
|
||||
provider.setTerminalObject(new byte[0]);
|
||||
provider.setWalletTermsObject(new byte[0]);
|
||||
provider.setPaymentTermsObject(new byte[0]);
|
||||
provider.setCurrent(true);
|
||||
providerDao.save(provider);
|
||||
providerDao.updateNotCurrent(provider.getProviderRefId());
|
||||
|
@ -81,7 +81,6 @@ public class DominatorServiceTest {
|
||||
.setPartyId("party-1")
|
||||
);
|
||||
assertNotNull(partyResponse);
|
||||
assertNotNull(partyResponse.getContinuationToken());
|
||||
assertNotNull(partyResponse.getTerms());
|
||||
assertEquals(1, partyResponse.getTerms().size());
|
||||
|
||||
@ -91,7 +90,6 @@ public class DominatorServiceTest {
|
||||
.setShopIds(List.of("party-1-shop-1", "party-2-shop-2", "party-2-shop-3", "party-3-shop-3"))
|
||||
);
|
||||
assertNotNull(shopResponse);
|
||||
assertNotNull(shopResponse.getContinuationToken());
|
||||
assertEquals(3, shopResponse.getTerms().size());
|
||||
|
||||
ShopTermSetsResponse termSetsIdsResponse = dominatorService.searchShopTermSets(
|
||||
@ -103,7 +101,6 @@ public class DominatorServiceTest {
|
||||
new TermSetHierarchyRef(5)))
|
||||
);
|
||||
assertNotNull(termSetsIdsResponse);
|
||||
assertNotNull(termSetsIdsResponse.getContinuationToken());
|
||||
assertEquals(3, termSetsIdsResponse.getTerms().size());
|
||||
|
||||
ShopTermSetsResponse termSetsNamesResponse = dominatorService.searchShopTermSets(
|
||||
@ -112,7 +109,6 @@ public class DominatorServiceTest {
|
||||
.setTermSetsNames(List.of("Name-1", "Name-6"))
|
||||
);
|
||||
assertNotNull(termSetsNamesResponse);
|
||||
assertNotNull(termSetsNamesResponse.getContinuationToken());
|
||||
assertEquals(2, termSetsNamesResponse.getTerms().size());
|
||||
}
|
||||
|
||||
@ -141,7 +137,6 @@ public class DominatorServiceTest {
|
||||
.setCommonSearchQueryParams(new CommonSearchQueryParams())
|
||||
);
|
||||
assertNotNull(emptyRequestResponse);
|
||||
assertNotNull(emptyRequestResponse.getContinuationToken());
|
||||
assertEquals(10, emptyRequestResponse.getTerms().size());
|
||||
|
||||
WalletTermSetsResponse partyResponse = dominatorService.searchWalletTermSets(
|
||||
@ -150,7 +145,6 @@ public class DominatorServiceTest {
|
||||
.setPartyId("WParty-1")
|
||||
);
|
||||
assertNotNull(partyResponse);
|
||||
assertNotNull(partyResponse.getContinuationToken());
|
||||
assertEquals(1, partyResponse.getTerms().size());
|
||||
|
||||
WalletTermSetsResponse walletResponse = dominatorService.searchWalletTermSets(
|
||||
@ -159,7 +153,6 @@ public class DominatorServiceTest {
|
||||
.setWalletIds(List.of("Wallet-9", "Wallet-8", "Wallet-81"))
|
||||
);
|
||||
assertNotNull(walletResponse);
|
||||
assertNotNull(walletResponse.getContinuationToken());
|
||||
assertEquals(2, walletResponse.getTerms().size());
|
||||
|
||||
WalletTermSetsResponse identityResponse = dominatorService.searchWalletTermSets(
|
||||
@ -172,7 +165,6 @@ public class DominatorServiceTest {
|
||||
))
|
||||
);
|
||||
assertNotNull(identityResponse);
|
||||
assertNotNull(identityResponse.getContinuationToken());
|
||||
assertEquals(3, identityResponse.getTerms().size());
|
||||
|
||||
WalletTermSetsResponse termIdsResponse = dominatorService.searchWalletTermSets(
|
||||
@ -186,7 +178,6 @@ public class DominatorServiceTest {
|
||||
))
|
||||
);
|
||||
assertNotNull(termIdsResponse);
|
||||
assertNotNull(termIdsResponse.getContinuationToken());
|
||||
assertEquals(4, termIdsResponse.getTerms().size());
|
||||
|
||||
WalletTermSetsResponse termNamesResponse = dominatorService.searchWalletTermSets(
|
||||
@ -195,7 +186,6 @@ public class DominatorServiceTest {
|
||||
.setTermSetsNames(List.of("Name-1", "Name-6"))
|
||||
);
|
||||
assertNotNull(termNamesResponse);
|
||||
assertNotNull(termNamesResponse.getContinuationToken());
|
||||
assertEquals(2, termNamesResponse.getTerms().size());
|
||||
}
|
||||
|
||||
@ -216,7 +206,6 @@ public class DominatorServiceTest {
|
||||
TerminalTermSetsResponse simpleResponse = dominatorService.searchTerminalTermSets(
|
||||
new TerminalSearchQuery().setCommonSearchQueryParams(new CommonSearchQueryParams()));
|
||||
assertNotNull(simpleResponse);
|
||||
assertNotNull(simpleResponse.getContinuationToken());
|
||||
assertEquals(10, simpleResponse.getTerms().size());
|
||||
|
||||
|
||||
@ -230,7 +219,6 @@ public class DominatorServiceTest {
|
||||
))
|
||||
);
|
||||
assertNotNull(terminalIdsResponse);
|
||||
assertNotNull(terminalIdsResponse.getContinuationToken());
|
||||
assertEquals(3, terminalIdsResponse.getTerms().size());
|
||||
|
||||
TerminalTermSetsResponse providerIdsResponse = dominatorService.searchTerminalTermSets(
|
||||
@ -245,7 +233,6 @@ public class DominatorServiceTest {
|
||||
))
|
||||
);
|
||||
assertNotNull(providerIdsResponse);
|
||||
assertNotNull(providerIdsResponse.getContinuationToken());
|
||||
assertEquals(5, providerIdsResponse.getTerms().size());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user