001package org.kuali.ole.externalds;
002
003
004/*import net.sf.jz3950.Association;
005import net.sf.jz3950.RecordResultSet;
006import net.sf.jz3950.query.PrefixQuery;*/
007import org.apache.log4j.Logger;
008import org.kuali.ole.docstore.common.search.SearchParams;
009
010import java.util.ArrayList;
011import java.util.List;
012
013public class Z3950DataSource
014        extends AbstractExternalDataSource {
015
016   /* private static final Logger LOG = Logger.getLogger(Z3950DataSource.class);
017    private static final int RESULT_SET_ITERATION_LIMIT = 80;
018
019
020    @Override
021    public List<String> searchForBibs(SearchParams searchParams, DataSourceConfig dataSourceConfigInfo)
022            throws Exception {
023
024        Association association = new Association();
025        String domainName = dataSourceConfigInfo.getDomainName();
026        String port = dataSourceConfigInfo.getPortNum();
027        String loginIdDbName = dataSourceConfigInfo.getLoginId();
028        String logInId = "";
029        String dataBase ="" ;
030        if(loginIdDbName != null && !loginIdDbName.trim().equals("")) {
031            String[] parts = loginIdDbName.split("/");
032            if(parts.length==2){
033                dataBase = parts[1];
034                logInId = parts[0];
035            } else {
036                dataBase = parts[0];
037            }
038
039        }
040        List<String> dataBaseList = new ArrayList<String>();
041        List<String> results=new ArrayList<String>() ;
042        dataBaseList.add(dataBase);
043        String password = dataSourceConfigInfo.getPassword();
044        String authKey =dataSourceConfigInfo.getAuthKey();
045        LOG.info("Connecting to external datasource: domainName = " + dataSourceConfigInfo.getDomainName() +" portNumber = "+dataSourceConfigInfo.getPortNum());
046        if(logInId != null && !logInId.trim().equals("") && password != null && ! password.trim().equals("")){
047            association.connect(domainName.trim(), Integer.parseInt(port.trim()),logInId.trim(), password.trim());
048        } else{
049            association.connect(domainName, Integer.parseInt(port));
050        }
051        //String query="@attrset bib-1 @attr 1=4 \"advanced java\"";
052        Z3950QueryBuilder z3950QueryBuilde = new Z3950QueryBuilder();
053        String query = z3950QueryBuilde.buildQuery(searchParams);
054        LOG.info("Z39.50 Query:" + query);
055        results = iterateOverPartOfResultSet(association.search(new PrefixQuery(dataBaseList, query)));
056        LOG.info("Z39.50 Query results size: " + results.size());
057        association.disconnect();
058        return results;
059    }
060    private List iterateOverPartOfResultSet(RecordResultSet resultSet) {
061        List<String> results = new ArrayList<String>();
062        LOG.info(("Iterating over maximum of " + RESULT_SET_ITERATION_LIMIT + " record(s) from "
063                + resultSet.getTotalResults() + " record(s) in total"));
064        int recordCount = 0;
065        try{
066        while(resultSet.hasNext()){
067                net.sf.jz3950.record.Record record =   resultSet.next();
068                String tempdata = record.getData() ;
069                   results.add(tempdata);
070                       if (++recordCount == RESULT_SET_ITERATION_LIMIT) {
071                             break;
072                       }
073            }
074         } catch(Exception ex){
075            LOG.error(ex.getMessage());
076            ex.printStackTrace();
077        }
078
079        return results;
080    }*/
081}