cancel
Showing results for 
Search instead for 
Did you mean: 

Create a link to show up a document in the repository

jlabuelo
Champ on-the-rise
Champ on-the-rise
Hi all

We are saving some of our documents in Alfresco indexed with a specific set of metadata information. We would like to link another system we have designed and where we also store the same metadata for each document stored in Alfresco.

Exactly what we would like to achieve is to design some source of "link" that will be generated from the externall system (SystemA) to point to Alfresco and which will include the metadata information that identifies the exact document.

Somehow we would like Alfresco to showup the document in the navigator as soon as this link "hits" the system, there is no need to show up the Alfresco UI.

Any ideas about how to design this?

Thanks a lot in advance!
6 REPLIES 6

mitpatoliya
Star Collaborator
Star Collaborator
You can use document view link with format.
http://<serverhost>:<post>/share/page/site/test/document-details?nodeRef=<noderef of document>
Where you can create link of any of you alfresco repository document by appending it's noderef in the end
ex..
http://localhost:9090/share/page/site/test/document-details?nodeRef=workspace://SpacesStore/25485c70...

But it will indeed show alfresco UI.

cperez
Champ in-the-making
Champ in-the-making
Thanks for your reply.

But we don't know if it's possible to do the same but with a ticket, because we need to send three metadata (telephone, docId and user) inside the link like parameters to identify the document.
We do not store the nodeRef inside this external system but we do this three parameters that I mentioned before. The idea is to call the document somehow in alfresco using this three parameters. Our first thought was to use a ticket (as we read in this forum),Do you know if this is a good way to do it?  and if so could you let us know how.
Also If you think this option is possible the way you explain but using these 3 metadata values could you show us an example or a document that explains how to do it please?


Thanks a lot in advance!

mitpatoliya
Star Collaborator
Star Collaborator
If you really want to get you documents using three parameters only then this how you can do it.

1)Create a webscript in alfresco which accept those three parameters and search in repository based on those parameters within Alfresco,get the respective noderef from repository ,create that document detail url and return you that url.

2) You can keep keep authentication for that webscript as "none" in that case it will not require any authentication otherwise you can use ticket to call this webscript also.

3) Get ticket from alfresco using authentication webscript.
   It is something like this
"http://localhost:8080/alfresco/service/api/login?u=admin&pw=admin"

4) append that ticket in your webscript call to get authenticated
http://localhost:9090/share/page/site/test/document-details?nodeRef=<nodref>& ticket=<ticket from step3>

cperez
Champ in-the-making
Champ in-the-making
Hi Mits

I think we are almost there!!! I am able to get access to the document I want to show up after the search using the parameters in the URL… however the problem is that Alfresco keeps asking me Login and Password before I show up the pdf document and this is something I want to avoid, I need to go straight from the URL to the document show up with not "interruptions".

Let me explain you what we have done so far

First we have created a Script to perform the search using the parameters the url will pass. This is the code of our script as a example where the parameter is only the name of the file:


// Búsquda del fichero .pdf con el nombre indicado como parámetro
var spath="'+PATH:\"app:company_home/app:intranet//*\" + ";
var scontent="@\\{http\\://www.alfresco.org/model/content/1.0\\}content.mimetype:application/pdf + ";
var qname = "@cm\\:name:" + args.name;
var strq=spath+scontent+qname;

var content=search.luceneSearch(strq);

// buscar usuario indicado como parámetro
var luceneQuery = "+@cm\\:userName:"+args.user;
var users = search.luceneSearch(luceneQuery);


// Mostrar error al no encontrar el fichero y/o el usuario
if (content.length != 1 || users.length!=1)
{
   status.code = 404;
   status.message = "File " + url.extension + " not found.";
   status.redirect = true;
}

model.fichero = content[0];
model.ticket = session.getTicket();


Then we have modified the file showContent.get.desc.xml   like this setting up different access levels (none in this example):

<webscript>
   <shortname>Show Content</shortname>
   <description>Show user specific content identified by parameters </description>
   <url>/showContent?name={nameArgument}&amp;user={userName}</url>
   <authentication>none</authentication>
   <transaction>required</transaction>
</webscript>


Then we have created a ftl file like this to show up the document


<html>
   <head>
      <title>Mostrar fichero</title>
   </head>
   <body>
      <script>
       
            window.location.href = "${url.serviceContext}/api/node/content/${fichero.nodeRef.storeRef.protocol}/${fichero.nodeRef.storeRef.identifier}/${fichero.nodeRef.id}/${fichero.name?url}?alf_ticket=${ticket}   ";
       
      </script>
   </body>
</html>


So now when we use an URL like http://IP_Address:8080/alfresco/service/showContent?name=documento3.pdf

If we set up the authentication to "none", we get an error screen saying:

The Web Script /alfresco/service/showContent has responded with a status of 500 - Internal Error.

500 Description:   An error inside the HTTP server which prevented it from fulfilling the request.

Message:   Wrapped Exception (with status template): A valid SecureContext was not provided in the RequestContext
   
Exception:   net.sf.acegisecurity.AuthenticationCredentialsNotFoundException - A valid SecureContext was not provided in the RequestContext



However if the authentication is set up to "user" then the Login&Password screen appears and we can not go straight to the document.

Question here is . Is there any way to "pass" somehow the login and password as parameters, or avoid this Login&Password screen and go straight to the document?

Thanks a lot for your help once more in advance

Yes, You need to use ticket to bypass authentication as mentioned by Ramesh.

romschn
Star Collaborator
Star Collaborator
If you have kept configuration as NONE for your webscript and still want to query against alfresco repository then in your webscript controller it requires to run that portion using system user.

For your scenario, if you want to avoid username/password dialog box appearing while you hit the webscript then here are the steps.
1. Set authentication as user in webscript desc.xml
2. First invoke the login webscript (which mitpatoliya already mentioned)- http://localhost:8080/alfresco/service/api/login?u=admin&pw=admin
   This will return a ticket in response.
3. Use the returned ticket while invoking your webscript. This will be the alf_ticket parameter.
   so, your webscript URL will appear as following - /alfresco/service/showContent?parrameter1=____&alf_ticket=___.