Web Script: net/torda/alfresco/people/subscribe.get
Generated from /alfresco/s/script/net/torda/alfresco/people/subscribe.get on 24 déc. 2012 09:31:29

Script Properties
Id:net/torda/alfresco/people/subscribe.get
Short Name:Test Users with relations
Description:Create tests users for My Network Dashlet
Authentication:admin
Transaction:required
Method:GET
URL Template:/torda/test/testusers/{users}/{relations}
Format Style:any
Default Format:html
Negotiated Formats:[undefined]
Implementation:class org.springframework.extensions.webscripts.DeclarativeWebScript
Extensions:[undefined]

Store: workspace://SpacesStore/app:company_home/app:dictionary/cm:extensionwebscripts

[No implementation files]

Store: workspace://SpacesStore/app:company_home/app:dictionary/cm:webscripts

[No implementation files]

Store: classpath:alfresco/extension/templates/webscripts

File: net/torda/alfresco/people/subscribe.get.desc.xml
<webscript>
   <shortname>Test Users with relations</shortname>
   <description>Create tests users for My Network Dashlet</description>
   <family>Torda</family>
   <url>/torda/test/testusers/{users}/{relations}</url>
   <authentication>admin</authentication>
   <transaction allow="readwrite">required</transaction>
</webscript>
File: net/torda/alfresco/people/subscribe.get.html.ftl
<html>
<body>
Created users:
<ul>
<#list persons as person>
	<li>${person}</li>
</#list>
</ul>

Generated links:
<ul>
<#list links?keys as key>
	<li>${key} : 
		<ul>
		<#list links[key] as value>
			<li>${value}</li>
		</#list>
		</ul>
	</li>
</#list>
</ul>

</body>
</html>
File: net/torda/alfresco/people/subscribe.get.js
script:
{
	var MAIL_DOMAIN = "domaine";
	var firstNames = [ "Joe", "Jack", "John", "Bob", "Bill" ];
	var lastNames = [ "Doe", "Smith", "Martin", "Dupont", "Durand" ];
		
   var userNumber = url.templateArgs.users;
	var relationNumber = url.templateArgs.relations;
	
	/* Create users */
	var firstName, lastName, userName, email, personNode;
	var generatedPersons = [];
	for (var i = 0; i < userNumber; i++) {
		firstName = getRandomElement(firstNames);
		lastName = getRandomElement(lastNames);
		userName = firstName + "." + lastName;
		email = userName + "@" + MAIL_DOMAIN;
		personNode = people.createPerson(userName, firstName, lastName, email, userName, true);
		if (personNode != null) {
			generatedPersons.push(userName);
		}
	}

	/* Create relations */
	if (generatedPersons.length > 0) {
		var sourceUser, targetUser;
		var links = [];
		for (var i=0; i < relationNumber; i++) {
			sourceUser = getRandomElement(generatedPersons);
			targetUser = getRandomElement(generatedPersons);
			while (sourceUser == targetUser) {
				targetUser = getRandomElement(generatedPersons);
			}
			if (links[sourceUser] == null ||
			links[sourceUser].indexOf(targetUser) < 0) {
				subscription.follow(sourceUser, targetUser);
				if (links[sourceUser] == null) {
					links[sourceUser] = [];
				}
				links[sourceUser].push(targetUser);
			}
		}
	}
	
	model.persons = generatedPersons;
	model.links = links;
}

function getRandomElement(list) {
	return  list[Math.round(Math.random()*(list.length-1))];
}

Store: classpath:alfresco/templates/webscripts

[No implementation files]

Store: classpath:webscripts

[No implementation files]