cancel
Showing results for 
Search instead for 
Did you mean: 

About custom action jeff potts tutorial

hdalang
Champ in-the-making
Champ in-the-making
I have tried to do the alfresco custom action tutorial of jeff potts, and I faced a problem with SetWebFlag.java, there was a problem in three lines:
1-
      properties.put(QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL, SomeCoModel.PROP_IS_ACTIVE), activeFlag);


2-
         properties.put(QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL, SomeCoModel.PROP_PUBLISHED), new Date());


3-

             QName.createQName(
                  SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL,
                  SomeCoModel.ASPECT_SC_WEBABLE)))



package com.someco.action.executer;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Map;

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

import com.someco.model.SomeCoModel;

public class SetWebFlag extends ActionExecuterAbstractBase {
   
   public final static String NAME = "set-web-flag";
   public final static String PARAM_ACTIVE = "active";
   
   /** The NodeService to be used by the bean */
   protected NodeService nodeService;
   
   private static Log logger = LogFactory.getLog(SetWebFlag.class);
   
   @Override
   protected void executeImpl(Action action, NodeRef actionedUponNodeRef) {
         
      Boolean activeFlag = (Boolean)action.getParameterValue(PARAM_ACTIVE);

      if (activeFlag == null) activeFlag = true;
      
      if (logger.isDebugEnabled()) logger.debug("Inside executeImpl");
               
      // set the sc:isActive property to true
      // set the sc:published property to now
      Map<QName, Serializable> properties = nodeService.getProperties(actionedUponNodeRef);
      properties.put(QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL, SomeCoModel.PROP_IS_ACTIVE), activeFlag);
       
      if (activeFlag) {
         properties.put(QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL, SomeCoModel.PROP_PUBLISHED), new Date());
      }
      
      // if the aspect has already been added, set the properties
      if (nodeService.hasAspect(actionedUponNodeRef,
             QName.createQName(
                  SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL,
                  SomeCoModel.ASPECT_SC_WEBABLE))) {
         if (logger.isDebugEnabled()) logger.debug("Node has aspect");
         nodeService.setProperties(actionedUponNodeRef, properties);
      } else {
         // otherwise, add the aspect and set the properties
         if (logger.isDebugEnabled()) logger.debug("Node does not have aspect");
         nodeService.addAspect(actionedUponNodeRef, QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL, SomeCoModel.ASPECT_SC_WEBABLE), properties);
      }                 
            
      if (logger.isDebugEnabled()) logger.debug("Ran web enable/disable action");
                                
   }

   @Override
   protected void addParameterDefinitions(List<ParameterDefinition> paramList) {
      paramList.add(
               new ParameterDefinitionImpl(               // Create a new parameter definition to add to the list
                  PARAM_ACTIVE,                           // The name used to identify the parameter
                  DataTypeDefinition.BOOLEAN,             // The parameter value type
                  false,                                  // Indicates whether the parameter is mandatory
                  getParamDisplayLabel(PARAM_ACTIVE)));   // The parameters display label
      
   }

   /**
   * @param nodeService The NodeService to set.
   */
   public void setNodeService(NodeService nodeService) {
      this.nodeService = nodeService;
   }

}


I think the problem that it's not configured well, in the SomeCoModel.java


package com.someco.model;

import org.alfresco.service.namespace.QName;


public interface SomeCoModel {
   
