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 @@
<version>5.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>net.ihe.gazelle.tm</groupId>
<artifactId>gazelle-tm-tools</artifactId>
<version>4.1.6-SNAPSHOT</version>
<packaging>ejb</packaging>
<url>http://gazelle.ihe.net</url>
<name>gazelle-tm-tools</name>
<version>4.1.6-SNAPSHOT</version>
<url>http://gazelle.ihe.net</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
......@@ -284,7 +286,7 @@
<dependency>
<groupId>net.ihe.gazelle.modules</groupId>
<artifactId>gazelle-ws-clients</artifactId>
<version>2.3.0</version>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>uk.com.robust-it</groupId>
......
......@@ -108,11 +108,7 @@ public class ApplicationPreferenceManagerImpl implements Serializable, Applicati
@Override
public Boolean getBooleanValue(String key) {
Object value = load(PreferenceType.BOOLEAN, key);
if (value == null) {
return false;
} else {
return (Boolean) value;
}
return value != null && (Boolean) value ;
}
private static Object load(final PreferenceType preferenceType, final String key) {
......@@ -270,8 +266,7 @@ public class ApplicationPreferenceManagerImpl implements Serializable, Applicati
@Override
public List<String> persistValues(Map<String, Object> values) {
List<String> preferences = new ArrayList<String>();
Set<Entry<String, Object>> entrySet = values.entrySet();
for (Entry<String, Object> entry : entrySet) {
for (Entry<String, Object> entry : values.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value != null) {
......@@ -315,30 +310,37 @@ public class ApplicationPreferenceManagerImpl implements Serializable, Applicati
preferences.add(key2);
}
} catch (MalformedURLException e) {
log.error("" + e);
log.error("Unable to extract URL basename from application URL", e);
}
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)
private boolean save(PreferenceType preferenceType, String key, Object value) {
CSPHeaderFilter.clearCache();
SQLinjectionFilter.resetInjectionFilter();
boolean updated = false;
String newValue = preferenceType.asString(value);
EntityManager entityManager = EntityManagerService.provideEntityManager();
Query query = entityManager
.createQuery("SELECT ap FROM ApplicationPreference ap where ap.preferenceName = :name");
query.setParameter("name", key);
ApplicationPreference applicationPreference = null;
try {
List<?> preferences = query.getResultList();
if (preferences.size() > 0) {
applicationPreference = (ApplicationPreference) preferences.get(0);
}
applicationPreference = (ApplicationPreference) query.getSingleResult();
} catch (Exception e) {
applicationPreference = null;
log.warn("Unexpeced error while reading preferences from database:", e);
}
if (applicationPreference == null) {
......@@ -353,10 +355,11 @@ public class ApplicationPreferenceManagerImpl implements Serializable, Applicati
if (!StringUtils.equals(oldValue, newValue)) {
applicationPreference.setPreferenceValue(newValue);
entityManager.merge(applicationPreference);
return true;
updated = true;
}
}
return false;
ApplicationCacheManager.getApplicationPreferencesCache().clearCache();
return updated;
}
@Override
......
......@@ -3,6 +3,7 @@ package net.ihe.gazelle.common.application.action;
import net.ihe.gazelle.common.Preferences.PreferencesKey;
import net.ihe.gazelle.common.model.ApplicationPreference;
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.junit.AbstractTestQueryJunit4;
import org.hibernate.jpa.HibernatePersistenceProvider;
......@@ -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
public void testGetCguLink() {
Map<String, Object> preferences = new HashMap<>();
......@@ -70,24 +65,30 @@ public class ApplicationPreferenceManagerTest extends AbstractTestQueryJunit4 {
@Test
public void testRefreshIntervalZero() {
Map<String, Object> preferences = new HashMap<>();
ApplicationPreferenceManager applicationPreferenceManager = new ApplicationPreferenceManagerImpl();
preferences.put("test_result_refresh_interval", 0);
applicationPreferenceManager.persistValues(preferences);
assertEquals(0, applicationPreferenceManager.retrieveTestResultRefreshInterval());
}
@Test
public void testRefreshInterval() {
Map<String, Object> preferences = new HashMap<>();
preferences.put("test_result_refresh_interval", 10);
ApplicationPreferenceManager applicationPreferenceManager = new ApplicationPreferenceManagerImpl();
preferences.put("test_result_refresh_interval", 10);
applicationPreferenceManager.persistValues(preferences);
assertEquals(10000, applicationPreferenceManager.retrieveTestResultRefreshInterval());
}
@Test
public void testCacheProxyChannelStatusFalse() {
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