You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@syncope.apache.org by cs...@apache.org on 2013/01/24 10:15:18 UTC
svn commit: r1437918 - in /syncope/trunk:
client/src/main/java/org/apache/syncope/client/services/proxy/
common/src/main/java/org/apache/syncope/common/services/
common/src/main/java/org/apache/syncope/common/to/
core/src/main/java/org/apache/syncope/c...
Author: cschneider
Date: Thu Jan 24 09:15:17 2013
New Revision: 1437918
URL: http://svn.apache.org/viewvc?rev=1437918&view=rev
Log:
SYNCOPE-231 NotficationService for CXF. Changing create in interface of service to reflect concept of returning url and id
Added:
syncope/trunk/core/src/main/java/org/apache/syncope/core/services/NotificationServiceImpl.java (with props)
Modified:
syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/NotificationServiceProxy.java
syncope/trunk/common/src/main/java/org/apache/syncope/common/services/NotificationService.java
syncope/trunk/common/src/main/java/org/apache/syncope/common/to/NotificationTO.java
syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/NotificationController.java
syncope/trunk/core/src/main/resources/restContext.xml
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/NotificationTestITCase.java
syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
Modified: syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/NotificationServiceProxy.java
URL: http://svn.apache.org/viewvc/syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/NotificationServiceProxy.java?rev=1437918&r1=1437917&r2=1437918&view=diff
==============================================================================
--- syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/NotificationServiceProxy.java (original)
+++ syncope/trunk/client/src/main/java/org/apache/syncope/client/services/proxy/NotificationServiceProxy.java Thu Jan 24 09:15:17 2013
@@ -18,8 +18,12 @@
*/
package org.apache.syncope.client.services.proxy;
+import java.net.URI;
import java.util.Arrays;
import java.util.List;
+
+import javax.ws.rs.core.Response;
+
import org.apache.syncope.common.services.NotificationService;
import org.apache.syncope.common.to.NotificationTO;
import org.springframework.web.client.RestTemplate;
@@ -43,9 +47,11 @@ public class NotificationServiceProxy ex
}
@Override
- public NotificationTO create(final NotificationTO notificationTO) {
- return getRestTemplate().postForObject(baseUrl + "notification/create.json", notificationTO,
+ public Response create(final NotificationTO notificationTO) {
+ NotificationTO notification = getRestTemplate().postForObject(baseUrl + "notification/create.json", notificationTO,
NotificationTO.class);
+ URI location = URI.create(baseUrl + "notification/read/" + notification.getId() + ".json");
+ return Response.created(location).entity(notification.getId()).build();
}
@Override
Modified: syncope/trunk/common/src/main/java/org/apache/syncope/common/services/NotificationService.java
URL: http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/services/NotificationService.java?rev=1437918&r1=1437917&r2=1437918&view=diff
==============================================================================
--- syncope/trunk/common/src/main/java/org/apache/syncope/common/services/NotificationService.java (original)
+++ syncope/trunk/common/src/main/java/org/apache/syncope/common/services/NotificationService.java Thu Jan 24 09:15:17 2013
@@ -21,26 +21,27 @@ package org.apache.syncope.common.servic
import java.util.List;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
+import javax.ws.rs.NotFoundException;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
+import javax.ws.rs.core.Response;
import org.apache.syncope.common.to.NotificationTO;
@Path("notifications")
public interface NotificationService {
+ @POST
+ Response create(NotificationTO notificationTO);
@GET
@Path("{notificationId}")
- NotificationTO read(@PathParam("notificationId") Long notificationId);
+ NotificationTO read(@PathParam("notificationId") Long notificationId) throws NotFoundException;
@GET
List<NotificationTO> list();
- @POST
- NotificationTO create(NotificationTO notificationTO);
-
@PUT
@Path("{notificationId}")
NotificationTO update(@PathParam("notificationId") Long notificationId, NotificationTO notificationTO);
Modified: syncope/trunk/common/src/main/java/org/apache/syncope/common/to/NotificationTO.java
URL: http://svn.apache.org/viewvc/syncope/trunk/common/src/main/java/org/apache/syncope/common/to/NotificationTO.java?rev=1437918&r1=1437917&r2=1437918&view=diff
==============================================================================
--- syncope/trunk/common/src/main/java/org/apache/syncope/common/to/NotificationTO.java (original)
+++ syncope/trunk/common/src/main/java/org/apache/syncope/common/to/NotificationTO.java Thu Jan 24 09:15:17 2013
@@ -21,11 +21,14 @@ package org.apache.syncope.common.to;
import java.util.ArrayList;
import java.util.List;
+import javax.xml.bind.annotation.XmlRootElement;
+
import org.apache.syncope.common.AbstractBaseBean;
import org.apache.syncope.common.search.NodeCond;
import org.apache.syncope.common.types.IntMappingType;
import org.apache.syncope.common.types.TraceLevel;
+@XmlRootElement
public class NotificationTO extends AbstractBaseBean {
private static final long serialVersionUID = -6145117115632592612L;
Modified: syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/NotificationController.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/NotificationController.java?rev=1437918&r1=1437917&r2=1437918&view=diff
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/NotificationController.java (original)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/rest/controller/NotificationController.java Thu Jan 24 09:15:17 2013
@@ -69,7 +69,7 @@ public class NotificationController exte
@PreAuthorize("hasRole('NOTIFICATION_LIST')")
@RequestMapping(method = RequestMethod.GET, value = "/list")
- public List<NotificationTO> list() throws NotFoundException {
+ public List<NotificationTO> list() {
List<Notification> notifications = notificationDAO.findAll();
@@ -88,15 +88,17 @@ public class NotificationController exte
@RequestMapping(method = RequestMethod.POST, value = "/create")
public NotificationTO create(final HttpServletResponse response, @RequestBody final NotificationTO notificationTO)
throws NotFoundException {
+ NotificationTO savedNotificationTO = createInternal(notificationTO);
+ response.setStatus(HttpServletResponse.SC_CREATED);
+ return savedNotificationTO;
+ }
+ public NotificationTO createInternal(final NotificationTO notificationTO)
+ throws NotFoundException {
LOG.debug("Notification create called with parameter {}", notificationTO);
-
Notification notification = notificationDAO.save(binder.createNotification(notificationTO));
-
auditManager.audit(Category.notification, NotificationSubCategory.create, Result.success,
"Successfully created notification: " + notification.getId());
-
- response.setStatus(HttpServletResponse.SC_CREATED);
return binder.getNotificationTO(notification);
}
Added: syncope/trunk/core/src/main/java/org/apache/syncope/core/services/NotificationServiceImpl.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/java/org/apache/syncope/core/services/NotificationServiceImpl.java?rev=1437918&view=auto
==============================================================================
--- syncope/trunk/core/src/main/java/org/apache/syncope/core/services/NotificationServiceImpl.java (added)
+++ syncope/trunk/core/src/main/java/org/apache/syncope/core/services/NotificationServiceImpl.java Thu Jan 24 09:15:17 2013
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.syncope.core.services;
+
+import java.net.URI;
+import java.util.List;
+
+import javax.ws.rs.PathParam;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.core.UriInfo;
+
+import org.apache.syncope.common.services.NotificationService;
+import org.apache.syncope.common.to.NotificationTO;
+import org.apache.syncope.core.rest.controller.NotificationController;
+import org.apache.syncope.core.util.NotFoundException;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+@Service
+public class NotificationServiceImpl implements NotificationService, ContextAware {
+
+ @Autowired
+ private NotificationController notificationController;
+
+ private UriInfo uriInfo;
+
+ @Override
+ public Response create(NotificationTO notificationTO) {
+ try {
+ NotificationTO createdNotificationTO = notificationController.createInternal(notificationTO);
+ URI location = uriInfo.getAbsolutePathBuilder().path("" + createdNotificationTO.getId()).build();
+ return Response.created(location).build();
+ } catch (NotFoundException e) {
+ throw new javax.ws.rs.NotFoundException(e);
+ }
+ }
+
+ @Override
+ public NotificationTO read(@PathParam("notificationId") Long notificationId) throws javax.ws.rs.NotFoundException {
+ try {
+ return notificationController.read(notificationId);
+ } catch (NotFoundException e) {
+ throw new javax.ws.rs.NotFoundException(e);
+ }
+ }
+
+ @Override
+ public List<NotificationTO> list() {
+ return notificationController.list();
+ }
+
+ @Override
+ public NotificationTO update(@PathParam("notificationId") Long notificationId,
+ NotificationTO notificationTO) {
+ try {
+ return notificationController.update(notificationTO);
+ } catch (NotFoundException e) {
+ throw new javax.ws.rs.NotFoundException(e);
+ }
+ }
+
+ @Override
+ public NotificationTO delete(@PathParam("notificationId") Long notificationId) {
+ try {
+ return notificationController.delete(notificationId);
+ } catch (NotFoundException e) {
+ throw new javax.ws.rs.NotFoundException(e);
+ }
+ }
+
+ @Override
+ public void setUriInfo(final UriInfo ui) {
+ this.uriInfo = ui;
+ }
+}
Propchange: syncope/trunk/core/src/main/java/org/apache/syncope/core/services/NotificationServiceImpl.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: syncope/trunk/core/src/main/resources/restContext.xml
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/main/resources/restContext.xml?rev=1437918&r1=1437917&r2=1437918&view=diff
==============================================================================
--- syncope/trunk/core/src/main/resources/restContext.xml (original)
+++ syncope/trunk/core/src/main/resources/restContext.xml Thu Jan 24 09:15:17 2013
@@ -67,6 +67,7 @@ under the License.
<jaxrs:server id="restContainer" address="/">
<jaxrs:serviceBeans>
<ref bean="configurationServiceImpl"/>
+ <ref bean="notificationServiceImpl"/>
<ref bean="connectorServiceImpl"/>
<ref bean="entitlementServiceImpl"/>
<ref bean="policyServiceImpl"/>
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=1437918&r1=1437917&r2=1437918&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 Thu Jan 24 09:15:17 2013
@@ -25,6 +25,8 @@ import static org.junit.Assert.assertNul
import java.util.List;
+import javax.ws.rs.core.Response;
+
import org.apache.syncope.common.search.AttributeCond;
import org.apache.syncope.common.search.MembershipCond;
import org.apache.syncope.common.search.NodeCond;
@@ -66,7 +68,9 @@ public class NotificationTestITCase exte
NodeCond recipients = NodeCond.getLeafCond(membCond);
notificationTO.setRecipients(recipients);
- NotificationTO actual = notificationService.create(notificationTO);
+ Response response = notificationService.create(notificationTO);
+ Long notificationId = (Long) response.getEntity();
+ NotificationTO actual = notificationService.read(notificationId);
assertNotNull(actual);
assertNotNull(actual.getId());
@@ -110,7 +114,8 @@ public class NotificationTestITCase exte
assertNotNull(e.getException(SyncopeClientExceptionType.NotFound));
notification = buildNotificationTO();
notification.setSelfAsRecipient(true);
- notification = notificationService.create(notification);
+ Response response = notificationService.create(notification);
+ notification = response.readEntity(NotificationTO.class);
}
NotificationTO deletedNotification = notificationService.delete(notification.getId());
@@ -133,8 +138,9 @@ public class NotificationTestITCase exte
NotificationTO actual = null;
SyncopeClientException exception = null;
try {
- actual = notificationService.create(notificationTO);
-
+ Response response = notificationService.create(notificationTO);
+ Long notificationId = (Long) response.getEntity();
+ actual = notificationService.read(notificationId);
} catch (SyncopeClientCompositeErrorException e) {
exception = e.getException(SyncopeClientExceptionType.InvalidNotification);
}
Modified: syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java
URL: http://svn.apache.org/viewvc/syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java?rev=1437918&r1=1437917&r2=1437918&view=diff
==============================================================================
--- syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java (original)
+++ syncope/trunk/core/src/test/java/org/apache/syncope/core/rest/TaskTestITCase.java Thu Jan 24 09:15:17 2013
@@ -27,6 +27,9 @@ import static org.junit.Assert.assertTru
import java.util.Collections;
import java.util.List;
import java.util.Set;
+
+import javax.ws.rs.core.Response;
+
import org.apache.syncope.common.search.AttributableCond;
import org.apache.syncope.common.search.AttributeCond;
import org.apache.syncope.common.search.MembershipCond;
@@ -524,7 +527,9 @@ public class TaskTestITCase extends Abst
notification.setSubject(subject);
notification.setTemplate("optin");
- notification = notificationService.create(notification);
+ Response response = notificationService.create(notification);
+ Long notificationId = (Long) response.getEntity();
+ notification = notificationService.read(notificationId);
assertNotNull(notification);
// 2. create user