Search in sources :

Example 1 with TenantRepository

use of org.eclipse.winery.repository.filebased.TenantRepository in project winery by eclipse.

the class RepositoryFactory method reconfigure.

public static void reconfigure(GitBasedRepositoryConfiguration configuration) throws IOException, GitAPIException {
    RepositoryFactory.gitBasedRepositoryConfiguration = configuration;
    RepositoryFactory.fileBasedRepositoryConfiguration = null;
    if (repositoryContainsMultiRepositoryConfiguration(configuration)) {
        repository = new MultiRepository(configuration.getRepositoryPath().get());
    } else if (Environments.getInstance().getRepositoryConfig().isTenantRepository()) {
        repository = new TenantRepository(configuration.getRepositoryPath().get());
    } else {
        // if a repository root is specified, use it instead of the root specified in the config
        AbstractFileBasedRepository localRepository = configuration.getRepositoryPath().isPresent() ? createXmlOrYamlRepository(configuration, configuration.getRepositoryPath().get()) : createXmlOrYamlRepository(configuration, Paths.get(Environments.getInstance().getRepositoryConfig().getRepositoryRoot()));
        repository = new GitBasedRepository(configuration, localRepository);
    }
}
Also used : MultiRepository(org.eclipse.winery.repository.filebased.MultiRepository) AbstractFileBasedRepository(org.eclipse.winery.repository.backend.filebased.AbstractFileBasedRepository) TenantRepository(org.eclipse.winery.repository.filebased.TenantRepository) GitBasedRepository(org.eclipse.winery.repository.backend.filebased.GitBasedRepository)

Example 2 with TenantRepository

use of org.eclipse.winery.repository.filebased.TenantRepository in project winery by eclipse.

the class RepositoryFactory method reconfigure.

public static void reconfigure(FileBasedRepositoryConfiguration configuration) {
    RepositoryFactory.fileBasedRepositoryConfiguration = configuration;
    RepositoryFactory.gitBasedRepositoryConfiguration = null;
    if (repositoryContainsMultiRepositoryConfiguration(configuration)) {
        try {
            repository = new MultiRepository(configuration.getRepositoryPath().get());
        } catch (IOException | GitAPIException e) {
            LOGGER.error("Error while initializing Multi-Repository!");
        }
    } else if (Environments.getInstance().getRepositoryConfig().isTenantRepository()) {
        try {
            repository = new TenantRepository(configuration.getRepositoryPath().get());
        } catch (IOException | GitAPIException e) {
            LOGGER.error("Error while initializing Tenant-Repository");
        }
    } else {
        // if a repository root is specified, use it instead of the root specified in the config
        repository = configuration.getRepositoryPath().isPresent() ? createXmlOrYamlRepository(configuration, configuration.getRepositoryPath().get()) : createXmlOrYamlRepository(configuration, Paths.get(Environments.getInstance().getRepositoryConfig().getRepositoryRoot()));
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) MultiRepository(org.eclipse.winery.repository.filebased.MultiRepository) TenantRepository(org.eclipse.winery.repository.filebased.TenantRepository) IOException(java.io.IOException)

Example 3 with TenantRepository

use of org.eclipse.winery.repository.filebased.TenantRepository in project winery by eclipse.

the class TenantFilter method filter.

@Override
public void filter(ContainerRequestContext containerRequestContext) throws IOException {
    MultivaluedMap<String, String> headers = containerRequestContext.getHeaders();
    MultivaluedMap<String, String> queryParameters = containerRequestContext.getUriInfo().getQueryParameters();
    String tenantName = null;
    if (headers.containsKey(WINERY_TENANT)) {
        tenantName = headers.getFirst(WINERY_TENANT);
    } else if (queryParameters.containsKey(WINERY_TENANT)) {
        tenantName = queryParameters.getFirst(WINERY_TENANT);
    }
    if (tenantName != null) {
        LOGGER.debug("Got new request for tenant: " + tenantName);
        IRepository repo = RepositoryFactory.getRepository();
        if (repo instanceof TenantRepository) {
            ((TenantRepository) repo).useTenant(tenantName);
        }
    }
}
Also used : TenantRepository(org.eclipse.winery.repository.filebased.TenantRepository) IRepository(org.eclipse.winery.repository.backend.IRepository)

Aggregations

TenantRepository (org.eclipse.winery.repository.filebased.TenantRepository)3 MultiRepository (org.eclipse.winery.repository.filebased.MultiRepository)2 IOException (java.io.IOException)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 IRepository (org.eclipse.winery.repository.backend.IRepository)1 AbstractFileBasedRepository (org.eclipse.winery.repository.backend.filebased.AbstractFileBasedRepository)1 GitBasedRepository (org.eclipse.winery.repository.backend.filebased.GitBasedRepository)1