Changeset 1852


Ignore:
Timestamp:
04/04/12 08:38:32 (12 years ago)
Author:
gaba
Message:

cache changes

Location:
MDService2/branches/MDService_simple3
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • MDService2/branches/MDService_simple3/WebContent/scripts/mdservice_ui_load.js

    r1681 r1852  
    5656
    5757        // server profile first - options needed
    58         jQuery.getJSON("/MDService2/workspaceprofile/json/server",function(sdata){
     58        jQuery.getJSON("/MDService2/workspaceprofile/server?format=json",function(sdata){
    5959                                //notifyUser(sdata['WorkspaceProfile'],'debug');
    6060                                var json = preprocessJSON(sdata);
     
    7070                               
    7171                                // USER WORKSPACEPROFILE
    72                                 jQuery.getJSON("/MDService2/workspaceprofile/json/user",function(data){
     72                                jQuery.getJSON("/MDService2/workspaceprofile/user?format=json",function(data){
    7373                                                        notifyUser(data['WorkspaceProfile'],'debug');
    7474                                                        workspace.user_json  = preprocessJSON(data);
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/FCSAction.java

    r1835 r1852  
    5151         * Properties to be filled by Struts with according request-parameters
    5252         */     
    53         /*
    54         private String q;
    55         private String version;
    56         private String operation;
    57         private String query;
    58         private String scanClause;
    59         private int startRecord;
    60         private int maximumRecords;
    61         private String recordPacking;
    62         private String recordSchema;
    63         private String recordXPath;
    64         private int resultSetTTL;
    65         private String sortKeys;
    66         private String stylesheet;     
    67         private String x_cmd_repository;
    68         private String x_cmd_collections;
    69         private Set paramSet;
    70 */
     53       
    7154        private String x_content;
    7255        private Map<String,String[]> fcsparams;
     
    7861       
    7962        //TODO cache after analysis ?
     63        /*
    8064        @Override
    8165        public String getCache() {
    8266                return Cache.SKIP;
    8367        }
    84        
     68        */
    8569       
    8670        @Override
     
    180164                }
    181165                if (params.get("cache") == null){
    182                         addParam("cache",Cache.SKIP);
     166                        addParam("cache",Cache.USE);
    183167                }
    184168               
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/GenericAction.java

    r1832 r1852  
    8282        }
    8383
     84        public String getOperation() {
     85                return getParam("operation");
     86        }
     87       
    8488        /**
    8589         * Empty implementation, subclasses have to decide themselves, which proxy to take.
     
    464468         */
    465469       
    466          public String getRequestKey() {
    467                         String key="";
    468                         if (getActionkey()!=null) {
    469                                 key += getActionkey() + "//-" ;
    470                         }else {
    471                                 key +="//-" ;
    472                         }
    473                         if (getQuery()!=null) {
    474                                 key += getQuery() + "//-" ;
    475                         } else {
    476                                 key +="//-" ;
    477                         }
    478                         if (getCollections()!=null) {
    479                                 key += getCollections() + "//-";
    480                         } else {
    481                                 key +="//-" ;
    482                         }
    483                         if (this.getStartRecord()!=null) {
    484                                 key += getStartRecord() + "//-";
    485                         }
    486                                 else{
    487                                         key +="//-" ;
    488                         }
    489                         if (getMaximumRecords()!=null) {
    490                                 key += getMaximumRecords() + "//-";
    491                         }
    492                         else{
    493                                 key +="//-" ;
    494                         }
    495                        
    496                         key += getRepository()  + "//-";
    497                         key += getMaxdepth()  + "//-";
    498                        
    499                         if (getLang()!=null) {
    500                                 key += getLang() + "//-";
    501                         }else{
    502                                 key +="//-" ;
    503                         }                       
    504 
    505                 return key;
    506         }
     470        public String getRequestKey() {
     471                String key="";
     472                if (getActionkey()!=null) {
     473                        key += getActionkey() + "//-" ;
     474                }else {
     475                        key +="//-" ;
     476                }
     477                if (!getQuery().equals("")) {
     478                        key += getQuery() + "//-" ;
     479                } else {
     480                        key += getScanClause() + "//-" ;
     481                }
     482                key += getOperation() + "//-";
     483               
     484                key += getCollections() + "//-";
     485               
     486                key += getStartRecord() + "//-";
     487               
     488                key += getMaximumRecords() + "//-";
     489               
     490                key += getRepository()  + "//-";
     491                key += getMaxdepth()  + "//-";
     492               
     493                key += getLang() + "//-";
     494               
     495        return key;
     496}
    507497       
    508498         
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/action/SRUAction.java

    r1832 r1852  
    4141         * Properties to be filled by Struts with according request-parameters
    4242         */     
    43         /*
    44         private String q;
    45         private String version;
    46         private String operation;
    47         private String query;
    48         private String scanClause;
    49         private int startRecord;
    50         private int maximumRecords;
    51         private String recordPacking;
    52         private String recordSchema;
    53         private String recordXPath;
    54         private int resultSetTTL;
    55         private String sortKeys;
    56         private String stylesheet;     
    57         private String x_cmd_repository;
    58         private String x_cmd_collections;
    59         private Set paramSet;
    60 */
    6143       
    6244        private static int OP_SEARCHRETRIEVE = 1;
     
    6648       
    6749        //TODO cache after analysis ?
     50        /*
    6851        @Override
    6952        public String getCache() {
    7053                return Cache.SKIP;
    7154        }
     55        */
    7256       
    7357        @Override
     
    9074        }
    9175       
     76        /*
    9277        public String getOperation() {
    9378                if (getParams().get("operation") == null){
     
    9681                return getParam("operation");
    9782        }
    98        
     83        */
    9984         protected final static HashMap<String,Integer> operation_code = new HashMap<String,Integer>();
    10085         static
     
    11499                return "";
    115100        }
    116 /*
    117         @Override
    118         protected void setDefaultParams() {             
    119                 // set defaults
    120         /*      if ( params.get("version") == null){
    121                         addParam("version","1.2");
    122                 }
    123                 if ( params.get("operation") == null){
    124                         addParam("operation","searchRetrieve");
    125                 }
    126                 //q=query                       
    127                 if (getQ() != null) {
    128                         addParam("q",getQ());
    129                         addParam("query",getQ());
    130                 } else {
    131                         addParam("q",this.getParam("query"));
    132                 }
    133                
    134                 if ( params.get("startRecord") == null){
    135                         addParam("startRecord","1");
    136                 }
    137                 if ( params.get("maximumRecords") == null){
    138                         addParam("maximumRecords","50");
    139                 }
    140                
    141                 if ( params.get("x-cmd-maxdepth") == null){
    142                         if (params.get("maxdepth") == null){
    143                                 addParam("maxdepth","2");
    144                         }
    145                 } else {
    146                         addParam("maxdepth",params.get("x-cmd-maxdepth")[0]);
    147                 }
    148                
    149                 if ( params.get("x-cmd-repository") == null){
    150                         if (params.get("repository") == null){
    151                                 addParam("repository",WorkspaceProfile.getRepositoryByIndex(0));
    152                         }
    153                 } else {
    154                         addParam("repository",params.get("x-cmd-repository")[0]);
    155                 }
    156                
    157                 if ( params.get("x-cmd-cache") == null){
    158                         if (params.get("cache") == null){
    159                                 addParam("cache",Cache.SKIP);
    160                         }
    161                 } else {
    162                         addParam("cache",params.get("x-cmd-cache")[0]);
    163                 }
    164                
    165                 if ( params.get("x-cmd-lang") == null){
    166                         if (params.get("lang") == null){
    167                                 addParam("lang","en");
    168                         }
    169                 } else {
    170                         addParam("lang",params.get("x-cmd-lang")[0]);
    171                 }
    172                
    173                 if ( params.get("x-cmd-format") == null){
    174                         if (params.get("format") == null){
    175                                 if (this.format == null) {
    176                                         addParam("format","xml");
    177                                 } else if (this.format.equals("")){
    178                                         addParam("format","xml");
    179                                 } else {
    180                                         addParam("format",this.format);
    181                                 }
    182                         }
    183                 } else {
    184                         addParam("format",params.get("x-cmd-format")[0]);
    185                 }
    186 
    187                 addParam("fullformat",getFullFormat());
    188                
    189         }
    190 */
    191         /*
    192         public void prepareOperation() throws UnsupportedEncodingException{
    193                
    194                 mdrepoproxyaction = new MDRepoProxyAction();
    195                 mdrepoproxyaction.setDiagnostics(diagnostics);
    196                 mdrepoproxyaction.setActionkey(hash_operations.get(this.getOperation()));
    197                
    198                 // set the SRU extern property in proxyaction
    199                 if (this.getX_cmd_repository() != null ) {
    200                         mdrepoproxyaction.setRepository(this.getX_cmd_repository());
    201                         //TODO\
    202                         if (mdrepoproxyaction.getBaseURI() == null) this.Diagnostics().Add(Diagnostic.UNSUPPORTED_PARAMETERVALUE, "Unknown repository." + getX_cmd_repository());
    203                 }
    204                
    205                 if (operation.equals("searchRetrieve")){
    206                        
    207                         //query
    208                         mdrepoproxyaction.setSquery("");
    209                         if (this.query == null) {
    210                                 this.Diagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "query");
    211                                 //return -1;
    212                         }
    213                         mdrepoproxyaction.setQ(getQuery());                     
    214                         mdrepoproxyaction.setFormat("xml");
    215                        
    216                         if ((this.startRecord < 0 ) ||((getServletRequest().getParameter("startRecord") != null)&&(getServletRequest().getParameter("startRecord").equals("0")))) {
    217                                 this.Diagnostics().Add(new Diagnostic(Diagnostic.UNSUPPORTED_PARAMETERVALUE, "startRecord must by grater than 0."));//,Diagnostic.NONFATALNONSURORGATE));
    218                                 //mdrepoproxyaction.setStartItem("1");
    219                         } else {
    220                                 mdrepoproxyaction.setStartItem(Integer.toString(getStartRecord()));
    221                         }
    222                
    223                         if ((this.maximumRecords < 0 ) ||((getServletRequest().getParameter("maximumRecords") != null) && (getServletRequest().getParameter("maximumRecords").equals("0")))){
    224                                    this.Diagnostics().Add(new Diagnostic(Diagnostic.UNSUPPORTED_PARAMETERVALUE,
    225                                                    "maximumRecords must by greater than 0."));
    226                         } else {
    227                                 mdrepoproxyaction.setMaximumItems(Integer.toString(this.getMaximumRecords())); 
    228                         }
    229                        
    230                         if (this.getX_cmd_repository() != null ) {
    231                                 mdrepoproxyaction.setRepository(this.getX_cmd_repository());
    232                                 //TODO\
    233                                 if (mdrepoproxyaction.getBaseURI() == null) this.Diagnostics().Add(Diagnostic.UNSUPPORTED_PARAMETERVALUE, "Unknown repository." + getX_cmd_repository());
    234                         }
    235                         if (this.getX_cmd_collections() != null ) {
    236                                 mdrepoproxyaction.setCollection(this.getX_cmd_collections());
    237                         }
    238 
    239                 } else {
    240                         if (operation.equals("explain") || operation == null){
    241                                 log.debug("explaining", "debug");
    242                         }else {
    243                                 if (operation.equals("scan")){
    244                                         if (this.scanClause == null) {
    245                                                 this.Diagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "scanClause");
    246                                                 //return -1;
    247                                         } else{
    248                                                 if (this.scanClause.equals("cmd.Collections")){
    249                                                        
    250                                                 } else {
    251                                                         if (this.scanClause.equals("cmd.Repository")){
    252                                                                 XMLSerializer xmlserializer = new XMLSerializer();
    253                                                                 String xml = xmlserializer.write( WorkspaceProfile.getRepositories());//mdrepoproxyaction.getRepositories() ); 
    254                                                                 this.setResultStream(new ByteArrayInputStream(xml.getBytes("UTF-8")));
    255 
    256                                                         } else {
    257                                                                
    258                                                         }
    259                                                 }
    260                                         }
    261                                 }else {
    262                                         this.Diagnostics().Add(Diagnostic.UNSUPPOERTED_OPERATION, "Only searchRetrieve,explain scan supported.");                               }
    263                         }
    264                 }
    265         }
    266101       
    267         public void sru2MD() throws UnsupportedEncodingException{
    268                 // special handling of parameter setting, x-cmd-... not alowed in java
    269                 this.setX_cmd_collections(getServletRequest().getParameter("x-cmd-collections"));               
    270                 // root call own SRU SERVER
    271                 //operation
    272                 if (operation.equals("explain") || operation == null){
    273                         // TODO: version param is mandatory for explain as well, but for root-request not!
    274                         //explain
    275                         termsproxyaction = new TermsProxyAction();
    276                         termsproxyaction.setDiagnostics(diagnostics);
    277                         termsproxyaction.setActionkey("terms");
    278                        
    279                         termsproxyaction.setQ("all");                   
    280                         termsproxyaction.setFormat("sru-explain");                     
    281                        
    282                         //return -1;
    283                 } else {                               
    284                         //version               
    285                         if (this.version == null) {
    286                                 this.Diagnostics().Add(Diagnostic.MANDATORY_NOTSUPPLIED, "version");
    287                                 //return -1;
    288                         } else {
    289                                 if (!version.equals("1.2")) {
    290                                         this.Diagnostics().Add(Diagnostic.UNSUPPORTED_VERSION, "Version 1.2 supported.");
    291                                         //return -1;
    292                                 }
    293                         }
    294                        
    295                         prepareOperation();
    296                 }
    297                
    298         }
    299102       
    300         public void  prepareMD() throws Exception{
    301                 sru2MD();
    302                 if (Diagnostics().Accepted()){
    303                         // root-explain
    304                         if (this.termsproxyaction != null) {                   
    305                                 if (this.termsproxyaction.execute() == SUCCESS){
    306                                         this.setResultStream(this.termsproxyaction.getResultStream());
    307                                         //return SUCCESS;
    308                                 }
    309                         } else {
    310                                 //TODO diagnostic                       
    311                                 if (this.mdrepoproxyaction.getTargetRequest() == null) {
    312                                         Diagnostics().Add(Diagnostic.QUERYSYNTAXERROR);
    313                                         //return ERROR;
    314                                 }
    315                                 if (this.mdrepoproxyaction.execute() == SUCCESS){
    316                                         this.setResultStream(this.mdrepoproxyaction.getResultStream());
    317                                         postprocess();
    318                                         //return SUCCESS;
    319                                 }
    320                         }
    321                 }
    322                 //return ERROR;
    323         }
    324         */
    325 /** TODO: move to Utils
    326  *
    327  * @param stream
    328  * @return
    329  * @throws IOException
    330  */
    331         /*
    332         public static String inputStreamAsString(InputStream stream)
    333                 throws IOException {
    334                 BufferedReader br = new BufferedReader(new InputStreamReader(stream));
    335                 StringBuilder sb = new StringBuilder();
    336                 String line = null;
    337 
    338                 while ((line = br.readLine()) != null) {
    339                 sb.append(line + "\n");
    340                 }
    341 
    342                 br.close();
    343                 return sb.toString();
    344         }
    345 
    346        
    347 
    348         public void postprocess() throws TransformerConfigurationException, UnsupportedEncodingException, ParserConfigurationException, TransformerException, TransformerFactoryConfigurationError{
    349                 //recordPacking
    350                 if (this.getRecordPacking() != null){
    351                         if (this.getRecordPacking().toLowerCase().equals("string")){
    352                                
    353                                 try {
    354                                         // FIXME: Which package is IOUTils from?
    355                                         this.setResultStream(IOUtils.toInputStream(StringEscapeUtils.escapeXml(inputStreamAsString(this.getResultStream()))));
    356                                 } catch (IOException e) {
    357                                         // TODO Auto-generated catch block
    358                                         e.printStackTrace();
    359                                 }
    360 
    361                         }
    362                 }
    363                
    364                 // add diagnostics
    365                 if (getDiagnostics().Exists()){
    366                         Document doc = Utils.stream2Document(getResultStream());
    367                         Node r_element=  doc.getElementsByTagName("searchRetrieveResponse").item(0);
    368                         Document ddoc = getDiagnostics().buildXMLDocument();
    369                         Node d_element=  ddoc.getElementsByTagName("diagnostics").item(0);
    370                         doc.adoptNode(d_element);
    371                         r_element.appendChild(d_element);
    372                         DOMSource source = new DOMSource(doc);   
    373                         StringWriter xmlAsWriter = new StringWriter();   
    374                         StreamResult result = new StreamResult(xmlAsWriter);   
    375                         TransformerFactory.newInstance().newTransformer().transform(source, result);
    376                         this.setResultStream(new ByteArrayInputStream(xmlAsWriter.toString().getBytes("UTF-8")));
    377                 }
    378         }
    379        
    380         //TODO create query + query.toURLParams ?
    381         public String createURLParams(){
    382                 String params = "";
    383                
    384                 //TODO params
    385                 /*
    386                 if (paramSet == null){
    387                         if (!(operation == null)){
    388                                 params = params + "operation=" + operation;
    389                         }
    390                         if (!(version == null)){
    391                                 params = params + "&version=" + version;
    392                         }
    393                         if (!(query == null)){
    394                                 params = params + "&query=" + query;
    395                         }
    396                         if (getStartRecord() > 0){
    397                                 params = params + "&startRecord=" + String.valueOf(getStartRecord());
    398                         }
    399                         if (getMaximumRecords()> 0){
    400                                 params = params + "&numRecords=" + String.valueOf(getMaximumRecords());
    401                         }
    402                 } else {
    403                         Iterator i = paramSet.iterator();
    404                         params = "";
    405                     while(i.hasNext()){
    406                               Map.Entry me = (Map.Entry)i.next();
    407                               if (!(me.getKey().equals("x-cmd-repository") || me.getKey().equals("x-cmd-collections"))){
    408                                       params = params + "&" + me.getKey() + "=" + ((String[])me.getValue())[0]; 
    409                               }
    410                         }
    411                     params = params.substring(1);
    412 
    413                 }
    414 
    415                 return params;
    416         }
    417 */     
    418 
    419 /*     
    420         @Override
    421         public void prepare() throws Exception{
    422                 //this.setX_cmd_repository(getServletRequest().getParameter("x-cmd-repository"));
    423                 //this.setRepository(this.getX_cmd_repository());
    424                 //TODO xsl usage according particular repositories ?
    425                 //this.setActionkey("sru");
    426                 //this.setFormat("xml");
    427                
    428                 //extern SRU repository
    429                 if (WorkspaceProfile.isSRURepository(getRepository()) || this.getBaseURI() == null){
    430                         super.prepare();
    431                 }
    432                 else {
    433                          prepareMD();
    434                 }
    435                
    436         }
    437 */
    438103        @Override
    439104        public void setTargetProxy(){
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/internal/Cache.java

    r1654 r1852  
    150150                }
    151151                if (key_array.length > 2){
    152                         e.setAttribute("collection", key_array[2]);
     152                        e.setAttribute("operation", key_array[2]);
     153                }else{
     154                        e.setAttribute("operation", "");
     155                }
     156                if (key_array.length > 3){
     157                        e.setAttribute("collection", key_array[3]);
    153158                }else{
    154159                        e.setAttribute("collection", "");
    155160                }
    156                 if (key_array.length > 3){
    157                         e.setAttribute("startItem", key_array[3]);
     161                if (key_array.length > 4){
     162                        e.setAttribute("startItem", key_array[4]);
    158163                }else{
    159164                        e.setAttribute("startItem", "");
    160165                }
    161                 if (key_array.length > 4){
    162                         e.setAttribute("maximumItems", key_array[4]);
     166                if (key_array.length > 5){
     167                        e.setAttribute("maximumItems", key_array[5]);
    163168                }else{
    164169                        e.setAttribute("maximumItems", "");
    165170                }
    166171               
    167                 if (key_array.length > 5){
    168                         e.setAttribute("repository", key_array[5]);
     172                if (key_array.length > 6){
     173                        e.setAttribute("repository", key_array[6]);
    169174                }else{
    170175                        e.setAttribute("repository", "");
    171176                }
    172                 if (key_array.length > 6){
    173                         e.setAttribute("maxDepth", key_array[6]);
     177                if (key_array.length > 7){
     178                        e.setAttribute("maxDepth", key_array[7]);
    174179                }else{
    175180                        e.setAttribute("maxDepth", "");
    176181                }
    177                 if (key_array.length > 7){
    178                         e.setAttribute("lang", key_array[7]);
     182                if (key_array.length > 8){
     183                        e.setAttribute("lang", key_array[8]);
    179184                }else{
    180185                        e.setAttribute("lang", "");
    181186                }
    182                 if (key_array.length > 8){
    183                         e.setAttribute("duration", key_array[8]);
     187                if (key_array.length > 9){
     188                        e.setAttribute("duration", key_array[9]);
    184189                }else{
    185190                        e.setAttribute("duration", "");
     
    270275               
    271276                if (key_array.length > 2){
    272                         xpath_expr = xpath_expr + "and @collection='"+key_array[2]+"'";
     277                        xpath_expr = xpath_expr + "and @operation='"+key_array[2]+"'";
     278                }else{
     279                        xpath_expr = xpath_expr + " and @operation=''";
     280                }
     281               
     282                if (key_array.length > 3){
     283                        xpath_expr = xpath_expr + "and @collection='"+key_array[3]+"'";
    273284                }else{
    274285                        xpath_expr = xpath_expr + " and @collection=''";
    275286                }
    276                 if (key_array.length > 3){
    277                         xpath_expr = xpath_expr + "and @startItem='"+key_array[3]+"'";
     287                if (key_array.length > 4){
     288                        xpath_expr = xpath_expr + "and @startItem='"+key_array[4]+"'";
    278289                }else{
    279290                        xpath_expr = xpath_expr + " and @startItem=''";
    280291                }
    281                 if (key_array.length > 4){
    282                         xpath_expr = xpath_expr + "and @maximumItems='"+key_array[4]+"'";
     292                if (key_array.length > 5){
     293                        xpath_expr = xpath_expr + "and @maximumItems='"+key_array[5]+"'";
    283294                }else{
    284295                        xpath_expr = xpath_expr + " and @maximumItems=''";
    285296                }
    286297               
    287                 if (key_array.length > 5){
    288                         xpath_expr = xpath_expr + "and @repository='"+key_array[5]+"'";
     298                if (key_array.length > 6){
     299                        xpath_expr = xpath_expr + "and @repository='"+key_array[6]+"'";
    289300                }else{
    290301                        xpath_expr = xpath_expr + " and @repository=''";
    291302                }
    292                 if (key_array.length > 6){
    293                         xpath_expr = xpath_expr + "and @maxDepth='"+key_array[6]+"'";
     303                if (key_array.length > 7){
     304                        xpath_expr = xpath_expr + "and @maxDepth='"+key_array[7]+"'";
    294305                }else{
    295306                        xpath_expr = xpath_expr + " and @maxDepth=''";
    296307                }
    297                 if (key_array.length > 7){
    298                         xpath_expr = xpath_expr + "and @lang='"+key_array[7]+"']";
     308                if (key_array.length > 8){
     309                        xpath_expr = xpath_expr + "and @lang='"+key_array[8]+"']";
    299310                }else{
    300311                        xpath_expr = xpath_expr + " and @lang='']";
  • MDService2/branches/MDService_simple3/src/eu/clarin/cmdi/mdservice/model/Repositories.java

    r1842 r1852  
    214214        public  Boolean repositoryExists(String repository_name){
    215215               
    216                
    217                 for(int i=0;i<repositories_nodelist.getLength();i++){
    218                         if (repositories_nodelist.item(i).getChildNodes().item(1).getNodeValue().equals(repository_name)){
    219                                 return true;
    220                         }
    221                 }
     216                NodeList chlist = repositories_nodelist.item(0).getChildNodes();
     217                for(int i=0;i<chlist.getLength();i++){
     218                        Node node = chlist.item(i);
     219                        if (node.getNodeName().equals("item")){
     220                                for(int j=0;j<node.getChildNodes().getLength();j++){
     221                                        if (node.getChildNodes().item(j).getNodeName().equals("name") && node.getChildNodes().item(j).getTextContent().equals(repository_name)){
     222                                                return true;
     223                                        }
     224                                }
     225                        }
     226                }
     227       
    222228               
    223229                return false;
Note: See TracChangeset for help on using the changeset viewer.