@Test public void represent() throws Exception { sut.setPathOverride("/resources/atom/stream/query/keywords/test"); final Request request = context.mock(Request.class); final Map<String, Object> attributes = new HashMap<String, Object>(); attributes.put("query", ""); attributes.put("mode", "query"); context.checking(new Expectations() { { allowing(request).getAttributes(); will(returnValue(attributes)); oneOf(principalPopulator).getPrincipal(null, null); oneOf(serviceActionController).execute(with(any(ServiceActionContext.class)), with(equal(action))); will(returnValue(results)); } }); sut.initParams(request); Representation actual = sut.represent(null); context.assertIsSatisfied(); }
@SuppressWarnings("unchecked") @Override public Representation represent(final Variant variant) throws ResourceException { if (log.isDebugEnabled()) { log.debug("Path: " + getPath()); } SyndFeed feed = new SyndFeedImpl(); feed.setFeedType("atom_1.0"); String status = GOOD_STATUS; try { JSONObject queryJson = null; if (mode.equals("query")) { queryJson = requestParser.parseRequest(getPath(), 5); feed.setTitle("Eureka Activity Stream Feed"); feed.setLink(baseUrl); feed.setDescription(""); } else if (mode.equals("saved")) { Stream stream = streamMapper.execute(new FindByIdRequest("Stream", streamId)); String feedTitle = ("Eureka Streams: " + stream.getName()); feed.setTitle(feedTitle); feed.setLink(baseUrl); feed.setDescription(feedTitle); if (stream == null) { throw new Exception("Unknown saved stream."); } queryJson = JSONObject.fromObject(stream.getRequest()); } else { throw new Exception("Unknown request mode."); } JSONObject query = queryJson.getJSONObject("query"); if (!query.has("sortBy")) { query.put("sortBy", "date"); } log.debug("Making request using: " + queryJson); PrincipalActionContext ac = new ServiceActionContext(queryJson.toString(), principalPopulator.getPrincipal(null, null)); PagedSet<ActivityDTO> activities = (PagedSet<ActivityDTO>) serviceActionController.execute(ac, action); feed.setUri(baseUrl + getRequest().getResourceRef().getPath()); if (activities.getPagedSet().size() > 0) { feed.setPublishedDate(activities.getPagedSet().get(0).getPostedTime()); } else { feed.setPublishedDate(new Date()); } List entries = new ArrayList(); for (ActivityDTO activity : activities.getPagedSet()) { SyndEntry entry; SyndContent description; String title = null; switch (activity.getBaseObjectType()) { case BOOKMARK: title = activity.getActor().getDisplayName() + ": " + activity.getBaseObjectProperties().get("content") + " " + activity.getBaseObjectProperties().get("targetUrl"); break; case NOTE: title = activity.getActor().getDisplayName() + ": " + activity.getBaseObjectProperties().get("content"); break; case PHOTO: title = activity.getActor().getDisplayName() + ": " + activity.getBaseObjectProperties().get("content"); break; case VIDEO: title = activity.getActor().getDisplayName() + ": " + activity.getBaseObjectProperties().get("content"); break; default: break; } if (title != null) { title = title.replace("%EUREKA:ACTORNAME%", activity.getActor().getDisplayName()); entry = new SyndEntryImpl(); entry.setTitle(title); entry.setAuthor(activity.getActor().getDisplayName()); String linkPrefix = activity.getDestinationStream().getType() == EntityType.PERSON ? "/#people/" : "/#groups/"; String link = baseUrl + linkPrefix + activity.getDestinationStream().getUniqueIdentifier() + "?activityId=" + activity.getId(); entry.setLink(link); entry.setUri(link); entry.setPublishedDate(activity.getPostedTime()); description = new SyndContentImpl(); description.setType("text/plain"); description.setValue(title); entry.setDescription(description); entries.add(entry); } } feed.setEntries(entries); } catch (Exception ex) { log.error("Error:" + ex.toString()); } log.debug(status); SyndFeedOutput output = new SyndFeedOutput(); StringWriter writer = new StringWriter(); try { output.output(feed, writer); } catch (IOException e) { log.error("error in writing feed"); } catch (FeedException e) { log.error("error in feed"); } Representation rep = new StringRepresentation(writer.toString(), MediaType.TEXT_XML); rep.setExpirationDate(new Date(0L)); return rep; }
StreamXMLResource extends SmpResource { @SuppressWarnings("unchecked") @Override public Representation represent(final Variant variant) throws ResourceException { if (log.isDebugEnabled()) { log.debug("Path: " + getPath()); } SyndFeed feed = new SyndFeedImpl(); feed.setFeedType("atom_1.0"); String status = GOOD_STATUS; try { JSONObject queryJson = null; if (mode.equals("query")) { queryJson = requestParser.parseRequest(getPath(), 5); feed.setTitle("Eureka Activity Stream Feed"); feed.setLink(baseUrl); feed.setDescription(""); } else if (mode.equals("saved")) { Stream stream = streamMapper.execute(new FindByIdRequest("Stream", streamId)); String feedTitle = ("Eureka Streams: " + stream.getName()); feed.setTitle(feedTitle); feed.setLink(baseUrl); feed.setDescription(feedTitle); if (stream == null) { throw new Exception("Unknown saved stream."); } queryJson = JSONObject.fromObject(stream.getRequest()); } else { throw new Exception("Unknown request mode."); } JSONObject query = queryJson.getJSONObject("query"); if (!query.has("sortBy")) { query.put("sortBy", "date"); } log.debug("Making request using: " + queryJson); PrincipalActionContext ac = new ServiceActionContext(queryJson.toString(), principalPopulator.getPrincipal(null, null)); PagedSet<ActivityDTO> activities = (PagedSet<ActivityDTO>) serviceActionController.execute(ac, action); feed.setUri(baseUrl + getRequest().getResourceRef().getPath()); if (activities.getPagedSet().size() > 0) { feed.setPublishedDate(activities.getPagedSet().get(0).getPostedTime()); } else { feed.setPublishedDate(new Date()); } List entries = new ArrayList(); for (ActivityDTO activity : activities.getPagedSet()) { SyndEntry entry; SyndContent description; String title = null; switch (activity.getBaseObjectType()) { case BOOKMARK: title = activity.getActor().getDisplayName() + ": " + activity.getBaseObjectProperties().get("content") + " " + activity.getBaseObjectProperties().get("targetUrl"); break; case NOTE: title = activity.getActor().getDisplayName() + ": " + activity.getBaseObjectProperties().get("content"); break; case PHOTO: title = activity.getActor().getDisplayName() + ": " + activity.getBaseObjectProperties().get("content"); break; case VIDEO: title = activity.getActor().getDisplayName() + ": " + activity.getBaseObjectProperties().get("content"); break; default: break; } if (title != null) { title = title.replace("%EUREKA:ACTORNAME%", activity.getActor().getDisplayName()); entry = new SyndEntryImpl(); entry.setTitle(title); entry.setAuthor(activity.getActor().getDisplayName()); String linkPrefix = activity.getDestinationStream().getType() == EntityType.PERSON ? "/#people/" : "/#groups/"; String link = baseUrl + linkPrefix + activity.getDestinationStream().getUniqueIdentifier() + "?activityId=" + activity.getId(); entry.setLink(link); entry.setUri(link); entry.setPublishedDate(activity.getPostedTime()); description = new SyndContentImpl(); description.setType("text/plain"); description.setValue(title); entry.setDescription(description); entries.add(entry); } } feed.setEntries(entries); } catch (Exception ex) { log.error("Error:" + ex.toString()); } log.debug(status); SyndFeedOutput output = new SyndFeedOutput(); StringWriter writer = new StringWriter(); try { output.output(feed, writer); } catch (IOException e) { log.error("error in writing feed"); } catch (FeedException e) { log.error("error in feed"); } Representation rep = new StringRepresentation(writer.toString(), MediaType.TEXT_XML); rep.setExpirationDate(new Date(0L)); return rep; } }
StreamXMLResource extends SmpResource { @SuppressWarnings("unchecked") @Override public Representation represent(final Variant variant) throws ResourceException { if (log.isDebugEnabled()) { log.debug("Path: " + getPath()); } SyndFeed feed = new SyndFeedImpl(); feed.setFeedType("atom_1.0"); String status = GOOD_STATUS; try { JSONObject queryJson = null; if (mode.equals("query")) { queryJson = requestParser.parseRequest(getPath(), 5); feed.setTitle("Eureka Activity Stream Feed"); feed.setLink(baseUrl); feed.setDescription(""); } else if (mode.equals("saved")) { Stream stream = streamMapper.execute(new FindByIdRequest("Stream", streamId)); String feedTitle = ("Eureka Streams: " + stream.getName()); feed.setTitle(feedTitle); feed.setLink(baseUrl); feed.setDescription(feedTitle); if (stream == null) { throw new Exception("Unknown saved stream."); } queryJson = JSONObject.fromObject(stream.getRequest()); } else { throw new Exception("Unknown request mode."); } JSONObject query = queryJson.getJSONObject("query"); if (!query.has("sortBy")) { query.put("sortBy", "date"); } log.debug("Making request using: " + queryJson); PrincipalActionContext ac = new ServiceActionContext(queryJson.toString(), principalPopulator.getPrincipal(null, null)); PagedSet<ActivityDTO> activities = (PagedSet<ActivityDTO>) serviceActionController.execute(ac, action); feed.setUri(baseUrl + getRequest().getResourceRef().getPath()); if (activities.getPagedSet().size() > 0) { feed.setPublishedDate(activities.getPagedSet().get(0).getPostedTime()); } else { feed.setPublishedDate(new Date()); } List entries = new ArrayList(); for (ActivityDTO activity : activities.getPagedSet()) { SyndEntry entry; SyndContent description; String title = null; switch (activity.getBaseObjectType()) { case BOOKMARK: title = activity.getActor().getDisplayName() + ": " + activity.getBaseObjectProperties().get("content") + " " + activity.getBaseObjectProperties().get("targetUrl"); break; case NOTE: title = activity.getActor().getDisplayName() + ": " + activity.getBaseObjectProperties().get("content"); break; case PHOTO: title = activity.getActor().getDisplayName() + ": " + activity.getBaseObjectProperties().get("content"); break; case VIDEO: title = activity.getActor().getDisplayName() + ": " + activity.getBaseObjectProperties().get("content"); break; default: break; } if (title != null) { title = title.replace("%EUREKA:ACTORNAME%", activity.getActor().getDisplayName()); entry = new SyndEntryImpl(); entry.setTitle(title); entry.setAuthor(activity.getActor().getDisplayName()); String linkPrefix = activity.getDestinationStream().getType() == EntityType.PERSON ? "/#people/" : "/#groups/"; String link = baseUrl + linkPrefix + activity.getDestinationStream().getUniqueIdentifier() + "?activityId=" + activity.getId(); entry.setLink(link); entry.setUri(link); entry.setPublishedDate(activity.getPostedTime()); description = new SyndContentImpl(); description.setType("text/plain"); description.setValue(title); entry.setDescription(description); entries.add(entry); } } feed.setEntries(entries); } catch (Exception ex) { log.error("Error:" + ex.toString()); } log.debug(status); SyndFeedOutput output = new SyndFeedOutput(); StringWriter writer = new StringWriter(); try { output.output(feed, writer); } catch (IOException e) { log.error("error in writing feed"); } catch (FeedException e) { log.error("error in feed"); } Representation rep = new StringRepresentation(writer.toString(), MediaType.TEXT_XML); rep.setExpirationDate(new Date(0L)); return rep; } StreamXMLResource(final ServiceAction inAction, final ActionController inServiceActionController,
            final PrincipalPopulator inPrincipalPopulator, final FindByIdMapper<Stream> inStreamMapper,
            final RestletQueryRequestParser inRequestParser, final String inBaseUrl); }
