Fix for ETHREEOH-100, cleanup to some webscripts as ETHREEOH-100 now fixed.

Basic "people" API for FreeMarker - just getPerson() and getGroup() currently.
Template cache size and delay now configurable in RepositoryTemplateProcessor (like they already are in PresentationTemplateProcessor) - related default cache size tweaks.

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13788 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Kevin Roast
2009-03-31 19:42:31 +00:00
parent dbec12a9c7
commit 2c43d8eb06
7 changed files with 122 additions and 101 deletions

View File

@@ -1,20 +1,20 @@
function main()
{
// Try and get the person
var userid = url.templateArgs.userid;
var person = people.getPerson(userid);
if (person == null)
{
// 404 since person resource could not be found
status.setCode(status.STATUS_NOT_FOUND, "The user " + userid + " could not be found");
return;
}
// Get the preferences for the person
var preferences = preferenceService.getPreferences(userid, args["pf"]);
// Convert the preferences to JSON and place in the model
model.preferences = jsonUtils.toJSONString(preferences);
// Try and get the person
var userid = url.templateArgs.userid;
var person = people.getPerson(userid);
if (person == null)
{
// 404 since person resource could not be found
status.setCode(status.STATUS_NOT_FOUND, "The user " + userid + " could not be found");
return;
}
// Get the preferences for the person
var preferences = preferenceService.getPreferences(userid, args["pf"]);
// Convert the preferences to JSON and place in the model
model.preferences = jsonUtils.toJSONString(preferences);
}
main();

View File

@@ -1,41 +1,40 @@
function main()
{
// Get the url values
var urlElements = url.extension.split("/");
var shortName = urlElements[0];
var userName = urlElements[2];
// Get the site
var site = siteService.getSite(shortName);
if (site == null)
{
// Site cannot be found
status.setCode(status.STATUS_NOT_FOUND, "The site " + shortName + " does not exist.");
return;
}
var person = people.getPerson(userName);
if (person == null)
{
// Person cannot be found
status.setCode(status.STATUS_NOT_FOUND, "The person with user name " + userName + " does not exist.");
return;
}
// Get the role of the user
var role = site.getMembersRole(userName);
if (role == null)
{
// Person is not a member of the site
status.setCode(status.STATUS_NOT_FOUND, "The person with user name " + userName + " is not a member of the site " + shortName);
return;
}
// Pass the values to the template
model.site = site;
model.person = person;
model.role = role;
// Get the url values
var urlElements = url.extension.split("/");
var shortName = urlElements[0];
var userName = urlElements[2];
// Get the site
var site = siteService.getSite(shortName);
if (site == null)
{
// Site cannot be found
status.setCode(status.STATUS_NOT_FOUND, "The site " + shortName + " does not exist.");
return;
}
var person = people.getPerson(userName);
if (person == null)
{
// Person cannot be found
status.setCode(status.STATUS_NOT_FOUND, "The person with user name " + userName + " does not exist.");
return;
}
// Get the role of the user
var role = site.getMembersRole(userName);
if (role == null)
{
// Person is not a member of the site
status.setCode(status.STATUS_NOT_FOUND, "The person with user name " + userName + " is not a member of the site " + shortName);
return;
}
// Pass the values to the template
model.site = site;
model.person = person;
model.role = role;
}
main();
main();

View File

@@ -1,24 +1,24 @@
<#macro membershipJSON site role person>
<#escape x as jsonUtils.encodeJSONString(x)>
<#escape x as jsonUtils.encodeJSONString(x)>
{
"role" : "${role}",
"person":
{
"userName" : "${person.properties.userName}",
"firstName" : "${person.properties.firstName}",
"lastName" : "${person.properties.lastName}",
<#if person.assocs["cm:avatar"]??>
"avatar" : "${"api/node/" + person.assocs["cm:avatar"][0].nodeRef?string?replace('://','/') + "/content/thumbnails/avatar"}",
</#if>
<#if person.properties.jobtitle??>
"jobtitle" : "${person.properties.jobtitle}",
</#if>
<#if person.properties.organization??>
"organization" : "${person.properties.organization}",
</#if>
"url" : "${url.serviceContext + "/api/people/" + person.properties.userName}"
},
"url" : "${url.serviceContext + "/api/sites/" + site.shortName + "/memberships/" + person.properties.userName}"
"role" : "${role}",
"person":
{
"userName" : "${person.properties.userName}",
"firstName" : "${person.properties.firstName}",
"lastName" : "${person.properties.lastName}",
<#if person.assocs["cm:avatar"]??>
"avatar" : "${"api/node/" + person.assocs["cm:avatar"][0].nodeRef?string?replace('://','/') + "/content/thumbnails/avatar"}",
</#if>
<#if person.properties.jobtitle??>
"jobtitle" : "${person.properties.jobtitle}",
</#if>
<#if person.properties.organization??>
"organization" : "${person.properties.organization}",
</#if>
"url" : "${url.serviceContext + "/api/people/" + person.properties.userName}"
},
"url" : "${url.serviceContext + "/api/sites/" + site.shortName + "/memberships/" + person.properties.userName}"
}
</#escape>
</#escape>
</#macro>

