cancel
Showing results for 
Search instead for 
Did you mean: 

Recupération du nodeRef dans une action

huberd
Champ in-the-making
Champ in-the-making
Bonjour,

Je viens de développer une action vide pour le moment et qui me permettra d'éffectuer une action bien précise sur le document associé à l'action.

J'ai déclaré mon bean comme ceci

    <bean id="CheckInOutBean" class="lpr.alfresco.web.bean.CheckInOutBean" init-method="init">

    </bean>

mon action comme ceci

         <action id="check_out_document">
            <evaluator>
               lpr.alfresco.delegation.evaluator.DirAccessEvaluator
            </evaluator>
            <label-id>check_out_document</label-id>
            <image>/images/extension/icons/create_user.gif</image>
            <action-listener>#{CheckInOutBean.out}</action-listener>
            <params>
               <param name="id">#{actionContext.id}</param>
            </params>
         </action>

et voici le code de mon action

package lpr.alfresco.web.bean;

import javax.faces.event.ActionEvent;
import org.alfresco.web.bean.BrowseBean;

public class CheckInOutBean {
   
   //private static Log logger = LogFactory.getLog(CheckInOutBean.class);
    protected BrowseBean browseBean;
   
   // private NodeRef nodeRef = null;
      
   public void init()
   {
      System.out.println("Init");
   }
     
   public void out(ActionEvent event) {
      try {
         System.out.println("CheckOut Document ");

         // Ici reste du code à écrire
         
      } catch (Exception e) {
         // TODO: handle exception
         e.printStackTrace();
      }
   }
}

Pour le moment mon action fonctionne et me loggue bien CheckOut Document dans le fichier de log, ce qui est déjà pas si mal  :wink:

Mais bon, je cherche pour pouvoir continuer le reste à récuperer le nodeRef du document sur lequel l'action a été lancé afin de pouvoir faire mes opérations.

Si quelqu'un peut m'aider, je lui en serai très reconnaissant.

Merci d'avance pour votre aide précieuse.
8 REPLIES 8

pdubois
Champ on-the-rise
Champ on-the-rise
Votre action doit dériver de
public class  ActionExecuterAbstractBase

Je vous conseille d'examiner les exemples suivants livrés avec le SDK:
SDK Custom Action et SDK TaggingSample.

Exemple:
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.

* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

* As a special exception to the terms and conditions of version 2.0 of
* the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception.  You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing"
*/
package org.alfresco.sample;

import java.util.List;

import org.alfresco.repo.action.ParameterDefinitionImpl;
import org.alfresco.repo.action.executer.ActionExecuterAbstractBase;
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;

/**
* Logger action executer.
*
* This action will log a message to the application log file at the level specified.
*
* @author Roy Wetherall
*/
public class LoggerActionExecuter extends ActionExecuterAbstractBase
{
    /** The logger */
    private static Log logger = LogFactory.getLog("org.alfresco.sample");
   
    /** The name of the action */
    public static final String NAME = "logger-action";   
   
    /** The parameter names */
    public static final String PARAM_LOG_MESSAGE = "param-log-message";
    public static final String PARAM_LOG_LEVEL = "param-log-level";
   
    /**
     * This action will take the log message and log it at the provided log level.
     *
     * If the log level is not provided the default will be INFO.
     *
     * @see org.alfresco.repo.action.executer.ActionExecuterAbstractBase#executeImpl(org.alfresco.service.cmr.action.Action, org.alfresco.service.cmr.repository.NodeRef)
     */
    @Override
    protected void executeImpl(Action action, NodeRef actionedUponNodeRef)
    {
        // Get the log message parameter
        String logMessage = (String)action.getParameterValue(PARAM_LOG_MESSAGE);
        if (logMessage != null && logMessage.length() != 0)
        {
            // Get the log level (default to INFO)
            LogLevel logLevel = LogLevel.INFO;
            String logLevelParam = (String) action.getParameterValue(PARAM_LOG_LEVEL);
            if (logLevelParam != null && logLevelParam.length() != 0)
            {
                logLevel = LogLevel.valueOf(logLevelParam);
            }
           
            // Log the message based on the log level
            switch (logLevel)
            {
                case DEBUG:
                {
                    logger.debug(logMessage);
                    break;
                }
                case ERROR:
                {
                    logger.error(logMessage);
                    break;
                }
                case FATAL:
                {
                    logger.fatal(logMessage);
                    break;
                }
                case INFO:
                {
                    logger.info(logMessage);
                    break;
                }
                case TRACE:
                {
                    logger.trace(logMessage);
                    break;
                }
                case WARN:
                {
                    logger.warn(logMessage);
                    break;
                }
            }
        }
    }

