Skip to content

Commit

Permalink
Merge pull request #1199 from briehl/copy-sharing-problem
Browse files Browse the repository at this point in the history
TASK-1229 - UPA handler API
  • Loading branch information
briehl committed Nov 9, 2017
2 parents f6ec7b4 + a959379 commit 6b4a466
Show file tree
Hide file tree
Showing 11 changed files with 542 additions and 535 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ env:
- TRAVIS_NODE_VERSION="6.6.0"
cache:
directories:
- kbase-extension/static/ext_components
- node_modules
- kbase-extension/static/ext_components
- node_modules
- $HOME/.cache/pip

branches:
only:
- develop
- staging
- master
- travis-firefox

Expand All @@ -27,6 +28,7 @@ before_install:
- npm install -g bower
- npm install -g grunt-cli
- npm install -g karma-cli

install:
- pip install -r src/requirements.txt

Expand Down
123 changes: 123 additions & 0 deletions kbase-extension/static/kbase/js/api/upa.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
define([
'common/runtime'
], function(Runtime) {
'use strict';

var UpaApi = function() {
var externalTag = '&';

/**
* Runs a regex that tests the given string to see if it's a valid upa.
* valid upas are of the form:
* ws/obj/ver or ws1/obj1/ver1;ws2/obj2/ver2;...
*/
var isUpa = function(upa) {
return RegExp(/^\d+(\/\d+){2}(;\d+(\/\d+){2})*$/).test(upa);
};

var prepareUpaSerialization = function(upa) {
if (typeof upa !== 'string') {
// stringify the array version of an UPA, if that's what we have.
if (Array.isArray(upa)) {
upa = upa.join(';');
}
else {
throw {error: 'Can only serialize UPA strings or Arrays of UPA paths'};
}
}
if (!isUpa(upa)) {
throw {error: '"' + upa + '" is not a valid UPA. It may already have been serialized.'};
}
return upa;
};

/**
* @method
* @public
* Serializes an UPA - prepares it for storage as a part of Narrative cell metadata.
* This means a bit of a tweak to the UPA itself. Currently, we want to store it in a way
* that designates it as a serialized string, and gives an easy path to substitute the
* initial workspace part of the UPA with a different workspace.
* So it gets transformed from:
* ws1/obj1/ver1;ws2/obj2/ver2;...
* to
* [ws1]/obj1/ver1;ws2/obj2/ver2;...
*
* If the passed upa is not properly formatted, this will throw an Error.
*/
var serialize = function(upa) {
upa = prepareUpaSerialization(upa);
return upa.replace(/^(\d+)\//, '[$1]/');
};

/**
* @public
* @method
*
* In the case of UPAs representing objects that are located in a different workspace all
* together (e.g. set items that aren't copied into the Narrative with the set container
* object), they get flagged with a special character. In that case, the UPA is maintained,
* but transformed into:
* &ws1/obj1/ver1;ws2/obj2/ver2;...
*
* This is an explicit method for handling that serialization. Deserialization of both is handled
* by the deserialize function.
*
* If the passed upa is not properly formatted, this will throw an Error.
*/
var serializeExternal = function(upa) {
upa = prepareUpaSerialization(upa);
return externalTag + upa;
};

/**
* @public
* @method
* Deserializes a serialized UPA to one that is valid for use with the Workspace (or other
* services that consume Workspace objects).
* A serialized UPA is either of the form:
* [ws]/obj/ver;ws/obj/ver;...
* or
* &ws/obj/ver;ws/obj/ver
* In the [ws] case, the current workspace id replaces that whole token. In the &ws case,
* the & tag is removed.
*/
var deserialize = function(serial) {
if (typeof serial !== 'string') {
throw {
error: 'Can only deserialize UPAs from strings.'
};
}
var deserial;
if (serial[0] === externalTag) {
deserial = serial.substring(externalTag.length);
} else {
var wsId = Runtime.make().workspaceId();
if (!wsId) {
throw {
error: 'Currently loaded workspace is unknown! Unable to deserialize UPA.'
};
}
deserial = serial.replace(/^\[\d+\]\//, Runtime.make().workspaceId() + '/');
}
if (!isUpa(deserial)) {
throw {
error: 'Deserialized UPA: ' + deserial + ' is invalid!'
};
}
return deserial;
};


return {
serialize: serialize,
deserialize: deserialize,
serializeExternal: serializeExternal,
externalTag: externalTag,
isUpa: isUpa
};
};

return UpaApi;

});
13 changes: 0 additions & 13 deletions nbextensions/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,6 @@ export IPYTHONDIR=$narrdir/kbase-extension/ipython
echo 'Root dir'
echo ${dir}

#jupyter nbextension disable appCell/main --sys-prefix
#jupyter nbextension uninstall ${dir}/appCell --sys-prefix
#jupyter nbextension install ${dir}/appCell --symlink --sys-prefix
#jupyter nbextension enable appCell/main --sys-prefix

#jupyter nbextension disable methodViewCell/main --sys-prefix
#jupyter nbextension uninstall ${dir}/methodViewCell --sys-prefix
jupyter nbextension install ${dir}/viewCell --symlink --sys-prefix
jupyter nbextension enable viewCell/main --sys-prefix

Expand All @@ -38,9 +31,3 @@ jupyter nbextension enable advancedViewCell/main --sys-prefix

jupyter nbextension install ${dir}/codeCell --symlink --sys-prefix
jupyter nbextension enable codeCell/main --sys-prefix

# jupyter nbextension disable codeCell/main --sys-prefix
# jupyter nbextension install ${dir}/codeCell --symlink --sys-prefix

#jupyter nbextension disable customView/main --sys-prefix
#jupyter nbextension uninstall ${dir}/customView --sys-prefix
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"karma-coverage": "1.1.1",
"karma-firefox-launcher": "1.0.0",
"karma-jasmine": "1.0.2",
"karma-mocha-reporter": "^2.2.5",
"karma-phantomjs-launcher": "1.0.1",
"karma-requirejs": "1.0.0",
"karma-safari-launcher": "1.0.0",
Expand Down
2 changes: 1 addition & 1 deletion src/biokbase/narrative/clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def __init_client(client_name):
c = UserAndJobState(URLS.user_and_job_state)
elif client_name == 'catalog':
c = Catalog(URLS.catalog)
elif client_name == 'service':
elif client_name == 'service' or client_name == 'service_wizard':
c = ServiceClient(URLS.service_wizard, use_url_lookup=True)

else:
Expand Down
Loading

0 comments on commit 6b4a466

Please sign in to comment.