05-07-2010 11:49 AM
05-10-2010 09:14 AM
05-10-2010 10:01 AM
package com.ixxus.projectname.alfresco.actions.importer;
import java.io.File;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.action.executer.ImporterActionExecuter;
import org.alfresco.repo.content.MimetypeMap;
import org.alfresco.repo.importer.ACPImportPackageHandler;
import org.alfresco.service.cmr.action.Action;
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.ImporterBinding;
import org.alfresco.service.cmr.view.ImporterService;
import org.alfresco.service.cmr.view.Location;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.TempFileProvider;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class ACPImportActionExecuter extends ImporterActionExecuter
{
private static final Log log = LogFactory.getLog(ACPImportActionExecuter.class);
public static final String NAME = "custom-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 = ".acp";
private ImporterBinding.UUID_BINDING uuidBinding;
private ImporterService importerService;
private NodeService nodeService;
private ContentService contentService;
public void setImporterService(ImporterService importerService) {
this.importerService = importerService;
}
public void setNodeService(NodeService nodeService) {
this.nodeService = nodeService;
}
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)
*/
@Override
public void executeImpl(Action ruleAction, NodeRef actionedUponNodeRef) {
log.error("actionedUponNodeRef:" + 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)
{
NodeRef importDest = (NodeRef)ruleAction.getParameterValue(PARAM_DESTINATION_FOLDER);
log.error("importDest:" + importDest + " actionedUponNodeRef:" + actionedUponNodeRef);
if (MimetypeMap.MIMETYPE_ACP.equals(reader.getMimetype()))
{
// perform an import of an Alfresco ACP file (special format ZIP structure)
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_ACP);
reader.getContent(zipFile);
ACPImportPackageHandler importHandler = new ACPImportPackageHandler(zipFile,
(String)ruleAction.getParameterValue(PARAM_ENCODING));
this.importerService.importView(importHandler, new Location(importDest), getBinding(), null);
}
finally
{
// now the import is done, delete the temporary file
if (zipFile != null)
{
zipFile.delete();
}
}
}
}
}
}
private ImporterBinding getBinding() {
ImporterBinding binding = new ImporterBinding() {
public boolean allowReferenceWithinTransaction() {
return false;
}
public QName[] getExcludedClasses() {
return null;
}
public UUID_BINDING getUUIDBinding() {
return uuidBinding;
}
public String getValue(String key) {
return null;
}
};
// Uses UPDATE_EXISTING as usage of REPLACE_EXISTING removes child nodes if these are not sent over in the export.
uuidBinding = ImporterBinding.UUID_BINDING.UPDATE_EXISTING;
return binding;
}
}
<bean id="custom-import" class="com.ixxus.projectname.alfresco.actions.importer.ACPImportActionExecuter" parent="action-executer">
<property name="importerService">
<ref bean="ImporterService"/>
</property>
<property name="nodeService">
<ref bean="NodeService"></ref>
</property>
<property name="contentService">
<ref bean="ContentService" />
</property>
</bean>05-10-2010 08:37 PM
20:17:22,740 User:admin ERROR [ui.common.Utils] Failed to create content due to error: 04100002 Failed to execute script 'workspace://SpacesStore/fe58573b-95fe-4b63-a6bd-39867247d86a': Failed to import package at line 27; column 20 due to error: Duplicate child name not allowed: mySite
org.alfresco.scripts.ScriptException: 04100002 Failed to execute script 'workspace://SpacesStore/fe58573b-95fe-4b63-a6bd-39867247d86a': Failed to import package at line 27; column 20 due to error: Duplicate child name not allowed: mySite
at org.alfresco.repo.jscript.RhinoScriptProcessor.execute(RhinoScriptProcessor.java:228)
at org.alfresco.repo.processor.ScriptServiceImpl.executeScript(ScriptServiceImpl.java:187)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:304)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149)
at org.alfresco.repo.security.permissions.impl.AlwaysProceedMethodInterceptor.invoke(AlwaysProceedMethodInterceptor.java:40)
….
05-11-2010 03:58 AM
Tags
Find what you came for
We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.