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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -64,11 +64,14 @@ public class RepositoryTemplateProcessor extends FreeMarkerProcessor
protected String defaultEncoding; protected String defaultEncoding;
protected Configuration templateConfig; protected Configuration templateConfig;
protected FreeMarkerProcessor freeMarkerProcessor; protected FreeMarkerProcessor freeMarkerProcessor;
private int updateDelay = 0;
private int cacheSize = 512;
/* (non-Javadoc) /* (non-Javadoc)
* @see org.alfresco.repo.template.FreeMarkerProcessor#setDefaultEncoding(java.lang.String) * @see org.alfresco.repo.template.FreeMarkerProcessor#setDefaultEncoding(java.lang.String)
*/ */
@Override
public void setDefaultEncoding(String defaultEncoding) public void setDefaultEncoding(String defaultEncoding)
{ {
this.defaultEncoding = defaultEncoding; this.defaultEncoding = defaultEncoding;
@@ -82,6 +85,25 @@ public class RepositoryTemplateProcessor extends FreeMarkerProcessor
return this.defaultEncoding; 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 * @param searchPath
*/ */
@@ -151,8 +173,8 @@ public class RepositoryTemplateProcessor extends FreeMarkerProcessor
Configuration config = new Configuration(); Configuration config = new Configuration();
// setup template cache // setup template cache
config.setCacheStorage(new MruCacheStorage(20, 100)); config.setCacheStorage(new MruCacheStorage(this.cacheSize, this.cacheSize << 1));
config.setTemplateUpdateDelay(0); config.setTemplateUpdateDelay(updateDelay);
// setup template loaders // setup template loaders
List<TemplateLoader> loaders = new ArrayList<TemplateLoader>(); List<TemplateLoader> loaders = new ArrayList<TemplateLoader>();