Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
<dependency>
<groupId>dev.vality</groupId>
<artifactId>damsel</artifactId>
<version>1.685-5c25c2e</version>
<version>1.692-70b59b9</version>
</dependency>
<dependency>
<groupId>dev.vality</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,21 @@ public abstract class AbstractDominantHandler<T, C, I> implements DominantHandle

protected abstract boolean acceptDomainObject();

protected abstract boolean acceptReference();

public abstract C convertToDatabaseObject(T object, Long versionId, boolean current, String createdAt);

@Override
@Transactional(propagation = Propagation.REQUIRED)
public void handle(FinalOperation operation, Long versionId, String createdAt) {
T object = getTargetObject();
if (operation.isSetInsert()) {
T object = getTargetObject();
insertDomainObject(object, versionId, createdAt);
} else if (operation.isSetUpdate()) {
T object = getTargetObject();
updateDomainObject(object, versionId, createdAt);
} else if (operation.isSetRemove()) {
removeDomainObject(object, versionId, createdAt);
removeDomainObject(versionId);
} else {
throw new IllegalStateException(
UNKNOWN_TYPE_EX + operation);
Expand All @@ -66,6 +69,7 @@ public boolean acceptAndSet(FinalOperation operation) {
setDomainObject(operation.getUpdate().getObject());
} else if (operation.isSetRemove()) {
setReference(operation.getRemove().getRef());
return acceptReference();
} else {
throw new IllegalStateException(
UNKNOWN_TYPE_EX + operation);
Expand Down Expand Up @@ -93,12 +97,9 @@ public void updateDomainObject(T object, Long versionId, String createdAt) {
}

@Transactional(propagation = Propagation.REQUIRED)
public void removeDomainObject(T object, Long versionId, String createdAt) {
log.info("Start to remove '{}' with id={}, versionId={}", object.getClass().getSimpleName(),
getTargetRefId(), versionId);
public void removeDomainObject(Long versionId) {
log.info("Start to remove object with id={}, versionId={}", getTargetRefId(), versionId);
getDomainObjectDao().updateNotCurrent(getTargetRefId());
getDomainObjectDao().save(convertToDatabaseObject(object, versionId, false, createdAt));
log.info("End to remove '{}' with id={}, versionId={}", object.getClass().getSimpleName(),
getTargetRefId(), versionId);
log.info("End to remove object with id={}, versionId={}", getTargetRefId(), versionId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ protected boolean acceptDomainObject() {
return getDomainObject() != null && getDomainObject().isSetCategory();
}

@Override
protected boolean acceptReference() {
return getReference() != null && getReference().isSetCategory();
}

@Override
public Category convertToDatabaseObject(CategoryObject categoryObject, Long versionId, boolean current, String createdAt) {
Category category = new Category();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@ protected boolean acceptDomainObject() {
return getDomainObject() != null && getDomainObject().isSetCurrency();
}

@Override
protected boolean acceptReference() {
return getReference() != null && getReference().isSetCurrency();
}

@Override
public Currency convertToDatabaseObject(CurrencyObject currencyObject, Long versionId, boolean current,
String createdAt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ protected boolean acceptDomainObject() {
return getDomainObject() != null && getDomainObject().isSetPartyConfig();
}

@Override
protected boolean acceptReference() {
return getReference() != null && getReference().isSetPartyConfig();
}

@Override
public Party convertToDatabaseObject(PartyConfigObject partyConfigObject, Long versionId, boolean current,
String createdAt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ protected boolean acceptDomainObject() {
return getDomainObject() != null && getDomainObject().isSetPaymentInstitution();
}

@Override
protected boolean acceptReference() {
return getReference() != null && getReference().isSetPaymentInstitution();
}

@Override
public PaymentInstitution convertToDatabaseObject(PaymentInstitutionObject paymentInstitutionObject, Long versionId,
boolean current, String createdAt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ protected boolean acceptDomainObject() {
return getDomainObject() != null && getDomainObject().isSetRoutingRules();
}

@Override
protected boolean acceptReference() {
return getReference() != null && getReference().isSetRoutingRules();
}

@Override
public PaymentRoutingRule convertToDatabaseObject(RoutingRulesObject rulesObject,
Long versionId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ protected boolean acceptDomainObject() {
return getDomainObject() != null && getDomainObject().isSetProvider();
}

@Override
protected boolean acceptReference() {
return getReference() != null && getReference().isSetProvider();
}

@Override
public Provider convertToDatabaseObject(ProviderObject providerObject, Long versionId, boolean current,
String createdAt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ protected boolean acceptDomainObject() {
return getDomainObject() != null && getDomainObject().isSetProxy();
}

@Override
protected boolean acceptReference() {
return getReference() != null && getReference().isSetProxy();
}

@Override
public Proxy convertToDatabaseObject(ProxyObject proxyObject, Long versionId, boolean current, String createdAt) {
Proxy proxy = new Proxy();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ protected boolean acceptDomainObject() {
return getDomainObject() != null && getDomainObject().isSetShopConfig();
}

@Override
protected boolean acceptReference() {
return getReference() != null && getReference().isSetShopConfig();
}

@Override
public Shop convertToDatabaseObject(ShopConfigObject shopConfigObject, Long versionId, boolean current,
String createdAt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ protected boolean acceptDomainObject() {
return getDomainObject() != null && getDomainObject().isSetTermSetHierarchy();
}

@Override
protected boolean acceptReference() {
return getReference() != null && getReference().isSetTermSetHierarchy();
}

@Override
public TermSetHierarchy convertToDatabaseObject(TermSetHierarchyObject termSetHierarchyObject, Long versionId,
boolean current, String createdAt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ protected boolean acceptDomainObject() {
return getDomainObject() != null && getDomainObject().isSetTerminal();
}

@Override
protected boolean acceptReference() {
return getReference() != null && getReference().isSetTerminal();
}

@Override
public Terminal convertToDatabaseObject(TerminalObject terminalObject, Long versionId, boolean current,
String createdAt) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ protected boolean acceptDomainObject() {
return getDomainObject() != null && getDomainObject().isSetWalletConfig();
}

@Override
protected boolean acceptReference() {
return getReference() != null && getReference().isSetWalletConfig();
}

@Override
public Wallet convertToDatabaseObject(WalletConfigObject walletConfigObjectData,
Long versionId,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package dev.vality.daway.handler.dominant.impl;

import dev.vality.damsel.domain.Reference;
import dev.vality.damsel.domain.ShopConfigRef;
import dev.vality.damsel.domain_config_v2.FinalOperation;
import dev.vality.damsel.domain_config_v2.RemoveOp;
import dev.vality.daway.dao.dominant.impl.ShopDaoImpl;
import dev.vality.daway.domain.tables.pojos.Shop;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;

@ExtendWith(MockitoExtension.class)
class ShopHandlerTest {

@Mock
private ShopDaoImpl shopDao;

@Test
void handleRemoveOperationByShopConfigReference() {
String shopId = "561b311f-803c-4caf-a8d0-8241f298a727";
ShopHandler shopHandler = new ShopHandler(shopDao);
FinalOperation operation = FinalOperation.remove(new RemoveOp()
.setRef(Reference.shop_config(new ShopConfigRef(shopId))));

assertTrue(shopHandler.acceptAndSet(operation));
shopHandler.handle(operation, 6079L, "2026-06-05T08:54:58Z");

verify(shopDao).updateNotCurrent(shopId);
verify(shopDao, never()).save(org.mockito.ArgumentMatchers.any(Shop.class));
}
}
Loading