source: DASISH/t5.6/client/branches/webannotator-basic/chrome/markingcollection/content/markingcollection/annotator-service/annotations.wired.marker.js @ 5442

Last change on this file since 5442 was 5442, checked in by stephanie.roth@snd.gu.se, 10 years ago

Added log output for XML representation that is posted through the client.

File size: 8.7 KB
Line 
1var annotationProxy = (function() {
2    return {
3        defaltDatabase : 'dwan',
4        /***
5         * Get current user info
6         * @returns {undefined} false if user in not loged in. user object if loged in
7         */
8        getLoggedInInfo: function(callback) { 
9            var authURL = annotationFramework.getBackend() + "/api/authentication/principal";
10            $.ajax({
11                type: 'GET',
12                url: authURL,
13                dataType: "xml",
14                timeout: 4000, // In order to be able to catch server inaccessibility, e.g. due to security restrictions.
15                success: function(xml ,textStatus, jqXHR) {
16                   $xml = $.parseXML(jqXHR.responseText);
17                   var user = new Object();
18                   user.dislayName = jQuery($xml).find('displayName').text();
19                   
20                   user.email = jQuery($xml).find('eMail').text();
21                   callback.call(undefined, {status:jqXHR.status, user:user});
22                },
23                error: function(jqXHR, status, thrownError) {
24                    // alert("statusCode in ajax error method: " + jqXHR.status);
25                    callback.call(undefined, {status: jqXHR.status});
26                }
27            });
28           
29            var user_placeholder = {
30                URI: 'https://lux17.mpi.nl/ds/webannotator/api/users/00000000-0000-0000-0000-0000000009999',
31                uid: '00000000-0000-0000-0000-0000000009999',
32                dislayName: 'Test Testsson',
33                eMail: 'test@test.com'
34            }; 
35
36            //return user_placeholder;
37        },
38        getAnnotations: function(url) {
39            annotationProxy.log('getAnnotations for: ' + url);
40
41            annotationFramework.getAnnotations(url,
42                function(annotations) {
43                    annotationProxy.log('got annotations ');
44                    annotationProxy.log(annotations);
45
46                    $.each(annotations, function(index, annotationURL) {
47                        annotationFramework.getAnnotation(annotationURL, function(result) {
48                            annotationProxy.log('checking if annotation exist in DB:');
49                            annotationProxy.log(result);
50
51                            //check if this annotation is already in the one of the local databases
52                            if (bitsObjectMng.Database._dasish_aid_exists(annotationProxy.defaltDatabase, result.dasish_aid, true)) {
53                                annotationProxy.log('AID already in database '+annotationProxy.defaltDatabase+': ' + result.dasish_aid);
54                            }else if(bitsObjectMng.Database._dasish_aid_exists('_uncategorized', result.dasish_aid, true)){
55                                annotationProxy.log('AID already in database _uncategorized: ' + result.dasish_aid);
56                            } else {
57                                annotationProxy.log('Adding annotation to database : ' + result.dasish_aid);
58                                bitsObjectMng.Database.addObject(result, annotationProxy.defaltDatabase, undefined);
59                            }
60                        });
61                    });
62                }
63            );
64        },
65        postAnnotation: function(om_object) {
66            var annotation = om_object2annotation(om_object);
67            annotationProxy.log("\n\nFull content of XML representation that is posted:\n\n" + annotation + "\n\n++++ end of XML representation content ++++\n\n");
68            annotationFramework.postAnnotation(annotation, om_object.oid, 
69                function(aid){
70                    annotationProxy.log('Annotation posted and returned AID: '+aid);
71                    annotationProxy.log('Geting target list for posting cache...');
72                    annotationFramework.getTargets(aid, 
73                        function(targets){
74                            //POST cache representation for HTML
75                            var htmlDump = annotationProxy.getCurrentHtmlDocument();
76                            var cacheMetadata = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>\n'+
77                                                '<cashedRepresentationInfo xmlns="http://www.dasish.eu/ns/addit" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" \n'+
78                                                '    URI="tmpNewCacheURI" xsi:schemaLocation="http://www.dasish.eu/ns/addit https://svn.clarin.eu/DASISH/t5.6/schema/trunk/annotator-schema/src/main/resources/DASISH-schema.xsd">\n'+
79                                                '    <mimeType>text/html</mimeType>\n'+
80                                                '    <tool>DWAN</tool>\n'+
81                                                '    <type>html</type>\n'+
82                                                '</cashedRepresentationInfo>';
83                            var cacheMimeType = 'text/html';
84                            $.each(targets, function(index, targetURL){
85                                var xpointer = encodeURIComponent(om_object_xpointer(om_object));
86                               
87                                var xpointer = xpointer.replace(/%/g,'--');
88                                annotationProxy.log(xpointer);
89                                targetURL += '/fragment/'+xpointer+'/cached';
90                               
91                                //cache html-dump
92                                annotationFramework.postCache(targetURL, cacheMetadata, htmlDump, cacheMimeType);
93                            });
94                    });
95                });
96        },
97        updateAnnotation: function(om_object) {
98            var aid = this.getAidFromOid(om_object.oid);
99            this.log('updateAnnotation : ' + JSON.stringify(om_object));
100            this.log('UPDATED ANNOTATION AS XML (aid: ' + aid + ')');
101            var xml = om_object_annotation_body(om_object);
102
103            this.log(xml);
104
105            annotationFramework.putAnnotation(aid, xml);
106        },
107        updateFullAnnotation: function(om_object) {
108            var aid = this.getAidFromOid(om_object.oid);
109            annotationFramework.getAnnotationXml(aid, function(annotation){
110                //update the annotation
111                var note = om_object.oid_property.match(/<NOTE>(.+?)<\/NOTE>/)[1];
112                annotation = $.parseXML(annotation);
113                $(annotation).find('headline').text(om_object.oid_title);
114                $(annotation).find('body').find('xhtml\\:span').text(note);
115               
116                var xmlString = (new XMLSerializer()).serializeToString(annotation);
117
118                annotationFramework.putFullAnnotation(aid, xmlString);
119            });
120        },
121        openRemoteCache: function(event){
122            this.log(event);
123            var oid = bitsAutocacheService.bitsItemView.object.oid;
124            var cacheUrl = this.getCacheURL(oid);
125           
126           
127        },
128        getCacheURL: function(oid, tabbed){
129            var aid = this.getAidFromOid(oid);
130            annotationFramework.getTargets(aid, function(targets){
131                var targetURL = targets[0];
132                annotationProxy.log('targets');
133                annotationProxy.log(targets[0]);
134                annotationFramework.getCacheURL(targetURL, function(cacheURL){
135                    cacheURL += '/stream';
136                    annotationProxy.log('cacheURL');
137                    annotationProxy.log(cacheURL);
138                   
139                    bitsAutocacheService.Common.loadURL(cacheURL,tabbed);
140                });
141            });
142           
143        },
144        getAidFromOid: function(oid) {
145            var aSql = 'SELECT dasish_aid FROM om_object WHERE oid="' + oid + '"';
146            var rtn; 
147
148            if(bitsObjectMng.Database._idExists('local', oid, true)){
149                rtn = bitsObjectMng.Database.selectB('local', aSql);
150            }else if(bitsObjectMng.Database._idExists('_uncategorized', oid, true)){
151                 rtn = bitsObjectMng.Database.selectB('_uncategorized', aSql);
152            }
153           
154            return rtn[0].dasish_aid;
155        },
156        getCurrentHtmlDocument : function(){
157            var xmlS = new XMLSerializer();
158            var temp = xmlS.serializeToString(bitsAutocacheService.gBrowser.contentDocument);
159            return temp;
160        },
161        log: function(message) {
162            //log to console
163            if (typeof Firebug != 'undefined' && Firebug.Console) {
164                Firebug.Console.log(message);
165            }
166            //log this to the local proxy
167            /*
168             $.ajax({
169             type: "POST",
170             url: 'http://localhost/annotations/annotator-service/test/proxy.php',
171             data: {log: 'true', message: message}
172             });
173             */
174        }
175    }
176}());
Note: See TracBrowser for help on using the repository browser.