Moving to root below branch label

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@2005 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2005-12-08 07:13:07 +00:00
commit e1e6508fec
1095 changed files with 230566 additions and 0 deletions

View File

@@ -0,0 +1,44 @@
/*
* 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 org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* @author Roy Wetherall
*/
public interface ActionExecuter
{
/**
* Get the action definition for the action
*
* @return the action definition
*/
public ActionDefinition getActionDefinition();
/**
* Execute the action executer
*
* @param action the action
* @param actionedUponNodeRef the actioned upon node reference
*/
public void execute(
Action action,
NodeRef actionedUponNodeRef);
}

View File

@@ -0,0 +1,103 @@
/*
* 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 org.alfresco.repo.action.ActionDefinitionImpl;
import org.alfresco.repo.action.ParameterizedItemAbstractBase;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Rule action executor abstract base.
*
* @author Roy Wetherall
*/
public abstract class ActionExecuterAbstractBase extends ParameterizedItemAbstractBase implements ActionExecuter
{
/**
* Action definition
*/
protected ActionDefinition actionDefinition;
/**
* Indicated whether the action is public or internal
*/
protected boolean publicAction = true;
/**
* Init method
*/
public void init()
{
if (this.publicAction == true)
{
this.runtimeActionService.registerActionExecuter(this);
}
}
/**
* Set whether the action is public or not.
*
* @param publicAction true if the action is public, false otherwise
*/
public void setPublicAction(boolean publicAction)
{
this.publicAction = publicAction;
}
/**
* Get rule action definition
*
* @return the action definition object
*/
public ActionDefinition getActionDefinition()
{
if (this.actionDefinition == null)
{
this.actionDefinition = new ActionDefinitionImpl(this.name);
((ActionDefinitionImpl)this.actionDefinition).setTitleKey(getTitleKey());
((ActionDefinitionImpl)this.actionDefinition).setDescriptionKey(getDescriptionKey());
((ActionDefinitionImpl)this.actionDefinition).setAdhocPropertiesAllowed(getAdhocPropertiesAllowed());
((ActionDefinitionImpl)this.actionDefinition).setRuleActionExecutor(this.name);
((ActionDefinitionImpl)this.actionDefinition).setParameterDefinitions(getParameterDefintions());
}
return this.actionDefinition;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
*/
public void execute(Action action, NodeRef actionedUponNodeRef)
{
// Check the mandatory properties
checkMandatoryProperties(action, getActionDefinition());
// Execute the implementation
executeImpl(action, actionedUponNodeRef);
}
/**
* Execute the action implementation
*
* @param action the action
* @param actionedUponNodeRef the actioned upon node
*/
protected abstract void executeImpl(Action action, NodeRef actionedUponNodeRef);
}

View File

@@ -0,0 +1,110 @@
/*
* 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.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
/**
* Add features action executor implementation.
*
* @author Roy Wetherall
*/
public class AddFeaturesActionExecuter extends ActionExecuterAbstractBase
{
/**
* Action constants
*/
public static final String NAME = "add-features";
public static final String PARAM_ASPECT_NAME = "aspect-name";
public static final String PARAM_ASPECT_PROPERTIES = "aspect_properties";
/**
* The node service
*/
private NodeService nodeService;
/**
* Set the node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Adhoc properties are allowed for this executor
*/
@Override
protected boolean getAdhocPropertiesAllowed()
{
return true;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.service.cmr.repository.NodeRef, NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
if (this.nodeService.exists(actionedUponNodeRef) == true)
{
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
QName aspectQName = null;
Map<String, Serializable> paramValues = ruleAction.getParameterValues();
for (Map.Entry<String, Serializable> entry : paramValues.entrySet())
{
if (entry.getKey().equals(PARAM_ASPECT_NAME) == true)
{
aspectQName = (QName)entry.getValue();
}
else
{
// Must be an adhoc property
QName propertyQName = QName.createQName(entry.getKey());
Serializable propertyValue = entry.getValue();
properties.put(propertyQName, propertyValue);
}
}
// Add the aspect
this.nodeService.addAspect(actionedUponNodeRef, aspectQName, properties);
}
}
/**
* @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefintions(java.util.List)
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_ASPECT_NAME, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_ASPECT_NAME)));
}
}

View File

@@ -0,0 +1,106 @@
/*
* 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 org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionImpl;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
/**
* Add features action execution test
*
* @author Roy Wetherall
*/
public class AddFeaturesActionExecuterTest extends BaseSpringTest
{
/**
* The node service
*/
private NodeService nodeService;
/**
* The store reference
*/
private StoreRef testStoreRef;
/**
* The root node reference
*/
private NodeRef rootNodeRef;
/**
* The test node reference
*/
private NodeRef nodeRef;
/**
* The add features action executer
*/
private AddFeaturesActionExecuter executer;
/**
* Id used to identify the test action created
*/
private final static String ID = GUID.generate();
/**
* Called at the begining of all tests
*/
@Override
protected void onSetUpInTransaction() throws Exception
{
this.nodeService = (NodeService)this.applicationContext.getBean("nodeService");
// Create the store and get the root node
this.testStoreRef = this.nodeService.createStore(
StoreRef.PROTOCOL_WORKSPACE, "Test_"
+ System.currentTimeMillis());
this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);
// Create the node used for tests
this.nodeRef = this.nodeService.createNode(
this.rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}testnode"),
ContentModel.TYPE_CONTENT).getChildRef();
// Get the executer instance
this.executer = (AddFeaturesActionExecuter)this.applicationContext.getBean(AddFeaturesActionExecuter.NAME);
}
/**
* Test execution
*/
public void testExecution()
{
// Check that the node does not have the classifiable aspect
assertFalse(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_CLASSIFIABLE));
// Execute the action
ActionImpl action = new ActionImpl(ID, AddFeaturesActionExecuter.NAME, null);
action.setParameterValue(AddFeaturesActionExecuter.PARAM_ASPECT_NAME, ContentModel.ASPECT_CLASSIFIABLE);
this.executer.execute(action, this.nodeRef);
// Check that the node now has the classifiable aspect applied
assertTrue(this.nodeService.hasAspect(this.nodeRef, ContentModel.ASPECT_CLASSIFIABLE));
}
}

View File

@@ -0,0 +1,115 @@
/*
* 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.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.version.VersionModel;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.version.Version;
import org.alfresco.service.cmr.version.VersionType;
/**
* Check in action executor
*
* @author Roy Wetherall
*/
public class CheckInActionExecuter extends ActionExecuterAbstractBase
{
public static final String NAME = "check-in";
public static final String PARAM_DESCRIPTION = "description";
public static final String PARAM_MINOR_CHANGE = "minorChange";
/**
* The node service
*/
private NodeService nodeService;
/**
* The coci service
*/
private CheckOutCheckInService cociService;
/**
* Set node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Set the checkIn checkOut service
*
* @param cociService the checkIn checkOut Service
*/
public void setCociService(CheckOutCheckInService cociService)
{
this.cociService = cociService;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.repo.ref.NodeRef, org.alfresco.repo.ref.NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
// First ensure that the actionedUponNodeRef is a workingCopy
if (this.nodeService.exists(actionedUponNodeRef) == true &&
this.nodeService.hasAspect(actionedUponNodeRef, ContentModel.ASPECT_WORKING_COPY) == true)
{
// Get the version description
String description = (String)ruleAction.getParameterValue(PARAM_DESCRIPTION);
Map<String, Serializable> versionProperties = new HashMap<String, Serializable>(1);
versionProperties.put(Version.PROP_DESCRIPTION, description);
// determine whether the change is minor or major
Boolean minorChange = (Boolean)ruleAction.getParameterValue(PARAM_MINOR_CHANGE);
if (minorChange != null && minorChange.booleanValue() == false)
{
versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
}
else
{
versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MINOR);
}
// TODO determine whether the document should be kept checked out
// Check the node in
this.cociService.checkin(actionedUponNodeRef, versionProperties);
}
}
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_DESCRIPTION, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_DESCRIPTION)));
}
}

