示例#1
0
 private boolean isEmptyContext(ImportContext context) {
   return (context.getPortalConfigs().isEmpty()
       && context.getPages().isEmpty()
       && context.getNavigations().isEmpty());
 }
示例#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);
    }
  }