mirror of
https://github.com/valitydev/dominator.git
synced 2024-11-06 01:45:16 +00:00
FIN-29: TermSets serialization fix (#18)
This commit is contained in:
parent
c56fc943f7
commit
e39f729ace
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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<>())
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user