View File

@@ -0,0 +1,113 @@
/*
* 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.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.coci.CheckOutCheckInService;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
/**
* Check out action executor
*
* @author Roy Wetherall
*/
public class CheckOutActionExecuter extends ActionExecuterAbstractBase
{
public static final String NAME = "check-out";
public static final String PARAM_DESTINATION_FOLDER = "destination-folder";
public static final String PARAM_ASSOC_TYPE_QNAME = "assoc-type";
public static final String PARAM_ASSOC_QNAME = "assoc-name";
/**
* The version operations service
*/
private CheckOutCheckInService cociService;
/**
* The node service
*/
private NodeService nodeService;
/**
* Set the node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Set the coci service
*
* @param cociService the coci service
*/
public void setCociService(CheckOutCheckInService cociService)
{
this.cociService = cociService;
}
/**
* Add the parameter defintions
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_DESTINATION_FOLDER, DataTypeDefinition.NODE_REF, false, getParamDisplayLabel(PARAM_DESTINATION_FOLDER)));
paramList.add(new ParameterDefinitionImpl(PARAM_ASSOC_TYPE_QNAME, DataTypeDefinition.QNAME, false, getParamDisplayLabel(PARAM_ASSOC_TYPE_QNAME)));
paramList.add(new ParameterDefinitionImpl(PARAM_ASSOC_QNAME, DataTypeDefinition.QNAME, false, getParamDisplayLabel(PARAM_ASSOC_QNAME)));
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.repo.ref.NodeRef, org.alfresco.repo.ref.NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
if (this.nodeService.exists(actionedUponNodeRef) == true &&
this.nodeService.hasAspect(actionedUponNodeRef, ContentModel.ASPECT_WORKING_COPY) == false)
{
// Get the destination details
NodeRef destinationParent = (NodeRef)ruleAction.getParameterValue(PARAM_DESTINATION_FOLDER);
QName destinationAssocTypeQName = (QName)ruleAction.getParameterValue(PARAM_ASSOC_TYPE_QNAME);
QName destinationAssocQName = (QName)ruleAction.getParameterValue(PARAM_ASSOC_QNAME);
if (destinationParent == null || destinationAssocTypeQName == null || destinationAssocQName == null)
{
// Check the node out to the current location
this.cociService.checkout(actionedUponNodeRef);
}
else
{
// Check the node out to the specified location
this.cociService.checkout(
actionedUponNodeRef,
destinationParent,
destinationAssocTypeQName,
destinationAssocQName);
}
}
}
}

View File

@@ -0,0 +1,78 @@
/*
* 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.util.List;
import org.alfresco.repo.action.RuntimeActionService;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.CompositeAction;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
/**
* Add features action executor implementation.
*
* @author Roy Wetherall
*/
public class CompositeActionExecuter extends ActionExecuterAbstractBase
{
/**
* Action constants
*/
public static final String NAME = "composite-action";
/**
* The action service
*/
private RuntimeActionService actionService;
/**
* Set the action service
*
* @param actionService the action service
*/
public void setActionService(RuntimeActionService actionService)
{
this.actionService = actionService;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.service.cmr.repository.NodeRef, NodeRef)
*/
public void executeImpl(Action action, NodeRef actionedUponNodeRef)
{
if (action instanceof CompositeAction)
{
for (Action subAction : ((CompositeAction)action).getActions())
{
// We don't check the conditions of sub-actions and they don't have an execution history
this.actionService.directActionExecution(subAction, actionedUponNodeRef);
}
}
}
/**
* Add parameter definitions
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
// No parameters
}
}

View File

@@ -0,0 +1,170 @@
/*
* Copyright (C) 2005 Jesper Steen M<>ller
*
* 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.repo.content.metadata.MetadataExtracter;
import org.alfresco.repo.content.metadata.MetadataExtracterRegistry;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
/**
* Extract metadata from any added content.
* <p>
* The metadata is extracted from the content and compared to the current
* property values. Missing or zero-length properties are replaced,
* otherwise they are left as is.<br/>
* <i>This may change if the action gets parameterized in future</i>.
*
* @author Jesper Steen M<>ller
*/
public class ContentMetadataExtracter extends ActionExecuterAbstractBase
{
/**
* Action constants
*/
public static final String NAME = "extract-metadata";
/*
* TODO: Action parameters.
*
* Currently none exist, but it may be nice to add a 'policy' parameter for
* overwriting the extracted properties, with the following possible values:
* 1) Never: Never overwrite node properties that
* exist (i.e. preserve values, nulls, and blanks)
* 2) Pragmatic: Write
* extracted properties if they didn't exist before, are null, or evaluate
* to an empty string.
* 3) Always: Always store the extracted properes.
*
* Policies 1 and 2 will preserve previously set properties in case nodes
* are moved/copied, making this action run on the same content several
* times. However, if a property is deliberately cleared (e.g. by putting
* the empty string into the "decription" field), the pragmatic policy would
* indeed overwrite it. The current implementation matches the 'pragmatic'
* policy.
*/
/**
* The node service
*/
private NodeService nodeService;
/**
* Set the node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Our content service
*/
private ContentService contentService;
/**
* @param contentService The contentService to set.
*/
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
/**
* Our Extracter
*/
private MetadataExtracterRegistry metadataExtracterRegistry;
/**
* @param metadataExtracterRegistry The metadataExtracterRegistry to set.
*/
public void setMetadataExtracterRegistry(MetadataExtracterRegistry metadataExtracterRegistry)
{
this.metadataExtracterRegistry = metadataExtracterRegistry;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.service.cmr.repository.NodeRef,
* NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
if (this.nodeService.exists(actionedUponNodeRef) == true)
{
ContentReader cr = contentService.getReader(actionedUponNodeRef, ContentModel.PROP_CONTENT);
// 'cr' may be null, e.g. for folders and the like
if (cr != null && cr.getMimetype() != null)
{
MetadataExtracter me = metadataExtracterRegistry.getExtracter(cr.getMimetype());
if (me != null)
{
Map<QName, Serializable> newProps = new HashMap<QName, Serializable>(7, 0.5f);
me.extract(cr, newProps);
Map<QName, Serializable> allProps = nodeService.getProperties(actionedUponNodeRef);
/*
* The code below implements a modestly conservative
* 'preserve' policy which shouldn't override values
* accidentally.
*/
boolean changed = false;
for (QName key : newProps.keySet())
{
Serializable value = newProps.get(key);
if (value == null)
continue; // Content extracters shouldn't do this
// Look up the old value, and check for nulls
Serializable oldValue = allProps.get(key);
if (oldValue == null || oldValue.toString().length() == 0)
{
allProps.put(key, value);
changed = true;
}
}
// TODO: Should we be adding the associated aspects or is
// that done by the type system
// (or are ad-hoc properties allowed?)
if (changed)
nodeService.setProperties(actionedUponNodeRef, allProps);
}
}
}
}
@Override
protected void addParameterDefintions(List<ParameterDefinition> arg0)
{
// None!
}
}

View File

@@ -0,0 +1,148 @@
/*
* Copyright (C) 2005 Jesper Steen M<>ller
*
* 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.Map;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionImpl;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.content.metadata.MetadataExtracterRegistry;
import org.alfresco.repo.content.transform.AbstractContentTransformerTest;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
/**
* Test of the ActionExecuter for extracting metadata. Note: This test makes
* assumptions about the PDF test data for PdfBoxExtracter.
*
* @author Jesper Steen M<>ller
*/
public class ContentMetadataExtracterTest extends BaseSpringTest
{
protected static final String QUICK_TITLE = "The quick brown fox jumps over the lazy dog";
protected static final String QUICK_DESCRIPTION = "Gym class featuring a brown fox and lazy dog";
protected static final String QUICK_CREATOR = "Nevin Nollop";
private NodeService nodeService;
private ContentService contentService;
private MetadataExtracterRegistry metadataExtracterRegistry;
private StoreRef testStoreRef;
private NodeRef rootNodeRef;
private NodeRef nodeRef;
private ContentMetadataExtracter executer;
private final static String ID = GUID.generate();
@Override
protected void onSetUpInTransaction() throws Exception
{
this.nodeService = (NodeService) this.applicationContext.getBean("nodeService");
this.contentService = (ContentService) this.applicationContext.getBean("contentService");
this.metadataExtracterRegistry = (MetadataExtracterRegistry) this.applicationContext
.getBean("metadataExtracterRegistry");
// Create the store and get the root node
this.testStoreRef = this.nodeService.createStore(
StoreRef.PROTOCOL_WORKSPACE,
"Test_" + System.currentTimeMillis());
this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);
// Create the node used for tests
this.nodeRef = this.nodeService.createNode(
this.rootNodeRef, ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}testnode"),
ContentModel.TYPE_CONTENT).getChildRef();
// Setup the content from the PDF test data
ContentWriter cw = this.contentService.getWriter(nodeRef, ContentModel.PROP_CONTENT, true);
cw.setMimetype(MimetypeMap.MIMETYPE_PDF);
cw.putContent(AbstractContentTransformerTest.loadQuickTestFile("pdf"));
// Get the executer instance
this.executer = (ContentMetadataExtracter) this.applicationContext.getBean(ContentMetadataExtracter.NAME);
}
/**
* Test execution of the extraction itself
*/
public void testFromBlanks()
{
// Test that the action writes properties when they don't exist or are
// unset
// Get the old props
Map<QName, Serializable> props = this.nodeService.getProperties(this.nodeRef);
props.remove(ContentModel.PROP_CREATOR);
props.put(ContentModel.PROP_TITLE, "");
props.put(ContentModel.PROP_DESCRIPTION, null); // Wonder how this will
// be handled
this.nodeService.setProperties(this.nodeRef, props);
// Execute the action
ActionImpl action = new ActionImpl(ID, SetPropertyValueActionExecuter.NAME, null);
this.executer.execute(action, this.nodeRef);
// Check that the properties have been set
assertEquals(QUICK_TITLE, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_TITLE));
assertEquals(QUICK_DESCRIPTION, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_DESCRIPTION));
assertEquals(QUICK_CREATOR, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_CREATOR));
}
/**
* Test execution of the pragmatic approach
*/
public void testFromPartial()
{
// Test that the action does not overwrite properties that are already
// set
String myCreator = "Null-op";
String myTitle = "The hot dog is eaten by the city fox";
// Get the old props
Map<QName, Serializable> props = this.nodeService.getProperties(this.nodeRef);
props.put(ContentModel.PROP_CREATOR, myCreator);
props.put(ContentModel.PROP_TITLE, myTitle);
props.remove(ContentModel.PROP_DESCRIPTION); // Allow this baby
this.nodeService.setProperties(this.nodeRef, props);
// Execute the action
ActionImpl action = new ActionImpl(ID, SetPropertyValueActionExecuter.NAME, null);
this.executer.execute(action, this.nodeRef);
// Check that the properties have been preserved
assertEquals(myTitle, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_TITLE));
assertEquals(myCreator, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_CREATOR));
// But this one should have been set
assertEquals(QUICK_DESCRIPTION, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_DESCRIPTION));
}
// If we implement other policies than "pragmatic", they should be tested as
// well...
}

