cancel
Showing results for 
Search instead for 
Did you mean: 

How to Reset the type of node using Javascript API?

anujs86
Champ in-the-making
Champ in-the-making
Hi,

Can any one knows how to reset a node in alfresco using javascript API.
I want to change the node type to "cm:content" or any other type.
Currently i am trying to delete the mandatory aspect associated with that node and getting integrity error.
Please help…

error

2010-08-19 20:07:37,485 (IntegrityChecker.java:666) ERROR org.alfresco.repo.node.integrity.IntegrityChecker - Found 1 integrity violations:
Mandatory aspect not set:
   Node: workspace://SpacesStore/9f34e5db-861f-4315-a958-5449b06d3244
   Type: {http://www.alfresco.org/model/fnodocs/1.0}clientmasteragreement
   Aspect: {http://www.alfresco.org/model/fnodocs/1.0}clientagreementproperties

thanks
Anuj
8 REPLIES 8

jottley
Confirmed Champ
Confirmed Champ
Because it is _Mandatory_ it can not be removed.

Nor can you "change" the type, but you can specialize the type….meaning that you can move to a type that inherits from the content type that is currently being used by the content.

Jared

anujs86
Champ in-the-making
Champ in-the-making
Suppose if my node type is "cmSmiley Tongueublish" which inherits from "cm:content" and i want to specialize it to "cm:content", can i do it?
Also, i saw, there is method available in NodeService Alfresco API setType(NodeRef nodeRef, QName typeQName)
which  Re-sets the type of the node.
There is no method in Javascript API for it?


thanks
Anuj

jottley
Confirmed Champ
Confirmed Champ
You've got to make sure you understand what happens if you call that Java code:

    
* Re-sets the type of the node.  Can be called in order specialise a node to a sub-type.
     *
     * This should be used with caution since calling it changes the type of the node and thus
     * implies a different set of aspects, properties and associations.  It is the calling codes
     * responsibility to ensure that the node is in a approriate state after changing the type.

The javascript implementation of specializeType enforces this:


    public boolean specializeType(String type)
    {
        ParameterCheck.mandatoryString("Type", type);
       
        QName qnameType = createQName(type);
       
        // Ensure that we are performing a specialise
        if (getQNameType().equals(qnameType) == false &&
                this.services.getDictionaryService().isSubClass(qnameType, getQNameType()) == true)
        {
            // Specialise the type of the node
            this.nodeService.setType(this.nodeRef, qnameType);
            this.type = qnameType;
           
            return true;
        }
        return false;
    }


Moving content up the inherited type chain is a dangerous thing…it _will_ most likely break content integrity.  That is why you will not find the ability to change the type in the UI or in the JavaScript API only to specialize the type.  If you use the Java API, you are responsible for ensuring the integrity is maintained.

Jared

anujs86
Champ in-the-making
Champ in-the-making
Thanks Jared !
I think i will need to find other way.


Anuj

mrogers
Star Contributor
Star Contributor
Please forgive me for butting in on this thread.   However I would have thought that wanting to change the "type" of a node indicates something slightly wrong with your data modeling.     I can understand why you would want to specialise from cm:content to cmSmiley Tongueublish but not vice-versa.

If you do need to frequently change type then I suspect that what you should be doing instead is adding and removing aspects rather than changing the "type".

anujs86
Champ in-the-making
Champ in-the-making
Yes i agree with you roger.
But the thing is we cannot change our content model now and as per my requirement we need to remove the mandatory aspect applied to that content type.
The option i figured out is to delete the existing content and create a new same type of content of type cm:content.
Do you have any other better way of doing it?


Anuj

mrogers
Star Contributor
Star Contributor
Can you change your model to make the aspect optional rather than mandatory?

anujs86
Champ in-the-making
Champ in-the-making
Yes we have tried changing the model, but still same problem.