Fix bug in profile service it (#222)
diff --git a/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java b/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java
index 317c4ff..2d0ad9a 100644
--- a/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/ProfileServiceIT.java
@@ -116,9 +116,9 @@
// Relevant only when throwExceptions system property is true
@Test
- public void testGetProfileWithWrongScrollerIdThrowException() throws InterruptedException {
- ElasticSearchPersistenceServiceImpl esPersistenceService = (ElasticSearchPersistenceServiceImpl)persistenceService;
- esPersistenceService.setThrowExceptions(true);
+ public void testGetProfileWithWrongScrollerIdThrowException() throws InterruptedException, NoSuchFieldException, IllegalAccessException {
+ boolean throwExceptionCurrent = (boolean) persistenceService.getSetting("throwExceptions");
+ persistenceService.setSetting("throwExceptions", true);
Query query = new Query();
query.setLimit(2);
@@ -129,9 +129,10 @@
profileService.search(query, Profile.class);
fail("search method didn't throw when expected");
} catch (RuntimeException ex) {
+ // Should get here since this scenario should throw exception
}
finally {
- esPersistenceService.setThrowExceptions(false);
+ persistenceService.setSetting("throwExceptions", throwExceptionCurrent);
}
}
diff --git a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
index df8fad4..9a1e6b1 100644
--- a/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
+++ b/persistence-elasticsearch/core/src/main/java/org/apache/unomi/persistence/elasticsearch/ElasticSearchPersistenceServiceImpl.java
@@ -142,6 +142,7 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.lang.reflect.Field;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
@@ -740,6 +741,26 @@
}
@Override
+ public void setSettings(Map<String, Object> settings) throws NoSuchFieldException, IllegalAccessException {
+ for (Map.Entry<String, Object> setting : settings.entrySet())
+ setSetting(setting.getKey(), setting.getValue());
+ }
+
+ @Override
+ public void setSetting(String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException {
+ Field field = this.getClass().getDeclaredField(fieldName);
+ field.set(getClass(), value);
+ }
+
+ @Override
+ public Object getSetting(String fieldName) throws NoSuchFieldException, IllegalAccessException {
+ Field field = this.getClass().getDeclaredField(fieldName);
+ return field.get(getClass());
+ }
+
+
+
+ @Override
public <T extends Item> T load(final String itemId, final Class<T> clazz) {
return load(itemId, null, clazz);
}
diff --git a/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java
index 1e81300..2b91b2f 100644
--- a/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java
+++ b/persistence-spi/src/main/java/org/apache/unomi/persistence/spi/PersistenceService.java
@@ -81,6 +81,34 @@
<T extends Item> PartialList<T> getAllItems(final Class<T> clazz, int offset, int size, String sortBy, String scrollTimeValidity);
/**
+ * Set settings of the persistence service
+ *
+ * @param settings map of setting name and it's value
+ * @throws NoSuchFieldException if the field does not exist
+ * @throws IllegalAccessException field is not accessible to be changed
+ */
+ void setSettings(Map<String, Object> settings) throws NoSuchFieldException, IllegalAccessException;
+
+ /**
+ * Set settings of the persistence service
+ *
+ * @param fieldName name of the field to set
+ * @param value value of the field to set
+ * @throws NoSuchFieldException if the field does not exist
+ * @throws IllegalAccessException field is not accessible to be changed
+ */
+ void setSetting(String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException;
+
+ /**
+ * Set settings of the persistence service
+ *
+ * @param fieldName name of the field to get
+ * @throws NoSuchFieldException if the field does not exist
+ * @throws IllegalAccessException field is not accessible to be changed
+ */
+ Object getSetting(String fieldName) throws NoSuchFieldException, IllegalAccessException;
+
+ /**
* Persists the specified Item in the context server.
*
* @param item the item to persist