StreamXMLResource extends SmpResource { @SuppressWarnings("unchecked") @Override public Representation represent(final Variant variant) throws ResourceException { if (log.isDebugEnabled()) { log.debug("Path: " + getPath()); } SyndFeed feed = new SyndFeedImpl(); feed.setFeedType("atom_1.0"); String status = GOOD_STATUS; try { JSONObject queryJson = null; if (mode.equals("query")) { queryJson = requestParser.parseRequest(getPath(), 5); feed.setTitle("Eureka Activity Stream Feed"); feed.setLink(baseUrl); feed.setDescription(""); } else if (mode.equals("saved")) { Stream stream = streamMapper.execute(new FindByIdRequest("Stream", streamId)); String feedTitle = ("Eureka Streams: " + stream.getName()); feed.setTitle(feedTitle); feed.setLink(baseUrl); feed.setDescription(feedTitle); if (stream == null) { throw new Exception("Unknown saved stream."); } queryJson = JSONObject.fromObject(stream.getRequest()); } else { throw new Exception("Unknown request mode."); } JSONObject query = queryJson.getJSONObject("query"); if (!query.has("sortBy")) { query.put("sortBy", "date"); } log.debug("Making request using: " + queryJson); PrincipalActionContext ac = new ServiceActionContext(queryJson.toString(), principalPopulator.getPrincipal(null, null)); PagedSet<ActivityDTO> activities = (PagedSet<ActivityDTO>) serviceActionController.execute(ac, action); feed.setUri(baseUrl + getRequest().getResourceRef().getPath()); if (activities.getPagedSet().size() > 0) { feed.setPublishedDate(activities.getPagedSet().get(0).getPostedTime()); } else { feed.setPublishedDate(new Date()); } List entries = new ArrayList(); for (ActivityDTO activity : activities.getPagedSet()) { SyndEntry entry; SyndContent description; String title = null; switch (activity.getBaseObjectType()) { case BOOKMARK: title = activity.getActor().getDisplayName() + ": " + activity.getBaseObjectProperties().get("content") + " " + activity.getBaseObjectProperties().get("targetUrl"); break; case NOTE: title = activity.getActor().getDisplayName() + ": " + activity.getBaseObjectProperties().get("content"); break; case PHOTO: title = activity.getActor().getDisplayName() + ": " + activity.getBaseObjectProperties().get("content"); break; case VIDEO: title = activity.getActor().getDisplayName() + ": " + activity.getBaseObjectProperties().get("content"); break; default: break; } if (title != null) { title = title.replace("%EUREKA:ACTORNAME%", activity.getActor().getDisplayName()); entry = new SyndEntryImpl(); entry.setTitle(title); entry.setAuthor(activity.getActor().getDisplayName()); String linkPrefix = activity.getDestinationStream().getType() == EntityType.PERSON ? "/#people/" : "/#groups/"; String link = baseUrl + linkPrefix + activity.getDestinationStream().getUniqueIdentifier() + "?activityId=" + activity.getId(); entry.setLink(link); entry.setUri(link); entry.setPublishedDate(activity.getPostedTime()); description = new SyndContentImpl(); description.setType("text/plain"); description.setValue(title); entry.setDescription(description); entries.add(entry); } } feed.setEntries(entries); } catch (Exception ex) { log.error("Error:" + ex.toString()); } log.debug(status); SyndFeedOutput output = new SyndFeedOutput(); StringWriter writer = new StringWriter(); try { output.output(feed, writer); } catch (IOException e) { log.error("error in writing feed"); } catch (FeedException e) { log.error("error in feed"); } Representation rep = new StringRepresentation(writer.toString(), MediaType.TEXT_XML); rep.setExpirationDate(new Date(0L)); return rep; } StreamXMLResource(final ServiceAction inAction, final ActionController inServiceActionController,
            final PrincipalPopulator inPrincipalPopulator, final FindByIdMapper<Stream> inStreamMapper,
            final RestletQueryRequestParser inRequestParser, final String inBaseUrl); @SuppressWarnings("unchecked") @Override Representation represent(final Variant variant); void setPathOverride(final String inPathOverride); String getPath(); }
