Skip to content

Commit

Permalink
Refactoring Documents model
Browse files Browse the repository at this point in the history
* Complete documents feed extensions
* Modify changestamp type to int
  • Loading branch information
astrada committed May 5, 2012
1 parent 2d778e5 commit df30630
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 50 deletions.
110 changes: 73 additions & 37 deletions src/gdata/gdataDocumentsV3Model.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@ open GapiUtils.Infix
(* Document data types *)
let ns_docs = "http://schemas.google.com/docs/2007"

(* TODO:
* fix GdataExtensions.FeedLink
* move to GdataExtensions all elements not in atom namespace
*)

module AclFeedLink = GdataExtensions.MakeFeedLink(GdataACL.Feed)

module Revision =
Expand All @@ -25,7 +20,7 @@ struct
publish : bool;
publishAuto : bool;
publishOutsideDomain : bool;
extensions : GdataCore.xml_data_model list
extensions : GdataAtom.GenericExtensions.t
}

let empty = {
Expand All @@ -39,7 +34,7 @@ struct
publish = false;
publishAuto = false;
publishOutsideDomain = false;
extensions = []
extensions = GdataAtom.GenericExtensions.empty
}

let to_xml_data_model entry =
Expand All @@ -54,7 +49,7 @@ struct
GdataAtom.render_bool_value ns_docs "publish" entry.publish;
GdataAtom.render_bool_value ns_docs "publishAuto" entry.publishAuto;
GdataAtom.render_bool_value ns_docs "publishOutsideDomain" entry.publishOutsideDomain;
entry.extensions]
GdataAtom.GenericExtensions.to_xml_data_model entry.extensions]

let of_xml_data_model entry tree =
match tree with
Expand Down Expand Up @@ -133,7 +128,11 @@ struct
_) when ns = Xmlm.ns_xmlns ->
entry
| extension ->
let extensions = extension :: entry.extensions in
let extensions =
GdataAtom.GenericExtensions.of_xml_data_model
entry.extensions
extension
in
{ entry with extensions }

end
Expand Down Expand Up @@ -175,9 +174,9 @@ struct
(* change entry data *)
deleted : bool;
removed : bool;
changestamp : string;
changestamp : int;

extensions : GdataCore.xml_data_model list
extensions : GdataAtom.GenericExtensions.t
}

let empty = {
Expand All @@ -204,8 +203,8 @@ struct
suggestedFilename = "";
removed = false;
deleted = false;
changestamp = "";
extensions = []
changestamp = 0;
extensions = GdataAtom.GenericExtensions.empty
}

let to_xml_data_model entry =
Expand Down Expand Up @@ -233,8 +232,8 @@ struct
GdataAtom.render_text_element ns_docs "suggestedFilename" entry.suggestedFilename;
GdataAtom.render_bool_empty_element ns_docs "removed" entry.removed;
GdataAtom.render_bool_empty_element ns_docs "deleted" entry.deleted;
GdataAtom.render_value ns_docs "changestamp" entry.changestamp;
entry.extensions]
GdataAtom.render_int_value ns_docs "changestamp" entry.changestamp;
GdataAtom.GenericExtensions.to_xml_data_model entry.extensions]

