Search in sources :

Example 16 with Repository

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

the class ExamplesServiceImpl method setupExamples.

@Override
public WorkspaceProjectContextChangeEvent setupExamples(final ExampleOrganizationalUnit exampleTargetOU, final List<ExampleProject> exampleProjects) {
    PortablePreconditions.checkNotNull("exampleTargetOU", exampleTargetOU);
    PortablePreconditions.checkNotNull("exampleProjects", exampleProjects);
    PortablePreconditions.checkCondition("Must have at least one ExampleProject", exampleProjects.size() > 0);
    // Retrieve or create Organizational Unit
    final String targetOUName = exampleTargetOU.getName();
    final OrganizationalUnit targetOU = getOrganizationalUnit(targetOUName);
    WorkspaceProject firstExampleProject = null;
    for (final ExampleProject exampleProject : exampleProjects) {
        try {
            final Repository targetRepository = repositoryCopier.copy(targetOU, exampleProject.getName(), exampleProject.getRoot());
            // Signal creation of new Project (Creation of OU and Repository, if applicable,
            // are already handled in the corresponding services).
            WorkspaceProject project = projectService.resolveProject(targetRepository);
            project = renameIfNecessary(targetOU, project);
            newProjectEvent.fire(new NewProjectEvent(project));
            // Store first new example project
            if (firstExampleProject == null) {
                firstExampleProject = project;
            }
        } catch (IOException ioe) {
            logger.error("Unable to create Example(s).", ioe);
        }
    }
    return new WorkspaceProjectContextChangeEvent(firstExampleProject, firstExampleProject.getMainModule());
}
Also used : NewProjectEvent(org.guvnor.common.services.project.events.NewProjectEvent) ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) Repository(org.guvnor.structure.repositories.Repository) GitRepository(org.guvnor.structure.repositories.impl.git.GitRepository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ExampleOrganizationalUnit(org.kie.workbench.common.screens.examples.model.ExampleOrganizationalUnit) WorkspaceProject(org.guvnor.common.services.project.model.WorkspaceProject) IOException(org.uberfire.java.nio.IOException) WorkspaceProjectContextChangeEvent(org.guvnor.common.services.project.context.WorkspaceProjectContextChangeEvent) ExampleProject(org.kie.workbench.common.screens.examples.model.ExampleProject)

Example 17 with Repository

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

the class ExamplesServiceImpl method getProjects.

@Override
public Set<ExampleProject> getProjects(final ExampleRepository repository) {
    if (repository == null) {
        return Collections.emptySet();
    }
    final String repositoryURL = repository.getUrl();
    if (repositoryURL == null || repositoryURL.trim().isEmpty()) {
        return Collections.emptySet();
    }
    // Avoid cloning playground repository multiple times
    Repository gitRepository = resolveGitRepository(repository);
    if (gitRepository == null) {
        return Collections.emptySet();
    }
    final Set<Module> modules = moduleService.getAllModules(gitRepository.getBranch("master").get());
    return convert(modules);
}
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) Module(org.guvnor.common.services.project.model.Module)

Example 18 with Repository

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

the class ExamplesServiceImplTest method resolveGitRepositoryNotClonedBefore.

@Test
public void resolveGitRepositoryNotClonedBefore() {
    ExampleRepository playgroundRepository = new ExampleRepository("file:///home/user/folder/.kie-wb-playground");
    service.setPlaygroundRepository(playgroundRepository);
    ConfigGroup configGroup = new ConfigGroup();
    when(configurationFactory.newConfigGroup(any(ConfigType.class), anyString(), anyString(), anyString())).thenReturn(configGroup);
    doCallRealMethod().when(configurationFactory).newConfigItem(anyString(), anyBoolean());
    doCallRealMethod().when(configurationFactory).newConfigItem(anyString(), anyString());
    doCallRealMethod().when(configurationFactory).newConfigItem(anyString(), any(Object.class));
    Repository repository = mock(Repository.class);
    when(repositoryFactory.newRepository(configGroup)).thenReturn(repository);
    Repository result = service.resolveGitRepository(playgroundRepository);
    assertEquals(repository, result);
    assertEquals(false, configGroup.getConfigItem(EnvironmentParameters.MIRROR).getValue());
    verify(repositoryFactory, times(1)).newRepository(configGroup);
}
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) ExampleRepository(org.kie.workbench.common.screens.examples.model.ExampleRepository) ConfigGroup(org.guvnor.structure.server.config.ConfigGroup) ConfigType(org.guvnor.structure.server.config.ConfigType) Test(org.junit.Test)

Example 19 with Repository

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

the class DefExplorerQueryServiceImpl method resolveQuery.

