Skip to content

Commit

Permalink
Merge pull request #289 from reTHINK-project/testMigration
Browse files Browse the repository at this point in the history
Test migration
  • Loading branch information
luistduarte committed Apr 17, 2019
2 parents 3ad79e9 + 90ea433 commit b7347e3
Show file tree
Hide file tree
Showing 22 changed files with 750 additions and 764 deletions.
2 changes: 1 addition & 1 deletion .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"presets": ["@babel/preset-env"],
"plugins": ["syntax-dynamic-import"]
"plugins": ["@babel/plugin-syntax-dynamic-import"]
}
4 changes: 2 additions & 2 deletions dist/PEP.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/ReThinkCtx.js

Large diffs are not rendered by default.

60 changes: 57 additions & 3 deletions dist/Runtime.js

Large diffs are not rendered by default.

173 changes: 3 additions & 170 deletions dist/Runtime.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/RuntimeCatalogue.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/StorageManager.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/minibus.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/rethink.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/sandbox.js

Large diffs are not rendered by default.

1,169 changes: 606 additions & 563 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"@babel/cli": "^7.2.0",
"@babel/core": "^7.2.0",
"@babel/parser": "^7.2.0",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/preset-env": "^7.2.0",
"babel-loader": "^8.0.4",
"base64-url": "^1.3.3",
Expand Down
2 changes: 1 addition & 1 deletion src/identity/IdentityModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ class IdentityModule {

}, (error) => {
if (error.hasOwnProperty('description') && error.description.hasOwnProperty('loginUrl')) {
_this.callIdentityModuleFunc('openPopup', { urlreceived: error.description.loginUrl }).then((value) => {
_this.callIdentityModuleFunc('login', { urlreceived: error.description.loginUrl }).then((value) => {
log.log('[IdentityModule:callIdentityModuleFunc:openPopup]', usernameHint);

resolve(value);
Expand Down
2 changes: 1 addition & 1 deletion src/registry/Registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ class Registry {

let registrationAtdomain = true;

if ( descriptor.hasOwnProperty("_configuration") && descriptor.configuration.hasOwnProperty("domain_registration")) {
if ( descriptor.hasOwnProperty("configuration") && descriptor.configuration.hasOwnProperty("domain_registration")) {
registrationAtdomain = descriptor.configuration.domain_registration;
}

Expand Down
4 changes: 2 additions & 2 deletions src/rethink/IdentitiesGUI.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ class IdentitiesGUI {
clearInterval(pollTimer);
}

if (win.document.URL.indexOf('id_token') !== -1 || win.document.URL.indexOf(location.origin) !== -1) {
// if ( win.document.URL.indexOf(location.origin) !== -1) {
// if (win.document.URL.indexOf('id_token') !== -1 || win.document.URL.indexOf(location.origin) !== -1) {
if ( win.document.URL.indexOf(location.origin) !== -1) {
window.clearInterval(pollTimer);
let url = win.document.URL;

Expand Down
9 changes: 9 additions & 0 deletions src/rethink/rethink.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,15 @@ const rethink = {
});

});
},
listenOnline: (callback) => {
return runtimeFactory.listenOnline(callback);

},

listenOffline: (callback) => {
return runtimeFactory.listenOffline(callback);

}

}
Expand Down
12 changes: 12 additions & 0 deletions src/rethink/runtimeFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ const runtimeFactory = Object.create({
return this.catalogue;
},*/

isOnline() {
return window.navigator.onLine;
},

listenOnline(callback) {
window.addEventListener('online', callback);
},

listenOffline(callback) {
window.addEventListener('offline', callback);
},

runtimeCapabilities() {

if (!this.capabilitiesManager) {
Expand Down
28 changes: 25 additions & 3 deletions src/runtime-catalogue/RuntimeCatalogue.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ class RuntimeCatalogue {
constructor(runtimeFactory, name, schema) {
if (!runtimeFactory) throw Error('The catalogue needs the runtimeFactory');

this._runtimeFactory = runtimeFactory;

this._factory = new CatalogueFactory();
this.httpRequest = runtimeFactory.createHttpRequest();
this.atob = runtimeFactory.atob ? runtimeFactory.atob : atob;

const storageName = name ? name : 'runtimeCatalogue';
const storageSchema = schema ? schema : '&cguid, accessControlPolicy, constraints, dataObjects, hypertyType, objectName, sourcePackage, version';
const storageSchema = schema ? schema : '&cguid, accessControlPolicy, constraints, dataObjects, type, objectName, sourcePackage, version, url';

const schemas = {};
schemas[storageName] = storageSchema;
Expand All @@ -32,8 +34,27 @@ class RuntimeCatalogue {
* @returns {Promise} - Promise that fulfills with the requested descriptor in the appropriate type.
* If constraints were provided, a descriptor is only returned if it meets the constraints, otherwise the promise will be rejected.
*/
getDescriptor(descriptorURL, createFunc, getFull = true, constraints) {
log.info('[RuntimeCatalogue] - getting descriptor from: ', descriptorURL, ' with constraints: ', constraints);
getDescriptor(descriptorURL, createFunc, getFull = true, constraints) {
log.info('[RuntimeCatalogue] - getting descriptor from: ', descriptorURL, ' with constraints: ', constraints);

return new Promise ((resolve, reject)=>{
if (this._runtimeFactory.isOnline() ) {
resolve( this._getDescriptor(descriptorURL, createFunc, getFull, constraints));
} else {
this.storageManager.get('url', descriptorURL).then((descriptor) => {
console.log('[RuntimeCatalogue] saved offline descriptor ', descriptor);

if (descriptor) resolve(createFunc.apply(this, [descriptor, constraints]));
else resolve( this._getDescriptor(descriptorURL, createFunc, getFull, constraints));

});
}

});

}

_getDescriptor(descriptorURL, createFunc, getFull = true, constraints) {

// some flags for optimization
// (later the descriptor will not be saved in case both of these booleans are true)
Expand Down Expand Up @@ -101,6 +122,7 @@ class RuntimeCatalogue {
returnPromise = returnPromise.then((descriptor) => {
// store if not saved before, or if full descriptor was requested and only partial descriptor was stored.
if (!isSavedDescriptor || (isSavedDescriptor && !isCompleteDescriptor && getFull)) {
descriptor.url = descriptorURL;
this.storageManager.set(descriptor.cguid, descriptor.version, descriptor);
}
return createFunc.apply(this, [descriptor, constraints]);
Expand Down
10 changes: 10 additions & 0 deletions src/runtime/RuntimeUA.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ class RuntimeUA {

this.domain = this.runtimeConfiguration.domain;


log.info('[RuntimeUA - init] Starting ');

try {
Expand Down Expand Up @@ -191,6 +192,8 @@ class RuntimeUA {


}).then((status) => {
this._setNetworkStatusListeners();


this._hypertyResourcesStorage = new HypertyResourcesStorage(this.runtimeURL, this.messageBus, this.storages.hypertyResources, this._hypertyResources);

Expand Down Expand Up @@ -218,6 +221,13 @@ class RuntimeUA {

}

_setNetworkStatusListeners() {

this.runtimeFactory.listenOnline( this._updateRuntimeStatus('online') );
this.runtimeFactory.listenOffline( this._updateRuntimeStatus('offline') );

}

_updateRuntimeStatus(event) {

let _this = this;
Expand Down
2 changes: 2 additions & 0 deletions src/runtime/Storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ let storages = {};
export function storage(runtimeFactory, runtimeStatusUpdate) {
if (!runtimeFactory) throw new Error('The runtime factory is a needed parameter');

console.log('[Storage.storage] storageSchemas ', runtimeConfiguration.storageSchemas);

Object.keys(runtimeConfiguration.storageSchemas).forEach((key) => {

if (!storages.hasOwnProperty(key)) {
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/runtimeConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const runtimeConfiguration = {
identities: 'userURL, userProfile.email, userProfile.userURL, userProfile.name'
},
runtimeCatalogue: {
runtimeCatalogue: '&cguid, accessControlPolicy, constraints, dataObjects, hypertyType, objectName, sourcePackage, version'
runtimeCatalogue: '&cguid, accessControlPolicy, constraints, dataObjects, type, objectName, sourcePackage, version, url'
},
policy: {
'rethink:activePolicy': 'key,version,value',
Expand Down Expand Up @@ -94,5 +94,5 @@ export const runtimeConfiguration = {
suffix: ''
},
globalRegistryURL: 'global://registry.',
remoteStorage: 'https://hysmart.rethink.ptinovacao.pt/backup/'
remoteStorage: 'https://backup.rethink-dev.alticelabs.com/'
};
8 changes: 4 additions & 4 deletions src/syncher/SyncherManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ class SyncherManager {

let properties = descriptor.sourcePackage.sourceCode.properties;
let scheme = properties.scheme ? properties.scheme : 'resource';
let childrens = properties.children ? properties.children : [];
let childrens = properties.childrens ? properties.childrens : [];

// Do schema validation
// TODO: check if is need to handle with the result of validation
Expand Down Expand Up @@ -511,7 +511,7 @@ class SyncherManager {

let properties = descriptor.sourcePackage.sourceCode.properties;
let scheme = properties.scheme ? properties.scheme.constant : 'resource';
let childrens = properties.children ? properties.children.constant : [];
let childrens = properties.childrens ? properties.childrens : [];

log.log('[SyncherManager] - getDataSchemaDescriptor: ', descriptor, childrens);

Expand Down Expand Up @@ -827,7 +827,7 @@ class SyncherManager {
//get schema from catalogue and parse -> (children)
_this._catalog.getDataSchemaDescriptor(msg.body.schema).then((descriptor) => {
let properties = descriptor.sourcePackage.sourceCode.properties;
let childrens = properties.children ? properties.children.constant : [];
let childrens = properties.childrens ? properties.childrens : [];

let subscriptions = [];
subscriptions.push(objURL + '/changes');
Expand Down Expand Up @@ -1013,7 +1013,7 @@ class SyncherManager {
// TODO: remove this since children resources should be available in the DataObjectsStorage
this._catalog.getDataSchemaDescriptor(schema).then((descriptor) => {
let properties = descriptor.sourcePackage.sourceCode.properties;
let childrens = properties.children ? properties.children.constant : [];
let childrens = properties.childrens ? properties.childrens : [];

//children addresses
let subscriptions = [];
Expand Down

0 comments on commit b7347e3

Please sign in to comment.