Trouble with custome site creation script
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2009 02:19 PM
I am working on duplicating the functionality of the create-site script in share so i can hook on some extra functions (copy default files, add users) when the site is created.
I opted not to extend the default script because i didn't want to screw it up (yet). So, as a result, I created my own versions of create-sites and on the alfresco end, a script to create.
the alfresco script runs some validation and ultimately runs this
the share script calls the alfresco script and then once it completes runs this
After this runs, the sites are identical to sites created using the stock create-site script. Groups, Users, folders, dashboard and the nodebrowser for the site are indistinguishable from what a normal site looks like (so far as i can tell).
The problem is after i run this, the my-sites dashlet and site search page stop functioning.
the my site dashlet says
the site search page pops up saying
then when i click search it says this
I can also navigate to the newly created site manually at http://server:8080/share/page/site/shortName/dashboard. so i know it was created properly and it looks proper (haven't checked functionality)
Does anyone know what is missing from my scripts that would cause these errors or know what i should be doing to emulate this behavior(full code below) ??
my best guess is it is the presets. but have no idea where to begin on this
thanks
Adam
PS. Please forgive the use of get and hard coding variables, i just want it to work and tried to take all the ambiguity out of it
alfresco code (the .js file)
share code, the .js file
I opted not to extend the default script because i didn't want to screw it up (yet). So, as a result, I created my own versions of create-sites and on the alfresco end, a script to create.
the alfresco script runs some validation and ultimately runs this
var site = siteService.createSite(sitePreset, shortName, title, description, isPublic);
the share script calls the alfresco script and then once it completes runs this
var sitePreset = "site-dashboard";
var tokens = new Array();
tokens["siteid"] = 'shortName';
sitedata.newPreset(sitePreset, tokens);
model.response = "ahhh";
After this runs, the sites are identical to sites created using the stock create-site script. Groups, Users, folders, dashboard and the nodebrowser for the site are indistinguishable from what a normal site looks like (so far as i can tell).
The problem is after i run this, the my-sites dashlet and site search page stop functioning.
the my site dashlet says
No sites to display
the site search page pops up saying
Failed to retrieve site membership information for the current user. Join and Leave buttons will not be available
then when i click search it says this
Wrapped Exception (with status template): Error during processing of the template 'Expression jsonUtils.encodeJSONString(x) is undefined on line 2, column 23 in org/alfresco/repository/site/site.lib.ftl.'. Please contact your system administrator.
I can also navigate to the newly created site manually at http://server:8080/share/page/site/shortName/dashboard. so i know it was created properly and it looks proper (haven't checked functionality)
Does anyone know what is missing from my scripts that would cause these errors or know what i should be doing to emulate this behavior(full code below) ??
my best guess is it is the presets. but have no idea where to begin on this
thanks
Adam
PS. Please forgive the use of get and hard coding variables, i just want it to work and tried to take all the ambiguity out of it
alfresco code (the .js file)
//grab site, role and group argsvar shortName = args.site;var role = args.role;var groupName = "GROUP_" + args.group;var title = args.title;var description = null;var isPublic = false;//see if site name passed throughif (shortName == null || shortName.length == 0){ status.code = 404; status.message = "Shortname not specified"; status.redirect = true;} var site = siteService.getSite(shortName);// See if the shortName is availableif (site != null){ status.code = 404; status.message = "Shortname already in use"; status.redirect = true;} //preset ***dont think this is in use**** this is how Alfresco does it. looks like it is a "to-do"//var sitePreset = args.preset;var sitePreset = "site-dashboard";if (shortName == null || shortName.length == 0) { status.code = 404; status.message = "preset not real"; status.redirect = true; } //check if role is set//**************validate to see if it is a reall one in the future***********if (role == null || role == undefined){ status.code = 404; status.message = "roll not defined"; status.redirect = true;} //see if group is real. if so, grab it, if not error 404if (people.getGroup(groupName) != undefined){ var group = people.getGroup(groupName).properties["{http://www.alfresco.org/model/user/1.0}members"];}if (group == undefined){ status.code = 404; status.message = "Group not found"; status.redirect = true;}else { var membersAdded =""; //create site. var site = siteService.createSite(sitePreset, shortName, title, description, isPublic); // var tokens = new Array(); // tokens["siteid"] = shortName; // sitedata.newPreset(sitePreset, tokens); for (var i=0; i<group.length; i++) { //we have a valid username, just want to make sure they are a person var person = people.getPerson(group[i]); if (person == null) { status.setCode(status.STATUS_BAD_REQUEST, "The person with user name " + group[i] + " could not be found."); //return; } //add them to the group site.setMembership(group[i],role); membersAdded += group[i] +"<br />"; } model.group = group; model.membersAdded = membersAdded; model.siteName = shortName; model.role = role; }
share code, the .js file
function main(){var scriptRemoteConnector = remote.connect("alfresco");var repoResponse = scriptRemoteConnector.get("/sample/createproject?group=someGroup&site=desiredSiteShortName&role=SiteContributor&preset=site-dashboard&title=titleOfSite"); model.response = repoResponse; if (repoResponse.status == 401) { status.setCode(repoResponse.status, "error.loggedOut"); return; } else { var sitePreset = "site-dashboard";var tokens = new Array();tokens["siteid"] = 'desiredSiteShortName';sitedata.newPreset(sitePreset, tokens);model.response = "ahhh";}}main();
Labels:
- Labels:
-
Archive
4 REPLIES 4
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-02-2009 11:37 AM
I think i got this one figured out. I didnt pass it through site.lib.ftl
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2009 11:14 AM
Let us first get back to all necessary steps for creating a site programmatically
1) On DM repo side, a node needs to be created under /Sites space and it needs to have all required metadata such as sitePreset etc. This will be taken care of by siteService.createSite. This API is available on DM site as both JAVA API and JavaScript API. Keep in mind, it doesn't create any required data on AVM side.
2) on AVM repo side, for each site, we need to create all necessary SURF XML files such as dashboard.xml etc. All needed APIs/services for creating those files are available on Share side. It should be doable on DM site as well since we can use AVM related service to create files. But it will require much more work.
Now let us figure out possible solutions:
If we take a close look at the Share side create site service, you can see the extra step is
// Check if we got a positive result
if (repoJSON.shortName)
{
// Yes we did, now create the site in the webtier
var tokens = new Array();
tokens["siteid"] = repoJSON.shortName;
sitedata.newPreset(clientJSON.sitePreset, tokens);
model.success = true;
}
The key is to populate the sitedata object once DM side siteService.createSite is invoked.
To validate it, let us first create a site on DM side
var site = siteService.createSite("site-dashboard", "yongtest", "YongTestSite", "YongTestSite", true);
The new site will be created. But if you click on the site link, it will be forwarded to user dashboard.
Now let us add a new webscript to share
File: custom-site.get.desc.xml
<webscript>
<shortname>Utility Service for creating site programmatically</shortname>
<description>Utility Service for creating site programmatically</description>
<url>/modules/custom-site</url>
</webscript>
File:custom-site.get.html.ftl
empty
File: custom-site.get.js
var tokens = new Array();
tokens["siteid"] = args.shortName;
sitedata.newPreset(args.sitePreset, tokens);
Add all files to
share\WEB-INF\classes\alfresco\site-webscripts\org\alfresco \modules
Refresh Share webscript list.
Open a browser and hit the following link
http://localhost:8080/share/service/modules/custom-site ?shortName=yongtest&sitePreset=site-dashboard
Now, let us visit the site dashboard again and you you will find out it works.
So the conclusion is
The suggested solution is to write java code to invoke Share site service directly.
We can prepare a JSON object and post to the Share side service endpoint
/modules/create-site
Sample code (for how to prepare a JSON object and do a POST) can be found org.alfresco.repo.web.scripts.site.SiteServiceTest.
Again, we need to post it to the Share service endpoint not the DM service endpoint.
Yong
1) On DM repo side, a node needs to be created under /Sites space and it needs to have all required metadata such as sitePreset etc. This will be taken care of by siteService.createSite. This API is available on DM site as both JAVA API and JavaScript API. Keep in mind, it doesn't create any required data on AVM side.
2) on AVM repo side, for each site, we need to create all necessary SURF XML files such as dashboard.xml etc. All needed APIs/services for creating those files are available on Share side. It should be doable on DM site as well since we can use AVM related service to create files. But it will require much more work.
Now let us figure out possible solutions:
If we take a close look at the Share side create site service, you can see the extra step is
// Check if we got a positive result
if (repoJSON.shortName)
{
// Yes we did, now create the site in the webtier
var tokens = new Array();
tokens["siteid"] = repoJSON.shortName;
sitedata.newPreset(clientJSON.sitePreset, tokens);
model.success = true;
}
The key is to populate the sitedata object once DM side siteService.createSite is invoked.
To validate it, let us first create a site on DM side
var site = siteService.createSite("site-dashboard", "yongtest", "YongTestSite", "YongTestSite", true);
The new site will be created. But if you click on the site link, it will be forwarded to user dashboard.
Now let us add a new webscript to share
File: custom-site.get.desc.xml
<webscript>
<shortname>Utility Service for creating site programmatically</shortname>
<description>Utility Service for creating site programmatically</description>
<url>/modules/custom-site</url>
</webscript>
File:custom-site.get.html.ftl
empty
File: custom-site.get.js
var tokens = new Array();
tokens["siteid"] = args.shortName;
sitedata.newPreset(args.sitePreset, tokens);
Add all files to
share\WEB-INF\classes\alfresco\site-webscripts\org\alfresco \modules
Refresh Share webscript list.
Open a browser and hit the following link
http://localhost:8080/share/service/modules/custom-site ?shortName=yongtest&sitePreset=site-dashboard
Now, let us visit the site dashboard again and you you will find out it works.
So the conclusion is
The suggested solution is to write java code to invoke Share site service directly.
We can prepare a JSON object and post to the Share side service endpoint
/modules/create-site
Sample code (for how to prepare a JSON object and do a POST) can be found org.alfresco.repo.web.scripts.site.SiteServiceTest.
Again, we need to post it to the Share service endpoint not the DM service endpoint.
Yong

Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2011 07:25 AM
Hi ofrxnz,
Also does your site work after tomcat restart?
Thanks
Sans!!
I think i got this one figured out. I didnt pass it through site.lib.ftlWhat did you do to pass it through site.lib.ftl?
Also does your site work after tomcat restart?
Thanks
Sans!!
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2012 06:59 AM
Is there any solution for PHP Rest API for custom site create?
https://forums.alfresco.com/en/viewtopic.php?f=21&t=44985
https://forums.alfresco.com/en/viewtopic.php?f=21&t=44985
