Prevent Aspect from being added in Alfresco Share

2019-09-05 23:51发布

Most tutorials don't take this into account, but I suppose there are many occasions where a node doesn't meet all requirements for a custom aspect.

The only way I found for this to occur is to develop a behavior, and in beforeAddAspect throw an Alfresco runtime exception.

Which is happening by registering a before add aspect categorically as FIRST_EVENT

this.beforeAddAspect = new JavaBehaviour(this, BEFORE_ADD_ASPECT, NotificationFrequency.FIRST_EVENT);

And then throwing the error itself:

@Override
    public void beforeAddAspect(NodeRef nodeRef, QName aspectTypeQName) {
        if(!hasRequirements())) {
           throw AlfrescoRuntimeException.create("error.my.message", new Object[]{......});
        }

    }

I wonder if I am doing it right, or if there are any other solution which involves not throwing errors.

This "error approach" has also a downside, the error message cannot be customized, and the user is getting a standard one.

Basically, as mentioned, this is a Custom Aspect, at time of development is a marker aspect (for the moment). As required, let me give few details about the subject:

  • the Aspect is meant to be applied only to content type and optionally (hopefully) only to specific mimetype.
  • by applying the aspect a few actions on the node are started: tagging, calculating variable etc. The user expect that if a node has an aspect, some other things has happened.
  • everything happens in the Share UI perimeter, the user apply the aspect in the classic way, but he also has few shortcuts actions available on node view which do the same, apply/remove aspect. The only difference is that the action give a customized feedback error/success to the user.

I am using Alfresco 4.2f

1条回答
ら.Afraid
2楼-- · 2019-09-06 00:03

Regarding Error message.you can achieve that by below.

You can return error code from hasRequirements function.According to error code or success code you can display message.

Your approach is the best approach for achieving your business requirement.You can achieve it using policy only.

hope this helps :)

查看更多
登录 后发表回答