@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();
  }
  @Override
  public String execute(CliContext context) {
    StringBuffer result = new StringBuffer();
    WeldContainer container = context.getContainer();

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

    InputReader input = context.getInput();
    System.out.print(">>Repository alias:");
    String alias = input.nextLine();

    Repository repo = repositoryService.getRepository(alias);
    if (repo == null) {
      return "No repository " + alias + " was found";
    }
    System.out.print(">>Security groups (comma separated list):");
    String groupsIn = input.nextLine();
    if (groupsIn.trim().length() > 0) {

      String[] groups = groupsIn.split(",");
      for (String group : groups) {
        if (repo.getGroups().contains(group)) {
          continue;
        }
        repositoryService.addGroup(repo, group);
        result.append(
            "Group " + group + " added successfully to repository " + repo.getAlias() + "\n");
      }
    }

    return result.toString();
  }
  @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();
  }
  @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();
    ExplorerService projectExplorerService =
        container.instance().select(ExplorerService.class).get();

    InputReader input = context.getInput();
    System.out.print(">>Repository alias:");
    String alias = input.nextLine();

    Repository repo = repositoryService.getRepository(alias);
    if (repo == null) {
      return "No repository " + alias + " was found";
    }

    OrganizationalUnit ou = null;
    Collection<OrganizationalUnit> units = organizationalUnitService.getOrganizationalUnits();
    for (OrganizationalUnit unit : units) {
      if (unit.getRepositories().contains(repo)) {
        ou = unit;
        break;
      }
    }
    if (ou == null) {
      return "Could not find Organizational Unit containing repository. Unable to proceed.";
    }

    ArrayList<Project> projects = new ArrayList<Project>();
    ProjectExplorerContentQuery query = new ProjectExplorerContentQuery(ou, repo, "master");
    query.setOptions(new ActiveOptions());
    ProjectExplorerContent content = projectExplorerService.getContent(query);
    projects.addAll(content.getProjects());
    if (projects.size() == 0) {
      return "No projects found in repository " + alias;
    }

    int projectIndex = 0;
    while (projectIndex == 0) {
      System.out.println(">>Select project:");
      for (int i = 0; i < projects.size(); i++) {
        System.out.println((i + 1) + ") " + projects.get(i).getProjectName());
      }
      try {
        projectIndex = Integer.parseInt(input.nextLine());
      } catch (NumberFormatException e) {
        System.out.println("Invalid index");
      }
      if (projectIndex < 1 || projectIndex > projects.size()) {
        projectIndex = 0;
        System.out.println("Invalid index");
      }
    }
    Project project = projects.get(projectIndex - 1);

    result.append("\tProject " + project.getProjectName() + "\n");
    result.append("\t Modules: " + project.getModules() + "\n");
    result.append("\t Root path: " + project.getRootPath().toURI() + "\n");
    result.append("\t Pom path: " + project.getPomXMLPath().toURI() + "\n");

    return result.toString();
  }