cancel
Showing results for 
Search instead for 
Did you mean: 

Extending an existing .post.json.js javascript controller

akusei
Champ in-the-making
Champ in-the-making
I'm trying to extend an existing .post.json.js javascript controller. I've done this successfully with share-header.get.js by using a module extension and now I want to add some additional "post" processing to the creation of a site. I've added a create-site.post.json.js file and the following module definition:


<module>
   <id>Create Site Extension</id>
   <version>1.0</version>
   <customizations>
      <customization>
         <targetPackageRoot>org.alfresco.modules</targetPackageRoot>
         <sourcePackageRoot>create-site</sourcePackageRoot>
      </customization>
   </customizations>
</module>


I've added the create-site.post.json.js to the directory /config/alfresco/site-webscripts/create-site inside my module's JAR file. The javascript in my create-site.post.json.js file doesn't seem to be running at all and yes, I've added it to the deployed modules list inside Alfresco.

I'm using Alfresco 5.0d. Does anyone know what I'm doing wrong? Is it even possible to add functionality to a post controller like you can a get controller?
1 ACCEPTED ANSWER

ddraper
World-Class Innovator
World-Class Innovator

I got asked to look into this thread and have done some debugging into it and it would seem that there is a bug in the way in which extension controller paths are looked up. Essentially what is happening is that Surf is looking for extension scripts with the name create-site.post.js and not create-site.post.json.js (note the missing .json).

The workaround to this problem is just to create your extension as create-site.post.js and that should then get processed.

View answer in original post

10 REPLIES 10

angelborroy
Community Manager Community Manager
Community Manager
It looks right.
Maybe the problem is in the code of your
create-site.post.json.js
Hyland Developer Evangelist

akusei
Champ in-the-making
Champ in-the-making
nope, just doesn't work. I added a function around my code to better debug it. I turned on server side debugging, chose to break on function enter and went to the create site form. When I went to the form the create-site.get.js was executed and the debugger hit the breakpoint on function enter. I then pressed the button the create the site and it hit the breakpoint on the built in create-site.post.json.js file and many other functions but never ever went into my code at all. I was even able to break into my custom create-site.get.js file. No clue why this is not working.

angelborroy
Community Manager Community Manager
Community Manager
Maybe it's conflicting with another extension. Have you any other module extension on your XML?
Hyland Developer Evangelist

akusei
Champ in-the-making
Champ in-the-making
Yes, but only one that modifies share-header.get.js and I'm not enabling that one in the module management. The module in question is only modifying creat-site.get.js and create-site.post.json.js. the get works fine but the post does not.

The code inside the post is very minimal and I've tested it elsewhere so I know it's not failing there, it's just not getting called.

I've also wrapped it in a function, turned on server side debugging and enabled "break on function enter" but it never hit the break point. 

angelborroy
Community Manager Community Manager
Community Manager
Can you provide a simple XML module extension and a sample
create-site.post.json.js
. It will help to find out this problem.
Hyland Developer Evangelist

angelborroy
Community Manager Community Manager
Community Manager
I've been testing your configuration in a clean project and (effectively) it does not work. Maybe you can review the info provided by Alfresco (http://docs.alfresco.com/community/tasks/dev-extensions-share-tutorials-js-customize.html) and put some light on this issue.
Hyland Developer Evangelist

akusei
Champ in-the-making
Champ in-the-making
That's my problem! I followed that tutorial to produce the module I have now. I'm able to modify the create-site.get.js but not the create-site.post.json.js. That link doesn't mention anything about .post files, only .get files.

WORKING MODULE
/config/alfresco/site-data/extensions/extension-modules.xml

<extension>
    <modules>
        <module>
            <id>Test Module</id>
            <version>1.0</version>
            <customizations>
                <customization>
                    <targetPackageRoot>org.alfresco.modules</targetPackageRoot>
                    <sourcePackageRoot>create-site</sourcePackageRoot>
                </customization>
            </customizations>
        </module>
   </modules>
</extension>


/config/alfresco/site-webscripts/create-site/create-site.get.js

model.sitePresets.push({
    id: "site-test",
    name: "TEST"
});


The above module (when activated) works perfectly. I click on create site and there is a new site type of "TEST" listed in the drop down on the form.

BROKEN NOT WORKING MODULE
/config/alfresco/site-data/extensions/extension-modules.xml

<extension>
    <modules>
        <module>
            <id>Test Module</id>
            <version>1.0</version>
            <customizations>
                <customization>
                    <targetPackageRoot>org.alfresco.modules</targetPackageRoot>
                    <sourcePackageRoot>create-site</sourcePackageRoot>
                </customization>
            </customizations>
        </module>
   </modules>
</extension>


/config/alfresco/site-webscripts/create-site/create-site.post.json.js

function deleteDashboard(type, id)
{
    var connector = remote.connect("alfresco");

    for (var col = 1; col < 5; col++)
    {
        for (var row = 1; row < 6; row++)
            connector.del("/remoteadm/delete/s/sitestore/alfresco/site-data/components/page.component-" + col + "-" + row + "." + type + "~" + id + "~dashboard.xml");
    }

    connector.del("/remoteadm/delete/s/sitestore/alfresco/site-data/pages/" + type + "/" + id + "/dashboard.xml");

    return status.STATUS_OK;
}

function test()
{
    deleteDashboard("site", "good-site");
}

test();


I know the function deleteDashboard works because I tested it in a different module that I created. I'm testing the post with this function so that I can verify that the dashboard page has been deleted from the existing "good-site" I've created.

This link is to the entire source code of the module I've created. Unless Alfresco doesn't allow extending POST controllers then this should work and I'm at a loss as to why it's not working.

<a href="https://drive.google.com/file/d/0By5d2e2jSbmJX0pRQmJXN1hfNnM/view?usp=sharing" target="_blank">Module Source</a> If you build this source into a JAR file and place inside tomcat/webapps/share/WEB-INF/lib and be sure to enable everything via http://ALFRESCOHOST/share/page/modules/deploy

angelborroy
Community Manager Community Manager
Community Manager
Last line of the documentation stays that it works only with a number of JSs, it depends on how that JS is developed. However, I don't know the conditions to predict this. Anyway, create-site.post does not sork, so you have to you use another approach in order to get your modifications done. Maybe overriding is the simpliest way.
Hyland Developer Evangelist

ddraper
World-Class Innovator
World-Class Innovator

I got asked to look into this thread and have done some debugging into it and it would seem that there is a bug in the way in which extension controller paths are looked up. Essentially what is happening is that Surf is looking for extension scripts with the name create-site.post.js and not create-site.post.json.js (note the missing .json).

The workaround to this problem is just to create your extension as create-site.post.js and that should then get processed.