Search in sources :

Example 1 with Credentials

use of org.kie.workbench.common.screens.examples.model.Credentials in project kie-wb-common by kiegroup.

the class ImportRepositoryPopUpPresenter method importRepository.

public void importRepository() {
    final String repositoryUrl = view.getRepositoryURL();
    if (isEmpty(repositoryUrl)) {
        view.showError(view.getEmptyRepositoryURLValidationMessage());
        return;
    }
    final String fixedRepositoryUrl = repositoryUrl.trim();
    view.showBusyIndicator(view.getLoadingMessage());
    importService.call((Set<ImportProject> projects) -> {
        view.hideBusyIndicator();
        if (projects.isEmpty()) {
            view.showError(view.getNoProjectsToImportMessage());
        } else {
            view.hide();
            libraryPlaces.goToExternalImportPresenter(projects);
        }
    }, (Message message, Throwable throwable) -> {
        if (throwable instanceof EmptyRemoteRepositoryException) {
            final String repositoryAlias = ((EmptyRemoteRepositoryException) throwable).getRepositoryAlias();
            createProjectFromEmptyRemoteRepository(fixedRepositoryUrl, repositoryAlias);
        } else {
            view.hideBusyIndicator();
            view.showError(view.getNoProjectsToImportMessage());
        }
        return false;
    }).getProjects(this.libraryPlaces.getActiveSpace(), new ExampleRepository(fixedRepositoryUrl, new Credentials(view.getUserName(), view.getPassword())));
}
Also used : Message(org.jboss.errai.bus.client.api.messaging.Message) ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) EmptyRemoteRepositoryException(org.kie.workbench.common.screens.examples.exception.EmptyRemoteRepositoryException) Credentials(org.kie.workbench.common.screens.examples.model.Credentials)

Example 2 with Credentials

use of org.kie.workbench.common.screens.examples.model.Credentials in project kie-wb-common by kiegroup.

the class ProjectImportServiceImpl method resolveGitRepository.

@Override
protected Repository resolveGitRepository(ExampleRepository repository) {
    try {
        String url = repository.getUrl();
        final String alias = getRepositoryAlias(url) + "_" + LocalTime.now().toString();
        Credentials credentials = repository.getCredentials();
        String username = null;
        String password = null;
        if (credentials != null) {
            username = credentials.getUsername();
            password = credentials.getPassword();
        }
        final Map<String, Object> env = this.buildGitEnv(url, username, password, true);
        final RepositoryInfo repositoryConfig = createConfigGroup(alias, env);
        Repository repo = repositoryFactory.newRepository(repositoryConfig);
        clonedRepositories.add(repo);
        return repo;
    } 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) RepositoryInfo(org.guvnor.structure.organizationalunit.config.RepositoryInfo) Credentials(org.kie.workbench.common.screens.examples.model.Credentials)

Example 3 with Credentials

use of org.kie.workbench.common.screens.examples.model.Credentials in project kie-wb-common by kiegroup.

the class ProjectImportServiceImplTest method testProjectImportWithNullCredentialsTest.

@Test
public void testProjectImportWithNullCredentialsTest() {
    final ArgumentCaptor<RepositoryEnvironmentConfigurations> captor = ArgumentCaptor.forClass(RepositoryEnvironmentConfigurations.class);
    final String origin = "file:///some/path/to/fake-repo.git";
    final String username = "fakeUser";
    final String password = null;
    final List<String> branches = Arrays.asList("main");
    final ImportProject importProject = mock(ImportProject.class);
    final Path rootPath = mock(Path.class);
    final org.uberfire.java.nio.file.Path convertedRootPath = mock(org.uberfire.java.nio.file.Path.class);
    when(pathUtil.convert(Mockito.<Path>any())).thenReturn(convertedRootPath);
    when(convertedRootPath.getFileSystem()).thenReturn(mock(FileSystem.class));
    when(service.getProjectRoot(rootPath)).thenReturn(convertedRootPath);
    when(importProject.getCredentials()).thenReturn(new Credentials(username, password));
    when(importProject.getRoot()).thenReturn(rootPath);
    when(importProject.getOrigin()).thenReturn(origin);
    when(importProject.getSelectedBranches()).thenReturn(branches);
    when(service.getProjectRoot(importProject)).thenReturn(convertedRootPath);
    service.importProject(organizationalUnit, importProject);
    verify(repoService).createRepository(any(), any(), any(), captor.capture());
    assertFalse(captor.getValue().containsConfiguration(EnvironmentParameters.USER_NAME));
    assertFalse(captor.getValue().containsConfiguration(EnvironmentParameters.PASSWORD));
}
Also used : Path(org.uberfire.backend.vfs.Path) RepositoryEnvironmentConfigurations(org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations) ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) FileSystem(org.uberfire.java.nio.file.FileSystem) Mockito.anyString(org.mockito.Mockito.anyString) Credentials(org.kie.workbench.common.screens.examples.model.Credentials) Test(org.junit.Test)

Example 4 with Credentials

