@Test public void testLikeWhenLiked() { List<LikedSharedResource> likedResources = getEntityManager().createQuery( "FROM LikedSharedResource where pk.personId = :personId AND pk.sharedResourceId = :sharedResourceId") .setParameter("personId", personId).setParameter("sharedResourceId", likedLinkId).getResultList(); assertEquals(1, likedResources.size()); getEntityManager().clear(); sut.execute(new SetSharedResourceLikeMapperRequest(personId, likedSr, true)); likedResources = getEntityManager().createQuery( "FROM LikedSharedResource where pk.personId = :personId AND pk.sharedResourceId = :sharedResourceId") .setParameter("personId", personId).setParameter("sharedResourceId", likedLinkId).getResultList(); assertEquals(1, likedResources.size()); }
@Override public Boolean execute(final SetSharedResourceLikeMapperRequest inRequest) { getEntityManager().createQuery( "DELETE LikedSharedResource WHERE pk.personId = :personId " + "AND pk.sharedResourceId = :sharedResourceId").setParameter("personId", inRequest.getPersonId()).setParameter("sharedResourceId", inRequest.getSharedResource().getId()) .executeUpdate(); if (inRequest.getLikedStatus()) { LikedSharedResource sharedResource = new LikedSharedResource(inRequest.getSharedResource().getId(), inRequest.getPersonId()); getEntityManager().persist(sharedResource); } return true; }
SetLikedSharedResourceStatusDbMapper extends
        BaseArgDomainMapper<SetSharedResourceLikeMapperRequest, Boolean> { @Override public Boolean execute(final SetSharedResourceLikeMapperRequest inRequest) { getEntityManager().createQuery( "DELETE LikedSharedResource WHERE pk.personId = :personId " + "AND pk.sharedResourceId = :sharedResourceId").setParameter("personId", inRequest.getPersonId()).setParameter("sharedResourceId", inRequest.getSharedResource().getId()) .executeUpdate(); if (inRequest.getLikedStatus()) { LikedSharedResource sharedResource = new LikedSharedResource(inRequest.getSharedResource().getId(), inRequest.getPersonId()); getEntityManager().persist(sharedResource); } return true; } }
SetLikedSharedResourceStatusDbMapper extends
        BaseArgDomainMapper<SetSharedResourceLikeMapperRequest, Boolean> { @Override public Boolean execute(final SetSharedResourceLikeMapperRequest inRequest) { getEntityManager().createQuery( "DELETE LikedSharedResource WHERE pk.personId = :personId " + "AND pk.sharedResourceId = :sharedResourceId").setParameter("personId", inRequest.getPersonId()).setParameter("sharedResourceId", inRequest.getSharedResource().getId()) .executeUpdate(); if (inRequest.getLikedStatus()) { LikedSharedResource sharedResource = new LikedSharedResource(inRequest.getSharedResource().getId(), inRequest.getPersonId()); getEntityManager().persist(sharedResource); } return true; }  }
SetLikedSharedResourceStatusDbMapper extends
        BaseArgDomainMapper<SetSharedResourceLikeMapperRequest, Boolean> { @Override public Boolean execute(final SetSharedResourceLikeMapperRequest inRequest) { getEntityManager().createQuery( "DELETE LikedSharedResource WHERE pk.personId = :personId " + "AND pk.sharedResourceId = :sharedResourceId").setParameter("personId", inRequest.getPersonId()).setParameter("sharedResourceId", inRequest.getSharedResource().getId()) .executeUpdate(); if (inRequest.getLikedStatus()) { LikedSharedResource sharedResource = new LikedSharedResource(inRequest.getSharedResource().getId(), inRequest.getPersonId()); getEntityManager().persist(sharedResource); } return true; }  @Override Boolean execute(final SetSharedResourceLikeMapperRequest inRequest); }
SetLikedSharedResourceStatusDbMapper extends
        BaseArgDomainMapper<SetSharedResourceLikeMapperRequest, Boolean> { @Override public Boolean execute(final SetSharedResourceLikeMapperRequest inRequest) { getEntityManager().createQuery( "DELETE LikedSharedResource WHERE pk.personId = :personId " + "AND pk.sharedResourceId = :sharedResourceId").setParameter("personId", inRequest.getPersonId()).setParameter("sharedResourceId", inRequest.getSharedResource().getId()) .executeUpdate(); if (inRequest.getLikedStatus()) { LikedSharedResource sharedResource = new LikedSharedResource(inRequest.getSharedResource().getId(), inRequest.getPersonId()); getEntityManager().persist(sharedResource); } return true; }  @Override Boolean execute(final SetSharedResourceLikeMapperRequest inRequest);  }