Changeset 1509 for MDService2


Ignore:
Timestamp:
09/03/11 11:58:22 (13 years ago)
Author:
vronk
Message:

intermediate version reworking RepoProxyAction? - adding a target_proxy

Location:
MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action/MDRepoProxyAction.java

    r1496 r1509  
    3939 *
    4040 */
    41 public class MDRepoProxyAction extends GenericProxyAction {
     41public class MDRepoProxyAction extends RepoProxyAction {
    4242
    4343        private static final long serialVersionUID = 1L;
  • MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action/Pz2ProxyAction.java

    r1496 r1509  
    3939 
    4040 */
    41 public class Pz2ProxyAction extends GenericProxyAction {
     41public class Pz2ProxyAction extends RepoProxyAction {
    4242
    4343        private static final long serialVersionUID = 1L;
     
    136136        }
    137137       
    138 /*
     138/**
     139 * Overrides the default implementation for the case, when the Service shall act as "collector",
     140 * waiting for the final result (implemented in getSourcePz2
     141 * The distinction is based on the command parameter: if it is given, the Class(Service) acts as a basic proxy
     142 * transparently passing the communication between client and target repository. 
     143 */
    139144        @Override
    140145        public InputStream getSourceStream() throws IOException, NoStylesheetException {
     
    151156        }
    152157       
     158/**
     159 * TODO: move to Utils
     160 * @param is
     161 * @return
     162 */
    153163        public Document getDocument(InputStream is){
    154164                Document doc = null;
     
    170180                return doc;
    171181        }
     182       
     183/**
     184 * TODO: move to Utils
     185 * @param is
     186 * @param expression
     187 * @return
     188 */
    172189        public String getDocumentData(InputStream is, String expression){
    173190                String sessionid = "";
     
    187204               
    188205        }
    189         */
    190         /*
     206
     207/**
     208 * This function wraps the session-based communication with a Pazpar2-target, waiting until all the responses were returned (or timeout occured)
     209 * returning the full result at the end.   
     210 * @return returns the collected final result as a stream
     211 * @throws Exception
     212 */
    191213        public InputStream getSourcePz2() throws Exception {
    192214               
     
    227249                return is;
    228250        }
    229 */
    230251       
    231252}
  • MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action/RepoProxyAction.java

    r1508 r1509  
    4444
    4545        private String proxy_key = "repository";
    46        
     46        private RepoProxyAction target_proxy;
     47        private RepoProxyAction source_action;
     48       
     49/**
     50 * Based on the repository type - we create a typed Proxy, that will do the work.
     51 * If the type is not recognized <this> will be also the target_proxy -
     52 * TODO: check if it is sane, to work without a typed target_proxy   
     53 */
     54        protected void  initialize(){
     55               
     56                switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository())))
     57                {               
     58                    case PAZPAR:
     59                        target_proxy = new Pz2ProxyAction();
     60                    case SRU:
     61                        target_proxy = new SRUProxyAction();
     62                    case MD:
     63                        target_proxy = new MDRepoProxyAction();
     64                    default:
     65                        target_proxy = this;
     66                }
     67                target_proxy.setSourceAction(this);
     68               
     69        }
     70       
     71        public RepoProxyAction getTargetProxy() {
     72                return target_proxy;
     73        }
     74
     75        public RepoProxyAction getSourceAction() {
     76                return source_action;
     77        }
     78       
     79        public void setSourceAction(RepoProxyAction p_source_action) {
     80                source_action = p_source_action;
     81        }
     82       
     83/**
     84 * Pass the proxy_key of the actual target_proxy,
     85 * or the basic "repository" if the target_proxy is identical 
     86 */
    4787        @Override
    4888        public String getProxyKey() {
    49                 return proxy_key;
     89                if (target_proxy.equals(this)) {
     90                  return proxy_key;
     91                } else {               
     92                        return getTargetProxy().getProxyKey();
     93                }
    5094        }
    5195
     
    60104        }
    61105       
    62         /**
    63          * A mapping between the actionkeys in the request and the operation-parameter expected by the MD!Repository
    64          * FIXME: This is taken from MDRepoProxyAction - so it will not work for SRU and Pazpar2
    65          */
    66         private final static HashMap<String,String> urls = new HashMap<String,String>();
    67          static
    68          {       urls.put("collection", "?operation=getCollections&collection=");
    69                  urls.put("model", "?operation=queryModel&q=");
    70                  urls.put("values", "?operation=scanIndex&q=");
    71                  urls.put("search", "?operation=searchRetrieve&query=");
    72                  urls.put("record", "?operation=searchRetrieve&query=");
    73          }
    74 
    75        
    76106        //TODO remove - just for tests
    77107        @Override
     
    106136        }
    107137       
    108 public URL getTargetRequestSRU() throws IOException, NoStylesheetException{
    109        
    110         SRUProxyAction sruaction = new SRUProxyAction();
    111         // TODO MD to SRU params
    112         // missing collections, columns...
    113         sruaction.setOperation("searchRetrieve");
    114         //TODO what version
    115         sruaction.setVersion("1.2");
    116         sruaction.setStartRecord(Integer.parseInt(this.getStartItem()));
    117         sruaction.setMaximumRecords(Integer.parseInt(this.getMaximumItems()));
    118         sruaction.setRepository(getRepository());
    119         sruaction.setQuery(this.fullQueryString());
    120        
    121         return sruaction.getTargetRequest();
    122        
    123 }
    124 public InputStream getSourcePz2() throws Exception {
    125                
    126                 InputStream is = null;
    127                 Pz2ProxyAction pzaction = new Pz2ProxyAction();
    128                 // TODO param settings
    129                 //init
    130                 pzaction.setRepository(getRepository());
    131                 pzaction.setCommand("init");
    132                 String sessionID = Helpers.getDocumentData(pzaction.getSourceStream(), "//init/session");
    133                 // get result
    134                 pzaction.setCommand("search");
    135                 pzaction.setSessionID(sessionID);
    136                 pzaction.setQuery(this.fullQueryString());
    137                 String ok = Helpers.getDocumentData(pzaction.getSourceStream(),"//search/status");
    138                
    139                 String activeclients = "1";
    140                 pzaction.setCommand("show");
    141                 pzaction.setSort("relevance");
    142                 pzaction.setBlock("1");
    143                 //TODO timeout  settings
    144                 long startMillis = System.currentTimeMillis();
    145                 long timeout = 0;
    146                 if (WorkspaceProfile.getOption("pazpartimeout") == null){
    147                         timeout = 1000;
    148                 } else {
    149                         timeout = Integer.parseInt(WorkspaceProfile.getOption("pazpartimeout"));
    150                 }
    151                 while (Integer.parseInt(activeclients) > 0){
    152                         //activeclients = getDocumentData(this.getSourceStream(), "//show/activeclients");
    153                         is = pzaction.getSourceStream();
    154                         activeclients = Helpers.getDocumentData(is, "//show/activeclients");
    155                         Thread.sleep(1000);
    156                         Admin.notifyUser("ActiveClients: " + activeclients, Admin.DEBUG);
    157                         if ((System.currentTimeMillis() - startMillis)/1000 > timeout) {
    158                                 break;
    159                         }
    160                 }
    161                 is = pzaction.getSourceStream();
    162                 return is;
    163         }
    164                
    165138        @Override
    166139        public InputStream getSourceStream() throws IOException, NoStylesheetException {
    167                
    168                
     140       
     141                return getTargetProxy().getSourceStream();
     142                /*
    169143                switch (WorkspaceProfile.RepositoryType.toRepositoryType(WorkspaceProfile.getRepositoryType(getRepository())))
    170144                {
     
    183157                        return super.getSourceStream();
    184158                }
    185                
     159                */
    186160        }
    187161 
  • MDService2/branches/MDService_simple/src/eu/clarin/cmdi/mdservice/action/SRUProxyAction.java

    r1496 r1509  
    5454
    5555
    56 public class SRUProxyAction extends GenericProxyAction//ActionSupport
     56public class SRUProxyAction extends RepoProxyAction//ActionSupport
    5757//implements ServletRequestAware
    5858{
     
    386386        public void sru2MD() throws UnsupportedEncodingException{
    387387                // special handling of parameter setting, x-cmd-... not alowed in java
    388                 this.setX_cmd_collections(getServletRequest().getParameter("x-cmd-collections"));
    389                
     388                this.setX_cmd_collections(getServletRequest().getParameter("x-cmd-collections"));               
    390389                // root call own SRU SERVER
    391390                //operation
     
    560559                return targetURL;
    561560        }
    562        
     561
     562
     563        public URL getTargetRequestSRU() throws IOException, NoStylesheetException{
     564               
     565                SRUProxyAction sruaction = new SRUProxyAction();
     566                // TODO MD to SRU params
     567                // missing collections, columns...
     568                sruaction.setOperation("searchRetrieve");
     569                //TODO what version
     570                sruaction.setVersion("1.2");
     571                sruaction.setStartRecord(Integer.parseInt(this.getStartItem()));
     572                sruaction.setMaximumRecords(Integer.parseInt(this.getMaximumItems()));
     573                sruaction.setRepository(getRepository());
     574                sruaction.setQuery(this.fullQueryString());
     575               
     576                return sruaction.getTargetRequest();
     577               
     578        }
     579
    563580        @Override
    564581        public void prepare() throws Exception{
Note: See TracChangeset for help on using the changeset viewer.