cancel
Showing results for 
Search instead for 
Did you mean: 

Alfresco Share and onCreate policy (customized behaviour)

itrub
Champ in-the-making
Champ in-the-making
Dear colleagues
I have a question about very interesting problem, that, seems, was not discussed before. So, I try to explain it as clear as possible.
I  wrote the new behaviour class, that realizes policy "onCreate" relationaly to documents of type SomeType. It works successfully, when I create SomeType-document in Alfreso Explorer. Action, that I implemented in behaviour class, is performed without errors. But this behaviour does not work when I create SomeType-document in Alfresco Share! I think, the reason is following. In Alfresco Explorer I choose document type before the document has been created, so, when the new Node Reference of type SomeType appears, Alfresco already knows, that the new document is SomeType-document, so onCreate trigger fires.
But in Alfreso Share I firstly create document without type and after that, when NodeReference on cm:content-document (not SomeType!) already exists, I perform action "Change Type" and transform new document to SomeType. So, may be trigger does not fire:
1) when I create document, because the type of this document is not SomeType;
2) when I perform "Change Type", because this is already not the new document, Node Reference has been created earlier.
If this explanation is true, what are possible decisions of this problem?
Sincerely, Iliya
6 REPLIES 6

loftux
Star Contributor
Star Contributor
Easy fix, change Share so that you can set the type on upload.
http://loftux.com/2010/03/22/set-the-document-type-on-file-upload/

itrub
Champ in-the-making
Champ in-the-making
Many thanks, Loftux. I shall try this solution and inform about results.

itrub
Champ in-the-making
Champ in-the-making
Good afternoon, Loftux and all Alfresco developers
I have tried decision, proposed by Loftux. Yes, now I can choose the type of document during uploading file. But behaviour "onCreate" does not fire all the same! It fires well, when I create document in Explorer. What is the reason? Did anybody check custom behaviour "onCreate" under Share interface at all? It seems to me, behaviour-feature is available only under Alfresco Explorer interface. Do you agree with me?

loftux
Star Contributor
Star Contributor
I Agree, and withdraw my statement. This was not an easy fix  :roll:

If you look at the rest api used in the upload
http://localhost:8080/alfresco/wcs/script/org/alfresco/repository/upload/upload.post
you see that
/**
          * Create a new file.
          */
         var newFile = destNode.createFile(filename);
         if (contentType !== null)
         {
            newFile.specializeType(contentType);
         }
it is first created, then specalized to the type. So your policy will not fire.
I looked for an alternative policy that could be useful in this case http://dev.alfresco.com/resource/docs/java/repository/org/alfresco/repo/policy/Policy.html like onSpecializeType, but there don't seem to be one. I think it would be useful if you file an enhancement request for this.

What you can do is change the upload script to set the type on create. You can do  var newFile = destNode.createNode(filename, contentType)
and with some testing of course that the contentType is not null. http://wiki.alfresco.com/wiki/3.4_JavaScript_API#Modifying_and_Creating_API
Not sure if there is any other difference that you have to account for using the 2 different ways of creating new nodes.

itrub
Champ in-the-making
Champ in-the-making
Hello, Loftux and other colleagues
Many thanks, Loftux' decision is completely workable, policy has become to fire now from Share. The only detail remains unclear. Loftux, on your blog you write:
"You also need to extend the file flash-upload.get.properties, in this case also html-upload.get.properties.
Add the value for “value” in the javascript for each of you custom types.
1 my_customtype=My Custom Type "

I have followed your instruction, but typenames in "select"-element appear under their system names, records similar "My Custom Type" are ignored. May be, it is necessary to extend some other files? But this is not important detail. I think, problem may be marked as solvable.

loftux
Star Contributor
Star Contributor
Create a file named itrub-context.xml (name it as you like, as long as it ends in -extension.xml) in folder web-extension
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>

<beans>
  
   <bean id="itrubResourceBundle" class="org.springframework.extensions.surf.util.ResourceBundleBootstrapComponent">
      <property name="resourceBundles">
         <list>
            <value>alfresco.messages.itrub</value>
         </list>
      </property>
   </bean>
  
</beans>
In shared/classes/alfresco/messages, create  a file itrub.properties for english message bundle, itrub_it.properties for italian and so on.
The <value> tag as you can tell specifies the classpath, and finally the expected file name (without properties ending in the value tag)

My blog post was written prior to med finding out where to add you custom message bundles, this is a better way to do it