View File

@@ -0,0 +1,100 @@
/*
* 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.util.List;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.CopyService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
/**
* Copy action executor.
* <p>
* Copies the actioned upon node to a specified location.
*
* @author Roy Wetherall
*/
public class CopyActionExecuter extends ActionExecuterAbstractBase
{
public static final String NAME = "copy";
public static final String PARAM_DESTINATION_FOLDER = "destination-folder";
public static final String PARAM_ASSOC_TYPE_QNAME = "assoc-type";
public static final String PARAM_ASSOC_QNAME = "assoc-name";
public static final String PARAM_DEEP_COPY = "deep-copy";
/**
* Node operations service
*/
private CopyService copyService;
/**
* The node service
*/
private NodeService nodeService;
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setCopyService(CopyService copyService)
{
this.copyService = copyService;
}
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_DESTINATION_FOLDER, DataTypeDefinition.NODE_REF, true, getParamDisplayLabel(PARAM_DESTINATION_FOLDER)));
paramList.add(new ParameterDefinitionImpl(PARAM_ASSOC_TYPE_QNAME, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_ASSOC_TYPE_QNAME)));
paramList.add(new ParameterDefinitionImpl(PARAM_ASSOC_QNAME, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_ASSOC_QNAME)));
paramList.add(new ParameterDefinitionImpl(PARAM_DEEP_COPY, DataTypeDefinition.BOOLEAN, false, getParamDisplayLabel(PARAM_DEEP_COPY)));
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.repo.ref.NodeRef, org.alfresco.repo.ref.NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
if (this.nodeService.exists(actionedUponNodeRef) == true)
{
NodeRef destinationParent = (NodeRef)ruleAction.getParameterValue(PARAM_DESTINATION_FOLDER);
QName destinationAssocTypeQName = (QName)ruleAction.getParameterValue(PARAM_ASSOC_TYPE_QNAME);
QName destinationAssocQName = (QName)ruleAction.getParameterValue(PARAM_ASSOC_QNAME);
// TODO get this from a parameter value
boolean deepCopy = false;
this.copyService.copy(
actionedUponNodeRef,
destinationParent,
destinationAssocTypeQName,
destinationAssocQName,
deepCopy);
}
}
}

View File

