FIN-29: TermSets serialization fix (#18)

This commit is contained in:
Baikov Dmitrii 2024-05-16 14:00:02 +03:00 committed by GitHub
parent c56fc943f7
commit e39f729ace
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 28 additions and 7 deletions

View File

@ -3,10 +3,10 @@ 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 com.empayre.dominator.exception.SerializationException;
import dev.vality.damsel.domain.TermSetHierarchyObject;
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;
@ -16,8 +16,10 @@ 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
@Component
@RequiredArgsConstructor
public class ShopTermSetConverter implements Converter<ShopTermSetDataObject, ShopTermSet> {
@ -48,13 +50,14 @@ public class ShopTermSetConverter implements Converter<ShopTermSetDataObject, Sh
private TermSetHierarchyObject deserializeTermSet(byte[] object) {
try {
if (object == null || object.length == 0) {
return new TermSetHierarchyObject();
return createEmptyTermSetHierarchyObject();
}
TermSetHierarchyObject termSetHierarchyObject = new TermSetHierarchyObject();
deserializer.deserialize(termSetHierarchyObject, object);
return termSetHierarchyObject;
} catch (TException e) {
throw new SerializationException(e);
log.error("TermSetHierarchyObject deserialization exception", e);
return createEmptyTermSetHierarchyObject();
}
}
}

View File

@ -63,7 +63,8 @@ public class TerminalTermSetConverter implements Converter<TerminalTermSetDataOb
deserializer.deserialize(termSet, object);
return termSet;
} catch (TException e) {
throw new SerializationException(e);
log.error("ProvisionTermSet deserialization exception", e);
return new ProvisionTermSet();
}
}

View File

@ -3,11 +3,11 @@ 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.exception.SerializationException;
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;
@ -17,8 +17,10 @@ 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
@Component
@RequiredArgsConstructor
public class WalletTermSetConverter implements Converter<WalletTermSetDataObject, WalletTermSet> {
@ -50,13 +52,14 @@ public class WalletTermSetConverter implements Converter<WalletTermSetDataObject
private TermSetHierarchyObject deserializeTermSet(byte[] object) {
try {
if (object == null || object.length == 0) {
return new TermSetHierarchyObject();
return createEmptyTermSetHierarchyObject();
}
TermSetHierarchyObject termSetHierarchyObject = new TermSetHierarchyObject();
deserializer.deserialize(termSetHierarchyObject, object);
return termSetHierarchyObject;
} catch (TException e) {
throw new SerializationException(e);
log.error("TermSetHierarchyObject deserialization exception", e);
return createEmptyTermSetHierarchyObject();
}
}
}

View File

@ -1,7 +1,11 @@
package com.empayre.dominator.util;
import dev.vality.damsel.domain.TermSetHierarchyObject;
import dev.vality.damsel.domain.TermSetHierarchyRef;
import lombok.experimental.UtilityClass;
import java.util.ArrayList;
@UtilityClass
public class TermSetConverterUtils {
@ -10,4 +14,14 @@ public class TermSetConverterUtils {
public static String replaceNull(String source) {
return source == null ? EMPTY : source;
}
public static TermSetHierarchyObject createEmptyTermSetHierarchyObject() {
return new TermSetHierarchyObject()
.setRef(new TermSetHierarchyRef().setId(-1))
.setData(new dev.vality.damsel.domain.TermSetHierarchy()
.setName("-")
.setDescription("-")
.setTermSets(new ArrayList<>())
);
}
}