You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ace.apache.org by ja...@apache.org on 2014/02/26 14:57:40 UTC

svn commit: r1572051 - in /ace/trunk/org.apache.ace.client.workspace/src/org/apache/ace/client/workspace: Workspace.java impl/WorkspaceImpl.java

Author: jawi
Date: Wed Feb 26 13:57:40 2014
New Revision: 1572051

URL: http://svn.apache.org/r1572051
Log:
Added a Gogo command to create & upload an artifact from a local file.


Modified:
    ace/trunk/org.apache.ace.client.workspace/src/org/apache/ace/client/workspace/Workspace.java
    ace/trunk/org.apache.ace.client.workspace/src/org/apache/ace/client/workspace/impl/WorkspaceImpl.java

Modified: ace/trunk/org.apache.ace.client.workspace/src/org/apache/ace/client/workspace/Workspace.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.workspace/src/org/apache/ace/client/workspace/Workspace.java?rev=1572051&r1=1572050&r2=1572051&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.workspace/src/org/apache/ace/client/workspace/Workspace.java (original)
+++ ace/trunk/org.apache.ace.client.workspace/src/org/apache/ace/client/workspace/Workspace.java Wed Feb 26 13:57:40 2014
@@ -24,6 +24,7 @@ import java.util.Map;
 
 import org.apache.ace.client.repository.ObjectRepository;
 import org.apache.ace.client.repository.RepositoryObject;
+import org.apache.ace.client.repository.helper.ArtifactHelper;
 import org.apache.ace.client.repository.object.Artifact2FeatureAssociation;
 import org.apache.ace.client.repository.object.ArtifactObject;
 import org.apache.ace.client.repository.object.Distribution2TargetAssociation;
@@ -118,7 +119,7 @@ public interface Workspace {
      *             when the ObjectRepository this Workspace represents would throw this same exception
      */
     public RepositoryObject createRepositoryObject(String entityType, Map<String, String> attributes,
-            Map<String, String> tags) throws IllegalArgumentException;
+        Map<String, String> tags) throws IllegalArgumentException;
 
     /**
      * @param entityType
@@ -151,7 +152,7 @@ public interface Workspace {
      *            the tags of the RepositoryObject
      */
     public void updateRepositoryObject(String entityType, String entityId, Map<String, String> attributes,
-            Map<String, String> tags);
+        Map<String, String> tags);
 
     /**
      * Create an association of the specified between a left-hand side object and a right-hand side object with the
@@ -169,7 +170,7 @@ public interface Workspace {
      *            the cardinality of the right-hand side
      */
     public void createAssocation(String entityType, String leftEntityId, String rightEntityId, String leftCardinality,
-            String rightCardinality);
+        String rightCardinality);
 
     /**
      * Get the RepositoryObject that represents the left-hand side of the specified association.
@@ -219,10 +220,52 @@ public interface Workspace {
 
     public List<ArtifactObject> la(String filter) throws Exception;
 
+    /**
+     * Creates and optionally uploads an artifact from a given URL.
+     * <p>
+     * This method uses, in contrast to the other "ca" methods, all known {@link ArtifactHelper}s to import the given
+     * artifact and therefore will fail in case you try to upload an unrecognized artifact.
+     * </p>
+     * 
+     * @param url
+     *            the URL of the artifact to import & create;
+     * @param upload
+     *            <code>true</code> if the artifact should be uploaded to the OBR, <code>false</code> if it is already
+     *            in the OBR.
+     * @throws Exception
+     */
+    public void ca(String url, boolean upload) throws Exception;
+
+    /**
+     * Creates a new bundle artifact.
+     * 
+     * @param name
+     *            the name of the bundle artifact;
+     * @param url
+     *            the URL of the bundle artifact;
+     * @param bsn
+     *            the BSN of the bundle artifact;
+     * @param version
+     *            the version of the bundle artifact.
+     */
     public void ca(String name, String url, String bsn, String version);
 
+    /**
+     * Creates a new bundle artifact.
+     * 
+     * @param attrs
+     *            the attributes of the to-be-created artifact;
+     */
     public void ca(Map<String, String> attrs);
 
+    /**
+     * Creates a new artifact.
+     * 
+     * @param attrs
+     *            the attributes of the to-be-created artifact;
+     * @param tags
+     *            the tags of the to-be-created artifact.
+     */
     public void ca(Map<String, String> attrs, Map<String, String> tags);
 
     public void da(RepositoryObject repositoryObject);
@@ -327,10 +370,10 @@ public interface Workspace {
     /*** other/generic ***/
 
     public void cas(String entityType, String leftEntityId, String rightEntityId, String leftCardinality,
-            String rightCardinality);
+        String rightCardinality);
 
     public boolean isModified() throws IOException;
 
     public boolean isCurrent() throws IOException;
 
-}
\ No newline at end of file
+}

