diff --git a/orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/ClientDetailsDaoImpl.java b/orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/ClientDetailsDaoImpl.java index 11d0ac2b61..ba95e030c9 100644 --- a/orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/ClientDetailsDaoImpl.java +++ b/orcid-persistence/src/main/java/org/orcid/persistence/dao/impl/ClientDetailsDaoImpl.java @@ -100,9 +100,8 @@ public void updateLastModified(String clientId) { /** * Update the last modified dates of given client ids - * - * @param clientIds - * A list of client ids + * + * @param clientIds A list of client ids * @return the amount of modified rows */ @@ -194,9 +193,8 @@ public void removeClient(String clientId) { /** * Get the public client that belongs to the given orcid ID - * - * @param ownerId - * The user or group id + * + * @param ownerId The user or group id * @return the public client that belongs to the given user */ @Override @@ -216,9 +214,8 @@ public ClientDetailsEntity getPublicClient(String ownerId) { /** * Get member name - * - * @param clientId - * The client id + * + * @param clientId The client id * @return the name of the member owner of the given client */ @Override @@ -269,7 +266,7 @@ public List findLegacyClientIds() { @Transactional public void changePersistenceTokensProperty(String clientId, boolean isPersistenTokensEnabled) { Query updateQuery = entityManager - .createQuery("update ClientDetailsEntity c set c.lastModified = :lastModified, c.persistentTokensEnabled = :isPersistenTokensEnabled where c.id = :clientId"); + .createQuery("update ClientDetailsEntity c set c.lastModified = :lastModified, c.persistentTokensEnabled = :isPersistenTokensEnabled where c.id = :clientId"); updateQuery.setParameter("clientId", clientId); updateQuery.setParameter("lastModified", new Date()); updateQuery.setParameter("isPersistenTokensEnabled", isPersistenTokensEnabled); @@ -280,7 +277,7 @@ public void changePersistenceTokensProperty(String clientId, boolean isPersisten @Transactional public void activateClient(String clientDetailsId) { Query updateQuery = entityManager - .createQuery("update ClientDetailsEntity c set c.lastModified = :lastModified, c.deactivatedDate = null, c.deactivatedBy = null where c.id = :clientId"); + .createQuery("update ClientDetailsEntity c set c.lastModified = :lastModified, c.deactivatedDate = null, c.deactivatedBy = null where c.id = :clientId"); updateQuery.setParameter("clientId", clientDetailsId); updateQuery.setParameter("lastModified", new Date()); updateQuery.executeUpdate(); @@ -290,7 +287,7 @@ public void activateClient(String clientDetailsId) { @Transactional public void deactivateClient(String clientDetailsId, String deactivatedBy) { Query updateQuery = entityManager - .createQuery("update ClientDetailsEntity c set c.lastModified = :lastModified, c.deactivatedDate = :deactivatedDate, c.deactivatedBy = :deactivatedBy where c.id = :clientId"); + .createQuery("update ClientDetailsEntity c set c.lastModified = :lastModified, c.deactivatedDate = :deactivatedDate, c.deactivatedBy = :deactivatedBy where c.id = :clientId"); updateQuery.setParameter("clientId", clientDetailsId); Date now = new Date(); updateQuery.setParameter("lastModified", now); @@ -324,7 +321,7 @@ public boolean updateClientGrantedAuthority(String clientId, String grantedAutho @Transactional public boolean updateNotificationInfo(String clientId, boolean userNotificationEnabled, String notificationWebpageUrl, String notificationDomains) { Query updateNotificationInfoQuery = entityManager.createNativeQuery( - "UPDATE client_details SET user_notification_enabled= :userNotificationEnabled, notification_webpage_url= :notificationWebpageUrl, notification_domains= :notificationDomains WHERE id = :clientId"); + "UPDATE client_details SET user_notification_enabled= :userNotificationEnabled, notification_webpage_url= :notificationWebpageUrl, notification_domains= :notificationDomains WHERE client_details_id = :clientId"); updateNotificationInfoQuery.setParameter("clientId", clientId); updateNotificationInfoQuery.setParameter("userNotificationEnabled", userNotificationEnabled); updateNotificationInfoQuery.setParameter("notificationWebpageUrl", notificationWebpageUrl); @@ -336,7 +333,7 @@ public boolean updateNotificationInfo(String clientId, boolean userNotificationE @Transactional(value = "transactionManagerReadOnly", readOnly = true) @SuppressWarnings("unchecked") public List findMVPEnabled() { - Query query = entityManager.createQuery("from ClientDetailsEntity where userNotificationEnabled = :userNotificationEnabled and client_type = :premiumUpdater" ); + Query query = entityManager.createQuery("from ClientDetailsEntity where userNotificationEnabled = :userNotificationEnabled and clientType = :premiumUpdater"); query.setParameter("userNotificationEnabled", true); query.setParameter("premiumUpdater", ClientType.PREMIUM_UPDATER.name()); return query.getResultList(); diff --git a/orcid-persistence/src/test/java/org/orcid/persistence/dao/ClientDetailsDaoTest.java b/orcid-persistence/src/test/java/org/orcid/persistence/dao/ClientDetailsDaoTest.java index b784aa911d..d5b514a993 100644 --- a/orcid-persistence/src/test/java/org/orcid/persistence/dao/ClientDetailsDaoTest.java +++ b/orcid-persistence/src/test/java/org/orcid/persistence/dao/ClientDetailsDaoTest.java @@ -1,6 +1,8 @@ package org.orcid.persistence.dao; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; import java.util.ArrayList; import java.util.Arrays; @@ -12,12 +14,14 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import org.orcid.jaxb.model.clientgroup.ClientType; +import org.orcid.persistence.jpa.entities.ClientDetailsEntity; import org.orcid.test.DBUnitTest; import org.orcid.test.OrcidJUnit4ClassRunner; import org.springframework.test.context.ContextConfiguration; @RunWith(OrcidJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "classpath:test-orcid-persistence-context.xml" }) +@ContextConfiguration(locations = {"classpath:test-orcid-persistence-context.xml"}) public class ClientDetailsDaoTest extends DBUnitTest { private static String CLIENT_ID = "APP-5555555555555557"; @@ -48,4 +52,16 @@ public void testUpdateLastModifiedBulk() { assertEquals(updateClients, 2); } + @Test + public void testFindMVPEnabled() { + clientDetailsDao.updateClientType(ClientType.PREMIUM_UPDATER.name(), CLIENT_ID); + clientDetailsDao.updateNotificationInfo(CLIENT_ID, true, "http://test.com", "test.com"); + List mvpEnabledClients = clientDetailsDao.findMVPEnabled(); + assertNotNull(mvpEnabledClients); + assertEquals(1, mvpEnabledClients.size()); + assertEquals(CLIENT_ID, mvpEnabledClients.get(0).getId()); + assertEquals(ClientType.PREMIUM_UPDATER.name(), mvpEnabledClients.get(0).getClientType()); + assertTrue(mvpEnabledClients.get(0).isUserNotificationEnabled()); + } + }