Search in sources :

Example 1 with EmptyRemoteRepositoryException

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);
}
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) ImportProject(org.kie.workbench.common.screens.examples.model.ImportProject) EmptyRemoteRepositoryException(org.kie.workbench.common.screens.examples.exception.EmptyRemoteRepositoryException)

Example 2 with EmptyRemoteRepositoryException

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())));
}
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 3 with EmptyRemoteRepositoryException

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());
}
Also used : OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) EmptyRemoteRepositoryException(org.kie.workbench.common.screens.examples.exception.EmptyRemoteRepositoryException) Test(org.junit.Test)

Example 4 with EmptyRemoteRepositoryException

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());
}
Also used : OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) NotificationEvent(org.uberfire.workbench.events.NotificationEvent) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) EmptyRemoteRepositoryException(org.kie.workbench.common.screens.examples.exception.EmptyRemoteRepositoryException) Test(org.junit.Test)

Aggregations

EmptyRemoteRepositoryException (org.kie.workbench.common.screens.examples.exception.EmptyRemoteRepositoryException)4 OrganizationalUnit (org.guvnor.structure.organizationalunit.OrganizationalUnit)2 Test (org.junit.Test)2 ExampleRepository (org.kie.workbench.common.screens.examples.model.ExampleRepository)2 ImportProject (org.kie.workbench.common.screens.examples.model.ImportProject)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 NotificationEvent (org.uberfire.workbench.events.NotificationEvent)2 Repository (org.guvnor.structure.repositories.Repository)1 GitRepository (org.guvnor.structure.repositories.impl.git.GitRepository)1 Message (org.jboss.errai.bus.client.api.messaging.Message)1 Credentials (org.kie.workbench.common.screens.examples.model.Credentials)1