WEbScript FileUpload and tags Creation

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2014 10:44 AM
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
when i try to use returned array of tag nodes elsewhere as;
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
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
Labels:
- Labels:
-
Archive
8 REPLIES 8
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2014 12:37 PM
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
2.you creat the tag "Information" using
3. you try to give it a name originally intended,which will set its name to "Information" again.
4.then you will call
So it is a bad idea for you to make tag sensitive .
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 .

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2014 05:44 PM
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
Which is also verified by putting in breakpoint and run it slowly
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-15-2014 07:57 PM
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.
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2014 12:37 AM
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
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
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2014 01:23 AM
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.
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.

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2014 02:01 AM
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
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

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2014 07:04 AM
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)"
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2014 09:35 PM
you have passed the store paramter in wrong format,it should be like this
workspace://SpacesStore
