cancel
Showing results for 
Search instead for 
Did you mean: 

Specialize type no parent

army81
Champ in-the-making
Champ in-the-making
Hi,
I have this configuration:

<type name="my:type1">
<title>My Type 1</title>
<parent>cm:content</parent>
<mandatory-aspects>
  <aspect>my:aspect_myaspect1</aspect>
  <aspect>my:aspect_myaspect2</aspect>
  <aspect>my:aspect_myaspect3</aspect>
</mandatory-aspects>
</type>

<type name="my:type2">
<title>My Type 2</title>
<parent>cm:content</parent>
<mandatory-aspects>
  <aspect>my:aspect_myaspect1</aspect>
  <aspect>my:aspect_myaspect4</aspect>
  <aspect>my:aspect_myaspect5</aspect>
</mandatory-aspects>
</type>




It's possible specialize type from my:type1 to my:type2 losing properties contained in my:aspect_myaspect2 and my:aspect_myaspect3 and save the properties contained in my:aspect_myaspect1 ?.
5 REPLIES 5

kaynezhang
World-Class Innovator
World-Class Innovator
In alfresco set a node to new type will do following:
1.update the node's  basic data(type qname,transaction,auditable properties);
2.add the default aspects and properties required for the new type.Existing property values will not be overridden or removed.

So I guess all properties belong to my:aspect_myaspect1/my:aspect_myaspect2/my:aspect_myaspect3 will all be preserved.
That is all what I'm thinking ,you 'd better perform a test to validate whether properties belong to my:aspect_myaspect2/my:aspect_myaspect3 are preserved or not

mrogers
Star Contributor
Star Contributor
Yes.   Aspect 1,2 and 3 will remain. 

army81
Champ in-the-making
Champ in-the-making
When I put in the file share-config-custom.xml this configuration:

<config evaluator="string-compare" condition="DocumentLibrary"
      replace="true">
<type name="my:type1" >
  <subtype name="my:type2" />
</type>

<type name="my:type2" >
  <subtype name="my:type1" />
</type>



I try to convert the document in Share, but the system generates an error "Unable to convert the document into my: type2".

kaynezhang
World-Class Innovator
World-Class Innovator
You can not fulfill your requirement in share ,in share it will only specialise the node to a sub class of current type
You should do some custom developmennt

army81
Champ in-the-making
Champ in-the-making
I have found the solution:
1) Override the file webapps/alfresco/web-inf/classes/org/alfresco/slingshot/documentlibrary/type.post.json.js with:

if (!node.specializeType(type))
   {

      try {
         
         customSpecializeTypeScript.customSpecializeType(node,type);

      } catch (e) {
         status.setCode(status.STATUS_INTERNAL_SERVER_ERROR, "Could not change type of nodeRef '" + nodeRef + "' to '" + type + "'");
         return null;
      }

   }



2)Create custom BaseScopableProcessorExtension:


public boolean customSpecializeType(Object obj,Object type) {
      
      if(obj instanceof ScriptNode) {
         ScriptNode nodeScript = (ScriptNode)obj;
         NodeRef nodeRef = nodeScript.getNodeRef();
         if(type instanceof String) {
            String[] splitType = ((String)type).split(":");
            if(splitType.length==2) {
               QName qnameNewType = QName.createQName(Constants.COSTMTYPEURI,splitType[1]);
               nodeService.setType(nodeRef, qnameNewType);
               return true;
            }
         }
         
         
      }
      
      
      return false;

      
   }