cancel
Showing results for 
Search instead for 
Did you mean: 

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

kodermax
Star Contributor
Star Contributor

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

7 REPLIES 7

cesarista
World-Class Innovator
World-Class Innovator

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.

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

cesarista
World-Class Innovator
World-Class Innovator

Both of them should be valid.

Behaviors/Policies | Alfresco Documentation 

Regards.

--C.

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
World-Class Innovator
World-Class Innovator

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.

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));
        }
    }

Can I change properties when I upload a new version?