        // Types
        public static final String NAMESPACE_SOMECO_CONTENT_MODEL  = "http://www.someco.com/model/content/1.0";
        public static final String TYPE_SC_DOC_STRING = "doc";
    public static final QName TYPE_SC_DOC = QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL, SomeCoModel.TYPE_SC_DOC_STRING);
    public static final String TYPE_SC_WHITEPAPER_STRING = "whitepaper";
    public static final QName TYPE_SC_WHITEPAPER = QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL, "whitepaper");
    public static final QName TYPE_SC_RATING = QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL, "rating");
       
    // Aspects
        public static final String ASPECT_SC_WEBABLE_STRING = "webable";
    public static final QName ASPECT_SC_WEBABLE = QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL, SomeCoModel.ASPECT_SC_WEBABLE_STRING);
    public static final String ASPECT_SC_CLIENT_RELATED_STRING = "clientRelated";
    public static final QName ASPECT_SC_CLIENT_RELATED = QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL, SomeCoModel.ASPECT_SC_CLIENT_RELATED_STRING);
    public static final QName ASPECT_SC_RATEABLE = QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL, "rateable");
   
    // Properties
    public static final String PROP_CLIENT_NAME_STRING = "clientName";
    public static final QName PROP_CLIENT_NAME = QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL, SomeCoModel.PROP_CLIENT_NAME_STRING);
    public static final QName PROP_CLIENT_PROJECT = QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL, "projectName");
    public static final String PROP_PUBLISHED_STRING = "published";
    public static final QName PROP_PUBLISHED = QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL, SomeCoModel.PROP_PUBLISHED_STRING);
    public static final String PROP_IS_ACTIVE_STRING = "isActive";
    public static final QName PROP_IS_ACTIVE = QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL, SomeCoModel.PROP_IS_ACTIVE_STRING);
    public static final QName PROP_RATING = QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL, "rating");
    public static final QName PROP_RATER = QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL, "rater");
    public static final QName PROP_AVERAGE_RATING= QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL, "averageRating");
    public static final QName PROP_TOTAL_RATING= QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL, "totalRating");
    public static final QName PROP_RATING_COUNT= QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL, "ratingCount");
   
    // Associations
    public static final String ASSN_RELATED_DOCUMENTS_STRING = "relatedDocuments";
    public static final QName ASSN_RELATED_DOCUMENTS = QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL, SomeCoModel.ASSN_RELATED_DOCUMENTS_STRING);
    public static final QName ASSN_SC_RATINGS = QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL, "ratings");

}



I need some help to complete this tutorial.

Regards,,
Hisham Khartoum | Technical Support Engineer at Duroob Technology
profile:http://sa.linkedin.com/pub/hisham-khartoum/57/133/15a/
3 REPLIES 3

jpotts
World-Class Innovator
World-Class Innovator
What version of Alfresco are you using?

What version of the tutorial are you using? (1st Edition or 2nd Edition).

Where did you get the tutorial source code? For example, 2nd edition source code lives here:
https://github.com/jpotts/alfresco-developer-series/tree/master/actions

What is the error message you are seeing?

Jeff

hdalang
Champ in-the-making
Champ in-the-making
Dear jeff potts,,

I'm really happy that you personally replied, I have uploaded my screen shot, and about the tutorial I use the code that comes with the reference at the end of the page. The problem is that there is a syntax error I believe some where in the code, from SetWebFlag.java while using eclipse, the error saying that qname syntax will accept only strings, Qname(String,String) but in the tutorial the Qname(String,Qname) so what I did is this:
1-

      properties.put(QName.createQName(
            SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL,
            (SomeCoModel.PROP_IS_ACTIVE).toString()), activeFlag);

2-

         properties.put(
               QName.createQName(SomeCoModel.NAMESPACE_SOMECO_CONTENT_MODEL,
                     (SomeCoModel.PROP_PUBLISHED).toString()), new Date());



I have added toString(), and the error is gone and it gave me build success, I don't know but I fixed this way, so do you think there's something wrong?

Regards,,

————————————————————————–
Hisham Khartoum | Technical Support Engineer at Duroob Technology
profile:http://sa.linkedin.com/pub/hisham-khartoum/57/133/15a/

jpotts
World-Class Innovator
World-Class Innovator
Different versions of the SomeCo code have used different types for the constants in SomeCoModel. I started out using QNames and changed to Strings. The very latest code for all of my tutorials, which is known to work on later versions of Alfresco, resides on GitHub:
https://github.com/jpotts/alfresco-developer-series

Your fix, which converts the QName to a String value should be fine.

Jeff