Merge pull request #196 from joshuadwire/develop
Reimplement import map data format to avoid serializer workaround
This commit is contained in:
commit
e0dd2a6c86
|
|
@ -57,7 +57,7 @@ abstract class ImportRequest
|
|||
@required String hash,
|
||||
@required String importType,
|
||||
@required bool skipHeader,
|
||||
@required BuiltMap<String, BuiltMap<int, String>> columnMap,
|
||||
@required BuiltMap<String, ImportRequestMapping> columnMap,
|
||||
}) {
|
||||
return _$ImportRequest._(
|
||||
hash: hash,
|
||||
|
|
@ -82,16 +82,31 @@ abstract class ImportRequest
|
|||
bool get skipHeader;
|
||||
|
||||
@BuiltValueField(wireName: 'column_map')
|
||||
BuiltMap<String, BuiltMap<int, String>> get columnMap;
|
||||
|
||||
// This needed so the builder factory for BuiltMap<int, String> is auto-created.
|
||||
@nullable
|
||||
@BuiltValueField(wireName: 'dummy_field')
|
||||
BuiltMap<int, String> get dummy;
|
||||
BuiltMap<String, ImportRequestMapping> get columnMap;
|
||||
|
||||
static Serializer<ImportRequest> get serializer => _$importRequestSerializer;
|
||||
}
|
||||
|
||||
abstract class ImportRequestMapping
|
||||
implements Built<ImportRequestMapping, ImportRequestMappingBuilder> {
|
||||
factory ImportRequestMapping(BuiltMap<int, String> mapping) {
|
||||
return _$ImportRequestMapping._(
|
||||
mapping: mapping
|
||||
);
|
||||
}
|
||||
|
||||
ImportRequestMapping._();
|
||||
|
||||
@override
|
||||
@memoized
|
||||
int get hashCode;
|
||||
|
||||
@BuiltValueField(wireName: 'mapping')
|
||||
BuiltMap<int, String> get mapping;
|
||||
|
||||
static Serializer<ImportRequestMapping> get serializer => _$importRequestMappingSerializer;
|
||||
}
|
||||
|
||||
class ImportType extends EnumClass {
|
||||
const ImportType._(String name) : super(name);
|
||||
|
||||
|
|
|
|||
|
|
@ -49,6 +49,8 @@ Serializer<PreImportResponseEntityDetails>
|
|||
new _$PreImportResponseEntityDetailsSerializer();
|
||||
Serializer<ImportRequest> _$importRequestSerializer =
|
||||
new _$ImportRequestSerializer();
|
||||
Serializer<ImportRequestMapping> _$importRequestMappingSerializer =
|
||||
new _$ImportRequestMappingSerializer();
|
||||
Serializer<ImportType> _$importTypeSerializer = new _$ImportTypeSerializer();
|
||||
|
||||
class _$PreImportResponseSerializer
|
||||
|
|
@ -187,17 +189,10 @@ class _$ImportRequestSerializer implements StructuredSerializer<ImportRequest> {
|
|||
serializers.serialize(object.columnMap,
|
||||
specifiedType: const FullType(BuiltMap, const [
|
||||
const FullType(String),
|
||||
const FullType(
|
||||
BuiltMap, const [const FullType(int), const FullType(String)])
|
||||
const FullType(ImportRequestMapping)
|
||||
])),
|
||||
];
|
||||
if (object.dummy != null) {
|
||||
result
|
||||
..add('dummy_field')
|
||||
..add(serializers.serialize(object.dummy,
|
||||
specifiedType: const FullType(BuiltMap,
|
||||
const [const FullType(int), const FullType(String)])));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -229,12 +224,54 @@ class _$ImportRequestSerializer implements StructuredSerializer<ImportRequest> {
|
|||
result.columnMap.replace(serializers.deserialize(value,
|
||||
specifiedType: const FullType(BuiltMap, const [
|
||||
const FullType(String),
|
||||
const FullType(BuiltMap,
|
||||
const [const FullType(int), const FullType(String)])
|
||||
const FullType(ImportRequestMapping)
|
||||
])));
|
||||
break;
|
||||
case 'dummy_field':
|
||||
result.dummy.replace(serializers.deserialize(value,
|
||||
}
|
||||
}
|
||||
|
||||
return result.build();
|
||||
}
|
||||
}
|
||||
|
||||
class _$ImportRequestMappingSerializer
|
||||
implements StructuredSerializer<ImportRequestMapping> {
|
||||
@override
|
||||
final Iterable<Type> types = const [
|
||||
ImportRequestMapping,
|
||||
_$ImportRequestMapping
|
||||
];
|
||||
@override
|
||||
final String wireName = 'ImportRequestMapping';
|
||||
|
||||
@override
|
||||
Iterable<Object> serialize(
|
||||
Serializers serializers, ImportRequestMapping object,
|
||||
{FullType specifiedType = FullType.unspecified}) {
|
||||
final result = <Object>[
|
||||
'mapping',
|
||||
serializers.serialize(object.mapping,
|
||||
specifiedType: const FullType(
|
||||
BuiltMap, const [const FullType(int), const FullType(String)])),
|
||||
];
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@override
|
||||
ImportRequestMapping deserialize(
|
||||
Serializers serializers, Iterable<Object> serialized,
|
||||
{FullType specifiedType = FullType.unspecified}) {
|
||||
final result = new ImportRequestMappingBuilder();
|
||||
|
||||
final iterator = serialized.iterator;
|
||||
while (iterator.moveNext()) {
|
||||
final key = iterator.current as String;
|
||||
iterator.moveNext();
|
||||
final Object value = iterator.current;
|
||||
switch (key) {
|
||||
case 'mapping':
|
||||
result.mapping.replace(serializers.deserialize(value,
|
||||
specifiedType: const FullType(BuiltMap,
|
||||
const [const FullType(int), const FullType(String)])));
|
||||
break;
|
||||
|
|
@ -502,15 +539,13 @@ class _$ImportRequest extends ImportRequest {
|
|||
@override
|
||||
final bool skipHeader;
|
||||
@override
|
||||
final BuiltMap<String, BuiltMap<int, String>> columnMap;
|
||||
@override
|
||||
final BuiltMap<int, String> dummy;
|
||||
final BuiltMap<String, ImportRequestMapping> columnMap;
|
||||
|
||||
factory _$ImportRequest([void Function(ImportRequestBuilder) updates]) =>
|
||||
(new ImportRequestBuilder()..update(updates)).build();
|
||||
|
||||
_$ImportRequest._(
|
||||
{this.hash, this.importType, this.skipHeader, this.columnMap, this.dummy})
|
||||
{this.hash, this.importType, this.skipHeader, this.columnMap})
|
||||
: super._() {
|
||||
if (hash == null) {
|
||||
throw new BuiltValueNullFieldError('ImportRequest', 'hash');
|
||||
|
|
@ -540,19 +575,16 @@ class _$ImportRequest extends ImportRequest {
|
|||
hash == other.hash &&
|
||||
importType == other.importType &&
|
||||
skipHeader == other.skipHeader &&
|
||||
columnMap == other.columnMap &&
|
||||
dummy == other.dummy;
|
||||
columnMap == other.columnMap;
|
||||
}
|
||||
|
||||
int __hashCode;
|
||||
@override
|
||||
int get hashCode {
|
||||
return __hashCode ??= $jf($jc(
|
||||
$jc(
|
||||
$jc($jc($jc(0, hash.hashCode), importType.hashCode),
|
||||
skipHeader.hashCode),
|
||||
columnMap.hashCode),
|
||||
dummy.hashCode));
|
||||
$jc($jc($jc(0, hash.hashCode), importType.hashCode),
|
||||
skipHeader.hashCode),
|
||||
columnMap.hashCode));
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -561,8 +593,7 @@ class _$ImportRequest extends ImportRequest {
|
|||
..add('hash', hash)
|
||||
..add('importType', importType)
|
||||
..add('skipHeader', skipHeader)
|
||||
..add('columnMap', columnMap)
|
||||
..add('dummy', dummy))
|
||||
..add('columnMap', columnMap))
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
|
@ -583,26 +614,21 @@ class ImportRequestBuilder
|
|||
bool get skipHeader => _$this._skipHeader;
|
||||
set skipHeader(bool skipHeader) => _$this._skipHeader = skipHeader;
|
||||
|
||||
MapBuilder<String, BuiltMap<int, String>> _columnMap;
|
||||
MapBuilder<String, BuiltMap<int, String>> get columnMap =>
|
||||
_$this._columnMap ??= new MapBuilder<String, BuiltMap<int, String>>();
|
||||
set columnMap(MapBuilder<String, BuiltMap<int, String>> columnMap) =>
|
||||
MapBuilder<String, ImportRequestMapping> _columnMap;
|
||||
MapBuilder<String, ImportRequestMapping> get columnMap =>
|
||||
_$this._columnMap ??= new MapBuilder<String, ImportRequestMapping>();
|
||||
set columnMap(MapBuilder<String, ImportRequestMapping> columnMap) =>
|
||||
_$this._columnMap = columnMap;
|
||||
|
||||
MapBuilder<int, String> _dummy;
|
||||
MapBuilder<int, String> get dummy =>
|
||||
_$this._dummy ??= new MapBuilder<int, String>();
|
||||
set dummy(MapBuilder<int, String> dummy) => _$this._dummy = dummy;
|
||||
|
||||
ImportRequestBuilder();
|
||||
|
||||
ImportRequestBuilder get _$this {
|
||||
if (_$v != null) {
|
||||
_hash = _$v.hash;
|
||||
_importType = _$v.importType;
|
||||
_skipHeader = _$v.skipHeader;
|
||||
_columnMap = _$v.columnMap?.toBuilder();
|
||||
_dummy = _$v.dummy?.toBuilder();
|
||||
final $v = _$v;
|
||||
if ($v != null) {
|
||||
_hash = $v.hash;
|
||||
_importType = $v.importType;
|
||||
_skipHeader = $v.skipHeader;
|
||||
_columnMap = $v.columnMap.toBuilder();
|
||||
_$v = null;
|
||||
}
|
||||
return this;
|
||||
|
|
@ -627,18 +653,18 @@ class ImportRequestBuilder
|
|||
try {
|
||||
_$result = _$v ??
|
||||
new _$ImportRequest._(
|
||||
hash: hash,
|
||||
importType: importType,
|
||||
skipHeader: skipHeader,
|
||||
columnMap: columnMap.build(),
|
||||
dummy: _dummy?.build());
|
||||
hash: BuiltValueNullFieldError.checkNotNull(
|
||||
hash, 'ImportRequest', 'hash'),
|
||||
importType: BuiltValueNullFieldError.checkNotNull(
|
||||
importType, 'ImportRequest', 'importType'),
|
||||
skipHeader: BuiltValueNullFieldError.checkNotNull(
|
||||
skipHeader, 'ImportRequest', 'skipHeader'),
|
||||
columnMap: columnMap.build());
|
||||
} catch (_) {
|
||||
String _$failedField;
|
||||
try {
|
||||
_$failedField = 'columnMap';
|
||||
columnMap.build();
|
||||
_$failedField = 'dummy';
|
||||
_dummy?.build();
|
||||
} catch (e) {
|
||||
throw new BuiltValueNestedFieldError(
|
||||
'ImportRequest', _$failedField, e.toString());
|
||||
|
|
@ -650,4 +676,98 @@ class ImportRequestBuilder
|
|||
}
|
||||
}
|
||||
|
||||
class _$ImportRequestMapping extends ImportRequestMapping {
|
||||
@override
|
||||
final BuiltMap<int, String> mapping;
|
||||
|
||||
factory _$ImportRequestMapping(
|
||||
[void Function(ImportRequestMappingBuilder) updates]) =>
|
||||
(new ImportRequestMappingBuilder()..update(updates)).build();
|
||||
|
||||
_$ImportRequestMapping._({this.mapping}) : super._() {
|
||||
BuiltValueNullFieldError.checkNotNull(
|
||||
mapping, 'ImportRequestMapping', 'mapping');
|
||||
}
|
||||
|
||||
@override
|
||||
ImportRequestMapping rebuild(
|
||||
void Function(ImportRequestMappingBuilder) updates) =>
|
||||
(toBuilder()..update(updates)).build();
|
||||
|
||||
@override
|
||||
ImportRequestMappingBuilder toBuilder() =>
|
||||
new ImportRequestMappingBuilder()..replace(this);
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
if (identical(other, this)) return true;
|
||||
return other is ImportRequestMapping && mapping == other.mapping;
|
||||
}
|
||||
|
||||
int __hashCode;
|
||||
@override
|
||||
int get hashCode {
|
||||
return __hashCode ??= $jf($jc(0, mapping.hashCode));
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return (newBuiltValueToStringHelper('ImportRequestMapping')
|
||||
..add('mapping', mapping))
|
||||
.toString();
|
||||
}
|
||||
}
|
||||
|
||||
class ImportRequestMappingBuilder
|
||||
implements Builder<ImportRequestMapping, ImportRequestMappingBuilder> {
|
||||
_$ImportRequestMapping _$v;
|
||||
|
||||
MapBuilder<int, String> _mapping;
|
||||
MapBuilder<int, String> get mapping =>
|
||||
_$this._mapping ??= new MapBuilder<int, String>();
|
||||
set mapping(MapBuilder<int, String> mapping) => _$this._mapping = mapping;
|
||||
|
||||
ImportRequestMappingBuilder();
|
||||
|
||||
ImportRequestMappingBuilder get _$this {
|
||||
final $v = _$v;
|
||||
if ($v != null) {
|
||||
_mapping = $v.mapping.toBuilder();
|
||||
_$v = null;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@override
|
||||
void replace(ImportRequestMapping other) {
|
||||
ArgumentError.checkNotNull(other, 'other');
|
||||
_$v = other as _$ImportRequestMapping;
|
||||
}
|
||||
|
||||
@override
|
||||
void update(void Function(ImportRequestMappingBuilder) updates) {
|
||||
if (updates != null) updates(this);
|
||||
}
|
||||
|
||||
@override
|
||||
_$ImportRequestMapping build() {
|
||||
_$ImportRequestMapping _$result;
|
||||
try {
|
||||
_$result = _$v ?? new _$ImportRequestMapping._(mapping: mapping.build());
|
||||
} catch (_) {
|
||||
String _$failedField;
|
||||
try {
|
||||
_$failedField = 'mapping';
|
||||
mapping.build();
|
||||
} catch (e) {
|
||||
throw new BuiltValueNestedFieldError(
|
||||
'ImportRequestMapping', _$failedField, e.toString());
|
||||
}
|
||||
rethrow;
|
||||
}
|
||||
replace(_$result);
|
||||
return _$result;
|
||||
}
|
||||
}
|
||||
|
||||
// ignore_for_file: always_put_control_body_on_new_line,always_specify_types,annotate_overrides,avoid_annotating_with_dynamic,avoid_as,avoid_catches_without_on_clauses,avoid_returning_this,lines_longer_than_80_chars,omit_local_variable_types,prefer_expression_function_bodies,sort_constructors_first,test_types_in_equals,unnecessary_const,unnecessary_new
|
||||
|
|
|
|||
|
|
@ -162,6 +162,7 @@ part 'serializers.g.dart';
|
|||
SystemLogEntity,
|
||||
PreImportResponse,
|
||||
ImportRequest,
|
||||
ImportRequestMapping,
|
||||
])
|
||||
final Serializers serializers =
|
||||
(_$serializers.toBuilder()..addPlugin(StandardJsonPlugin())).build();
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@ Serializers _$serializers = (new Serializers().toBuilder()
|
|||
..add(HealthCheckResponse.serializer)
|
||||
..add(HistoryRecord.serializer)
|
||||
..add(ImportRequest.serializer)
|
||||
..add(ImportRequestMapping.serializer)
|
||||
..add(IndustryEntity.serializer)
|
||||
..add(IndustryItemResponse.serializer)
|
||||
..add(IndustryListResponse.serializer)
|
||||
|
|
@ -523,6 +524,7 @@ Serializers _$serializers = (new Serializers().toBuilder()
|
|||
..addBuilderFactory(const FullType(BuiltMap, const [const FullType(String), const FullType(GatewayOptionsEntity)]), () => new MapBuilder<String, GatewayOptionsEntity>())
|
||||
..addBuilderFactory(const FullType(BuiltMap, const [const FullType(String), const FullType(GroupEntity)]), () => new MapBuilder<String, GroupEntity>())
|
||||
..addBuilderFactory(const FullType(BuiltList, const [const FullType(String)]), () => new ListBuilder<String>())
|
||||
..addBuilderFactory(const FullType(BuiltMap, const [const FullType(String), const FullType(ImportRequestMapping)]), () => new MapBuilder<String, ImportRequestMapping>())
|
||||
..addBuilderFactory(const FullType(BuiltMap, const [const FullType(String), const FullType(InvoiceEntity)]), () => new MapBuilder<String, InvoiceEntity>())
|
||||
..addBuilderFactory(const FullType(BuiltList, const [const FullType(String)]), () => new ListBuilder<String>())
|
||||
..addBuilderFactory(const FullType(BuiltMap, const [const FullType(String), const FullType(InvoiceEntity)]), () => new MapBuilder<String, InvoiceEntity>())
|
||||
|
|
|
|||
|
|
@ -400,11 +400,10 @@ class __FileMapperState extends State<_FileMapper> {
|
|||
final state = StoreProvider.of<AppState>(context).state;
|
||||
final credentials = state.credentials;
|
||||
final url = '${credentials.url}/import';
|
||||
final convertedMapping = <String, BuiltMap<int, String>>{};
|
||||
final convertedMapping=<String,ImportRequestMapping>{};
|
||||
|
||||
for (MapEntry<String, Map<int, String>> e
|
||||
in _mapping.entries) {
|
||||
convertedMapping[e.key] = BuiltMap(e.value);
|
||||
for(MapEntry<String,Map<int,String>> e in _mapping.entries){
|
||||
convertedMapping[e.key] = new ImportRequestMapping(BuiltMap(e.value));
|
||||
}
|
||||
|
||||
setState(() => _isLoading = true);
|
||||
|
|
|
|||
Loading…
Reference in New Issue