let of_xml_data_model entry tree =
match tree with
Expand Down Expand Up @@ -392,43 +391,76 @@ struct
[GapiCore.AnnotatedTree.Leaf
([`Attribute; `Name "value"; `Namespace ""],
v)]) when ns = ns_docs ->
{ entry with changestamp = v }
{ entry with changestamp = int_of_string v }
| GapiCore.AnnotatedTree.Leaf
([`Attribute; `Name _; `Namespace ns],
_) when ns = Xmlm.ns_xmlns ->
entry
| extension ->
let extensions = extension :: entry.extensions in
let extensions =
GdataAtom.GenericExtensions.of_xml_data_model
entry.extensions
extension
in
{ entry with extensions }

end

module DocumentFeedExtensions =
struct
type t = {
largestChangestamp : string;
extensions : GdataCore.xml_data_model list;
quotaBytesTotal : int64;
quotaBytesUsed : int64;
quotaBytesUsedInTrash : int64;
largestChangestamp : int;
extensions : GdataAtom.GenericExtensions.t;
}

let empty = {
largestChangestamp = "";
extensions = [];
quotaBytesTotal = 0L;
quotaBytesUsed = 0L;
quotaBytesUsedInTrash = 0L;
largestChangestamp = 0;
extensions = GdataAtom.GenericExtensions.empty;
}

let to_xml_data_model ext =
GdataAtom.render_value ns_docs "largestChangestamp" ext.largestChangestamp @
ext.extensions
List.concat
[GdataAtom.render_int64_element GdataAtom.ns_gd "quotaBytesTotal" ext.quotaBytesTotal;
GdataAtom.render_int64_element GdataAtom.ns_gd "quotaBytesUsed" ext.quotaBytesUsed;
GdataAtom.render_int64_element ns_docs "quotaBytesUsedInTrash" ext.quotaBytesUsedInTrash;
GdataAtom.render_int_value ns_docs "largestChangestamp" ext.largestChangestamp;
GdataAtom.GenericExtensions.to_xml_data_model ext.extensions]

let of_xml_data_model ext tree =
match tree with
GapiCore.AnnotatedTree.Node
([`Element; `Name "quotaBytesTotal"; `Namespace ns],
[GapiCore.AnnotatedTree.Leaf
([`Text], v)]) when ns = GdataAtom.ns_gd ->
{ ext with quotaBytesTotal = Int64.of_string v }
| GapiCore.AnnotatedTree.Node
([`Element; `Name "quotaBytesUsed"; `Namespace ns],
[GapiCore.AnnotatedTree.Leaf
([`Text], v)]) when ns = GdataAtom.ns_gd ->
{ ext with quotaBytesUsed = Int64.of_string v }
| GapiCore.AnnotatedTree.Node
([`Element; `Name "quotaBytesUsedInTrash"; `Namespace ns],
[GapiCore.AnnotatedTree.Leaf
([`Text], v)]) when ns = ns_docs ->
{ ext with quotaBytesUsedInTrash = Int64.of_string v }
| GapiCore.AnnotatedTree.Node
([`Element; `Name "largestChangestamp"; `Namespace ns],
[GapiCore.AnnotatedTree.Leaf
([`Attribute; `Name "value"; `Namespace ""],
v)]) when ns = ns_docs ->
{ ext with largestChangestamp = v }
{ ext with largestChangestamp = int_of_string v }
| extension ->
let extensions = extension :: ext.extensions in
let extensions =
GdataAtom.GenericExtensions.of_xml_data_model
ext.extensions
extension
in
{ ext with extensions }

end
Expand Down Expand Up @@ -671,8 +703,8 @@ struct
title : GdataAtom.Title.t;
links : GdataAtom.Link.t list;
authors : GdataAtom.Author.t list;
largestChangestamp : string;
remainingChangestamps : string;
largestChangestamp : int;
remainingChangestamps : int;
quotaBytesTotal : int64;
quotaBytesUsed : int64;
quotaBytesUsedInTrash : int64;
Expand All @@ -682,7 +714,7 @@ struct
features : Feature.t list;
maxUploadSizes : MaxUploadSize.t list;
additionalRoleInfos : AdditionalRoleInfo.t list;
extensions : GdataCore.xml_data_model list
extensions : GdataAtom.GenericExtensions.t
}

let empty = {
Expand All @@ -693,8 +725,8 @@ struct
title = GdataAtom.Title.empty;
links = [];
authors = [];
largestChangestamp = "";
remainingChangestamps = "";
largestChangestamp = 0;
remainingChangestamps = 0;
quotaBytesTotal = 0L;
quotaBytesUsed = 0L;
quotaBytesUsedInTrash = 0L;
Expand All @@ -704,7 +736,7 @@ struct
features = [];
maxUploadSizes = [];
additionalRoleInfos = [];
extensions = []
extensions = GdataAtom.GenericExtensions.empty
}

