cancel
Showing results for 
Search instead for 
Did you mean: 

Database Connectivity in Alfresco Share ...??

nirvanvjain
Champ on-the-rise
Champ on-the-rise
Dear Folks,

I am working on Alfresco Share.

After Exploring a lot, as per my understanding – First of all Component FTL then its javascript file –then components calls the data webscript  and then (meta) data comes or goes to database.

How Alfresco's data webscript connects to database ? In which Function it connects to database ?

Please guide me at least by one simple example.

Thanks!
-Nirvan
9 REPLIES 9

fstnboy
Champ on-the-rise
Champ on-the-rise
Hi,

Alfresco's webscript basically uses Java backed objects to do clever stuff… To retrieve node's properties is uses the ScriptNode object, which uses the NodeService.

The NodeService, uses NodeDAOServiceImpl which uses a persistence framework to connect to the database at the background.


Hope this can help you….

nirvanvjain
Champ on-the-rise
Champ on-the-rise
Dear fstnboy,

Thanks a tonn for your reply.

Your answer is much more self explanatory, but Can you please help me with when complete example Say ,

In Upload,
FTL–flash-upload-min.js–upload.post.js–<THEN–Along with Java Class Name> ???

I know there are planty services in ALFRESCO such as Node , Workflow, Person , Authentication , fileFolder Server etc …. <I don't know Spring and Never did Java Coding for Alfresco Smiley Sad >

Thanks!
-Nirvan

cjimenez2581
Champ in-the-making
Champ in-the-making
I'd like an example where I could make an insert into a database using WF to save a property!
But I cant figure out how I can do that

sylvain78
Champ in-the-making
Champ in-the-making
In Alfresco, you never connect directly to the database.  You have to use the Java Foundation API, the Web Services, the RESTful API, Javascript API, CMIS, etc. which are all in /alfresco.

Now, Share typically uses the RESTful API and Alfresco data webscripts typically use the Javascript API : http://wiki.alfresco.com/wiki/3.4_JavaScript_API

So, if you need something in Share, that the RESTful API does not provide OOTB, you would write a data webscript which resides in /alfresco and you would invoke it in your presentation webscripts using the remote javascript object.

Note that a data webscript can be written only with javascript and freemarker if you don't want to code a java controller (but I would not recommend developing a javascript controller if you're doing complicated stuff…).

sylvain78
Champ in-the-making
Champ in-the-making
Here are a few files you can look at in the remote-api and slingshot projects.

Data webscript example : http://localhost:8080/alfresco/service/api/people/admin/sites

Data webscript files in source (remote-api project) :
/Remote API/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.sites.get.desc.xml
/Remote API/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.sites.get.js
/Remote API/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.sites.get.json.ftl

Presentation webscript call example (slingshot project) :
/Slingshot/config/alfresco/site-webscripts/org/alfresco/components/dashlets/my-sites.get.js

nirvanvjain
Champ on-the-rise
Champ on-the-rise
Here are a few files you can look at in the remote-api and slingshot projects.

Data webscript example : http://localhost:8080/alfresco/service/api/people/admin/sites

Data webscript files in source (remote-api project) :
/Remote API/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.sites.get.desc.xml
/Remote API/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.sites.get.js
/Remote API/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.sites.get.json.ftl

Presentation webscript call example (slingshot project) :
/Slingshot/config/alfresco/site-webscripts/org/alfresco/components/dashlets/my-sites.get.js

Dear Sir,

First of all I have no words to thank you but I know that Presentation webscript calls data webscript but How DATA WEBSCRIPT connects to JAVA CLASSES and inturns to the Database ? Sir, Request you to see Comment by "fstnboy"  above and please give me complete example, Please..!!

Say –>FTL–flash-upload-min.js–upload.post.js--<THEN–Along with Java Class Name> ???


I know some what about JAVA FOUNDATION API but not have worked on it. I know there are planty services in ALFRESCO such as Node , Workflow, Person , Authentication , fileFolder Server etc …. <I don't know Spring and Never did Java Coding for Alfresco Smiley Sad >

Awaiting for your reply.

Thanks!
-Nirvan

