@Test public void testFailureWithInvalidConsumerKey() { GetGadgetsByGadgetDefAndConsumerKeyRequest request = new GetGadgetsByGadgetDefAndConsumerKeyRequest( "badkey", USER_2); Long returnValue = sut.execute(request); assertEquals(new Long(0), returnValue); }
@Override @SuppressWarnings("unchecked") public Long execute(final GetGadgetsByGadgetDefAndConsumerKeyRequest inRequest) { String consumerKey = inRequest.getConsumerKey(); Long personId = inRequest.getPersonId(); Query gadgetDefIdQuery = getEntityManager().createQuery( "select gd.id from GadgetDefinition gd, OAuthConsumer oc " + "where gd.url = oc.gadgetUrl and oc.consumerKey =:consumerKey").setParameter("consumerKey", consumerKey); List<Long> results = gadgetDefIdQuery.getResultList(); if (results.size() == 0) { return 0L; } Long gadgetDefId = (Long) results.get(0); Query gadgetCountQuery = getEntityManager().createQuery( "select count(ga.id) from Gadget ga, Tab tab, Person p " + "where ga.template.id = tab.template.id and p.startTabGroup.id = tab.tabGroup.id " + "and p.id =:personId and ga.deleted = 'f' and ga.gadgetDefinition.id =:gadgetDefId") .setParameter("personId", personId).setParameter("gadgetDefId", gadgetDefId); return (Long) gadgetCountQuery.getSingleResult(); }
GetGadgetsByGadgetDefAndConsumerKey extends ReadMapper<GetGadgetsByGadgetDefAndConsumerKeyRequest, Long> { @Override @SuppressWarnings("unchecked") public Long execute(final GetGadgetsByGadgetDefAndConsumerKeyRequest inRequest) { String consumerKey = inRequest.getConsumerKey(); Long personId = inRequest.getPersonId(); Query gadgetDefIdQuery = getEntityManager().createQuery( "select gd.id from GadgetDefinition gd, OAuthConsumer oc " + "where gd.url = oc.gadgetUrl and oc.consumerKey =:consumerKey").setParameter("consumerKey", consumerKey); List<Long> results = gadgetDefIdQuery.getResultList(); if (results.size() == 0) { return 0L; } Long gadgetDefId = (Long) results.get(0); Query gadgetCountQuery = getEntityManager().createQuery( "select count(ga.id) from Gadget ga, Tab tab, Person p " + "where ga.template.id = tab.template.id and p.startTabGroup.id = tab.tabGroup.id " + "and p.id =:personId and ga.deleted = 'f' and ga.gadgetDefinition.id =:gadgetDefId") .setParameter("personId", personId).setParameter("gadgetDefId", gadgetDefId); return (Long) gadgetCountQuery.getSingleResult(); } }
GetGadgetsByGadgetDefAndConsumerKey extends ReadMapper<GetGadgetsByGadgetDefAndConsumerKeyRequest, Long> { @Override @SuppressWarnings("unchecked") public Long execute(final GetGadgetsByGadgetDefAndConsumerKeyRequest inRequest) { String consumerKey = inRequest.getConsumerKey(); Long personId = inRequest.getPersonId(); Query gadgetDefIdQuery = getEntityManager().createQuery( "select gd.id from GadgetDefinition gd, OAuthConsumer oc " + "where gd.url = oc.gadgetUrl and oc.consumerKey =:consumerKey").setParameter("consumerKey", consumerKey); List<Long> results = gadgetDefIdQuery.getResultList(); if (results.size() == 0) { return 0L; } Long gadgetDefId = (Long) results.get(0); Query gadgetCountQuery = getEntityManager().createQuery( "select count(ga.id) from Gadget ga, Tab tab, Person p " + "where ga.template.id = tab.template.id and p.startTabGroup.id = tab.tabGroup.id " + "and p.id =:personId and ga.deleted = 'f' and ga.gadgetDefinition.id =:gadgetDefId") .setParameter("personId", personId).setParameter("gadgetDefId", gadgetDefId); return (Long) gadgetCountQuery.getSingleResult(); }  }
GetGadgetsByGadgetDefAndConsumerKey extends ReadMapper<GetGadgetsByGadgetDefAndConsumerKeyRequest, Long> { @Override @SuppressWarnings("unchecked") public Long execute(final GetGadgetsByGadgetDefAndConsumerKeyRequest inRequest) { String consumerKey = inRequest.getConsumerKey(); Long personId = inRequest.getPersonId(); Query gadgetDefIdQuery = getEntityManager().createQuery( "select gd.id from GadgetDefinition gd, OAuthConsumer oc " + "where gd.url = oc.gadgetUrl and oc.consumerKey =:consumerKey").setParameter("consumerKey", consumerKey); List<Long> results = gadgetDefIdQuery.getResultList(); if (results.size() == 0) { return 0L; } Long gadgetDefId = (Long) results.get(0); Query gadgetCountQuery = getEntityManager().createQuery( "select count(ga.id) from Gadget ga, Tab tab, Person p " + "where ga.template.id = tab.template.id and p.startTabGroup.id = tab.tabGroup.id " + "and p.id =:personId and ga.deleted = 'f' and ga.gadgetDefinition.id =:gadgetDefId") .setParameter("personId", personId).setParameter("gadgetDefId", gadgetDefId); return (Long) gadgetCountQuery.getSingleResult(); }  @Override @SuppressWarnings("unchecked") Long execute(final GetGadgetsByGadgetDefAndConsumerKeyRequest inRequest); }
GetGadgetsByGadgetDefAndConsumerKey extends ReadMapper<GetGadgetsByGadgetDefAndConsumerKeyRequest, Long> { @Override @SuppressWarnings("unchecked") public Long execute(final GetGadgetsByGadgetDefAndConsumerKeyRequest inRequest) { String consumerKey = inRequest.getConsumerKey(); Long personId = inRequest.getPersonId(); Query gadgetDefIdQuery = getEntityManager().createQuery( "select gd.id from GadgetDefinition gd, OAuthConsumer oc " + "where gd.url = oc.gadgetUrl and oc.consumerKey =:consumerKey").setParameter("consumerKey", consumerKey); List<Long> results = gadgetDefIdQuery.getResultList(); if (results.size() == 0) { return 0L; } Long gadgetDefId = (Long) results.get(0); Query gadgetCountQuery = getEntityManager().createQuery( "select count(ga.id) from Gadget ga, Tab tab, Person p " + "where ga.template.id = tab.template.id and p.startTabGroup.id = tab.tabGroup.id " + "and p.id =:personId and ga.deleted = 'f' and ga.gadgetDefinition.id =:gadgetDefId") .setParameter("personId", personId).setParameter("gadgetDefId", gadgetDefId); return (Long) gadgetCountQuery.getSingleResult(); }  @Override @SuppressWarnings("unchecked") Long execute(final GetGadgetsByGadgetDefAndConsumerKeyRequest inRequest);  }