. 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

@@ -355,7 +355,7 @@
</property> </property>
</bean> </bean>
<bean id="script" class="org.alfresco.repo.action.executer.ScriptActionExecutor" parent="action-executer"> <bean id="script" class="org.alfresco.repo.action.executer.ScriptActionExecuter" parent="action-executer">
<property name="serviceRegistry"> <property name="serviceRegistry">
<ref bean="ServiceRegistry" /> <ref bean="ServiceRegistry" />
</property> </property>
@@ -370,6 +370,12 @@
</property> </property>
</bean> </bean>
<bean id="counter" class="org.alfresco.repo.action.executer.CounterIncrementActionExecuter" parent="action-executer">
<property name="nodeService">
<ref bean="nodeService" /> <!-- runtime nodeService -->
</property>
</bean>
<bean id="execute-all-rules" class="org.alfresco.repo.action.executer.ExecuteAllRulesActionExecuter" parent="action-executer"> <bean id="execute-all-rules" class="org.alfresco.repo.action.executer.ExecuteAllRulesActionExecuter" parent="action-executer">
<property name="nodeService"> <property name="nodeService">
<ref bean="NodeService" /> <ref bean="NodeService" />

View File

@@ -74,10 +74,13 @@ export.generic.package.description=Alfresco Repository export.
export.package.error=Failed to find temporary file for export export.package.error=Failed to find temporary file for export
script.title=Execute a script script.title=Execute a script
script.description=Execute a JavaScript file to perform tasks such as creating new files or folders script.description=Execute a JavaScript file to perform tasks such as creating new files or folders.
counter.title=Increment Counter
counter.counter=Increment the counter property for the item.
execute-all-rules.title=Execute all rules execute-all-rules.title=Execute all rules
execute-all-rules.description=Execute all rules on the child items execute-all-rules.description=Execute all rules on the child items.
start-workflow.title=Start Workflow start-workflow.title=Start Workflow
start-workflow.description=This will start a workflow for the matched items. start-workflow.description=This will start a workflow for the matched items.

View File

@@ -526,6 +526,9 @@
<property name="cm:hits"> <property name="cm:hits">
<type>d:int</type> <type>d:int</type>
</property> </property>
<property name="cm:counter">
<type>d:int</type>
</property>
</properties> </properties>
</aspect> </aspect>

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_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"); static final QName PROP_SYS_VERSION_EDITION = QName.createQName(NamespaceService.SYSTEM_MODEL_1_0_URI, "versionEdition");
// //
// Content Model Definitions // 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_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"); 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 // 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; 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 * @author Kevin Roast
*/ */
public class ScriptActionExecutor extends ActionExecuterAbstractBase public class ScriptActionExecuter extends ActionExecuterAbstractBase
{ {
public static final String NAME = "script"; public static final String NAME = "script";
public static final String PARAM_SCRIPTREF = "script-ref"; public static final String PARAM_SCRIPTREF = "script-ref";