@@ -0,0 +1,75 @@
/*
* 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.util.List;
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.cmr.version.VersionService;
/**
* Add features action executor implementation.
*
* @author Roy Wetherall
*/
public class CreateVersionActionExecuter extends ActionExecuterAbstractBase
{
/**
* Action constants
*/
public static final String NAME = "create-version";
public NodeService nodeService;
public VersionService versionService;
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
public void setVersionService(VersionService versionService)
{
this.versionService = versionService;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.service.cmr.repository.NodeRef, NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
if (this.nodeService.exists(actionedUponNodeRef) == true &&
this.nodeService.hasAspect(actionedUponNodeRef, ContentModel.ASPECT_VERSIONABLE) == true)
{
// TODO would be nice to be able to set the version details
this.versionService.createVersion(actionedUponNodeRef, null);
}
}
/**
* @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefintions(java.util.List)
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
}
}

View File

@@ -0,0 +1,249 @@
/*
* 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.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.i18n.I18NUtil;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.exporter.ACPExportPackageHandler;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ActionServiceException;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.ChildAssociationRef;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.cmr.view.ExporterCrawlerParameters;
import org.alfresco.service.cmr.view.ExporterService;
import org.alfresco.service.cmr.view.Location;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.TempFileProvider;
/**
* Exporter action executor
*
* @author gavinc
*/
public class ExporterActionExecuter extends ActionExecuterAbstractBase
{
public static final String NAME = "export";
public static final String PARAM_STORE = "store";
public static final String PARAM_PACKAGE_NAME = "package-name";
public static final String PARAM_DESTINATION_FOLDER = "destination";
public static final String PARAM_INCLUDE_CHILDREN = "include-children";
public static final String PARAM_INCLUDE_SELF = "include-self";
public static final String PARAM_ENCODING = "encoding";
private static final String TEMP_FILE_PREFIX = "alf";
/**
* The exporter service
*/
private ExporterService exporterService;
/**
* The node service
*/
private NodeService nodeService;
/**
* The content service
*/
private ContentService contentService;
/**
* Sets the ExporterService to use
*
* @param exporterService The ExporterService
*/
public void setExporterService(ExporterService exporterService)
{
this.exporterService = exporterService;
}
/**
* Sets the NodeService to use
*
* @param nodeService The NodeService
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Sets the ContentService to use
*
* @param contentService The ContentService
*/
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.repo.ref.NodeRef, org.alfresco.repo.ref.NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
File zipFile = null;
try
{
String packageName = (String)ruleAction.getParameterValue(PARAM_PACKAGE_NAME);
File dataFile = new File(packageName);
File contentDir = new File(packageName);
// create a temporary file to hold the zip
zipFile = TempFileProvider.createTempFile(TEMP_FILE_PREFIX, ACPExportPackageHandler.ACP_EXTENSION);
ACPExportPackageHandler zipHandler = new ACPExportPackageHandler(new FileOutputStream(zipFile),
dataFile, contentDir);
ExporterCrawlerParameters params = new ExporterCrawlerParameters();
boolean includeChildren = true;
Boolean withKids = (Boolean)ruleAction.getParameterValue(PARAM_INCLUDE_CHILDREN);
if (withKids != null)
{
includeChildren = withKids.booleanValue();
}
params.setCrawlChildNodes(includeChildren);
boolean includeSelf = false;
Boolean andMe = (Boolean)ruleAction.getParameterValue(PARAM_INCLUDE_SELF);
if (andMe != null)
{
includeSelf = andMe.booleanValue();
}
params.setCrawlSelf(includeSelf);
params.setExportFrom(new Location(actionedUponNodeRef));
// perform the actual export
this.exporterService.exportView(zipHandler, params, null);
// now the export is done we need to create a node in the repository
// to hold the exported package
NodeRef zip = createExportZip(ruleAction, actionedUponNodeRef);
ContentWriter writer = this.contentService.getWriter(zip, ContentModel.PROP_CONTENT, true);
writer.setEncoding((String)ruleAction.getParameterValue(PARAM_ENCODING));
writer.setMimetype(MimetypeMap.MIMETYPE_ACP);
writer.putContent(zipFile);
}
catch (FileNotFoundException fnfe)
{
throw new ActionServiceException("export.package.error", fnfe);
}
finally
{
// try and delete the temporary file
if (zipFile != null)
{
zipFile.delete();
}
}
}
/**
* @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefintions(java.util.List)
*/
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_PACKAGE_NAME, DataTypeDefinition.TEXT, true,
getParamDisplayLabel(PARAM_PACKAGE_NAME)));
paramList.add(new ParameterDefinitionImpl(PARAM_ENCODING, DataTypeDefinition.TEXT, true,
getParamDisplayLabel(PARAM_ENCODING)));
paramList.add(new ParameterDefinitionImpl(PARAM_STORE, DataTypeDefinition.TEXT, true,
getParamDisplayLabel(PARAM_STORE)));
paramList.add(new ParameterDefinitionImpl(PARAM_DESTINATION_FOLDER, DataTypeDefinition.NODE_REF, true,
getParamDisplayLabel(PARAM_DESTINATION_FOLDER)));
paramList.add(new ParameterDefinitionImpl(PARAM_INCLUDE_CHILDREN, DataTypeDefinition.BOOLEAN, false,
getParamDisplayLabel(PARAM_INCLUDE_CHILDREN)));
paramList.add(new ParameterDefinitionImpl(PARAM_INCLUDE_SELF, DataTypeDefinition.BOOLEAN, false,
getParamDisplayLabel(PARAM_INCLUDE_SELF)));
}
/**
* Creates the ZIP file node in the repository for the export
*
* @param ruleAction The rule being executed
* @return The NodeRef of the newly created ZIP file
*/
private NodeRef createExportZip(Action ruleAction, NodeRef actionedUponNodeRef)
{
// create a node in the repository to represent the export package
NodeRef exportDest = (NodeRef)ruleAction.getParameterValue(PARAM_DESTINATION_FOLDER);
String packageName = (String)ruleAction.getParameterValue(PARAM_PACKAGE_NAME);
// add the default Alfresco content package extension if an extension hasn't been given
if (packageName.indexOf(".") == -1)
{
packageName = packageName + "." + ACPExportPackageHandler.ACP_EXTENSION;
}
// set the name for the new node
Map<QName, Serializable> contentProps = new HashMap<QName, Serializable>(1);
contentProps.put(ContentModel.PROP_NAME, packageName);
// create the node to represent the zip file
String assocName = QName.createValidLocalName(packageName);
ChildAssociationRef assocRef = this.nodeService.createNode(
exportDest, ContentModel.ASSOC_CONTAINS,
QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, assocName),
ContentModel.TYPE_CONTENT, contentProps);
NodeRef zipNodeRef = assocRef.getChildRef();
// build a description string to be set on the node representing the content package
String desc = "";
String storeRef = (String)ruleAction.getParameterValue(PARAM_STORE);
NodeRef rootNode = this.nodeService.getRootNode(new StoreRef(storeRef));
if (rootNode.equals(actionedUponNodeRef))
{
desc = I18NUtil.getMessage("export.root.package.description");
}
else
{
String spaceName = (String)this.nodeService.getProperty(actionedUponNodeRef, ContentModel.PROP_NAME);
String pattern = I18NUtil.getMessage("export.package.description");
if (pattern != null && spaceName != null)
{
desc = MessageFormat.format(pattern, spaceName);
}
}
// apply the titled aspect to behave in the web client
Map<QName, Serializable> titledProps = new HashMap<QName, Serializable>(3, 1.0f);
titledProps.put(ContentModel.PROP_TITLE, packageName);
titledProps.put(ContentModel.PROP_DESCRIPTION, desc);
this.nodeService.addAspect(zipNodeRef, ContentModel.ASPECT_TITLED, titledProps);
return zipNodeRef;
}
}

