Commit 8bd87f79 authored by Boris Kocherov's avatar Boris Kocherov

erp5_officejs: schema editor: add upload zip archive containing schema and documents

parent 089ef620
......@@ -191,7 +191,7 @@
tasks.push(gen_element({command: 'display', options: {page: "ojs_configurator"}},
"Storages", "dropbox"));
if (context.state.editable) {
tasks.push(gen_element({command: 'index', options: {page: "ojs_multi_upload"}},
tasks.push(gen_element({command: 'index', options: {page: "ojs_zip_upload"}},
"Upload", "upload"));
}
return RSVP.all(tasks);
......
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>OfficeJS Jio Upload Zip File Containing files or files as is</title>
<script src="rsvp.js"></script>
<script src="renderjs.js"></script>
<script src="jio_ziptodocuments.js"></script>
<script src="zipfilestorage-with-jszip.js"></script>
<script src="gadget_erp5_page_ojs_zip_upload.js"></script>
</head>
<body>
<div data-gadget-url="gadget_erp5_form.html"
data-gadget-scope="form_view"
data-gadget-sandbox="public">
</div>
</body>
</html>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Web Page" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Change_local_roles_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_erp5_page_ojs_zip_upload.html</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>gadget_erp5_page_ojs_zip_upload.html</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Page</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>document_publication_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>edit_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>processing_status_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAU=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>publish</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1531858269.29</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>published</string> </value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>edit</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>968.63483.10177.13550</string> </value>
</item>
<item>
<key> <string>state</string> </key>
<value> <string>current</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1531858473.45</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>detect_converted_file</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_processing_state</string> </key>
<value> <string>converted</string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>0.0.0.0</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1531848195.02</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
/*global window, rJS, RSVP, loopEventListener,
jIO, document */
/*jslint nomen: true, indent: 2, maxerr: 3 */
(function (window, rJS, jIO, RSVP) {
"use strict";
var content_type = {
Spreadsheet: 'application/x-asc-spreadsheet',
Presentation: 'application/x-asc-presentation',
Text: 'application/x-asc-text'
};
function endsWith(str, suffix) {
return str.indexOf(suffix, str.length - suffix.length) !== -1;
}
function generateMetadata(id, filename, path, body) {
// it's core of upload of zip gadget
// in this function can be added support another formats
var ret;
if (endsWith(filename, ".json")) {
ret = {
id: id,
content_type: "application/json",
reference: path
};
if (body) {
if (body.$schema && body.$schema !== "") {
ret.portal_type = "JSON Schema";
ret.parent_relative_url = "schema_module";
ret.title = body.title || "";
} else {
// XXX need schema relation property
ret.portal_type = "JSON Document";
ret.parent_relative_url = "document_module";
ret.title = body.filename || "";
}
} else {
ret.format = "json";
}
// used for detect supported extension
return ret;
}
}
rJS(window)
/////////////////////////////////////////////////////////////////
// Acquired methods
/////////////////////////////////////////////////////////////////
.declareAcquiredMethod("updateHeader", "updateHeader")
.declareAcquiredMethod("getUrlFor", "getUrlFor")
.declareAcquiredMethod("getSetting", "getSetting")
.declareAcquiredMethod("notifySubmitting", "notifySubmitting")
.declareAcquiredMethod("notifySubmitted", "notifySubmitted")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
.declareAcquiredMethod("redirect", "redirect")
.declareAcquiredMethod("jio_post", "jio_post")
.declareAcquiredMethod("jio_put", "jio_put")
.declareAcquiredMethod("jio_putAttachment", "jio_putAttachment")
/////////////////////////////////////////////////////////////////
// declared methods
/////////////////////////////////////////////////////////////////
.declareMethod("render", function () {
var gadget = this;
return gadget.changeState({
title: 'Untitled Document'
});
})
.declareMethod('putIntoDB', function (id, file_name, path, blob) {
var gadget = this,
queue = RSVP.Queue(),
// first run generateMetadata for check file support
// and detect document format
file_supported = generateMetadata(id, file_name, path);
if (file_supported) {
if (file_supported.format === "json") {
queue
.push(function () {
return jIO.util.readBlobAsText(blob);
})
.push(function (evt) {
return JSON.parse(evt.target.result);
});
} else {
queue.push(function () {
return blob;
});
}
queue
.push(function (data) {
return gadget.jio_post(generateMetadata(id, file_name, path, data))
.push(function (added_id) {
return gadget.jio_putAttachment(added_id, 'data', blob);
});
});
}
return queue;
})
.declareMethod('triggerSubmit', function () {
var gadget = this;
return gadget.notifySubmitting()
.push(function () {
return gadget.getDeclaredGadget('form_view');
})
.push(function (form_gadget) {
return form_gadget.getContent();
})
.push(function (content) {
return new RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getSetting('jio_storage_name'),
gadget.getSetting('jio_storage_description')
]);
})
.push(function (result) {
var promiseArray = [],
data_array = content.data,
i,
blob,
storage_name = result[0],
storage_description = result[1],
storage,
local_database,
configuration;
// XXX support other type of storage
if (storage_name === "LOCAL") {
local_database = storage_description.sub_storage.sub_storage.database;
}
for (i = 0; i < data_array.length; i += 1) {
blob = jIO.util.dataURItoBlob(data_array[i].url);
if (endsWith(data_array[i].file_name, ".zip")) {
configuration = {
type: "replicate",
conflict_handling: 2,
check_local_attachment_creation: false,
check_local_creation: false,
check_local_modification: false,
check_local_deletion: false,
check_remote_attachment_creation: true,
check_remote_creation: true,
check_remote_modification: true,
check_remote_deletion: true,
local_sub_storage: {
type: "indexeddb",
database: local_database
},
signature_sub_storage: {
type: "query",
sub_storage: {
type: "memory"
}
},
remote_sub_storage: {
type: "ziptodocuments",
generateMetadata: generateMetadata,
sub_storage: {
type: "zipfile",
file: blob
}
}
};
storage = jIO.createJIO(configuration);
promiseArray.push(storage.repair());
} else {
promiseArray.push(gadget.putIntoDB("", data_array[i].file_name, data_array[i].file_name, blob));
}
}
return RSVP.all(promiseArray);
});
})
.push(function () {
return RSVP.all([
gadget.notifySubmitted({message: 'Data Updated', status: 'success'}),
gadget.redirect({command: 'history_previous'})
]);
});
})
.onStateChange(function () {
var gadget = this;
return RSVP.Queue()
.push(function () {
return RSVP.all([
gadget.getDeclaredGadget('form_view'),
gadget.getSetting('upload_content_type')
]);
})
.push(function (result) {
return result[0].render({
erp5_document: {
"_embedded": {
"_view": {
"my_file": {
"description": "",
"title": "Upload files and Zip archive containing files",
"default": "",
"css_class": "",
"required": 1,
"editable": 1,
"key": "data",
"hidden": 0,
"multiple": "true",
"accept": "application/zip," + result[1],
"type": "FileField"
}
}
},
"_links": {
"type": {
// form_list display portal_type in header
name: ""
}
}
},
form_definition: {
group_list: [[
"left",
[["my_file"]]
]]
}
});
})
.push(function () {
return gadget.getUrlFor({command: 'history_previous'});
})
.push(function (result) {
return gadget.updateHeader({
page_title: 'Document(s)',
back_field: true,
selection_url: result,
save_action: true
});
});
});
}(window, rJS, jIO, RSVP));
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Web Script" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Change_local_roles_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/javascript</string> </value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>gadget_erp5_page_ojs_zip_upload.js</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>gadget_erp5_page_ojs_zip_upload.js</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Script</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>document_publication_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>edit_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>processing_status_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAU=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>publish</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1531858278.36</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>published</string> </value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>edit</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>968.63287.21360.10154</string> </value>
</item>
<item>
<key> <string>state</string> </key>
<value> <string>current</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1531846571.54</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>detect_converted_file</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_processing_state</string> </key>
<value> <string>converted</string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>0.0.0.0</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1531846497.56</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
......@@ -126,6 +126,8 @@ URI.js\n
dygraph.js\n
handlebars.js\n
jiodev.js\n
jio_ziptodocuments.js\n
zipfilestorage-with-jszip.js\n
renderjs.js\n
rsvp.js\n
gadget_global.js\n
......@@ -150,8 +152,10 @@ gadget_ojs_jio.html\n
gadget_ojs_jio.js\n
gadget_erp5_page_ojs_controller.html\n
gadget_erp5_page_ojs_controller.js\n
gadget_erp5_page_ojs_add_document.html\n
gadget_erp5_page_ojs_add_document.js\n
gadget_erp5_page_ojs_add_json_schema.html\n
gadget_erp5_page_ojs_add_json_schema.js\n
gadget_erp5_page_ojs_add_json_document.html\n
gadget_erp5_page_ojs_add_json_document.js\n
gadget_erp5_page_ojs_configurator.html\n
gadget_erp5_page_ojs_configurator.js\n
gadget_erp5_page_ojs_dav_configurator.html\n
......@@ -217,6 +221,8 @@ gadget_officejs_jio_json_schema_view.html\n
gadget_officejs_jio_json_schema_view.js\n
gadget_erp5_page_ojs_multi_upload.html\n
gadget_erp5_page_ojs_multi_upload.js\n
gadget_erp5_page_ojs_zip_upload.html\n
gadget_erp5_page_ojs_zip_upload.js\n
gadget_erp5_page_ojs_schema_document_list.html\n
gadget_erp5_page_ojs_schema_document_list.js\n
\n
......@@ -380,7 +386,7 @@ NETWORK:\n
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>968.9700.26907.3566</string> </value>
<value> <string>968.64276.14441.43929</string> </value>
</item>
<item>
<key> <string>state</string> </key>
......@@ -398,7 +404,7 @@ NETWORK:\n
</tuple>
<state>
<tuple>
<float>1528717715.13</float>
<float>1531905921.42</float>
<string>UTC</string>
</tuple>
</state>
......
/*jslint nomen: true*/
/*global jIO, RSVP*/
(function (jIO, RSVP) {
"use strict";
function decodeJsonPointer(_str) {
// https://tools.ietf.org/html/rfc6901#section-5
return _str.replace(/~1/g, '/').replace(/~0/g, '~');
}
function encodeJsonPointer(_str) {
// https://tools.ietf.org/html/rfc6901#section-5
return _str.replace(/~/g, '~0').replace(/\//g, '~1');
}
/**
* The jIO ZipToDocumentsBridgeStorage extension
*
* convert set of files provided zip container as
* documents contains metadata for files
* with attachment 'body' as file content
*
* @class ZipToDocumentsBridgeStorage
* @constructor
*/
function ZipToDocumentsBridgeStorage(spec) {
this._sub_storage = jIO.createJIO(spec.sub_storage);
if (spec.generateMetadata) {
this._generateMetadata = spec.generateMetadata;
} else {
throw new jIO.util.jIOError("Need specify generateMetadata function",
400);
/**
* used for generate metadata for files
* based on extension and file content.
* used for determine supported or not
* supported file by return undefined.
*
* @function generateMetadata
*/
// example generateMetadata function
// function generateMetadata(id, filename, path, body) {
// var ret;
// if (endsWith(filename, ".json")) {
// ret = {
// id: id,
// content_type: "application/json",
// reference: path
// };
// if (body) {
// if (body.$schema && body.$schema !== "") {
// ret.portal_type = "JSON Schema";
// ret.parent_relative_url = "schema_module";
// ret.title = body.title;
// } else {
// // XXX need schema relation property
// ret.portal_type = "JSON Document";
// ret.parent_relative_url = "document_module";
// ret.title = body.filename;
// }
// } else {
// ret.format = "json";
// }
// // used for detect supported extension
// return ret;
// }
// }
}
}
ZipToDocumentsBridgeStorage.prototype.get = function (id) {
var context = this,
path = "/" + decodeJsonPointer(id),
idx = path.lastIndexOf('/') + 1,
filename = path.substring(idx),
dirname = path.substring(0, idx),
file_supported;
path = path.substring(1);
file_supported = context._generateMetadata(id, filename, path);
if (!file_supported) {
return new RSVP.Queue()
.push(function () {
throw new jIO.util.jIOError("Cannot find document " + id,
404);
});
}
return context._sub_storage.getAttachment(dirname, filename,
{format: file_supported.format}
)
.push(undefined, function (error) {
if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) {
throw new jIO.util.jIOError("Cannot find document " + id,
404);
}
throw error;
})
.push(function (attachment) {
return context._generateMetadata(id, filename, path, attachment);
});
};
ZipToDocumentsBridgeStorage.prototype.allAttachments = function (id) {
var context = this,
path = "/" + decodeJsonPointer(id),
idx = path.lastIndexOf('/') + 1,
filename = path.substring(idx),
dirname = path.substring(0, idx);
return context._sub_storage.getAttachment(dirname, filename)
.push(function () {
return {"data": {}};
}, function (error) {
if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) {
throw new jIO.util.jIOError("Cannot find document " + id,
404);
}
throw error;
});
};
ZipToDocumentsBridgeStorage.prototype.put = function (doc_id) {
// we can not save file metadata(document in upper storage)
// in zip so do nothing
return RSVP.Queue()
.push(function () {
return doc_id;
});
};
ZipToDocumentsBridgeStorage.prototype.remove = function (id) {
var context = this,
path = "/" + decodeJsonPointer(id),
idx = path.lastIndexOf('/') + 1,
filename = path.substring(idx),
dirname = path.substring(0, idx);
return context._sub_storage.removeAttachment(dirname, filename)
.push(undefined, function (error) {
if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) {
throw new jIO.util.jIOError("Cannot find document " + id,
404);
}
throw error;
});
};
ZipToDocumentsBridgeStorage.prototype.hasCapacity = function (capacity) {
return ((capacity === "list") || (capacity === "include"));
};
ZipToDocumentsBridgeStorage.prototype.buildQuery = function (options) {
var result_dict = {},
context = this;
return context._sub_storage.allDocs()
.push(function (result) {
var i,
id,
tasks = [];
function push_doc(k, filename, path) {
return function (json) {
result_dict[k].doc = context._generateMetadata(k, filename, path, json);
};
}
function f(dirname) {
return function (dir) {
var k,
path,
filename,
attachment_tasks = [];
for (filename in dir) {
if (dir.hasOwnProperty(filename)) {
path = dirname.substring(1) + filename;
k = encodeJsonPointer(dirname.substring(1) + filename);
// check file with extension supported
if (context._generateMetadata(k, filename, path)) {
result_dict[k] = {
id: k,
value: {}
};
if (options.include_docs) {
attachment_tasks.push(
context._sub_storage.getAttachment(id, filename)
.push(push_doc(k, filename, path))
);
}
}
}
}
if (attachment_tasks.length > 0) {
return RSVP.all(attachment_tasks);
}
};
}
for (i = 0; i < result.data.rows.length; i += 1) {
id = result.data.rows[i].id;
tasks.push(context._sub_storage.allAttachments(id)
.push(f(id)));
}
return RSVP.all(tasks);
})
.push(function () {
var result = [],
key;
for (key in result_dict) {
if (result_dict.hasOwnProperty(key)) {
result.push(result_dict[key]);
}
}
return result;
});
};
ZipToDocumentsBridgeStorage.prototype.getAttachment = function (id,
name,
options) {
if (name !== "data") {
throw new jIO.util.jIOError("Only support 'data' attachment",
400);
}
var path = "/" + decodeJsonPointer(id),
idx = path.lastIndexOf('/') + 1,
filename = path.substring(idx),
dirname = path.substring(0, idx);
return this._sub_storage.getAttachment(dirname, filename, options);
};
ZipToDocumentsBridgeStorage.prototype.putAttachment = function (id,
name,
blob) {
if (name !== "data") {
throw new jIO.util.jIOError("Only support 'data' attachment",
400);
}
var path = "/" + decodeJsonPointer(id),
idx = path.lastIndexOf('/') + 1,
filename = path.substring(idx),
dirname = path.substring(0, idx);
return this._sub_storage.putAttachment(dirname, filename, blob);
};
ZipToDocumentsBridgeStorage.prototype.removeAttachment = function (id,
name) {
if (name !== "data") {
throw new jIO.util.jIOError("Only support 'data' attachment" +
" in document:" + id,
400);
}
// document(metadata) with attachment === attachment in zip
// so we can do nothing
};
ZipToDocumentsBridgeStorage.prototype.repair = function () {
return this._sub_storage.repair.apply(this._sub_storage, arguments);
};
jIO.addStorage('ziptodocuments', ZipToDocumentsBridgeStorage);
}(jIO, RSVP));
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Web Script" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_Access_contents_information_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Add_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Change_local_roles_Permission</string> </key>
<value>
<tuple>
<string>Assignor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_Modify_portal_content_Permission</string> </key>
<value>
<tuple>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>_View_Permission</string> </key>
<value>
<tuple>
<string>Anonymous</string>
<string>Assignee</string>
<string>Assignor</string>
<string>Associate</string>
<string>Auditor</string>
<string>Manager</string>
</tuple>
</value>
</item>
<item>
<key> <string>content_md5</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/javascript</string> </value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>jio_ziptodocuments.js</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>jio_ziptodocuments.js</string> </value>
</item>
<item>
<key> <string>language</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Web Script</string> </value>
</item>
<item>
<key> <string>short_title</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>document_publication_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
<item>
<key> <string>edit_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
<item>
<key> <string>processing_status_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAU=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>publish</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1531857837.73</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>published</string> </value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>edit</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>968.63397.4495.43707</string> </value>
</item>
<item>
<key> <string>state</string> </key>
<value> <string>current</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1531857455.0</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
<record id="5" aka="AAAAAAAAAAU=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>detect_converted_file</string> </value>
</item>
<item>
<key> <string>actor</string> </key>
<value> <string>zope</string> </value>
</item>
<item>
<key> <string>comment</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>error_message</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>external_processing_state</string> </key>
<value> <string>converted</string> </value>
</item>
<item>
<key> <string>serial</string> </key>
<value> <string>0.0.0.0</string> </value>
</item>
<item>
<key> <string>time</string> </key>
<value>
<object>
<klass>
<global name="DateTime" module="DateTime.DateTime"/>
</klass>
<tuple>
<none/>
</tuple>
<state>
<tuple>
<float>1531853065.16</float>
<string>UTC</string>
</tuple>
</state>
</object>
</value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment