cancel
Showing results for 
Search instead for 
Did you mean: 

Search for a file inside the avm store

garima
Champ in-the-making
Champ in-the-making
I have to search a file placed inside the avm store.

Using the inbuilt webscript I can traverse through the avm store and am able to see my file.

But I want to write and use a web script inside a php file wherein i can specify the name of the file to be searched in the avm store. It should give back the file in HTTP response.

Do I need a node_id to achieve this? If yes, how can I get the node_id of my file?
9 REPLIES 9

pmonks
Star Contributor
Star Contributor
Are you trying to find all files with a given name (eg. "web.xml"), or trying to retrieve a specific file directly from an AVM store using its path and filename as a key (eg. "/ROOT/WEB-INF/web.xml")?

Either way, you'll need to implement a custom web script that receives the filename (whether fully qualified or not), finds the file in the repository (see below for more details on this step) and then streams back the contents of the file, if it exists (return a 404 HTTP status if no files were found).  If you're attempting to find all files with a given name, you'd also have to figure out what to return if multiple files exist with the same name (ie. in different folders).

I can think of at least two ways to find files in an AVM store:
1. (recommended if you're looking for fully qualified files) traverse the folder tree in the AVM store until you find matching file(s) - the built in /api/path/content web script does this for the DM repository already and it's probably a good source of ideas on how to do this
2. configure indexing of files stored in the AVM (http://wiki.alfresco.com/wiki/Metadata_Extraction#XML_Metadata_Extractor_Configuration_for_WCM provides a starting point for how this might be done), and then have the web script issue a Lucene query to find all files with the given name

Arguably all files in the AVM should have their "system" metadata (filename etc.) indexed into Lucene automatically, but doing so requires virtualisation of the Lucene indexes (so that searches work as expected within each sandbox), and that's quite complex.

garima
Champ in-the-making
Champ in-the-making
Thanks for the quick response.

I am trying to retrieve a specific file directly from an AVM store using its path and filename as a key.

The built in /api/path/content web script is unclear to me as I am not able to run it through a browser.
GET /alfresco/service/api/node/content{;property}/{store_type}/{store_id}/{node_id}?a={attach?}
GET /alfresco/service/api/path/content{;property}/{store_type}/{store_id}/{path}?a={attach?}
According to me:
property = '<name/title/creator.. etc>'
store_type = 'avm'
store_id = '<domain name>' which we enter while creating the web project.
But what is node_id. From where do I get this?

Also, how do I see the code for this web script for writing a customized web script.

pmonks
Star Contributor
Star Contributor
Yeah it's going to require a custom web script - unfortunately the /api/path/content web script doesn't seem to be able to retrieve content from an AVM store (bug report http://issues.alfresco.com/browse/AR-1977 has been filed for this issue).

The source code for the web scripts is in one of two places (depending on whether it was implemented in Javascript or Java):
1. the source code for the built-in Javascript web scripts is located within the Alfresco WAR file at WEB-INF/classes/alfresco/templates, which (if you're running Alfresco on Tomcat) gets exploded to ${TOMCAT_HOME}/webapps/alfresco/WEB-INF/classes/alfresco/templates
2. the source code for the built-in Java webscripts is located within the web client project in the Alfresco source code, which can be obtained from our public Subversion server (more details at http://wiki.alfresco.com/wiki/Alfresco_SVN_Development_Environment)

pmonks
Star Contributor
Star Contributor
Just to follow up, if you do implement a custom web script that does this, would you mind posting the code back here?  This is probably a reasonably common requirement, and while we work on fixing AR-1977 others will find it useful to have a workaround readily available.  Thanks in advance!

garima
Champ in-the-making
Champ in-the-making
I searched both the places (Javascript and java Implementation Places) but there is only the description xml file present. There is neither .js file nor .ftl file.
Where do I look for the code?

Or If you can guide me in writing the .ftl file that would be great.

And surely, I can post the code back!!

garima
Champ in-the-making
Champ in-the-making
Here is the code. It works!!
Firstly, I used the inbuilt web script to get the login ticket.

I then used the ticket for invoking customized web script by sending two parameters: {storeid} and {filename}. i.e. the id of the store in which the given filename has to be searched.

The code for customized web script is:

Desc XML file
<webscript>
  <shortname>AVM Stores LookUp</shortname>
  <description>Returning the specified XML file</description>
  <url>/sample/avm/store/file?store={storeid}&amp;file={filename}</url>
  <format default="text"/>
  <authentication>admin</authentication>
  <transaction>required</transaction>
</webscript>

FTL File
<#assign stagingURL = avm.assetUrl("${args.store}","${args.file}")>
${stagingURL}


This gives back the staging URL which can be used to get back the desired file.
I basically aim at getting the xml file and parsing it inside my php file.

There is a small query:
Instead of passing the username and password as a plain text in the login web script can I use the encrypted username and password?

pmonks
Star Contributor
Star Contributor
Instead of passing the username and password as a plain text in the login web script can I use the encrypted username and password?

If you're accessing the web script via /alfresco/service you can use HTTP basic authentication - this doesn't encrypt the username / password by itself, but used in combination with SSL (ie. https) it's pretty secure.

You can also access web scripts via /alfresco/wcservice, in which case it's authenticated using whatever authentication mechanism has been configured for the web client (which may or may not encrypt usernames / passwords, depending on which authentication mechanism you've configured).

garima
Champ in-the-making
Champ in-the-making
If you're accessing the web script via /alfresco/service you can use HTTP basic authentication - this doesn't encrypt the username / password by itself, but used in combination with SSL (ie. https) it's pretty secure.

How do I call the web script via SSL (https) from PHP code?
I am able to access the web scripts from the browser using https. But not able to call them through the PHP code.

pmonks
Star Contributor
Star Contributor
I'm not a PHP guy, but a quick google for "PHP HTTPS" turned up a bunch of hits:

    http://www.google.com/search?q=PHP+HTTPS

It looks like PHP has had native support for HTTP over SSL since version 4.3.0, and there are some libraries that provide easy ways to do HTTP authentication (basic, digest and NTLM).