Modified: ace/trunk/org.apache.ace.client.workspace/src/org/apache/ace/client/workspace/impl/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.client.workspace/src/org/apache/ace/client/workspace/impl/WorkspaceImpl.java?rev=1572051&r1=1572050&r2=1572051&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.client.workspace/src/org/apache/ace/client/workspace/impl/WorkspaceImpl.java (original)
+++ ace/trunk/org.apache.ace.client.workspace/src/org/apache/ace/client/workspace/impl/WorkspaceImpl.java Wed Feb 26 13:57:40 2014
@@ -82,14 +82,14 @@ public class WorkspaceImpl implements Wo
     private volatile LogService m_log;
 
     public WorkspaceImpl(String sessionID, String repositoryURL, String customerName, String storeRepositoryName,
-            String distributionRepositoryName, String deploymentRepositoryName) throws MalformedURLException {
+        String distributionRepositoryName, String deploymentRepositoryName) throws MalformedURLException {
         this(sessionID, repositoryURL, customerName, storeRepositoryName, customerName, distributionRepositoryName,
-                customerName, deploymentRepositoryName);
+            customerName, deploymentRepositoryName);
     }
 
     public WorkspaceImpl(String sessionID, String repositoryURL, String storeCustomerName, String storeRepositoryName,
-            String distributionCustomerName, String distributionRepositoryName, String deploymentCustomerName,
-            String deploymentRepositoryName) throws MalformedURLException {
+        String distributionCustomerName, String distributionRepositoryName, String deploymentCustomerName,
+        String deploymentRepositoryName) throws MalformedURLException {
         m_sessionID = sessionID;
         m_repositoryURL = new URL(repositoryURL);
         m_storeCustomerName = storeCustomerName;
@@ -107,13 +107,13 @@ public class WorkspaceImpl implements Wo
 
     private void addSessionDependency(Component component, Class<?> service, boolean isRequired) {
         component.add(m_manager.createServiceDependency()
-                .setService(service, "(" + SessionFactory.SERVICE_SID + "=" + m_sessionID + ")")
-                .setRequired(isRequired).setInstanceBound(true));
+            .setService(service, "(" + SessionFactory.SERVICE_SID + "=" + m_sessionID + ")")
+            .setRequired(isRequired).setInstanceBound(true));
     }
 
     private void addDependency(Component component, Class<?> service, boolean isRequired) {
         component.add(m_manager.createServiceDependency().setService(service).setRequired(isRequired)
-                .setInstanceBound(true));
+            .setInstanceBound(true));
     }
 
     public void init(Component component) {
@@ -140,13 +140,13 @@ public class WorkspaceImpl implements Wo
             RepositoryAdminLoginContext context = m_repositoryAdmin.createLoginContext(user);
 
             context.add(
-                    context.createShopRepositoryContext().setLocation(m_repositoryURL).setCustomer(m_storeCustomerName)
-                            .setName(m_storeRepositoryName).setWriteable())
-                    .add(context.createTargetRepositoryContext().setLocation(m_repositoryURL)
-                            .setCustomer(m_distributionCustomerName).setName(m_distributionRepositoryName)
-                            .setWriteable())
-                    .add(context.createDeploymentRepositoryContext().setLocation(m_repositoryURL)
-                            .setCustomer(m_deploymentCustomerName).setName(m_deploymentRepositoryName).setWriteable());
+                context.createShopRepositoryContext().setLocation(m_repositoryURL).setCustomer(m_storeCustomerName)
+                    .setName(m_storeRepositoryName).setWriteable())
+                .add(context.createTargetRepositoryContext().setLocation(m_repositoryURL)
+                    .setCustomer(m_distributionCustomerName).setName(m_distributionRepositoryName)
+                    .setWriteable())
+                .add(context.createDeploymentRepositoryContext().setLocation(m_repositoryURL)
+                    .setCustomer(m_deploymentCustomerName).setName(m_deploymentRepositoryName).setWriteable());
 
             m_repositoryAdmin.login(context);
             m_repositoryAdmin.checkout();
@@ -154,7 +154,7 @@ public class WorkspaceImpl implements Wo
         catch (IOException e) {
             e.printStackTrace();
             m_log.log(LogService.LOG_ERROR,
-                    "Could not login and checkout. Workspace will probably not work correctly.", e);
+                "Could not login and checkout. Workspace will probably not work correctly.", e);
             return false;
         }
 