let to_xml_data_model entry =
Expand All @@ -716,8 +748,8 @@ struct
GdataAtom.Title.to_xml_data_model entry.title;
GdataAtom.render_element_list GdataAtom.Link.to_xml_data_model entry.links;
GdataAtom.render_element_list GdataAtom.Author.to_xml_data_model entry.authors;
GdataAtom.render_text_element ns_docs "largestChangestamp" entry.largestChangestamp;
GdataAtom.render_text_element ns_docs "remainingChangestamps" entry.remainingChangestamps;
GdataAtom.render_int_element ns_docs "largestChangestamp" entry.largestChangestamp;
GdataAtom.render_int_element ns_docs "remainingChangestamps" entry.remainingChangestamps;
GdataAtom.render_int64_element GdataAtom.ns_gd "quotaBytesTotal" entry.quotaBytesTotal;
GdataAtom.render_int64_element GdataAtom.ns_gd "quotaBytesUsed" entry.quotaBytesUsed;
GdataAtom.render_int64_element ns_docs "quotaBytesUsedInTrash" entry.quotaBytesUsedInTrash;
Expand All @@ -727,7 +759,7 @@ struct
GdataAtom.render_element_list Feature.to_xml_data_model entry.features;
GdataAtom.render_element_list MaxUploadSize.to_xml_data_model entry.maxUploadSizes;
GdataAtom.render_element_list AdditionalRoleInfo.to_xml_data_model entry.additionalRoleInfos;
entry.extensions]
GdataAtom.GenericExtensions.to_xml_data_model entry.extensions]

