@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();
  }
Exemplo 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();
    }
  }
  @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();
  }
Exemplo 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));
  }
Exemplo n.º 5
0
  @Override
  public Repository createRepository(
      final OrganizationalUnit organizationalUnit,
      final String scheme,
      final String alias,
      final RepositoryEnvironmentConfigurations repositoryEnvironmentConfigurations)
      throws RepositoryAlreadyExistsException {

    try {
      final Repository repository =
          createRepository(scheme, alias, repositoryEnvironmentConfigurations);
      if (organizationalUnit != null && repository != null) {
        organizationalUnitService.addRepository(organizationalUnit, repository);
      }
      return repository;
    } catch (final Exception e) {
      logger.error("Error during create repository", e);
      throw new RuntimeException(e);
    }
  }
  @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();
  }
Exemplo n.º 7
0
  @PostConstruct
  public void onStartup() {
    try {
      Repository jbpmRepo = repositoryService.getRepository(JBPM_REPO_PLAYGROUND);
      if (jbpmRepo == null) {
        jbpmRepo =
            repositoryService.createRepository(
                "git",
                JBPM_REPO_PLAYGROUND,
                new HashMap<String, Object>() {
                  {
                    put("origin", JBPM_URL);
                    put("username", userName);
                    put("crypt:password", password);
                  }
                });
      }

      // TODO in case repo is not defined in system repository so we add default
      //            Repository guvnorRepo = repositoryService.getRepository( GUVNOR_REPO_PLAYGROUND
      // );
      //            if ( guvnorRepo == null ) {
      //                guvnorRepo = repositoryService.createRepository( "git",
      //                                                                 GUVNOR_REPO_PLAYGROUND,
      //                                                                 new HashMap<String,
      // Object>() {{
      //                                                                     put( "origin",
      // GUVNOR_URL );
      //                                                                     put( "username",
      // userName );
      //                                                                     put( "crypt:password",
      // password );
      //                                                                 }} );
      //            }

      // TODO in case groups are not defined
      Collection<OrganizationalUnit> groups = organizationalUnitService.getOrganizationalUnits();
      if (groups == null || groups.isEmpty()) {
        final List<Repository> repositories = new ArrayList<Repository>();
        repositories.add(jbpmRepo);
        //                repositories.add( guvnorRepo );

        organizationalUnitService.createOrganizationalUnit(
            "demo", "*****@*****.**", null, repositories);
      }

      // Define mandatory properties
      List<ConfigGroup> globalConfigGroups =
          configurationService.getConfiguration(ConfigType.GLOBAL);
      boolean globalSettingsDefined = false;
      for (ConfigGroup globalConfigGroup : globalConfigGroups) {
        if (GLOBAL_SETTINGS.equals(globalConfigGroup.getName())) {
          globalSettingsDefined = true;
          break;
        }
      }
      if (!globalSettingsDefined) {
        configurationService.addConfiguration(getGlobalConfiguration());
      }

      // notify cluster service that bootstrap is completed to start synchronization
      if (ioService instanceof IOClusteredService) {
        ((IOClusteredService) ioService).start();
      }
    } catch (Exception e) {
      throw new RuntimeException("Error when starting designer " + e.getMessage(), e);
    }
  }