cancel
Showing results for 
Search instead for 
Did you mean: 

WEbScript FileUpload and tags Creation

zafarale
Champ in-the-making
Champ in-the-making
Hi I have a simple script which recieves file and pushes it into repo. one of the requirement is request can contain tags t associate with newly uploaded file, while preserving tags case.

folowing is the code i am using to create tags


/**
* @param tags array( with tag names in it)
*/
function getTag(tags){
   var store = "workspace://SpacesStore/";

   for(var t=0; t< tags.length; t++) {
      var tag = taggingService.getTag(store, tags[t]);
       var tagExists = (tag != null);   
      if (!tagExists){
                 //It creates tag with lower case
       tag = taggingService.createTag(store, tags[t]);
                 //For some reason after createTag tag was null in some cases
            var tagNode = search.findNode("workspace://SpacesStore/"+tag.id);
                 //Give it a name originally intended
            tagNode.properties.name=tags[t];
            tagNode.save();     
      }
      tags[t] = tag;
   }
   return tags;
}


when i try to use returned array of tag nodes elsewhere as;


tags = getTag(tags);
for(var t=0; t<tags.length; t++) {
                    //This line works fine
   logger.info(tags[t].name);
                    //This line again sometimes throws NullPointer even though tags array has all  nodes
   upload.addTag(tags[t].name);
}


upload is a node created but not called save() upon.


With webscript debugger attaching break point at logger.info and letting it go every time it stops seems to fix the issue.

Any ideas, it's urgent
8 REPLIES 8

kaynezhang
World-Class Innovator
World-Class Innovator
I guess it might cause by following reasons:
suppose you begin with adding a capital letters tag "Information" which was not present yet .
1.you get the tag using
var tag = taggingService.getTag(store, tags[t]);
which will not lower the case,so nothing will return.
2.you creat the tag "Information" using
 tag = taggingService.createTag(store, tags[t]);
,but in createTag implementation ,"Information" will be lowered case to "information".
3. you try to give it a name originally intended,which will set its name to "Information" again.
4.then you will call
upload.addTag(tags[t].name);
which is
 ScriptNode.addTag()
method ,in ScriptNode.addTag alfresco will lower the case of the tag(to "information" again),but in repository there is no node named "information",so you get a null pointer.

So it is a bad idea for you to make tag sensitive .

zafarale
Champ in-the-making
Champ in-the-making
Each tag has node I'd available which means it has been saved.

Which is also verified by putting in breakpoint and run it slowly

kaynezhang
World-Class Innovator
World-Class Innovator

By default node name is case sensitive,but tags are all saved and retrieved in lower case.


in
upload.addTag(tags[t].name) 
method :
1.alfresco will first lower the case of tags[t].name(for examp tags[t].name is "Information"
2.and search the tag node acoording to the lower case tag name(that is "information") ,but you have already updated the tag node's name to originally intended(that is "Information"),so the tag node possible could not be found,and it will you null pointer exception.


The null pointer exception is thrown because alfresco will search the corresponding tag node using tag name as paramter in
upload.addTag(tag)
method.

zafarale
Champ in-the-making
Champ in-the-making
I think you have not read my initial post carefully, I clearly pointed out that this does not happen always.

If I accept you argument alfresco should throw null pointer every single time.

And I can confirm there are already tags in alfresco created via same code in mixed case and are searchable

kaynezhang
World-Class Innovator
World-Class Innovator
You also did not get what I mean.
Of course it will not  throw null pointer every single time.It will happen under following circumstances:
You have added capital letters tag in repository but not the lower case,for example you have added "Information" tag to repository and not "information" .When you try to add  "Information"  tag to other node ,it will give you null pointer.

The following two will not throw null pointer
1.If you have added the lowercase one( "information") and not the capital  one to repository,and just use the lower case tag .it will work fine.
2.If you have added both the capital("Information") and lowercase ( "information"),and it will also work fine ,but the lower case one( "information") will be used.

zafarale
Champ in-the-making
Champ in-the-making
Wht I meant is alfresco has successfully added mixed cased tags to node which is created as a part of same request and assigned it to node

So I created a tag "abc.Case" tag it has accepted it on another occasion I added "abc.Base" and it failed

So as per ur example in ui there is no tag "Information" and I create and capitalise "Information" add it to node works, purged everything tried the same it fails

zafarale
Champ in-the-making
Champ in-the-making
Hi guys i got it working, now faced with another problem, when this script goes into another server (test) it throws exception


"message" : "04160002 Wrapped Exception (with status template): 04160015 Failed to execute script 'classpath*:alfresco\/templates\/webscripts\/com\/passivsystems\/upload.post.js': 04160014 No solr query support for store workspace:\/\/SpacesStore\/", 
  "exception" : "org.springframework.extensions.webscripts.WebScriptException - 04160002 Wrapped Exception (with status template): 04160015 Failed to execute script 'classpath*:alfresco\/templates\/webscripts\/com\/passivsystems\/upload.post.js': 04160014 No solr query support for store workspace:\/\/SpacesStore\/",
 
  "callstack" :
  [
       ""      ,"org.alfresco.error.AlfrescoRuntimeException: 04160014 No solr query support for store workspace:\/\/SpacesStore\/"
      ,"org.alfresco.repo.search.impl.solr.SolrQueryHTTPClient.executeQuery(SolrQueryHTTPClient.java:224)"
      ,"org.alfresco.repo.search.impl.solr.SolrQueryLanguage.executeQuery(SolrQueryLanguage.java:49)"
      ,"org.alfresco.repo.search.impl.solr.SolrSearchService.query(SolrSearchService.java:348)"
      ,"org.alfresco.repo.search.impl.solr.SolrSearchService.query(SolrSearchService.java:152)"
      ,"org.alfresco.repo.search.impl.lucene.LuceneCategoryServiceImpl.getClassificationNodes(LuceneCategoryServiceImpl.java:311)"
      ,"org.alfresco.repo.search.impl.lucene.LuceneCategoryServiceImpl.getRootCategories(LuceneCategoryServiceImpl.java:447)"
      ,"sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)"
      ,"sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)"
      ,"sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)"

kaynezhang
World-Class Innovator
World-Class Innovator

you have passed the store paramter in wrong format,it should be like this

workspace://SpacesStore