mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
TransferService:
No-Op implementation of script transfer service. TransferService interface rework for createTransferTarget git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@19163 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -221,4 +221,12 @@
|
||||
</property>
|
||||
<property name="serviceRegistry" ref="ServiceRegistry" />
|
||||
</bean>
|
||||
|
||||
<bean id="transferServiceScript" parent="baseJavaScriptExtension" class="org.alfresco.repo.transfer.script.ScriptTransferService">
|
||||
<property name="extensionName">
|
||||
<value>transfer</value>
|
||||
</property>
|
||||
<property name="transferService" ref="TransferService"/>
|
||||
</bean>
|
||||
|
||||
</beans>
|
||||
|
@@ -122,33 +122,66 @@ 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)
|
||||
public TransferTarget createTransferTarget(String name)
|
||||
{
|
||||
/**
|
||||
* Check whether name is already used
|
||||
*/
|
||||
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<QName, Serializable> properties = new HashMap<QName, Serializable>();
|
||||
|
||||
// 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);
|
||||
@@ -156,22 +189,26 @@ public class TransferServiceImpl implements TransferService
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -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<TransferTarget> 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<TransferTarget> 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;
|
||||
}
|
||||
|
||||
|
@@ -139,8 +139,15 @@ public class TransferTargetImpl implements TransferTarget
|
||||
return false;
|
||||
}
|
||||
TransferTargetImpl that = (TransferTargetImpl) obj;
|
||||
if(this.getNodeRef() == null)
|
||||
{
|
||||
return (this.getName().equals(that.getName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
return (this.getNodeRef().equals(that.getNodeRef()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see #getNodeRef()
|
||||
@@ -148,6 +155,10 @@ public class TransferTargetImpl implements TransferTarget
|
||||
*/
|
||||
public int hashCode()
|
||||
{
|
||||
if(nodeRef == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return getNodeRef().hashCode();
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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;
|
||||
|
||||
|
@@ -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;
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Provides the JavaScript implementation of the transfer service.
|
||||
* @since 3.3
|
||||
*/
|
||||
package org.alfresco.repo.transfer.script;
|
@@ -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();
|
@@ -115,7 +115,8 @@ public interface TransferService
|
||||
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.
|
||||
* <ul>
|
||||
* <li>title</li>
|
||||
* <li>description</li>
|
||||
* <li>endpointProtocol</li>
|
||||
* <li>endpointHost</li>
|
||||
* <li>endpointPort</li>
|
||||
* <li>endpointPath</li>
|
||||
* <li>username</li>
|
||||
* <li>password</li>
|
||||
* </ul>
|
||||
* @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
|
||||
|
Reference in New Issue
Block a user