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