    /**
     *  @see org.alfresco.repo.action.ParameterizedItemAbstractBase#addParameterDefinitions(java.util.List)
     */
    @Override
    protected void addParameterDefinitions(List<ParameterDefinition> paramList)
    {
        // Specify the parameters
        paramList.add(new ParameterDefinitionImpl(PARAM_LOG_MESSAGE, DataTypeDefinition.TEXT, true, getParamDisplayLabel(PARAM_LOG_MESSAGE)));
        paramList.add(new ParameterDefinitionImpl(PARAM_LOG_LEVEL, DataTypeDefinition.TEXT, false, getParamDisplayLabel(PARAM_LOG_LEVEL)));
    }
   
    /**
     * Helper enum to differentiate log levels
     */
    private enum LogLevel
    {
        DEBUG, ERROR, FATAL, INFO, WARN, TRACE
    }
}

Il est possible de télécharger le SDK à:

http://wiki.alfresco.com/wiki/Download_Alfresco_Community_Network

Pour installer le SDK: http://wiki.alfresco.com/wiki/Alfresco_SDK


Bon travail.

huberd
Champ in-the-making
Champ in-the-making
Votre action doit dériver de
public class  ActionExecuterAbstractBase

Je vous conseille d'examiner les exemples suivants livrés avec le SDK:
SDK Custom Action et SDK TaggingSample.

Exemple:
/*
* Copyright (C) 2005-2007 Alfresco Software Limited.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.

Il est possible de télécharger le SDK à:

http://wiki.alfresco.com/wiki/Download_Alfresco_Community_Network

Pour installer le SDK: http://wiki.alfresco.com/wiki/Alfresco_SDK


Bon travail.

Bonjour,

il me semble que les exemples énoncés ne sont pas en adéquation avec ce que je recherche. Je ne cherche pas à créer une action applicable par règle, mais une action executable par l'utilisateur comme les action Copier, Coller, Mettre à jour, …

huberd
Champ in-the-making
Champ in-the-making
Bon à priori, je commence à y voir plus clair, mais me voici à nouveau bloqué.

Voici mes fichiers de configuration de mon action :

alfresco\extension\custom-model-context.xml

    <bean id="CheckInOutBean" class="lpr.alfresco.web.bean.CheckInOutBean" init-method="init">
       <property name="nodeService">
          <ref bean="nodeService" />
       </property>
    </bean>

alfresco\extension\web-client-config-custom.xml

      <actions>

         <action id="check_out_document">
            <evaluator>
               lpr.alfresco.delegation.evaluator.DirAccessEvaluator
            </evaluator>
            <label-id>check_out_document</label-id>
            <image>/images/extension/icons/create_user.gif</image>
            <!–action>dialog:manageDelegInvitedUsers</action>
            <action-listener>#{BrowseBean.setupSpaceAction}</action-listener–>
            <action-listener>#{CheckInOutBean.out}</action-listener>
            <params>
               <param name="ref">#{actionContext.nodeRef}</param>
               <!–<param name="parent">#{NavigationBean.currentNodeId}</param>–>
            </params>
         </action>

         <!– Actions Menu for a document in the Browse screen –>
         <action-group id="document_browse_menu">
            <action idref="check_out_document" />
         </action-group>
      </actions>

Source de mon bean CheckInOutBean

package lpr.alfresco.web.bean;

import java.util.Map;
import javax.faces.event.ActionEvent;
import org.alfresco.model.ContentModel;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.web.bean.BrowseBean;
import org.alfresco.web.ui.common.component.UIActionLink;

public class CheckInOutBean {
   
   //private static Log logger = LogFactory.getLog(CheckInOutBean.class);
   protected BrowseBean browseBean;
   private NodeService nodeService;   
      
   public void init() {
      System.out.println("Init"); 
   }
   
   /**
    * @return Returns the BrowseBean.
    */   
   public BrowseBean getBrowseBean() {
      return this.browseBean;
   }
     
   /**
    * @param browseBean The BrowseBean to set.
    */
   public void setBrowseBean(BrowseBean browseBean) {
      this.browseBean = browseBean;
   }   

   /**
    * @return Returns the NodeService.
    */
   public NodeService getNodeService() {
      return this.nodeService;
   }

   /**       
    * @param nodeService The NodeService to set.
    */
   public void setNodeService(NodeService nodeService) {
      this.nodeService = nodeService;
   }  
  
   public void out(ActionEvent event) {
      try {
         System.out.println("CheckOut Document ");
         UIActionLink link = (UIActionLink)event.getComponent();
          Map<String, String> params = link.getParameterMap();
          String ref = params.get("ref");
          if (ref != null && ref.length() != 0)
          {
             NodeRef myNode = new NodeRef(ref);
             System.out.println("My node ref: " + myNode);
             
             String DocumentName = (String)nodeService.getProperty(myNode, ContentModel.PROP_NAME);
            System.out.println("Doc name : " + DocumentName);
          }
         // Ici reste du code à écrire
         
         
      } catch (Exception e) {
         // TODO: handle exception
         e.printStackTrace();
      }
   }
}

