[[BackLinksMenu]]

[[TicketQuery(summary=ANNOTATIONS_EXPORT_IMPORT_R1, format=table, col=summary|owner|status|type|component|priority|effort|importance, rows=description|analysis_owners|analysis_reviewers|analysis_score|design_owners|design_reviewers|design_score|implementation_owners|implementation_reviewers|implementation_score|test_owners|test_reviewers|test_score|)]]

= Analysis =

== Overview ==
The goal of this task is to provide persistence of stickies.

== Task requirements ==
 * The user should be able to persist annotation sets.

 * Annotation sets are resources which can contain stickies, highlights and audio annotations. Currently only stickies are implemented.

 * Annotation sets should be persisted in zip files, just like Sophie books are saved (which are resources too).

 * "All annotations" palette should contain the following buttons:
  * Import Annotations...
   * When clicked, a file dialog for zip files is opened.
   * If the file is not a valid annotation set, an error message is displayed ("Invalid file.").
   * If the annotation set does not refer to current book, an error message is displayed ("These annotations does not refer current book").
   * The annotation set is loaded in current book's window (not added in the book).
   * The annotation set is set as current for current book.
  * Export Annotations...
   * When clicked, a file dialog for zip files is opened.
   * If a file name is selected, current annotation set for current book is stored in the selected file.
   * If an error occurs, for example user wants to save on read-only media, an error message is displayed.

== Task result ==
 * Source code.

== Implementation idea ==
 * Create a {{{FileDialogInput}}} for zip files and use the {{{DialogManager}}} to display the dialog.

 * Create a persister between {{{AnnotationSet}}} and {{{Storage}}}.
 * Use {{{ZipPackagePersister}}} to persist between {{{Storage}}} and zip files.

== Related ==
[wiki:GROUP_ANNOTATIONS_R0]

== How to demo ==
 * Open Sophie.
 * Create two stickies.
 * Save the annotation set to a file.
 * Close the annotation set (using the Close Extra button). The stickies should disappear.
 * Open the annotation set from a file and check if the stickies are displayed again.

= Design =
 * Create a package {{{org.sophie2.extra.func.annotations.persistence}}}.

 * Create a class {{{AnnotationsPersister}}} that extends {{{Persister<String, Storage>}}}.
  * Schema: "resource:annotation-set|storage|r3"

 * In {{{AnnotationsLogic}}}:
  * Loading annotations:
   * Create a new {{{FileDialogInput}}} for zip files and display it using the {{{DialogManager}}}.
   * Load the zip file in a {{{Storage}}}.
   * Convert the storage to {{{AnnotationSet}}} using the schema "resource:annotation-set|storage|r3".
   * If an error occurs, display "Invalid file." using {{{DialogUtils.showErrorDialog}}}.
   * If the refered book is not the currently open book, display error message.
   * If none of the above issues is present, add the annotation set to current book's window {{{shownExtras}}} list,
   * then use {{{CurrentAnnotationsMap.setAsCurrent}}}.
  * Saving annotations:
   * Create a new {{{FileDialogInput}}} for zip files and display it using the {{{DialogManager}}}.
   * Store current annotation set to storage using the schema "resource:annotation-set|storage|r3".

= Implementation =
^(Describe and link the implementation results here (from the wiki or the repository).)^

= Testing =
^(Place the testing results here.)^

= Comments =
^(Write comments for this or later revisions here.)