View Javadoc
1   package org.kuali.ole.externalds;
2   
3   
4   /*import net.sf.jz3950.Association;
5   import net.sf.jz3950.RecordResultSet;
6   import net.sf.jz3950.query.PrefixQuery;*/
7   import org.apache.log4j.Logger;
8   import org.kuali.ole.docstore.common.search.SearchParams;
9   
10  import java.util.ArrayList;
11  import java.util.List;
12  
13  public class Z3950DataSource
14          extends AbstractExternalDataSource {
15  
16     /* private static final Logger LOG = Logger.getLogger(Z3950DataSource.class);
17      private static final int RESULT_SET_ITERATION_LIMIT = 80;
18  
19  
20      @Override
21      public List<String> searchForBibs(SearchParams searchParams, DataSourceConfig dataSourceConfigInfo)
22              throws Exception {
23  
24          Association association = new Association();
25          String domainName = dataSourceConfigInfo.getDomainName();
26          String port = dataSourceConfigInfo.getPortNum();
27          String loginIdDbName = dataSourceConfigInfo.getLoginId();
28          String logInId = "";
29          String dataBase ="" ;
30          if(loginIdDbName != null && !loginIdDbName.trim().equals("")) {
31              String[] parts = loginIdDbName.split("/");
32              if(parts.length==2){
33                  dataBase = parts[1];
34                  logInId = parts[0];
35              } else {
36                  dataBase = parts[0];
37              }
38  
39          }
40          List<String> dataBaseList = new ArrayList<String>();
41          List<String> results=new ArrayList<String>() ;
42          dataBaseList.add(dataBase);
43          String password = dataSourceConfigInfo.getPassword();
44          String authKey =dataSourceConfigInfo.getAuthKey();
45          LOG.info("Connecting to external datasource: domainName = " + dataSourceConfigInfo.getDomainName() +" portNumber = "+dataSourceConfigInfo.getPortNum());
46          if(logInId != null && !logInId.trim().equals("") && password != null && ! password.trim().equals("")){
47              association.connect(domainName.trim(), Integer.parseInt(port.trim()),logInId.trim(), password.trim());
48          } else{
49              association.connect(domainName, Integer.parseInt(port));
50          }
51          //String query="@attrset bib-1 @attr 1=4 \"advanced java\"";
52          Z3950QueryBuilder z3950QueryBuilde = new Z3950QueryBuilder();
53          String query = z3950QueryBuilde.buildQuery(searchParams);
54          LOG.info("Z39.50 Query:" + query);
55          results = iterateOverPartOfResultSet(association.search(new PrefixQuery(dataBaseList, query)));
56          LOG.info("Z39.50 Query results size: " + results.size());
57          association.disconnect();
58          return results;
59      }
60      private List iterateOverPartOfResultSet(RecordResultSet resultSet) {
61          List<String> results = new ArrayList<String>();
62          LOG.info(("Iterating over maximum of " + RESULT_SET_ITERATION_LIMIT + " record(s) from "
63                  + resultSet.getTotalResults() + " record(s) in total"));
64          int recordCount = 0;
65          try{
66          while(resultSet.hasNext()){
67                  net.sf.jz3950.record.Record record =   resultSet.next();
68                  String tempdata = record.getData() ;
69                     results.add(tempdata);
70                         if (++recordCount == RESULT_SET_ITERATION_LIMIT) {
71                               break;
72                         }
73              }
74           } catch(Exception ex){
75              LOG.error(ex.getMessage());
76              ex.printStackTrace();
77          }
78  
79          return results;
80      }*/
81  }