1 | jsx3.util.Logger.getLogger("org.isocat").info("Loading class[org.isocat.data.WS]"); |
---|
2 | |
---|
3 | /** |
---|
4 | * The WS class |
---|
5 | * @author Menzo.Windhouwer@mpi.nl |
---|
6 | */ |
---|
7 | jsx3.lang. Class.defineClass("org.isocat.data.WS", null,[], function (WS, WS_prototype) { |
---|
8 | |
---|
9 | /** |
---|
10 | * The class logger |
---|
11 | */ |
---|
12 | WS.log = jsx3.util.Logger.getLogger("org.isocat.data.WS"); |
---|
13 | |
---|
14 | /** |
---|
15 | * The WS user profile |
---|
16 | */ |
---|
17 | WS_prototype.profile; |
---|
18 | |
---|
19 | /** |
---|
20 | * The WS CDF document |
---|
21 | */ |
---|
22 | WS_prototype.doc; |
---|
23 | |
---|
24 | /** |
---|
25 | * Constructor |
---|
26 | */ |
---|
27 | WS_prototype.init = function (user) { |
---|
28 | org.isocat.data.WS.log.info("initialize WS[" + this + "]"); |
---|
29 | |
---|
30 | this.profile = user;//link to the user profile |
---|
31 | this.profile.ws(this); |
---|
32 | //link back |
---|
33 | org.isocat.data.WS.log.info("- WS user[" + this.profile + "]"); |
---|
34 | |
---|
35 | this.doc = jsx3.xml.CDF.Document.newDocument(); |
---|
36 | org.isocat.APP.getCache().setDocument(this.cacheId(), this.doc); |
---|
37 | org.isocat.data.WS.log.info("- WS CDF document[" + this.doc + "]"); |
---|
38 | |
---|
39 | org.isocat.data.WS.log.info("initialized WS[" + this + "]"); |
---|
40 | |
---|
41 | // create message |
---|
42 | var message = { |
---|
43 | jss: "org.pagebus.msg.Message", |
---|
44 | jssv: "1.0.0", |
---|
45 | header: { |
---|
46 | }, |
---|
47 | body: this |
---|
48 | }; |
---|
49 | |
---|
50 | // publish the message using PageBus |
---|
51 | window.PageBus.publish("org.isocat.data.WS.init", message); |
---|
52 | }; |
---|
53 | |
---|
54 | WS_prototype.cacheId = function () { |
---|
55 | return "WS-" + this.profile.user(); |
---|
56 | } |
---|
57 | |
---|
58 | WS_prototype.uri = function (format) { |
---|
59 | return "http://localhost:8080/isocat/rest/user/" + escape(this.profile.user()) + "/workspace" + format; |
---|
60 | } |
---|
61 | |
---|
62 | // CREATE |
---|
63 | |
---|
64 | // RETRIEVE |
---|
65 | WS_prototype.retrieve = function (params) { |
---|
66 | var uri = this.uri(".cdf"); |
---|
67 | if (org.isocat.view) { |
---|
68 | uri += "?view=" + escape(org.isocat.view); |
---|
69 | } |
---|
70 | if (params != null && typeof (params) != 'undefined') { |
---|
71 | if (uri.indexOf('?') < 0) { |
---|
72 | uri += "?"; |
---|
73 | } else { |
---|
74 | uri += "&"; |
---|
75 | } |
---|
76 | uri += params; |
---|
77 | } |
---|
78 | // load the WS |
---|
79 | org.isocat.asyncLoadCDFDocument(new jsx3.net.URI(uri), this.cacheId(), this, this.retrieved); |
---|
80 | return this.cacheId(); |
---|
81 | }; |
---|
82 | |
---|
83 | WS_prototype.retrieved = function (doc, req) { |
---|
84 | if (doc != null) { |
---|
85 | this.doc = doc; |
---|
86 | org.isocat.data.WS.log.info("The WS service call returned a valid response, stored in the cache[" + this.cacheId() + "]."); |
---|
87 | org.isocat.publish("org.isocat.WS.retrieved", this.user); |
---|
88 | } else { |
---|
89 | org.isocat.data.Group.log.info("The WS service call failed. The HTTP Status code is: " + req.getStatus()); |
---|
90 | org.isocat.publish("org.isocat.WS.retrieve-failed", this.user); |
---|
91 | } |
---|
92 | }; |
---|
93 | |
---|
94 | // UPDATE |
---|
95 | |
---|
96 | // DELETE |
---|
97 | }); |
---|