@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();
  }
Esempio n. 2
0
  @Override
  public void removeRepository(final String alias) {
    final ConfigGroup thisRepositoryConfig = findRepositoryConfig(alias);

    try {
      configurationService.startBatch();
      if (thisRepositoryConfig != null) {
        configurationService.removeConfiguration(thisRepositoryConfig);
      }

      final Repository repo = configuredRepositories.remove(alias);
      if (repo != null) {
        repositoryRemovedEvent.fire(new RepositoryRemovedEvent(repo));
        ioService.delete(convert(repo.getRoot()).getFileSystem().getPath(null));
      }

      // Remove reference to Repository from Organizational Units
      final Collection<OrganizationalUnit> organizationalUnits =
          organizationalUnitService.getOrganizationalUnits();
      for (OrganizationalUnit ou : organizationalUnits) {
        for (Repository repository : ou.getRepositories()) {
          if (repository.getAlias().equals(alias)) {
            organizationalUnitService.removeRepository(ou, repository);
          }
        }
      }
    } catch (final Exception e) {
      logger.error("Error during remove repository", e);
      throw new RuntimeException(e);
    } finally {
      configurationService.endBatch();
    }
  }
  @Test
  public void loadTest() throws Exception {
    when(libraryService.getDefaultLibraryInfo()).thenReturn(getDefaultLibraryMock());

    newProjectScreen.load();

    verify(view).setOUAlias(ouAlias);
    verify(view, times(2)).addOrganizationUnit(any());
    verify(view).setOrganizationUnitSelected(ou2.getIdentifier());
    assertEquals(ou2.getIdentifier(), newProjectScreen.selectOu);
  }
Esempio n. 4
0
  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();
  }
  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;
  }
  @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();
  }