Search in sources :

Example 36 with Repository

use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.

the class ExplorerServiceImpl method getContent.

@Override
public ProjectExplorerContent getContent(final String _path, final ActiveOptions activeOptions) {
    checkNotEmpty("path", _path);
    final Path path = Paths.convert(ioService.get(URI.create(_path.trim())));
    final Module module = moduleService.resolveModule(path);
    final Path convertedPath = Paths.convert(Paths.convert(path).getRoot());
    final Repository repo = repositoryService.getRepository(convertedPath);
    final Branch branch = getBranch(repo, convertedPath);
    return getContent(new ProjectExplorerContentQuery(repo, branch, module, activeOptions));
}
Also used : Path(org.uberfire.backend.vfs.Path) Repository(org.guvnor.structure.repositories.Repository) Branch(org.guvnor.structure.repositories.Branch) ProjectExplorerContentQuery(org.kie.workbench.common.screens.explorer.service.ProjectExplorerContentQuery) Module(org.guvnor.common.services.project.model.Module)

Example 37 with Repository

use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.

the class ProjectExplorerContentResolver method setupSelectedItems.

protected Content setupSelectedItems(ProjectExplorerContentQuery query) {
    final Content content = new Content(query, getProject(query));
    final UserExplorerLastData lastContent = helper.getLastContent();
    final UserExplorerData userContent = helper.loadUserContent();
    if (!lastContent.isDataEmpty()) {
        if (query.getRepository() == null && query.getModule() == null) {
            // If nothing has been selected (i.e. on start-up) set-up Content from last saved state
            if (query.getOptions().contains(Option.BUSINESS_CONTENT) && lastContent.getLastPackage() != null) {
                Repository lastRepo = lastContent.getLastPackage().getRepository();
                content.setSelectedProject(projectService.resolveProject(lastRepo.getSpace(), lastRepo.getBranch(lastContent.getLastPackage().getBranch()).get()));
                content.setSelectedModule(lastContent.getLastPackage().getModule());
                content.setSelectedPackage(lastContent.getLastPackage().getPkg());
                content.setSelectedItem(null);
            } else if (query.getOptions().contains(Option.TECHNICAL_CONTENT) && lastContent.getLastFolderItem() != null) {
                content.setSelectedProject(projectService.resolveProject(lastContent.getLastFolderItem().getRepository().getSpace(), lastContent.getLastFolderItem().getRepository().getBranch(lastContent.getLastFolderItem().getBranch()).get()));
                content.setSelectedModule(lastContent.getLastFolderItem().getModule());
                content.setSelectedItem(lastContent.getLastFolderItem().getItem());
                content.setSelectedPackage(null);
            }
        } else if (query.getOptions().contains(Option.BUSINESS_CONTENT) && lastContent.getLastPackage() != null) {
            if (query.getRepository() != null && !query.getRepository().equals(lastContent.getLastPackage().getRepository()) || query.getBranch() != null && !query.getBranch().getName().equals(lastContent.getLastPackage().getBranch()) || query.getModule() != null && !query.getModule().equals(lastContent.getLastPackage().getModule())) {
                // Handle a change in selected Repository or Module in BUSINESS_CONTENT view
                content.setSelectedProject(loadProject(query.getRepository().getSpace(), query.getRepository().getBranch(query.getBranch().getName()).get()));
                content.setSelectedModule(loadModule(content.getSelectedProject(), query.getModule()));
                content.setSelectedPackage(loadPackage(content.getSelectedProject(), content.getSelectedModule(), query.getPkg(), userContent));
                content.setSelectedItem(null);
            } else {
                // Fall back to the last saved state
                content.setSelectedProject(loadProject(lastContent.getLastPackage().getRepository().getSpace(), lastContent.getLastPackage().getRepository().getBranch(lastContent.getLastPackage().getBranch()).get()));
                content.setSelectedModule(loadModule(content.getSelectedProject(), lastContent.getLastPackage().getModule()));
                content.setSelectedPackage(loadPackage(content.getSelectedProject(), content.getSelectedModule(), lastContent.getLastPackage().getPkg(), userContent));
                content.setSelectedItem(null);
            }
        } else if (query.getOptions().contains(Option.TECHNICAL_CONTENT) && lastContent.getLastFolderItem() != null) {
            if (lastContent.getOptions().contains(Option.BUSINESS_CONTENT)) {
                // When switching from BUSINESS_VIEW we cannot use LastFolderItem().getItem() and must use Module root; set by FolderListingResolver.getFolderListing()
                content.setSelectedProject(loadProject(lastContent.getLastPackage().getRepository().getSpace(), lastContent.getLastFolderItem().getRepository().getBranch(lastContent.getLastPackage().getBranch()).get()));
                content.setSelectedModule(loadModule(content.getSelectedProject(), lastContent.getLastFolderItem().getModule()));
                content.setSelectedItem(null);
                content.setSelectedPackage(null);
            } else if (query.getRepository() != null && !query.getRepository().equals(lastContent.getLastFolderItem().getRepository()) || query.getModule() != null && !query.getModule().equals(lastContent.getLastFolderItem().getModule())) {
                // Handle a change in selected OU, Repository or Module in TECHNICAL_CONTENT view
                content.setSelectedProject(loadProject(query.getRepository().getSpace(), query.getRepository().getBranch(query.getBranch().getName()).get()));
                content.setSelectedModule(loadModule(content.getSelectedProject(), query.getModule()));
                content.setSelectedItem(null);
                content.setSelectedPackage(null);
            } else {
                // Fall back to the last saved state
                content.setSelectedProject(loadProject(query.getRepository().getSpace(), lastContent.getLastFolderItem().getRepository().getBranch(lastContent.getLastFolderItem().getBranch()).get()));
                content.setSelectedModule(loadModule(content.getSelectedProject(), lastContent.getLastFolderItem().getModule()));
                content.setSelectedItem(loadFolderItem(content.getSelectedProject(), content.getSelectedModule(), lastContent.getLastFolderItem().getItem(), userContent));
                content.setSelectedPackage(null);
            }
        }
    }
    return content;
}
Also used : Repository(org.guvnor.structure.repositories.Repository) ProjectExplorerContent(org.kie.workbench.common.screens.explorer.model.ProjectExplorerContent)

