You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streams.apache.org by ds...@apache.org on 2013/11/08 17:36:11 UTC
svn commit: r1540111 - in /incubator/streams/branches/webservice:
streams-components/src/main/java/org/apache/streams/components/service/
streams-components/src/main/java/org/apache/streams/components/service/impl/
streams-components/src/test/java/org/...
Author: dsullivan
Date: Fri Nov 8 16:36:11 2013
New Revision: 1540111
URL: http://svn.apache.org/r1540111
Log:
getTags returns tags for subscriber
Added:
incubator/streams/branches/webservice/streams-components/src/main/java/org/apache/streams/components/service/StreamsTagsService.java
incubator/streams/branches/webservice/streams-components/src/main/java/org/apache/streams/components/service/impl/StreamsTagsServiceImpl.java
incubator/streams/branches/webservice/streams-components/src/test/java/org/apache/streams/components/service/StreamsTagsServiceTest.java
Removed:
incubator/streams/branches/webservice/streams-components/src/main/java/org/apache/streams/components/service/StreamsTagsUpdatingService.java
incubator/streams/branches/webservice/streams-components/src/main/java/org/apache/streams/components/service/impl/StreamsTagsUpdatingServiceImpl.java
incubator/streams/branches/webservice/streams-components/src/test/java/org/apache/streams/components/service/StreamsTagsUpdatingServiceTest.java
Modified:
incubator/streams/branches/webservice/streams-persistence/src/main/resources/cassandra.properties
incubator/streams/branches/webservice/streams-web/src/main/java/org/apache/streams/mvc/controller/StreamsWebController.java
Added: incubator/streams/branches/webservice/streams-components/src/main/java/org/apache/streams/components/service/StreamsTagsService.java
URL: http://svn.apache.org/viewvc/incubator/streams/branches/webservice/streams-components/src/main/java/org/apache/streams/components/service/StreamsTagsService.java?rev=1540111&view=auto
==============================================================================
--- incubator/streams/branches/webservice/streams-components/src/main/java/org/apache/streams/components/service/StreamsTagsService.java (added)
+++ incubator/streams/branches/webservice/streams-components/src/main/java/org/apache/streams/components/service/StreamsTagsService.java Fri Nov 8 16:36:11 2013
@@ -0,0 +1,10 @@
+package org.apache.streams.components.service;
+
+import org.codehaus.jackson.JsonParseException;
+
+import java.io.IOException;
+
+public interface StreamsTagsService {
+ String getTags(String subscriberId) throws Exception;
+ String updateTags(String subscriberId, String tagsJson) throws Exception;
+}
Added: incubator/streams/branches/webservice/streams-components/src/main/java/org/apache/streams/components/service/impl/StreamsTagsServiceImpl.java
URL: http://svn.apache.org/viewvc/incubator/streams/branches/webservice/streams-components/src/main/java/org/apache/streams/components/service/impl/StreamsTagsServiceImpl.java?rev=1540111&view=auto
==============================================================================
--- incubator/streams/branches/webservice/streams-components/src/main/java/org/apache/streams/components/service/impl/StreamsTagsServiceImpl.java (added)
+++ incubator/streams/branches/webservice/streams-components/src/main/java/org/apache/streams/components/service/impl/StreamsTagsServiceImpl.java Fri Nov 8 16:36:11 2013
@@ -0,0 +1,50 @@
+package org.apache.streams.components.service.impl;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.streams.components.activitysubscriber.ActivityStreamsSubscriberWarehouse;
+import org.apache.streams.components.service.StreamsSubscriptionRepositoryService;
+import org.apache.streams.components.service.StreamsTagsService;
+import org.apache.streams.persistence.model.ActivityStreamsSubscription;
+import org.codehaus.jackson.map.DeserializationConfig;
+import org.codehaus.jackson.map.ObjectMapper;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+
+@Component
+public class StreamsTagsServiceImpl implements StreamsTagsService {
+ private static final Log LOG = LogFactory.getLog(StreamsTagsServiceImpl.class);
+
+ private StreamsSubscriptionRepositoryService repositoryService;
+ private ActivityStreamsSubscriberWarehouse subscriberWarehouse;
+ private ObjectMapper mapper;
+
+ @Autowired
+ public StreamsTagsServiceImpl(StreamsSubscriptionRepositoryService repositoryService, ActivityStreamsSubscriberWarehouse subscriberWarehouse) {
+ this.repositoryService = repositoryService;
+ this.subscriberWarehouse = subscriberWarehouse;
+ this.mapper = new ObjectMapper();
+ mapper.configure(DeserializationConfig.Feature.FAIL_ON_UNKNOWN_PROPERTIES, false);
+ }
+
+ @Override
+ public String getTags(String subscriberId) throws Exception{
+ ActivityStreamsSubscription subscription = repositoryService.getSubscriptionByInRoute(subscriberId);
+ return mapper.writeValueAsString(subscription.getTags());
+ }
+
+ @Override
+ public String updateTags(String subscriberId, String tagsJson) throws Exception {
+ LOG.info("updating tags for " + subscriberId);
+
+ Map<String, List> updateTags = (Map<String, List>) mapper.readValue(tagsJson, Map.class);
+ repositoryService.updateTags(subscriberId, new HashSet<String>(updateTags.get("add")), new HashSet<String>(updateTags.get("remove")));
+ subscriberWarehouse.updateSubscriber(repositoryService.getSubscriptionByInRoute(subscriberId));
+
+ return "Tags Updated Successfully!";
+ }
+}
Added: incubator/streams/branches/webservice/streams-components/src/test/java/org/apache/streams/components/service/StreamsTagsServiceTest.java
URL: http://svn.apache.org/viewvc/incubator/streams/branches/webservice/streams-components/src/test/java/org/apache/streams/components/service/StreamsTagsServiceTest.java?rev=1540111&view=auto
==============================================================================
--- incubator/streams/branches/webservice/streams-components/src/test/java/org/apache/streams/components/service/StreamsTagsServiceTest.java (added)
+++ incubator/streams/branches/webservice/streams-components/src/test/java/org/apache/streams/components/service/StreamsTagsServiceTest.java Fri Nov 8 16:36:11 2013
@@ -0,0 +1,62 @@
+package org.apache.streams.components.service;
+
+import org.apache.streams.components.activitysubscriber.ActivityStreamsSubscriberWarehouse;
+import org.apache.streams.components.service.impl.StreamsTagsServiceImpl;
+import org.apache.streams.persistence.model.ActivityStreamsSubscription;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import static org.easymock.EasyMock.*;
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertThat;
+
+public class StreamsTagsServiceTest {
+ private StreamsTagsService tagsService;
+ private StreamsSubscriptionRepositoryService repositoryService;
+ private ActivityStreamsSubscriberWarehouse subscriberWarehouse;
+
+ @Before
+ public void setup(){
+ repositoryService = createMock(StreamsSubscriptionRepositoryService.class);
+ subscriberWarehouse = createMock(ActivityStreamsSubscriberWarehouse.class);
+ tagsService = new StreamsTagsServiceImpl(repositoryService, subscriberWarehouse);
+ }
+
+ @Test
+ public void updateTagsTest() throws Exception {
+ String subscriberId = "subscriberId";
+ String tagsJson = "{\"add\":[\"this\"], \"remove\":[\"that\"]}";
+ ActivityStreamsSubscription subscription = createMock(ActivityStreamsSubscription.class);
+
+ repositoryService.updateTags(eq(subscriberId), isA(Set.class), isA(Set.class));
+ expectLastCall();
+ expect(repositoryService.getSubscriptionByInRoute(subscriberId)).andReturn(subscription);
+ subscriberWarehouse.updateSubscriber(subscription);
+ expectLastCall();
+ replay(repositoryService,subscriberWarehouse);
+
+ String returned = tagsService.updateTags(subscriberId,tagsJson);
+
+ assertThat(returned,is(equalTo("Tags Updated Successfully!")));
+ }
+
+ @Test
+ public void getTagsTest() throws Exception {
+ String subscriberId = "subscriberId";
+ ActivityStreamsSubscription subscription = createMock(ActivityStreamsSubscription.class);
+ Set<String> tags = new HashSet<String>(Arrays.asList("tags"));
+
+ expect(repositoryService.getSubscriptionByInRoute(subscriberId)).andReturn(subscription);
+ expect(subscription.getTags()).andReturn(tags);
+ replay(subscription,repositoryService);
+
+ String returned = tagsService.getTags(subscriberId);
+
+ assertThat(returned, is(equalTo("[\"tags\"]")));
+ }
+}
Modified: incubator/streams/branches/webservice/streams-persistence/src/main/resources/cassandra.properties
URL: http://svn.apache.org/viewvc/incubator/streams/branches/webservice/streams-persistence/src/main/resources/cassandra.properties?rev=1540111&r1=1540110&r2=1540111&view=diff
==============================================================================
--- incubator/streams/branches/webservice/streams-persistence/src/main/resources/cassandra.properties (original)
+++ incubator/streams/branches/webservice/streams-persistence/src/main/resources/cassandra.properties Fri Nov 8 16:36:11 2013
@@ -1,5 +1,5 @@
cassandra.keyspaceName=keyspaceB
cassandra.activitystreamsColumnFamilyName=activitystreamsD
cassandra.subscriptionColumnFamilyName=subscriptionsD
-cassandra.publisherColumnFamilyName=publishersD
+cassandra.publisherColumnFamilyName=publishersE
cassandra.cassandraPort=127.0.0.1
\ No newline at end of file
Modified: incubator/streams/branches/webservice/streams-web/src/main/java/org/apache/streams/mvc/controller/StreamsWebController.java
URL: http://svn.apache.org/viewvc/incubator/streams/branches/webservice/streams-web/src/main/java/org/apache/streams/mvc/controller/StreamsWebController.java?rev=1540111&r1=1540110&r2=1540111&view=diff
==============================================================================
--- incubator/streams/branches/webservice/streams-web/src/main/java/org/apache/streams/mvc/controller/StreamsWebController.java (original)
+++ incubator/streams/branches/webservice/streams-web/src/main/java/org/apache/streams/mvc/controller/StreamsWebController.java Fri Nov 8 16:36:11 2013
@@ -23,7 +23,7 @@ public class StreamsWebController {
private StreamsSubscriberRegistrationService subscriberRegistrationService;
private StreamsActivityPublishingService activityPublishingService;
private StreamsActivityReceivingService activityReceivingService;
- private StreamsTagsUpdatingService tagsUpdatingService;
+ private StreamsTagsService tagsService;
@Autowired
public StreamsWebController(
@@ -31,12 +31,12 @@ public class StreamsWebController {
StreamsSubscriberRegistrationService subscriberRegistrationService,
StreamsActivityPublishingService activityPublishingService,
StreamsActivityReceivingService activityReceivingService,
- StreamsTagsUpdatingService tagsUpdatingService) {
+ StreamsTagsService tagsService) {
this.publisherRegistrationService = publisherRegistrationService;
this.subscriberRegistrationService = subscriberRegistrationService;
this.activityPublishingService = activityPublishingService;
this.activityReceivingService = activityReceivingService;
- this.tagsUpdatingService = tagsUpdatingService;
+ this.tagsService = tagsService;
}
/**
@@ -66,7 +66,7 @@ public class StreamsWebController {
@ResponseBody
public ResponseEntity<String> registerSubscriber(@RequestBody String payload, @RequestHeader("host") String host) {
try {
- return new ResponseEntity<String>("http://" + host + "/streams-web/app/activity/" + subscriberRegistrationService.register(payload), HttpStatus.OK);
+ return new ResponseEntity<String>("http://" + host + "/streams-web/app/getActivity/" + subscriberRegistrationService.register(payload), HttpStatus.OK);
} catch (Exception e) {
log.error(e);
return new ResponseEntity<String>(e.getMessage(), HttpStatus.BAD_REQUEST);
@@ -97,7 +97,7 @@ public class StreamsWebController {
* @param subscriberID the id of the subscriber
* @return an array of activity for this subscriber
*/
- @RequestMapping(value = "/activity/{subscriberID}", method = RequestMethod.GET)
+ @RequestMapping(value = "/getActivity/{subscriberID}", method = RequestMethod.GET)
@ResponseBody
public ResponseEntity<String> getActivity(@PathVariable("subscriberID") String subscriberID) {
HttpHeaders responseHeaders = new HttpHeaders();
@@ -109,13 +109,30 @@ public class StreamsWebController {
* this method is the entry point for updating tags
*
* @param subscriberID the id of the subscriber
- * @return an array of activity for this subscriber
+ * @return a message indicating whether the update was successful
*/
- @RequestMapping(value = "/activity/{subscriberID}", method = RequestMethod.POST)
+ @RequestMapping(value = "/updateTags/{subscriberID}", method = RequestMethod.POST)
@ResponseBody
public ResponseEntity<String> updateTags(@PathVariable("subscriberID") String subscriberID, @RequestBody String payload) {
try {
- return new ResponseEntity<String>(tagsUpdatingService.updateTags(subscriberID, payload), HttpStatus.OK);
+ return new ResponseEntity<String>(tagsService.updateTags(subscriberID, payload), HttpStatus.OK);
+ } catch (Exception e) {
+ log.error(e);
+ return new ResponseEntity<String>(e.getMessage(), HttpStatus.BAD_REQUEST);
+ }
+ }
+
+ /**
+ * this method is the entry point for updating tags
+ *
+ * @param subscriberID the id of the subscriber
+ * @return an array of tags for this subscriber
+ */
+ @RequestMapping(value = "/getTags/{subscriberID}", method = RequestMethod.GET)
+ @ResponseBody
+ public ResponseEntity<String> getTags(@PathVariable("subscriberID") String subscriberID) {
+ try {
+ return new ResponseEntity<String>(tagsService.getTags(subscriberID), HttpStatus.OK);
} catch (Exception e) {
log.error(e);
return new ResponseEntity<String>(e.getMessage(), HttpStatus.BAD_REQUEST);