deprecations
diff --git a/src/main/java/de/ids_mannheim/korap/interfaces/AuthenticationManagerIface.java b/src/main/java/de/ids_mannheim/korap/interfaces/AuthenticationManagerIface.java
index a6cf827..7c0b418 100644
--- a/src/main/java/de/ids_mannheim/korap/interfaces/AuthenticationManagerIface.java
+++ b/src/main/java/de/ids_mannheim/korap/interfaces/AuthenticationManagerIface.java
@@ -63,15 +63,19 @@
public abstract void updateUserData(Userdata data) throws KustvaktException;
+ @Deprecated
public abstract UserDetails getUserDetails(User user)
throws KustvaktException;
+ @Deprecated
public abstract UserSettings getUserSettings(User user)
throws KustvaktException;
+ @Deprecated
public abstract void updateUserDetails(User user, UserDetails details)
throws KustvaktException;
+ @Deprecated
public abstract void updateUserSettings(User user, UserSettings settings)
throws KustvaktException;
diff --git a/src/main/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManager.java b/src/main/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManager.java
index 8cd65eb..73eecd1 100644
--- a/src/main/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManager.java
+++ b/src/main/java/de/ids_mannheim/korap/security/auth/KustvaktAuthenticationManager.java
@@ -708,8 +708,6 @@
dao.update(data);
}
- // todo: use getuserdata for that!
- @Deprecated
public UserDetails getUserDetails(User user) throws KustvaktException {
try {
for (Userdata data : user.getUserdata()) {
@@ -725,7 +723,6 @@
return user.getDetails();
}
- @Deprecated
public UserSettings getUserSettings(User user) throws KustvaktException {
try {
if (user.getSettings() == null)
diff --git a/src/main/java/de/ids_mannheim/korap/user/UserDataDbIface.java b/src/main/java/de/ids_mannheim/korap/user/UserDataDbIface.java
index 6d4e2a1..2d2f231 100644
--- a/src/main/java/de/ids_mannheim/korap/user/UserDataDbIface.java
+++ b/src/main/java/de/ids_mannheim/korap/user/UserDataDbIface.java
@@ -6,8 +6,6 @@
*/
public interface UserDataDbIface<T extends Userdata> {
- public Class<? extends Userdata> getType();
-
public int store(T data);
public int update(T data);
diff --git a/src/main/java/de/ids_mannheim/korap/user/UserDetailsDao.java b/src/main/java/de/ids_mannheim/korap/user/UserDetailsDao.java
index 0bd204d..4e16bed 100644
--- a/src/main/java/de/ids_mannheim/korap/user/UserDetailsDao.java
+++ b/src/main/java/de/ids_mannheim/korap/user/UserDetailsDao.java
@@ -24,11 +24,6 @@
}
@Override
- public Class<Userdetails2> getType() {
- return Userdetails2.class;
- }
-
- @Override
public int store(Userdetails2 data) {
String sql = "INSERT INTO user_details2 (user_id, data) VALUES (:userid, :data);";
MapSqlParameterSource source = new MapSqlParameterSource();
diff --git a/src/main/java/de/ids_mannheim/korap/user/UserSettings.java b/src/main/java/de/ids_mannheim/korap/user/UserSettings.java
index 046ef56..77351e9 100644
--- a/src/main/java/de/ids_mannheim/korap/user/UserSettings.java
+++ b/src/main/java/de/ids_mannheim/korap/user/UserSettings.java
@@ -15,6 +15,7 @@
* Time: 10:26 AM
*/
+@Deprecated
@Getter
@Setter
public class UserSettings {
diff --git a/src/main/java/de/ids_mannheim/korap/user/UserSettings2.java b/src/main/java/de/ids_mannheim/korap/user/UserSettings2.java
new file mode 100644
index 0000000..6e87a53
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/user/UserSettings2.java
@@ -0,0 +1,18 @@
+package de.ids_mannheim.korap.user;
+
+/**
+ * @author hanl
+ * @date 28/01/2016
+ */
+public class UserSettings2 extends Userdata {
+
+
+ public UserSettings2(Integer userid) {
+ super(userid);
+ }
+
+ @Override
+ public String[] requiredFields() {
+ return new String[0];
+ }
+}
diff --git a/src/main/java/de/ids_mannheim/korap/user/UserSettingsDao.java b/src/main/java/de/ids_mannheim/korap/user/UserSettingsDao.java
new file mode 100644
index 0000000..5af93e7
--- /dev/null
+++ b/src/main/java/de/ids_mannheim/korap/user/UserSettingsDao.java
@@ -0,0 +1,133 @@
+package de.ids_mannheim.korap.user;
+
+import de.ids_mannheim.korap.interfaces.db.PersistenceClient;
+import org.springframework.dao.DataAccessException;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
+import org.springframework.jdbc.support.GeneratedKeyHolder;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.HashMap;
+
+/**
+ * @author hanl
+ * @date 28/01/2016
+ */
+public class UserSettingsDao implements UserDataDbIface<UserSettings2> {
+
+ NamedParameterJdbcTemplate jdbcTemplate;
+
+ public UserSettingsDao(PersistenceClient client) {
+ this.jdbcTemplate = (NamedParameterJdbcTemplate) client.getSource();
+ }
+ @Override
+ public int store(UserSettings2 data) {
+ String sql = "INSERT INTO user_details2 (user_id, data) VALUES (:userid, :data);";
+ MapSqlParameterSource source = new MapSqlParameterSource();
+ source.addValue("userid", data.getUserID());
+ source.addValue("data", data.data());
+
+ GeneratedKeyHolder gen = new GeneratedKeyHolder();
+ try {
+ this.jdbcTemplate.update(sql, source, gen);
+ int id = gen.getKey().intValue();
+ data.setId(id);
+ return id;
+ }catch (DataAccessException e) {
+ e.printStackTrace();
+ return -1;
+ }
+ }
+
+ @Override
+ public int update(UserSettings2 data) {
+ String sql = "UPDATE user_details2 SET data = :data WHERE user_id=:userid;";
+ MapSqlParameterSource source = new MapSqlParameterSource();
+ source.addValue("userid", data.getUserID());
+ source.addValue("data", data.data());
+
+ try {
+ return this.jdbcTemplate.update(sql, source);
+ }catch (DataAccessException e) {
+ return -1;
+ }
+ }
+
+ @Override
+ public UserSettings2 get(Integer id) {
+ String sql = "SELECT * FROM user_details2 WHERE id=:id;";
+ MapSqlParameterSource source = new MapSqlParameterSource();
+ source.addValue("id", id);
+
+ try {
+ return this.jdbcTemplate
+ .queryForObject(sql, source, new RowMapper<UserSettings2>() {
+
+ @Override
+ public UserSettings2 mapRow(ResultSet rs, int rowNum)
+ throws SQLException {
+ UserSettings2 details = new UserSettings2(
+ rs.getInt("user_id"));
+ details.setId(rs.getInt("id"));
+ details.setData(rs.getString("data"));
+ return details;
+ }
+ });
+
+ }catch (DataAccessException e) {
+ return null;
+ }
+ }
+
+ @Override
+ public UserSettings2 get(User user) {
+ String sql = "SELECT * FROM user_details2 WHERE user_id=:userid;";
+ MapSqlParameterSource source = new MapSqlParameterSource();
+ source.addValue("userid", user.getId());
+
+ try {
+ return this.jdbcTemplate
+ .queryForObject(sql, source, new RowMapper<UserSettings2>() {
+
+ @Override
+ public UserSettings2 mapRow(ResultSet rs, int rowNum)
+ throws SQLException {
+ UserSettings2 details = new UserSettings2(
+ rs.getInt("user_id"));
+ details.setId(rs.getInt("id"));
+ details.setData(rs.getString("data"));
+ return details;
+ }
+ });
+
+ }catch (DataAccessException e) {
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ @Override
+ public int delete(UserSettings2 data) {
+ String sql = "DELETE FROM user_details2 WHERE id=:id";
+ MapSqlParameterSource source = new MapSqlParameterSource();
+ source.addValue("id", data.getId());
+ try {
+ return this.jdbcTemplate.update(sql, source);
+ }catch (DataAccessException e) {
+ return -1;
+ }
+ }
+
+ @Override
+ public int deleteAll() {
+ String sql = "DELETE FROM user_details2;";
+ try {
+ return this.jdbcTemplate.update(sql, new HashMap<String, Object>());
+ }catch (DataAccessException e) {
+ e.printStackTrace();
+ return -1;
+ }
+ }
+}
diff --git a/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java b/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java
index 293da84..1d886ed 100644
--- a/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java
+++ b/src/main/java/de/ids_mannheim/korap/web/filter/PiwikFilter.java
@@ -13,9 +13,7 @@
import de.ids_mannheim.korap.config.BeanConfiguration;
import de.ids_mannheim.korap.exceptions.KustvaktException;
import de.ids_mannheim.korap.interfaces.AuthenticationManagerIface;
-import de.ids_mannheim.korap.user.TokenContext;
-import de.ids_mannheim.korap.user.User;
-import de.ids_mannheim.korap.user.UserSettings;
+import de.ids_mannheim.korap.user.*;
import net.minidev.json.JSONArray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,11 +37,10 @@
private static Logger jlog = LoggerFactory.getLogger(PiwikFilter.class);
public static boolean ENABLED = false;
private Map<String, String> customVars;
- private AuthenticationManagerIface securityController;
+ private AuthenticationManagerIface controller;
public PiwikFilter() {
- securityController = BeanConfiguration.getBeans()
- .getAuthenticationManager();
+ controller = BeanConfiguration.getBeans().getAuthenticationManager();
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
if (jlog.isDebugEnabled())
@@ -69,8 +66,8 @@
if (request.getAcceptableLanguages() != null)
l = request.getAcceptableLanguages().get(0);
try {
- service.path("piwik/piwik.php")
- .queryParam("idsite", "2").queryParam("rec", "1")
+ service.path("piwik/piwik.php").queryParam("idsite", "2")
+ .queryParam("rec", "1")
//todo check for empty container
.queryParam("_cvar", translateCustomData())
.queryParam("cip", request.getHeaderValue("Host"))
@@ -116,10 +113,10 @@
TokenContext context = (TokenContext) request
.getUserPrincipal();
// since this is cached, not very expensive!
- User user = securityController.getUser(context.getUsername());
- UserSettings settiings = securityController
- .getUserSettings(user);
- if (settiings.isCollectData())
+ User user = controller.getUser(context.getUsername());
+ Userdata data = controller
+ .getUserData(user, UserSettings2.class);
+ if ((Boolean) data.get(Attributes.COLLECT_AUDITING_DATA))
customVars.put("username", context.getUsername());
}catch (KustvaktException | UnsupportedOperationException e) {
//do nothing
diff --git a/src/main/java/de/ids_mannheim/korap/web/service/full/UserService.java b/src/main/java/de/ids_mannheim/korap/web/service/full/UserService.java
index b342e84..3d8e0e4 100644
--- a/src/main/java/de/ids_mannheim/korap/web/service/full/UserService.java
+++ b/src/main/java/de/ids_mannheim/korap/web/service/full/UserService.java
@@ -220,8 +220,7 @@
User user;
try {
user = controller.getUser(ctx.getUsername());
- Userdata data = controller
- .getUserData(user, Userdetails2.class);
+ Userdata data = controller.getUserData(user, Userdetails2.class);
user.addUserData(data);
Set<String> base_scope = StringUtils.toSet(scopes, " ");
@@ -242,19 +241,17 @@
public Response getUserSettings(@Context SecurityContext context,
@Context Locale locale) {
TokenContext ctx = (TokenContext) context.getUserPrincipal();
- User user;
+ String result;
try {
- user = controller.getUser(ctx.getUsername());
- controller.getUserSettings(user);
-
+ User user = controller.getUser(ctx.getUsername());
+ Userdata data = controller.getUserData(user, UserSettings2.class);
+ data.addField(Attributes.USERNAME, ctx.getUsername());
+ result = data.data();
}catch (KustvaktException e) {
jlog.error("Exception encountered!", e);
throw KustvaktResponseHandler.throwit(e);
}
-
- Map m = user.getSettings().toObjectMap();
- m.put(Attributes.USERNAME, ctx.getUsername());
- return Response.ok(JsonUtils.toJSON(m)).build();
+ return Response.ok(result).build();
}
// todo: test
@@ -270,18 +267,21 @@
try {
User user = controller.getUser(ctx.getUsername());
- UserSettings us = controller.getUserSettings(user);
+ if (user.isDemo())
+ return Response.notModified().build();
+
+ Userdata data = controller.getUserData(user, UserSettings2.class);
// todo: check setting only within the scope of user settings permissions; not foundry range. Latter is part of
// frontend which only displays available foundries and
// SecurityManager.findbyId(us.getDefaultConstfoundry(), user, Foundry.class);
// SecurityManager.findbyId(us.getDefaultLemmafoundry(), user, Foundry.class);
// SecurityManager.findbyId(us.getDefaultPOSfoundry(), user, Foundry.class);
// SecurityManager.findbyId(us.getDefaultRelfoundry(), user, Foundry.class);
- us.updateStringSettings(settings);
+ Userdata new_data = new UserSettings2(user.getId());
+ new_data.setData(JsonUtils.toJSON(settings));
+ data.update(new_data);
- controller.updateUserSettings(user, us);
- if (user.isDemo())
- return Response.notModified().build();
+ controller.updateUserData(data);
}catch (KustvaktException e) {
jlog.error("Exception encountered!", e);
throw KustvaktResponseHandler.throwit(e);
@@ -300,8 +300,7 @@
User user;
try {
user = controller.getUser(ctx.getUsername());
- Userdata data = controller
- .getUserData(user, Userdetails2.class);
+ Userdata data = controller.getUserData(user, Userdetails2.class);
user.addUserData(data);
}catch (KustvaktException e) {
@@ -327,11 +326,15 @@
try {
User user = controller.getUser(ctx.getUsername());
- UserDetails det = controller.getUserDetails(user);
- det.updateDetails(wrapper);
- controller.updateUserDetails(user, det);
if (user.isDemo())
return Response.notModified().build();
+
+ Userdetails2 new_data = new Userdetails2(user.getId());
+ new_data.setData(JsonUtils.toJSON(wrapper));
+
+ Userdetails2 det = controller.getUserData(user, Userdetails2.class);
+ det.update(new_data);
+ controller.updateUserData(det);
}catch (KustvaktException e) {
jlog.error("Exception encountered!", e);
throw KustvaktResponseHandler.throwit(e);