Updated Branches: refs/heads/develop d0688b3f3 -> d8374a31a
MARMOTTA-421: store users in system configuration instead of triplestore Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/d8374a31 Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/d8374a31 Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/d8374a31 Branch: refs/heads/develop Commit: d8374a31a48489baa34c01c3f73bba8be8abc6cf Parents: d0688b3 Author: Sebastian Schaffert <[email protected]> Authored: Mon Jan 13 16:58:22 2014 +0100 Committer: Sebastian Schaffert <[email protected]> Committed: Mon Jan 13 16:58:22 2014 +0100 ---------------------------------------------------------------------- .../core/services/user/UserServiceImpl.java | 44 ++++++++------------ 1 file changed, 18 insertions(+), 26 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/marmotta/blob/d8374a31/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/user/UserServiceImpl.java ---------------------------------------------------------------------- diff --git a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/user/UserServiceImpl.java b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/user/UserServiceImpl.java index 6fcd12f..403c0e4 100644 --- a/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/user/UserServiceImpl.java +++ b/platform/marmotta-core/src/main/java/org/apache/marmotta/platform/core/services/user/UserServiceImpl.java @@ -17,12 +17,7 @@ */ package org.apache.marmotta.platform.core.services.user; -import static org.apache.marmotta.commons.sesame.repository.ExceptionUtils.handleRepositoryException; -import static org.apache.marmotta.commons.sesame.model.Namespaces.ADMIN_LOGIN; -import static org.apache.marmotta.commons.sesame.model.Namespaces.ANONYMOUS_LOGIN; - import org.apache.marmotta.commons.sesame.facading.FacadingFactory; -import org.apache.marmotta.commons.sesame.repository.ResourceUtils; import org.apache.marmotta.platform.core.api.config.ConfigurationService; import org.apache.marmotta.platform.core.api.triplestore.SesameService; import org.apache.marmotta.platform.core.api.user.UserService; @@ -44,10 +39,13 @@ import javax.enterprise.event.Observes; import javax.enterprise.inject.Produces; import javax.inject.Inject; import javax.inject.Named; - import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import static org.apache.marmotta.commons.sesame.model.Namespaces.ADMIN_LOGIN; +import static org.apache.marmotta.commons.sesame.model.Namespaces.ANONYMOUS_LOGIN; +import static org.apache.marmotta.commons.sesame.repository.ExceptionUtils.handleRepositoryException; + /** * Add file description here! * <p/> @@ -266,17 +264,24 @@ public class UserServiceImpl implements UserService { lock.lock(); try { if(!userExists(login)) { - String webId_str = buildUserUri(login); + log.info("creating user with webId: {} ", webId_str); + + + String template = "user.%s.%s"; + + configurationService.setConfiguration(String.format(template, login, "webid"), webId_str); + configurationService.setConfiguration(String.format(template, login, "first"), firstName); + configurationService.setConfiguration(String.format(template, login, "last"), lastName); + + try { RepositoryConnection conn = sesameService.getConnection(); try { conn.begin(); URI webId = conn.getValueFactory().createURI(webId_str); - log.info("creating user with webId: {} ", webId.stringValue()); - if (!login.equals(ANONYMOUS_LOGIN) && !login.equals(ADMIN_LOGIN)) { MarmottaUser u = FacadingFactory.createFacading(conn).createFacade(webId, MarmottaUser.class); u.setFirstName(firstName); @@ -339,24 +344,11 @@ public class UserServiceImpl implements UserService { * @return the user with the given login, or null if no such user exists */ private URI getUserByLogin(String login) { - try { - RepositoryConnection conn = sesameService.getConnection(); - try { - conn.begin(); - String userUri = buildUserUri(login); - if (ResourceUtils.existsResource(conn, userUri)) - return conn.getValueFactory().createURI(userUri); - else - return null; - } finally { - // TODO: this is not the perfect way to do it, but the only way to avoid cycles - // with the versioning - conn.rollback(); - conn.close(); - } - } catch (RepositoryException e) { - handleRepositoryException(e, UserServiceImpl.class); + String webId = configurationService.getStringConfiguration(String.format("user.%s.webid", login)); + if(webId != null) { + return sesameService.getRepository().getValueFactory().createURI(webId); + } else { return null; } }
