You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by jb...@apache.org on 2013/01/25 14:34:00 UTC

svn commit: r1438507 - in /syncope/trunk: client/src/main/java/org/apache/syncope/client/services/proxy/ common/src/main/java/org/apache/syncope/common/services/ console/src/main/java/org/apache/syncope/console/ console/src/main/java/org/apache/syncope...

Author: jbernhardt
Date: Fri Jan 25 13:33:59 2013
New Revision: 1438507

URL: http://svn.apache.org/viewvc?rev=1438507&view=rev
Log:
[SYNCOPE-231]
* Adding RoleService

Modified:
    syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/RoleServiceProxy.java
    syncope/trunk/common/src/main/java/org/apache/syncope/common/services/RoleService.java
    syncope/trunk/console/src/main/java/org/apache/syncope/console/SyncopeSession.java
    syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/RoleRestClient.java
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/NotificationTestITCase.java
    syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java

Modified: syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/RoleServiceProxy.java
URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/RoleServiceProxy.java?rev=1438507&r1=1438506&r2=1438507&view=diff
==============================================================================
--- syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/RoleServiceProxy.java (original)
+++ syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/RoleServiceProxy.java Fri Jan 25 13:33:59 2013
@@ -18,8 +18,16 @@
  */
 package org.apache.syncope.client.services.proxy;
 
+import java.net.URI;
 import java.util.Arrays;
 import java.util.List;
+
+import javax.ws.rs.NotFoundException;
+import javax.ws.rs.NotSupportedException;
+import javax.ws.rs.ServiceUnavailableException;
+import javax.ws.rs.core.Response;
+
+import org.apache.syncope.common.SyncopeConstants;
 import org.apache.syncope.common.mod.RoleMod;
 import org.apache.syncope.common.search.NodeCond;
 import org.apache.syncope.common.services.RoleService;
@@ -39,14 +47,16 @@ public class RoleServiceProxy extends Sp
     }
 
     @Override
