How can I remove some aspect when I upload new version?

cancel
Showing results for 
Search instead for 
Did you mean: 
kodermax
Active Member II

How can I remove some aspect when I upload new version?

I'd like to remove some properties or some aspects when user make upload a new version.

7 Replies
cesarista
Customer

Re: How can I remove some aspect when I upload new version?

Hi:

Try with a content rule that executes a Javascript API script, removing the corresponding aspects and modifying properties. If the trigger for the rule ("when the document is modified") is not enough or valid for you, you will need to program a behaviour component that runs some java or javascript code for doing it.

Regards.

--C.

kodermax
Active Member II

Re: How can I remove some aspect when I upload new version?

What event should I use for java version? onCreateVersion? beforeCreateVersion?

cesarista
Customer

Re: How can I remove some aspect when I upload new version?

Both of them should be valid.

Behaviors/Policies | Alfresco Documentation 

Regards.

--C.

kodermax
Active Member II

Re: How can I remove some aspect when I upload new version?

When I use this code, my aspect don't removed

public void onCreateVersion(QName qName, NodeRef nodeRef, Map<String, Serializable> map, PolicyScope policyScope) {
   policyScope.removeAspect(nodeRef, QName.createQName(PharmModel.NAMESPACE_PHARM_CONTENT_MODEL, PharmModel.ASPECT_SC_APPROVABLE));
}

cesarista
Customer

Re: How can I remove some aspect when I upload new version?

Try both events and be sure that the events are triggered via log4j loggers. If the event is not reached, you will need to use another event.

Hope this helps.

Regards.

--C.

kodermax
Active Member II

Re: How can I remove some aspect when I upload new version?

I use both events, but I was able to remove the aspect only from node, not version. The newly created version still has this aspect.

public void onCreateVersion(QName qName, NodeRef nodeRef, Map<String, Serializable> map, PolicyScope policyScope) {
        if (logger.isDebugEnabled()) logger.debug("Inside onCreateVersion");
        if (qName.equals(QName.createQName(PharmModel.NAMESPACE_PHARM_CONTENT_MODEL, PharmModel.ASPECT_SC_APPROVABLE))) {
            policyScope.removeAspect(QName.createQName(PharmModel.NAMESPACE_PHARM_CONTENT_MODEL, PharmModel.ASPECT_SC_APPROVABLE));
        }
    }

    public void beforeCreateVersion(NodeRef nodeRef) {
        if (versionService.getVersionHistory(nodeRef).getHeadVersion().getVersionType() == VersionType.MAJOR &&
                nodeService.hasAspect(nodeRef, QName.createQName(PharmModel.NAMESPACE_PHARM_CONTENT_MODEL, PharmModel.ASPECT_SC_APPROVABLE))) {
            nodeService.removeAspect(nodeRef, QName.createQName(PharmModel.NAMESPACE_PHARM_CONTENT_MODEL, PharmModel.ASPECT_SC_APPROVABLE));
        }
    }
kodermax
Active Member II

Re: How can I remove some aspect when I upload new version?

Can I change properties when I upload a new version?