/** Creates the actions. */
  @Override
  public void createActions(MigrationContext ctx) throws MigrationException {

    // Config fragments
    for (IConfigFragment fragment :
        ctx.getMigrationData().get(SecurityMigrator.class).getConfigFragments()) {
      if (fragment instanceof ApplicationPolicyBean) {
        try {
          SecurityDomainBean appPolicy = migrateAppPolicy((ApplicationPolicyBean) fragment, ctx);
          ctx.getActions().addAll(createSecurityDomainCliAction(appPolicy));
        } catch (CliScriptException e) {
          throw new MigrationException(
              "Migration of application-policy failed: " + e.getMessage(), e);
        }
        continue;
      }
      throw new MigrationException(
          "Config fragment unrecognized by " + this.getClass().getSimpleName() + ": " + fragment);
    }

    // Files to copy
    File as5profileDir = getGlobalConfig().getAS5Config().getProfileDir();
    String as7Dir = getGlobalConfig().getAS7Config().getDir();

    for (String fileName : this.fileNames) {
      File src;
      try {
        // TODO: MIGR-54 The paths in AS 5 config relate to some base dir. Find out which and use
        // that, instead of searching.
        //       Then, create the actions directly in the code creating this "files to copy"
        // collection.
        src = Utils.searchForFile(fileName, as5profileDir).iterator().next();
      } catch (CopyException ex) {
        // throw new ActionException("Failed copying a security file: " + ex.getMessage(), ex);
        // Some files referenced in security may not exist. (?)
        log.warn("Couldn't find file referenced in AS 5 security config: " + fileName);
        continue;
      }

      File target = Utils.createPath(as7Dir, "standalone", "configuration", src.getName());

      // Default value for overwrite => false
      ctx.getActions().add(new CopyFileAction(this.getClass(), src, target, false));
    }
  }
  /**
   * Creates a CLI script for adding Security-Domain to AS7
   *
   * @param securityDomain object representing migrated security-domain
   * @return created string containing the CLI script for adding the Security-Domain
   * @throws CliScriptException if required attributes are missing
   */
  private static String createSecurityDomainScript(SecurityDomainBean securityDomain)
      throws CliScriptException {
    String errMsg = " in security-domain must be set.";
    Utils.throwIfBlank(securityDomain.getSecurityDomainName(), errMsg, "Security name");

    CliAddScriptBuilder builder = new CliAddScriptBuilder();
    StringBuilder resultScript = new StringBuilder("/subsystem=security/security-domain=");

    resultScript.append(securityDomain.getSecurityDomainName()).append(":add(");
    builder.addProperty("cache-type", securityDomain.getCacheType());

    resultScript.append(builder.asString()).append(")");

    return resultScript.toString();
  }
  /**
   * Creates a list of CliCommandActions for adding a Security-Domain
   *
   * @param domain Security-Domain
   * @return created list containing CliCommandActions for adding the Security-Domain
   * @throws CliScriptException if required attributes for a creation of the CLI command of the
   *     Security-Domain are missing or are empty (security-domain-name)
   */
  public static List<CliCommandAction> createSecurityDomainCliAction(SecurityDomainBean domain)
      throws CliScriptException {
    String errMsg = " in security-domain must be set.";
    Utils.throwIfBlank(domain.getSecurityDomainName(), errMsg, "Security name");

    List<CliCommandAction> actions = new ArrayList();

    ModelNode domainCmd = new ModelNode();
    domainCmd.get(ClientConstants.OP).set(ClientConstants.ADD);
    domainCmd.get(ClientConstants.OP_ADDR).add("subsystem", "security");
    domainCmd.get(ClientConstants.OP_ADDR).add("security-domain", domain.getSecurityDomainName());

    actions.add(
        new CliCommandAction(
            SecurityMigrator.class, createSecurityDomainScript(domain), domainCmd));

    if (domain.getLoginModules() != null) {
      for (LoginModuleAS7Bean module : domain.getLoginModules()) {
        actions.add(createLoginModuleCliAction(domain, module));
      }
    }

    return actions;
  }