AnsweredAssumed Answered

Trouble with custome site creation script

Question asked by ofrxnz on Apr 1, 2009
Latest reply on Jun 6, 2012 by devmehta555
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

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 args
var 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 through
if (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 available
if (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 404
if (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();

Outcomes