diff --git a/config/alfresco/transfer-service-context.xml b/config/alfresco/transfer-service-context.xml
index 27b79398a6..dc34a3996a 100644
--- a/config/alfresco/transfer-service-context.xml
+++ b/config/alfresco/transfer-service-context.xml
@@ -221,4 +221,12 @@
+
+
+
+ transfer
+
+
+
+
diff --git a/source/java/org/alfresco/repo/transfer/TransferServiceImpl.java b/source/java/org/alfresco/repo/transfer/TransferServiceImpl.java
index 16522684eb..4e2017d0a9 100644
--- a/source/java/org/alfresco/repo/transfer/TransferServiceImpl.java
+++ b/source/java/org/alfresco/repo/transfer/TransferServiceImpl.java
@@ -122,56 +122,93 @@ public class TransferServiceImpl implements TransferService
private long commitPollDelay = 2000;
/**
- * create transfer target
+ * Create a new in memory transfer target
*/
- public TransferTarget createTransferTarget(String name, String title, String description, String endpointProtocol, String endpointHost, int endpointPort, String endpointPath, String username, char[] password)
- {
- /**
- * Check whether name is already used
- */
+ public TransferTarget createTransferTarget(String name)
+ {
NodeRef dummy = lookupTransferTarget(name);
if(dummy != null)
{
throw new TransferException(MSG_TARGET_EXISTS, new Object[]{name} );
}
+ TransferTargetImpl newTarget = new TransferTargetImpl();
+ newTarget.setName(name);
+ return newTarget;
+ }
+
+ /**
+ * create transfer target
+ */
+ public TransferTarget createAndSaveTransferTarget(String name, String title, String description, String endpointProtocol, String endpointHost, int endpointPort, String endpointPath, String username, char[] password)
+ {
+ TransferTargetImpl newTarget = new TransferTargetImpl();
+ newTarget.setName(name);
+ newTarget.setTitle(title);
+ newTarget.setDescription(description);
+ newTarget.setEndpointProtocol(endpointProtocol);
+ newTarget.setEndpointHost(endpointHost);
+ newTarget.setEndpointPort(endpointPort);
+ newTarget.setEndpointPath(endpointPath);
+ newTarget.setUsername(username);
+ newTarget.setPassword(password);
+ return createTransferTarget(newTarget);
+
+ }
+
+ /**
+ * create transfer target
+ */
+ private TransferTarget createTransferTarget(TransferTarget newTarget)
+ {
+ /**
+ * Check whether name is already used
+ */
+ NodeRef dummy = lookupTransferTarget(newTarget.getName());
+ if (dummy != null) { throw new TransferException(MSG_TARGET_EXISTS,
+ new Object[] { newTarget.getName() }); }
+
Map properties = new HashMap();
-
+
// type properties
- properties.put(TransferModel.PROP_ENDPOINT_HOST, endpointHost);
- properties.put(TransferModel.PROP_ENDPOINT_PORT, endpointPort);
- properties.put(TransferModel.PROP_ENDPOINT_PROTOCOL, endpointProtocol);
- properties.put(TransferModel.PROP_ENDPOINT_PATH, endpointPath);
- properties.put(TransferModel.PROP_USERNAME, username);
- properties.put(TransferModel.PROP_PASSWORD, encrypt(password));
-
+ properties.put(TransferModel.PROP_ENDPOINT_HOST, newTarget.getEndpointHost());
+ properties.put(TransferModel.PROP_ENDPOINT_PORT, newTarget.getEndpointPort());
+ properties.put(TransferModel.PROP_ENDPOINT_PROTOCOL, newTarget.getEndpointProtocol());
+ properties.put(TransferModel.PROP_ENDPOINT_PATH, newTarget.getEndpointPath());
+ properties.put(TransferModel.PROP_USERNAME, newTarget.getUsername());
+ properties.put(TransferModel.PROP_PASSWORD, encrypt(newTarget.getPassword()));
+
// titled aspect
- properties.put(ContentModel.PROP_TITLE, title);
- properties.put(ContentModel.PROP_NAME, name);
- properties.put(ContentModel.PROP_DESCRIPTION, description);
-
+ properties.put(ContentModel.PROP_TITLE, newTarget.getTitle());
+ properties.put(ContentModel.PROP_NAME, newTarget.getName());
+ properties.put(ContentModel.PROP_DESCRIPTION, newTarget.getDescription());
+
// enableable aspect
properties.put(TransferModel.PROP_ENABLED, Boolean.TRUE);
-
+
NodeRef home = getTransferHome();
-
+
/**
- * Work out which group the transfer target is for, in this case the default group.
+ * Work out which group the transfer target is for, in this case the
+ * default group.
*/
- NodeRef defaultGroup = nodeService.getChildByName(home, ContentModel.ASSOC_CONTAINS, defaultTransferGroup);
-
+ NodeRef defaultGroup = nodeService.getChildByName(home, ContentModel.ASSOC_CONTAINS,
+ defaultTransferGroup);
+
/**
* Go ahead and create the new node
*/
- ChildAssociationRef ref = nodeService.createNode(defaultGroup, ContentModel.ASSOC_CONTAINS, QName.createQName(TransferModel.TRANSFER_MODEL_1_0_URI, name), TransferModel.TYPE_TRANSFER_TARGET, properties);
-
+ ChildAssociationRef ref = nodeService.createNode(defaultGroup, ContentModel.ASSOC_CONTAINS,
+ QName.createQName(TransferModel.TRANSFER_MODEL_1_0_URI, newTarget.getName()),
+ TransferModel.TYPE_TRANSFER_TARGET, properties);
+
/**
* Now create a new TransferTarget object to return to the caller.
*/
- TransferTargetImpl newTarget = new TransferTargetImpl();
- mapTransferTarget(ref.getChildRef(), newTarget);
+ TransferTargetImpl retVal = new TransferTargetImpl();
+ mapTransferTarget(ref.getChildRef(), retVal);
- return newTarget;
+ return retVal;
}
/**
@@ -289,10 +326,16 @@ public class TransferServiceImpl implements TransferService
}
/**
- *
+ * create or update a transfer target.
*/
- public TransferTarget updateTransferTarget(TransferTarget update)
- {
+ public TransferTarget saveTransferTarget(TransferTarget update)
+ {
+ if(update.getNodeRef() == null)
+ {
+ // This is a save for the first time
+ return createTransferTarget(update);
+ }
+
NodeRef nodeRef = lookupTransferTarget(update.getName());
if(nodeRef == null)
{
@@ -1066,4 +1109,6 @@ public class TransferServiceImpl implements TransferService
String transferId;
boolean cancelMe = false;
}
+
+
}
diff --git a/source/java/org/alfresco/repo/transfer/TransferServiceImplTest.java b/source/java/org/alfresco/repo/transfer/TransferServiceImplTest.java
index 1a235d2f96..f1c41deb69 100644
--- a/source/java/org/alfresco/repo/transfer/TransferServiceImplTest.java
+++ b/source/java/org/alfresco/repo/transfer/TransferServiceImplTest.java
@@ -148,7 +148,7 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest
/**
* Now go ahead and create our first transfer target
*/
- TransferTarget ret = transferService.createTransferTarget(name, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
+ TransferTarget ret = transferService.createAndSaveTransferTarget(name, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
assertNotNull("return value is null", ret);
assertNotNull("node ref is null", ret.getNodeRef());
@@ -181,7 +181,88 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest
/**
* Negative test - try to create a transfer target with a name that's already used.
*/
- transferService.createTransferTarget(name, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
+ transferService.createAndSaveTransferTarget(name, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
+ fail("duplicate name not detected");
+ }
+ catch (TransferException e)
+ {
+ // expect to go here
+ }
+ finally
+ {
+ endTransaction();
+ }
+ }
+
+ /**
+ * Test create target via in memory data object.
+ *
+ * @throws Exception
+ */
+ public void testCreateTargetSyntax2() throws Exception
+ {
+ String name = "nameSyntax2";
+ String title = "title";
+ String description = "description";
+ String endpointProtocol = "http";
+ String endpointHost = "localhost";
+ int endpointPort = 8080;
+ String endpointPath = "rhubarb";
+ String username = "admin";
+ char[] password = "password".toCharArray();
+
+
+ startNewTransaction();
+ try
+ {
+ /**
+ * Now go ahead and create our first transfer target
+ */
+ TransferTarget newValue = transferService.createTransferTarget(name);
+ newValue.setDescription(description);
+ newValue.setEndpointHost(endpointHost);
+ newValue.setEndpointPort(endpointPort);
+ newValue.setEndpointPath(endpointPath);
+ newValue.setEndpointProtocol(endpointProtocol);
+ newValue.setPassword(password);
+ newValue.setTitle(title);
+ newValue.setUsername(username);
+
+ TransferTarget ret = transferService.saveTransferTarget(newValue);
+
+ assertNotNull("return value is null", ret);
+ assertNotNull("node ref is null", ret.getNodeRef());
+
+ //titled aspect
+ assertEquals("name not equal", ret.getName(), name);
+ assertEquals("title not equal", ret.getTitle(), title);
+ assertEquals("description not equal", ret.getDescription(), description);
+
+ // endpoint
+ assertEquals("endpointProtocol not equal", ret.getEndpointProtocol(), endpointProtocol);
+ assertEquals("endpointHost not equal", ret.getEndpointHost(), endpointHost);
+ assertEquals("endpointPort not equal", ret.getEndpointPort(), endpointPort);
+ assertEquals("endpointPath not equal", ret.getEndpointPath(), endpointPath);
+
+ // authentication
+ assertEquals("username not equal", ret.getUsername(), username);
+ char[] password2 = ret.getPassword();
+
+ assertEquals(password.length, password2.length);
+
+ for(int i = 0; i < password.length; i++)
+ {
+ if(password[i] != password2[i])
+ {
+ fail("password not equal:" + new String(password) + new String(password2));
+ }
+ }
+
+
+ /**
+ * Negative test - try to create a transfer target with a name that's already used.
+ */
+ transferService.createAndSaveTransferTarget(name, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
fail("duplicate name not detected");
}
catch (TransferException e)
@@ -218,8 +299,8 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest
/**
* Now go ahead and create our first transfer target
*/
- TransferTarget targetA = transferService.createTransferTarget(nameA, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
- TransferTarget targetB = transferService.createTransferTarget(nameB, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
+ TransferTarget targetA = transferService.createAndSaveTransferTarget(nameA, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
+ TransferTarget targetB = transferService.createAndSaveTransferTarget(nameB, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
Set targets = transferService.getTransferTargets();
assertTrue("targets is empty", targets.size() > 0);
@@ -258,7 +339,7 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest
/**
* Now go ahead and create our first transfer target
*/
- transferService.createTransferTarget(getMe, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
+ transferService.createAndSaveTransferTarget(getMe, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
Set targets = transferService.getTransferTargets("Default Group");
assertTrue("targets is empty", targets.size() > 0);
@@ -301,12 +382,12 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest
/**
* Create our transfer target
*/
- TransferTarget target = transferService.createTransferTarget(updateMe, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
+ TransferTarget target = transferService.createAndSaveTransferTarget(updateMe, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
/*
* Now update with exactly the same values.
*/
- TransferTarget update1 = transferService.updateTransferTarget(target);
+ TransferTarget update1 = transferService.saveTransferTarget(target);
assertNotNull("return value is null", update1);
assertNotNull("node ref is null", update1.getNodeRef());
@@ -357,7 +438,7 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest
target.setPassword(password2);
target.setUsername(username2);
- TransferTarget update2 = transferService.updateTransferTarget(target);
+ TransferTarget update2 = transferService.saveTransferTarget(target);
assertNotNull("return value is null", update2);
assertNotNull("node ref is null", update2.getNodeRef());
@@ -413,7 +494,7 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest
/**
* Now go ahead and create our first transfer target
*/
- transferService.createTransferTarget(deleteMe, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
+ transferService.createAndSaveTransferTarget(deleteMe, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
transferService.deleteTransferTarget(deleteMe);
@@ -1808,7 +1889,7 @@ public class TransferServiceImplTest extends BaseAlfrescoSpringTest
/**
* Now go ahead and create our first transfer target
*/
- TransferTarget target = transferService.createTransferTarget(name, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
+ TransferTarget target = transferService.createAndSaveTransferTarget(name, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
return target;
}
diff --git a/source/java/org/alfresco/repo/transfer/TransferTargetImpl.java b/source/java/org/alfresco/repo/transfer/TransferTargetImpl.java
index efeed02a29..800e7e719b 100644
--- a/source/java/org/alfresco/repo/transfer/TransferTargetImpl.java
+++ b/source/java/org/alfresco/repo/transfer/TransferTargetImpl.java
@@ -139,7 +139,14 @@ public class TransferTargetImpl implements TransferTarget
return false;
}
TransferTargetImpl that = (TransferTargetImpl) obj;
- return (this.getNodeRef().equals(that.getNodeRef()));
+ if(this.getNodeRef() == null)
+ {
+ return (this.getName().equals(that.getName()));
+ }
+ else
+ {
+ return (this.getNodeRef().equals(that.getNodeRef()));
+ }
}
/**
@@ -148,6 +155,10 @@ public class TransferTargetImpl implements TransferTarget
*/
public int hashCode()
{
+ if(nodeRef == null)
+ {
+ return 0;
+ }
return getNodeRef().hashCode();
}
diff --git a/source/java/org/alfresco/repo/transfer/TransferTestUtil.java b/source/java/org/alfresco/repo/transfer/TransferTestUtil.java
index fd69c736e5..08cd64dc7c 100644
--- a/source/java/org/alfresco/repo/transfer/TransferTestUtil.java
+++ b/source/java/org/alfresco/repo/transfer/TransferTestUtil.java
@@ -35,7 +35,7 @@ public class TransferTestUtil
TransferTarget target;
if (!transferService.targetExists(TEST_TARGET_NAME))
{
- target = transferService.createTransferTarget(TEST_TARGET_NAME, "Test Target", "Test Target", "http",
+ target = transferService.createAndSaveTransferTarget(TEST_TARGET_NAME, "Test Target", "Test Target", "http",
"localhost", 8090, "/alfresco/service/api/transfer", "admin", "admin".toCharArray());
}
else
diff --git a/source/java/org/alfresco/repo/transfer/manifest/ManifestIntegrationTest.java b/source/java/org/alfresco/repo/transfer/manifest/ManifestIntegrationTest.java
index e9d2ce30d1..aab3ad42ea 100644
--- a/source/java/org/alfresco/repo/transfer/manifest/ManifestIntegrationTest.java
+++ b/source/java/org/alfresco/repo/transfer/manifest/ManifestIntegrationTest.java
@@ -101,7 +101,7 @@ public class ManifestIntegrationTest extends BaseAlfrescoSpringTest
/**
* Create our transfer target
*/
- TransferTarget target = transferService.createTransferTarget(snapshotMe, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
+ TransferTarget target = transferService.createAndSaveTransferTarget(snapshotMe, title, description, endpointProtocol, endpointHost, endpointPort, endpointPath, username, password);
File snapshotFile = null;
diff --git a/source/java/org/alfresco/repo/transfer/script/ScriptTransferService.java b/source/java/org/alfresco/repo/transfer/script/ScriptTransferService.java
new file mode 100644
index 0000000000..26c89656bc
--- /dev/null
+++ b/source/java/org/alfresco/repo/transfer/script/ScriptTransferService.java
@@ -0,0 +1,52 @@
+package org.alfresco.repo.transfer.script;
+
+import org.alfresco.repo.jscript.BaseScopableProcessorExtension;
+import org.alfresco.service.cmr.repository.NodeRef;
+import org.alfresco.service.cmr.transfer.TransferService;
+import org.mozilla.javascript.NativeArray;
+import org.mozilla.javascript.Scriptable;
+
+/**
+ * Java Script Transfer Service. Adapts the Java Transfer Service to
+ * Java Script.
+ *
+ * @author Mark Rogers
+ */
+public class ScriptTransferService extends BaseScopableProcessorExtension
+{
+ private TransferService transferService;
+
+ /**
+ * @param transferService
+ */
+ public void setTransferService(TransferService transferService)
+ {
+ this.transferService = transferService;
+ }
+
+ /**
+ *
+ * @return
+ */
+ public TransferService getTransferService()
+ {
+ return transferService;
+ }
+
+ /**
+ * create a transfer target
+ */
+
+ /**
+ * Transfer a set of nodes, with no callback
+ * @param targetName
+ * @param nodes
+ *
+ * @return node ref of transfer report.
+ */
+ public NodeRef transfer(String targetName, Scriptable nodes)
+ {
+ return null;
+ }
+
+}
diff --git a/source/java/org/alfresco/repo/transfer/script/package-info.java b/source/java/org/alfresco/repo/transfer/script/package-info.java
new file mode 100644
index 0000000000..49d3d53f76
--- /dev/null
+++ b/source/java/org/alfresco/repo/transfer/script/package-info.java
@@ -0,0 +1,5 @@
+/**
+ * Provides the JavaScript implementation of the transfer service.
+ * @since 3.3
+ */
+package org.alfresco.repo.transfer.script;
diff --git a/source/java/org/alfresco/repo/transfer/script/test_transferService.js b/source/java/org/alfresco/repo/transfer/script/test_transferService.js
new file mode 100644
index 0000000000..a5e35a57a9
--- /dev/null
+++ b/source/java/org/alfresco/repo/transfer/script/test_transferService.js
@@ -0,0 +1,10 @@
+function testTransferService()
+{
+
+ test.assertNotNull(transfer, "RootScoped object not found :transfer: ");
+
+ //test.assertNotNull(transfer, "Form should have been found for: " + testDoc);
+}
+
+// Execute test's
+testTransferService();
\ No newline at end of file
diff --git a/source/java/org/alfresco/service/cmr/transfer/TransferService.java b/source/java/org/alfresco/service/cmr/transfer/TransferService.java
index fe4e7f04db..dfcb528c9e 100644
--- a/source/java/org/alfresco/service/cmr/transfer/TransferService.java
+++ b/source/java/org/alfresco/service/cmr/transfer/TransferService.java
@@ -106,16 +106,17 @@ public interface TransferService
*
* @throws TransferException
*/
- public void transferAsync(String targetName, TransferDefinition definition, TransferCallback... callbacks) throws TransferException;
+ public void transferAsync(String targetName, TransferDefinition definition, TransferCallback... callbacks) throws TransferException;
- /**
- * Verify a target is available and that the configured credentials correctly identify an admin user.
- * @throws TransferException
- */
- public void verify(TransferTarget target) throws TransferException;
+ /**
+ * Verify a target is available and that the configured credentials correctly identify an admin user.
+ * @throws TransferException
+ */
+ public void verify(TransferTarget target) throws TransferException;
/**
- * crate a new transfer target
+ * Create and save a new transfer target. Creates and saves a new transfer target with a single, but long, method call.
+ *
* @param name, the name of this transfer target, which must be unique
* @param title, the display name of this transfer target
* @param description,
@@ -125,8 +126,26 @@ public interface TransferService
* @param endpointPath,
* @param username,
* @param password,
+ * @return the newly create transfer target.
*/
- public TransferTarget createTransferTarget(String name, String title, String description, String endpointProtocol, String endpointHost, int endpointPort, String endpointPath, String username, char[] password) throws TransferException;
+ public TransferTarget createAndSaveTransferTarget(String name, String title, String description, String endpointProtocol, String endpointHost, int endpointPort, String endpointPath, String username, char[] password) throws TransferException;
+
+ /**
+ * Creates an in memory transfer target. Before it is used it must be populated with the following values and
+ * saved with the saveTransferTarget method. The name of the transfer target must be unique.
+ *
+ * - title
+ * - description
+ * - endpointProtocol
+ * - endpointHost
+ * - endpointPort
+ * - endpointPath
+ * - username
+ * - password
+ *
+ * @return an in memory transfer target
+ */
+ public TransferTarget createTransferTarget(String name);
/**
* Get all the transfer targets
@@ -160,7 +179,8 @@ public interface TransferService
public void deleteTransferTarget(String name) throws TransferException;
/**
- * Update TransferTarget
+ * Save TransferTarget, will create a transfer target if it does not already exist or update an existing transfer target.
+ *
* The following properties may be updated:
* endpointHost,
* endpointPort,
@@ -177,7 +197,7 @@ public interface TransferService
*
* @param update
*/
- public TransferTarget updateTransferTarget(TransferTarget update) throws TransferException;
+ public TransferTarget saveTransferTarget(TransferTarget update) throws TransferException;
/**
* Enables/Disables the named transfer target