cancel
Showing results for 
Search instead for 
Did you mean: 

Noisy cm:content objects

sammasue
Champ in-the-making
Champ in-the-making
Hello everybody,

I recently created a Behaviour on cm:content / onCreateNode and I was really surprised to see how many objects of cm:content type or subtype are created. For example:
- page.title.user~admin~dashboard.xml
- page.full-width-dashlet.user~admin~dashboard.xml
- page.component-1-1.user~admin~dashboard.xml
- pdf {http://www.alfresco.org/model/content/1.0}thumbnail

And this is just a sample. I find all these objects really noisy. Indeed if I would like to do some treatment in a behaviour on cm:content I don't know what I going to modify. Thumbnail? document? some dashboard xml? And then what's happen if I modify these objects.

And I actually had one issue because I was modifying thumbnail (subtype of cm:content) I broke document previous.

I would expect in that case to work only on my documents I uploaded. Any idea how to filter? It is quite easy to filter subtypes but unfortunately some nodes are cm:content.

Thanks in advance for any help,

Sam
5 REPLIES 5

s_palyukh
Star Contributor
Star Contributor
Hi,
The following types are skipped in the search results by default: cm:thumbnail, cm:failedThumbnail, cm:rating and aspect sys:hidden.
If you want to use behavior for cm:content then you need to skip all system files. You can do it by adding the condition into the code. Something like that:




    @Override
    public void onCreateNode(ChildAssociationRef childAssocRef) {

                if (applicable(childAssocRef.getChildRef())) {

                    onCreateNodeImpl(childAssocRef);

                }

    }


    protected boolean applicable(NodeRef nodeRef) {
        return getNodeService().exists(nodeRef) &&
                !getNodeService().hasAspect(nodeRef, RenditionModel.ASPECT_HIDDEN_RENDITION) &&
                !getNodeService().hasAspect(nodeRef, ContentModel.ASPECT_HIDDEN) &&
                !getNodeService().getType(nodeRef).equals(ForumModel.TYPE_FORUM) &&
                !getNodeService().getType(nodeRef).equals(ForumModel.TYPE_POST) &&
                !getNodeService().getType(nodeRef).equals(ForumModel.TYPE_FORUMS) &&
                !getNodeService().getType(nodeRef).equals(ForumModel.TYPE_TOPIC)
    }



sammasue
Champ in-the-making
Champ in-the-making
Hi,

Thank you very much S.Palyukh for your help. Unfortunately I have tried to see if these documents had any "hidden" aspects but they don't (I am using Alfresco 5.0.c). Here the code I used:


@Service
@BehaviourBean
public class ApplyConfidentiality implements NodeServicePolicies.OnCreateNodePolicy
{
  @Autowired
  @Qualifier("NodeService")
  private NodeService nodeService;

  /**
   * Called when a new node has been created.
   *
   * @param childAssocRef the created child association reference
   */
  @Behaviour(
    kind = BehaviourKind.CLASS,
    type = "cm:content")
  @Override
  public void onCreateNode(ChildAssociationRef childAssocRef)
  {
   
    if (ContentModel.TYPE_CONTENT.equals(nodeService.getType(childAssocRef.getChildRef())))
    {
      System.out.println("CM:CONTENT");
    }else
    {
      System.out.println("CM:CONTENT subType");
    }

    for (QName qName : nodeService.getAspects(childAssocRef.getChildRef()))
    {
      System.out.println(qName.getLocalName());
    }

    if (nodeService.hasAspect(childAssocRef.getChildRef(), RenditionModel.ASPECT_HIDDEN_RENDITION))
    {
      System.out.println("REDITION HIDDEN");
    }

    if (nodeService.hasAspect(childAssocRef.getChildRef(), ContentModel.ASPECT_HIDDEN))
    {
      System.out.println("ASPECT HIDDEN");
    }
  }
}


I have got only these aspects :
auditable
referenceable
localized

Sam

leonardo_celati
Champ in-the-making
Champ in-the-making
Just a guess, have you tried filtering by cm:creator or cm:modifier ?

s_palyukh
Star Contributor
Star Contributor
I found how rules work in alfresco , they also use a behavior to start executing (look at the RuleTriggerAbstractBase class):


   /** the types (hardcoded) to ignore generally */
    private static final Set<QName> IGNORE_TYPES;
    /** the aspects (hardcoded) to ignore generally */
    private static final Set<QName> IGNORE_ASPECTS;
    static
    {
        IGNORE_TYPES = new HashSet<QName>(13);
        IGNORE_TYPES.add(RuleModel.TYPE_RULE);
        IGNORE_TYPES.add(ActionModel.TYPE_ACTION);
        IGNORE_TYPES.add(ContentModel.TYPE_THUMBNAIL);
        // Workaround to prevent rules running on cm:rating nodes (which happened for 'liked' folders ALF-8308 & ALF-8382)
        IGNORE_TYPES.add(ContentModel.TYPE_RATING);
        IGNORE_TYPES.add(ContentModel.TYPE_SYSTEM_FOLDER);

        IGNORE_ASPECTS = new HashSet<QName>(13);
        IGNORE_ASPECTS.add(ContentModel.ASPECT_TEMPORARY);
    }

    protected void triggerRules(NodeRef nodeRef, NodeRef actionedUponNodeRef)
    {
        // Break out early if rules are off
        if (!areRulesEnabled())
        {
            return;
        }

       // Do not trigger rules for rule and action type nodes
       if (ignoreTrigger(actionedUponNodeRef) == false)
       {
           for (RuleType ruleType : this.ruleTypes)
           {
               ruleType.triggerRuleType(nodeRef, actionedUponNodeRef, this.executeRuleImmediately);
           }
       }
    }

    /**
     * Indicate whether the trigger should be ignored or not
     * @param actionedUponNodeRef     actioned upon node reference
     * @return boolean              true if the trigger should be ignored, false otherwise
     */
    private boolean ignoreTrigger(NodeRef actionedUponNodeRef)
    {
       boolean result = false;       
       QName typeQName = nodeService.getType(actionedUponNodeRef);
       if (IGNORE_TYPES.contains(typeQName))
       {
          result = true;
       }
       for (QName aspectToIgnore : IGNORE_ASPECTS)
        {
            if (nodeService.hasAspect(actionedUponNodeRef, aspectToIgnore))
            {
                return true;
            }
        }
       return result;
    }


This code is from Alfresco 4.1.5

sammasue
Champ in-the-making
Champ in-the-making
Hello,

I have tried this and it seems to work pretty well. I have improved a bit to ignore as well nodes used for the "surf-config". My result looks like this.

/**
   * the types to ignore generally (see RuleTriggerAbstractBase)
   */
  private static ImmutableSet<QName> IGNORE_TYPES = ImmutableSet.<QName>builder()
    .add(RuleModel.TYPE_RULE)
    .add(ActionModel.TYPE_ACTION)
    .add(ContentModel.TYPE_THUMBNAIL)
    .add(ContentModel.TYPE_RATING)
    .add(ContentModel.TYPE_SYSTEM_FOLDER)
    .build();

  /**
   * the aspects to ignoreForBehaviour generally (see RuleTriggerAbstractBase)
   */
  public static ImmutableSet<QName> IGNORE_ASPECTS =
    ImmutableSet.<QName>builder().add(ContentModel.ASPECT_TEMPORARY).build();

  /**
   * (see RuleTriggerAbstractBase)
   * determine if the node has to be ignored for a behaviour*
   *
   * @param nodeRef ref of the node
   * @return true if the node should be ignored, false otherwise
   */
  public boolean ignoreForBehaviour(NodeRef nodeRef)
  {
    if (IGNORE_TYPES.contains(nodeService.getType(nodeRef)))
    {
      return true;
    }
    for (QName aspectToIgnore : IGNORE_ASPECTS)
    {
      if (nodeService.hasAspect(nodeRef, aspectToIgnore))
      {
        return true;
      }
    }
   
    return isSurfConfig(nodeRef);
  }

  /**
   * Check if the node is inside a surf-config folder (E.g. of files in the surf-config folder dashboard.xml)*
   * @param nodeRef ref of the node to check
   * @return true if it's surf-config file otherwise false
   */
  private boolean isSurfConfig(NodeRef nodeRef)
  {
    if(nodeRef != null && nodeService.exists(nodeRef))
    {
      if ("surf-config".equals(nodeService.getProperty(nodeRef, ContentModel.PROP_NAME)))
      {
        return true;
      }
      return isSurfConfig(nodeService.getPrimaryParent(nodeRef).getParentRef());
    }
    return false;
  }


If someone has a better idea he is welcome to share it Smiley Happy.


Sam
Getting started

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.