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())));
}
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);
}
}
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));
}
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;
}
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());
}
Aggregations