Example 38 with Repository

use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.

the class ExamplesServiceImpl method cloneRepository.

private Repository cloneRepository(final String repositoryURL, final String userName, final String password) {
    Repository repository = null;
    try {
        final String alias = getExampleAlias(repositoryURL);
        final Map<String, Object> env = new HashMap<String, Object>() {

            {
                put("origin", repositoryURL);
                put(SCHEME, GitRepository.SCHEME.toString());
                put("replaceIfExists", true);
                put("username", userName);
                put("password", password);
                put(MIRROR, false);
            }
        };
        final ConfigGroup repositoryConfig = configurationFactory.newConfigGroup(REPOSITORY, "system", alias, "");
        for (final Map.Entry<String, Object> entry : env.entrySet()) {
            repositoryConfig.addConfigItem(configurationFactory.newConfigItem(entry.getKey(), entry.getValue()));
        }
        repositoryConfig.addConfigItem(configurationFactory.newConfigItem(EnvironmentParameters.AVOID_INDEX, "true"));
        repositoryConfig.addConfigItem(configurationFactory.newConfigItem(EnvironmentParameters.SPACE, "system"));
        repository = repositoryFactory.newRepository(repositoryConfig);
        clonedRepositories.add(repository);
        return repository;
    } catch (final Exception e) {
        logger.error("Error during create repository", e);
        throw new RuntimeException(e);
    }
}
Also used : ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) Repository(org.guvnor.structure.repositories.Repository) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) HashMap(java.util.HashMap) ConfigGroup(org.guvnor.structure.server.config.ConfigGroup) Map(java.util.Map) HashMap(java.util.HashMap) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(org.uberfire.java.nio.IOException)

Example 39 with Repository

use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.

the class ExamplesServiceImplTest method resolveGitRepositoryClonedBefore.

@Test
public void resolveGitRepositoryClonedBefore() {
    ExampleRepository playgroundRepository = new ExampleRepository("file:///home/user/folder/.kie-wb-playground");
    service.setPlaygroundRepository(playgroundRepository);
    GitRepository repository = mock(GitRepository.class);
    Map<String, Object> repositoryEnvironment = new HashMap<>();
    repositoryEnvironment.put("origin", playgroundRepository.getUrl());
    when(repository.getEnvironment()).thenReturn(repositoryEnvironment);
    service.getClonedRepositories().add(repository);
    Repository result = service.resolveGitRepository(playgroundRepository);
    assertEquals(repository, result);
    verify(repositoryFactory, never()).newRepository(any(ConfigGroup.class));
}
Also used : GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) Repository(org.guvnor.structure.repositories.Repository) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) HashMap(java.util.HashMap) ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) ConfigGroup(org.guvnor.structure.server.config.ConfigGroup) Test(org.junit.Test)

Example 40 with Repository

use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.

the class DefExplorerQueryServiceImpl method resolveRepositories.

/**
 * Given an organizational unit, resolves the repositories accessible by current user in the given OU.
 */
private Map<String, Repository> resolveRepositories(final OrganizationalUnit organizationalUnit) {
    final Map<String, Repository> authorizedRepositories = new HashMap<>();
    if (organizationalUnit == null) {
        return authorizedRepositories;
    }
    // Reload OrganizationalUnit as the organizational unit's repository list might have been changed server-side
    final Collection<Repository> repositories = organizationalUnitService.getOrganizationalUnit(organizationalUnit.getName()).getRepositories();
    for (Repository repository : repositories) {
        if (authorizationManager.authorize(repository, identity)) {
            authorizedRepositories.put(repository.getAlias(), repository);
        }
    }
    return authorizedRepositories;
}
Also used : Repository(org.guvnor.structure.repositories.Repository) HashMap(java.util.HashMap)

Aggregations

Repository (org.guvnor.structure.repositories.Repository)51 Test (org.junit.Test)25 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)21 Branch (org.guvnor.structure.repositories.Branch)21 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)20 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)15 Module (org.guvnor.common.services.project.model.Module)14 ArrayList (java.util.ArrayList)13 Path (org.uberfire.backend.vfs.Path)13 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)10 POM (org.guvnor.common.services.project.model.POM)7 KieModule (org.kie.workbench.common.services.shared.project.KieModule)7 ExampleOrganizationalUnit (org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit)5 HashMap (java.util.HashMap)4 MavenRepositoryMetadata (org.guvnor.common.services.project.model.MavenRepositoryMetadata)4 Before (org.junit.Before)4 Metadata (org.guvnor.common.services.shared.metadata.model.Metadata)3 RepositoryEnvironmentConfigurations (org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations)3 ConfigGroup (org.guvnor.structure.server.config.ConfigGroup)3 Space (org.uberfire.spaces.Space)3