Ignore:
Timestamp:
05/22/11 21:55:04 (13 years ago)
Author:
gaba
Message:

changes in save
jsonw removed

Location:
MDService2/trunk/MDService2
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • MDService2/trunk/MDService2/WebContent/scripts/mdservice_model.js

    r1310 r1350  
    1111//var workspace;
    1212
     13// json for user and server data
    1314function Workspace(){
    14 
    15 };
    16 Workspace.save = function(type, query, id, iq){
     15        user_json = undefined;
     16        server_json = undefined;
     17};
     18Workspace.prototype.addquery = function(jsonquery, qsid){
     19        var qsjson = this.user_json["WorkspaceProfile"]["Querysets"][qsid];
     20        var queries = qsjson["Queries"]; //this.user_json["WorkspaceProfile"]["Querysets"][qsid]["Queries"];
     21        var iq = 0;
     22       
     23        if (queries == "null"){
     24                //this.user_json["WorkspaceProfile"]["Querysets"][qsid]["Queries"] = [{}];
     25                qsjson["Queries"] = [{}];
     26        } else {
     27                iq = queries.length;
     28        }
     29        //this.user_json["WorkspaceProfile"]["Querysets"][qsid]["Queries"][iq] = jsonq;
     30        qsjson["Queries"][iq] = jsonquery;
     31};
     32Workspace.prototype.addqueryset = function(name){
     33
     34        var id = $('#qts_select option').size();
     35        var dt = new Date();
     36        var str_time = dateFormat(dt);//dt.toString("yyyy-MM-dd HH:mm:ss");
     37       
     38        if (id == 0){
     39                this.user_json["WorkspaceProfile"]["Querysets"] = [{}];
     40        }
     41
     42        this.user_json["WorkspaceProfile"]["Querysets"][id] = {"name":name,"created":str_time , "Queries" : "null"};
     43       
     44};
     45Workspace.prototype.removequeryset = function(qsid){
     46        //var ind;
     47        //$.each(this.user_json["WorkspaceProfile"]["Querysets"], function(index,jdata){
     48        //      if (jdata == json){
     49        //              ind = index;
     50        //      }
     51        //});
     52        var size = this.user_json["WorkspaceProfile"].Querysets.length;
     53       
     54        for (var i=qsid;i<size-1;i++){
     55                this.user_json["WorkspaceProfile"].Querysets[i] = this.user_json["WorkspaceProfile"].Querysets[i+1];
     56        }
     57
     58        delete this.user_json["WorkspaceProfile"].Querysets[size-1];
     59        this.user_json["WorkspaceProfile"]["Querysets"].length = size-1;
     60        // set null string , if 0 querysets
     61        if (size == 1) {
     62                this.user_json["WorkspaceProfile"]["Querysets"] = "null";
     63        }
     64};
     65Workspace.prototype.getQuerysets = function(type){
     66        var json;
     67        if (type == "user"){
     68                return  this.user_json["WorkspaceProfile"]["Querysets"];
     69        }
     70        return  this.server_json["WorkspaceProfile"]["Querysets"];
     71};
     72
     73Workspace.prototype.getCustomTermsets = function(){
     74        var json;
     75        json = this.user_json["WorkspaceProfile"]["CustomTermsets"];
     76        return json;
     77};
     78Workspace.prototype.save = function(type){
     79        var JSONText;
     80
     81        JSONText = JSON.stringify(this.user_json["WorkspaceProfile"]);
     82        $.post("/MDService2/workspaceprofilesave/" + type + "/",{"data":JSONText},  function(data) {
     83        });
     84
     85};
     86Workspace.prototype.savequery = function(json, querysetname){
     87        var JSONText;
     88        var type = "user";
     89        var qdata = "/" + querysetname;
     90        JSONText = JSON.stringify(json);
     91       
     92        $.post("/MDService2/workspaceprofilesave/" + type + qdata,{"data":JSONText},  function(data) {
     93                if (json.id == 0){
     94                        json.id = $(data).text();
     95                        appendQueryUI(json,querysetname, $('#userqueries'));
     96                } else {
     97                        changeQueryUI(json,querysetname, $('#userqueries'));
     98                }
     99        });
     100};
     101/*Workspace.save = function(type, query, id, iq){
    17102        var JSONText;
    18103        var qdata = "/";
    19         /*
    20         if (type == "ADMIN"){
    21                 JSONText = JSON.stringify(json_admin["WorkspaceProfile"]);
    22         } else {
    23                 JSONText = JSON.stringify(jsonw["WorkspaceProfile"]);
    24         }
    25         */
    26         //var JSONText = JSON.stringify({"aa.a":"r"});
    27         //notifyUser(JSONText,'debug');
    28104       
    29105        JSONText = JSON.stringify(jsonw["WorkspaceProfile"]);
     
    32108        }
    33109        $.post("/MDService2/workspaceprofilesave/" + type + qdata,{"data":JSONText},  function(data) {
    34                 query.id = $(data).text();
    35                 jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq]["id"] = query.id;
    36                 appendQueryUI(jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq],iq, $('#userqueries'));
    37 //            alert("success");
     110                if (query != undefined){
     111                        if (query.id == 0){
     112                                query.id = $(data).text();
     113                                jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq]["id"] = query.id;
     114                                appendQueryUI(jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq],iq, $('#userqueries'));
     115                        }
     116                }
    38117        });
    39         //.success(function() { alert("second success"); })
    40     //.error(function(e) { alert("error"); })
    41     //.complete(function() { alert("complete"); });
    42 
    43 
    44 };
    45 /*
    46 Workspace.newQueryID = function(){
    47         var new_id;
    48        
    49         loadAdminFile();
    50         json_admin["Admin"]["maxqid"]  = parseInt(json_admin["Admin"]["maxqid"]) + 1;
    51         new_id = json_admin["Admin"]["maxqid"];
    52         Workspace.save("ADMIN");
    53         return new_id;
     118
    54119};
    55120*/
     
    72137        this.listid = "";
    73138        this.container = {};
     139        this.bookmark = 0;
    74140        // page
    75141        this.startItem = 1;
     
    83149        this.format = 'htmltable';
    84150        this.columns_widget = null;
     151       
     152        //vcr
     153        this.vcrid = 0;
    85154};
    86155
     
    141210        }
    142211        this.id = json.id;
    143 };
    144 
     212        this.vcrid = json.vcrid;
     213};
    145214Query.prototype.save = function(){
    146215        //queryset id
    147         var id = parseInt($("#qts_select option:selected").val());
     216        var qsid = parseInt($("#qts_select option:selected").val());
     217        //var qsname = $("#qts_select option:selected").text();
     218        //var qsjson = $("#qts_select option:selected").val();
     219        var qsjson = workspace.getQuerysets("user")[qsid];
     220        var jsonq = this.toJSON();
     221        if (this.id == 0){
     222                workspace.addquery(jsonq, qsid);//qsjson);
     223                workspace.savequery(jsonq, qsjson["name"]);
     224        } else {
     225                workspace.savequery(jsonq);
     226        }
     227};
     228/*
     229Query.prototype.save = function(){
     230        //queryset id
     231        var qsid = parseInt($("#qts_select option:selected").val());
    148232        var iq = 0;
    149         var queries = jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"];
     233        var queries = jsonw["WorkspaceProfile"]["Querysets"][qsid]["Queries"];
    150234       
    151235        //var iq = $('#userqueries').children().size();
    152         if (queries == "null"){
    153                 jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"] = [{}];
     236        var jsonq = this.toJSON();
     237        if (this.id == 0){
     238                if (queries == "null"){
     239                        jsonw["WorkspaceProfile"]["Querysets"][qsid]["Queries"] = [{}];
     240                } else {
     241                        iq = queries.length;
     242                }
     243                jsonw["WorkspaceProfile"]["Querysets"][qsid]["Queries"][iq] = jsonq;
     244                Workspace.save("USER", this, qsid, iq);
    154245        } else {
    155                 iq = queries.length;
    156         }
    157         // create queryID
    158         this.id = 0;//Workspace.newQueryID();//id + "_" + iq;
    159         var jsonq = this.toJSON();
    160         jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq] = jsonq;
    161         Workspace.save("USER", this, id, iq);
     246                $.each(jsonw["WorkspaceProfile"]["Querysets"][qsid]["Queries"], function(index,value){
     247                        if (value.id == jsonq.id){
     248                                iq = index;
     249                        }
     250                });
     251                jsonw["WorkspaceProfile"]["Querysets"][qsid]["Queries"][iq] = jsonq;
     252                Workspace.save("USER", this, qsid, iq);
     253        }
     254       
     255       
    162256        //appendQueryUI(jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq],iq, $('#userqueries'));
    163257       
    164258};
    165 
     259*/
    166260
    167261Query.prototype.getcolumnstext = function (){
     
    238332
    239333Query.prototype.publish = function() {
    240         $.post("/MDService2/virtualcollection/USER/" + this.id,"");
     334        //$.data("query",this);
     335        var q = this;
     336        if (q.vcrid == 0){
     337                $.get("/MDService2/virtualcollection/USER/" + this.id,"", function(data){
     338                        var id = parseInt($(data).children().children('virtualcollectionid').text());
     339                        q.vcrid = id;
     340                        q.save();
     341                });
     342        }
    241343};
    242344
     
    266368        //columns
    267369        var json_cols;
    268         var colls = this.columns;
    269         if (colls == "") {
     370        var cols = this.columns;
     371        if (cols == "") {
    270372                //json_cols = {};
    271373                json_cols = "null";
     
    299401                                 "maximumItems" : this.maximumItems,
    300402                                 "options" : json_options,
    301                                  "bookmark" : "0",
    302                                  "time" : str_time};
    303        
    304         jsonq.name = Query.fullformatstring(jsonq);
     403                                 "bookmark" : this.bookmark,
     404                                 "time" : str_time,
     405                                 "vcrid": this.vcrid};
     406       
     407        if (this.bookmark == "1") {
     408                qstring = Url.decode(qstring);
     409                var s = qstring.split(':');
     410                jsonq.name = s[s.length - 2] + ":" + s[s.length - 1];
     411        } else {
     412                jsonq.name = Query.fullformatstring(jsonq);
     413        }
    305414       
    306415        return jsonq;//JSON.stringify(jsonq);
  • MDService2/trunk/MDService2/WebContent/scripts/mdservice_ui.js

    r1273 r1350  
    3030                // get url parameters
    3131                url_params = getUrlVars();
     32                workspace = new Workspace();
    3233                // create searchclauses
    3334                //searchclauseset.addsearchclause(new SearchClause("","",""),"",0,0);
     
    363364         */
    364365        $('#querylist .cmd_save').live('click',  function(event) {
     366                // bookmark
     367                if ($(this).parents('.result').length > 0){
     368                        qstring = $(this).parent().find("a").attr('href');
     369                        qstring = qstring.substring(18,qstring.length);
     370                       
     371                        var q = new Query([],"",qstring,"");
     372                        q.bookmark = 1;
     373                        q.save();
     374                       
     375                }
     376        });
     377        /*     
     378        $('#querylist .cmd_save').live('click',  function(event) {
    365379               
    366380                var qid = "";
     
    420434                //$("#qs_select").append(new Option(Query.simplequerystring(qstring),iq));
    421435        });
     436        */
    422437        /*
    423438        $('#querylist .cmd-xml').live('click',  function(event) {
     
    504519                var id = $("#qts_select option:selected").val();
    505520                //notifyUser($('#qts_input').val() + $('#qts_input').text(),'debug');
    506                 jsonw["WorkspaceProfile"]["Querysets"][id]["name"] = $('#qts_input').val();
    507                        
     521                workspace.user_json["WorkspaceProfile"]["Querysets"][id]["name"] = $('#qts_input').val();
     522                workspace.save("USER");
     523               
    508524                $("#qts_select option:selected").text( $('#qts_input').val());
    509                 //saveWorkspace("USER");
    510                 Workspace.save("USER");
     525               
    511526        });
    512527        $('#qts_add').click(function(){
    513528                var new_name = "new_queryset";
    514529               
     530                workspace.addqueryset(new_name);
     531                workspace.save("USER");
     532                //todo
    515533                var id = $('#qts_select option').size();
    516                 var dt = new Date();
    517                 var str_time = dateFormat(dt);//dt.toString("yyyy-MM-dd HH:mm:ss");
    518                
    519                 if (id == 0){
    520                         jsonw["WorkspaceProfile"]["Querysets"] = [{}];
    521                 }
    522        
    523                 jsonw["WorkspaceProfile"]["Querysets"][id] = {"name":new_name,"created":str_time , "Queries" : "null"};
    524                
    525                 //saveWorkspace("USER");
    526                 Workspace.save("USER");
    527                 //todo
    528                
    529                 //loadWorkspace(jsonw["WorkspaceProfile"]["Querysets"]);
    530534                $("#qts_select").append(new Option(new_name, id));
    531535                $("#qts_select").find('option').attr("selected","false");
     
    537541               
    538542                //if (count > 1){
     543                /*
    539544                        var id = parseInt($("#qts_select option:selected").val());
    540545                        var size = jsonw["WorkspaceProfile"].Querysets.length;
     
    556561                       
    557562                //}
     563                */
     564                var qsid = parseInt($("#qts_select option:selected").val());
     565                //var json = $("#qts_select option:selected").val();
     566                workspace.removequeryset(qsid);
     567                workspace.save("USER");
     568                //update
     569                //loadQuerysets(jsonw["WorkspaceProfile"]["Querysets"],"user");
     570                loadQuerysets("user");
    558571        });
    559572       
     
    663676        $('#serverqueries .cmd_load').live('click',function(event){
    664677               
    665                 var id = parseInt( $("#serverqts_select option:selected").val());
    666                 var str = $(this).parent().find('a').attr("href");
    667                 var iq = parseInt(str.substring(9));
    668                 var json = jQuery.parseJSON($("#serverqs").attr("data"));
    669                 var q = json["WorkspaceProfile"]["Querysets"][id]["Queries"][iq];
    670                
     678                //var id = parseInt( $("#serverqts_select option:selected").val());
     679                //var str = $(this).parent().find('a').attr("href");
     680                //var iq = parseInt(str.substring(9));
     681                //var json = jQuery.parseJSON($("#serverqs").attr("data"));
     682                //var q = json["WorkspaceProfile"]["Querysets"][id]["Queries"][iq];
     683               
     684                var q = $(this).closest('.cmds-elem-plus').data("queryjson");
    671685                loadQuery(q);
    672686        });
    673687        $('#userqueries .cmd_load').live('click',function(event){
    674688               
    675                 var id = parseInt( $("#qts_select option:selected").val());
    676                 var str = $(this).parent().find('a').attr("href");
    677                 var iq = parseInt(str.substring(7));
    678                 var q = jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][iq];
    679                
     689                //var id = parseInt( $("#qts_select option:selected").val());
     690                //var str = $(this).parent().find('a').attr("href");
     691                //var iq = parseInt(str.substring(7));
     692                //var q = workspace.getQuerysets("user")[id]["Queries"][iq];
     693                var q = $(this).closest('.cmds-elem-plus').data("queryjson");
    680694                loadQuery(q);
    681695        });
     
    685699                var str = $(this).parent().find('a').attr("href");
    686700                var iq = parseInt(str.substring(7));
    687                 var size = jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"].length;
     701                var size = workspace.user_json["WorkspaceProfile"]["Querysets"][id]["Queries"].length;
    688702               
    689703                for (var i=iq;i<size-1;i++){
    690                         jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][i] = jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][i+1];
    691                 }
    692        
    693                 delete jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"][size-1];
    694                 jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"].length = size-1;
     704                        workspace.user_json["WorkspaceProfile"]["Querysets"][id]["Queries"][i] = workspace.user_json["WorkspaceProfile"]["Querysets"][id]["Queries"][i+1];
     705                }
     706       
     707                delete workspace.user_json["WorkspaceProfile"]["Querysets"][id]["Queries"][size-1];
     708                workspace.user_json["WorkspaceProfile"]["Querysets"][id]["Queries"].length = size-1;
    695709               
    696710                if (size == 1){
    697                         jsonw["WorkspaceProfile"]["Querysets"][id]["Queries"] = "null";
     711                        workspace.user_json["WorkspaceProfile"]["Querysets"][id]["Queries"] = "null";
    698712                }
    699713               
    700714                //saveWorkspace("USER");
    701                 Workspace.save("USER");
    702                 loadQuerysets(jsonw["WorkspaceProfile"]["Querysets"],"user");
     715                workspace.save("USER");
     716                loadQuerysets("user");
    703717                //$("#qs_select option").remove();
    704718                //$("#qs_select option").first().attr("selected","true");
  • MDService2/trunk/MDService2/WebContent/scripts/mdservice_ui_detail.js

    r1274 r1350  
    114114                        selectionlistset.add(selectionlist);
    115115                        //selectionlist.listwidget.query = query;
    116                         selectionlist.load(jsonw["WorkspaceProfile"]["CustomTermsets"]);
     116                        selectionlist.load(workspace.getCustomTermsets());//jsonw["WorkspaceProfile"]["CustomTermsets"]);
    117117                        $(this.content).find('.cmd_reload').data('selectionlist',selectionlist);
    118118                        if (query.columns == ""){
  • MDService2/trunk/MDService2/WebContent/scripts/mdservice_ui_load.js

    r1273 r1350  
    4545function loadWorkspaceProfiles(){
    4646        //empty json
    47         jsonw = {'WorkspaceProfile':{'CustomTermsets':'null','Termsets':'null','Repositories':'null','Querysets':'null','created':'null','lastchanged':'null','profilename':'null'}};
     47        workspace.user_json = {'WorkspaceProfile':{'CustomTermsets':'null','Termsets':'null','Repositories':'null','Querysets':'null','created':'null','lastchanged':'null','profilename':'null'}};
    4848        $('#qts_input').val("");
    4949       
     
    5151        jQuery.getJSON("/MDService2/workspaceprofile/user",function(data){
    5252                notifyUser(data['WorkspaceProfile'],'debug');
    53                                 jsonw = preprocessJSON(data);
     53                                workspace.user_json = preprocessJSON(data);
    5454                               
    5555                                jQuery.getJSON("/MDService2/workspaceprofile/server",function(data){
    5656                                        notifyUser(data['WorkspaceProfile'],'debug');
    5757                                                        var json = preprocessJSON(data);
     58                                                        workspace.server_json = json;
    5859                                                        $("#serverqs").attr("data",JSON.stringify(json));
    59                                                         loadQuerysets(json["WorkspaceProfile"]["Querysets"],"server");
     60                                                        //loadQuerysets(json["WorkspaceProfile"]["Querysets"],"server");
     61                                                        loadQuerysets("server");
    6062                                                        loadRepositories(json["WorkspaceProfile"]["Repositories"]);
    6163                                                        loadCollections(true);                         
     
    6769                                        });
    6870
    69                                 loadQuerysets(jsonw["WorkspaceProfile"]["Querysets"],"user");
     71                                //loadQuerysets(workspace.user_json["WorkspaceProfile"]["Querysets"],"user");
     72                                loadQuerysets("user");
    7073                                //loadTermsets(jsonw["WorkspaceProfile"]["CustomTermsets"]);
    7174                                createTooltip(this);
     
    293296        query.load(json);
    294297        $(qs).find("[href='"+ id + "_" + i + "']").closest('.cmds-elem-plus').data('query',query);
     298        $(qs).find("[href='"+ id + "_" + i + "']").closest('.cmds-elem-plus').data('queryjson',json);
     299        $(qs).find('.input-name').data('queryjson',json);
    295300        $(qs).find('.detail').css({'z-index' : '1000'});
    296301       
     
    301306                };
    302307                if (ev.which === 13) {
     308                        $(this).data("queryjson").name = $(this).val();
     309                        Workspace.save("user");
     310                        //var query = new Query();
     311                        //query.load($(this).data("queryjson"));
     312                        //query.save();
     313                        /*
    303314                        var id = parseInt( $("#qts_select option:selected").val());
    304315                        $(this).parent().parent().parent().find('a').text($(this).val());
     
    309320                        //saveWorkspace("USER");
    310321                        Workspace.save("USER");
     322                        */
    311323                        evStop();
    312324                }
     
    326338       
    327339}
    328 function loadQuerysets(json, type) {
    329        
     340function loadQuerysets(type) {
     341       
     342        var json = workspace.getQuerysets(type);
    330343        var $select;
    331344        if (type == "user") {
     
    350363                        var id = parseInt($select.find("option:selected").val());
    351364                        var jsonq = json[id];
     365                        //var jsonq = $select.find("option:selected").val();
    352366                       
    353367                        if (type == "user") {
     
    365379                                var id = parseInt($select.find("option:selected").val());
    366380                                var jsonq = json[id];
    367                                
     381                                //var jsonq = $select.find("option:selected").val();
     382                                       
    368383                                if (type == "user") {
    369384                                        $('#qts_input').val(jsonq["name"]);
  • MDService2/trunk/MDService2/WebContent/scripts/mdservice_ui_settings.js

    r1273 r1350  
    1212
    1313//VARIABLES
    14 var jsonw, json_admin;
     14//var jsonw, json_admin;
     15var workspace;
     16var json_admin;
    1517var url_params;
    1618var local_collections = false;
  • MDService2/trunk/MDService2/src/eu/clarin/cmdi/mdservice/action/WorkspaceAction.java

    r1310 r1350  
    8888        public static String USER = "user";
    8989        public static String SERVER = "server";
     90       
     91        // save element type
     92        public static String SE_WORKSPACE = "workspace";
     93        public static String SE_QUERY = "query";
     94       
    9095        // administration query identification
    9196        public static String ADMIN = "admin";
     
    103108        //private String actionkey;
    104109        private String data;
    105         private String type;
     110        private String type;  //workspacetype
     111        private String elementtype;
    106112        private String qid;
     113        private String qsid;
    107114        //private String format;
    108115        //private String userMsg;
     
    138145        }
    139146
     147        public String getEelemnttype(){
     148                return elementtype;
     149        }
     150
     151        public void setElementtype(String elementtype) {
     152                this.elementtype = elementtype;
     153        }
     154
    140155        public String getType() {
    141156                return type;
     
    149164                return qid;
    150165        }
    151 
     166       
    152167        public void setQid(String qid) {
    153168                this.qid = qid;
    154169        }
    155170
    156         public WorkspaceAction () {             
     171        public void setQsid(String qsid) {
     172                this.qsid = qsid;
     173        }
     174       
     175        public String getQsid() {
     176                return qsid;
     177        }
     178
     179        public WorkspaceAction () {     
     180                this.elementtype = WorkspaceAction.SE_WORKSPACE;
    157181                workspacefilename = Admin.getConfig().getProperty("workspaceprofile.path") + Admin.getConfig().getProperty("workspace.file");
    158182                if (workspace_doc == null){
     
    423447            XPathExpression expr;
    424448            String xpath_expr = "";
    425                 xpath_expr = "//WorkspaceProfile/Querysets/item/Queries/item/id[.='" + from_id + "']";
     449                //xpath_expr = "//WorkspaceProfile/Querysets/item/Queries/item/id[.='" + from_id + "']";
     450            xpath_expr = "//item/id[.='" + from_id + "']";
    426451                expr = xpath.compile(xpath_expr);
    427452                Object result = null;
     
    474499
    475500        }
     501        public String getXMLRootName(){
     502                String rootname = "WorkspaceProfile";
     503                if (this.elementtype.equals(WorkspaceAction.SE_QUERY)){
     504                        rootname = "Query";
     505                }
     506                return rootname;
     507        }
     508        public  String  DocumentReplaceNewElement(Document new_doc) throws XPathExpressionException{
     509                String newid = "";
     510                if (this.elementtype.equals(WorkspaceAction.SE_WORKSPACE)){
     511                        NodeList wsnodelist = (NodeList) getWorkspace();
     512                // remove
     513                //childeNode
     514                if (wsnodelist.getLength() > 0){
     515                        ((Node)wsnodelist.item(0)).getParentNode().removeChild(wsnodelist.item(0));
     516                }
     517                //String qidstring = "";
     518                //if (qid.equals("0")) {
     519                //    newid = createNewQid();
     520                //    changeQueryId(new_doc,qid,newid);
     521                //}
     522               
     523                Node node = new_doc.getFirstChild();
     524                Node node2 = workspace_doc.adoptNode(node.cloneNode(true));
     525                ((Element)node2).setAttribute("user", getUserName());
     526                workspace_doc.getElementsByTagName("WorkspaceProfiles").item(0).appendChild(node2);
     527                }
     528                if (this.elementtype.equals(WorkspaceAction.SE_QUERY)){
     529// new query
     530                        Node node = new_doc.getFirstChild();
     531                        if (this.qid.equals("0")){
     532                                newid = createNewQid(); 
     533                                new_doc.getElementsByTagName("id").item(0).setTextContent(newid);
     534                        Element root = workspace_doc.getDocumentElement();
     535                        Node node2 = workspace_doc.adoptNode(node.cloneNode(true));
     536                        node2 = workspace_doc.renameNode(node2, "", "item");
     537                   // apend to specific queryset
     538                                NodeList wsnodelist = (NodeList) getQueryset();
     539                        wsnodelist.item(0).appendChild(node2);
     540                        }
     541                       
     542                        else {
     543                                // edit existing query
     544                                NodeList wsnodelist = (NodeList) getQuery();
     545                        // remove
     546                        //childeNode
     547                        if (wsnodelist.getLength() > 0){
     548                                //Element root = workspace_doc.getDocumentElement();
     549                                Node node2 = workspace_doc.adoptNode(node.cloneNode(true));
     550                                node2 = workspace_doc.renameNode(node2, "", "item");
     551                                Node qnode  = (Node)wsnodelist.item(0);
     552                                //root.replaceChild(node2,(Node)wsnodelist.item(0));   
     553                               
     554                                Element parentElement = (Element)qnode.getParentNode();
     555                                        parentElement.insertBefore(node2, qnode);
     556                                        qnode.getParentNode().removeChild(qnode);
     557                                        parentElement.normalize();
     558                        }
     559                        }
     560                }
     561                return newid;
     562        }
     563       
     564        //todo
     565        public void parseDataInit(JSONObject json){
     566                // workspaceelement
     567                if (json.containsKey("Querysets")) {
     568                        this.setQid("0");
     569                        this.setElementtype(WorkspaceAction.SE_WORKSPACE);
     570                } else {
     571                        // Queryelement
     572                        this.setElementtype(WorkspaceAction.SE_QUERY);
     573                        this.setQid(json.getString("id"));
     574                        //this.//
     575                }
     576
     577        }
    476578        public String save() throws ParserConfigurationException, SAXException, IOException, DOMException, XPathExpressionException, TransformerException, TransformerFactoryConfigurationError{
    477579               
     
    480582        XMLSerializer serializer = new XMLSerializer();
    481583                JSON json = JSONSerializer.toJSON( jsonData );
    482                 serializer.setRootName("WorkspaceProfile");     
     584                // init qid, elementtype
     585                parseDataInit((JSONObject)json);
     586                serializer.setRootName(getXMLRootName()); //"WorkspaceProfile");       
    483587                serializer.setElementName("item");
    484588        serializer.setTypeHintsEnabled(false);
     
    490594        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    491595        DocumentBuilder builder = factory.newDocumentBuilder();
    492         Document d = builder.parse( is_xml );
     596        Document new_doc = builder.parse( is_xml );
    493597        // set user
    494598        //((Element)d.getFirstChild()).setAttribute("user", getServletRequest().getRemoteUser());
    495         NodeList wsnodelist = (NodeList) getWorkspace();
    496         // remove
    497         //childeNode
    498         if (wsnodelist.getLength() > 0){
    499                 ((Node)wsnodelist.item(0)).getParentNode().removeChild(wsnodelist.item(0));
    500         }
    501         String qidstring = "";
    502         if (qid.equals("0")) {
    503             qidstring = createNewQid();
    504             changeQueryId(d,qid,qidstring);
    505         }
     599        String newid = DocumentReplaceNewElement(new_doc);
    506600       
    507         Node node = d.getFirstChild();
    508         Node node2 = workspace_doc.adoptNode(node.cloneNode(true));
    509         ((Element)node2).setAttribute("user", getUserName());
    510         workspace_doc.getElementsByTagName("WorkspaceProfiles").item(0).appendChild(node2);
    511601
    512602      //TODO
     
    516606        //javax.xml.transform.stream.StreamSource s = new StreamSource(src);
    517607        //InputStream in = s.getInputStream();
    518                 this.setResultStream(createStream(qidstring));//(InputStream)(new ByteArrayInputStream(qidstring.getBytes())));
     608                this.setResultStream(createStream(newid));//(InputStream)(new ByteArrayInputStream(qidstring.getBytes())));
    519609               
    520610               
     
    645735        }
    646736       
    647            
     737        public Object getQuery() throws XPathExpressionException{
     738               
     739                XPathFactory factory = XPathFactory.newInstance();
     740            XPath xpath = factory.newXPath();
     741            XPathExpression expr;
     742                        expr = xpath.compile("//Profiles/WorkspaceProfiles/WorkspaceProfile/Querysets/item/Queries/item[id='" + this.qid + "']");
     743                //expr = xpath.compile("//item[@id='" + this.qid + "']");
     744                        //expression is evaluated with respect to a certain context node which is doc.
     745                        Object result = null;
     746                        try{
     747                        result = expr.evaluate(workspace_doc, XPathConstants.NODESET);
     748                        } catch(Exception e){
     749                               
     750                        }
     751
     752             return result;
     753        }
     754
     755        public Object getQueryset() throws XPathExpressionException{
     756               
     757                XPathFactory factory = XPathFactory.newInstance();
     758            XPath xpath = factory.newXPath();
     759            XPathExpression expr;
     760                        expr = xpath.compile("//Profiles/WorkspaceProfiles/WorkspaceProfile/Querysets/item[name='" + this.qsid + "']/Queries");
     761                        //expression is evaluated with respect to a certain context node which is doc.
     762                        Object result = null;
     763                        try{
     764                        result = expr.evaluate(workspace_doc, XPathConstants.NODESET);
     765                        } catch(Exception e){
     766                               
     767                        }
     768
     769             return result;
     770        }
     771
    648772        @Override
    649773        public void prepare() throws Exception {               
  • MDService2/trunk/MDService2/src/struts.xml

    r1310 r1350  
    190190                           <param name="format">JSON</param>
    191191                           <param name="type">{1}</param>
    192                            <param name="qid">{2}</param>
     192                           <param name="qsid">{2}</param>
    193193                           <!-- <param name="data">{1}</param> 
    194194                           <param name="actionkey"></param>     
Note: See TracChangeset for help on using the changeset viewer.