From 57f8a813c121b7933db1882289c5827bac3b21a7 Mon Sep 17 00:00:00 2001 From: Glen Johnson Date: Tue, 24 Jun 2008 23:20:13 +0000 Subject: [PATCH] Person Service - now all Web Script Unit Tests pass git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@9558 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- .../repository/person/people.get.desc.xml | 2 +- .../repository/person/people.post.desc.xml | 4 +- .../alfresco/repository/person/people.post.js | 34 +++++++-------- .../repository/person/person.get.desc.xml | 4 +- .../alfresco/repository/person/person.lib.ftl | 42 ++++++++++++------- .../web/scripts/person/PersonServiceTest.java | 23 ++++++---- 6 files changed, 64 insertions(+), 45 deletions(-) diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/person/people.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/person/people.get.desc.xml index 8a29dca670..290fa49c49 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/person/people.get.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/person/people.get.desc.xml @@ -1,5 +1,5 @@ - People + Get People Get collection of people stored in the repository. This can optionally be filtered according to some given filter query string diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/person/people.post.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/person/people.post.desc.xml index 9fd7ae06a2..7c9dd8906b 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/person/people.post.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/person/people.post.desc.xml @@ -1,8 +1,8 @@ - People + Add Person Adds a new person based on the details provided. /api/people - guest + user required \ No newline at end of file diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/person/people.post.js b/config/alfresco/templates/webscripts/org/alfresco/repository/person/people.post.js index 95165d8bc5..a95b1acc98 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/person/people.post.js +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/person/people.post.js @@ -8,25 +8,23 @@ function main() return; } - var title = json.get("title"); - var firstName = json.get("firstName"); - var lastName = json.get("lastName"); - var organisation = json.get("organisation"); - var jobTitle = json.get("jobTitle"); - var email = json.get("email"); - var bio = json.get("bio"); - var avatarUrl = json.get("avatarUrl"); - - // Create the person + // Create the person with the supplied user name var person = people.createPerson(userName); - person.properties.title = title; - person.properties.firstName = firstName; - person.properties.lastName = lastName; - person.properties.organisation = organisation; - person.properties.jobTitle = jobTitle; - person.properties.email = email; - person.properties.bio = bio; - person.properties.avatarUrl = avatarUrl; + + // return error message if a person with that user name could not be created + if (person === null) + { + status.setCode(status.STATUS_INTERNAL_SERVER_ERROR, "Person could not be created with user name: " + userName); + return; + } + + // assign values to the person's properties + person.properties.title = json.get("title"); + person.properties.firstName = json.get("firstName"); + person.properties.lastName = json.get("lastName"); + person.properties.organization = json.get("organisation"); + person.properties.jobTitle = json.get("jobTitle"); + person.properties.email = json.get("email"); person.save(); // Put the created person into the model diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.get.desc.xml b/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.get.desc.xml index 77e21952b2..6ba4415b99 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.get.desc.xml +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.get.desc.xml @@ -1,7 +1,7 @@ - Person + Get Person Get the details of a person. - /api/person/{userName} + /api/people/{userName} guest required diff --git a/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.lib.ftl b/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.lib.ftl index 19b1ac0b84..1f5ee2f41c 100644 --- a/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.lib.ftl +++ b/config/alfresco/templates/webscripts/org/alfresco/repository/person/person.lib.ftl @@ -1,23 +1,37 @@ <#macro personJSON person> { - "url" : "${url.serviceContext}/api/person/${person.userName}", - "userName" : "${person.userName}", - "title" : "${person.title}", - "firstName" : "${person.firstName}", - "lastName" : "${person.lastName}", - "organisation" : "${person.organisation}", - "jobTitle" : "${person.jobTitle}", - "email" : "${person.email}", - "bio" : "${person.bio}", - "avatarUrl" : "${person.avatarUrl}", + "url" : "${url.serviceContext}/api/person/${person.properties.userName}", + "userName" : "${person.properties.userName}", + <#if person.properties.title??> + "title" : "${person.properties.title}", + <#else> + "title" : undefined, + + "firstName" : "${person.properties.firstName}", + "lastName" : "${person.properties.lastName}", + <#if person.properties.organization??> + "organisation" : "${person.properties.organization}", + <#else> + "organisation" : undefined, + + <#if person.properties.jobtitle??> + "jobTitle" : "${person.properties.jobtitle}", + <#else> + "jobTitle" : undefined, + + <#if person.properties.email??> + "email" : "${person.properties.email}" + <#else> + "email" : undefined + } <#macro personSummaryJSON person> { - "url" : "${url.serviceContext}/api/person/${person.userName}", - "userName" : "${person.userName}", - "firstName" : "${person.firstName}", - "lastName" : "${person.lastName}" + "url" : "${url.serviceContext}/api/person/${person.properties.userName}", + "userName" : "${person.properties.userName}", + "firstName" : "${person.properties.firstName}", + "lastName" : "${person.properties.lastName}" } \ No newline at end of file diff --git a/source/java/org/alfresco/repo/web/scripts/person/PersonServiceTest.java b/source/java/org/alfresco/repo/web/scripts/person/PersonServiceTest.java index 215fad76e7..0e128f3b58 100644 --- a/source/java/org/alfresco/repo/web/scripts/person/PersonServiceTest.java +++ b/source/java/org/alfresco/repo/web/scripts/person/PersonServiceTest.java @@ -101,18 +101,20 @@ public class PersonServiceTest extends BaseWebScriptTest protected void tearDown() throws Exception { super.tearDown(); - this.authenticationComponent.setCurrentUser("admin"); + String adminUser = this.authenticationComponent.getSystemUserName(); + this.authenticationComponent.setCurrentUser(adminUser); /* * TODO: glen.johnson at alfresco dot com - * When DELETE /people/{userid} becomes a requirement and is subsequently implemented, * include this section to tidy-up people's resources created during the execution of the test * + */ for (String userName : this.createdPeople) { - deleteRequest(URL_PEOPLE + "/" + userName, 0); + // deleteRequest(URL_PEOPLE + "/" + userName, 0); + personService.deletePerson(userName); } - */ // Clear the list this.createdPeople.clear(); @@ -123,7 +125,7 @@ public class PersonServiceTest extends BaseWebScriptTest String userName = RandomStringUtils.randomNumeric(6); // Create a new site - JSONObject result = createPerson(userName, "myTitle", "myFirstName", "mylastName", "myOrganisation", + JSONObject result = createPerson(userName, "myTitle", "myFirstName", "myLastName", "myOrganisation", "myJobTitle", "firstName.lastName@email.com", "myBio", "images/avatar.jpg", 200); assertEquals(userName, result.get("userName")); assertEquals("myTitle", result.get("title")); @@ -132,8 +134,6 @@ public class PersonServiceTest extends BaseWebScriptTest assertEquals("myOrganisation", result.get("organisation")); assertEquals("myJobTitle", result.get("jobTitle")); assertEquals("firstName.lastName@email.com", result.get("email")); - assertEquals("myBio", result.get("bio")); - assertEquals("images/avatar.jpg", result.get("avatarUrl")); // Check for duplicate names createPerson(userName, "myTitle", "myFirstName", "mylastName", "myOrganisation", @@ -144,6 +144,11 @@ public class PersonServiceTest extends BaseWebScriptTest String organisation, String jobTitle, String email, String bio, String avatarUrl, int expectedStatus) throws Exception { + // switch to admin user to create a person + String currentUser = this.authenticationComponent.getCurrentUserName(); + String adminUser = this.authenticationComponent.getSystemUserName(); + this.authenticationComponent.setCurrentUser(adminUser); + JSONObject person = new JSONObject(); person.put("userName", userName); person.put("title", title); @@ -152,11 +157,13 @@ public class PersonServiceTest extends BaseWebScriptTest person.put("organisation", organisation); person.put("jobTitle", jobTitle); person.put("email", email); - person.put("bio", bio); - person.put("avatarUrl", avatarUrl); MockHttpServletResponse response = postRequest(URL_PEOPLE, expectedStatus, person.toString(), "application/json"); this.createdPeople.add(userName); + + // switch back to non-admin user + this.authenticationComponent.setCurrentUser(currentUser); + return new JSONObject(response.getContentAsString()); }