diff --git a/config/alfresco/action-services-context.xml b/config/alfresco/action-services-context.xml index fdc46bdd75..d7a8fe6f13 100644 --- a/config/alfresco/action-services-context.xml +++ b/config/alfresco/action-services-context.xml @@ -394,4 +394,16 @@ + + + + + + + + + false + + + diff --git a/config/alfresco/messages/action-config.properties b/config/alfresco/messages/action-config.properties index 5e796af107..84c4e57c15 100644 --- a/config/alfresco/messages/action-config.properties +++ b/config/alfresco/messages/action-config.properties @@ -84,3 +84,9 @@ execute-all-rules.description=Execute all rules on the child items. start-workflow.title=Start Workflow start-workflow.description=This will start a workflow for the matched items. + +# WCM Actions + +simple-avm-submit.title=Simple Direct Submit +simple-avm-submit.description=This will submit any newer nodes in the matched item to the corresponding staging. + diff --git a/source/java/org/alfresco/repo/avm/AVMServiceTest.java b/source/java/org/alfresco/repo/avm/AVMServiceTest.java index 1134ca73d5..ed7edf801b 100644 --- a/source/java/org/alfresco/repo/avm/AVMServiceTest.java +++ b/source/java/org/alfresco/repo/avm/AVMServiceTest.java @@ -31,6 +31,8 @@ import java.util.Set; import java.util.TreeMap; import org.alfresco.model.ContentModel; +import org.alfresco.repo.action.ActionImpl; +import org.alfresco.repo.avm.actions.SimpleAVMSubmitAction; import org.alfresco.repo.avm.util.BulkLoader; import org.alfresco.repo.domain.PropertyValue; import org.alfresco.repo.security.authentication.AuthenticationComponent; @@ -59,6 +61,53 @@ import org.alfresco.service.transaction.TransactionService; */ public class AVMServiceTest extends AVMServiceTestBase { + /** + * Test the SimpleAVMSubmitAction. + */ + public void testSubmitAction() + { + try + { + fService.createAVMStore("foo-staging"); + fService.createDirectory("foo-staging:/", "layer"); + fService.createDirectory("foo-staging:/layer", "a"); + fService.createDirectory("foo-staging:/layer/a","b"); + fService.createDirectory("foo-staging:/layer/a/b", "c"); + fService.createFile("foo-staging:/layer/a/b/c", "foo").close(); + fService.createFile("foo-staging:/layer/a/b/c", "bar").close(); + fService.createAVMStore("area"); + fService.setStoreProperty("area", QName.createQName(null, ".website.name"), + new PropertyValue(null, "foo")); + fService.createLayeredDirectory("foo-staging:/layer", "area:/", "layer"); + fService.createFile("area:/layer", "figs").close(); + fService.getFileOutputStream("area:/layer/a/b/c/foo").close(); + fService.removeNode("area:/layer/a/b/c/bar"); + List diffs = + fSyncService.compare(-1, "area:/layer", -1, "foo-staging:/layer"); + assertEquals(3, diffs.size()); + final SimpleAVMSubmitAction action = (SimpleAVMSubmitAction)fContext.getBean("simple-avm-submit"); + class TxnWork implements TransactionUtil.TransactionWork + { + public Object doWork() throws Exception + { + action.execute(null, AVMNodeConverter.ToNodeRef(-1, "area:/layer")); + return null; + } + }; + TxnWork worker = new TxnWork(); + TransactionUtil.executeInUserTransaction((TransactionService)fContext.getBean("transactionComponent"), + worker); + diffs = + fSyncService.compare(-1, "area:/layer", -1, "foo-staging:/layer"); + assertEquals(0, diffs.size()); + } + catch (Exception e) + { + e.printStackTrace(System.err); + fail(); + } + } + /** * Test one argument remove. */ diff --git a/source/java/org/alfresco/repo/avm/actions/SimpleAVMSubmitAction.java b/source/java/org/alfresco/repo/avm/actions/SimpleAVMSubmitAction.java new file mode 100644 index 0000000000..c4e1dfe656 --- /dev/null +++ b/source/java/org/alfresco/repo/avm/actions/SimpleAVMSubmitAction.java @@ -0,0 +1,126 @@ +/* + * Copyright (C) 2006 Alfresco, Inc. + * + * Licensed under the Mozilla Public License version 1.1 + * with a permitted attribution clause. You may obtain a + * copy of the License at + * + * http://www.alfresco.org/legal/license.txt + * + * 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.alfresco.repo.avm.actions; + +import java.util.List; + +import org.alfresco.repo.action.executer.ActionExecuterAbstractBase; +import org.alfresco.repo.avm.AVMNodeConverter; +import org.alfresco.repo.domain.PropertyValue; +import org.alfresco.service.cmr.action.Action; +import org.alfresco.service.cmr.action.ParameterDefinition; +import org.alfresco.service.cmr.avm.AVMService; +import org.alfresco.service.cmr.avmsync.AVMDifference; +import org.alfresco.service.cmr.avmsync.AVMSyncService; +import org.alfresco.service.cmr.repository.NodeRef; +import org.alfresco.service.namespace.QName; +import org.apache.log4j.Logger; + +/** + * This action submits all the newer changes in the passed in NodeRef + * to its corresponding staging area. It ignores conflicts and older nodes. + * @author britt + */ +public class SimpleAVMSubmitAction extends ActionExecuterAbstractBase +{ + private static Logger fgLogger = Logger.getLogger(SimpleAVMSubmitAction.class); + + public static String NAME = "simple-avm-submit"; + + /** + * The AVMService instance. + */ + private AVMService fAVMService; + + /** + * The AVMSyncService instance. + */ + private AVMSyncService fAVMSyncService; + + /** + * Default constructor. + */ + public SimpleAVMSubmitAction() + { + super(); + } + + /** + * Set the AVMService. + * @param avmService The instance. + */ + public void setAvmService(AVMService avmService) + { + fAVMService = avmService; + } + + /** + * Set the AVMSyncService. + * @param avmSyncService The instance. + */ + public void setAvmSyncService(AVMSyncService avmSyncService) + { + fAVMSyncService = avmSyncService; + } + + /** + * Perform the action. The NodeRef must be an AVM NodeRef. + * @param action Don't actually need anything from this here. + * @param actionedUponNodeRef The AVM NodeRef. + */ + @Override + protected void executeImpl(Action action, NodeRef actionedUponNodeRef) + { + // Crack the NodeRef. + Object [] avmVersionPath = AVMNodeConverter.ToAVMVersionPath(actionedUponNodeRef); + int version = (Integer)avmVersionPath[0]; + String path = (String)avmVersionPath[1]; + // Get store name and path parts. + String [] storePath = path.split(":"); + // Get the .website.name property. + PropertyValue wsProp = + fAVMService.getStoreProperty(storePath[0], + QName.createQName(null, ".website.name")); + if (wsProp == null) + { + fgLogger.warn(".website.name property not found."); + return; + } + // And the actual web-site name. + String websiteName = wsProp.getStringValue(); + // Construct the submit destination path. + String avmDest = websiteName + "-staging:" + storePath[1]; + // Get the difference between source and destination. + List diffs = + fAVMSyncService.compare(version, path, -1, avmDest); + // Do the update. + fAVMSyncService.update(diffs, true, true, false, false); + // Cleanup by flattening the source relative to the destination. + fAVMSyncService.flatten(path, avmDest); + } + + /** + * This action takes no parameters. + * @param paramList The List to add nothing to. + */ + @Override + protected void addParameterDefinitions(List paramList) + { + // No parameters for this action. + } +}