01-20-2012 01:35 PM
package org.alfresco.sample;
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.action.executer.ActionExecuterAbstractBase;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
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.model.FileFolderService;
import org.alfresco.service.cmr.model.FileInfo;
import org.alfresco.service.cmr.model.FileNotFoundException;
import org.alfresco.service.cmr.repository.ContentData;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.version.VersionType;
import org.alfresco.repo.version.VersionModel;
public class TraitementActionExecuter extends ActionExecuterAbstractBase{
public static final String NAME = "Traitement-Action";
public static final String PARAM_DESTINATION_FOLDER_0 = "destination-folder-0";
public static final String PARAM_DESTINATION_FOLDER_1 = "destination-folder-1";
public static final String PARAM_DESTINATION_FOLDER_2 = "destination-folder-2";
private NodeService nodeService;
private CheckOutCheckInService checkOutCheckInService;
private FileFolderService fileFolderService;
int pt1=0;
int pt2=0;
int pt0=0;
public void setNodeService(NodeService nodeService)
{
this.nodeService=nodeService;
}
public void setCheckOutCheckInService(CheckOutCheckInService checkOutCheckInService)
{
this.checkOutCheckInService = checkOutCheckInService;
}
public void setFileFolderService(FileFolderService fileFolderService)
{
this.fileFolderService=fileFolderService;
}
@Override
protected void executeImpl(Action MonAction, final NodeRef actionedUponNodeRef)
{
final NodeRef destinationParent0 = (NodeRef)MonAction.getParameterValue(PARAM_DESTINATION_FOLDER_0);
final NodeRef destinationParent1 = (NodeRef)MonAction.getParameterValue(PARAM_DESTINATION_FOLDER_1);
final NodeRef destinationParent2 = (NodeRef)MonAction.getParameterValue(PARAM_DESTINATION_FOLDER_2);
AuthenticationUtil.runAs(new AuthenticationUtil.RunAsWork<Void>()
{
public Void doWork() throws Exception
{
//… mon code Java …
try
{
List<FileInfo> listFichierEtDossier1 = fileFolderService.list(destinationParent1);
if(listFichierEtDossier1.isEmpty())
{
return null;
}
for( FileInfo fichierOuDossier : listFichierEtDossier1)
{
if(fichierOuDossier.isFolder())
{
// rien faire:fichierOuDossier est un dossier
}else if(fichierOuDossier.isLink())
{
// ne rien faire: fichierOuDossier est un link
}else {
// fichierOuDossier est fichier
if(nodeService.getPath(fichierOuDossier.getNodeRef())==nodeService.getPath(actionedUponNodeRef));
{
ContentData Contenu = (ContentData) nodeService.getProperty(actionedUponNodeRef, ContentModel.PROP_CONTENT);
nodeService.setProperty(fichierOuDossier.getNodeRef(), ContentModel.PROP_CONTENT, Contenu);
pt1++;
}
}
}
if(pt1==0)
{
fileFolderService.copy(actionedUponNodeRef, destinationParent1, null);
}
List<FileInfo> listFichierEtDossier2 = fileFolderService.list(destinationParent2);
if(listFichierEtDossier2.isEmpty())
{
return null;
}
for( FileInfo fichierOuDossier : listFichierEtDossier2)
{
if(fichierOuDossier.isFolder())
{
// rien faire:fichierOuDossier est un dossier
}
else if(fichierOuDossier.isLink())
{
// ne rien faire: fichierOuDossier est un link
}else {
// fichierOuDossier est fichier
if(nodeService.getPath(fichierOuDossier.getNodeRef())==nodeService.getPath(actionedUponNodeRef));
{
// changer le contenu du fichier existant
ContentData Contenu = (ContentData) nodeService.getProperty(actionedUponNodeRef, ContentModel.PROP_CONTENT);
ContentData newContenu = ContentData.setMimetype(Contenu, "application/PDF");
nodeService.setProperty(fichierOuDossier.getNodeRef(), ContentModel.PROP_CONTENT, newContenu);
pt2++;
}
}
}
// changer le format du fichier en PDF et l'ajouter au dossier
if(pt2==0)
{
NodeRef fichier = actionedUponNodeRef;
ContentData Contenu = (ContentData) nodeService.getProperty(fichier, ContentModel.PROP_CONTENT);
ContentData newContenu = ContentData.setMimetype(Contenu, "application/PDF");
nodeService.setProperty(fichier, ContentModel.PROP_CONTENT, newContenu);
fileFolderService.copy(fichier, destinationParent2, null);
}
// faire une verfication et une modification l'aspect du fichier
if(nodeService.hasAspect(actionedUponNodeRef, ContentModel.ASPECT_VERSIONABLE)==false)
{
nodeService.addAspect(actionedUponNodeRef,ContentModel.ASPECT_VERSIONABLE,null);
fileFolderService.move(actionedUponNodeRef, destinationParent0, null);
}
List<FileInfo> listFichierEtDossier0 = fileFolderService.list(destinationParent0);
if(!listFichierEtDossier0.isEmpty())
{
return null;
}
for( FileInfo fichierOuDossier : listFichierEtDossier0)
{
if(fichierOuDossier.isFolder())
{
// rien faire:fichierOuDossier est un dossier
}
else if(fichierOuDossier.isLink())
{
// ne rien faire: fichierOuDossier est un link
}else {
// fichierOuDossier est un fichier
if(nodeService.getPath(fichierOuDossier.getNodeRef())==nodeService.getPath(actionedUponNodeRef));
{
//(nodeService.getPath(fichierOuDossier.getNodeRef())).equals(nodeService.getPath(actionedUponNodeRef));
checkOutCheckInService.checkout(fichierOuDossier.getNodeRef());
NodeRef copieDeTravail=checkOutCheckInService.getWorkingCopy(fichierOuDossier.getNodeRef());
ContentData Contenu = (ContentData) nodeService.getProperty(actionedUponNodeRef, ContentModel.PROP_CONTENT);
nodeService.setProperty(copieDeTravail, ContentModel.PROP_CONTENT, Contenu);
Map<String,Serializable> versionProperties = new HashMap<String,Serializable>();
versionProperties.put(VersionModel.PROP_VERSION_TYPE, VersionType.MAJOR);
checkOutCheckInService.checkin(copieDeTravail, versionProperties);
pt0++;
}
}
}
if(pt0==0)
{
fileFolderService.copy(actionedUponNodeRef, destinationParent0, null);
}
}
catch (FileNotFoundException e)
{
// ne rien faire
}
return null;
}
}, "admin");
}
@Override
protected void addParameterDefinitions(List<ParameterDefinition> paramList) {
paramList.add(new ParameterDefinitionImpl(PARAM_DESTINATION_FOLDER_0,
DataTypeDefinition.NODE_REF,
true,
getParamDisplayLabel(PARAM_DESTINATION_FOLDER_0)));
paramList.add(new ParameterDefinitionImpl(PARAM_DESTINATION_FOLDER_1,
DataTypeDefinition.NODE_REF,
true,
getParamDisplayLabel(PARAM_DESTINATION_FOLDER_1)));
paramList.add(new ParameterDefinitionImpl(PARAM_DESTINATION_FOLDER_2,
DataTypeDefinition.NODE_REF,
true,
getParamDisplayLabel(PARAM_DESTINATION_FOLDER_2)));
}
}
# Action title and description
traitement-action.title=Actualisation de documents
traitement-action.description=Cette action permet d'ajouter une nouvelle version et d'actualiser le document
# Action parameter display labels
traitement-action.param_destination_folder_0.display-label=Documents Versionnés
traitement-action.param_destination_folder_1.display-label=Documents VF
traitement-action.param_destination_folder_2.display-label=Documents PDF
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
<beans>
<!– Traitement Action Bean –>
<bean id="Traitement-Action" class="org.alfresco.sample.TraitementActionExecuter" parent="action-executer">
<property name="nodeService">
<ref bean="nodeService" />
</property>
</bean>
<!– Load the Traitement Action Messages –>
<bean id="traitement-action-messages" class="org.alfresco.i18n.ResourceBundleBootstrapComponent">
<property name="resourceBundles">
<list>
<value>org.alfresco.sample.traitement-action-messages</value>
</list>
</property>
</bean>
</beans>
<?xml version="1.0"?>
<project name="Traitement Action" default="package-jar" basedir=".">
<property name="project.dir" value="."/>
<property name="build.dir" value="${project.dir}/build"/>
<property name="config.dir" value="${project.dir}/config"/>
<property name="package.file.jar" value="${build.dir}/traitement.jar"/>
<property name="package.file.zip" value="${build.dir}/traitement.zip"/>
<path id="class.path">
<dirset dir="${build.dir}" />
<fileset dir="../../lib/server" includes="**/*.jar"/>
</path>
<target name="compile">
<mkdir dir="${build.dir}" />
<javac classpathref="class.path" srcdir= "${project.dir}/source" destdir="${build.dir}" />
</target>
<target name="package-jar">
<delete file="${package.file.jar}" />
<jar destfile="${package.file.jar}">
<fileset dir="${build.dir}" excludes="*.zip"/>
<fileset dir="${config.dir}"/>
</jar>
</target>
<target name="package-extension" depends="package-jar">
<delete file="${package.file.zip}" />
<zip destfile="${package.file.zip}">
<zipfileset file="${package.file.jar}" prefix="WEB-INF/lib" />
</zip>
</target>
<target name="integrate-extension" depends="package-extension">
<available file="alfresco.war" type="file" property="alfresco.war.present" />
<fail unless="alfresco.war.present" message="Could not find alfresco.war, please copy it to ${basedir}" />
<zip destfile="alfresco.war" update="true">
<zipfileset file="${package.file.jar}" prefix="WEB-INF/lib" />
</zip>
</target>
</project>
01-22-2012 02:00 AM
01-23-2012 04:38 AM
01-30-2012 04:03 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.