cancel
Showing results for 
Search instead for 
Did you mean: 

HELP!!!! alfresco actions

enkidu
Champ in-the-making
Champ in-the-making
hi mates,

need help.. i want to transform xml to pdf using a custom transformer (a script batch file). i copy and paste the example from http://docs.alfresco.com/4.1/index.jsp?topic=%2Fcom.alfresco.enterprise.doc%2Ftasks%2Fserv-runtimetr...

but i didnt know how the action will be performed (didnt show up under actions). did i need to do something more then create a file under extensions? some advice would be nice.

using alfresco 4.2.d
17 REPLIES 17

enkidu
Champ in-the-making
Champ in-the-making
here is a comment i found at amazon: http://www.amazon.de/Alfresco-Developer-Guide-Jeff-Potts/dp/1847193110

– amazon –
Alfresco has some of the worst documentation that I have ever seen. This book is only slightly better. No matter what I try and do I have to go to the community to get the real, workable information. I just seem to hit what should be the simple stuff that is not documented anywhere.
– amazon –


maybe the alfresco staff should take it more serious

i totally agree.. alfresco has a problem with its documentation and code samples are poor

jpotts
World-Class Innovator
World-Class Innovator
enkidu,

Your comment isn't really constructive. If you point to something in http://docs.alfresco.com, which is the official documentation, that you think could be improved that would be helpful.

You are in the forums, which is a community-managed resource, asking for help. You'll notice that people who get help are those who (1) read the documentation, (2) try various things, including reading the source code, (3) provide a lot of details about what they are having trouble with, and (4) remain patient and respectful of those who give their time outside of work to help others.

It's okay to be frustrated, but saying only that we have a problem with our documentation and that the code samples are poor does nothing to improve the situation and it makes people reluctant to help you.

Jeff

enkidu
Champ in-the-making
Champ in-the-making
hi jeff,

i just wanna make a point.. and that is there is no decent tutorial about custom actions. and thats a fact. prove me wrong and post the link where i can find a documentation including sample code and i agree that i was completly wrong. but as long as u cant proof me wrong i will stick to my point.

and if u take a closer look at the forum u will realize that there is a problem.





enkidu
Champ in-the-making
Champ in-the-making
hi jeff,

got my custom action running and shown in UI. just for the beginning i just inherit from ActionExecuterAbstractBase nothing special and make a jar this i copied to "$alfrescodir\tomcat\webapps\alfresco\WEB-INF\lib" and the XML file i copied to -> goes to ($alfrescodir\tomcat\shared\classes\alfresco\extension).

can u tell me why i get WHAAAT? instead of WOOOOO?


package com.myfirstaction;

import java.util.List;

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.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class MyCustomAction extends ActionExecuterAbstractBase {

   private Log logger = LogFactory.getLog("com.myfirstaction");
   protected NodeService nodeService;
   public final static String NAME = "myaction-action";
   
   @Override
   protected void executeImpl(Action arg0, NodeRef arg1) {
      // TODO Auto-generated method stub
                  logger.error("WHAAAAT????");
      logger.info("WOOOOOO!!!!!");
   }

   @Override
   protected void addParameterDefinitions(List<ParameterDefinition> arg0) {
      // TODO Auto-generated method stub
      
   }

}



<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>
    
<bean id="myaction-action" class="com.myfirstaction.MyCustomAction" parent="action-executer">
    <property name="nodeService">
        <ref bean="NodeService" />
    </property>
</bean>
   
   
</beans>

enkidu
Champ in-the-making
Champ in-the-making
i got the example running but can someone explain me the logging mechanism? oh btw to get this work maybe this is a nice ref.. http://forums.alfresco.com/forum/developer-discussions/development-environment/loggeractionexecuter-...


/*
* Copyright (C) 2005-2010 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
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
    }
}

kaynezhang
World-Class Innovator
World-Class Innovator
alfresco use log4j to record log messages.  by default The root category is set to error(which is configured in alfresco\WEB-INF\classes) .
As your categories have not had their log level set ,It will inherit their log level from the root, which is set to ERROR.
So only if the level is ERROR or higher will be dumped to log file,that's why you get  WHAAAT instead of WOOOOO.

enkidu
Champ in-the-making
Champ in-the-making
hi kaynezhang.. if u compare the both code i posted u will see there is not so much difference, but at the last code i posted the code will output INFO as well not just ERROR so im wondering what im missing? where does my bottom code know that he now should output INFO as well?

enkidu
Champ in-the-making
Champ in-the-making
thnk u all for ur help and ur patience