Maintenant, je n'arrive pas à utiliser le nodeService, et j'obtiens le message d'erreur suivant:

CheckOut Document 
My node ref: workspace://SpacesStore/6a0aade6-15ed-11dd-886c-bd82866ddcfa
org.alfresco.error.AlfrescoRuntimeException: Transaction must be active and synchronization is required
   at org.alfresco.repo.transaction.AlfrescoTransactionSupport.registerSynchronizations(AlfrescoTransactionSupport.java:399)
   at org.alfresco.repo.transaction.AlfrescoTransactionSupport.getSynchronization(AlfrescoTransactionSupport.java:384)
   at org.alfresco.repo.transaction.AlfrescoTransactionSupport.bindDaoService(AlfrescoTransactionSupport.java:238)
   at org.alfresco.repo.transaction.TransactionalDaoInterceptor.invoke(TransactionalDaoInterceptor.java:66)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
   at $Proxy1.getNode(Unknown Source)
   at org.alfresco.repo.node.db.DbNodeServiceImpl.getNodeNotNull(DbNodeServiceImpl.java:128)
   at org.alfresco.repo.node.db.DbNodeServiceImpl.getProperty(DbNodeServiceImpl.java:930)
   at sun.reflect.GeneratedMethodAccessor118.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
   at org.alfresco.repo.transaction.TransactionResourceInterceptor.invoke(TransactionResourceInterceptor.java:129)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
   at $Proxy2.getProperty(Unknown Source)
   at sun.reflect.GeneratedMethodAccessor118.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.alfresco.repo.service.StoreRedirectorProxyFactory$RedirectorInvocationHandler.invoke(StoreRedirectorProxyFactory.java:221)
   at $Proxy3.getProperty(Unknown Source)
   at sun.reflect.GeneratedMethodAccessor118.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
   at org.alfresco.repo.node.MLPropertyInterceptor.invoke(MLPropertyInterceptor.java:145)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
   at $Proxy2.getProperty(Unknown Source)
   at lpr.alfresco.web.bean.CheckInOutBean.out(CheckInOutBean.java:82)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
   at java.lang.reflect.Method.invoke(Unknown Source)
   at org.apache.myfaces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:132)
   at javax.faces.component.UICommand.broadcast(UICommand.java:89)
   at javax.faces.component.UIViewRoot._broadcastForPhase(UIViewRoot.java:97)
   at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:171)
   at org.apache.myfaces.lifecycle.InvokeApplicationExecutor.execute(InvokeApplicationExecutor.java:32)
   at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:95)
   at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:70)
   at javax.faces.webapp.FacesServlet.service(FacesServlet.java:139)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
   at org.alfresco.web.app.servlet.NTLMAuthenticationFilter.processType3(NTLMAuthenticationFilter.java:899)
   at org.alfresco.web.app.servlet.NTLMAuthenticationFilter.doFilter(NTLMAuthenticationFilter.java:402)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
   at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:834)
   at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:640)
   at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1286)
   at java.lang.Thread.run(Unknown Source)

Si quelqu'un a une idée…
Je me suis basé sur le document suivant : http://forge.alfresco.com/frs/download.php/82/subscription.pdf

Merci pour votre aide

rivarola
Champ on-the-rise
Champ on-the-rise
Bonjour,

J'ai vu que tu avais injecté le nodeService avec un petit n dans ton bean :

 <property name="nodeService">
          <ref bean="nodeService" />
       </property>

Or le nodeService est sous la couche d'intercepteurs de transaction. Essaie avec le NodeService (grand N). Peut-être que ça changera qqchose…

huberd
Champ in-the-making
Champ in-the-making
Bonjour,

J'ai vu que tu avais injecté le nodeService avec un petit n dans ton bean :

 <property name="nodeService">
          <ref bean="nodeService" />
       </property>

Or le nodeService est sous la couche d'intercepteurs de transaction. Essaie avec le NodeService (grand N). Peut-être que ça changera qqchose…