-    public Integer count() {
-        //return getRestTemplate().getForObject(baseUrl + "role/count.json", Integer.class);
-        throw new UnsupportedOperationException();
+    public int count() {
+        return Integer.valueOf(list().size());
     }
 
     @Override
-    public RoleTO create(final RoleTO roleTO) {
-        return getRestTemplate().postForObject(baseUrl + "role/create", roleTO, RoleTO.class);
+    public Response create(final RoleTO roleTO) {
+        RoleTO role = getRestTemplate().postForObject(baseUrl + "role/create", roleTO, RoleTO.class);
+
+        URI location = URI.create(baseUrl + "role/read/" + role.getId() + ".json");
+        return Response.created(location).header(SyncopeConstants.REST_HEADER_ID, role.getId()).build();
     }
 
     @Override
@@ -61,8 +71,7 @@ public class RoleServiceProxy extends Sp
 
     @Override
     public List<RoleTO> list(final int page, final int size) {
-        //return Arrays.asList(getRestTemplate().getForObject(baseURL + "role/list.json", RoleTO[].class, page, size));
-        throw new UnsupportedOperationException();
+        throw new ServiceUnavailableException();
     }
 
     @Override

Modified: syncope/trunk/common/src/main/java/org/apache/syncope/common/services/RoleService.java
URL: http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/services/RoleService.java?rev=1438507&r1=1438506&r2=1438507&view=diff
==============================================================================
--- syncope/trunk/common/src/main/java/org/apache/syncope/common/services/RoleService.java (original)
+++ syncope/trunk/common/src/main/java/org/apache/syncope/common/services/RoleService.java Fri Jan 25 13:33:59 2013
@@ -26,6 +26,8 @@ import javax.ws.rs.POST;
 import javax.ws.rs.Path;
 import javax.ws.rs.PathParam;
 import javax.ws.rs.QueryParam;
+import javax.ws.rs.core.Response;
+
 import org.apache.syncope.common.search.NodeCond;
 import org.apache.syncope.common.mod.RoleMod;
 import org.apache.syncope.common.to.RoleTO;
@@ -39,10 +41,10 @@ public interface RoleService {
 
     @GET
     @Path("count")
-    Integer count();
+    int count();
 
     @POST
-    RoleTO create(RoleTO roleTO);
+    Response create(RoleTO roleTO);
 
     @DELETE
     @Path("{roleId}")
@@ -80,4 +82,5 @@ public interface RoleService {
     @POST
     @Path("{roleId}")
     RoleTO update(@PathParam("roleId") Long roleId, RoleMod roleMod);
+
 }
\ No newline at end of file

Modified: syncope/trunk/console/src/main/java/org/apache/syncope/console/SyncopeSession.java
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/SyncopeSession.java?rev=1438507&r1=1438506&r2=1438507&view=diff
==============================================================================
--- syncope/trunk/console/src/main/java/org/apache/syncope/console/SyncopeSession.java (original)
+++ syncope/trunk/console/src/main/java/org/apache/syncope/console/SyncopeSession.java Fri Jan 25 13:33:59 2013
@@ -92,6 +92,10 @@ public class SyncopeSession extends WebS
         restTemplate = applicationContext.getBean(RestTemplate.class);
         baseURL = applicationContext.getBean("baseURL", String.class);
 
+        setupRESTClients();
+    }
+
+    protected void setupRESTClients() {
         services.put(ConfigurationService.class, new ConfigurationServiceProxy(baseURL, restTemplate));
         services.put(ConnectorService.class, new ConnectorServiceProxy(baseURL, restTemplate));
         services.put(EntitlementService.class, new EntitlementServiceProxy(baseURL, restTemplate));

Modified: syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/RoleRestClient.java
URL: http://svn.apache.org/viewvc/syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/RoleRestClient.java?rev=1438507&r1=1438506&r2=1438507&view=diff
==============================================================================
--- syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/RoleRestClient.java (original)
+++ syncope/trunk/console/src/main/java/org/apache/syncope/console/rest/RoleRestClient.java Fri Jan 25 13:33:59 2013
@@ -20,6 +20,8 @@ package org.apache.syncope.console.rest;
 
 import java.util.List;
 
+import javax.ws.rs.core.Response;
+
 import org.apache.syncope.common.mod.RoleMod;
 import org.apache.syncope.common.search.NodeCond;
 import org.apache.syncope.common.services.ResourceService;
@@ -27,7 +29,6 @@ import org.apache.syncope.common.service
 import org.apache.syncope.common.to.ConnObjectTO;
 import org.apache.syncope.common.to.RoleTO;
 import org.apache.syncope.common.types.AttributableType;
-import org.apache.syncope.common.validation.SyncopeClientCompositeErrorException;
 import org.springframework.stereotype.Component;
 
 /**
@@ -58,19 +59,18 @@ public class RoleRestClient extends Abst
     }
 
     @Override
-    public List<RoleTO> search(final NodeCond searchCond, final int page, final int size)
-            throws SyncopeClientCompositeErrorException {
+    public List<RoleTO> search(final NodeCond searchCond, final int page, final int size) {
         return getService(RoleService.class).search(searchCond, page, size);
     }
 
     @Override
-    public ConnObjectTO getRemoteObject(final String resourceName, final String objectId)
-            throws SyncopeClientCompositeErrorException {
+    public ConnObjectTO getRemoteObject(final String resourceName, final String objectId) {
         return getService(ResourceService.class).getConnector(resourceName, AttributableType.ROLE, objectId);
     }
 
     public RoleTO create(final RoleTO roleTO) {
-        return getService(RoleService.class).create(roleTO);
+        Response response = getService(RoleService.class).create(roleTO);
+        return (RoleTO) response.getEntity(); // FIXME after CXF migration
     }
 
     public RoleTO read(final Long id) {

Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java?rev=1438507&r1=1438506&r2=1438507&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/AuthenticationTestITCase.java Fri Jan 25 13:33:59 2013
@@ -54,7 +54,7 @@ import org.springframework.web.client.Ht
 public class AuthenticationTestITCase extends AbstractTest {
 
     // Enable running test more than once with parameters
-    public AuthenticationTestITCase(String contentType) {
+    public AuthenticationTestITCase(final String contentType) {
         super(contentType);
      }
 
@@ -81,7 +81,8 @@ public class AuthenticationTestITCase ex
         authRoleTO.setParent(8L);
         authRoleTO.addEntitlement("SCHEMA_READ");
 
-        authRoleTO = roleService.create(authRoleTO);
+        Response response = roleService.create(authRoleTO);
+        authRoleTO = getObject(response, RoleTO.class, roleService);
         assertNotNull(authRoleTO);
 
         // 1. create a schema (as admin)
@@ -90,7 +91,7 @@ public class AuthenticationTestITCase ex
         schemaTO.setMandatoryCondition("false");
         schemaTO.setType(SchemaType.String);
 
-        Response response = schemaService.create(AttributableType.USER, SchemaService.SchemaType.NORMAL, schemaTO);
+        response = schemaService.create(AttributableType.USER, SchemaService.SchemaType.NORMAL, schemaTO);
         SchemaTO newSchemaTO = getObject(response, SchemaTO.class, entitlementService);
         assertEquals(schemaTO, newSchemaTO);
 
@@ -411,7 +412,8 @@ public class AuthenticationTestITCase ex
         parentRole.addEntitlement("ROLE_1");
         parentRole.setParent(1L);
 
-        parentRole = roleService.create(parentRole);
+        Response response = roleService.create(parentRole);
+        parentRole = getObject(response, RoleTO.class, roleService);
         assertNotNull(parentRole);
 
         // Child role, with no entitlements
@@ -419,7 +421,8 @@ public class AuthenticationTestITCase ex
         childRole.setName("childAdminRole");
         childRole.setParent(parentRole.getId());
 
-        childRole = roleService.create(childRole);
+        response = roleService.create(childRole);
+        childRole = getObject(response, RoleTO.class, roleService);
         assertNotNull(childRole);
 
         // User with child role, created by admin

Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/NotificationTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/NotificationTestITCase.java?rev=1438507&r1=1438506&r2=1438507&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/NotificationTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/NotificationTestITCase.java Fri Jan 25 13:33:59 2013
@@ -114,7 +114,7 @@ public class NotificationTestITCase exte
     	NotificationTO notification = null;
     	try {
     		// Check for pre-loaded notification: must be deleted for other create tests success
-    		notification = notificationService.read(101L);	
+    		notification = notificationService.read(101L);
     	} catch (SyncopeClientCompositeErrorException e) {
     		assertNotNull(e.getException(SyncopeClientExceptionType.NotFound));
     		notification = buildNotificationTO();
@@ -122,7 +122,7 @@ public class NotificationTestITCase exte
             Response response = notificationService.create(notification);
             notification = response.readEntity(NotificationTO.class);
     	}
-    	
+
         NotificationTO deletedNotification = notificationService.delete(notification.getId());
         assertNotNull(deletedNotification);
 

Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java?rev=1438507&r1=1438506&r2=1438507&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/RoleTestITCase.java Fri Jan 25 13:33:59 2013
@@ -27,6 +27,9 @@ import static org.junit.Assert.fail;
 
 import java.util.ArrayList;
 import java.util.List;
+
+import javax.ws.rs.core.Response;
+
 import org.apache.syncope.common.mod.RoleMod;
 import org.apache.syncope.common.to.ConnObjectTO;
 import org.apache.syncope.common.to.RoleTO;
@@ -95,7 +98,8 @@ public class RoleTestITCase extends Abst
         roleTO.addVirtualAttribute(attributeTO("rvirtualdata", "rvirtualvalue"));
         roleTO.setRoleOwner(8L);
 
-        roleTO = roleService.create(roleTO);
+        Response response = roleService.create(roleTO);
+        roleTO = getObject(response, RoleTO.class, roleService);
         assertNotNull(roleTO);
 
         assertNotNull(roleTO.getVirtualAttributeMap());
@@ -124,7 +128,8 @@ public class RoleTestITCase extends Abst
         roleTO.setParent(8L);
         roleTO.setPasswordPolicy(4L);
 
-        RoleTO actual = roleService.create(roleTO);
+        Response response = roleService.create(roleTO);
+        RoleTO actual = getObject(response, RoleTO.class, roleService);
         assertNotNull(actual);
 
         actual = roleService.read(actual.getId());
@@ -147,7 +152,8 @@ public class RoleTestITCase extends Abst
 
         roleTO.addResource("resource-ldap");
 
-        roleTO = roleService.create(roleTO);
+        Response response = roleService.create(roleTO);
+        roleTO = getObject(response, RoleTO.class, roleService);
         assertNotNull(roleTO);
 
         RoleTO deletedRole = roleService.delete(roleTO.getId());
@@ -218,7 +224,8 @@ public class RoleTestITCase extends Abst
     @Test
     public void update() {
         RoleTO roleTO = buildRoleTO("latestRole");
-        roleTO = roleService.create(roleTO);
+        Response response = roleService.create(roleTO);
+        roleTO = getObject(response, RoleTO.class, roleService);
 
         assertEquals(1, roleTO.getAttributes().size());
 
@@ -255,7 +262,8 @@ public class RoleTestITCase extends Abst
         RoleTO roleTO = buildBasicRoleTO("withvirtual");
         roleTO.addVirtualAttribute(attributeTO("rvirtualdata", null));
 
-        roleTO = roleService.create(roleTO);
+        Response response = roleService.create(roleTO);
+        roleTO = getObject(response, RoleTO.class, roleService);
 
         assertNotNull(roleTO);
         assertEquals(1, roleTO.getVirtualAttributes().size());
@@ -275,7 +283,8 @@ public class RoleTestITCase extends Abst
         RoleTO roleTO = buildBasicRoleTO("withderived");
         roleTO.addDerivedAttribute(attributeTO("rderivedschema", null));
 
-        roleTO = roleService.create(roleTO);
+        Response response = roleService.create(roleTO);
+        roleTO = getObject(response, RoleTO.class, roleService);
 
         assertNotNull(roleTO);
         assertEquals(1, roleTO.getDerivedAttributes().size());
@@ -332,7 +341,8 @@ public class RoleTestITCase extends Abst
         String roleName = "torename" + getUUIDString();
         roleTO.setName(roleName);
 
-        RoleTO actual = roleService.create(roleTO);
+        Response response = roleService.create(roleTO);
+        RoleTO actual = getObject(response, RoleTO.class, roleService);
 
         assertNotNull(actual);
         assertEquals(roleName, actual.getName());
@@ -356,7 +366,8 @@ public class RoleTestITCase extends Abst
         roleTO.addEntitlement("USER_READ");
         roleTO.addEntitlement("SCHEMA_READ");
 
-        roleTO = roleService.create(roleTO);
+        Response response = roleService.create(roleTO);
+        roleTO = getObject(response, RoleTO.class, roleService);
         assertNotNull(roleTO);
         assertNotNull(roleTO.getEntitlements());
         assertFalse(roleTO.getEntitlements().isEmpty());