View File

@@ -14,18 +14,18 @@ var memberships = site.listMembers(nameFilter, roleFilter, sizeString != null ?
var peopleList = Array(memberships.length);
for (userName in memberships)
{
var person = people.getPerson(userName);
peopleList["_" + userName] = person; // make sure the keys are strings
var person = people.getPerson(userName);
// make sure the keys are strings - as usernames may be all numbers!
peopleList['_' + userName] = person;
}
// also copy over the memberships.
var mems = {};
var pos = 0; // memberships[userName] won't return the correct value if userName is a digit-only value
for (userName in memberships)
{
var membershipType = memberships[pos];
mems["_" + userName] = membershipType; // make sure the keys are strings
pos++;
var membershipType = memberships[userName];
// make sure the keys are strings - as usernames may be all numbers!
mems['_' + userName] = membershipType;
}
// Pass the information to the template

View File

@@ -2,7 +2,7 @@
<#assign userNames = memberships?keys />
[
<#list userNames as userName>
<@membershipLib.membershipJSON site=site role=memberships[userName] person=people[userName] />
<#if userName_has_next>,</#if>
<@membershipLib.membershipJSON site=site role=memberships[userName] person=people[userName] />
<#if userName_has_next>,</#if>
</#list>
]

View File

@@ -1,22 +1,22 @@
function main()
{
// Get the shortname
var shortName = url.extension;
// Get the site
var site = siteService.getSite(shortName);
if (site != null)
{
// Pass the site to the template
model.site = site;
}
else
{
// Return 404
status.setCode(404, "Site " + shortName + " does not exist");
return;
}
// Get the shortname
var shortName = url.extension;
// Get the site
var site = siteService.getSite(shortName);
if (site != null)
{
// Pass the site to the template
model.site = site;
}
else
{
// Return 404
status.setCode(404, "Site " + shortName + " does not exist");
return;
}
}
main();
main();

View File

@@ -64,11 +64,14 @@ public class RepositoryTemplateProcessor extends FreeMarkerProcessor
protected String defaultEncoding;
protected Configuration templateConfig;
protected FreeMarkerProcessor freeMarkerProcessor;
private int updateDelay = 0;
private int cacheSize = 512;
/* (non-Javadoc)
* @see org.alfresco.repo.template.FreeMarkerProcessor#setDefaultEncoding(java.lang.String)
*/
@Override
public void setDefaultEncoding(String defaultEncoding)
{
this.defaultEncoding = defaultEncoding;
@@ -81,6 +84,25 @@ public class RepositoryTemplateProcessor extends FreeMarkerProcessor
{
return this.defaultEncoding;
}
/**
* @param updateDelay the time in seconds between checks on the modified date for cached templates
*/
public void setUpdateDelay(int updateDelay)
{
this.updateDelay = updateDelay;
}
/**
* @param cacheSize the size of the MRU template cache, default is 256
*/
public void setCacheSize(int cacheSize)
{
if (cacheSize >= 0)
{
this.cacheSize = cacheSize;
}
}
/**
* @param searchPath
@@ -151,9 +173,9 @@ public class RepositoryTemplateProcessor extends FreeMarkerProcessor
Configuration config = new Configuration();
// setup template cache
config.setCacheStorage(new MruCacheStorage(20, 100));
config.setTemplateUpdateDelay(0);
config.setCacheStorage(new MruCacheStorage(this.cacheSize, this.cacheSize << 1));
config.setTemplateUpdateDelay(updateDelay);
// setup template loaders
List<TemplateLoader> loaders = new ArrayList<TemplateLoader>();
for (Store apiStore : searchPath.getStores())