View File

@@ -0,0 +1,85 @@
/*
* 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.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.content.transform.magick.ImageMagickContentTransformer;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.NoTransformerException;
/**
* Transfor action executer
*
* @author Roy Wetherall
*/
public class ImageTransformActionExecuter extends TransformActionExecuter
{
/**
* Action constants
*/
public static final String NAME = "transform-image";
public static final String PARAM_CONVERT_COMMAND = "convert-command";
private ImageMagickContentTransformer imageMagickContentTransformer;
/**
* Set the image magick content transformer
*
* @param imageMagickContentTransformer the conten transformer
*/
public void setImageMagickContentTransformer(ImageMagickContentTransformer imageMagickContentTransformer)
{
this.imageMagickContentTransformer = imageMagickContentTransformer;
}
/**
* Add parameter definitions
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
super.addParameterDefintions(paramList);
paramList.add(new ParameterDefinitionImpl(PARAM_CONVERT_COMMAND, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_CONVERT_COMMAND)));
}
/**
* @see org.alfresco.repo.action.executer.TransformActionExecuter#doTransform(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.ContentReader, org.alfresco.service.cmr.repository.ContentWriter)
*/
protected void doTransform(Action ruleAction, ContentReader contentReader, ContentWriter contentWriter)
{
// check if the transformer is going to work, i.e. is available
if (!this.imageMagickContentTransformer.isAvailable())
{
throw new NoTransformerException(contentReader.getMimetype(), contentWriter.getMimetype());
}
// Try and transform the content
String convertCommand = (String)ruleAction.getParameterValue(PARAM_CONVERT_COMMAND);
// create some options for the transform
Map<String, Object> options = new HashMap<String, Object>(5);
options.put(ImageMagickContentTransformer.KEY_OPTIONS, convertCommand);
this.imageMagickContentTransformer.transform(contentReader, contentWriter, options);
}
}

View File

@@ -0,0 +1,147 @@
/*
* 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.File;
import java.util.List;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.importer.ACPImportPackageHandler;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.view.ImporterService;
import org.alfresco.service.cmr.view.Location;
import org.alfresco.util.TempFileProvider;
/**
* Importer action executor
*
* @author gavinc
*/
public class ImporterActionExecuter extends ActionExecuterAbstractBase
{
public static final String NAME = "import";
public static final String PARAM_ENCODING = "encoding";
public static final String PARAM_DESTINATION_FOLDER = "destination";
private static final String TEMP_FILE_PREFIX = "alf";
private static final String TEMP_FILE_SUFFIX = ".acp";
/**
* The importer service
*/
private ImporterService importerService;
/**
* The node service
*/
private NodeService nodeService;
/**
* The content service
*/
private ContentService contentService;
/**
* Sets the ImporterService to use
*
* @param importerService The ImporterService
*/
public void setImporterService(ImporterService importerService)
{
this.importerService = importerService;
}
/**
* Sets the NodeService to use
*
* @param nodeService The NodeService
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Sets the ContentService to use
*
* @param contentService The ContentService
*/
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.repo.ref.NodeRef, org.alfresco.repo.ref.NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
if (this.nodeService.exists(actionedUponNodeRef) == true)
{
// The node being passed in should be an Alfresco content package
ContentReader reader = this.contentService.getReader(actionedUponNodeRef, ContentModel.PROP_CONTENT);
if (reader != null)
{
if (MimetypeMap.MIMETYPE_ACP.equals(reader.getMimetype()))
{
File zipFile = null;
try
{
// unfortunately a ZIP file can not be read directly from an input stream so we have to create
// a temporary file first
zipFile = TempFileProvider.createTempFile(TEMP_FILE_PREFIX, TEMP_FILE_SUFFIX);
reader.getContent(zipFile);
ACPImportPackageHandler importHandler = new ACPImportPackageHandler(zipFile,
(String)ruleAction.getParameterValue(PARAM_ENCODING));
NodeRef importDest = (NodeRef)ruleAction.getParameterValue(PARAM_DESTINATION_FOLDER);
this.importerService.importView(importHandler, new Location(importDest), null, null);
}
finally
{
// now the import is done, delete the temporary file
if (zipFile != null)
{
zipFile.delete();
}
}
}
}
}
}
/**
* @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefintions(java.util.List)
*/
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_DESTINATION_FOLDER, DataTypeDefinition.NODE_REF,
true, getParamDisplayLabel(PARAM_DESTINATION_FOLDER)));
paramList.add(new ParameterDefinitionImpl(PARAM_ENCODING, DataTypeDefinition.TEXT,
true, getParamDisplayLabel(PARAM_ENCODING)));
}
}

View File

@@ -0,0 +1,128 @@
/*
* 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.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.dictionary.PropertyDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
/**
* Link category action executor
*
* @author Roy Wetherall
*/
public class LinkCategoryActionExecuter extends ActionExecuterAbstractBase
{
/**
* Rule constants
*/
public static final String NAME = "link-category";
public static final String PARAM_CATEGORY_ASPECT = "category-aspect";
public static final String PARAM_CATEGORY_VALUE = "category-value";
/**
* The node service
*/
private NodeService nodeService;
/**
* The dictionary service
*/
private DictionaryService dictionaryService;
/**
* Sets the node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Sets the dictionary service
*
* @param dictionaryService the dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* Add the parameter definitions
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_CATEGORY_ASPECT, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_CATEGORY_ASPECT)));
paramList.add(new ParameterDefinitionImpl(PARAM_CATEGORY_VALUE, DataTypeDefinition.NODE_REF, true, getParamDisplayLabel(PARAM_CATEGORY_VALUE)));
}
/**
* Execute action implementation
*/
@Override
protected void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
// Double check that the node still exists
if (this.nodeService.exists(actionedUponNodeRef) == true)
{
// Get the rule parameter values
QName categoryAspect = (QName)ruleAction.getParameterValue(PARAM_CATEGORY_ASPECT);
NodeRef categoryValue = (NodeRef)ruleAction.getParameterValue(PARAM_CATEGORY_VALUE);
// Check that the apect is classifiable and is currently applied to the node
if (this.dictionaryService.isSubClass(categoryAspect, ContentModel.ASPECT_CLASSIFIABLE) == true)
{
// Get the category property qname
QName categoryProperty = null;
Map<QName, PropertyDefinition> propertyDefs = this.dictionaryService.getAspect(categoryAspect).getProperties();
for (Map.Entry<QName, PropertyDefinition> entry : propertyDefs.entrySet())
{
if (DataTypeDefinition.CATEGORY.equals(entry.getValue().getDataType().getName()) == true)
{
// Found the category property
categoryProperty = entry.getKey();
break;
}
}
if (categoryAspect != null)
{
// Add the aspect setting the category property to the approptiate values
Map<QName, Serializable> properties = new HashMap<QName, Serializable>();
properties.put(categoryProperty, categoryValue);
this.nodeService.addAspect(actionedUponNodeRef, categoryAspect, properties);
}
}
}
}
}

