@Override
  public String execute(CliContext context) {
    StringBuffer result = new StringBuffer();
    WeldContainer container = context.getContainer();

    OrganizationalUnitService organizationalUnitService =
        container.instance().select(OrganizationalUnitService.class).get();

    InputReader input = context.getInput();
    System.out.print(">>Organizational Unit name:");
    String name = input.nextLine();

    OrganizationalUnit organizationalUnit = organizationalUnitService.getOrganizationalUnit(name);
    if (organizationalUnit == null) {
      return "No Organizational Unit " + name + " was found";
    }
    System.out.print(">>Security roles (comma separated list):");
    String rolesIn = input.nextLine();
    if (rolesIn.trim().length() > 0) {

      String[] roles = rolesIn.split(",");
      for (String role : roles) {
        organizationalUnitService.removeRole(organizationalUnit, role);
        result.append(
            "Role "
                + role
                + " removed successfully from Organizational Unit "
                + organizationalUnit.getName()
                + "\n");
      }
    }

    return result.toString();
  }
  private PermissionNode toPermissionNode(OrganizationalUnit ou) {
    PermissionLeafNode node = new PermissionLeafNode();
    node.setNodeName(ou.getName());

    Permission readPermission = newPermission(ou, READ);
    Permission updatePermission = newPermission(ou, UPDATE);
    Permission deletePermission = newPermission(ou, DELETE);

    node.addPermission(readPermission, i18n.OrganizationalUnitActionRead());
    node.addPermission(updatePermission, i18n.OrganizationalUnitActionUpdate());
    node.addPermission(deletePermission, i18n.OrganizationalUnitActionDelete());

    node.addDependencies(readPermission, updatePermission, deletePermission);
    return node;
  }
  public RepositoryInfo getRepositoryInfo(final String alias) {
    final Repository repo = getRepository(alias);
    String ouName = null;
    for (final OrganizationalUnit ou : organizationalUnitService.getOrganizationalUnits()) {
      for (Repository repository : ou.getRepositories()) {
        if (repository.getAlias().equals(alias)) {
          ouName = ou.getName();
        }
      }
    }

    return new RepositoryInfo(
        alias,
        ouName,
        repo.getRoot(),
        repo.getPublicURIs(),
        getRepositoryHistory(alias, 0, HISTORY_PAGE_SIZE));
  }
  @Override
  public String execute(CliContext context) {
    StringBuffer result = new StringBuffer();
    WeldContainer container = context.getContainer();

    OrganizationalUnitService organizationalUnitService =
        container.instance().select(OrganizationalUnitService.class).get();
    RepositoryService repositoryService =
        container.instance().select(RepositoryService.class).get();

    InputReader input = context.getInput();
    System.out.print(">>Organizational Unit name:");
    String name = input.nextLine();

    System.out.print(">>Organizational Unit owner:");
    String owner = input.nextLine();

    System.out.print(">>Default Group Id for this Organizational Unit:");
    String defaultGroupId = input.nextLine();

    System.out.print(">>Repositories (comma separated list):");
    String repos = input.nextLine();
    Collection<Repository> repositories = new ArrayList<Repository>();
    if (repos != null && repos.trim().length() > 0) {
      String[] repoAliases = repos.split(",");
      for (String alias : repoAliases) {
        Repository repo = repositoryService.getRepository(alias);
        if (repo != null) {
          repositories.add(repo);
        } else {
          System.out.println(
              "WARN: Repository with alias " + alias + " does not exists and will be skipped");
        }
      }
    }

    OrganizationalUnit organizationalUnit =
        organizationalUnitService.createOrganizationalUnit(
            name, owner, defaultGroupId, repositories);
    result.append("Organizational Unit " + organizationalUnit.getName() + " successfully created");
    return result.toString();
  }