Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 5ee90e7f authored by Cédric Eoche-Duval's avatar Cédric Eoche-Duval
Browse files

Feature/GZL-5200 identity usage

parent 1f9ecbe3
No related branches found
No related tags found
2 merge requests!17Release/4.1.6,!15Feature/GZL-5200 identity usage
...@@ -6,12 +6,14 @@ ...@@ -6,12 +6,14 @@
<version>5.0.0-SNAPSHOT</version> <version>5.0.0-SNAPSHOT</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<groupId>net.ihe.gazelle.tm</groupId> <groupId>net.ihe.gazelle.tm</groupId>
<artifactId>gazelle-tm-tools</artifactId> <artifactId>gazelle-tm-tools</artifactId>
<version>4.1.6-SNAPSHOT</version>
<packaging>ejb</packaging> <packaging>ejb</packaging>
<url>http://gazelle.ihe.net</url>
<name>gazelle-tm-tools</name> <name>gazelle-tm-tools</name>
<version>4.1.6-SNAPSHOT</version> <url>http://gazelle.ihe.net</url>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
...@@ -284,7 +286,7 @@ ...@@ -284,7 +286,7 @@
<dependency> <dependency>
<groupId>net.ihe.gazelle.modules</groupId> <groupId>net.ihe.gazelle.modules</groupId>
<artifactId>gazelle-ws-clients</artifactId> <artifactId>gazelle-ws-clients</artifactId>
<version>2.3.0</version> <version>3.0.0-SNAPSHOT</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>uk.com.robust-it</groupId> <groupId>uk.com.robust-it</groupId>
......
...@@ -108,11 +108,7 @@ public class ApplicationPreferenceManagerImpl implements Serializable, Applicati ...@@ -108,11 +108,7 @@ public class ApplicationPreferenceManagerImpl implements Serializable, Applicati
@Override @Override
public Boolean getBooleanValue(String key) { public Boolean getBooleanValue(String key) {
Object value = load(PreferenceType.BOOLEAN, key); Object value = load(PreferenceType.BOOLEAN, key);
if (value == null) { return value != null && (Boolean) value ;
return false;
} else {
return (Boolean) value;
}
} }
private static Object load(final PreferenceType preferenceType, final String key) { private static Object load(final PreferenceType preferenceType, final String key) {
...@@ -270,8 +266,7 @@ public class ApplicationPreferenceManagerImpl implements Serializable, Applicati ...@@ -270,8 +266,7 @@ public class ApplicationPreferenceManagerImpl implements Serializable, Applicati
@Override @Override
public List<String> persistValues(Map<String, Object> values) { public List<String> persistValues(Map<String, Object> values) {
List<String> preferences = new ArrayList<String>(); List<String> preferences = new ArrayList<String>();
Set<Entry<String, Object>> entrySet = values.entrySet(); for (Entry<String, Object> entry : values.entrySet()) {
for (Entry<String, Object> entry : entrySet) {
String key = entry.getKey(); String key = entry.getKey();
Object value = entry.getValue(); Object value = entry.getValue();
if (value != null) { if (value != null) {
...@@ -315,30 +310,37 @@ public class ApplicationPreferenceManagerImpl implements Serializable, Applicati ...@@ -315,30 +310,37 @@ public class ApplicationPreferenceManagerImpl implements Serializable, Applicati
preferences.add(key2); preferences.add(key2);
} }
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
log.error("" + e); log.error("Unable to extract URL basename from application URL", e);
} }
return preferences; return preferences;
} }
/**
* Persist an application preference in the underlying database.
*
* @param preferenceType Type of the preference.
* @param key name of the preference.
* @param value value of the preference (depends on preferenceType).
* @return true if the preference was already existing and the value has been updated, false otherwise.
*/
@TransactionAttribute(TransactionAttributeType.REQUIRED) @TransactionAttribute(TransactionAttributeType.REQUIRED)
private boolean save(PreferenceType preferenceType, String key, Object value) { private boolean save(PreferenceType preferenceType, String key, Object value) {
CSPHeaderFilter.clearCache(); CSPHeaderFilter.clearCache();
SQLinjectionFilter.resetInjectionFilter(); SQLinjectionFilter.resetInjectionFilter();
boolean updated = false;
String newValue = preferenceType.asString(value); String newValue = preferenceType.asString(value);
EntityManager entityManager = EntityManagerService.provideEntityManager(); EntityManager entityManager = EntityManagerService.provideEntityManager();
Query query = entityManager Query query = entityManager
.createQuery("SELECT ap FROM ApplicationPreference ap where ap.preferenceName = :name"); .createQuery("SELECT ap FROM ApplicationPreference ap where ap.preferenceName = :name");
query.setParameter("name", key); query.setParameter("name", key);
ApplicationPreference applicationPreference = null; ApplicationPreference applicationPreference = null;
try { try {
List<?> preferences = query.getResultList(); applicationPreference = (ApplicationPreference) query.getSingleResult();
if (preferences.size() > 0) {
applicationPreference = (ApplicationPreference) preferences.get(0);
}
} catch (Exception e) { } catch (Exception e) {
applicationPreference = null; log.warn("Unexpeced error while reading preferences from database:", e);
} }
if (applicationPreference == null) { if (applicationPreference == null) {
...@@ -353,10 +355,11 @@ public class ApplicationPreferenceManagerImpl implements Serializable, Applicati ...@@ -353,10 +355,11 @@ public class ApplicationPreferenceManagerImpl implements Serializable, Applicati
if (!StringUtils.equals(oldValue, newValue)) { if (!StringUtils.equals(oldValue, newValue)) {
applicationPreference.setPreferenceValue(newValue); applicationPreference.setPreferenceValue(newValue);
entityManager.merge(applicationPreference); entityManager.merge(applicationPreference);
return true; updated = true;
} }
} }
return false; ApplicationCacheManager.getApplicationPreferencesCache().clearCache();
return updated;
} }
@Override @Override
......
...@@ -3,6 +3,7 @@ package net.ihe.gazelle.common.application.action; ...@@ -3,6 +3,7 @@ package net.ihe.gazelle.common.application.action;
import net.ihe.gazelle.common.Preferences.PreferencesKey; import net.ihe.gazelle.common.Preferences.PreferencesKey;
import net.ihe.gazelle.common.model.ApplicationPreference; import net.ihe.gazelle.common.model.ApplicationPreference;
import net.ihe.gazelle.common.model.ApplicationPreferenceQuery; import net.ihe.gazelle.common.model.ApplicationPreferenceQuery;
import net.ihe.gazelle.common.preference.PreferenceType;
import net.ihe.gazelle.hql.providers.EntityManagerService; import net.ihe.gazelle.hql.providers.EntityManagerService;
import net.ihe.gazelle.junit.AbstractTestQueryJunit4; import net.ihe.gazelle.junit.AbstractTestQueryJunit4;
import org.hibernate.jpa.HibernatePersistenceProvider; import org.hibernate.jpa.HibernatePersistenceProvider;
...@@ -52,12 +53,6 @@ public class ApplicationPreferenceManagerTest extends AbstractTestQueryJunit4 { ...@@ -52,12 +53,6 @@ public class ApplicationPreferenceManagerTest extends AbstractTestQueryJunit4 {
} }
} }
@Test
public void testGetCguLinkNull() {
ApplicationPreferenceManager applicationPreferenceManager = new ApplicationPreferenceManagerImpl();
assertNull("The cgu link is not initialized here", applicationPreferenceManager.getCguLink());
}
@Test @Test
public void testGetCguLink() { public void testGetCguLink() {
Map<String, Object> preferences = new HashMap<>(); Map<String, Object> preferences = new HashMap<>();
...@@ -70,24 +65,30 @@ public class ApplicationPreferenceManagerTest extends AbstractTestQueryJunit4 { ...@@ -70,24 +65,30 @@ public class ApplicationPreferenceManagerTest extends AbstractTestQueryJunit4 {
@Test @Test
public void testRefreshIntervalZero() { public void testRefreshIntervalZero() {
Map<String, Object> preferences = new HashMap<>();
ApplicationPreferenceManager applicationPreferenceManager = new ApplicationPreferenceManagerImpl(); ApplicationPreferenceManager applicationPreferenceManager = new ApplicationPreferenceManagerImpl();
preferences.put("test_result_refresh_interval", 0);
applicationPreferenceManager.persistValues(preferences);
assertEquals(0, applicationPreferenceManager.retrieveTestResultRefreshInterval()); assertEquals(0, applicationPreferenceManager.retrieveTestResultRefreshInterval());
} }
@Test @Test
public void testRefreshInterval() { public void testRefreshInterval() {
Map<String, Object> preferences = new HashMap<>(); Map<String, Object> preferences = new HashMap<>();
preferences.put("test_result_refresh_interval", 10);
ApplicationPreferenceManager applicationPreferenceManager = new ApplicationPreferenceManagerImpl(); ApplicationPreferenceManager applicationPreferenceManager = new ApplicationPreferenceManagerImpl();
preferences.put("test_result_refresh_interval", 10);
applicationPreferenceManager.persistValues(preferences); applicationPreferenceManager.persistValues(preferences);
assertEquals(10000, applicationPreferenceManager.retrieveTestResultRefreshInterval()); assertEquals(10000, applicationPreferenceManager.retrieveTestResultRefreshInterval());
} }
@Test @Test
public void testCacheProxyChannelStatusFalse() { public void testCacheProxyChannelStatusFalse() {
ApplicationPreferenceManager applicationPreferenceManager = new ApplicationPreferenceManagerImpl(); ApplicationPreferenceManager applicationPreferenceManager = new ApplicationPreferenceManagerImpl();
assertFalse("Uninitialized value, should be false",applicationPreferenceManager.cacheProxyChannelStatus()); assertFalse("Uninitialized boolean value, should be false", applicationPreferenceManager.getCASEnabled());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment