AnsweredAssumed Answered

About custom action jeff potts tutorial

Question asked by hdalang on Nov 18, 2014
Latest reply on Nov 20, 2014 by jpotts
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/

Outcomes