use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.
the class ExplorerServiceImpl method getContent.
@Override
public ProjectExplorerContent getContent(final String _path, final ActiveOptions activeOptions) {
checkNotEmpty("path", _path);
final Path path = Paths.convert(ioService.get(URI.create(_path.trim())));
final Module module = moduleService.resolveModule(path);
final Path convertedPath = Paths.convert(Paths.convert(path).getRoot());
final Repository repo = repositoryService.getRepository(convertedPath);
final Branch branch = getBranch(repo, convertedPath);
return getContent(new ProjectExplorerContentQuery(repo, branch, module, activeOptions));
}
use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.
the class ProjectExplorerContentResolver method setupSelectedItems.
protected Content setupSelectedItems(ProjectExplorerContentQuery query) {
final Content content = new Content(query, getProject(query));
final UserExplorerLastData lastContent = helper.getLastContent();
final UserExplorerData userContent = helper.loadUserContent();
if (!lastContent.isDataEmpty()) {
if (query.getRepository() == null && query.getModule() == null) {
// If nothing has been selected (i.e. on start-up) set-up Content from last saved state
if (query.getOptions().contains(Option.BUSINESS_CONTENT) && lastContent.getLastPackage() != null) {
Repository lastRepo = lastContent.getLastPackage().getRepository();
content.setSelectedProject(projectService.resolveProject(lastRepo.getSpace(), lastRepo.getBranch(lastContent.getLastPackage().getBranch()).get()));
content.setSelectedModule(lastContent.getLastPackage().getModule());
content.setSelectedPackage(lastContent.getLastPackage().getPkg());
content.setSelectedItem(null);
} else if (query.getOptions().contains(Option.TECHNICAL_CONTENT) && lastContent.getLastFolderItem() != null) {
content.setSelectedProject(projectService.resolveProject(lastContent.getLastFolderItem().getRepository().getSpace(), lastContent.getLastFolderItem().getRepository().getBranch(lastContent.getLastFolderItem().getBranch()).get()));
content.setSelectedModule(lastContent.getLastFolderItem().getModule());
content.setSelectedItem(lastContent.getLastFolderItem().getItem());
content.setSelectedPackage(null);
}
} else if (query.getOptions().contains(Option.BUSINESS_CONTENT) && lastContent.getLastPackage() != null) {
if (query.getRepository() != null && !query.getRepository().equals(lastContent.getLastPackage().getRepository()) || query.getBranch() != null && !query.getBranch().getName().equals(lastContent.getLastPackage().getBranch()) || query.getModule() != null && !query.getModule().equals(lastContent.getLastPackage().getModule())) {
// Handle a change in selected Repository or Module in BUSINESS_CONTENT view
content.setSelectedProject(loadProject(query.getRepository().getSpace(), query.getRepository().getBranch(query.getBranch().getName()).get()));
content.setSelectedModule(loadModule(content.getSelectedProject(), query.getModule()));
content.setSelectedPackage(loadPackage(content.getSelectedProject(), content.getSelectedModule(), query.getPkg(), userContent));
content.setSelectedItem(null);
} else {
// Fall back to the last saved state
content.setSelectedProject(loadProject(lastContent.getLastPackage().getRepository().getSpace(), lastContent.getLastPackage().getRepository().getBranch(lastContent.getLastPackage().getBranch()).get()));
content.setSelectedModule(loadModule(content.getSelectedProject(), lastContent.getLastPackage().getModule()));
content.setSelectedPackage(loadPackage(content.getSelectedProject(), content.getSelectedModule(), lastContent.getLastPackage().getPkg(), userContent));
content.setSelectedItem(null);
}
} else if (query.getOptions().contains(Option.TECHNICAL_CONTENT) && lastContent.getLastFolderItem() != null) {
if (lastContent.getOptions().contains(Option.BUSINESS_CONTENT)) {
// When switching from BUSINESS_VIEW we cannot use LastFolderItem().getItem() and must use Module root; set by FolderListingResolver.getFolderListing()
content.setSelectedProject(loadProject(lastContent.getLastPackage().getRepository().getSpace(), lastContent.getLastFolderItem().getRepository().getBranch(lastContent.getLastPackage().getBranch()).get()));
content.setSelectedModule(loadModule(content.getSelectedProject(), lastContent.getLastFolderItem().getModule()));
content.setSelectedItem(null);
content.setSelectedPackage(null);
} else if (query.getRepository() != null && !query.getRepository().equals(lastContent.getLastFolderItem().getRepository()) || query.getModule() != null && !query.getModule().equals(lastContent.getLastFolderItem().getModule())) {
// Handle a change in selected OU, Repository or Module in TECHNICAL_CONTENT view
content.setSelectedProject(loadProject(query.getRepository().getSpace(), query.getRepository().getBranch(query.getBranch().getName()).get()));
content.setSelectedModule(loadModule(content.getSelectedProject(), query.getModule()));
content.setSelectedItem(null);
content.setSelectedPackage(null);
} else {
// Fall back to the last saved state
content.setSelectedProject(loadProject(query.getRepository().getSpace(), lastContent.getLastFolderItem().getRepository().getBranch(lastContent.getLastFolderItem().getBranch()).get()));
content.setSelectedModule(loadModule(content.getSelectedProject(), lastContent.getLastFolderItem().getModule()));
content.setSelectedItem(loadFolderItem(content.getSelectedProject(), content.getSelectedModule(), lastContent.getLastFolderItem().getItem(), userContent));
content.setSelectedPackage(null);
}
}
}
return content;
}
use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.
the class ExamplesServiceImpl method cloneRepository.
private Repository cloneRepository(final String repositoryURL, final String userName, final String password) {
Repository repository = null;
try {
final String alias = getExampleAlias(repositoryURL);
final Map<String, Object> env = new HashMap<String, Object>() {
{
put("origin", repositoryURL);
put(SCHEME, GitRepository.SCHEME.toString());
put("replaceIfExists", true);
put("username", userName);
put("password", password);
put(MIRROR, false);
}
};
final ConfigGroup repositoryConfig = configurationFactory.newConfigGroup(REPOSITORY, "system", alias, "");
for (final Map.Entry<String, Object> entry : env.entrySet()) {
repositoryConfig.addConfigItem(configurationFactory.newConfigItem(entry.getKey(), entry.getValue()));
}
repositoryConfig.addConfigItem(configurationFactory.newConfigItem(EnvironmentParameters.AVOID_INDEX, "true"));
repositoryConfig.addConfigItem(configurationFactory.newConfigItem(EnvironmentParameters.SPACE, "system"));
repository = repositoryFactory.newRepository(repositoryConfig);
clonedRepositories.add(repository);
return repository;
} catch (final Exception e) {
logger.error("Error during create repository", e);
throw new RuntimeException(e);
}
}
use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.
the class ExamplesServiceImplTest method resolveGitRepositoryClonedBefore.
@Test
public void resolveGitRepositoryClonedBefore() {
ExampleRepository playgroundRepository = new ExampleRepository("file:///home/user/folder/.kie-wb-playground");
service.setPlaygroundRepository(playgroundRepository);
GitRepository repository = mock(GitRepository.class);
Map<String, Object> repositoryEnvironment = new HashMap<>();
repositoryEnvironment.put("origin", playgroundRepository.getUrl());
when(repository.getEnvironment()).thenReturn(repositoryEnvironment);
service.getClonedRepositories().add(repository);
Repository result = service.resolveGitRepository(playgroundRepository);
assertEquals(repository, result);
verify(repositoryFactory, never()).newRepository(any(ConfigGroup.class));
}
use of org.guvnor.structure.repositories.Repository in project kie-wb-common by kiegroup.
the class DefExplorerQueryServiceImpl method resolveRepositories.
/**
* Given an organizational unit, resolves the repositories accessible by current user in the given OU.
*/
private Map<String, Repository> resolveRepositories(final OrganizationalUnit organizationalUnit) {
final Map<String, Repository> authorizedRepositories = new HashMap<>();
if (organizationalUnit == null) {
return authorizedRepositories;
}
// Reload OrganizationalUnit as the organizational unit's repository list might have been changed server-side
final Collection<Repository> repositories = organizationalUnitService.getOrganizationalUnit(organizationalUnit.getName()).getRepositories();
for (Repository repository : repositories) {
if (authorizationManager.authorize(repository, identity)) {
authorizedRepositories.put(repository.getAlias(), repository);
}
}
return authorizedRepositories;
}
Aggregations