--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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.editors.ArtifactEditor;
+import org.argeo.slc.client.ui.dist.editors.ModuleEditorInput;
+import org.argeo.slc.client.ui.dist.editors.DistributionEditor;
+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;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Open the relevant editor for a given module node of a given repository
+ * workspace. For the time being, modules can be artifacts or
+ * modularDistributions
+ */
+public class OpenModuleEditor extends AbstractHandler {
+ public final static String ID = DistPlugin.ID + ".openModuleEditor";
+ public final static String DEFAULT_LABEL = "Open relevant editor";
+
+ // use local node repo and repository factory to retrieve and log to
+ // relevant repository
+ public final static String PARAM_REPO_NODE_PATH = "param.repoNodePath";
+ // use URI and repository factory to retrieve and ANONYMOUSLY log in
+ // relevant repository
+ public final static String PARAM_REPO_URI = "param.repoUri";
+ public final static String PARAM_WORKSPACE_NAME = "param.workspaceName";
+ public final static String PARAM_ARTIFACT_PATH = "param.artifactPath";
+
+ /* 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;
+
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ String repoNodePath = event.getParameter(PARAM_REPO_NODE_PATH);
+ String repoUri = event.getParameter(PARAM_REPO_URI);
+ String workspaceName = event.getParameter(PARAM_WORKSPACE_NAME);
+ String artifactPath = event.getParameter(PARAM_ARTIFACT_PATH);
+
+ Session localSession = null;
+ Session businessSession = null;
+ Node repoNode = null;
+
+ try {
+ if (repoNodePath != null && repoUri == null) {
+ try {
+ localSession = localRepository.login();
+ if (repoNodePath != null
+ && localSession.nodeExists(repoNodePath))
+ repoNode = localSession.getNode(repoNodePath);
+
+ businessSession = RepoUtils.getCorrespondingSession(
+ repositoryFactory, keyring, repoNode, repoUri,
+ workspaceName);
+ repoUri = repoNode.getProperty(ArgeoNames.ARGEO_URI)
+ .getString();
+
+ } 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,
+ repoUri, workspaceName, artifactPath);
+ Node artifact = businessSession.getNode(artifactPath);
+
+ // Choose correct editor based on the artifact mixin
+ if (artifact.isNodeType(SlcTypes.SLC_MODULAR_DISTRIBUTION))
+ HandlerUtil.getActiveWorkbenchWindow(event).getActivePage()
+ .openEditor(wei, DistributionEditor.ID);
+ else
+ HandlerUtil.getActiveWorkbenchWindow(event).getActivePage()
+ .openEditor(wei, ArtifactEditor.ID);
+ } catch (RepositoryException e) {
+ throw new SlcException("Unexpected error while "
+ + "getting repoNode info for repoNode at path "
+ + repoNodePath, e);
+ } catch (PartInitException e) {
+ throw new SlcException("Unexpected error while "
+ + "opening editor for workspace " + workspaceName
+ + " with URI " + repoUri + " and repoNode at path "
+ + repoNodePath, e);
+ }
+ return null;
+ }
+
+ /* 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;
+ }
+
+}
\ No newline at end of file
import org.argeo.eclipse.ui.utils.CommandUtils;
import org.argeo.slc.SlcException;
+import org.argeo.slc.client.ui.dist.commands.OpenModuleEditor;
import org.argeo.slc.client.ui.dist.commands.OpenWorkspaceEditor;
+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.WorkspaceElem;
import org.eclipse.jface.viewers.DoubleClickEvent;
}
} else if (obj instanceof WorkspaceElem) {
WorkspaceElem wn = (WorkspaceElem) obj;
- if (!wn.isConnected())
+ if (!wn.isConnected()) {
wn.login();
- else {
+ treeViewer.refresh(obj);
+ } else {
WorkspaceElem we = (WorkspaceElem) obj;
-
+ Node repoNode = null;
try {
RepoElem repoElem = we.getRepoElem();
Map<String, String> params = new HashMap<String, String>();
- Node repoNode = repoElem.getRepoNode();
+ repoNode = repoElem.getRepoNode();
if (repoNode != null)
params.put(OpenWorkspaceEditor.PARAM_REPO_NODE_PATH,
repoNode.getPath());
we.getWorkspaceName());
CommandUtils.callCommand(OpenWorkspaceEditor.ID, params);
} catch (RepositoryException re) {
- throw new SlcException(
- "Cannot get path for node while "
- + "setting parameters of command OpenWorkspaceEditor",
- re);
+ throw new SlcException("Cannot get path for node "
+ + repoNode + " while "
+ + "setting parameters of command "
+ + "OpenWorkspaceEditor", re);
}
}
- treeViewer.refresh(obj);
+ } else if (obj instanceof ModularDistVersionElem) {
+ ModularDistVersionElem modDistElem = (ModularDistVersionElem) obj;
+ WorkspaceElem wkspElem = modDistElem.getWorkspaceElem();
+ Node repoNode = null;
+ Node moduleNode = modDistElem.getModularDistVersionNode();
+ try {
+ RepoElem repoElem = wkspElem.getRepoElem();
+ Map<String, String> params = new HashMap<String, String>();
+ 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_ARTIFACT_PATH,
+ moduleNode.getPath());
+ CommandUtils.callCommand(OpenModuleEditor.ID, params);
+ } catch (RepositoryException re) {
+ throw new SlcException("Cannot get path for node " + repoNode
+ + " or " + moduleNode
+ + " while setting parameters for "
+ + "command OpenModuleEditor", re);
+ }
}
}
}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+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.client.ui.dist.DistPlugin;
+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;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.forms.editor.FormEditor;
+
+/**
+ * Base editor to manage an artifact in a multirepository environment
+ */
+public class ArtifactEditor extends FormEditor implements SlcNames {
+ // private final static Log log =
+ // LogFactory.getLog(ArtifactEditor.class);
+ public final static String ID = DistPlugin.ID + ".artifactEditor";
+
+ 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 Session businessSession;
+ private Node artifact;
+
+ @Override
+ public void init(IEditorSite site, IEditorInput input)
+ throws PartInitException {
+ editorInput = (ModuleEditorInput) input;
+ 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);
+ }
+ setPartName(editorInput.getWorkspaceName());
+ super.init(site, input);
+ }
+
+ @Override
+ protected void addPages() {
+ try {
+ addPage(new DistributionOverviewPage(this, "Overview",
+ businessSession));
+ addPage(new ArtifactsBrowserPage(this, "Browser", businessSession));
+ } catch (PartInitException e) {
+ throw new ArgeoException("Cannot add distribution editor pages", e);
+ }
+ }
+
+ @Override
+ public void doSave(IProgressMonitor arg0) {
+ }
+
+ @Override
+ public void dispose() {
+ JcrUtils.logoutQuietly(businessSession);
+ JcrUtils.logoutQuietly(localSession);
+ super.dispose();
+ }
+
+ @Override
+ public void doSaveAs() {
+ }
+
+ @Override
+ public boolean isSaveAsAllowed() {
+ return false;
+ }
+
+ protected Node getRepoNode() {
+ return repoNode;
+ }
+
+ protected Node getArtifact() {
+ return artifact;
+ }
+
+ /* 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;
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.argeo.slc.client.ui.dist.editors;
+
+import org.argeo.jcr.JcrUtils;
+import org.argeo.slc.SlcException;
+import org.argeo.slc.jcr.SlcNames;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IPersistableElement;
+
+/**
+ * An editor input for a JCR node object in a multi-repository environment.
+ */
+public class ModuleEditorInput implements IEditorInput, SlcNames {
+
+ // Define relevant workspace on a given repository
+ private String repoNodePath;
+ private String uri;
+ private String workspaceName;
+ private String modulePath;
+
+ public ModuleEditorInput(String repoNodePath, String uri,
+ 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 (artifactPath == null)
+ throw new SlcException("Module path cannot be null");
+ this.repoNodePath = repoNodePath;
+ this.uri = uri;
+ this.workspaceName = workspaceName;
+ this.modulePath = artifactPath;
+ }
+
+ public String getModulePath() {
+ return modulePath;
+ }
+
+ public String getWorkspaceName() {
+ return workspaceName;
+ }
+
+ public String getRepoNodePath() {
+ return repoNodePath;
+ }
+
+ public String getUri() {
+ return uri;
+ }
+
+ public Object getAdapter(@SuppressWarnings("rawtypes") Class adapter) {
+ return null;
+ }
+
+ public boolean exists() {
+ return true;
+ }
+
+ public ImageDescriptor getImageDescriptor() {
+ return null;
+ }
+
+ // Dummy compulsory methods
+ public String getToolTipText() {
+ return getModulePath();
+ }
+
+ public String getName() {
+ return JcrUtils.lastPathElement(modulePath);
+ }
+
+ public IPersistableElement getPersistable() {
+ return null;
+ }
+
+ /**
+ * equals method based on coordinates
+ */
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+
+ ModuleEditorInput other = (ModuleEditorInput) obj;
+
+ if (!modulePath.equals(other.getModulePath()))
+ return false;
+ if (!workspaceName.equals(other.getWorkspaceName()))
+ return false;
+ if (!uri.equals(other.getUri()))
+ return false;
+
+ if (repoNodePath == null)
+ return other.getRepoNodePath() == null;
+ else
+ return repoNodePath.equals(other.getRepoNodePath());
+ }
+}
\ No newline at end of file
// Create a dynamic operand for each property on which we want to
// filter
DynamicOperand catDO = factory.propertyValue(
- source.getSelectorName(), SlcNames.SLC_MODULE_CATEGORY);
+ source.getSelectorName(), SlcNames.SLC_CATEGORY);
DynamicOperand nameDO = factory.propertyValue(
- source.getSelectorName(), SlcNames.SLC_MODULE_NAME);
+ source.getSelectorName(), SlcNames.SLC_NAME);
DynamicOperand versionDO = factory.propertyValue(
- source.getSelectorName(), SlcNames.SLC_MODULE_VERSION);
+ source.getSelectorName(), SlcNames.SLC_VERSION);
String path = modularDistribution.getPath() + "/"
+ SlcNames.SLC_MODULES;
return getName();
}
+ public WorkspaceElem getWorkspaceElem() {
+ return (WorkspaceElem) getParent().getParent();
+ }
+
public Node getModularDistVersionNode() {
return modularDistVersionNode;
}
Node moduleCoord = modules.addNode(
artifact.getArtifactId(),
SlcTypes.SLC_MODULE_COORDINATES);
- moduleCoord.setProperty(SlcNames.SLC_MODULE_NAME,
+ moduleCoord.setProperty(SlcNames.SLC_NAME,
artifact.getArtifactId());
- moduleCoord.setProperty(SlcNames.SLC_MODULE_VERSION,
+ moduleCoord.setProperty(SlcNames.SLC_VERSION,
artifact.getVersion());
String groupId = artifact.getGroupId();
if (groupId != null && !"".equals(groupId.trim()))
- moduleCoord.setProperty(
- SlcNames.SLC_MODULE_CATEGORY,
+ moduleCoord.setProperty(SlcNames.SLC_CATEGORY,
artifact.getGroupId());
}
}
while ((line = reader.readLine()) != null) {
StringTokenizer st = new StringTokenizer(line, separator);
- String moduleName = st.nextToken();
- String moduleVersion = st.nextToken();
+ // String moduleName =
+ st.nextToken();
+ // String moduleVersion =
+ st.nextToken();
String relativeUrl = st.nextToken();
//
return artifacts;
}
- /** Relative path to the directories where the files will be stored */
- private String getCategoryFromRelativeUrl(String relativeUrl,
- String moduleName) {
- int index = relativeUrl.indexOf("moduleName");
- if (index < 1)
- throw new SlcException("Unvalid relative URL: " + relativeUrl
- + " for module " + moduleName);
- // Remove trailing /
- String result = relativeUrl.substring(0, index - 1);
- return result.replace('/', '.');
- }
+ // /** Relative path to the directories where the files will be stored */
+ // private String getCategoryFromRelativeUrl(String relativeUrl,
+ // String moduleName) {
+ // int index = relativeUrl.indexOf("moduleName");
+ // if (index < 1)
+ // throw new SlcException("Unvalid relative URL: " + relativeUrl
+ // + " for module " + moduleName);
+ // // Remove trailing /
+ // String result = relativeUrl.substring(0, index - 1);
+ // return result.replace('/', '.');
+ // }
/**
* List full URLs of the bundles, based on base URL, usable directly for
// so using groupId would conflict
- slc:groupBaseId (STRING) m
+// Mark a given group base as relevant to create modular distribution in the current workspace
+[slc:category]
+mixin
+
[slc:distribution] > slc:artifactVersion
mixin
+ slc:artifactVersions (argeo:references) m
+
+[slc:modularDistributionBase]
+mixin
+
[slc:modularDistribution]
mixin
+ slc:modules (nt:unstructured) m
public final static String SLC_AGGREGATED_STATUS = "slc:aggregatedStatus";
public final static String SLC_TYPE = "slc:type";
+ public final static String SLC_CATEGORY = "slc:category";
public final static String SLC_NAME = "slc:name";
public final static String SLC_VERSION = "slc:version";
public final static String SLC_VALUE = "slc:value";
// slc:modularDistribution
public final static String SLC_MODULES = "slc:modules";
- // slc:moduleCoordinates
- public final static String SLC_MODULE_CATEGORY = "slc:category";
- public final static String SLC_MODULE_NAME = "slc:name";
- public final static String SLC_MODULE_VERSION = "slc:version";
-
// RPM
// slc:rpm
public final static String SLC_RPM_VERSION = "slc:rpmVersion";
public final static String SLC_REQUIRED_BUNDLE = "slc:requiredBundle";
public final static String SLC_FRAGMENT_HOST = "slc:fragmentHost";
+ // Distribution management
+ public final static String SLC_RELEVANT_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";