diff --git a/pom.xml b/pom.xml index 2bf9e1a8dd34c1b8d488c8d16c2327a60f104baa..fd58de4f825c186c0c35221e4a1614b817d9cdae 100644 --- a/pom.xml +++ b/pom.xml @@ -185,11 +185,6 @@ <groupId>log4j</groupId> <artifactId>log4j</artifactId> </dependency> - <dependency> - <groupId>de.thm.couchdb4j</groupId> - <artifactId>couchdb4j</artifactId> - <version>0.8-SNAPSHOT</version> - </dependency> <dependency> <groupId>org.ektorp</groupId> <artifactId>org.ektorp</artifactId> diff --git a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java b/src/main/java/de/thm/arsnova/dao/CouchDBDao.java deleted file mode 100644 index 38aa4ee8371940bb6a73991477e3a810183a8119..0000000000000000000000000000000000000000 --- a/src/main/java/de/thm/arsnova/dao/CouchDBDao.java +++ /dev/null @@ -1,186 +0,0 @@ -/* - * This file is part of ARSnova Backend. - * Copyright (C) 2012-2017 The ARSnova Team - * - * ARSnova Backend is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ARSnova Backend is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ -package de.thm.arsnova.dao; - -import com.fourspaces.couchdb.Database; -import com.fourspaces.couchdb.Document; -import com.fourspaces.couchdb.View; -import com.fourspaces.couchdb.ViewResults; -import de.thm.arsnova.connector.model.Course; -import de.thm.arsnova.entities.*; -import de.thm.arsnova.persistance.ContentRepository; -import de.thm.arsnova.persistance.LogEntryRepository; -import de.thm.arsnova.persistance.MotdRepository; -import de.thm.arsnova.persistance.SessionRepository; -import de.thm.arsnova.services.ISessionService; -import net.sf.json.JSONObject; -import org.checkerframework.checker.nullness.qual.NonNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.aop.framework.AopContext; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Profile; -import org.springframework.stereotype.Service; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -/** - * Database implementation based on CouchDB. - * - * Note to developers: - * - * This class makes use of Spring Framework's caching annotations. When you are about to add new functionality, - * you should also think about the possibility of caching. Ideally, your methods should be dependent on domain - * objects like Session or Content, which can be used as cache keys. Relying on plain String objects as a key, e.g. - * by passing only a Session's keyword, will make your cache annotations less readable. You will also need to think - * about cases where your cache needs to be updated and evicted. - * - * In order to use cached methods from within this object, you have to use the getDatabaseDao() method instead of - * using the "this" pointer. This is because caching is only available if the method is called through a Spring Proxy, - * which is not the case when using "this". - * - * @see <a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/html/cache.html">Spring Framework's Cache Abstraction</a> - * @see <a href="https://github.com/thm-projects/arsnova-backend/wiki/Caching">Caching in ARSnova explained</a> - */ -@Profile("!test") -@Service("databaseDao") -public class CouchDBDao implements IDatabaseDao { - - @Autowired - private ISessionService sessionService; - - @Autowired - private LogEntryRepository dbLogger; - - @Autowired - private SessionRepository sessionRepository; - - @Autowired - private MotdRepository motdRepository; - - @Autowired - private ContentRepository contentRepository; - - private String databaseHost; - private int databasePort; - private String databaseName; - private Database database; - - private static final Logger logger = LoggerFactory.getLogger(CouchDBDao.class); - - @Value("${couchdb.host}") - public void setDatabaseHost(final String newDatabaseHost) { - databaseHost = newDatabaseHost; - } - - @Value("${couchdb.port}") - public void setDatabasePort(final String newDatabasePort) { - databasePort = Integer.parseInt(newDatabasePort); - } - - @Value("${couchdb.name}") - public void setDatabaseName(final String newDatabaseName) { - databaseName = newDatabaseName; - } - - public void setSessionService(final ISessionService service) { - sessionService = service; - } - - /** - * <strike> - * Allows access to the proxy object. It has to be used instead of <code>this</code> for local calls to public - * methods for caching purposes. This is an ugly but necessary temporary workaround until a better solution is - * implemented (e.g. use of AspectJ's weaving). - * @return the proxy for CouchDBDao - * </strike> - */ - private @NonNull IDatabaseDao getDatabaseDao() { - return this; - } - - private Database getDatabase() { - if (database == null) { - try { - final com.fourspaces.couchdb.Session session = new com.fourspaces.couchdb.Session( - databaseHost, - databasePort - ); - database = session.getDatabase(databaseName); - } catch (final Exception e) { - logger.error("Cannot connect to CouchDB database '{}' on host '{}' using port {}.", - databaseName, databaseHost, databasePort, e); - } - } - - return database; - } - - private void deleteDocument(final String documentId) throws IOException { - final Document d = getDatabase().getDocument(documentId); - getDatabase().deleteDocument(d); - } - - @SuppressWarnings("unchecked") - @Override - public <T> T getObjectFromId(final String documentId, final Class<T> klass) { - try { - final Document doc = getDatabase().getDocument(documentId); - if (doc == null) { - return null; - } - // TODO: This needs some more error checking... - return (T) JSONObject.toBean(doc.getJSONObject(), klass); - } catch (ClassCastException | IOException | net.sf.json.JSONException e) { - return null; - } - } - - private boolean isEmptyResults(final ViewResults results) { - return results == null || results.getResults().isEmpty() || results.getJSONArray("rows").isEmpty(); - } - - /** - * Adds convenience methods to CouchDB4J's view class. - */ - private static class ExtendedView extends View { - - ExtendedView(final String fullname) { - super(fullname); - } - - void setCourseIdKeys(final List<Course> courses) { - List<String> courseIds = new ArrayList<>(); - for (Course c : courses) { - courseIds.add(c.getId()); - } - setKeys(courseIds); - } - - void setSessionIdKeys(final List<Session> sessions) { - List<String> sessionIds = new ArrayList<>(); - for (Session s : sessions) { - sessionIds.add(s.getId()); - } - setKeys(sessionIds); - } - } -} diff --git a/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java b/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java deleted file mode 100644 index 48729d1160190b21e7871a95de1c2cc9e3ed1276..0000000000000000000000000000000000000000 --- a/src/main/java/de/thm/arsnova/dao/IDatabaseDao.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * This file is part of ARSnova Backend. - * Copyright (C) 2012-2017 The ARSnova Team - * - * ARSnova Backend is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * ARSnova Backend is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - */ -package de.thm.arsnova.dao; - -/** - * All methods the database must support. - */ -public interface IDatabaseDao { - <T> T getObjectFromId(String documentId, Class<T> klass); -} diff --git a/src/main/java/de/thm/arsnova/dao/package-info.java b/src/main/java/de/thm/arsnova/dao/package-info.java deleted file mode 100644 index 1b1c0dd99512dc8a48b58c97a9d33b92f34b43a3..0000000000000000000000000000000000000000 --- a/src/main/java/de/thm/arsnova/dao/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Classes and interfaces for accessing the database - */ -package de.thm.arsnova.dao; diff --git a/src/main/java/de/thm/arsnova/security/ApplicationPermissionEvaluator.java b/src/main/java/de/thm/arsnova/security/ApplicationPermissionEvaluator.java index 7b65c1c95fe3f05b37d3797331d1a294268db896..fd72edb9c147432e3fa754f924cea85caac97b32 100644 --- a/src/main/java/de/thm/arsnova/security/ApplicationPermissionEvaluator.java +++ b/src/main/java/de/thm/arsnova/security/ApplicationPermissionEvaluator.java @@ -17,7 +17,6 @@ */ package de.thm.arsnova.security; -import de.thm.arsnova.dao.IDatabaseDao; import de.thm.arsnova.entities.Comment; import de.thm.arsnova.entities.Content; import de.thm.arsnova.entities.Session; @@ -47,9 +46,6 @@ public class ApplicationPermissionEvaluator implements PermissionEvaluator { @Value("${security.admin-accounts}") private String[] adminAccounts; - @Autowired - private IDatabaseDao dao; - @Autowired private SessionRepository sessionRepository; diff --git a/src/main/java/de/thm/arsnova/services/ContentService.java b/src/main/java/de/thm/arsnova/services/ContentService.java index 0cf430d1e755f76d38eb429aaaf06afdf0c1d893..2191d8cf7d1216bd621fbe8bb1ad194f8a0bffb9 100644 --- a/src/main/java/de/thm/arsnova/services/ContentService.java +++ b/src/main/java/de/thm/arsnova/services/ContentService.java @@ -18,7 +18,6 @@ package de.thm.arsnova.services; import de.thm.arsnova.ImageUtils; -import de.thm.arsnova.dao.IDatabaseDao; import de.thm.arsnova.entities.Answer; import de.thm.arsnova.entities.Comment; import de.thm.arsnova.entities.CommentReadingCount; @@ -56,10 +55,6 @@ import java.util.TimerTask; */ @Service public class ContentService implements IContentService, ApplicationEventPublisherAware { - - @Autowired - private IDatabaseDao databaseDao; - @Autowired private IUserService userService; @@ -87,10 +82,6 @@ public class ContentService implements IContentService, ApplicationEventPublishe private HashMap<String, Timer> timerList = new HashMap<>(); - public void setDatabaseDao(final IDatabaseDao databaseDao) { - this.databaseDao = databaseDao; - } - @Override @PreAuthorize("isAuthenticated()") public List<Content> getSkillQuestions(final String sessionkey) { diff --git a/src/main/java/de/thm/arsnova/services/FeedbackService.java b/src/main/java/de/thm/arsnova/services/FeedbackService.java index 91a8c021597058474f1085e5f51cef988c6a3d76..0a4a69599944a7f9d26df23104dcbda994fbf955 100644 --- a/src/main/java/de/thm/arsnova/services/FeedbackService.java +++ b/src/main/java/de/thm/arsnova/services/FeedbackService.java @@ -18,7 +18,6 @@ package de.thm.arsnova.services; import de.thm.arsnova.FeedbackStorage; -import de.thm.arsnova.dao.IDatabaseDao; import de.thm.arsnova.entities.Feedback; import de.thm.arsnova.entities.Session; import de.thm.arsnova.entities.User; @@ -56,9 +55,6 @@ public class FeedbackService implements IFeedbackService, ApplicationEventPublis @Value("${feedback.cleanup}") private int cleanupFeedbackDelay; - @Autowired - private IDatabaseDao databaseDao; - @Autowired private SessionRepository sessionRepository; @@ -66,10 +62,6 @@ public class FeedbackService implements IFeedbackService, ApplicationEventPublis private ApplicationEventPublisher publisher; - public void setDatabaseDao(final IDatabaseDao newDatabaseDao) { - databaseDao = newDatabaseDao; - } - @PostConstruct public void init() { feedbackStorage = new FeedbackStorage(); diff --git a/src/main/java/de/thm/arsnova/services/UserService.java b/src/main/java/de/thm/arsnova/services/UserService.java index 2ff8debe0b80be7c1067bfebac0df301124aab9e..fe8fdbc632103524944114306e8539c1c49eb44d 100644 --- a/src/main/java/de/thm/arsnova/services/UserService.java +++ b/src/main/java/de/thm/arsnova/services/UserService.java @@ -18,7 +18,6 @@ package de.thm.arsnova.services; import com.codahale.metrics.annotation.Gauge; -import de.thm.arsnova.dao.IDatabaseDao; import de.thm.arsnova.entities.DbUser; import de.thm.arsnova.entities.User; import de.thm.arsnova.exceptions.BadRequestException; @@ -99,9 +98,6 @@ public class UserService implements IUserService { @Autowired private UserRepository userRepository; - @Autowired - private IDatabaseDao databaseDao; - @Autowired private JavaMailSender mailSender; diff --git a/src/test/java/de/thm/arsnova/config/TestAppConfig.java b/src/test/java/de/thm/arsnova/config/TestAppConfig.java index ff715cd5c31e2e28a4247152a9511d9ce7e33371..5c7eeed2562fb478fb7b81e9a7c132a44651e826 100644 --- a/src/test/java/de/thm/arsnova/config/TestAppConfig.java +++ b/src/test/java/de/thm/arsnova/config/TestAppConfig.java @@ -1,6 +1,5 @@ package de.thm.arsnova.config; -import de.thm.arsnova.dao.IDatabaseDao; import de.thm.arsnova.dao.StubDatabaseDao; import de.thm.arsnova.services.StubUserService; import de.thm.arsnova.socket.ARSnovaSocket; @@ -61,7 +60,7 @@ public class TestAppConfig { } @Bean - public IDatabaseDao databaseDao() { + public StubDatabaseDao databaseDao() { return new StubDatabaseDao(); } diff --git a/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java b/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java index 1901a6cc395eae53200de0b5e07048dd04dd6794..9bdfb951140c86df3b6a36a8dd2c9f6e6e7c729c 100644 --- a/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java +++ b/src/test/java/de/thm/arsnova/dao/StubDatabaseDao.java @@ -28,7 +28,7 @@ import java.util.concurrent.ConcurrentHashMap; @Profile("test") @Service("databaseDao") -public class StubDatabaseDao implements IDatabaseDao { +public class StubDatabaseDao { private static Map<String, Session> stubSessions = new ConcurrentHashMap<>(); private static Map<String, Feedback> stubFeedbacks = new ConcurrentHashMap<>(); @@ -94,10 +94,4 @@ public class StubDatabaseDao implements IDatabaseDao { contents.add(new Content()); stubQuestions.put("12345678", contents); } - - @Override - public <T> T getObjectFromId(String documentId, Class<T> klass) { - // TODO Auto-generated method stub - return null; - } } diff --git a/src/test/java/de/thm/arsnova/services/SessionServiceTest.java b/src/test/java/de/thm/arsnova/services/SessionServiceTest.java index cd6102e26ab542ba914ed190fd180856c3d1a8ec..c7d2e79bfbb9d5aa1404168357283aedd352a8cb 100644 --- a/src/test/java/de/thm/arsnova/services/SessionServiceTest.java +++ b/src/test/java/de/thm/arsnova/services/SessionServiceTest.java @@ -20,13 +20,11 @@ package de.thm.arsnova.services; import de.thm.arsnova.config.AppConfig; import de.thm.arsnova.config.TestAppConfig; import de.thm.arsnova.config.TestSecurityConfig; -import de.thm.arsnova.dao.IDatabaseDao; import de.thm.arsnova.dao.StubDatabaseDao; import de.thm.arsnova.entities.Session; import de.thm.arsnova.exceptions.NotFoundException; import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.aop.framework.Advised; @@ -41,15 +39,12 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.util.ReflectionTestUtils; import java.util.ArrayList; import java.util.Comparator; import java.util.List; import static org.junit.Assert.*; -import static org.mockito.Matchers.anyString; -import static org.mockito.Mockito.*; @RunWith(SpringJUnit4ClassRunner.class) @WebAppConfiguration