Ejemplo n.º 1
0
  public HarvestResult harvest() throws Exception {
    XmlRequest req = new XmlRequest(new URL(params.host));

    Lib.net.setupProxy(context, req);

    // --- login

    if (params.useAccount) {

      try {
        log.info("Login into : " + params.name);
        req.setCredentials(params.username, params.password);
        req.setAddress(params.getServletPath() + "/srv/eng/xml.info?type=me");

        Element response = req.execute();
        if (!response.getName().equals("info") || response.getChild("me") == null) {
          pre29Login(req);
        } else if (!"true".equals(response.getChild("me").getAttributeValue("authenticated"))) {
          throw new UserNotFoundEx(params.username);
        }
      } catch (Exception e) {
        pre29Login(req);
      }
    }

    // --- retrieve info on categories and groups

    log.info("Retrieving information from : " + params.host);

    req.setAddress(params.getServletPath() + "/srv/en/" + Geonet.Service.XML_INFO);
    req.clearParams();
    req.addParam("type", "sources");
    req.addParam("type", "groups");

    Element remoteInfo = req.execute();

    if (!remoteInfo.getName().equals("info")) throw new BadServerResponseEx(remoteInfo);

    // --- perform all searches

    Set<RecordInfo> records = new HashSet<RecordInfo>();

    for (Search s : params.getSearches()) records.addAll(search(req, s));

    if (params.isSearchEmpty()) records.addAll(search(req, Search.createEmptySearch()));

    log.info("Total records processed in all searches :" + records.size());

    // --- align local node

    Aligner aligner = new Aligner(log, context, dbms, req, params, remoteInfo);
    HarvestResult result = aligner.align(records);

    Map<String, String> sources = buildSources(remoteInfo);
    updateSources(dbms, records, sources);

    return result;
  }
Ejemplo n.º 2
0
  public HarvestResult harvest() throws Exception {

    XmlRequest req = new XmlRequest(params.host, Integer.valueOf(params.port));

    Lib.net.setupProxy(context, req);

    // --- perform all searches

    Set<RecordInfo> records = new HashSet<RecordInfo>();

    for (Search s : params.getSearches()) records.addAll(search(req, s));

    if (params.isSearchEmpty()) records.addAll(search(req, Search.createEmptySearch()));

    log.info("Total records processed in all searches :" + records.size());

    // --- config local node

    Z3950Config configer = new Z3950Config(log, context, req, params);
    HarvestResult result = configer.config(records);

    return result;
  }