cancel
Showing results for 
Search instead for 
Did you mean: 

any API to verify if document is new in a space/folder?

rajshekar
Champ in-the-making
Champ in-the-making
Hi,

any alfresco API to verify, if a document is created/entered in a space/folder.
When a document is uploaded via WebDav/FTP in space called "Test", i need the document url to see and download.

Thanks,
Rajshekar.
10 REPLIES 10

mrogers
Star Contributor
Star Contributor
Yea Policies and Rules.

rajshekar
Champ in-the-making
Champ in-the-making
From the following code, successfully am able to get the latest document.

var path = args.path;
sortby = "@" + "cm:modified";
generic = "PATH:\"" + path + "//.\"";
generic+= " AND " + "TYPE:\"" + "cm:folder" + "\"";
results = search.luceneSearch(generic, sortby, false);
currentNode = search.findNode(results[0].nodeRef);
displayPath = currentNode.displayPath;
logger.log("CURRENT NODE IS : " + displayPath);
docs = currentNode.childFileFolders(true, true, 'cm:folder', 0, 1, 0, 'cm:modified', false, null);
files = docs.getPage();

But when i pass
http://localhost:6280/repo/service/api/document/latest?path=/app:company_home/st:sites/cm:test/cm:do...

in the url, if am passing any numeric value having space name, then i get
Exception unexpected '20130810'…

Tried to encode the whole path with (search.ISO9075Encode(path)) but unable to get the noderef.

Is there any to get noderef from Xpath?

mitpatoliya
Star Collaborator
Star Collaborator
If there is issue with encoding you can try encoding each of the folder name separately.
First split the path by "/"
then in iterate though that array in for loop and encode each name of folder and create full query again by appending encoded name.

Yes, but how to get noderef on encoded path, i get cannot read noderef on unknown property.

Thanks,
Rajshekar.

mitpatoliya
Star Collaborator
Star Collaborator
You need to use encoded path in query instead of genericPath which you are using right now.



var path = args.path;
var []patharr=path.split("/");
var encodedpath= "PATH:\"";
for(var comp in patharr)
{
encodedpath=encodedpath+search.ISO9075Encode(comp);
}
encodedpath=encodedpath+"//.\""+" AND " + "TYPE:\"" + "cm:folder" + "\"";

sortby = "@" + "cm:modified";

results = search.luceneSearch(encodedpath, sortby, false);
currentNode = search.findNode(results[0].nodeRef);
displayPath = currentNode.displayPath;
logger.log("CURRENT NODE IS : " + displayPath);
docs = currentNode.childFileFolders(true, true, 'cm:folder', 0, 1, 0, 'cm:modified', false, null);
files = docs.getPage();


something like this just verify the syntax as I have not tested this code

Hi,

Using the above i get the following,
072121690 TypeError: Cannot read property "nodeRef" from undefined
***currentNode = search.findNode(results[0].nodeRef);****
Am not sure where am going wrong…

Thanks,
Rajshekar.

Also i get
results = search.luceneSearch(encodedpath, sortby, false);
logger.log("RESULTS : " + results);
As empty….

But when i use without encoding the path i get
******************************************************************************
RESULTS : Node Type: {http://www.alfresco.org/model/content/1.0}folder, Node Aspects: [{http://www.alfresco.org/model/content/1.0}auditable, {http://www.alfresco.org/model/application/1.0}uifacets, {http://www.alfresco.org/model/system/1.0}referenceable, {http://www.alfresco.org/model/content/1.0}titled, {http://www.alfresco.org/model/system/1.0}localized],Node Type: {http://www.alfresco.org/model/content/1.0}folder, Node Aspects: [{http://www.alfresco.org/model/content/1.0}auditable, {http://www.alfresco.org/model/application/1.0}uifacets, {http://www.alfresco.org/model/system/1.0}referenceable, {http://www.alfresco.org/model/content/1.0}titled, {http://www.alfresco.org/model/system/1.0}localized, {http://www.alfresco.org/model/system/1.0}temporary],Node Type: {http://www.alfresco.org/model/content/1.0}folder, Node Aspects: [{http://www.alfresco.org/model/content/1.0}auditable, {http://www.alfresco.org/model/system/1.0}referenceable, {http://www.alfresco.org/model/content/1.0}titled, {http://www.alfresco.org/model/system/1.0}localized],Node Type: {http://www.alfresco.org/model/content/1.0}folder, Node Aspects: [{http://www.alfresco.org/model/content/1.0}auditable, {http://www.alfresco.org/model/application/1.0}uifacets, {http://www.alfresco.org/model/system/1.0}referenceable, {http://www.alfresco.org/model/content/1.0}titled, {http://www.alfresco.org/model/system/1.0}localized],Node Type: {http://www.alfresco.org/model/content/1.0}folder, Node Aspects: [{http://www.alfresco.org/model/content/1.0}auditable, {http://www.alfresco.org/model/application/1.0}uifacets, {http://www.alfresco.org/model/system/1.0}referenceable, {http://www.alfresco.org/model/content/1.0}titled, {http://www.alfresco.org/model/system/1.0}localized],Node Type: {http://www.alfresco.org/model/content/1.0}folder, Node Aspects: [{http://www.alfresco.org/model/content/1.0}auditable, {http://www.alfresco.org/model/application/1.0}uifacets, {http://www.alfresco.org/model/system/1.0}referenceable, {http://www.alfresco.org/model/content/1.0}titled, {http://www.alfresco.org/model/system/1.0}localized, {http://www.alfresco.org/model/system/1.0}temporary],Node Type: {http://www.alfresco.org/model/content/1.0}folder, Node Aspects: [{http://www.alfresco.org/model/content/1.0}auditable, {http://www.alfresco.org/model/application/1.0}uifacets, {http://www.alfresco.org/model/system/1.0}referenceable, {http://www.alfresco.org/model/content/1.0}titled, {http://www.alfresco.org/model/system/1.0}localized, {http://www.alfresco.org/model/system/1.0}temporary]
*******************************************************************************

I think that is why am not able to get the noderef.

Thanks,
Rajshekar.

mitpatoliya
Star Collaborator
Star Collaborator
It is returning you the script node array which you can iterate as follow


for (var i=0; i<results.length; i++)
   {
     var test= "Name: " + results.name ;
   }

Hi,

Am not sure what you are trying to say, can you please elaborate on this.

When i use this
results = search.luceneSearch(encodedpath, sortby, false);
i get results as empty, looks like query is not accepting the encoded path.

Thanks,
Rajshekar.