use of org.kie.workbench.common.screens.examples.exception.EmptyRemoteRepositoryException in project kie-wb-common by kiegroup.
the class BaseProjectImportService method getProjects.
@Override
public Set<ImportProject> getProjects(final OrganizationalUnit target, final ExampleRepository repository) {
if (repository == null) {
return Collections.emptySet();
}
final String repositoryURL = repository.getUrl();
if (repositoryURL == null || repositoryURL.trim().isEmpty()) {
return Collections.emptySet();
}
Repository gitRepository = resolveGitRepository(repository);
if (gitRepository == null) {
return Collections.emptySet();
}
if (gitRepository.getBranches().isEmpty()) {
throw new EmptyRemoteRepositoryException(getRepositoryAlias(repositoryURL));
}
Set<ImportProject> importProjects = convert(gitRepository.getBranch("master").get(), repository);
return validateProjects(target, importProjects);
}
use of org.kie.workbench.common.screens.examples.exception.EmptyRemoteRepositoryException 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.exception.EmptyRemoteRepositoryException in project kie-wb-common by kiegroup.
the class ImportRepositoryPopUpPresenterTest method importEmptyRepositoryOnSuccessTest.
@Test
public void importEmptyRepositoryOnSuccessTest() {
final String repositoryUrl = "repoUrl";
final String repositoryAlias = "myRepository";
final OrganizationalUnit orgUnit = mock(OrganizationalUnit.class);
doThrow(new EmptyRemoteRepositoryException(repositoryAlias)).when(importService).getProjects(any(), any());
doReturn(repositoryUrl).when(view).getRepositoryURL();
doReturn(Optional.of(orgUnit)).when(projectContext).getActiveOrganizationalUnit();
presenter.importRepository();
verify(libraryService).createProject(orgUnit, repositoryUrl, repositoryAlias);
verify(view, never()).showError(anyString());
verify(view).hideBusyIndicator();
verify(view).hide();
verify(notificationEvent).fire(any(NotificationEvent.class));
verify(libraryPlaces).goToProject(Mockito.<WorkspaceProject>any());
}
use of org.kie.workbench.common.screens.examples.exception.EmptyRemoteRepositoryException in project kie-wb-common by kiegroup.
the class ImportRepositoryPopUpPresenterTest method importEmptyRepositoryOnFailureTest.
@Test
public void importEmptyRepositoryOnFailureTest() {
final String repositoryUrl = "repoUrl";
final String repositoryAlias = "myRepository";
final OrganizationalUnit orgUnit = mock(OrganizationalUnit.class);
doThrow(new EmptyRemoteRepositoryException(repositoryAlias)).when(importService).getProjects(any(), any());
doThrow(new RuntimeException()).when(libraryService).createProject(any(), anyString(), anyString());
doReturn(repositoryUrl).when(view).getRepositoryURL();
doReturn(Optional.of(orgUnit)).when(projectContext).getActiveOrganizationalUnit();
presenter.importRepository();
verify(view).showError(Mockito.<String>any());
verify(view).hideBusyIndicator();
verify(view, never()).hide();
verify(notificationEvent, never()).fire(any(NotificationEvent.class));
verify(libraryPlaces, never()).goToProject(Mockito.<WorkspaceProject>any());
}
Aggregations