From f6d785bcd6ef7ff71e143379c95789dcbb364ccb Mon Sep 17 00:00:00 2001 From: jld3103 Date: Mon, 31 Jul 2023 13:26:21 +0200 Subject: [PATCH] refactor(nextcloud): Rename WebDAV prop without values --- packages/nextcloud/bin/generate_props.dart | 2 +- packages/nextcloud/lib/src/webdav/client.dart | 8 +++--- packages/nextcloud/lib/src/webdav/props.dart | 9 ++++--- .../nextcloud/lib/src/webdav/props.g.dart | 27 ++++++++++--------- packages/nextcloud/lib/src/webdav/webdav.dart | 4 +-- .../nextcloud/lib/src/webdav/webdav.g.dart | 4 +-- packages/nextcloud/test/webdav_test.dart | 14 +++++----- 7 files changed, 35 insertions(+), 33 deletions(-) diff --git a/packages/nextcloud/bin/generate_props.dart b/packages/nextcloud/bin/generate_props.dart index cec196e0..35c79e82 100644 --- a/packages/nextcloud/bin/generate_props.dart +++ b/packages/nextcloud/bin/generate_props.dart @@ -29,7 +29,7 @@ void main() { "part 'props.g.dart';", '', ...generateClass( - 'WebDavPropfindProp', + 'WebDavPropWithoutValues', 'prop', 'namespaceDav', findProps, diff --git a/packages/nextcloud/lib/src/webdav/client.dart b/packages/nextcloud/lib/src/webdav/client.dart index 0d9eea6c..40c407f4 100644 --- a/packages/nextcloud/lib/src/webdav/client.dart +++ b/packages/nextcloud/lib/src/webdav/client.dart @@ -204,7 +204,7 @@ class WebDavClient { /// See http://www.webdav.org/specs/rfc2518.html#METHOD_PROPFIND for more information. Future propfind( final String path, { - final WebDavPropfindProp? prop, + final WebDavPropWithoutValues? prop, final String? depth, }) async { assert(depth == null || ['0', '1', 'infinity'].contains(depth), 'Depth has to be 0, 1 or infinity'); @@ -215,7 +215,7 @@ class WebDavClient { data: Stream.value( Uint8List.fromList( utf8.encode( - WebDavPropfind(prop: prop ?? WebDavPropfindProp()).toXmlElement(namespaces: namespaces).toXmlString(), + WebDavPropfind(prop: prop ?? WebDavPropWithoutValues()).toXmlElement(namespaces: namespaces).toXmlString(), ), ), ), @@ -244,7 +244,7 @@ class WebDavClient { Future report( final String path, final WebDavOcFilterRules filterRules, { - final WebDavPropfindProp? prop, + final WebDavPropWithoutValues? prop, }) async => _parseResponse( await _send( @@ -256,7 +256,7 @@ class WebDavClient { utf8.encode( WebDavOcFilterFiles( filterRules: filterRules, - prop: prop ?? WebDavPropfindProp(), // coverage:ignore-line + prop: prop ?? WebDavPropWithoutValues(), // coverage:ignore-line ).toXmlElement(namespaces: namespaces).toXmlString(), ), ), diff --git a/packages/nextcloud/lib/src/webdav/props.dart b/packages/nextcloud/lib/src/webdav/props.dart index e35e9506..0346fc28 100644 --- a/packages/nextcloud/lib/src/webdav/props.dart +++ b/packages/nextcloud/lib/src/webdav/props.dart @@ -7,8 +7,8 @@ part 'props.g.dart'; @annotation.XmlSerializable(createMixin: true) @annotation.XmlRootElement(name: 'prop', namespace: namespaceDav) -class WebDavPropfindProp with _$WebDavPropfindPropXmlSerializableMixin { - WebDavPropfindProp({ +class WebDavPropWithoutValues with _$WebDavPropWithoutValuesXmlSerializableMixin { + WebDavPropWithoutValues({ this.davgetlastmodified, this.davgetetag, this.davgetcontenttype, @@ -38,7 +38,7 @@ class WebDavPropfindProp with _$WebDavPropfindPropXmlSerializableMixin { this.ocmsharepermissions, }); - WebDavPropfindProp.fromBools({ + WebDavPropWithoutValues.fromBools({ final bool davgetlastmodified = false, final bool davgetetag = false, final bool davgetcontenttype = false, @@ -94,7 +94,8 @@ class WebDavPropfindProp with _$WebDavPropfindPropXmlSerializableMixin { ocssharepermissions = ocssharepermissions ? [null] : null, ocmsharepermissions = ocmsharepermissions ? [null] : null; - factory WebDavPropfindProp.fromXmlElement(final XmlElement element) => _$WebDavPropfindPropFromXmlElement(element); + factory WebDavPropWithoutValues.fromXmlElement(final XmlElement element) => + _$WebDavPropWithoutValuesFromXmlElement(element); @annotation.XmlElement( name: 'getlastmodified', diff --git a/packages/nextcloud/lib/src/webdav/props.g.dart b/packages/nextcloud/lib/src/webdav/props.g.dart index 3e842c96..b1d201a7 100644 --- a/packages/nextcloud/lib/src/webdav/props.g.dart +++ b/packages/nextcloud/lib/src/webdav/props.g.dart @@ -6,7 +6,7 @@ part of 'props.dart'; // XmlSerializableGenerator // ************************************************************************** -void _$WebDavPropfindPropBuildXmlChildren(WebDavPropfindProp instance, XmlBuilder builder, +void _$WebDavPropWithoutValuesBuildXmlChildren(WebDavPropWithoutValues instance, XmlBuilder builder, {Map namespaces = const {}}) { final davgetlastmodified = instance.davgetlastmodified; final davgetlastmodifiedSerialized = davgetlastmodified; @@ -308,14 +308,14 @@ void _$WebDavPropfindPropBuildXmlChildren(WebDavPropfindProp instance, XmlBuilde } } -void _$WebDavPropfindPropBuildXmlElement(WebDavPropfindProp instance, XmlBuilder builder, +void _$WebDavPropWithoutValuesBuildXmlElement(WebDavPropWithoutValues instance, XmlBuilder builder, {Map namespaces = const {}}) { builder.element('prop', namespace: 'DAV:', namespaces: namespaces, nest: () { instance.buildXmlChildren(builder, namespaces: namespaces); }); } -WebDavPropfindProp _$WebDavPropfindPropFromXmlElement(XmlElement element) { +WebDavPropWithoutValues _$WebDavPropWithoutValuesFromXmlElement(XmlElement element) { final davgetlastmodified = element.getElements('getlastmodified', namespace: 'DAV:')?.map((e) => e.getText()).whereType(); final davgetetag = element.getElements('getetag', namespace: 'DAV:')?.map((e) => e.getText()).whereType(); @@ -401,7 +401,7 @@ WebDavPropfindProp _$WebDavPropfindPropFromXmlElement(XmlElement element) { .getElements('share-permissions', namespace: 'http://open-cloud-mesh.org/ns') ?.map((e) => e.getText()) .whereType(); - return WebDavPropfindProp( + return WebDavPropWithoutValues( davgetlastmodified: davgetlastmodified?.toList(), davgetetag: davgetetag?.toList(), davgetcontenttype: davgetcontenttype?.toList(), @@ -431,13 +431,13 @@ WebDavPropfindProp _$WebDavPropfindPropFromXmlElement(XmlElement element) { ocmsharepermissions: ocmsharepermissions?.toList()); } -List _$WebDavPropfindPropToXmlAttributes(WebDavPropfindProp instance, +List _$WebDavPropWithoutValuesToXmlAttributes(WebDavPropWithoutValues instance, {Map namespaces = const {}}) { final attributes = []; return attributes; } -List _$WebDavPropfindPropToXmlChildren(WebDavPropfindProp instance, +List _$WebDavPropWithoutValuesToXmlChildren(WebDavPropWithoutValues instance, {Map namespaces = const {}}) { final children = []; final davgetlastmodified = instance.davgetlastmodified; @@ -638,28 +638,29 @@ List _$WebDavPropfindPropToXmlChildren(WebDavPropfindProp instance, return children; } -XmlElement _$WebDavPropfindPropToXmlElement(WebDavPropfindProp instance, {Map namespaces = const {}}) { +XmlElement _$WebDavPropWithoutValuesToXmlElement(WebDavPropWithoutValues instance, + {Map namespaces = const {}}) { return XmlElement( XmlName('prop', namespaces['DAV:']), [...namespaces.toXmlAttributes(), ...instance.toXmlAttributes(namespaces: namespaces)], instance.toXmlChildren(namespaces: namespaces)); } -mixin _$WebDavPropfindPropXmlSerializableMixin { +mixin _$WebDavPropWithoutValuesXmlSerializableMixin { void buildXmlChildren(XmlBuilder builder, {Map namespaces = const {}}) => - _$WebDavPropfindPropBuildXmlChildren(this as WebDavPropfindProp, builder, namespaces: namespaces); + _$WebDavPropWithoutValuesBuildXmlChildren(this as WebDavPropWithoutValues, builder, namespaces: namespaces); void buildXmlElement(XmlBuilder builder, {Map namespaces = const {}}) => - _$WebDavPropfindPropBuildXmlElement(this as WebDavPropfindProp, builder, namespaces: namespaces); + _$WebDavPropWithoutValuesBuildXmlElement(this as WebDavPropWithoutValues, builder, namespaces: namespaces); List toXmlAttributes({Map namespaces = const {}}) => - _$WebDavPropfindPropToXmlAttributes(this as WebDavPropfindProp, namespaces: namespaces); + _$WebDavPropWithoutValuesToXmlAttributes(this as WebDavPropWithoutValues, namespaces: namespaces); List toXmlChildren({Map namespaces = const {}}) => - _$WebDavPropfindPropToXmlChildren(this as WebDavPropfindProp, namespaces: namespaces); + _$WebDavPropWithoutValuesToXmlChildren(this as WebDavPropWithoutValues, namespaces: namespaces); XmlElement toXmlElement({Map namespaces = const {}}) => - _$WebDavPropfindPropToXmlElement(this as WebDavPropfindProp, namespaces: namespaces); + _$WebDavPropWithoutValuesToXmlElement(this as WebDavPropWithoutValues, namespaces: namespaces); } void _$WebDavPropBuildXmlChildren(WebDavProp instance, XmlBuilder builder, diff --git a/packages/nextcloud/lib/src/webdav/webdav.dart b/packages/nextcloud/lib/src/webdav/webdav.dart index 981c520b..68ccc9b7 100644 --- a/packages/nextcloud/lib/src/webdav/webdav.dart +++ b/packages/nextcloud/lib/src/webdav/webdav.dart @@ -104,7 +104,7 @@ class WebDavPropfind with _$WebDavPropfindXmlSerializableMixin { }); @annotation.XmlElement(name: 'prop', namespace: namespaceDav) - final WebDavPropfindProp prop; + final WebDavPropWithoutValues prop; } @annotation.XmlSerializable(createMixin: true) @@ -119,7 +119,7 @@ class WebDavOcFilterFiles with _$WebDavOcFilterFilesXmlSerializableMixin { final WebDavOcFilterRules filterRules; @annotation.XmlElement(name: 'prop', namespace: namespaceDav) - final WebDavPropfindProp prop; + final WebDavPropWithoutValues prop; } @annotation.XmlSerializable(createMixin: true) diff --git a/packages/nextcloud/lib/src/webdav/webdav.g.dart b/packages/nextcloud/lib/src/webdav/webdav.g.dart index 1007981f..2e48e19e 100644 --- a/packages/nextcloud/lib/src/webdav/webdav.g.dart +++ b/packages/nextcloud/lib/src/webdav/webdav.g.dart @@ -356,7 +356,7 @@ void _$WebDavPropfindBuildXmlElement(WebDavPropfind instance, XmlBuilder builder WebDavPropfind _$WebDavPropfindFromXmlElement(XmlElement element) { final prop = element.getElement('prop', namespace: 'DAV:')!; - return WebDavPropfind(prop: WebDavPropfindProp.fromXmlElement(prop)); + return WebDavPropfind(prop: WebDavPropWithoutValues.fromXmlElement(prop)); } List _$WebDavPropfindToXmlAttributes(WebDavPropfind instance, @@ -424,7 +424,7 @@ WebDavOcFilterFiles _$WebDavOcFilterFilesFromXmlElement(XmlElement element) { final filterRules = element.getElement('filter-rules', namespace: 'http://owncloud.org/ns')!; final prop = element.getElement('prop', namespace: 'DAV:')!; return WebDavOcFilterFiles( - filterRules: WebDavOcFilterRules.fromXmlElement(filterRules), prop: WebDavPropfindProp.fromXmlElement(prop)); + filterRules: WebDavOcFilterRules.fromXmlElement(filterRules), prop: WebDavPropWithoutValues.fromXmlElement(prop)); } List _$WebDavOcFilterFilesToXmlAttributes(WebDavOcFilterFiles instance, diff --git a/packages/nextcloud/test/webdav_test.dart b/packages/nextcloud/test/webdav_test.dart index 3762c8b9..56f540e9 100644 --- a/packages/nextcloud/test/webdav_test.dart +++ b/packages/nextcloud/test/webdav_test.dart @@ -32,7 +32,7 @@ void main() { test('List directory', () async { final responses = (await client.webdav.propfind( '/', - prop: WebDavPropfindProp.fromBools( + prop: WebDavPropWithoutValues.fromBools( nchaspreview: true, davgetcontenttype: true, davgetlastmodified: true, @@ -75,7 +75,7 @@ void main() { final responses = (await client.webdav.propfind( '/', - prop: WebDavPropfindProp.fromBools( + prop: WebDavPropWithoutValues.fromBools( ocsize: true, ), )) @@ -106,7 +106,7 @@ void main() { final props = (await client.webdav.propfind( '/', - prop: WebDavPropfindProp.fromBools( + prop: WebDavPropWithoutValues.fromBools( davgetlastmodified: true, nccreationtime: true, ), @@ -207,7 +207,7 @@ void main() { test('Get file props', () async { final response = (await client.webdav.propfind( 'Nextcloud.png', - prop: WebDavPropfindProp.fromBools( + prop: WebDavPropWithoutValues.fromBools( davgetlastmodified: true, davgetetag: true, davgetcontenttype: true, @@ -294,7 +294,7 @@ void main() { final response = (await client.webdav.propfind( 'test', - prop: WebDavPropfindProp.fromBools( + prop: WebDavPropWithoutValues.fromBools( davgetcontenttype: true, davgetlastmodified: true, davresourcetype: true, @@ -334,7 +334,7 @@ void main() { WebDavOcFilterRules( ocfavorite: 1, ), - prop: WebDavPropfindProp.fromBools( + prop: WebDavPropWithoutValues.fromBools( ocid: true, ocfavorite: true, ), @@ -365,7 +365,7 @@ void main() { final props = (await client.webdav.propfind( 'test.txt', - prop: WebDavPropfindProp.fromBools( + prop: WebDavPropWithoutValues.fromBools( ocfavorite: true, nccreationtime: true, ncuploadtime: true,