@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.º 2
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);
    }
  }