@@ -195,7 +195,7 @@ public class WorkspaceImpl implements Wo
 
     @Override
     public RepositoryObject createRepositoryObject(String entityType, Map<String, String> attributes,
-            Map<String, String> tags) throws IllegalArgumentException {
+        Map<String, String> tags) throws IllegalArgumentException {
         if (TARGET.equals(entityType)) {
             ObjectRepository<StatefulTargetObject> repo = getGenericObjectRepository(TARGET);
             StatefulTargetRepository statefulRepo = (StatefulTargetRepository) repo;
@@ -212,7 +212,7 @@ public class WorkspaceImpl implements Wo
     // be integrated given the current API.
     private void prepareAssociationAttributes(String entityType, Map<String, String> attributes) {
         if (ARTIFACT2FEATURE.equals(entityType) || FEATURE2DISTRIBUTION.equals(entityType)
-                || DISTRIBUTION2TARGET.equals(entityType)) {
+            || DISTRIBUTION2TARGET.equals(entityType)) {
 
             String leftAttribute = attributes.get("left");
             String rightAttribute = attributes.get("right");
@@ -231,7 +231,7 @@ public class WorkspaceImpl implements Wo
                 if (left instanceof StatefulTargetObject) {
                     if (((StatefulTargetObject) left).isRegistered()) {
                         attributes.put(Association.LEFT_ENDPOINT, ((StatefulTargetObject) left).getTargetObject()
-                                .getAssociationFilter(attributes));
+                            .getAssociationFilter(attributes));
                     }
                 }
                 else {
@@ -242,7 +242,7 @@ public class WorkspaceImpl implements Wo
                 if (right instanceof StatefulTargetObject) {
                     if (((StatefulTargetObject) right).isRegistered()) {
                         attributes.put(Association.RIGHT_ENDPOINT, ((StatefulTargetObject) right).getTargetObject()
-                                .getAssociationFilter(attributes));
+                            .getAssociationFilter(attributes));
                     }
                 }
                 else {
@@ -254,7 +254,7 @@ public class WorkspaceImpl implements Wo
 
     @Override
     public void updateRepositoryObject(String entityType, String entityId, Map<String, String> attributes,
-            Map<String, String> tags) {
+        Map<String, String> tags) {
         RepositoryObject repositoryObject = getRepositoryObject(entityType, entityId);
         // first handle the attributes
         for (Entry<String, String> attribute : attributes.entrySet()) {
@@ -300,7 +300,7 @@ public class WorkspaceImpl implements Wo
     // can't be integrated given the current API.
     private void updateAssociationAttributes(String entityType, RepositoryObject repositoryObject) {
         if (ARTIFACT2FEATURE.equals(entityType) || FEATURE2DISTRIBUTION.equals(entityType)
-                || DISTRIBUTION2TARGET.equals(entityType)) {
+            || DISTRIBUTION2TARGET.equals(entityType)) {
             String leftAttribute = repositoryObject.getAttribute("left");
             String rightAttribute = repositoryObject.getAttribute("right");
 
@@ -318,28 +318,28 @@ public class WorkspaceImpl implements Wo
                 if (left instanceof StatefulTargetObject) {
                     if (((StatefulTargetObject) left).isRegistered()) {
                         repositoryObject.addAttribute(
-                                Association.LEFT_ENDPOINT,
-                                ((StatefulTargetObject) left).getTargetObject().getAssociationFilter(
-                                        getAttributes(((StatefulTargetObject) left).getTargetObject())));
+                            Association.LEFT_ENDPOINT,
+                            ((StatefulTargetObject) left).getTargetObject().getAssociationFilter(
+                                getAttributes(((StatefulTargetObject) left).getTargetObject())));
                     }
                 }
                 else {
                     repositoryObject.addAttribute(Association.LEFT_ENDPOINT,
-                            left.getAssociationFilter(getAttributes(left)));
+                        left.getAssociationFilter(getAttributes(left)));
                 }
             }
             if (right != null) {
                 if (right instanceof StatefulTargetObject) {
                     if (((StatefulTargetObject) right).isRegistered()) {
                         repositoryObject.addAttribute(
-                                Association.RIGHT_ENDPOINT,
-                                ((StatefulTargetObject) right).getTargetObject().getAssociationFilter(
-                                        getAttributes(((StatefulTargetObject) right).getTargetObject())));
+                            Association.RIGHT_ENDPOINT,
+                            ((StatefulTargetObject) right).getTargetObject().getAssociationFilter(
+                                getAttributes(((StatefulTargetObject) right).getTargetObject())));
                     }
                 }
                 else {
                     repositoryObject.addAttribute(Association.RIGHT_ENDPOINT,
-                            right.getAssociationFilter(getAttributes(right)));
+                        right.getAssociationFilter(getAttributes(right)));
                 }
             }
         }
@@ -356,7 +356,7 @@ public class WorkspaceImpl implements Wo
 
     @Override
     public void createAssocation(String entityType, String leftEntityId, String rightEntityId, String leftCardinality,
-            String rightCardinality) {
+        String rightCardinality) {
         Map<String, String> attrs = new HashMap<String, String>();
         Map<String, String> tags = new HashMap<String, String>();
         attrs.put(Association.LEFT_ENDPOINT, leftEntityId);
@@ -484,6 +484,11 @@ public class WorkspaceImpl implements Wo
     }
 
     @Override
+    public void ca(String url, boolean upload) throws Exception {
+        m_artifactRepository.importArtifact(new URL(url), upload);
+    }
+
+    @Override
     public void ca(String name, String url, String bsn, String version) {
         Map<String, String> attrs = new HashMap<String, String>();
         attrs.put(ArtifactObject.KEY_ARTIFACT_NAME, name);
@@ -713,7 +718,7 @@ public class WorkspaceImpl implements Wo
 
     @Override
     public void cas(String entityType, String leftEntityId, String rightEntityId, String leftCardinality,
-            String rightCardinality) {
+        String rightCardinality) {
         createAssocation(entityType, leftEntityId, rightEntityId, leftCardinality, rightCardinality);
     }