let of_xml_data_model entry tree =
match tree with
Expand Down Expand Up @@ -782,13 +814,13 @@ struct
[GapiCore.AnnotatedTree.Leaf
([`Attribute; `Name "value"; `Namespace ""],
v)]) when ns = ns_docs ->
{ entry with largestChangestamp = v }
{ entry with largestChangestamp = int_of_string v }
| GapiCore.AnnotatedTree.Node
([`Element; `Name "remainingChangestamps"; `Namespace ns],
[GapiCore.AnnotatedTree.Leaf
([`Attribute; `Name "value"; `Namespace ""],
v)]) when ns = ns_docs ->
{ entry with remainingChangestamps = v }
{ entry with remainingChangestamps = int_of_string v }
| GapiCore.AnnotatedTree.Node
([`Element; `Name "quotaBytesTotal"; `Namespace ns],
[GapiCore.AnnotatedTree.Leaf
Expand Down Expand Up @@ -854,7 +886,11 @@ struct
_) when ns = Xmlm.ns_xmlns ->
entry
| extension ->
let extensions = extension :: entry.extensions in
let extensions =
GdataAtom.GenericExtensions.of_xml_data_model
entry.extensions
extension
in
{ entry with extensions }

end
Expand Down
2 changes: 1 addition & 1 deletion src/test/testDocumentsV3Model.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let test_parse_changes_feed () =
"test_data/test_parse_changes_feed.xml"
(GdataUtils.data_to_xml_string tree);
assert_equal
"5635"
5635
(Document.get_largest_changestamp feed)

let test_parse_revisions_feed () =
Expand Down
12 changes: 6 additions & 6 deletions src/test/testDocumentsV3Service.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ let test_get_remaining_changestamps () =
let (entry, session) = get_user_metadata
~url:"https://docs.google.com/feeds/metadata/default?remaining-changestamps-first=1&remaining-changestamps-limit=100"
session in
TestHelper.assert_not_empty
"docs:remainingChangestamps should not be empty"
entry.Metadata.Entry.remainingChangestamps;
assert_bool
"docs:remainingChangestamps should be greater than 0"
(entry.Metadata.Entry.remainingChangestamps > 0);
TestHelper.assert_not_empty
"ETag should not be empty"
session.GapiConversation.Session.etag)
Expand Down Expand Up @@ -94,9 +94,9 @@ let suite = "Documents List v3 Service test" >:::
[(*"test_all_documents" >:: test_all_documents;
"test_resumable_upload" >:: test_resumable_upload;
"test_get_user_metadata" >:: test_get_user_metadata;
"test_get_remaining_changestamps" >:: test_get_remaining_changestamps;
"test_all_changes" >:: test_all_changes;*)
"test_get_revisions" >:: test_get_revisions;
"test_get_remaining_changestamps" >:: test_get_remaining_changestamps;*)
"test_all_changes" >:: test_all_changes;
(*"test_get_revisions" >:: test_get_revisions;*)

]

4 changes: 2 additions & 2 deletions test_data/test_documents_changes_feed.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/"
xmlns:docs="http://schemas.google.com/docs/2007" xmlns:gd="http://schemas.google.com/g/2005"
xmlns:app="http://www.w3.org/2007/app" gd:etag="W/&quot;DEEMQ3w8eyt7ImA9WhZUGUo.&quot;">
gd:etag="W/&quot;DEEMQ3w8eyt7ImA9WhZUGUo.&quot;">
<id>https://docs.google.com/feeds/default/private/changes</id>
<updated>2011-06-13T14:51:22.000Z</updated>
<category scheme="http://schemas.google.com/g/2005#kind"
Expand Down Expand Up @@ -85,7 +85,7 @@
<id>https://docs.google.com/feeds/id/document%3A1DJ1Qrt_N41aX1nDxxo0QHs5XIM90zTT-seYG2FYxrRk</id>
<published>2011-06-13T15:05:37.544Z</published>
<updated>2011-06-13T15:05:38.108Z</updated>
<app:edited>2011-06-13T15:05:38.456Z</app:edited>
<app:edited xmlns:app="http://www.w3.org/2007/app">2011-06-13T15:05:38.456Z</app:edited>
<category scheme="http://schemas.google.com/g/2005#kind"
term="http://schemas.google.com/docs/2007#document" label="document"/>
<category scheme="http://schemas.google.com/g/2005/labels"
Expand Down
7 changes: 3 additions & 4 deletions test_data/test_documents_feed.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/"
xmlns:docs="http://schemas.google.com/docs/2007" xmlns:batch="http://schemas.google.com/gdata/batch"
xmlns:gd="http://schemas.google.com/g/2005" xmlns:app="http://www.w3.org/2007/app"
gd:etag="W/&quot;DUMFR3YyfCt7ImA9WxNTFU0.&quot;">
xmlns:gd="http://schemas.google.com/g/2005" gd:etag="W/&quot;DUMFR3YyfCt7ImA9WxNTFU0.&quot;">

<!-- Unique identifier of this feed. Not unique between users. -->
<id>https://docs.google.com/feeds/default/private/full</id>
Expand Down Expand Up @@ -77,7 +76,7 @@
<updated>2009-07-29T20:31:39.000Z</updated>

<!-- Date this document was last edited by a user in the document editor in a web browser. -->
<app:edited>2009-07-31T17:21:26.000Z</app:edited>
<app:edited xmlns:app="http://www.w3.org/2007/app">2009-07-31T17:21:26.000Z</app:edited>

<!-- Information about the user who last modified this entry (not necessarily the user authorizing this request). -->
<gd:lastModifiedBy>
Expand Down Expand Up @@ -154,7 +153,7 @@
<id>https://docs.google.com/feeds/id/pdf%3A12345</id>
<published>2009-04-09T18:23:09.000Z</published>
<updated>2009-04-09T18:23:09.000Z</updated>
<app:edited>2009-06-18T22:16:02.000Z</app:edited>
<app:edited xmlns:app="http://www.w3.org/2007/app">2009-06-18T22:16:02.000Z</app:edited>
<category scheme="http://schemas.google.com/g/2005/labels" term="http://schemas.google.com/g/2005/labels#starred" label="starred"/>
<category scheme="http://schemas.google.com/g/2005/labels" term="http://schemas.google.com/g/2005/labels#viewed" label="viewed"/>
<category scheme="http://schemas.google.com/g/2005/labels" term="http://schemas.google.com/g/2005/labels#hidden" label="hidden"/>
Expand Down

0 comments on commit df30630

Please sign in to comment.