ddraper
World-Class Innovator
World-Class Innovator
Nirvan,

There is a saying "Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime".  The information that has already been appended to this thread should be more than sufficient for you to resolve this issue without requesting for complete code samples to solve your specific problem.  If you aren't sufficiently equipped with Java, JavaScript and Spring knowledge to complete your tasks then now is an excellent opportunity for you to gain that knowledge. There are many resources on the web that will help you with these concepts. I'd suggest you review the information in the links that have been thoughtfully posted by other community members before requesting again for a complete code solution.

Regards,
Dave

kevinr
Star Contributor
Star Contributor
Nirvan,

I highly suggest you purchase one of the many good books on Alfresco development. It is a very powerful platform with many rich and powerful features - however it is not a simple as writing a PHP script that directly connects to a SQL database like you might do for a simple website - there is a lot to learn first. You will need to understand concepts such as content modelling and REST APIs and Java or JavaScript services. I don't think you are going to get the answers to the detail level that you clearly need here. Come back one you have grasped the basics from a book.

Cheers,

Kev

sylvain78
Champ in-the-making
Champ in-the-making
Here are a few files you can look at in the remote-api and slingshot projects.

Data webscript example : http://localhost:8080/alfresco/service/api/people/admin/sites

Data webscript files in source (remote-api project) :
/Remote API/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.sites.get.desc.xml
/Remote API/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.sites.get.js
/Remote API/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.sites.get.json.ftl

Presentation webscript call example (slingshot project) :
/Slingshot/config/alfresco/site-webscripts/org/alfresco/components/dashlets/my-sites.get.js
It is a complete example, just look at the javascript controller (person.sites.get.js) :

function main()
{
    // Get the user name of the person to get
    var userName = url.templateArgs.userid;
   
    // Get the person who has that user name
    var person = people.getPerson(userName);
   
    if (person === null) 
    {
        // Return 404 - Not Found     
        status.setCode(status.STATUS_NOT_FOUND, "Person " + userName + " does not exist");
        return;
    }
   
    // Get the list of sites
    var sites = siteService.listUserSites(userName);
   
    var sizeString = args["size"];
    if (sizeString != null)
    {
        var size = parseInt(sizeString);
       
        if (size < sites.length)
        {
            // Only return the first n sites based on the passed page size
            var pagedSites = new Array(size);
            for (var index = 0; index < size; index++)
            {
                pagedSites[index] = sites[index];  
            }
           
            sites = pagedSites;
        }
    }
   
    model.sites = sites;
}

main();
This is using the following javascript API objects : people and siteService.  These are the kind of objects you would use to get stuff out of the repository.

In the case of the controller you are interested in (upload.post.js), this is also a javascript controller using the search javascript objects for example as in :


// This returns a ScriptNode from the repository (see Javascript API)
var updateNode = search.findNode(updateNodeRef);

// A few other bunch of Javascript API calls you can find in this controller (write content in the repository to the updatedNode, checkin updatedNode)
// Update the working copy content
updateNode.properties.content.write(content);
// Reset working copy mimetype and encoding
updateNode.properties.content.guessMimetype(filename);
updateNode.properties.content.guessEncoding();
// check it in again, with supplied version history note
updateNode = updateNode.checkin(description, majorVersion);

As for Java-backed webscript, you would have a description file and a template file as in any other webscript + a java class and a bean reference in your Spring context file.
But before getting into this, you would have to be somewhat familiar with the Foundation API, Spring and how to extend the Spring context in Alfresco and how to package and compile java code in Alfresco.

Java-backed webscripts, in my opinion, are great for debugging, even though you have to compile them.

As an example, you can look at a java-backed webscript such as "changepassword" in the source :
/Remote API/config/alfresco/templates/webscripts/org/alfresco/repository/person/changepassword.post.desc.xml
/Remote API/source/java/org/alfresco/repo/web/scripts/person/ChangePasswordPost.java (your java controller instead)
/Remote API/config/alfresco/templates/webscripts/org/alfresco/repository/person/changepassword.post.json.ftl
Spring bean : /Remote API/config/alfresco/web-scripts-application-context.xml (see the bean "webscript.org.alfresco.repository.person.changepassword.post")