View File

@@ -0,0 +1,106 @@
/*
* 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.util.List;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
/**
* Mail action executor implementation.
*
* @author Roy Wetherall
*/
public class MailActionExecuter extends ActionExecuterAbstractBase
{
private static Log logger = LogFactory.getLog(MailActionExecuter.class);
/**
* Action executor constants
*/
public static final String NAME = "mail";
public static final String PARAM_TO = "to";
public static final String PARAM_SUBJECT = "subject";
public static final String PARAM_TEXT = "text";
/**
* From address
*/
public static final String FROM_ADDRESS = "alfresco_repository@alfresco.org";
/**
* The java mail sender
*/
private JavaMailSender javaMailSender;
/**
* Set the java mail sender
*
* @param javaMailSender the java mail sender
*/
public void setMailService(JavaMailSender javaMailSender)
{
this.javaMailSender = javaMailSender;
}
/**
* Execute the rule action
*/
@Override
protected void executeImpl(
Action ruleAction,
NodeRef actionedUponNodeRef)
{
// Create the simple mail message
SimpleMailMessage simpleMailMessage = new SimpleMailMessage();
simpleMailMessage.setTo((String)ruleAction.getParameterValue(PARAM_TO));
simpleMailMessage.setSubject((String)ruleAction.getParameterValue(PARAM_SUBJECT));
simpleMailMessage.setText((String)ruleAction.getParameterValue(PARAM_TEXT));
simpleMailMessage.setFrom(FROM_ADDRESS);
try
{
// Send the message
javaMailSender.send(simpleMailMessage);
}
catch (Throwable e)
{
// don't stop the action but let admins know email is not getting sent
logger.error("Failed to send email to " + (String)ruleAction.getParameterValue(PARAM_TO), e);
}
}
/**
* Add the parameter definitions
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_TO, DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_TO)));
paramList.add(new ParameterDefinitionImpl(PARAM_SUBJECT, DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_SUBJECT)));
paramList.add(new ParameterDefinitionImpl(PARAM_TEXT, DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_TEXT)));
}
}

View File

@@ -0,0 +1,80 @@
/*
* 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.util.List;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
/**
* Copy action executor.
* <p>
* Copies the actioned upon node to a specified location.
*
* @author Roy Wetherall
*/
public class MoveActionExecuter extends ActionExecuterAbstractBase
{
public static final String NAME = "move";
public static final String PARAM_DESTINATION_FOLDER = "destination-folder";
public static final String PARAM_ASSOC_TYPE_QNAME = "assoc-type";
public static final String PARAM_ASSOC_QNAME = "assoc-name";
/**
* Node service
*/
private NodeService nodeService;
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_DESTINATION_FOLDER, DataTypeDefinition.NODE_REF, true, getParamDisplayLabel(PARAM_DESTINATION_FOLDER)));
paramList.add(new ParameterDefinitionImpl(PARAM_ASSOC_TYPE_QNAME, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_ASSOC_TYPE_QNAME)));
paramList.add(new ParameterDefinitionImpl(PARAM_ASSOC_QNAME, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_ASSOC_QNAME)));
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.repo.ref.NodeRef, org.alfresco.repo.ref.NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
if (this.nodeService.exists(actionedUponNodeRef) == true)
{
NodeRef destinationParent = (NodeRef)ruleAction.getParameterValue(PARAM_DESTINATION_FOLDER);
QName destinationAssocTypeQName = (QName)ruleAction.getParameterValue(PARAM_ASSOC_TYPE_QNAME);
QName destinationAssocQName = (QName)ruleAction.getParameterValue(PARAM_ASSOC_QNAME);
this.nodeService.moveNode(
actionedUponNodeRef,
destinationParent,
destinationAssocTypeQName,
destinationAssocQName);
}
}
}

View File

@@ -0,0 +1,83 @@
/*
* 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.util.List;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
/**
* Add features action executor implementation.
*
* @author Roy Wetherall
*/
public class SetPropertyValueActionExecuter extends ActionExecuterAbstractBase
{
/**
* Action constants
*/
public static final String NAME = "set-property-value";
public static final String PARAM_PROPERTY = "property";
public static final String PARAM_VALUE = "value";
/**
* The node service
*/
private NodeService nodeService;
/**
* Set the node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.service.cmr.repository.NodeRef, NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
if (this.nodeService.exists(actionedUponNodeRef) == true)
{
// Set the value of the property
this.nodeService.setProperty(
actionedUponNodeRef,
(QName)ruleAction.getParameterValue(PARAM_PROPERTY),
ruleAction.getParameterValue(PARAM_VALUE));
}
}
/**
* Add parameter definitions
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_PROPERTY, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_PROPERTY)));
paramList.add(new ParameterDefinitionImpl(PARAM_VALUE, DataTypeDefinition.ANY, true, getParamDisplayLabel(PARAM_VALUE)));
}
}

View File

@@ -0,0 +1,97 @@
/*
* 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 org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionImpl;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.repository.StoreRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
/**
* Is sub class evaluator test
*
* @author Roy Wetherall
*/
public class SetPropertyValueActionExecuterTest extends BaseSpringTest
{
private NodeService nodeService;
private StoreRef testStoreRef;
private NodeRef rootNodeRef;
private NodeRef nodeRef;
private SetPropertyValueActionExecuter executer;
private final static String ID = GUID.generate();
private final static String TEST_VALUE = "TestValue";
@Override
protected void onSetUpInTransaction() throws Exception
{
this.nodeService = (NodeService)this.applicationContext.getBean("nodeService");
// Create the store and get the root node
this.testStoreRef = this.nodeService.createStore(
StoreRef.PROTOCOL_WORKSPACE, "Test_"
+ System.currentTimeMillis());
this.rootNodeRef = this.nodeService.getRootNode(this.testStoreRef);
// Create the node used for tests
this.nodeRef = this.nodeService.createNode(
this.rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}testnode"),
ContentModel.TYPE_CONTENT).getChildRef();
// Get the executer instance
this.executer = (SetPropertyValueActionExecuter)this.applicationContext.getBean(SetPropertyValueActionExecuter.NAME);
}
/**
* Test execution
*/
public void testExecution()
{
// Check that the property is empty
assertNull(this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_NAME));
// Execute the action
ActionImpl action = new ActionImpl(ID, SetPropertyValueActionExecuter.NAME, null);
action.setParameterValue(SetPropertyValueActionExecuter.PARAM_PROPERTY, ContentModel.PROP_NAME);
action.setParameterValue(SetPropertyValueActionExecuter.PARAM_VALUE, TEST_VALUE);
this.executer.execute(action, this.nodeRef);
// Check that the property value has been set
assertEquals(TEST_VALUE, this.nodeService.getProperty(this.nodeRef, ContentModel.PROP_NAME));
// Check what happens when a bad property name is set
action.setParameterValue(SetPropertyValueActionExecuter.PARAM_PROPERTY, QName.createQName("{test}badProperty"));
try
{
this.executer.execute(action, this.nodeRef);
fail("We would expect and exception to be thrown since the property name is invalid.");
}
catch (Throwable exception)
{
// Good .. we where expecting this
}
}
}

