Esempio n. 1
0
  @Override
  public Repository createRepository(
      final String scheme,
      final String alias,
      final RepositoryEnvironmentConfigurations repositoryEnvironmentConfigurations) {

    if (configuredRepositories.containsAlias(alias)) {
      throw new RepositoryAlreadyExistsException(alias);
    }

    Repository repo = null;
    try {
      configurationService.startBatch();
      final ConfigGroup repositoryConfig =
          configurationFactory.newConfigGroup(REPOSITORY, alias, "");
      repositoryConfig.addConfigItem(
          configurationFactory.newConfigItem("security:groups", new ArrayList<String>()));

      if (!repositoryEnvironmentConfigurations.containsConfiguration(SCHEME)) {
        repositoryConfig.addConfigItem(configurationFactory.newConfigItem(SCHEME, scheme));
      }

      for (final RepositoryEnvironmentConfiguration configuration :
          repositoryEnvironmentConfigurations.getConfigurationList()) {
        repositoryConfig.addConfigItem(getRepositoryConfigItem(configuration));
      }

      repo = createRepository(repositoryConfig);
      return repo;
    } catch (final Exception e) {
      logger.error("Error during create repository", e);
      throw new RuntimeException(e);
    } finally {
      configurationService.endBatch();
      if (repo != null) {
        event.fire(new NewRepositoryEvent(repo));
      }
    }
  }
Esempio n. 2
0
  @Override
  public Repository updateRepositoryConfiguration(
      final Repository repository,
      final RepositoryEnvironmentConfigurations repositoryEnvironmentConfigurations) {
    final ConfigGroup thisRepositoryConfig = findRepositoryConfig(repository.getAlias());

    if (thisRepositoryConfig != null && repositoryEnvironmentConfigurations != null) {

      try {
        configurationService.startBatch();

        for (final Map.Entry<String, Object> entry :
            repositoryEnvironmentConfigurations.getConfigurationMap().entrySet()) {

          ConfigItem configItem = thisRepositoryConfig.getConfigItem(entry.getKey());
          if (configItem == null) {
            thisRepositoryConfig.addConfigItem(
                configurationFactory.newConfigItem(entry.getKey(), entry.getValue()));
          } else {
            configItem.setValue(entry.getValue());
          }
        }

        configurationService.updateConfiguration(thisRepositoryConfig);

        final Repository updatedRepo = repositoryFactory.newRepository(thisRepositoryConfig);
        configuredRepositories.update(updatedRepo);

        return updatedRepo;
      } catch (final Exception e) {
        logger.error("Error during remove repository", e);
        throw new RuntimeException(e);
      } finally {
        configurationService.endBatch();
      }

    } else {
      throw new IllegalArgumentException("Repository " + repository.getAlias() + " not found");
    }
  }