forked from sachbalag/ibm-maximo-api
/
maximofactory.js
122 lines (103 loc) · 2.43 KB
/
maximofactory.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
'use strict';
module.exports = MaximoFactory;
var ResourceObject = require('./resources/resourceobject');
var InvalidArgumentError = require('./error/error');
var events = require('events');
var url = require('url');
var AuthConnector = require('./resources/connectors/authconnector');
/**
@typedef MaximoProperties
@type {object}
@property {string} protocol
@property {string} hostname
@property {number} port
@property {string} user
@property {string} password
@property {string} tenantcode
@property {string} auth_scheme
@property {string} authtype
@property {boolean} islean
*/
/**
*
* Creates an object for exposing Maximo OSLC API
*
* @param {MaximoProperties} options
* @param cookie
* @param callback
* @returns {MaximoFactory}
* @constructor
*/
function MaximoFactory(options,cookie,callback)
{
this.protocol = options.protocol;
this.hostname = options.hostname;
this.port = options.port;
this.user = options.user;
this.password = options.password;
this.islean = 0;
this.tenantcode = options.tenantcode;
this.auth_scheme = options.auth_scheme;
this.authType = options.authtype;
this.cookie = cookie;
this.isCookieSet = this.cookie ? true : false;
if(this.authType && this.authType == "form")
{
this.authPath = this.auth_scheme+"/j_security_check";
}
if(options.islean != null)
{
this.islean = options.islean;
}
console.log("### islean "+this.islean);
this.resturl = url.parse(this.protocol+"://"+this.user+":"+this.password+"@"+this.hostname+":"+this.port);
this.resturl.auth_scheme = this.auth_scheme;
if(callback != null)
{
if(this.hostname === "" || this.user === "" || this.password === "")
{
callback(new Error("Invalid null arguments.",""));
}
}
return this;
}
/**
*
* @returns {*}
*/
MaximoFactory.prototype.authenticate = function()
{
this.authC = new AuthConnector(this.resturl);
this.authC.authType = this.authType;
return this.authC.authenticate(this.authC);
};
/**
*
* @param mbo
* @returns {ResourceObject}
*/
MaximoFactory.prototype.resourceobject = function(mbo)
{
//return new ResourceSet(this.resturl,this.user,this.password,mbo);
return new ResourceObject(this,mbo);
};
/**
*
* @returns {string|*}
*/
MaximoFactory.prototype.publicuri = function()
{
return this.hostname;
};
/**
*
* @returns {MaximoFactory.user|*}
*/
MaximoFactory.prototype.user = function()
{
return this.user;
};
/**
*
*/
MaximoFactory.prototype.isCookieSet;