Prevent Aspect from being added in Alfresco Share

…衆ロ難τιáo~ 提交于 2019-12-11 20:15:08

问题


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:


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 :)



来源:https://stackoverflow.com/questions/28294319/prevent-aspect-from-being-added-in-alfresco-share

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!