View File

@@ -0,0 +1,103 @@
/*
* 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.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
/**
* Simple workflow action executor
*
* @author Roy Wetherall
*/
public class SimpleWorkflowActionExecuter extends ActionExecuterAbstractBase
{
public static final String NAME = "simple-workflow";
public static final String PARAM_APPROVE_STEP = "approve-step";
public static final String PARAM_APPROVE_FOLDER = "approve-folder";
public static final String PARAM_APPROVE_MOVE = "approve-move";
public static final String PARAM_REJECT_STEP = "reject-step";
public static final String PARAM_REJECT_FOLDER = "reject-folder";
public static final String PARAM_REJECT_MOVE = "reject-move";
private NodeService nodeService;
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_APPROVE_STEP, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_APPROVE_STEP)));
paramList.add(new ParameterDefinitionImpl(PARAM_APPROVE_FOLDER, DataTypeDefinition.NODE_REF, false, getParamDisplayLabel(PARAM_APPROVE_FOLDER)));
paramList.add(new ParameterDefinitionImpl(PARAM_APPROVE_MOVE, DataTypeDefinition.BOOLEAN, false, getParamDisplayLabel(PARAM_APPROVE_MOVE)));
paramList.add(new ParameterDefinitionImpl(PARAM_REJECT_STEP, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_REJECT_STEP)));
paramList.add(new ParameterDefinitionImpl(PARAM_REJECT_FOLDER, DataTypeDefinition.NODE_REF, false, getParamDisplayLabel(PARAM_REJECT_FOLDER)));
paramList.add(new ParameterDefinitionImpl(PARAM_REJECT_MOVE, DataTypeDefinition.BOOLEAN, false, getParamDisplayLabel(PARAM_REJECT_MOVE)));
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
protected void executeImpl(
Action ruleAction,
NodeRef actionedUponNodeRef)
{
if (this.nodeService.exists(actionedUponNodeRef) == true)
{
// Get the parameter values
String approveStep = (String)ruleAction.getParameterValue(PARAM_APPROVE_STEP);
NodeRef approveFolder = (NodeRef)ruleAction.getParameterValue(PARAM_APPROVE_FOLDER);
Boolean approveMove = (Boolean)ruleAction.getParameterValue(PARAM_APPROVE_MOVE);
String rejectStep = (String)ruleAction.getParameterValue(PARAM_REJECT_STEP);
NodeRef rejectFolder = (NodeRef)ruleAction.getParameterValue(PARAM_REJECT_FOLDER);
Boolean rejectMove = (Boolean)ruleAction.getParameterValue(PARAM_REJECT_MOVE);
// Set the property values
Map<QName, Serializable> propertyValues = new HashMap<QName, Serializable>();
propertyValues.put(ContentModel.PROP_APPROVE_STEP, approveStep);
propertyValues.put(ContentModel.PROP_APPROVE_FOLDER, approveFolder);
if (approveMove != null)
{
propertyValues.put(ContentModel.PROP_APPROVE_MOVE, approveMove.booleanValue());
}
propertyValues.put(ContentModel.PROP_REJECT_STEP, rejectStep);
propertyValues.put(ContentModel.PROP_REJECT_FOLDER, rejectFolder);
if (rejectMove != null)
{
propertyValues.put(ContentModel.PROP_REJECT_MOVE, rejectMove.booleanValue());
}
// Apply the simple workflow aspect to the node
this.nodeService.addAspect(actionedUponNodeRef, ContentModel.ASPECT_SIMPLE_WORKFLOW, propertyValues);
}
}
}

View File

@@ -0,0 +1,103 @@
/*
* 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.util.List;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
/**
* Add features action executor implementation.
*
* @author Roy Wetherall
*/
public class SpecialiseTypeActionExecuter extends ActionExecuterAbstractBase
{
/**
* Action constants
*/
public static final String NAME = "specialise-type";
public static final String PARAM_TYPE_NAME = "type-name";
/**
* The node service
*/
private NodeService nodeService;
/**
* The dictionary service
*/
private DictionaryService dictionaryService;
/**
* Set the node service
*
* @param nodeService the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Set the dictionary service
*
* @param dictionaryService the dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuter#execute(org.alfresco.service.cmr.repository.NodeRef, NodeRef)
*/
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef)
{
if (this.nodeService.exists(actionedUponNodeRef) == true)
{
// Get the type of the node
QName currentType = this.nodeService.getType(actionedUponNodeRef);
QName destinationType = (QName)ruleAction.getParameterValue(PARAM_TYPE_NAME);
// Ensure that we are performing a specialise
if (currentType.equals(destinationType) == false &&
this.dictionaryService.isSubClass(destinationType, currentType) == true)
{
// Specialise the type of the node
this.nodeService.setType(actionedUponNodeRef, destinationType);
}
}
}
/**
* @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefintions(java.util.List)
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_TYPE_NAME, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_TYPE_NAME)));
}
}

View File

@@ -0,0 +1,90 @@
/*
* 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 org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ActionImpl;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.BaseAlfrescoSpringTest;
import org.alfresco.util.GUID;
/**
* Specialise type action execution test
*
* @author Roy Wetherall
*/
public class SpecialiseTypeActionExecuterTest extends BaseAlfrescoSpringTest
{
/**
* The test node reference
*/
private NodeRef nodeRef;
/**
* The specialise action executer
*/
private SpecialiseTypeActionExecuter executer;
/**
* Id used to identify the test action created
*/
private final static String ID = GUID.generate();
/**
* Called at the begining of all tests
*/
@Override
protected void onSetUpInTransaction() throws Exception
{
super.onSetUpInTransaction();
// Create the node used for tests
this.nodeRef = this.nodeService.createNode(
this.rootNodeRef,
ContentModel.ASSOC_CHILDREN,
QName.createQName("{test}testnode"),
ContentModel.TYPE_CONTENT).getChildRef();
// Get the executer instance
this.executer = (SpecialiseTypeActionExecuter)this.applicationContext.getBean(SpecialiseTypeActionExecuter.NAME);
}
/**
* Test execution
*/
public void testExecution()
{
// Check the type of the node
assertEquals(ContentModel.TYPE_CONTENT, this.nodeService.getType(this.nodeRef));
// Execute the action
ActionImpl action = new ActionImpl(ID, SpecialiseTypeActionExecuter.NAME, null);
action.setParameterValue(SpecialiseTypeActionExecuter.PARAM_TYPE_NAME, ContentModel.TYPE_FOLDER);
this.executer.execute(action, this.nodeRef);
// Check that the node's type has not been changed since it would not be a specialisation
assertEquals(ContentModel.TYPE_CONTENT, this.nodeService.getType(this.nodeRef));
// Execute the action agian
action.setParameterValue(SpecialiseTypeActionExecuter.PARAM_TYPE_NAME, ContentModel.TYPE_DICTIONARY_MODEL);
this.executer.execute(action, this.nodeRef);
// Check that the node's type has now been changed
assertEquals(ContentModel.TYPE_DICTIONARY_MODEL, this.nodeService.getType(this.nodeRef));
}
}

