Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -269,7 +266,7 @@ public List<String> 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);
Expand All @@ -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();
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -336,7 +333,7 @@ public boolean updateNotificationInfo(String clientId, boolean userNotificationE
@Transactional(value = "transactionManagerReadOnly", readOnly = true)
@SuppressWarnings("unchecked")
public List<ClientDetailsEntity> 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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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<ClientDetailsEntity> 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());
}

}
Loading