non, non, je t'assure que la syntaxe est bonne  :wink:

rivarola
Champ on-the-rise
Champ on-the-rise
Je n'ai pas dit que la syntaxe était mauvaise, mais que tu injectais le mauvais bean…

huberd
Champ in-the-making
Champ in-the-making
Je n'ai pas dit que la syntaxe était mauvaise, mais que tu injectais le mauvais bean…

En faite, j'ai trouvé la solution à mon problème. La déclaration de mon bean n'était pas correcte. Les actions personnalisé que l'on retrouve directemnt sur les documents ne doivent pas être déclarées dans la fichier alfresco\extension\custom-model-context.xml comme je l'ai fait ci-dessous.

    <bean id="CheckInOutBean" class="lpr.alfresco.web.bean.CheckInOutBean" init-method="init">
       <property name="nodeService">
          <ref bean="nodeService" />
       </property>
    </bean>

mais dans le fichier faces-config-beans.xml situé dans le dossier WEB-INF
   <managed-bean>
      <description>
         The bean that backs up the Checkin and Checkout pages.
      </description>
      <managed-bean-name>CheckInOutBean</managed-bean-name>
      <managed-bean-class>lpr.alfresco.web.bean.CheckInOutBean</managed-bean-class>
      <managed-bean-scope>session</managed-bean-scope>
      <managed-property>
         <property-name>browseBean</property-name>
         <value>#{BrowseBean}</value>
      </managed-property>
      <managed-property>
         <property-name>nodeService</property-name>
         <value>#{NodeService}</value>
      </managed-property>
      <managed-property>
         <property-name>authenticationService</property-name>
         <value>#{AuthenticationService}</value>
      </managed-property>
      <managed-property>
         <property-name>permissionService</property-name>
         <value>#{PermissionService}</value>
      </managed-property>
      <managed-property>
         <property-name>fileFolderService</property-name>
         <value>#{FileFolderService}</value>
      </managed-property>
      <managed-property>
         <property-name>copyService</property-name>
          <value>#{CopyService}</value>
      </managed-property>
   </managed-bean>

et voici le code de mon action corrigé
package lpr.alfresco.web.bean;