private DefExplorerQueryResult resolveQuery(final DefExplorerQuery query) {
    final DefExplorerQueryResult result = new DefExplorerQueryResult();
    // load the organizational units.
    final Collection<OrganizationalUnit> organizationalUnits = resolveOrganizationalUnits();
    // piggyback the organizational units.
    result.getOrganizationalUnits().addAll(organizationalUnits);
    if (query.getOrganizationalUnit() == null || !containsOU(organizationalUnits, query.getOrganizationalUnit())) {
        // if no OU was set for filtering or the selected OU has been removed or has changed in backend.
        return result;
    }
    // set the repositories for current OU.
    final Map<String, Repository> repositories = resolveRepositories(query.getOrganizationalUnit());
    // piggyback the repositories.
    result.getRepositories().addAll(repositories.values());
    if (query.getRepository() == null || !repositories.containsKey(query.getRepository().getAlias())) {
        // changed in backend.
        return result;
    }
    // load the modules for current OU/Repository and the selected branch.
    final Map<String, Module> modules = resolveModules(repositories, query.getBranchName());
    result.getModules().addAll(modules.values());
    if (query.getModule() == null || !modules.containsKey(query.getModule().getModuleName())) {
        // changed in backend.
        return result;
    }
    // get the data sources and drivers for the selected module.
    result.setDataSourceDefs(queryService.findModuleDataSources(query.getModule()));
    result.setDriverDefs(queryService.findModuleDrivers(query.getModule()));
    return result;
}
Also used : Repository(org.guvnor.structure.repositories.Repository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) Module(org.guvnor.common.services.project.model.Module) DefExplorerQueryResult(org.kie.workbench.common.screens.datasource.management.service.DefExplorerQueryResult)

Example 20 with Repository

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

the class ModuleSelector method loadOptions.

public void loadOptions(final Collection<OrganizationalUnit> organizationalUnits, final OrganizationalUnit activeOrganizationalUnit, final Collection<Repository> repositories, final Repository activeRepository, final Collection<Module> modules, final Module activeModule) {
    this.organizationUnits.clear();
    if (organizationalUnits != null) {
        if (activeOrganizationalUnit != null) {
            this.organizationUnits.setText(activeOrganizationalUnit.getName());
        }
        for (final OrganizationalUnit ou : organizationalUnits) {
            this.organizationUnits.add(new AnchorListItem(ou.getName()) {

                {
                    addClickHandler(new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                            onOrganizationalUnitSelected(ou);
                        }
                    });
                }
            });
        }
    }
    this.repos.clear();
    if (repositories != null) {
        if (activeRepository != null) {
            this.repos.setText(activeRepository.getAlias());
        } else {
            this.repos.setText(ProjectExplorerConstants.INSTANCE.nullEntry());
        }
        for (final Repository repository : repositories) {
            this.repos.add(new AnchorListItem(repository.getAlias()) {

                {
                    addClickHandler(new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                            onRepositorySelected(repository);
                        }
                    });
                }
            });
        }
    }
    this.modules.clear();
    if (modules != null) {
        if (activeModule != null) {
            this.modules.setText(activeModule.getModuleName());
        } else {
            this.modules.setText(ProjectExplorerConstants.INSTANCE.nullEntry());
        }
        for (final Module module : modules) {
            this.modules.add(new AnchorListItem(module.getModuleName()) {

                {
                    addClickHandler(new ClickHandler() {

                        @Override
                        public void onClick(ClickEvent event) {
                            onModuleSelected(module);
                        }
                    });
                }
            });
        }
    }
    if (organizationalUnits != null && organizationalUnits.isEmpty()) {
        this.organizationUnits.setText(ProjectExplorerConstants.INSTANCE.nullEntry());
        this.organizationUnits.add(new AnchorListItem(ProjectExplorerConstants.INSTANCE.nullEntry()));
        this.repos.setText(ProjectExplorerConstants.INSTANCE.nullEntry());
        this.repos.add(new AnchorListItem(ProjectExplorerConstants.INSTANCE.nullEntry()));
        this.modules.setText(ProjectExplorerConstants.INSTANCE.nullEntry());
        this.modules.add(new AnchorListItem(ProjectExplorerConstants.INSTANCE.nullEntry()));
    } else if (repositories != null && repositories.isEmpty()) {
        this.repos.setText(ProjectExplorerConstants.INSTANCE.nullEntry());
        this.repos.add(new AnchorListItem(ProjectExplorerConstants.INSTANCE.nullEntry()));
        this.modules.setText(ProjectExplorerConstants.INSTANCE.nullEntry());
        this.modules.add(new AnchorListItem(ProjectExplorerConstants.INSTANCE.nullEntry()));
    } else if (modules != null && modules.isEmpty()) {
        this.modules.setText(ProjectExplorerConstants.INSTANCE.nullEntry());
        this.modules.add(new AnchorListItem(ProjectExplorerConstants.INSTANCE.nullEntry()));
    }
    if (!isAlreadyInitialized) {
        container.clear();
        setupNavigatorBreadcrumbs();
        addDivToAlignComponents();
        isAlreadyInitialized = true;
    }
}
Also used : AnchorListItem(org.gwtbootstrap3.client.ui.AnchorListItem) Repository(org.guvnor.structure.repositories.Repository) OrganizationalUnit(org.guvnor.structure.organizationalunit.OrganizationalUnit) ClickHandler(com.google.gwt.event.dom.client.ClickHandler) ClickEvent(com.google.gwt.event.dom.client.ClickEvent) Module(org.guvnor.common.services.project.model.Module)

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