From 1e6cf7254fb9f150251594cf0383b3b1c5210517 Mon Sep 17 00:00:00 2001 From: Bruno Sinou Date: Fri, 21 Mar 2014 15:42:13 +0000 Subject: [PATCH] + clean repo model + enhance remote session management + fix a few bugs git-svn-id: https://svn.argeo.org/slc/trunk@6907 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc --- .../META-INF/spring/commands.xml | 12 ++- .../META-INF/spring/editors.xml | 9 +- .../META-INF/spring/jcr.xml | 6 ++ .../org.argeo.slc.client.ui.dist/plugin.xml | 18 +++- .../slc/client/ui/dist/DistConstants.java | 3 + .../argeo/slc/client/ui/dist/RepoService.java | 14 +++ .../slc/client/ui/dist/RepoServiceImpl.java | 36 +++++++ .../dist/commands/DisplayRepoInformation.java | 56 +++++------ .../dist/commands/MarkAsRelevantCategory.java | 97 ++++++++---------- .../commands/OpenGenerateBinariesWizard.java | 77 +++++---------- .../ui/dist/commands/OpenModuleEditor.java | 62 +++--------- .../DistTreeDoubleClickListener.java | 54 ++++------ .../controllers/DistTreeLabelProvider.java | 4 +- .../dist/editors/ArtifactVersionEditor.java | 61 +++++------- .../ui/dist/editors/DistWorkspaceEditor.java | 2 +- .../editors/ModularDistVersionEditor.java | 25 ++++- .../ModularDistVersionOverviewPage.java | 4 +- .../ui/dist/editors/ModuleEditorInput.java | 18 ++-- .../editors/WkspCategoryBaseListPage.java | 99 +++++++++++-------- ...m.java => ModularDistVersionBaseElem.java} | 49 ++++----- .../ui/dist/model/ModularDistVersionElem.java | 2 +- .../slc/client/ui/dist/model/RepoElem.java | 20 +++- .../client/ui/dist/model/WorkspaceElem.java | 42 ++++---- .../ui/dist/views/DistributionsView.java | 86 +++++++++------- .../dist/wizards/GenerateBinariesWizard.java | 40 ++++---- .../java/org/argeo/slc/repo/RepoUtils.java | 36 ++++++- .../resources/org/argeo/slc/repo/repo.cnd | 7 +- .../main/java/org/argeo/slc/jcr/SlcNames.java | 1 - .../main/java/org/argeo/slc/jcr/SlcTypes.java | 2 +- 29 files changed, 494 insertions(+), 448 deletions(-) create mode 100644 plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/RepoService.java create mode 100644 plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/RepoServiceImpl.java rename plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/{ModularDistBaseElem.java => ModularDistVersionBaseElem.java} (73%) diff --git a/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/commands.xml b/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/commands.xml index c8ec38b37..bdf126d82 100644 --- a/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/commands.xml +++ b/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/commands.xml @@ -14,9 +14,7 @@ - - - + @@ -36,8 +34,8 @@ - - + + @@ -73,6 +71,10 @@ + + + diff --git a/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/editors.xml b/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/editors.xml index 3dd0cbae0..e36f591cb 100644 --- a/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/editors.xml +++ b/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/editors.xml @@ -21,15 +21,12 @@ - - - + + - - - + diff --git a/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/jcr.xml b/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/jcr.xml index 1d2cd11c4..e6b5e60dd 100644 --- a/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/jcr.xml +++ b/plugins/org.argeo.slc.client.ui.dist/META-INF/spring/jcr.xml @@ -10,6 +10,12 @@ + + + + + + diff --git a/plugins/org.argeo.slc.client.ui.dist/plugin.xml b/plugins/org.argeo.slc.client.ui.dist/plugin.xml index 530833b99..976379576 100644 --- a/plugins/org.argeo.slc.client.ui.dist/plugin.xml +++ b/plugins/org.argeo.slc.client.ui.dist/plugin.xml @@ -193,16 +193,28 @@ - - + --> + + + + + + it = ((IStructuredSelection) selector) - .iterator(); - - Node node = (Node) it.next(); - if (node.isNodeType(SlcTypes.SLC_CATEGORY)) { - String msg = "Your are about to unlist this category from the relevant category list for current workspace" - + ".\n" + "Are you sure you want to proceed?"; - if (MessageDialog.openConfirm(DistPlugin.getDefault() - .getWorkbench().getDisplay().getActiveShell(), - "Confirm", msg)) { - node.removeMixin(SlcTypes.SLC_CATEGORY); - node.getSession().save(); - } - } else { - String msg = "Your are about to mark this group as category base in the current workspace" - + ".\n" + "Are you sure you want to proceed?"; - - if (MessageDialog.openConfirm(DistPlugin.getDefault() - .getWorkbench().getDisplay().getActiveShell(), - "Confirm", msg)) { - node.addMixin(SlcTypes.SLC_CATEGORY); - node.getSession().save(); - } - } - } - } - } catch (RepositoryException re) { - throw new ArgeoException( - "Unexpected error while deleting artifacts.", re); - } + // try { + // IWorkbenchPart activePart = DistPlugin.getDefault().getWorkbench() + // .getActiveWorkbenchWindow().getActivePage().getActivePart(); + // + // if (activePart instanceof IEditorPart) { + // ISelection selector = ((IEditorPart) activePart) + // .getEditorSite().getSelectionProvider().getSelection(); + // if (selector != null + // && selector instanceof IStructuredSelection) { + // Iterator it = ((IStructuredSelection) selector) + // .iterator(); + // + // Node node = (Node) it.next(); + // if (node.isNodeType(SlcTypes.SLC_CATEGORY)) { + // String msg = + // "Your are about to unlist this category from the relevant category list for current workspace" + // + ".\n" + "Are you sure you want to proceed?"; + // if (MessageDialog.openConfirm(DistPlugin.getDefault() + // .getWorkbench().getDisplay().getActiveShell(), + // "Confirm", msg)) { + // node.removeMixin(SlcTypes.SLC_CATEGORY); + // node.getSession().save(); + // } + // } else { + // String msg = + // "Your are about to mark this group as category base in the current workspace" + // + ".\n" + "Are you sure you want to proceed?"; + // + // if (MessageDialog.openConfirm(DistPlugin.getDefault() + // .getWorkbench().getDisplay().getActiveShell(), + // "Confirm", msg)) { + // node.addMixin(SlcTypes.SLC_CATEGORY); + // node.getSession().save(); + // } + // } + // } + // } + // } catch (RepositoryException re) { + // throw new ArgeoException( + // "Unexpected error while deleting artifacts.", re); + // } return null; } } \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/OpenGenerateBinariesWizard.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/OpenGenerateBinariesWizard.java index 1c2ad68c3..84ee759d7 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/OpenGenerateBinariesWizard.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/OpenGenerateBinariesWizard.java @@ -15,17 +15,8 @@ */ package org.argeo.slc.client.ui.dist.commands; -import java.util.Iterator; - -import javax.jcr.Credentials; -import javax.jcr.Node; -import javax.jcr.Repository; -import javax.jcr.RepositoryException; - -import org.argeo.slc.SlcException; import org.argeo.slc.client.ui.dist.DistPlugin; -import org.argeo.slc.client.ui.dist.model.ModularDistBaseElem; -import org.argeo.slc.client.ui.dist.model.WorkspaceElem; +import org.argeo.slc.client.ui.dist.RepoService; import org.argeo.slc.client.ui.dist.utils.CommandHelpers; import org.argeo.slc.client.ui.dist.wizards.GenerateBinariesWizard; import org.eclipse.core.commands.AbstractHandler; @@ -33,10 +24,7 @@ import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.ui.IViewPart; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.handlers.HandlerUtil; @@ -51,53 +39,38 @@ public class OpenGenerateBinariesWizard extends AbstractHandler { public final static String DEFAULT_LABEL = "Generate Aether Index"; public final static ImageDescriptor DEFAULT_ICON = null; + /* DEPENDENCY INJECTION */ + private RepoService repoService; + + // Absolute Coordinates of the current group node + public final static String PARAM_REPO_NODE_PATH = "param.repoNodePath"; + public final static String PARAM_WORKSPACE_NAME = "param.workspaceName"; + public final static String PARAM_MODULE_PATH = "param.modulePath"; + public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchPart activePart = DistPlugin.getDefault().getWorkbench() .getActiveWorkbenchWindow().getActivePage().getActivePart(); - if (activePart instanceof IViewPart) { - ISelection selector = ((IViewPart) activePart).getViewSite() - .getSelectionProvider().getSelection(); - if (selector != null && selector instanceof IStructuredSelection) { - Iterator it = ((IStructuredSelection) selector).iterator(); - Object element = it.next(); - if (element instanceof ModularDistBaseElem) { - ModularDistBaseElem elem = (ModularDistBaseElem) element; - // Session newSession = null; - try { - Node cBase = elem.getCategoryBase(); - String catBasePath = cBase.getPath(); - // newSession = ((WorkspaceElem) elem.getParent()) - // .getNewSession(); - - String wkspName = ((WorkspaceElem) elem.getParent()) - .getWorkspaceName(); - Repository repository = ((WorkspaceElem) elem - .getParent()).getRepoElem().getRepository(); - Credentials credentials = ((WorkspaceElem) elem - .getParent()).getRepoElem().getCredentials(); + String repoNodePath = event.getParameter(PARAM_REPO_NODE_PATH); + String workspaceName = event.getParameter(PARAM_WORKSPACE_NAME); + String modulePath = event.getParameter(PARAM_MODULE_PATH); - GenerateBinariesWizard wizard = new GenerateBinariesWizard( - repository, credentials, wkspName, catBasePath); + GenerateBinariesWizard wizard = new GenerateBinariesWizard(repoService, + repoNodePath, workspaceName, modulePath); - WizardDialog dialog = new WizardDialog( - HandlerUtil.getActiveShell(event), wizard); - int result = dialog.open(); + WizardDialog dialog = new WizardDialog( + HandlerUtil.getActiveShell(event), wizard); + int result = dialog.open(); - if (result == Dialog.OK) - CommandHelpers - .callCommand(RefreshDistributionsView.ID); - } catch (RepositoryException re) { - throw new SlcException( - "Unable to duplicate session for node " + elem, - re); - // } finally { - // JcrUtils.logoutQuietly(newSession); - } - } + if (result == Dialog.OK + && (activePart instanceof RefreshDistributionsView)) + CommandHelpers.callCommand(RefreshDistributionsView.ID); - } - } return null; } + + /* DEPENDENCY INJECTION */ + public void setRepoService(RepoService repoService) { + this.repoService = repoService; + } } \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/OpenModuleEditor.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/OpenModuleEditor.java index 85d047a95..9250b25e6 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/OpenModuleEditor.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/commands/OpenModuleEditor.java @@ -16,21 +16,17 @@ package org.argeo.slc.client.ui.dist.commands; import javax.jcr.Node; -import javax.jcr.Repository; import javax.jcr.RepositoryException; -import javax.jcr.RepositoryFactory; import javax.jcr.Session; -import org.argeo.jcr.ArgeoNames; import org.argeo.jcr.JcrUtils; import org.argeo.slc.SlcException; import org.argeo.slc.client.ui.dist.DistPlugin; +import org.argeo.slc.client.ui.dist.RepoService; import org.argeo.slc.client.ui.dist.editors.ArtifactVersionEditor; import org.argeo.slc.client.ui.dist.editors.ModularDistVersionEditor; import org.argeo.slc.client.ui.dist.editors.ModuleEditorInput; import org.argeo.slc.jcr.SlcTypes; -import org.argeo.slc.repo.RepoUtils; -import org.argeo.util.security.Keyring; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; @@ -56,11 +52,7 @@ public class OpenModuleEditor extends AbstractHandler { public final static String PARAM_MODULE_PATH = "param.modulePath"; /* DEPENDENCY INJECTION */ - private Repository localRepository; - // We must log in the corresponding repository to get the node and be able - // to decide which editor to open depending on its mixin - private RepositoryFactory repositoryFactory; - private Keyring keyring; + private RepoService repoService; public Object execute(ExecutionEvent event) throws ExecutionException { String repoNodePath = event.getParameter(PARAM_REPO_NODE_PATH); @@ -68,43 +60,22 @@ public class OpenModuleEditor extends AbstractHandler { String workspaceName = event.getParameter(PARAM_WORKSPACE_NAME); String modulePath = event.getParameter(PARAM_MODULE_PATH); - Session localSession = null; Session businessSession = null; - Node repoNode = null; - try { - try { - localSession = localRepository.login(); - if (repoNodePath != null - && localSession.nodeExists(repoNodePath)) - repoNode = localSession.getNode(repoNodePath); - - businessSession = RepoUtils.getCorrespondingSession( - repositoryFactory, keyring, repoNode, repoUri, - workspaceName); - if (repoUri == null && repoNode != null) - repoUri = repoNode.getProperty(ArgeoNames.ARGEO_URI) - .getString(); + businessSession = repoService.getRemoteSession(repoNodePath, + repoUri, workspaceName); - } catch (RepositoryException e) { - throw new SlcException("Cannot log to workspace " - + workspaceName + " for repo defined in " - + repoNodePath, e); - } finally { - JcrUtils.logoutQuietly(localSession); - } - - ModuleEditorInput wei = new ModuleEditorInput(repoNodePath, + Node module = businessSession.getNode(modulePath); + ModuleEditorInput mei = new ModuleEditorInput(repoNodePath, repoUri, workspaceName, modulePath); - Node artifact = businessSession.getNode(modulePath); - // Choose correct editor based on the artifact mixin - if (artifact.isNodeType(SlcTypes.SLC_MODULAR_DISTRIBUTION)) + // Choose correct editor based on its mixin + if (module.isNodeType(SlcTypes.SLC_MODULAR_DISTRIBUTION)) HandlerUtil.getActiveWorkbenchWindow(event).getActivePage() - .openEditor(wei, ModularDistVersionEditor.ID); + .openEditor(mei, ModularDistVersionEditor.ID); else HandlerUtil.getActiveWorkbenchWindow(event).getActivePage() - .openEditor(wei, ArtifactVersionEditor.ID); + .openEditor(mei, ArtifactVersionEditor.ID); } catch (RepositoryException e) { throw new SlcException("Unexpected error while " + "getting repoNode info for repoNode at path " @@ -121,16 +92,7 @@ public class OpenModuleEditor extends AbstractHandler { } /* DEPENDENCY INJECTION */ - public void setLocalRepository(Repository localRepository) { - this.localRepository = localRepository; - } - - public void setRepositoryFactory(RepositoryFactory repositoryFactory) { - this.repositoryFactory = repositoryFactory; - } - - public void setKeyring(Keyring keyring) { - this.keyring = keyring; + public void setRepoService(RepoService repoService) { + this.repoService = repoService; } - } \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/controllers/DistTreeDoubleClickListener.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/controllers/DistTreeDoubleClickListener.java index 5136a9128..c280a53e0 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/controllers/DistTreeDoubleClickListener.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/controllers/DistTreeDoubleClickListener.java @@ -40,56 +40,36 @@ public class DistTreeDoubleClickListener implements IDoubleClickListener { treeViewer.refresh(obj); } } else if (obj instanceof WorkspaceElem) { - //WorkspaceElem wn = (WorkspaceElem) obj; - // if (!wn.isConnected()) { - // wn.login(); - // treeViewer.refresh(obj); - // } else { WorkspaceElem we = (WorkspaceElem) obj; - Node repoNode = null; - try { - RepoElem repoElem = we.getRepoElem(); - Map params = new HashMap(); + RepoElem repoElem = we.getRepoElem(); + Map params = new HashMap(); + params.put(OpenWorkspaceEditor.PARAM_REPO_NODE_PATH, + repoElem.getRepoNodePath()); + params.put(OpenWorkspaceEditor.PARAM_REPO_URI, repoElem.getUri()); + params.put(OpenWorkspaceEditor.PARAM_WORKSPACE_NAME, + we.getWorkspaceName()); + CommandUtils.callCommand(OpenWorkspaceEditor.ID, params); - repoNode = repoElem.getRepoNode(); - if (repoNode != null) - params.put(OpenWorkspaceEditor.PARAM_REPO_NODE_PATH, - repoNode.getPath()); - params.put(OpenWorkspaceEditor.PARAM_REPO_URI, - repoElem.getUri()); - params.put(OpenWorkspaceEditor.PARAM_WORKSPACE_NAME, - we.getWorkspaceName()); - CommandUtils.callCommand(OpenWorkspaceEditor.ID, params); - } catch (RepositoryException re) { - throw new SlcException("Cannot get path for node " + repoNode - + " while " + "setting parameters of command " - + "OpenWorkspaceEditor", re); - } - // } } else if (obj instanceof ModularDistVersionElem) { ModularDistVersionElem modDistElem = (ModularDistVersionElem) obj; WorkspaceElem wkspElem = modDistElem.getWorkspaceElem(); - Node repoNode = null; Node moduleNode = modDistElem.getModularDistVersionNode(); + RepoElem repoElem = wkspElem.getRepoElem(); + Map params = new HashMap(); + params.put(OpenModuleEditor.PARAM_REPO_NODE_PATH, + repoElem.getRepoNodePath()); + params.put(OpenModuleEditor.PARAM_REPO_URI, repoElem.getUri()); + params.put(OpenModuleEditor.PARAM_WORKSPACE_NAME, + wkspElem.getWorkspaceName()); try { - RepoElem repoElem = wkspElem.getRepoElem(); - Map params = new HashMap(); - repoNode = repoElem.getRepoNode(); - if (repoNode != null) - params.put(OpenModuleEditor.PARAM_REPO_NODE_PATH, - repoNode.getPath()); - params.put(OpenModuleEditor.PARAM_REPO_URI, repoElem.getUri()); - params.put(OpenModuleEditor.PARAM_WORKSPACE_NAME, - wkspElem.getWorkspaceName()); params.put(OpenModuleEditor.PARAM_MODULE_PATH, moduleNode.getPath()); - CommandUtils.callCommand(OpenModuleEditor.ID, params); } catch (RepositoryException re) { - throw new SlcException("Cannot get path for node " + repoNode - + " or " + moduleNode + throw new SlcException("Cannot get path for node " + moduleNode + " while setting parameters for " + "command OpenModuleEditor", re); } + CommandUtils.callCommand(OpenModuleEditor.ID, params); } } } \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/controllers/DistTreeLabelProvider.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/controllers/DistTreeLabelProvider.java index 37bff6bd7..4ce4b77a9 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/controllers/DistTreeLabelProvider.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/controllers/DistTreeLabelProvider.java @@ -3,7 +3,7 @@ package org.argeo.slc.client.ui.dist.controllers; import org.argeo.eclipse.ui.jcr.JcrImages; import org.argeo.slc.client.ui.dist.DistImages; import org.argeo.slc.client.ui.dist.model.DistParentElem; -import org.argeo.slc.client.ui.dist.model.ModularDistBaseElem; +import org.argeo.slc.client.ui.dist.model.ModularDistVersionBaseElem; import org.argeo.slc.client.ui.dist.model.ModularDistVersionElem; import org.argeo.slc.client.ui.dist.model.RepoElem; import org.argeo.slc.client.ui.dist.model.WkspGroupElem; @@ -39,7 +39,7 @@ public class DistTreeLabelProvider extends ColumnLabelProvider { return DistImages.IMG_WKSP_GROUP; // else if (element instanceof GroupBaseElem) // return DistImages.IMG_GROUP_BASE; - else if (element instanceof ModularDistBaseElem) + else if (element instanceof ModularDistVersionBaseElem) return DistImages.IMG_MODULAR_DIST_BASE; else if (element instanceof ModularDistVersionElem) return DistImages.IMG_MODULAR_DIST_VERSION; diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ArtifactVersionEditor.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ArtifactVersionEditor.java index 549dc4046..ad9a33b75 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ArtifactVersionEditor.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ArtifactVersionEditor.java @@ -16,18 +16,15 @@ package org.argeo.slc.client.ui.dist.editors; import javax.jcr.Node; -import javax.jcr.Repository; import javax.jcr.RepositoryException; -import javax.jcr.RepositoryFactory; import javax.jcr.Session; import org.argeo.ArgeoException; import org.argeo.jcr.JcrUtils; import org.argeo.slc.SlcException; import org.argeo.slc.client.ui.dist.DistPlugin; +import org.argeo.slc.client.ui.dist.RepoService; import org.argeo.slc.jcr.SlcNames; -import org.argeo.slc.repo.RepoUtils; -import org.argeo.util.security.Keyring; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IEditorSite; @@ -42,49 +39,41 @@ public class ArtifactVersionEditor extends FormEditor implements SlcNames { // LogFactory.getLog(ArtifactEditor.class); public final static String ID = DistPlugin.ID + ".artifactVersionEditor"; - private ModuleEditorInput editorInput; - /* DEPENDENCY INJECTION */ - private RepositoryFactory repositoryFactory; - private Repository localRepository; - private Keyring keyring; - - // Business objects - private Node repoNode; - // Session that provides the node in the home of the local repository - private Session localSession = null; - // The business Session on an optionally remote repository + private RepoService repoService; + + // Business Objects private Session businessSession; private Node artifact; + private ModuleEditorInput editorInput; + @Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { editorInput = (ModuleEditorInput) input; + businessSession = repoService.getRemoteSession( + editorInput.getRepoNodePath(), editorInput.getUri(), + editorInput.getWorkspaceName()); try { - localSession = localRepository.login(); - if (editorInput.getRepoNodePath() != null - && localSession.nodeExists(editorInput.getRepoNodePath())) - repoNode = localSession.getNode(editorInput.getRepoNodePath()); - businessSession = RepoUtils.getCorrespondingSession( - repositoryFactory, keyring, repoNode, editorInput.getUri(), - editorInput.getWorkspaceName()); artifact = businessSession.getNode(editorInput.getModulePath()); } catch (RepositoryException e) { throw new PartInitException( "Unable to initialise editor for artifact " + editorInput.getModulePath() + " in workspace " - + editorInput.getWorkspaceName() - + " of repository " + editorInput.getUri(), e); + + editorInput.getWorkspaceName(), e); } - setPartName(getFormattedName()); super.init(site, input); } /** Override to provide a specific part name */ protected String getFormattedName() { try { - String partName = artifact.getProperty(SLC_ARTIFACT_ID).getString(); + String partName = null; + if (artifact.hasProperty(SLC_ARTIFACT_ID)) + partName = artifact.getProperty(SLC_ARTIFACT_ID).getString(); + else + partName = artifact.getName(); if (partName.length() > 10) { partName = "..." + partName.substring(partName.length() - 10); @@ -99,12 +88,15 @@ public class ArtifactVersionEditor extends FormEditor implements SlcNames { @Override protected void addPages() { + setPartName(getFormattedName()); + try { addPage(new BundleDetailsPage(this, "Details ", artifact)); addPage(new BundleRawPage(this, "Raw Meta-Data ", artifact)); } catch (PartInitException e) { throw new ArgeoException("Cannot add distribution editor pages", e); } + } @Override @@ -114,7 +106,6 @@ public class ArtifactVersionEditor extends FormEditor implements SlcNames { @Override public void dispose() { JcrUtils.logoutQuietly(businessSession); - JcrUtils.logoutQuietly(localSession); super.dispose(); } @@ -127,8 +118,8 @@ public class ArtifactVersionEditor extends FormEditor implements SlcNames { return false; } - protected Node getRepoNode() { - return repoNode; + protected RepoService getRepoService() { + return repoService; } protected Node getArtifact() { @@ -136,15 +127,7 @@ public class ArtifactVersionEditor extends FormEditor implements SlcNames { } /* DEPENDENCY INJECTION */ - public void setRepositoryFactory(RepositoryFactory repositoryFactory) { - this.repositoryFactory = repositoryFactory; - } - - public void setKeyring(Keyring keyring) { - this.keyring = keyring; - } - - public void setLocalRepository(Repository localRepository) { - this.localRepository = localRepository; + public void setRepoService(RepoService repoService) { + this.repoService = repoService; } } \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/DistWorkspaceEditor.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/DistWorkspaceEditor.java index 0d3220aaf..0a34a62da 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/DistWorkspaceEditor.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/DistWorkspaceEditor.java @@ -64,7 +64,7 @@ public class DistWorkspaceEditor extends FormEditor implements SlcNames { && localSession.nodeExists(editorInput.getRepoNodePath())) repoNode = localSession.getNode(editorInput.getRepoNodePath()); - businessSession = RepoUtils.getCorrespondingSession( + businessSession = RepoUtils.getRemoteSession( repositoryFactory, keyring, repoNode, editorInput.getUri(), editorInput.getWorkspaceName()); } catch (RepositoryException e) { diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ModularDistVersionEditor.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ModularDistVersionEditor.java index f80c5e928..284347bc3 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ModularDistVersionEditor.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ModularDistVersionEditor.java @@ -15,6 +15,8 @@ */ package org.argeo.slc.client.ui.dist.editors; +import javax.jcr.RepositoryException; + import org.argeo.slc.SlcException; import org.argeo.slc.client.ui.dist.DistPlugin; import org.eclipse.ui.IEditorInput; @@ -34,13 +36,13 @@ public class ModularDistVersionEditor extends ArtifactVersionEditor { public void init(IEditorSite site, IEditorInput input) throws PartInitException { super.init(site, input); - // setPartName("Editing distrib"); } @Override protected void addPages() { try { - addPage(new ModularDistVersionOverviewPage(this, "Modules ", getArtifact())); + addPage(new ModularDistVersionOverviewPage(this, "Modules ", + getArtifact())); addPage(new RunInOsgiPage(this, "Run as OSGi ", getArtifact())); super.addPages(); } catch (PartInitException e) { @@ -49,4 +51,23 @@ public class ModularDistVersionEditor extends ArtifactVersionEditor { // throw new SlcException("Cannot get artifact session", e); } } + + protected String getFormattedName() { + try { + String partName = null; + if (getArtifact().hasProperty(SLC_NAME)) + partName = getArtifact().getProperty(SLC_NAME).getString(); + else + partName = getArtifact().getName(); + + if (partName.length() > 10) { + partName = "..." + partName.substring(partName.length() - 10); + } + return partName; + } catch (RepositoryException re) { + throw new SlcException("unable to get slc:name property for node " + + getArtifact(), re); + } + } + } \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ModularDistVersionOverviewPage.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ModularDistVersionOverviewPage.java index 38b3a8b46..fb8229672 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ModularDistVersionOverviewPage.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ModularDistVersionOverviewPage.java @@ -130,8 +130,8 @@ public class ModularDistVersionOverviewPage extends FormPage implements .getProperty(SlcNames.SLC_NAME).getString() : ""); form.setMessage( modularDistribution - .hasProperty(SlcNames.SLC_BUNDLE_DESCRIPTION) ? modularDistribution - .getProperty(SlcNames.SLC_BUNDLE_DESCRIPTION) + .hasProperty(DistConstants.SLC_BUNDLE_DESCRIPTION) ? modularDistribution + .getProperty(DistConstants.SLC_BUNDLE_DESCRIPTION) .getString() : "", IMessageProvider.NONE); } catch (RepositoryException re) { throw new SlcException("Unable to get bundle name for node " diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ModuleEditorInput.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ModuleEditorInput.java index bc15959dc..8c297259e 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ModuleEditorInput.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/ModuleEditorInput.java @@ -37,8 +37,9 @@ public class ModuleEditorInput implements IEditorInput, SlcNames { String workspaceName, String artifactPath) { if (workspaceName == null) throw new SlcException("Workspace name cannot be null"); - if (uri == null) - throw new SlcException("URI for repository cannot be null"); + if (uri == null && repoNodePath == null) + throw new SlcException("Define at least one of the 2 " + + "parameters URI or Repo Node Path"); if (artifactPath == null) throw new SlcException("Module path cannot be null"); this.repoNodePath = repoNodePath; @@ -105,12 +106,15 @@ public class ModuleEditorInput implements IEditorInput, SlcNames { return false; if (!workspaceName.equals(other.getWorkspaceName())) return false; - if (!uri.equals(other.getUri())) + + if (uri == null && other.getUri() != null + || !uri.equals(other.getUri())) + return false; + + if (repoNodePath == null && other.getRepoNodePath() != null + || !repoNodePath.equals(other.getRepoNodePath())) return false; - if (repoNodePath == null) - return other.getRepoNodePath() == null; - else - return repoNodePath.equals(other.getRepoNodePath()); + return true; } } \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/WkspCategoryBaseListPage.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/WkspCategoryBaseListPage.java index c8b87c0a4..c82312e8b 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/WkspCategoryBaseListPage.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/editors/WkspCategoryBaseListPage.java @@ -16,7 +16,9 @@ package org.argeo.slc.client.ui.dist.editors; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.jcr.Node; import javax.jcr.NodeIterator; @@ -24,7 +26,6 @@ import javax.jcr.PropertyType; import javax.jcr.RepositoryException; import javax.jcr.Session; import javax.jcr.observation.Event; -import javax.jcr.observation.ObservationManager; import javax.jcr.query.QueryManager; import javax.jcr.query.QueryResult; import javax.jcr.query.qom.Constraint; @@ -42,10 +43,11 @@ import org.argeo.slc.SlcException; import org.argeo.slc.client.ui.dist.DistConstants; import org.argeo.slc.client.ui.dist.DistImages; import org.argeo.slc.client.ui.dist.DistPlugin; -import org.argeo.slc.client.ui.dist.commands.MarkAsRelevantCategory; +import org.argeo.slc.client.ui.dist.commands.OpenGenerateBinariesWizard; import org.argeo.slc.client.ui.dist.utils.NodeViewerComparator; import org.argeo.slc.jcr.SlcNames; import org.argeo.slc.jcr.SlcTypes; +import org.argeo.slc.repo.RepoConstants; import org.eclipse.jface.action.IMenuListener; import org.eclipse.jface.action.IMenuManager; import org.eclipse.jface.action.MenuManager; @@ -100,8 +102,9 @@ public class WkspCategoryBaseListPage extends FormPage implements SlcNames { private final static String FILTER_HELP_MSG = "Enter filter criterion separated by a space"; // Observes changes - private final static String[] observedTypes = { SlcTypes.SLC_GROUP_BASE }; - private CategoryObserver categoriesObserver; + // private final static String[] observedTypes = { SlcTypes.SLC_GROUP_BASE + // }; + // private CategoryObserver categoriesObserver; public WkspCategoryBaseListPage(FormEditor formEditor, String title, Session session) { @@ -135,18 +138,18 @@ public class WkspCategoryBaseListPage extends FormPage implements SlcNames { tableCmp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); createTableViewer(tableCmp); - categoriesObserver = new CategoryObserver(viewer.getTable() - .getDisplay()); - try { - ObservationManager observationManager = session.getWorkspace() - .getObservationManager(); - // FIXME Will not be notified if empty result is deleted - observationManager.addEventListener(categoriesObserver, - Event.PROPERTY_CHANGED, "/", true, null, observedTypes, - false); - } catch (RepositoryException e) { - throw new SlcException("Cannot register listeners", e); - } + // categoriesObserver = new CategoryObserver(viewer.getTable() + // .getDisplay()); + // try { + // ObservationManager observationManager = session.getWorkspace() + // .getObservationManager(); + // // FIXME Will not be notified if empty result is deleted + // observationManager.addEventListener(categoriesObserver, + // Event.PROPERTY_CHANGED, "/", true, null, observedTypes, + // false); + // } catch (RepositoryException e) { + // throw new SlcException("Cannot register listeners", e); + // } refresh(); } @@ -281,13 +284,14 @@ public class WkspCategoryBaseListPage extends FormPage implements SlcNames { // Version col = new TableViewerColumn(viewer, SWT.NONE); col.getColumn().setWidth(80); - col.getColumn().setText("Relevant"); + col.getColumn().setText("Has binaries"); col.setLabelProvider(new ColumnLabelProvider() { @Override public String getText(Object element) { try { - return ((Node) element) - .isNodeType(SlcTypes.SLC_CATEGORY) ? "Yes" + Node currNode = (Node) element; + + return currNode.hasNode(RepoConstants.BINARIES_ARTIFACT_ID) ? "Yes" : "No"; } catch (RepositoryException e) { throw new SlcException("unable to check type of node " @@ -341,29 +345,46 @@ public class WkspCategoryBaseListPage extends FormPage implements SlcNames { .getFirstElement(); Node currSelected = (Node) firstElement; - boolean isRelevant = false; - try { - isRelevant = currSelected - .isNodeType(SlcTypes.SLC_CATEGORY); - boolean canEdit = currSelected - .canAddMixin(SlcTypes.SLC_CATEGORY); + DistWkspEditorInput input = (DistWkspEditorInput) getEditorInput(); + Map params = new HashMap(); + params.put(OpenGenerateBinariesWizard.PARAM_REPO_NODE_PATH, + input.getRepoNodePath()); + try { + params.put(OpenGenerateBinariesWizard.PARAM_MODULE_PATH, + currSelected.getPath()); } catch (RepositoryException e) { - throw new SlcException("unable to check type of node " - + firstElement, e); - } - // Add - if (isRelevant) {// Remove - CommandUtils.refreshCommand(menuManager, window, - MarkAsRelevantCategory.ID, - MarkAsRelevantCategory.DEFAULT_REMOVE_LABEL, - MarkAsRelevantCategory.DEFAULT_REMOVE_ICON, true); - } else { - CommandUtils.refreshCommand(menuManager, window, - MarkAsRelevantCategory.ID, - MarkAsRelevantCategory.DEFAULT_LABEL, - MarkAsRelevantCategory.DEFAULT_ICON, true); + throw new SlcException("Unable to get path for " + currSelected, e); } + params.put(OpenGenerateBinariesWizard.PARAM_WORKSPACE_NAME, + input.getWorkspaceName()); + + CommandUtils.refreshParametrizedCommand(menuManager, window, + OpenGenerateBinariesWizard.ID, + OpenGenerateBinariesWizard.DEFAULT_LABEL, + OpenGenerateBinariesWizard.DEFAULT_ICON, true, params); + + // boolean isRelevant = false; + // try { + // isRelevant = currSelected.isNodeType(SlcTypes.SLC_CATEGORY); + // boolean canEdit = currSelected.canAddMixin(SlcTypes.SLC_CATEGORY); + // + // } catch (RepositoryException e) { + // throw new SlcException("unable to check type of node " + // + firstElement, e); + // } + // // Add + // if (isRelevant) {// Remove + // CommandUtils.refreshCommand(menuManager, window, + // MarkAsRelevantCategory.ID, + // MarkAsRelevantCategory.DEFAULT_REMOVE_LABEL, + // MarkAsRelevantCategory.DEFAULT_REMOVE_ICON, true); + // } else { + // CommandUtils.refreshCommand(menuManager, window, + // MarkAsRelevantCategory.ID, + // MarkAsRelevantCategory.DEFAULT_LABEL, + // MarkAsRelevantCategory.DEFAULT_ICON, true); + // } } private SelectionAdapter getSelectionAdapter(final int index) { diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/ModularDistBaseElem.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/ModularDistVersionBaseElem.java similarity index 73% rename from plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/ModularDistBaseElem.java rename to plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/ModularDistVersionBaseElem.java index b85659440..af42d8744 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/ModularDistBaseElem.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/ModularDistVersionBaseElem.java @@ -19,33 +19,37 @@ import org.argeo.slc.jcr.SlcTypes; * Abstract the base of a given modular distribution set i.e. the parent of all * versions of a given modular distribution */ -public class ModularDistBaseElem extends DistParentElem { +public class ModularDistVersionBaseElem extends DistParentElem { - final static public String AETHER_CATEGORY_BASE = "categoryBase"; + // final static public String AETHER_CATEGORY_BASE = "categoryBase"; final static public String AETHER_BINARIES_TYPE = "binaries"; final static public String AETHER_DEP_TYPE = "dep"; private String type; - private Node modularDistBase; + private Node modularDistVersionBase; - public ModularDistBaseElem(WorkspaceElem wkspElem, String name, - Node modularDistBase, String type) { + public ModularDistVersionBaseElem(WorkspaceElem wkspElem, String name, + Node modularDistVersionBase, String type) { super(name, wkspElem.inHome(), wkspElem.isReadOnly()); setParent(wkspElem); - this.modularDistBase = modularDistBase; + this.modularDistVersionBase = modularDistVersionBase; this.type = type; } - public Node getCategoryBase() { - // TODO clean this - if (type.equals(AETHER_CATEGORY_BASE)) - return modularDistBase; - else - try { - return modularDistBase.getParent(); - } catch (RepositoryException e) { - throw new SlcException("unable tyo get parent node for " - + modularDistBase, e); - } + public Node getModularDistBase() { + // // TODO clean this + // if (type.equals(AETHER_CATEGORY_BASE)) + // return modularDistVersionBase; + // else + try { + return modularDistVersionBase.getParent(); + } catch (RepositoryException e) { + throw new SlcException("unable to get parent node for " + + modularDistVersionBase, e); + } + } + + public WorkspaceElem getWkspElem() { + return (WorkspaceElem) getParent(); } /** @@ -82,24 +86,24 @@ public class ModularDistBaseElem extends DistParentElem { return super.getChildren(); } catch (RepositoryException re) { throw new ArgeoException("Unable to retrieve children for " - + modularDistBase, re); + + modularDistVersionBase, re); } } } private NodeIterator getDistVersions() { try { - if (AETHER_CATEGORY_BASE.equals(type)) - return null; + // if (AETHER_CATEGORY_BASE.equals(type)) + // return null; - QueryManager queryManager = modularDistBase.getSession() + QueryManager queryManager = modularDistVersionBase.getSession() .getWorkspace().getQueryManager(); QueryObjectModelFactory factory = queryManager.getQOMFactory(); Selector source = factory.selector( SlcTypes.SLC_MODULAR_DISTRIBUTION, SlcTypes.SLC_MODULAR_DISTRIBUTION); Constraint constraint = factory.descendantNode( - source.getSelectorName(), modularDistBase.getPath()); + source.getSelectorName(), modularDistVersionBase.getPath()); // Ordering order = factory.descending(factory.propertyValue( // source.getSelectorName(), SlcNames.SLC_ARTIFACT_VERSION)); // Ordering[] orderings = { order }; @@ -117,5 +121,4 @@ public class ModularDistBaseElem extends DistParentElem { public String getType() { return type; } - } \ No newline at end of file diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/ModularDistVersionElem.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/ModularDistVersionElem.java index 54a82e812..23c757895 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/ModularDistVersionElem.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/ModularDistVersionElem.java @@ -9,7 +9,7 @@ import javax.jcr.Node; public class ModularDistVersionElem extends DistParentElem { private final Node modularDistVersionNode; - public ModularDistVersionElem(ModularDistBaseElem modularDistGroupElem, + public ModularDistVersionElem(ModularDistVersionBaseElem modularDistGroupElem, String version, Node modularDistVersionNode) { super(version, modularDistGroupElem.inHome(), modularDistGroupElem .isReadOnly()); diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/RepoElem.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/RepoElem.java index 3dc56ed2b..28841c869 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/RepoElem.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/RepoElem.java @@ -199,20 +199,32 @@ public class RepoElem extends DistParentElem { return uri; } + public String getRepoNodePath() { + if (repoNode == null) + return null; + else + try { + return repoNode.getPath(); + } catch (RepositoryException e) { + throw new SlcException("Cannot get node path for repository " + + label, e); + } + } + /** * Exposes the local repoNode that completely define a connection to a * repository (including a set of credentials). Might return null in case of * an anonymous user */ - public Node getRepoNode() { + protected Node getRepoNode() { return repoNode; } - public Repository getRepository() { + protected Repository getRepository() { return repository; } - - public Credentials getCredentials() { + + protected Credentials getCredentials() { return credentials; } diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/WorkspaceElem.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/WorkspaceElem.java index c3088ebb2..e35c66da4 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/WorkspaceElem.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/model/WorkspaceElem.java @@ -4,6 +4,7 @@ import javax.jcr.Node; import javax.jcr.NodeIterator; import javax.jcr.RepositoryException; import javax.jcr.Session; +import javax.jcr.query.InvalidQueryException; import javax.jcr.query.Query; import org.argeo.ArgeoException; @@ -82,8 +83,17 @@ public class WorkspaceElem extends DistParentElem { "select * from [" + SlcTypes.SLC_MODULAR_DISTRIBUTION + "]", Query.JCR_SQL2); - NodeIterator distributions = groupQuery.execute().getNodes(); - distribs: while (distributions.hasNext()) { + NodeIterator distributions = null; + try { + distributions = groupQuery.execute().getNodes(); + } catch (InvalidQueryException iqe) { + // For legacy only does not throw an exception while + // browsing + // legacy repositories that does not know + // SLC_MODULAR_DISTRIBUTION type + } + distribs: while (distributions != null + && distributions.hasNext()) { Node currDist = distributions.nextNode(); Node distBase = currDist.getParent().getParent(); if (!distBase.isNodeType(SlcTypes.SLC_ARTIFACT_BASE)) @@ -95,35 +105,17 @@ public class WorkspaceElem extends DistParentElem { String name; String type; - if (ModularDistBaseElem.AETHER_BINARIES_TYPE + if (ModularDistVersionBaseElem.AETHER_BINARIES_TYPE .equals(artifactId)) { name = groupId; - type = ModularDistBaseElem.AETHER_BINARIES_TYPE; + type = ModularDistVersionBaseElem.AETHER_BINARIES_TYPE; } else { name = artifactId; - type = ModularDistBaseElem.AETHER_DEP_TYPE; + type = ModularDistVersionBaseElem.AETHER_DEP_TYPE; } if (getChildByName(name) == null) - addChild(new ModularDistBaseElem(WorkspaceElem.this, - name, distBase, type)); - } - // Add empty group base that have been marked as relevant - groupQuery = currSession - .getWorkspace() - .getQueryManager() - .createQuery( - "select * from [" - + SlcTypes.SLC_CATEGORY + "]", - Query.JCR_SQL2); - distributions = groupQuery.execute().getNodes(); - while (distributions.hasNext()) { - Node distBase = distributions.nextNode(); - String groupBaseId = distBase.getProperty( - SlcNames.SLC_GROUP_BASE_ID).getString(); - if (getChildByName(groupBaseId) == null) - addChild(new ModularDistBaseElem(WorkspaceElem.this, - groupBaseId, distBase, - ModularDistBaseElem.AETHER_CATEGORY_BASE)); + addChild(new ModularDistVersionBaseElem( + WorkspaceElem.this, name, distBase, type)); } return super.getChildren(); } catch (RepositoryException e) { diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java index 84cb8e5ef..677bed994 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/views/DistributionsView.java @@ -46,7 +46,7 @@ import org.argeo.slc.client.ui.dist.controllers.DistTreeContentProvider; import org.argeo.slc.client.ui.dist.controllers.DistTreeDoubleClickListener; import org.argeo.slc.client.ui.dist.controllers.DistTreeLabelProvider; import org.argeo.slc.client.ui.dist.model.DistParentElem; -import org.argeo.slc.client.ui.dist.model.ModularDistBaseElem; +import org.argeo.slc.client.ui.dist.model.ModularDistVersionBaseElem; import org.argeo.slc.client.ui.dist.model.RepoElem; import org.argeo.slc.client.ui.dist.model.WkspGroupElem; import org.argeo.slc.client.ui.dist.model.WorkspaceElem; @@ -128,57 +128,58 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames IWorkbenchWindow window = DistPlugin.getDefault().getWorkbench() .getActiveWorkbenchWindow(); + // Most of the implemented commands support only one selected + // element + boolean singleElement = ((IStructuredSelection) viewer.getSelection()) + .size() == 1; + // Get Current selected item : + Object firstElement = ((IStructuredSelection) viewer.getSelection()) + .getFirstElement(); + try { - // Most of the implemented commands support only one selected - // element - boolean singleElement = ((IStructuredSelection) viewer - .getSelection()).size() == 1; - // Get Current selected item : - Object firstElement = ((IStructuredSelection) viewer.getSelection()) - .getFirstElement(); if (firstElement instanceof TreeParent || firstElement instanceof DistParentElem) { String targetRepoPath = null, workspaceName = null, workspacePrefix = null; + String modularDistBasePath = null; // String targetRepoUri = null; // Build conditions depending on element type - boolean isDistribElem = false, isModularDistBaseElem = false, isRepoElem = false, isDistribGroupElem = false; + boolean isDistribElem = false, isModularDistVersionBaseElem = false, isRepoElem = false, isDistribGroupElem = false; boolean isLocal = false, isReadOnly = true; RepoElem re = null; - if (firstElement instanceof WorkspaceElem) { - WorkspaceElem de = (WorkspaceElem) firstElement; - re = (RepoElem) de.getParent().getParent(); - isDistribElem = true; - isReadOnly = de.isReadOnly(); - workspaceName = de.getWorkspaceName(); - isLocal = de.inHome(); - } else if (firstElement instanceof RepoElem) { + if (firstElement instanceof RepoElem) { re = (RepoElem) firstElement; isRepoElem = true; isLocal = re.inHome(); isReadOnly = re.isReadOnly(); - } else if (firstElement instanceof ModularDistBaseElem) { - ModularDistBaseElem mdbe = (ModularDistBaseElem) firstElement; - re = (RepoElem) mdbe.getParent().getParent().getParent(); - isModularDistBaseElem = true; - isLocal = re.inHome(); - isReadOnly = re.isReadOnly(); } else if (firstElement instanceof WkspGroupElem) { WkspGroupElem wge = (WkspGroupElem) firstElement; isReadOnly = wge.isReadOnly(); isDistribGroupElem = true; re = (RepoElem) wge.getParent(); workspacePrefix = wge.getName(); + } else if (firstElement instanceof WorkspaceElem) { + WorkspaceElem we = (WorkspaceElem) firstElement; + re = we.getRepoElem(); + isDistribElem = true; + isReadOnly = we.isReadOnly(); + workspaceName = we.getWorkspaceName(); + isLocal = we.inHome(); + } else if (firstElement instanceof ModularDistVersionBaseElem) { + ModularDistVersionBaseElem mdbe = (ModularDistVersionBaseElem) firstElement; + isModularDistVersionBaseElem = true; + re = mdbe.getWkspElem().getRepoElem(); + isLocal = re.inHome(); + isReadOnly = re.isReadOnly(); + workspaceName = mdbe.getWkspElem().getWorkspaceName(); + modularDistBasePath = mdbe.getModularDistBase().getPath(); } - // TODO add case for goups - if (re != null) { - // targetRepoUri = re.getUri(); - targetRepoPath = re.getRepoNode().getPath(); + targetRepoPath = re.getRepoNodePath(); } // Display repo info @@ -198,18 +199,19 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames CreateWorkspace.ID, CreateWorkspace.DEFAULT_LABEL, CreateWorkspace.DEFAULT_ICON, (isRepoElem || isDistribGroupElem) && singleElement - && !isReadOnly && !isLocal, params); + && !isReadOnly && !isLocal, params); // TODO Manage the case where it is not a java workspace params = new HashMap(); params.put(CreateLocalJavaWorkspace.PARAM_WORKSPACE_PREFIX, workspacePrefix); CommandUtils.refreshParametrizedCommand(menuManager, window, - CreateLocalJavaWorkspace.ID, CreateLocalJavaWorkspace.DEFAULT_LABEL, + CreateLocalJavaWorkspace.ID, + CreateLocalJavaWorkspace.DEFAULT_LABEL, CreateLocalJavaWorkspace.DEFAULT_ICON, (isRepoElem || isDistribGroupElem) && singleElement && !isReadOnly && isLocal, params); - + // Register a remote repository CommandUtils.refreshCommand(menuManager, window, RegisterRepository.ID, @@ -255,14 +257,15 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames CopyWorkspace.ID, CopyWorkspace.DEFAULT_LABEL, CopyWorkspace.DEFAULT_ICON, isDistribElem && singleElement && !isLocal, params); - + params = new HashMap(); params.put(CopyLocalJavaWorkspace.PARAM_SOURCE_WORKSPACE_NAME, workspaceName); CommandUtils.refreshParametrizedCommand(menuManager, window, - CopyLocalJavaWorkspace.ID, CopyLocalJavaWorkspace.DEFAULT_LABEL, + CopyLocalJavaWorkspace.ID, + CopyLocalJavaWorkspace.DEFAULT_LABEL, CopyLocalJavaWorkspace.DEFAULT_ICON, isDistribElem - && singleElement&& isLocal, params); + && singleElement && isLocal, params); // Clear Workspace params = new HashMap(); @@ -310,13 +313,22 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames CommandUtils.refreshParametrizedCommand(submenu, window, RunInOsgi.ID, RunInOsgi.DEFAULT_LABEL, RunInOsgi.DEFAULT_ICON, isDistribElem && singleElement - && isLocal, params);// Run in OSGi + && isLocal, params); - CommandUtils.refreshCommand(submenu, window, + // Open generate binaries + params = new HashMap(); + params.put(OpenGenerateBinariesWizard.PARAM_REPO_NODE_PATH, + targetRepoPath); + params.put(OpenGenerateBinariesWizard.PARAM_MODULE_PATH, + modularDistBasePath); + params.put(OpenGenerateBinariesWizard.PARAM_WORKSPACE_NAME, + workspaceName); + + CommandUtils.refreshParametrizedCommand(submenu, window, OpenGenerateBinariesWizard.ID, OpenGenerateBinariesWizard.DEFAULT_LABEL, OpenGenerateBinariesWizard.DEFAULT_ICON, - isModularDistBaseElem && !isReadOnly); + isModularDistVersionBaseElem && !isReadOnly, params); if (submenu.getSize() > 0) menuManager.add(submenu); @@ -332,7 +344,7 @@ public class DistributionsView extends ViewPart implements SlcNames, ArgeoNames } } catch (RepositoryException e) { throw new SlcException("unexpected errror while " - + "building context menu", e); + + "building context menu for element " + firstElement, e); } } diff --git a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/wizards/GenerateBinariesWizard.java b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/wizards/GenerateBinariesWizard.java index 136eae150..a76d38d14 100644 --- a/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/wizards/GenerateBinariesWizard.java +++ b/plugins/org.argeo.slc.client.ui.dist/src/main/java/org/argeo/slc/client/ui/dist/wizards/GenerateBinariesWizard.java @@ -18,10 +18,8 @@ package org.argeo.slc.client.ui.dist.wizards; import java.util.ArrayList; import java.util.List; -import javax.jcr.Credentials; import javax.jcr.Node; import javax.jcr.NodeIterator; -import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.Session; @@ -33,6 +31,7 @@ import org.argeo.jcr.JcrUtils; import org.argeo.slc.SlcException; import org.argeo.slc.client.ui.dist.DistPlugin; import org.argeo.slc.client.ui.dist.PrivilegedJob; +import org.argeo.slc.client.ui.dist.RepoService; import org.argeo.slc.client.ui.dist.utils.ViewerUtils; import org.argeo.slc.jcr.SlcTypes; import org.argeo.slc.repo.RepoConstants; @@ -71,10 +70,10 @@ public class GenerateBinariesWizard extends Wizard { .getLog(GenerateBinariesWizard.class); // Business objects - private String groupNodePath; - private Repository repository; - private Credentials credentials; + private final RepoService repoService; + private final String repoNodePath; private String wkspName; + private String groupNodePath; // The pages private RecapPage recapPage; @@ -84,11 +83,11 @@ public class GenerateBinariesWizard extends Wizard { private Text latestVersionTxt; private Text highestArtifactVersionTxt; - public GenerateBinariesWizard(Repository repository, - Credentials credentials, String wkspName, String groupNodePath) { + public GenerateBinariesWizard(RepoService repoService, String repoNodePath, + String wkspName, String groupNodePath) { super(); - this.repository = repository; - this.credentials = credentials; + this.repoService = repoService; + this.repoNodePath = repoNodePath; this.wkspName = wkspName; this.groupNodePath = groupNodePath; } @@ -123,8 +122,8 @@ public class GenerateBinariesWizard extends Wizard { "Confirm Launch", msg); if (result) { - GenerateBinaryJob job = new GenerateBinaryJob(repository, - credentials, wkspName, groupNodePath, + GenerateBinaryJob job = new GenerateBinaryJob(repoService, + repoNodePath, wkspName, groupNodePath, versionTxt.getText()); job.setUser(true); job.schedule(); @@ -159,7 +158,8 @@ public class GenerateBinariesWizard extends Wizard { private void refreshValues() { Session session = null; try { - session = repository.login(credentials, wkspName); + session = repoService.getRemoteSession(repoNodePath, null, + wkspName); Node groupNode = session.getNode(groupNodePath); GenerateBinaries gb = GenerateBinaries.preProcessGroupNode( groupNode, null); @@ -283,19 +283,18 @@ public class GenerateBinariesWizard extends Wizard { */ private class GenerateBinaryJob extends PrivilegedJob { - private final Repository repository; - private final Credentials credentials; + private final RepoService repoService; + private final String repoNodePath; private final String wkspName; private final String groupNodePath; private final String version; - public GenerateBinaryJob(Repository repository, - Credentials credentials, String wkspName, String groupNodePath, - String version) { + public GenerateBinaryJob(RepoService repoService, String repoNodePath, + String wkspName, String groupNodePath, String version) { super("Fetch"); this.version = version; - this.repository = repository; - this.credentials = credentials; + this.repoService = repoService; + this.repoNodePath = repoNodePath; this.wkspName = wkspName; this.groupNodePath = groupNodePath; } @@ -305,7 +304,8 @@ public class GenerateBinariesWizard extends Wizard { Session session = null; try { ArgeoMonitor monitor = new EclipseArgeoMonitor(progressMonitor); - session = repository.login(credentials, wkspName); + session = repoService.getRemoteSession(repoNodePath, null, + wkspName); Node groupBaseNode = session.getNode(groupNodePath); GenerateBinaries.processGroupNode(groupBaseNode, version, monitor); diff --git a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/RepoUtils.java b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/RepoUtils.java index fa4fa0c70..b0e65bce5 100644 --- a/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/RepoUtils.java +++ b/runtime/org.argeo.slc.repo/src/main/java/org/argeo/slc/repo/RepoUtils.java @@ -420,14 +420,13 @@ public class RepoUtils implements ArgeoNames, SlcNames { /** * Shortcut to retrieve a session given variable information: Handle the * case where we only have an URI of the repository, that we want to connect - * as anonymous or the case of a identified connexion to a local or remote + * as anonymous or the case of a identified connection to a local or remote * repository. * * Callers must close the session once it has been used */ - public static Session getCorrespondingSession( - RepositoryFactory repositoryFactory, Keyring keyring, - Node repoNode, String uri, String workspaceName) { + public static Session getRemoteSession(RepositoryFactory repositoryFactory, + Keyring keyring, Node repoNode, String uri, String workspaceName) { try { if (repoNode == null && uri == null) throw new SlcException( @@ -453,6 +452,35 @@ public class RepoUtils implements ArgeoNames, SlcNames { } } + /** + * Shortcut to retrieve a session on a remote Jrc Repository from + * information stored in a local argeo node or from an URI: Handle the case + * where we only have an URI of the repository, that we want to connect as + * anonymous or the case of a identified connection to a local or remote + * repository. + * + * Callers must close the session once it has been used + */ + public static Session getRemoteSession(RepositoryFactory repositoryFactory, + Keyring keyring, Repository localRepository, String repoNodePath, + String uri, String workspaceName) { + Session localSession = null; + Node repoNode = null; + try { + localSession = localRepository.login(); + if (repoNodePath != null && localSession.nodeExists(repoNodePath)) + repoNode = localSession.getNode(repoNodePath); + + return RepoUtils.getRemoteSession(repositoryFactory, keyring, + repoNode, uri, workspaceName); + } catch (RepositoryException e) { + throw new SlcException("Cannot log to workspace " + workspaceName + + " for repo defined in " + repoNodePath, e); + } finally { + JcrUtils.logoutQuietly(localSession); + } + } + /** * Write group indexes: 'binaries' lists all bundles and their versions, * 'sources' list theire sources, and 'sdk' aggregates both. diff --git a/runtime/org.argeo.slc.repo/src/main/resources/org/argeo/slc/repo/repo.cnd b/runtime/org.argeo.slc.repo/src/main/resources/org/argeo/slc/repo/repo.cnd index 1acaf9823..271e85eee 100644 --- a/runtime/org.argeo.slc.repo/src/main/resources/org/argeo/slc/repo/repo.cnd +++ b/runtime/org.argeo.slc.repo/src/main/resources/org/argeo/slc/repo/repo.cnd @@ -27,8 +27,8 @@ mixin - slc:groupBaseId (STRING) m // Mark a given group base as relevant to create modular distribution in the current workspace -[slc:category] -mixin +// [slc:category] +// mixin [slc:distribution] > slc:artifactVersion mixin @@ -38,8 +38,7 @@ mixin [slc:modularDistributionBase] mixin -// Inherit from > slc:categorizedNameVersion ?? -// (not possible without migration) +// Question: Extend slc:categorizedNameVersion ? (not possible without migration) [slc:modularDistribution] mixin + slc:modules (nt:unstructured) m diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcNames.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcNames.java index c12f86c85..15213fc0a 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcNames.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcNames.java @@ -105,7 +105,6 @@ public interface SlcNames { // shared OSGi public final static String SLC_SYMBOLIC_NAME = "slc:symbolic-name"; public final static String SLC_BUNDLE_VERSION = "slc:bundle-version"; - public final static String SLC_BUNDLE_DESCRIPTION = "slc:Bundle-Description"; // slc:osgiBaseVersion public final static String SLC_MAJOR = "slc:major"; diff --git a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcTypes.java b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcTypes.java index 177dbb369..5cb6a1361 100644 --- a/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcTypes.java +++ b/runtime/org.argeo.slc.support.jcr/src/main/java/org/argeo/slc/jcr/SlcTypes.java @@ -69,7 +69,7 @@ public interface SlcTypes { public final static String SLC_FRAGMENT_HOST = "slc:fragmentHost"; // Distribution management - public final static String SLC_CATEGORY = "slc:category"; + // public final static String SLC_CATEGORY = "slc:category"; public final static String SLC_MODULAR_DISTRIBUTION_BASE = "slc:modularDistributionBase"; public final static String SLC_MODULAR_DISTRIBUTION = "slc:modularDistribution"; public final static String SLC_MODULE_COORDINATES = "slc:moduleCoordinates"; -- 2.39.5