import java.text.MessageFormat;
import java.util.Map;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import lpr.alfresco.definitions.LprConstante;
import lpr.alfresco.model.LprContentModel;
//import lpr.alfresco.util.MyLogger;
import org.alfresco.model.ContentModel;
//import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.repository.CopyService;
import org.alfresco.service.cmr.repository.InvalidNodeRefException;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.security.AuthenticationService;
import org.alfresco.service.cmr.security.PermissionService;
import org.alfresco.service.namespace.NamespaceService;
import org.alfresco.service.namespace.QName;
import org.alfresco.web.app.AlfrescoNavigationHandler;
import org.alfresco.web.app.Application;
import org.alfresco.web.app.context.UIContextService;
import org.alfresco.web.bean.BrowseBean;
import org.alfresco.web.bean.repository.Node;
import org.alfresco.web.bean.repository.Repository;
import org.alfresco.web.ui.common.Utils;
import org.alfresco.web.ui.common.component.UIActionLink;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class CheckInOutBean {

    /** Parameters to add in alfresco\WEB-INF\faces-config-navigation.xml
     *
     * <navigation-case>
     *    <from-outcome>cancelCheckoutFile</from-outcome>
     *    <to-view-id>/jsp/dialog/cancelcheckout-file.jsp</to-view-id>
     * </navigation-case>
   */
   
   /** Parameters to add in alfresco\WEB-INF\faces-config-beans.xml
    *
    *    <managed-bean>
     *       <description>
     *          The bean that backs up the Checkin and Checkout pages.
     *       </description>
     *       <managed-bean-name>CheckInOutBean</managed-bean-name>
     *       <managed-bean-class>org.alfresco.web.bean.CheckinCheckoutBean</managed-bean-class>
     *       <managed-bean-scope>session</managed-bean-scope>
     *       <managed-property>
     *          <property-name>browseBean</property-name>
     *          <value>#{BrowseBean}</value>
     *       </managed-property>
     *       <managed-property>
     *          <property-name>navigator</property-name>
     *          <value>#{NavigationBean}</value>
     *       </managed-property>
     *       <managed-property>
     *          <property-name>nodeService</property-name>
     *          <value>#{NodeService}</value>
     *       </managed-property>
     *       <managed-property>
     *          <property-name>authenticationService</property-name>
     *          <value>#{AuthenticationService}</value>
     *       </managed-property>
     *       <managed-property>
     *          <property-name>permissionService</property-name>
     *          <value>#{PermissionService}</value>
     *       </managed-property>
     *       <managed-property>
     *          <property-name>fileFolderService</property-name>
     *          <value>#{FileFolderService}</value>
     *       </managed-property>
     *       <managed-property>
     *          <property-name>copyService</property-name>
     *          <value>#{CopyService}</value>
     *       </managed-property>      
     *    </managed-bean>
    */
   
   // ——————————————————————————
   // Bean property getters and setters    
   /**
    * @return Returns the BrowseBean.
    */
   public BrowseBean getBrowseBean()
   {
      return this.browseBean;
   }
  
   /**
    * @param browseBean The BrowseBean to set.
    */
   public void setBrowseBean(BrowseBean browseBean)
   {
      this.browseBean = browseBean;
   }
  
   /**
    * @return Returns the NodeService.
    */
   public NodeService getNodeService()
   {
      return this.nodeService;
   }

   /**
    * @param nodeService The NodeService to set.
    */
   public void setNodeService(NodeService nodeService)
   {
      this.nodeService = nodeService;
   }   
   
   /**
    * @return Returns the AuthenticationService.
    */
   public AuthenticationService getAuthenticationService()
   {
      return this.authenticationService;
   }

   /**
    * @param nodeService The AuthenticationService to set.
    */
   public void setAuthenticationService(AuthenticationService authenticationService)
   {
      this.authenticationService = authenticationService;
   }   
  
   /**
    * @return Returns the PermissionService.
    */
   public PermissionService getPermissionService()
   {
      return this.permissionService;
   }

   /**
    * @param nodeService The PermissionService to set.
    */
   public void setPermissionService(PermissionService permissionService)
   {
      this.permissionService = permissionService;
   }   
  
   /**
    * @return Returns the FileFolderService.
    */
   public FileFolderService getFileFolderService()
   {
      return this.fileFolderService;
   }

   /**
    * @param nodeService The FileFolderService to set.
    */
   public void setFileFolderService(FileFolderService fileFolderService)
   {
      this.fileFolderService = fileFolderService;
   }   
  
   /**
    * @return Returns the CopyService.
    */
   public CopyService getCopyService()
   {
      return this.copyService;
   }

   /**
    * @param nodeService The CopyService to set.
    */
   public void setCopyService(CopyService copyService)
   {
      this.copyService = copyService;
   }     
  
   /**
    * @return The document node being used for the current operation
    */
   public Node getDocument()
   {
      return this.document;
   }

   /**
    * @param document The document node to be used for the current operation
    */
   public void setDocument(Node document)
   {
      this.document = document;
   }
  
   /**
    * @return Returns the working copy Document.
    */
   public Node getWorkingDocument()
   {
      return this.workingDocument;
   }

   /**
    * @param workingDocument The working copy Document to set.
    */
   public void setWorkingDocument(Node workingDocument)
   {
      this.workingDocument = workingDocument;
   }  
  
   // ——————————————————————————
   // Navigation action event handlers
  
   /**
    * Action event
    *
    * @param event   ActionEvent
    */
   public void setupContentAction(ActionEvent event)
   {
     //MyLogger.debugln("lpr.alfresco.web.bean.CheckInOutBean.setupContentAction (Start)",1);
      UIActionLink link = (UIActionLink)event.getComponent();
      Map<String, String> params = link.getParameterMap();
      String id = params.get("id");
      if (id != null && id.length() != 0)
      {
         setupContentDocument(id);
      }
      else
      {
         setDocument(null);
      }
      //MyLogger.debugln("lpr.alfresco.web.bean.CheckInOutBean.setupContentAction (End)",1);
   }  
  
   /**
    * Setup a content document node context
    *
    * @param id      GUID of the node to setup as the content document context
    *
    * @return The Node
    */
   private Node setupContentDocument(String id)
   {
     //MyLogger.debugln("lpr.alfresco.web.bean.CheckInOutBean.setupContentDocument (Start)",1);
      if (logger.isDebugEnabled())
         logger.debug("Setup for action, setting current document to: " + id);

      Node node = null;
     
      try
      {
         // create the node ref, then our node representation
         NodeRef ref = new NodeRef(Repository.getStoreRef(), id);
         node = new Node(ref);
        
         // remember the document
         setDocument(node);
        
         // refresh the UI, calling this method now is fine as it basically makes sure certain
         // beans clear the state - so when we finish here other beans will have been reset
         UIContextService.getInstance(FacesContext.getCurrentInstance()).notifyBeans();
      }
      catch (InvalidNodeRefException refErr)
      {
         Utils.addErrorMessage(MessageFormat.format(Application.getMessage(
               FacesContext.getCurrentInstance(), Repository.ERROR_NODEREF), new Object[] {id}) );
      }
      //MyLogger.debugln("lpr.alfresco.web.bean.CheckInOutBean.setupContentDocument (End)",1);
      return node;
   }   
  
   /**
    * Action to undo the checkout of a document just checked out from the checkout screen.
    */
   public String undoCheckout()
   {
     //MyLogger.debugln("lpr.alfresco.web.bean.CheckInOutBean.undoCheckout (Start)",1);
      String outcome = null;
     
      Node node = getDocument();
      //System.out.println("Node: " + node.getNodeRef());
      if (node != null)
      {
         try
         {
            // try to cancel checkout of the working copy
           AuthenticationService auth = getAuthenticationService();
           auth.authenticate(WORKFLOW_USER, WORKFLOW_PASSWORD.toCharArray());
           NodeRef originalNode = new NodeRef((String)(LprConstante.WORKSPACE_BASE + "/" + nodeService.getProperty(node.getNodeRef(), LprContentModel.PROP_ORIGINE_NODE)));
          //System.out.println("Original node Ref: " + originalNode);
          if (nodeService.hasAspect(originalNode, LprContentModel.ASPECT_WORKING_COPY) == true) {
            nodeService.removeAspect(originalNode, LprContentModel.ASPECT_WORKING_COPY);
         }
          // Delete copy
           this.fileFolderService.delete(node.getNodeRef());
           
            outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
         }
         catch (Throwable err)
         {
            Utils.addErrorMessage(Application.getMessage(
                  FacesContext.getCurrentInstance(), MSG_ERROR_CANCELCHECKOUT) + err.getMessage(), err);
         }
      }
      else
      {
         logger.warn("WARNING: undoCheckout called without a current WorkingDocument!");
      }
      //MyLogger.debugln("lpr.alfresco.web.bean.CheckInOutBean.undoCheckout (End)",1);
      return outcome;
   }

   /**
    * Action to checkout a document.
    */
   public void checkOut(ActionEvent event)
   {
     //MyLogger.debugln("lpr.alfresco.web.bean.CheckInOutBean.Checkout (Start)",1);
     setupContentAction(event);
      Node node = getDocument();
      //System.out.println("Node: " + node.getNodeRef());
      if (node != null)
      {
         try
         {
            // try to cancel checkout of the working copy
           AuthenticationService auth = getAuthenticationService();
           String Currentuser = authenticationService.getCurrentUserName();
          //System.out.println("Current user : " + Currentuser);
           auth.authenticate(WORKFLOW_USER, WORKFLOW_PASSWORD.toCharArray());

           // Get the Draft nodeRef
           NodeRef nodeBase = new NodeRef((String)(LprConstante.WORKSPACE_BASE + "/" + nodeService.getProperty(node.getNodeRef(), LprContentModel.PROP_BASE_CONTENT_NODE)));
           NodeRef nodeChild = this.nodeService.getChildByName(nodeBase, ContentModel.ASSOC_CONTAINS, LprConstante.SPACE_DRAFTS);
         //System.out.println("Draft Folder : " + nodeService.getProperty(nodeChild, ContentModel.PROP_NAME));
           
         // Make copy of document
         String docname = (String)nodeService.getProperty(node.getNodeRef(), ContentModel.PROP_NAME);
         String qname = QName.createValidLocalName(docname);
         NodeRef copyNodeRef = copyService.copy(node.getNodeRef(), nodeChild,ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, qname), true);
         nodeService.setProperty(copyNodeRef, ContentModel.PROP_NAME, docname);
         
           //copyService = getCopyService();
           //permissionService = getPermissionService();
           
         // Change Document Status and Permission
         nodeService.setProperty(copyNodeRef, LprContentModel.PROP_STATUS, LprConstante.STATUS_DRAFT);
         permissionService.setPermission(copyNodeRef, Currentuser, PermissionService.EDITOR, true);
         
         // Add Aspect Working Copy and backup the copy nodeRef in the original document
         if (nodeService.hasAspect(node.getNodeRef(), LprContentModel.ASPECT_WORKING_COPY) == false) {
            nodeService.addAspect(node.getNodeRef(), LprContentModel.ASPECT_WORKING_COPY, null);
         }
         nodeService.setProperty(node.getNodeRef(), LprContentModel.PROP_WORKING_COPY_NODE, copyNodeRef.getId());
         
         // Add Aspect Origine Copy on the copy and backup the origine nodeRef
         if (nodeService.hasAspect(copyNodeRef, LprContentModel.ASPECT_ORIGINE) == false) {
            nodeService.addAspect(copyNodeRef, LprContentModel.ASPECT_ORIGINE, null);
         }
         nodeService.setProperty(copyNodeRef, LprContentModel.PROP_ORIGINE_NODE, node.getNodeRef().getId());
           
           //outcome = AlfrescoNavigationHandler.CLOSE_DIALOG_OUTCOME;
         }
         catch (Throwable err)
         {
            Utils.addErrorMessage(Application.getMessage(
                  FacesContext.getCurrentInstance(), MSG_ERROR_CANCELCHECKOUT) + err.getMessage(), err);
         }
      }
      else
      {
         logger.warn("WARNING: undoCheckout called without a current WorkingDocument!");
      }
     //MyLogger.debugln("lpr.alfresco.web.bean.CheckInOutBean.Checkout (End)",1);
   }
  


  
   /**
    * CheckOut Document
    * @param event
    */  
   /*public void out(ActionEvent event) {
      MyLogger.debugln("lpr.alfresco.web.bean.CheckInOutBean.out (Start)",1);
      try {
         System.out.println("CheckOut Document ");
         UIActionLink link = (UIActionLink)event.getComponent();
          Map<String, String> params = link.getParameterMap();
          String ref = params.get("ref");
          if (ref != null && ref.length() != 0)
          {
             NodeRef nodeRef = new NodeRef(ref);
             System.out.println("My node ref: " + nodeRef);

             // search for node current user
            FacesContext context = FacesContext.getCurrentInstance();
            
            // Obtain the ServiceRegistry
             serviceRegistry = Repository.getServiceRegistry(context);
             
             // Obtain the services we need from the ServiceRegistry
             nodeService = serviceRegistry.getNodeService();
             authenticationService = serviceRegistry.getAuthenticationService();             
             //namespaceService = serviceRegistry.getNamespaceService();
             copyService = serviceRegistry.getCopyService();
             permissionService = serviceRegistry.getPermissionService();
             
             String Currentuser = authenticationService.getCurrentUserName();
             System.out.println("Current user : " + Currentuser);
             authenticationService.authenticate(WORKFLOW_USER, WORKFLOW_PASSWORD.toCharArray());
             String docname = (String)nodeService.getProperty(nodeRef, ContentModel.PROP_NAME);
             
             //authenticationService.clearCurrentSecurityContext();
             NodeRef nodeBase = new NodeRef((String)(LprConstante.WORKSPACE_BASE + "/" + nodeService.getProperty(nodeRef, LprContentModel.PROP_BASE_CONTENT_NODE)));
            //String basePath = nodeService.getPath(nodeBase).toPrefixString(namespaceService);
            //System.out.println("Base Path: " + basePath);
            //System.out.println("Doc name : " + docname);
            
            NodeRef nodeChild = this.nodeService.getChildByName(nodeBase, ContentModel.ASSOC_CONTAINS, LprConstante.SPACE_DRAFTS);
            System.out.println("Draft Folder : " + nodeService.getProperty(nodeChild, ContentModel.PROP_NAME));
   
            // Make copy of document
            String qname = QName.createValidLocalName(docname);
            NodeRef copyNodeRef = copyService.copy(nodeRef, nodeChild,ContentModel.ASSOC_CONTAINS, QName.createQName(NamespaceService.CONTENT_MODEL_1_0_URI, qname), true);
            nodeService.setProperty(copyNodeRef, ContentModel.PROP_NAME, docname);
            
            // Change Document Status and Permission
            nodeService.setProperty(copyNodeRef, LprContentModel.PROP_STATUS, LprConstante.STATUS_DRAFT);
            permissionService.setPermission(copyNodeRef, Currentuser, PermissionService.EDITOR, true);
            
            // Add Aspect Working Copy and backup the copy nodeRef in the original document
            if (nodeService.hasAspect(nodeRef, LprContentModel.ASPECT_WORKING_COPY) == false) {
               nodeService.addAspect(nodeRef, LprContentModel.ASPECT_WORKING_COPY, null);
            }
            nodeService.setProperty(nodeRef, LprContentModel.PROP_WORKING_COPY_NODE, copyNodeRef.getId());
            
            // Add Aspect Origine Copy on the copy and backup the origine nodeRef
            if (nodeService.hasAspect(copyNodeRef, LprContentModel.ASPECT_ORIGINE) == false) {
               nodeService.addAspect(copyNodeRef, LprContentModel.ASPECT_ORIGINE, null);
            }
            nodeService.setProperty(copyNodeRef, LprContentModel.PROP_ORIGINE_NODE, nodeRef.getId());
          }   
      } catch (Exception e) {
         // TODO: handle exception
         e.printStackTrace();
      }
      MyLogger.debugln("lpr.alfresco.web.bean.CheckInOutBean.out (End)",1);
   }*/
   
   /**
    * Cancel CheckOut Document
    * @param event
    */
   /*public void cancel(ActionEvent event) {
      MyLogger.debugln("lpr.alfresco.web.bean.CheckInOutBean.cancel (Start)",1);
      try {
         System.out.println("Cancel CheckOut Document ");
         UIActionLink link = (UIActionLink)event.getComponent();
          Map<String, String> params = link.getParameterMap();
          String ref = params.get("ref");
          String id = params.get("id");
          System.out.println("ID: " + id);
          if (ref != null && ref.length() != 0)
          {
             NodeRef nodeRef = new NodeRef(ref);
             System.out.println("My node ref: " + nodeRef);

             // search for node current user
            FacesContext context = FacesContext.getCurrentInstance();
            
            // Obtain the ServiceRegistry
             serviceRegistry = Repository.getServiceRegistry(context);
             
             // Obtain the services we need from the ServiceRegistry
             nodeService = serviceRegistry.getNodeService();
             fileFolderService = serviceRegistry.getFileFolderService();
                       
             authenticationService.authenticate(WORKFLOW_USER, WORKFLOW_PASSWORD.toCharArray());
               
             //MyLogger.debugNodeRef(nodeService, nodeRef, 2);      
             System.out.println("Value origine node: " + nodeService.getProperty(nodeRef, LprContentModel.PROP_ORIGINE_NODE));
             NodeRef originalNode = new NodeRef ((String)(LprConstante.WORKSPACE_BASE + "/" + nodeService.getProperty(nodeRef, LprContentModel.PROP_ORIGINE_NODE)));
             System.out.println("Ooriginal node Ref: " + originalNode);
             if (nodeService.hasAspect(originalNode, LprContentModel.ASPECT_WORKING_COPY) == true) {
               nodeService.removeAspect(originalNode, LprContentModel.ASPECT_WORKING_COPY);
            }
             
             // Delete file
             fileFolderService.delete(nodeRef);
             //authenticationService.clearCurrentSecurityContext();
          }
         
      } catch (Exception e) {
         // TODO: handle exception
         e.printStackTrace();
      }
      MyLogger.debugln("lpr.alfresco.web.bean.CheckInOutBean.cancel (End)",1);
   }*/
   
   // ——————————————————————————
   // Private data
   
   private static Log logger = LogFactory.getLog(CheckInOutBean.class);
    
   /** I18N messages */
   public static final String MSG_ERROR_CHECKIN = "error_checkin";
   public static final String MSG_ERROR_CANCELCHECKOUT = "error_cancel_checkout";
   public static final String MSG_ERROR_UPDATE = "error_update";
   public static final String MSG_ERROR_CHECKOUT = "error_checkout";
     
   /** The current document */
   private Node document;
   
   /** The working copy of the document we are checking out */
   private Node workingDocument;   
   
   /** The BrowseBean to be used by the bean */
   protected BrowseBean browseBean;
   
   /** The NavigationBean bean reference */
   //protected NavigationBean navigator;
   
    /** The NodeService to be used by the bean */
   private NodeService nodeService;   
   
   /** The AuthenticationService to be used by the bean */
   private AuthenticationService authenticationService;
   
   /** The PermissionService to be used by the bean */
   private PermissionService permissionService;
   
   /** The FileFolderService to be used by the bean */
   private FileFolderService fileFolderService;
   
   /** The CopyService to be used by the bean */
   private CopyService copyService;
   
   
   /** Others */
   //private ServiceRegistry serviceRegistry;
   //private NamespaceService namespaceService;
      
   private static final String WORKFLOW_USER = "workflow";
   private static final String WORKFLOW_PASSWORD = "myPassword";
}

huberd
Champ in-the-making
Champ in-the-making
N'y arait-il pas moyen de pouvoir déclarer ce bean ailleur que dans le fichier faces-config-beans.xml situé dans le dossier WEB-INF
qui est déployé par la war d'alfresco à chaque nouvelle installation. Mon souhait serait de pouvoir faire cette déclaration dans un fichier de configuration situé dans le dossier alfresco\extension.