View File

@@ -0,0 +1,247 @@
/*
* 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.util.List;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.service.cmr.action.Action;
import org.alfresco.service.cmr.action.ParameterDefinition;
import org.alfresco.service.cmr.dictionary.DataTypeDefinition;
import org.alfresco.service.cmr.dictionary.DictionaryService;
import org.alfresco.service.cmr.repository.ContentReader;
import org.alfresco.service.cmr.repository.ContentService;
import org.alfresco.service.cmr.repository.ContentWriter;
import org.alfresco.service.cmr.repository.CopyService;
import org.alfresco.service.cmr.repository.MimetypeService;
import org.alfresco.service.cmr.repository.NoTransformerException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.namespace.QName;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Transfor action executer
*
* @author Roy Wetherall
*/
public class TransformActionExecuter extends ActionExecuterAbstractBase
{
/**
* The logger
*/
private static Log logger = LogFactory.getLog(TransformActionExecuter.class);
/**
* Action constants
*/
public static final String NAME = "transform";
public static final String PARAM_MIME_TYPE = "mime-type";
public static final String PARAM_DESTINATION_FOLDER = "destination-folder";
public static final String PARAM_ASSOC_TYPE_QNAME = "assoc-type";
public static final String PARAM_ASSOC_QNAME = "assoc-name";
private DictionaryService dictionaryService;
private NodeService nodeService;
private ContentService contentService;
private CopyService copyService;
private MimetypeService mimetypeService;
/**
* Set the mime type service
*
* @param mimetypeService the mime type service
*/
public void setMimetypeService(MimetypeService mimetypeService)
{
this.mimetypeService = mimetypeService;
}
/**
* Set the node service
*
* @param nodeService set the node service
*/
public void setNodeService(NodeService nodeService)
{
this.nodeService = nodeService;
}
/**
* Set the dictionary service
*
* @param dictionaryService the dictionary service
*/
public void setDictionaryService(DictionaryService dictionaryService)
{
this.dictionaryService = dictionaryService;
}
/**
* Set the content service
*
* @param contentService the content service
*/
public void setContentService(ContentService contentService)
{
this.contentService = contentService;
}
/**
* Set the copy service
*
* @param copyService the copy service
*/
public void setCopyService(CopyService copyService)
{
this.copyService = copyService;
}
/**
* Add parameter definitions
*/
@Override
protected void addParameterDefintions(List<ParameterDefinition> paramList)
{
paramList.add(new ParameterDefinitionImpl(PARAM_MIME_TYPE, DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_MIME_TYPE)));
paramList.add(new ParameterDefinitionImpl(PARAM_DESTINATION_FOLDER, DataTypeDefinition.NODE_REF, true, getParamDisplayLabel(PARAM_DESTINATION_FOLDER)));
paramList.add(new ParameterDefinitionImpl(PARAM_ASSOC_TYPE_QNAME, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_ASSOC_TYPE_QNAME)));
paramList.add(new ParameterDefinitionImpl(PARAM_ASSOC_QNAME, DataTypeDefinition.QNAME, true, getParamDisplayLabel(PARAM_ASSOC_QNAME)));
}
/**
* @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.repository.NodeRef, org.alfresco.service.cmr.repository.NodeRef)
*/
@Override
protected void executeImpl(
Action ruleAction,
NodeRef actionedUponNodeRef)
{
if (this.nodeService.exists(actionedUponNodeRef) == false)
{
// node doesn't exist - can't do anything
return;
}
// First check that the node is a sub-type of content
QName typeQName = this.nodeService.getType(actionedUponNodeRef);
if (this.dictionaryService.isSubClass(typeQName, ContentModel.TYPE_CONTENT) == false)
{
// it is not content, so can't transform
return;
}
// Get the mime type
String mimeType = (String)ruleAction.getParameterValue(PARAM_MIME_TYPE);
// Get the details of the copy destination
NodeRef destinationParent = (NodeRef)ruleAction.getParameterValue(PARAM_DESTINATION_FOLDER);
QName destinationAssocTypeQName = (QName)ruleAction.getParameterValue(PARAM_ASSOC_TYPE_QNAME);
QName destinationAssocQName = (QName)ruleAction.getParameterValue(PARAM_ASSOC_QNAME);
// Copy the content node
NodeRef copyNodeRef = this.copyService.copy(
actionedUponNodeRef,
destinationParent,
destinationAssocTypeQName,
destinationAssocQName,
false);
// Get the content reader
ContentReader contentReader = this.contentService.getReader(actionedUponNodeRef, ContentModel.PROP_CONTENT);
if (contentReader == null)
{
// for some reason, this action is premature
throw new AlfrescoRuntimeException(
"Attempting to execute content transformation rule " +
"but content has not finished writing, i.e. no URL is available.");
}
String originalMimetype = contentReader.getMimetype();
// get the writer and set it up
ContentWriter contentWriter = this.contentService.getWriter(copyNodeRef, ContentModel.PROP_CONTENT, true);
contentWriter.setMimetype(mimeType); // new mimetype
contentWriter.setEncoding(contentReader.getEncoding()); // original encoding
// Adjust the name of the copy
String originalName = (String)nodeService.getProperty(actionedUponNodeRef, ContentModel.PROP_NAME);
String newName = transformName(originalName, originalMimetype, mimeType);
nodeService.setProperty(copyNodeRef, ContentModel.PROP_NAME, newName);
String originalTitle = (String)nodeService.getProperty(actionedUponNodeRef, ContentModel.PROP_TITLE);
if (originalTitle != null && originalTitle.length() > 0)
{
String newTitle = transformName(originalTitle, originalMimetype, mimeType);
nodeService.setProperty(copyNodeRef, ContentModel.PROP_TITLE, newTitle);
}
// Try and transform the content
try
{
doTransform(ruleAction, contentReader, contentWriter);
}
catch(NoTransformerException e)
{
if (logger.isDebugEnabled())
{
logger.debug("No transformer found to execute rule: \n" +
" reader: " + contentReader + "\n" +
" writer: " + contentWriter + "\n" +
" action: " + this);
}
// TODO: Revisit this for alternative solutions
nodeService.deleteNode(copyNodeRef);
}
}
protected void doTransform(Action ruleAction, ContentReader contentReader, ContentWriter contentWriter)
{
this.contentService.transform(contentReader, contentWriter);
}
/**
* Transform name from original extension to new extension
*
* @param original
* @param originalMimetype
* @param newMimetype
* @return
*/
private String transformName(String original, String originalMimetype, String newMimetype)
{
// get the current extension
int dotIndex = original.lastIndexOf('.');
StringBuilder sb = new StringBuilder(original.length());
if (dotIndex > -1)
{
// we found it
sb.append(original.substring(0, dotIndex));
}
else
{
// no extension
sb.append(original);
}
// add the new extension
String newExtension = mimetypeService.getExtension(newMimetype);
sb.append('.').append(newExtension);
// done
return sb.toString();
}
}