Skip to content

Commit

Permalink
Introduced compatibility for liferay 7 (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbe92 authored and yuchi committed Feb 9, 2017
1 parent 139850f commit f1e07d8
Show file tree
Hide file tree
Showing 7 changed files with 95 additions and 7 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Liferay Connector

This module, available for Node.js and Titanium SDK, wraps the Liferay JSON WS into an easier to use (and easier to test!) API.

Works and tested with **Liferay 6.2.x** and **6.1.x**, both CE and EE.
Works and tested with **Liferay 7.0.x** and **6.2.x** and **6.1.x**, both CE and EE.


Installation
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ liferay.camelcase = require('./lib/camelcase');
liferay.base = require('./lib/connectors/base');
liferay.v61 = require('./lib/connectors/liferay61');
liferay.v62 = require('./lib/connectors/liferay62');
liferay.v70 = require('./lib/connectors/liferay70');

liferay.connectors = [
liferay.v61, liferay.v62
liferay.v61, liferay.v62, liferay.v70
];

liferay.guest = function (portalURL, auth, callback) {
Expand Down
8 changes: 4 additions & 4 deletions lib/connectors/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,17 +148,17 @@ Connector.guest = function (portalURL) {
Connector.authenticate = function (portalURL, auth) {
var connection = new this(portalURL, auth);

return connection.invoke({
"/group/get-user-sites": {}
})
return connection.invoke(
connection.getUserSites()
)
.then(function (sites) {
connection.sites = sites;

if (auth.companyId) {
connection.companyId = auth.companyId;
}

if (sites.length) {
if (sites && sites.length) {
connection.companyId = sites[0].companyId;
}

Expand Down
6 changes: 6 additions & 0 deletions lib/connectors/liferay61.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ inherits(Liferay61, Connector, {
if (user) return user;
else throw new errors.NotFound("Could not retrieve the user");
});
},

getUserSites: function () {
return {
"/group/get-user-sites": {}
}
}

});
Expand Down
6 changes: 6 additions & 0 deletions lib/connectors/liferay62.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ inherits(Liferay62, Connector, {
if (user) return user;
else throw new errors.NotFound("Could not retrieve the user");
});
},

getUserSites: function () {
return {
"/group/get-user-sites": {}
}
}

});
Expand Down
75 changes: 75 additions & 0 deletions lib/connectors/liferay70.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@

'use strict';

var inherits = require('../inherits');
var invoker = require('../invoker');
var errors = require('../errors');
var Connector = require('./base');
var Promise = require('bluebird');

module.exports = Liferay70;

function Liferay70(portalURL, auth) {
Connector.call(this, portalURL, auth);
}

Liferay70.version = '7.0';

inherits(Liferay70, Connector, {

raw: function (payload) {
return invoker(this.portalURL, '/api/jsonws', this.auth, this.mangle(payload));
},

mangle: function (payload) {
return this.mangleCamelCase(this.mangleInstantiation(payload));
},

getUser: function () {
var auth = this.auth;
var login = auth.login;
var companyId = this.companyId;

return Promise.bind(this)
.then(function () {
if (companyId) return this.invoke({
"/user/get-user-by-email-address": {
emailAddress: login,
companyId: companyId
}
});
else throw new errors.NotFound();
})
.catch(errors.NotFound, function () {
if (!isNaN(+login)) return this.invoke({
"/user/get-user-by-id": {
userId: +login
}
});
else throw new errors.NotFound();
})
.catch(errors.NotFound, function () {
return this.invoke({
"/user/get-user-by-screen-name": {
screenName: login,
companyId: companyId
}
});
})
.then(function (user) {
if (user) return user;
else throw new errors.NotFound("Could not retrieve the user");
});
},

getUserSites: function () {
return {
"/group/get-user-sites-groups": {}
}
}

});

Liferay70.matches = function (buildnumber) {
return buildnumber >= 7000 && buildnumber < 7100; // 7000
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "liferay-connector",
"version": "0.8.1",
"version": "0.8.2",
"description": "Liferay JSON WS wrapper for Node and Titanium SDK",
"titaniumManifest": {
"guid": "b74f4463-69a6-20ae-0ef0-3033a20889de",
Expand Down

0 comments on commit f1e07d8

Please sign in to comment.