From 5bc37ec44574f094217c102bb9d29dd6472a1c6c Mon Sep 17 00:00:00 2001 From: "D. Stuart Freeman" Date: Thu, 9 Oct 2014 14:37:16 -0400 Subject: [PATCH 1/3] use OaeUtil toArray --- .../oae-preview-processor/lib/filters.js | 27 +++++-------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/node_modules/oae-preview-processor/lib/filters.js b/node_modules/oae-preview-processor/lib/filters.js index 9ad1d3853b..ae1a2f1055 100644 --- a/node_modules/oae-preview-processor/lib/filters.js +++ b/node_modules/oae-preview-processor/lib/filters.js @@ -14,6 +14,7 @@ */ var _ = require('underscore'); +var OaeUtil = require('oae-util/lib/util') /** * Allows for validation and applying of filters when triggering a "reprocessing" previews task @@ -57,7 +58,7 @@ var FilterGenerator = module.exports.FilterGenerator = function(filters) { columnNames.push('resourceSubType'); // Construct the filter function - var types = _wrapInArray(value); + var types = OaeUtil.toArray(value); contentCheckers.push(function(content) { return _.contains(types, content.resourceSubType); }); @@ -66,7 +67,7 @@ var FilterGenerator = module.exports.FilterGenerator = function(filters) { columnNames.push('previews'); // Construct the filter function - var statuses = _wrapInArray(value); + var statuses = OaeUtil.toArray(value); contentCheckers.push(function(content) { if (content.previews && content.previews.status) { return _.contains(statuses, content.previews.status); @@ -76,7 +77,7 @@ var FilterGenerator = module.exports.FilterGenerator = function(filters) { } }); } else if (name === 'createdBy') { - var userIds = _wrapInArray(value); + var userIds = OaeUtil.toArray(value); contentCheckers.push(function(content) { return _.contains(userIds, content.createdBy); }); @@ -89,7 +90,7 @@ var FilterGenerator = module.exports.FilterGenerator = function(filters) { _.each(revisionFilters, function(value, name) { if (name === 'mime') { needsRevisions = true; - var types = _wrapInArray(value); + var types = OaeUtil.toArray(value); revisionCheckers.push(function(revision) { if (!revision.mime) { return false; @@ -100,7 +101,7 @@ var FilterGenerator = module.exports.FilterGenerator = function(filters) { }); } else if (name === 'previewsStatus') { needsRevisions = true; - var statuses = _wrapInArray(value); + var statuses = OaeUtil.toArray(value); revisionCheckers.push(function(revision) { if (revision.previews && revision.previews.status) { return _.contains(statuses, revision.previews.status); @@ -111,7 +112,7 @@ var FilterGenerator = module.exports.FilterGenerator = function(filters) { }); } else if (name === 'createdBy') { needsRevisions = true; - var userIds = _wrapInArray(value); + var userIds = OaeUtil.toArray(value); revisionCheckers.push(function(revision) { return _.contains(userIds, revision.createdBy); }); @@ -223,17 +224,3 @@ var FilterGenerator = module.exports.FilterGenerator = function(filters) { return that; }; - -/** - * Wraps a value in an array if it's not an array already - * - * @param {Object} value The value to wrap in an array - * @return {Object[]} The wrapped array - * @api private - */ -var _wrapInArray = function(value) { - if (!_.isArray(value)) { - value = [ value ]; - } - return value; -}; \ No newline at end of file From 0bb4b0b16f8232ae3b1f7668fc957a03ac7203ca Mon Sep 17 00:00:00 2001 From: "D. Stuart Freeman" Date: Tue, 14 Oct 2014 15:32:16 -0400 Subject: [PATCH 2/3] add ability to filter by tenant --- node_modules/oae-preview-processor/lib/filters.js | 10 +++++++++- node_modules/oae-preview-processor/lib/rest.js | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/node_modules/oae-preview-processor/lib/filters.js b/node_modules/oae-preview-processor/lib/filters.js index ae1a2f1055..79664fa216 100644 --- a/node_modules/oae-preview-processor/lib/filters.js +++ b/node_modules/oae-preview-processor/lib/filters.js @@ -14,7 +14,7 @@ */ var _ = require('underscore'); -var OaeUtil = require('oae-util/lib/util') +var OaeUtil = require('oae-util/lib/util'); /** * Allows for validation and applying of filters when triggering a "reprocessing" previews task @@ -24,6 +24,7 @@ var OaeUtil = require('oae-util/lib/util') * @param {String[]} [filters.content.createdBy] Filter content based on who it was created by * @param {String[]} [filters.content.previewsStatus] Filter content based on the status of the previews processing * @param {String[]} [filters.content.resourceSubType] Filter content based on its resourceSubType + * @param {String[]} [filters.content.tenant] Filter content based on the tenant where it was created * @param {String[]} [filters.revision.mime] Filter based on the mime type of a file. Only useful in combination with `content_resourceSubType: file` * @param {Number} [filters.revision.createdAfter] Filter those revisions who were created after a certain timestamp. The value of the timestamp should be specified in ms since epoch * @param {Number} [filters.revision.createdBefore] Filter those revisions who were created before a certain timestamp. The value of the timestamp should be specified in ms since epoch @@ -81,6 +82,13 @@ var FilterGenerator = module.exports.FilterGenerator = function(filters) { contentCheckers.push(function(content) { return _.contains(userIds, content.createdBy); }); + } else if (name === 'tenant') { + columnNames.push('tenantAlias'); + var tenantAliases = OaeUtil.toArray(value); + + contentCheckers.push(function(content) { + return (_.contains(tenantAliases, content.tenantAlias)); + }); } else { errors.push({'code': 400, 'msg': 'Unknown content filter'}); } diff --git a/node_modules/oae-preview-processor/lib/rest.js b/node_modules/oae-preview-processor/lib/rest.js index 9f2efe721b..d071d90d33 100644 --- a/node_modules/oae-preview-processor/lib/rest.js +++ b/node_modules/oae-preview-processor/lib/rest.js @@ -32,6 +32,7 @@ var PreviewProcessorAPI = require('oae-preview-processor'); * @FormParam {String[]} [content_createdBy] Filter content based on who it was created by * @FormParam {string[]} [content_resourceSubType] Filter content based on its resourceSubType [collabdoc,file,link] * @FormParam {string[]} [content_previewsStatus] Filter content based on the status of the previews processing [ignored,error] + * @FormParam {string[]} [content_tenant] Filter content based on the tenant where it was created * @FormParam {number} [revision_createdAfter] Filter those revisions who were created after a certain timestamp in ms since epoch * @FormParam {number} [revision_createdBefore] Filter those revisions who were created before a certain timestamp in ms since epoch * @FormParam {string[]} [revision_createdBy] Filter the revisions based on who it was created by From 0a2bc9788fbb18107718b79ad539fe5c04aba492 Mon Sep 17 00:00:00 2001 From: "D. Stuart Freeman" Date: Thu, 16 Oct 2014 12:55:24 -0400 Subject: [PATCH 3/3] add test for reprocess by tenant --- .../tests/test-filters.js | 53 ++++++++++++++----- 1 file changed, 39 insertions(+), 14 deletions(-) diff --git a/node_modules/oae-preview-processor/tests/test-filters.js b/node_modules/oae-preview-processor/tests/test-filters.js index 0a9c2fc960..74a5fb2ab3 100644 --- a/node_modules/oae-preview-processor/tests/test-filters.js +++ b/node_modules/oae-preview-processor/tests/test-filters.js @@ -46,7 +46,7 @@ describe('Preview processor - filters', function() { new Content('camtest', 'c:camtest:b', 'public', 'B', 'B', 'link', 'u:camtest:nico', times.B, times.B, 'b-1'), new Content('camtest', 'c:camtest:c', 'public', 'C', 'C', 'collabdoc', 'u:camtest:mrvisser', times.B, times.D, 'c-3'), new Content('camtest', 'c:camtest:d', 'public', 'D', 'D', 'file', 'u:camtest:simon', times.C, times.D, 'd-2'), - new Content('camtest', 'c:camtest:e', 'public', 'E', 'E', 'file', 'u:camtest:simon', times.D, times.F, 'e-2') + new Content('gttest', 'c:gttest:e', 'public', 'E', 'E', 'file', 'u:gttest:stuart', times.D, times.F, 'e-2') ]; // Give each content item a revision @@ -74,9 +74,13 @@ describe('Preview processor - filters', function() { ]; content[4].previews = {'status': 'error'}; content[4].revisions = [ - {'revisionId': 'e-1', 'created': times.D, 'createdBy': 'u:camtest:simon', 'mime': 'video/mp4', 'previews': {'status': 'done'}}, + {'revisionId': 'e-1', 'created': times.D, 'createdBy': 'u:gttest:stuart', 'mime': 'video/mp4', 'previews': {'status': 'done'}}, {'revisionId': 'e-2', 'created': times.F, 'createdBy': 'u:camtest:bert', 'mime': 'video/theora', 'previews': {'status': 'error'}} ]; + // Populate each piece of content's tenantAlias + _.each(content, function(c) { + c.tenantAlias = c.tenant.alias; + }); return content; }; @@ -183,6 +187,29 @@ describe('Preview processor - filters', function() { callback(); }); + /** + * Test that verifies you can filter by tenant + */ + it('filter by content.tenantAlias', function(callback) { + var filters = { + 'content': { + 'tenant': 'camtest' + } + }; + + _filterAndAssert(filters, { + 'needsRevisions': false, + 'contentStage': ['c:camtest:a', 'c:camtest:b', 'c:camtest:c', 'c:camtest:d'], + 'revisionStage': [ + {'contentId': 'c:camtest:a', 'revisions': ['a-1', 'a-2', 'a-3']}, + {'contentId': 'c:camtest:b', 'revisions': ['b-1']}, + {'contentId': 'c:camtest:c', 'revisions': ['c-1', 'c-2', 'c-3']}, + {'contentId': 'c:camtest:d', 'revisions': ['d-1', 'd-2']} + ] + }); + callback(); + }); + /** * Test that verifies you can filter by the content creator */ @@ -195,11 +222,10 @@ describe('Preview processor - filters', function() { _filterAndAssert(filters, { 'needsRevisions': false, - 'contentStage': ['c:camtest:a', 'c:camtest:d', 'c:camtest:e'], + 'contentStage': ['c:camtest:a', 'c:camtest:d'], 'revisionStage': [ {'contentId': 'c:camtest:a', 'revisions': ['a-1', 'a-2', 'a-3']}, - {'contentId': 'c:camtest:d', 'revisions': ['d-1', 'd-2']}, - {'contentId': 'c:camtest:e', 'revisions': ['e-1', 'e-2']} + {'contentId': 'c:camtest:d', 'revisions': ['d-1', 'd-2']} ] }); callback(); @@ -217,11 +243,10 @@ describe('Preview processor - filters', function() { _filterAndAssert(filters, { 'needsRevisions': true, - 'contentStage': ['c:camtest:a', 'c:camtest:b', 'c:camtest:c', 'c:camtest:d', 'c:camtest:e'], + 'contentStage': ['c:camtest:a', 'c:camtest:b', 'c:camtest:c', 'c:camtest:d', 'c:gttest:e'], 'revisionStage': [ {'contentId': 'c:camtest:a', 'revisions': ['a-1']}, - {'contentId': 'c:camtest:d', 'revisions': ['d-1']}, - {'contentId': 'c:camtest:e', 'revisions': ['e-1']} + {'contentId': 'c:camtest:d', 'revisions': ['d-1']} ] }); callback(); @@ -257,10 +282,10 @@ describe('Preview processor - filters', function() { }; _filterAndAssert(filters, { 'needsRevisions': true, - 'contentStage': ['c:camtest:a', 'c:camtest:b', 'c:camtest:c', 'c:camtest:d', 'c:camtest:e'], + 'contentStage': ['c:camtest:a', 'c:camtest:b', 'c:camtest:c', 'c:camtest:d', 'c:gttest:e'], 'revisionStage': [ {'contentId': 'c:camtest:a', 'revisions': ['a-3']}, - {'contentId': 'c:camtest:e', 'revisions': ['e-2']} + {'contentId': 'c:gttest:e', 'revisions': ['e-2']} ] }); callback(); @@ -280,7 +305,7 @@ describe('Preview processor - filters', function() { 'contentStage': ['c:camtest:a', 'c:camtest:b', 'c:camtest:c', 'c:camtest:d', 'c:camtest:e'], 'revisionStage': [ {'contentId': 'c:camtest:a', 'revisions': ['a-1']}, - {'contentId': 'c:camtest:e', 'revisions': ['e-1']} + {'contentId': 'c:gttest:e', 'revisions': ['e-1']} ] }); callback(); @@ -297,10 +322,10 @@ describe('Preview processor - filters', function() { }; _filterAndAssert(filters, { 'needsRevisions': false, - 'contentStage': ['c:camtest:a', 'c:camtest:e'], + 'contentStage': ['c:camtest:a', 'c:gttest:e'], 'revisionStage': [ {'contentId': 'c:camtest:a', 'revisions': ['a-1', 'a-2', 'a-3']}, - {'contentId': 'c:camtest:e', 'revisions': ['e-1', 'e-2']} + {'contentId': 'c:gttest:e', 'revisions': ['e-1', 'e-2']} ] }); @@ -332,7 +357,7 @@ describe('Preview processor - filters', function() { 'revisionStage': [ {'contentId': 'c:camtest:a', 'revisions': ['a-2']}, {'contentId': 'c:camtest:d', 'revisions': ['d-1']}, - {'contentId': 'c:camtest:e', 'revisions': ['e-2']} + {'contentId': 'c:gttest:e', 'revisions': ['e-2']} ] });