Exemple #1
0
  void init() {
    portalContainer = Utils.trimToNull(portalContainer);

    if (importFile == null) {
      String file = Utils.getUserInput("Import file", level);
      importFile = new File(file);
    }
    if (!importFile.exists()) {
      System.err.println("Cannot find file " + importFile);
      System.exit(1);
    }

    File importDir = importFile.getParentFile();
    if (importDir == null) importDir = new File(".");

    Utils.initializeLogging(log4jFile, logLevel, importDir, importFile.getName(), "import");
  }
Exemple #2
0
  public void doImport() {
    if (portalContainer == null) {
      portalContainer = Utils.getUserInput("Container name (ie portal)", level);
    }

    try {
      client =
          PortalObjectsMgmtClient.Factory.create(
              InetAddress.getByName(host), port, username, password, portalContainer);
    } catch (UnknownHostException e) {
      System.err.println("Unknown host name " + host + ". See log for more details.");
      log.error("Exception retrieving host " + host + " by name.", e);
      System.exit(1);
    }

    if (overwrite == null) {
      String ow =
          Utils.getUserInput(
              "Do you wish to fully overwrite all data defined in import file (N) ? Y/N", level);
      if ("Y".equalsIgnoreCase(ow)) {
        overwrite = Boolean.TRUE;
      } else {
        overwrite = Boolean.FALSE;
      }
    }

    if (overwrite && !force) {
      System.out.println(
          "\nOverwrite set to true. This means that all data for a site will be overwritten and any data not defined will be deleted.");
      String proceed = Utils.getUserInput("Do you wish to proceed (N) ? Y/N", level);
      if (!"Y".equalsIgnoreCase(proceed)) {
        System.exit(0);
      }
    }

    log.info("Starting import of file " + importFile + " for portal container " + portalContainer);
    try {
      ImportContext context = client.importFromZip(importFile);
      if (isEmptyContext(context)) {
        System.out.println(
            "Nothing to import. " + importFile + " did not contain anything to import.");
        log.warn("Nothing imported. Zip file did not contain any data for import.");
        System.exit(0);
      }

      if (overwrite) {
        log.info("Overwrite set to true, overwriting all data.");
      }
      context.setOverwrite(overwrite);
      client.importContext(context);
      log.info("Import was successful.");
    } catch (IOException e) {
      System.err.println("Exception reading zip file. See log for more details.");
      log.error("IOException reading zip file " + importFile, e);
    } catch (ClientException e) {
      System.err.println("Client exception during import. See log for more details.");
      log.error("ClientException during import.", e);
    } catch (Throwable t) {
      System.err.println("Unknown exception occurred during import.  See log for more details.");
      log.error("Uknown exception during import.", t);
    }
  }