use of org.kie.workbench.common.screens.examples.model.Credentials in project kie-wb-common by kiegroup.

the class BaseProjectImportService method importProject.

@Override
public WorkspaceProject importProject(OrganizationalUnit organizationalUnit, ImportProject importProject) {
    this.checkIfProjectAlreadyExist(organizationalUnit, importProject);
    final org.uberfire.java.nio.file.Path rootPath = getProjectRoot(importProject);
    String origin = importProject.getOrigin();
    final RepositoryEnvironmentConfigurations configurations = new RepositoryEnvironmentConfigurations();
    configurations.setInit(false);
    configurations.setOrigin(origin);
    configurations.setBranches(getBranches(importProject, rootPath));
    Credentials credentials = importProject.getCredentials();
    if (credentials != null && credentials.getUsername() != null && credentials.getPassword() != null) {
        configurations.setUserName(credentials.getUsername());
        configurations.setPassword(credentials.getPassword());
    }
    configurations.setMirror(false);
    String projectName = importProject.getName();
    if (!pathUtil.convert(importProject.getRoot()).equals(rootPath)) {
        final String subdirectoryPath = pathUtil.stripRepoNameAndSpace(pathUtil.stripProtocolAndBranch(importProject.getRoot().toURI()));
        configurations.setSubdirectory(subdirectoryPath);
    } else {
        projectName = inferProjectName(importProject.getOrigin());
    }
    final Repository importedRepo = repoService.createRepository(organizationalUnit, GitRepository.SCHEME.toString(), projectName, configurations);
    // Signal creation of new Project (Creation of OU and Repository, if applicable,
    // are already handled in the corresponding services).
    WorkspaceProject project = projectService.resolveProject(importedRepo);
    // delete the transient repo created in system folder
    ioService.deleteIfExists(rootPath.getFileSystem().getPath(null));
    return project;
}
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) RepositoryEnvironmentConfigurations(org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) Credentials(org.kie.workbench.common.screens.examples.model.Credentials)

Example 5 with Credentials

use of org.kie.workbench.common.screens.examples.model.Credentials in project kie-wb-common by kiegroup.

the class ProjectImportServiceImplTest method testProjectImportWithCredentialsTest.

@Test
public void testProjectImportWithCredentialsTest() {
    final String origin = "file:///some/path/to/fake-repo.git";
    final String username = "fakeUser";
    final String password = "fakePassword";
    final List<String> branches = Arrays.asList("main");
    final ImportProject importProject = mock(ImportProject.class);
    final Path rootPath = mock(Path.class);
    final org.uberfire.java.nio.file.Path convertedRootPath = mock(org.uberfire.java.nio.file.Path.class);
    when(pathUtil.convert(Mockito.<Path>any())).thenReturn(convertedRootPath);
    when(convertedRootPath.getFileSystem()).thenReturn(mock(FileSystem.class));
    when(service.getProjectRoot(rootPath)).thenReturn(convertedRootPath);
    when(importProject.getCredentials()).thenReturn(new Credentials(username, password));
    when(importProject.getRoot()).thenReturn(rootPath);
    when(importProject.getOrigin()).thenReturn(origin);
    when(importProject.getSelectedBranches()).thenReturn(branches);
    when(service.getProjectRoot(importProject)).thenReturn(convertedRootPath);
    service.importProject(organizationalUnit, importProject);
    verify(repoService).createRepository(eq(organizationalUnit), any(), any(), configurations.capture());
    assertEquals(username, configurations.getValue().getUserName());
}
Also used : Path(org.uberfire.backend.vfs.Path) ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) JGitFileSystem(org.uberfire.java.nio.fs.jgit.JGitFileSystem) FileSystem(org.uberfire.java.nio.file.FileSystem) Mockito.anyString(org.mockito.Mockito.anyString) Credentials(org.kie.workbench.common.screens.examples.model.Credentials) Test(org.junit.Test)

Aggregations

Credentials (org.kie.workbench.common.screens.examples.model.Credentials)7 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)4 Test (org.junit.Test)3 ImportProject (org.kie.workbench.common.screens.examples.model.ImportProject)3 Repository (org.guvnor.structure.repositories.Repository)2 RepositoryEnvironmentConfigurations (org.guvnor.structure.repositories.RepositoryEnvironmentConfigurations)2 Mockito.anyString (org.mockito.Mockito.anyString)2 Path (org.uberfire.backend.vfs.Path)2 FileSystem (org.uberfire.java.nio.file.FileSystem)2 JGitFileSystem (org.uberfire.java.nio.fs.jgit.JGitFileSystem)2 WorkspaceProject (org.guvnor.common.services.project.model.WorkspaceProject)1 RepositoryInfo (org.guvnor.structure.organizationalunit.config.RepositoryInfo)1 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)1 Message (org.jboss.errai.bus.client.api.messaging.Message)1 EmptyRemoteRepositoryException (org.kie.workbench.common.screens.examples.exception.EmptyRemoteRepositoryException)1