public void updateChoices(boolean reportError, Form<?> form) { final String repoUriStr = repositoryUriModel.getObject(); if (REPOSITORY.sample != null && REPOSITORY.sample.equals(repoUriStr)) { return; } List<String> branchNames = new ArrayList<>(); if (repoUriStr != null) { try { RepositoryManager manager = this.manager.get(); URI repoURI = new URI(repoUriStr); RepositoryResolver resolver = RepositoryResolver.lookup(repoURI); String repoName = resolver.getName(repoURI); RepositoryInfo repoInfo = manager.getByRepoName(repoName); String repoId = repoInfo.getId(); List<Ref> branchRefs = manager.listBranches(repoId); for (Ref branch : branchRefs) { branchNames.add(branch.localName()); } } catch (IOException | URISyntaxException e) { if (reportError) { form.error("Could not list branches: " + e.getMessage()); } branchNames = new ArrayList<String>(); } String current = (String) choice.getModelObject(); if (current != null && !branchNames.contains(current)) { branchNames.add(0, current); } } choice.setChoices(branchNames); }
/** * Create a repository with the given name for testing. * * @param name the repository name * @return a newly created {@link TestData} for the repository. * @throws Exception */ @Override protected TestData createRepo(String name) throws Exception { GeoGigTestData testData = new GeoGigTestData(); testData.setUp(name); testData.init(); GeoGIG geogig = testData.getGeogig(); Catalog catalog = helper.getCatalog(); CatalogBuilder catalogBuilder = testData.newCatalogBuilder(catalog); int i = rnd.nextInt(); catalogBuilder.namespace("geogig.org/" + i).workspace("geogigws" + i).store("geogigstore" + i); catalogBuilder.addAllRepoLayers().build(); String workspaceName = catalogBuilder.workspaceName(); String storeName = catalogBuilder.storeName(); DataStoreInfo dsInfo = catalog.getDataStoreByName(workspaceName, storeName); assertNotNull(dsInfo); assertEquals(GeoGigDataStoreFactory.DISPLAY_NAME, dsInfo.getType()); DataAccess<? extends FeatureType, ? extends Feature> dataStore = dsInfo.getDataStore(null); assertNotNull(dataStore); assertTrue(dataStore instanceof GeoGigDataStore); String repoId = (String) dsInfo.getConnectionParameters().get(GeoGigDataStoreFactory.REPOSITORY.key); RepositoryInfo repositoryInfo = RepositoryManager.get().get(repoId); assertNotNull(repositoryInfo); return new TestData(geogig); }
/** Clean up resources used in the scenario. */ @Override protected void tearDown() throws Exception { try { if (helper != null) { RepositoryManager.close(); helper.doTearDown(); } } finally { helper = null; } }
/** Set up the context for a scenario. */ @Override protected void setUp() throws Exception { if (helper == null) { helper = new TestHelper(); helper.doSetup(); repoProvider = new GeoServerRepositoryProvider(); RepositoryManager.get().setCatalog(helper.getCatalog()); } }
@Override public RepositoryManager get() { return RepositoryManager.get(); }
public class BranchSelectionPanel extends FormComponentPanel<String> { private static final long serialVersionUID = 1L; private final DropDownChoice<String> choice; private final IModel<String> repositoryUriModel; private Supplier<RepositoryManager> manager = RepositoryManager.supplier(); public BranchSelectionPanel( String id, IModel<String> repositoryUriModel, IModel<String> branchNameModel, Form<DataStoreInfo> storeEditForm) { super(id, branchNameModel); this.repositoryUriModel = repositoryUriModel; final List<String> choices = new ArrayList<String>(); choice = new DropDownChoice<String>("branchDropDown", branchNameModel, choices); choice.setOutputMarkupId(true); choice.setNullValid(true); choice.setRequired(false); add(choice); updateChoices(false, null); final AjaxSubmitLink refreshLink = new AjaxSubmitLink("refresh", storeEditForm) { private static final long serialVersionUID = 1L; @Override protected void onError(AjaxRequestTarget target, Form<?> form) { onSubmit(target, form); } @Override protected void onSubmit(AjaxRequestTarget target, Form<?> form) { updateChoices(true, form); target.add(BranchSelectionPanel.this.choice); } }; add(refreshLink); } @Override public void convertInput() { choice.processInput(); String branch = choice.getConvertedInput(); setModelObject(branch); setConvertedInput(branch); } @VisibleForTesting void setRepositoryManager(Supplier<RepositoryManager> supplier) { this.manager = supplier; } public void updateChoices(boolean reportError, Form<?> form) { final String repoUriStr = repositoryUriModel.getObject(); if (REPOSITORY.sample != null && REPOSITORY.sample.equals(repoUriStr)) { return; } List<String> branchNames = new ArrayList<>(); if (repoUriStr != null) { try { RepositoryManager manager = this.manager.get(); URI repoURI = new URI(repoUriStr); RepositoryResolver resolver = RepositoryResolver.lookup(repoURI); String repoName = resolver.getName(repoURI); RepositoryInfo repoInfo = manager.getByRepoName(repoName); String repoId = repoInfo.getId(); List<Ref> branchRefs = manager.listBranches(repoId); for (Ref branch : branchRefs) { branchNames.add(branch.localName()); } } catch (IOException | URISyntaxException e) { if (reportError) { form.error("Could not list branches: " + e.getMessage()); } branchNames = new ArrayList<String>(); } String current = (String) choice.getModelObject(); if (current != null && !branchNames.contains(current)) { branchNames.add(0, current); } } choice.setChoices(branchNames); } }