StreamXMLResource extends SmpResource { @SuppressWarnings("unchecked") @Override public Representation represent(final Variant variant) throws ResourceException { if (log.isDebugEnabled()) { log.debug("Path: " + getPath()); } SyndFeed feed = new SyndFeedImpl(); feed.setFeedType("atom_1.0"); String status = GOOD_STATUS; try { JSONObject queryJson = null; if (mode.equals("query")) { queryJson = requestParser.parseRequest(getPath(), 5); feed.setTitle("Eureka Activity Stream Feed"); feed.setLink(baseUrl); feed.setDescription(""); } else if (mode.equals("saved")) { Stream stream = streamMapper.execute(new FindByIdRequest("Stream", streamId)); String feedTitle = ("Eureka Streams: " + stream.getName()); feed.setTitle(feedTitle); feed.setLink(baseUrl); feed.setDescription(feedTitle); if (stream == null) { throw new Exception("Unknown saved stream."); } queryJson = JSONObject.fromObject(stream.getRequest()); } else { throw new Exception("Unknown request mode."); } JSONObject query = queryJson.getJSONObject("query"); if (!query.has("sortBy")) { query.put("sortBy", "date"); } log.debug("Making request using: " + queryJson); PrincipalActionContext ac = new ServiceActionContext(queryJson.toString(), principalPopulator.getPrincipal(null, null)); PagedSet<ActivityDTO> activities = (PagedSet<ActivityDTO>) serviceActionController.execute(ac, action); feed.setUri(baseUrl + getRequest().getResourceRef().getPath()); if (activities.getPagedSet().size() > 0) { feed.setPublishedDate(activities.getPagedSet().get(0).getPostedTime()); } else { feed.setPublishedDate(new Date()); } List entries = new ArrayList(); for (ActivityDTO activity : activities.getPagedSet()) { SyndEntry entry; SyndContent description; String title = null; switch (activity.getBaseObjectType()) { case BOOKMARK: title = activity.getActor().getDisplayName() + ": " + activity.getBaseObjectProperties().get("content") + " " + activity.getBaseObjectProperties().get("targetUrl"); break; case NOTE: title = activity.getActor().getDisplayName() + ": " + activity.getBaseObjectProperties().get("content"); break; case PHOTO: title = activity.getActor().getDisplayName() + ": " + activity.getBaseObjectProperties().get("content"); break; case VIDEO: title = activity.getActor().getDisplayName() + ": " + activity.getBaseObjectProperties().get("content"); break; default: break; } if (title != null) { title = title.replace("%EUREKA:ACTORNAME%", activity.getActor().getDisplayName()); entry = new SyndEntryImpl(); entry.setTitle(title); entry.setAuthor(activity.getActor().getDisplayName()); String linkPrefix = activity.getDestinationStream().getType() == EntityType.PERSON ? "/#people/" : "/#groups/"; String link = baseUrl + linkPrefix + activity.getDestinationStream().getUniqueIdentifier() + "?activityId=" + activity.getId(); entry.setLink(link); entry.setUri(link); entry.setPublishedDate(activity.getPostedTime()); description = new SyndContentImpl(); description.setType("text/plain"); description.setValue(title); entry.setDescription(description); entries.add(entry); } } feed.setEntries(entries); } catch (Exception ex) { log.error("Error:" + ex.toString()); } log.debug(status); SyndFeedOutput output = new SyndFeedOutput(); StringWriter writer = new StringWriter(); try { output.output(feed, writer); } catch (IOException e) { log.error("error in writing feed"); } catch (FeedException e) { log.error("error in feed"); } Representation rep = new StringRepresentation(writer.toString(), MediaType.TEXT_XML); rep.setExpirationDate(new Date(0L)); return rep; } StreamXMLResource(final ServiceAction inAction, final ActionController inServiceActionController,
            final PrincipalPopulator inPrincipalPopulator, final FindByIdMapper<Stream> inStreamMapper,
            final RestletQueryRequestParser inRequestParser, final String inBaseUrl); @SuppressWarnings("unchecked") @Override Representation represent(final Variant variant); void setPathOverride(final String inPathOverride); String getPath();  }