. Added action called 'counter' to increment the 'cm:counter' property on the 'cm:countable' aspect

- uses the runtime NodeService so any user can increment the counter on a node
. Renamed incorrectly spelt script action class (doh)

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@3626 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2006-08-29 16:36:10 +00:00
parent 297a7dec6e
commit 0c85451dc5
6 changed files with 113 additions and 6 deletions

View File

@@ -77,6 +77,7 @@ public interface ContentModel
static final QName PROP_SYS_VERSION_SCHEMA = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "versionSchema");
static final QName PROP_SYS_VERSION_EDITION = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "versionEdition");
//
// Content Model Definitions
//
@@ -184,6 +185,12 @@ public interface ContentModel
public static final QName PROP_ADDRESSEES = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "addressees");
public static final QName PROP_SUBJECT = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "subjectline");
// countable aspect
public static final QName ASPECT_COUNTABLE = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "countable");
public static final QName PROP_HITS = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "hits");
public static final QName PROP_COUNTER = QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, "counter");
//
// Application Model Definitions
//

View File

@@ -0,0 +1,84 @@
/*
* Copyright (C) 2005 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.action.executer;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
/**
* Simple action to increment an integer value. The runtime NodeService is used so any user
* can increment the counter value on a node.
*
* @author Kevin Roast
*/
public class CounterIncrementActionExecuter extends ActionExecuterAbstractBase
{
/** Runtime NodeService with no permissions protection */
private NodeService nodeService;
/**
* @param nodeService The Runtime NodeService to set.
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
*/
protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
{
// add the cm:countable aspect as required
if (this.nodeService.hasAspect(actionedUponNodeRef, ContentModel.ASPECT_COUNTABLE) == false)
{
// set the value to 1 by default
Map<QName, Serializable> props = new HashMap<QName, Serializable>(1);
props.put(ContentModel.PROP_COUNTER, 1);
this.nodeService.addAspect(actionedUponNodeRef, ContentModel.ASPECT_COUNTABLE, props);
}
else
{
// increment the value and handle possibility that no value has been set yet
int resultValue = 1;
Integer value = (Integer)this.nodeService.getProperty(actionedUponNodeRef, ContentModel.PROP_COUNTER);
if (value != null)
{
resultValue = value.intValue() + 1;
}
this.nodeService.setProperty(actionedUponNodeRef, ContentModel.PROP_COUNTER, resultValue);
}
}
/**
* @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefinitions(java.util.List)
*/
protected void addParameterDefinitions(List<ParameterDefinition> paramList)
{
// none required
}
}

View File

@@ -32,9 +32,13 @@ import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.security.PersonService;
/**
* Action to execute a JavaScript. The script has access to the default model.
* The actionedUponNodeRef is added to the default model as the 'document' and the owning
* NodeRef is added as the 'space'.
*
* @author Kevin Roast
*/
public class ScriptActionExecutor extends ActionExecuterAbstractBase
public class ScriptActionExecuter extends ActionExecuterAbstractBase
{
public static final String NAME = "script";
public static final String PARAM_SCRIPTREF = "script-ref";