@Test public void testExecuteWithOutExisting() { GetFeedByUrlRequest request = new GetFeedByUrlRequest(2L, "http: Feed feed = sut.execute(request); assertEquals("http: assertEquals(2L, feed.getPlugin().getId()); Feed persisted = findByIdMapper.execute(new FindByIdRequest("Feed", feed.getId())); assertEquals(persisted.getId(), feed.getId()); }
@SuppressWarnings("unchecked") @Override public Feed execute(final GetFeedByUrlRequest inRequest) { String query = "FROM Feed WHERE streamPlugin.id=:pluginId AND url = :url"; List<Feed> feeds = getEntityManager().createQuery(query).setParameter("pluginId", inRequest.getPluginId()) .setParameter("url", inRequest.getUrl()).getResultList(); if (feeds.size() > 0) { return feeds.get(0); } Feed feed = new Feed(); feed.setLastUpdated(new Date().getTime() / MS_IN_MIN); feed.setLastPostDate(new Date()); feed.setUrl(inRequest.getUrl()); feed.setTitle("Undefined"); feed.setPlugin(getEntityManager().find(PluginDefinition.class, inRequest.getPluginId())); getEntityManager().persist(feed); return feed; }
GetFeedByUrlOrCreateMapper extends ReadMapper<GetFeedByUrlRequest, Feed> { @SuppressWarnings("unchecked") @Override public Feed execute(final GetFeedByUrlRequest inRequest) { String query = "FROM Feed WHERE streamPlugin.id=:pluginId AND url = :url"; List<Feed> feeds = getEntityManager().createQuery(query).setParameter("pluginId", inRequest.getPluginId()) .setParameter("url", inRequest.getUrl()).getResultList(); if (feeds.size() > 0) { return feeds.get(0); } Feed feed = new Feed(); feed.setLastUpdated(new Date().getTime() / MS_IN_MIN); feed.setLastPostDate(new Date()); feed.setUrl(inRequest.getUrl()); feed.setTitle("Undefined"); feed.setPlugin(getEntityManager().find(PluginDefinition.class, inRequest.getPluginId())); getEntityManager().persist(feed); return feed; } }
GetFeedByUrlOrCreateMapper extends ReadMapper<GetFeedByUrlRequest, Feed> { @SuppressWarnings("unchecked") @Override public Feed execute(final GetFeedByUrlRequest inRequest) { String query = "FROM Feed WHERE streamPlugin.id=:pluginId AND url = :url"; List<Feed> feeds = getEntityManager().createQuery(query).setParameter("pluginId", inRequest.getPluginId()) .setParameter("url", inRequest.getUrl()).getResultList(); if (feeds.size() > 0) { return feeds.get(0); } Feed feed = new Feed(); feed.setLastUpdated(new Date().getTime() / MS_IN_MIN); feed.setLastPostDate(new Date()); feed.setUrl(inRequest.getUrl()); feed.setTitle("Undefined"); feed.setPlugin(getEntityManager().find(PluginDefinition.class, inRequest.getPluginId())); getEntityManager().persist(feed); return feed; }  }
GetFeedByUrlOrCreateMapper extends ReadMapper<GetFeedByUrlRequest, Feed> { @SuppressWarnings("unchecked") @Override public Feed execute(final GetFeedByUrlRequest inRequest) { String query = "FROM Feed WHERE streamPlugin.id=:pluginId AND url = :url"; List<Feed> feeds = getEntityManager().createQuery(query).setParameter("pluginId", inRequest.getPluginId()) .setParameter("url", inRequest.getUrl()).getResultList(); if (feeds.size() > 0) { return feeds.get(0); } Feed feed = new Feed(); feed.setLastUpdated(new Date().getTime() / MS_IN_MIN); feed.setLastPostDate(new Date()); feed.setUrl(inRequest.getUrl()); feed.setTitle("Undefined"); feed.setPlugin(getEntityManager().find(PluginDefinition.class, inRequest.getPluginId())); getEntityManager().persist(feed); return feed; }  @SuppressWarnings("unchecked") @Override Feed execute(final GetFeedByUrlRequest inRequest); }
GetFeedByUrlOrCreateMapper extends ReadMapper<GetFeedByUrlRequest, Feed> { @SuppressWarnings("unchecked") @Override public Feed execute(final GetFeedByUrlRequest inRequest) { String query = "FROM Feed WHERE streamPlugin.id=:pluginId AND url = :url"; List<Feed> feeds = getEntityManager().createQuery(query).setParameter("pluginId", inRequest.getPluginId()) .setParameter("url", inRequest.getUrl()).getResultList(); if (feeds.size() > 0) { return feeds.get(0); } Feed feed = new Feed(); feed.setLastUpdated(new Date().getTime() / MS_IN_MIN); feed.setLastPostDate(new Date()); feed.setUrl(inRequest.getUrl()); feed.setTitle("Undefined"); feed.setPlugin(getEntityManager().find(PluginDefinition.class, inRequest.getPluginId())); getEntityManager().persist(feed); return feed; }  @SuppressWarnings("unchecked") @Override Feed execute(final GetFeedByUrlRequest inRequest);  }