From e3a2ba6994664224653341655c1956b95b7f08a4 Mon Sep 17 00:00:00 2001 From: Mihail Atanassov Date: Wed, 6 Jul 2016 10:58:45 +0200 Subject: [PATCH 1/3] Pack current changes to switch branch --- .gitignore | 3 +- pom.xml | 53 ++- .../CollectionAlreadyExistsException.java | 15 + .../spinfo/upcase/config/AppConfig.java | 10 - .../spinfo/upcase/config/MongoDbConfig.java | 2 +- .../spinfo/upcase/config/PostDbHandler.java | 51 ++ .../spinfo/upcase/config/SecurityConfig.java | 50 +- .../SecurityWebApplicationInitializer.java | 7 - .../upcase/config/SpringMvcInitializer.java | 22 - .../spinfo/upcase/config/ThymeLeafConfig.java | 12 +- .../upcase/config/WebAppInitializer.java | 28 -- .../controller/CollectionsNavController.java | 53 +-- .../upcase/controller/ContentController.java | 150 +++--- .../upcase/controller/HomeController.java | 40 ++ .../upcase/controller/IndexController.java | 26 - .../upcase/controller/JsonController.java | 32 +- .../controller/UserSessionController.java | 25 - .../upcase/controller/VolumeController.java | 32 +- .../administration/AdminController.java | 3 +- .../controller/search/SearchController.java | 162 +++---- .../controller/user/CollectionController.java | 82 ++++ .../user/RegistrationController.java | 8 +- .../controller/user/UploadController.java | 57 --- .../user/UserCollectionController.java | 28 -- .../user/UserSessionController.java | 38 ++ .../spinfo/upcase/lucene/Indexer.java | 447 +++++++++--------- .../spinfo/upcase/model/UploadForm.java | 158 ------- .../model/{ => form}/RegistrationForm.java | 2 +- .../spinfo/upcase/model/form/UploadForm.java | 89 ++++ .../validator/RegistrationFormValidator.java | 2 +- .../model/validator/UploadFormValidator.java | 33 ++ .../spinfo/upcase/mongodb/data/PoS.java | 27 -- .../spinfo/upcase/mongodb/data/Rectangle.java | 61 --- .../spinfo/upcase/mongodb/data/Version.java | 27 -- .../mongodb/data/core/AbstractDocument.java | 64 --- .../mongodb/data/core/RangeDocument.java | 27 -- .../upcase/mongodb/data/document/Chapter.java | 66 --- .../mongodb/data/document/Language.java | 49 -- .../upcase/mongodb/data/document/Page.java | 98 ---- .../upcase/mongodb/data/document/Token.java | 183 ------- .../mongodb/data/document/UpcaseUser.java | 203 -------- .../upcase/mongodb/data/document/Volume.java | 47 -- .../upcase/mongodb/data/document/Word.java | 180 ------- .../data/document/future/Annotation.java | 6 +- .../mongodb/data/document/future/Box.java | 24 +- .../mongodb/data/document/future/Chapter.java | 26 +- .../data/document/future/Collection.java | 106 +++-- .../document/future/ContributionRequest.java | 45 +- .../mongodb/data/document/future/Page.java | 93 +++- .../data/document/future/UpcaseUser.java | 270 +++++++---- .../mongodb/data/document/future/Word.java | 14 +- .../upcase/mongodb/data/light/Letter.java | 78 --- .../mongodb/data/light/RectangleLight.java | 107 ----- .../mongodb/repository/ChapterRepository.java | 19 - .../repository/LanguageRepository.java | 17 - .../mongodb/repository/PageRepository.java | 33 -- .../repository/PageRepositoryImpl.java | 91 ---- .../mongodb/repository/TokenRepository.java | 21 - .../repository/UpcaseUserRepository.java | 32 -- .../repository/UpcaseUserRepositoryImpl.java | 92 ---- .../mongodb/repository/VolumeRepository.java | 11 - .../mongodb/repository/WordRepository.java | 27 -- .../repository/WordRepositoryImpl.java | 73 --- .../future/CollectionRepository.java | 12 +- .../future/CollectionRepositoryImpl.java | 42 ++ .../future/ContributionRequestRepository.java | 3 +- .../repository/future/PageRepository.java | 29 ++ .../repository/future/PageRepositoryImpl.java | 72 +++ .../future/UpcaseUserRepository.java | 14 + .../future/UpcaseUserRepositoryImpl.java | 55 ++- .../repository/future/WordRepository.java | 9 + .../spinfo/upcase/mongodb/util/DataBase.java | 63 +-- .../MyInMemoryUserDetailsManager.java | 20 + .../upcase/service/CollectionService.java | 21 + .../upcase/service/CollectionServiceImpl.java | 111 +++++ .../service/ContributionServiceImpl.java | 21 +- .../spinfo/upcase/service/LoginService.java | 11 +- .../spinfo/upcase/service/OCRService.java | 66 +++ .../spinfo/upcase/service/SSHConnection.java | 34 ++ .../upcase/service/UpcaseUserDetails.java | 80 ---- .../spinfo/upcase/util/HOCRParser.java | 73 +++ src/main/resources/locale/messages.properties | 6 +- .../resources/locale/messages_de.properties | 6 +- .../webapp/WEB-INF/applicationContext.xml | 2 +- .../webapp/WEB-INF/dispatcher-servlet.xml | 7 +- .../WEB-INF/views/fragments/nav-bar-user.html | 2 +- src/main/webapp/WEB-INF/views/login.html | 4 +- src/main/webapp/WEB-INF/views/metnions.html | 28 -- src/main/webapp/WEB-INF/views/upload.html | 84 ++-- .../WEB-INF/views/user/userCollection.html | 7 +- src/main/webapp/WEB-INF/web.xml | 10 + src/main/webapp/assets/css/upcase.css | 4 + .../spinfo/upcase/test/JUnitTestSuite.java | 5 +- .../spinfo/upcase/test/data/ImportTests.java | 258 ++++++++-- upcase.launch | 2 +- 95 files changed, 2066 insertions(+), 3032 deletions(-) create mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/CollectionAlreadyExistsException.java delete mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/config/AppConfig.java create mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/config/PostDbHandler.java delete mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/config/SecurityWebApplicationInitializer.java delete mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/config/SpringMvcInitializer.java delete mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/config/WebAppInitializer.java create mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/controller/HomeController.java delete mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/controller/IndexController.java delete mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/controller/UserSessionController.java create mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/controller/user/CollectionController.java delete mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/controller/user/UploadController.java delete mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/controller/user/UserCollectionController.java create mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/controller/user/UserSessionController.java delete mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/model/UploadForm.java rename src/main/java/de/uni_koeln/spinfo/upcase/model/{ => form}/RegistrationForm.java (98%) create mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/model/form/UploadForm.java create mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/model/validator/UploadFormValidator.java delete mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/PoS.java delete mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/Rectangle.java delete mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/Version.java delete mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/core/AbstractDocument.java delete mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/core/RangeDocument.java delete mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Chapter.java delete mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Language.java delete mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Page.java delete mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Token.java delete mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/UpcaseUser.java delete mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Volume.java delete mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Word.java delete mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/light/Letter.java delete mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/light/RectangleLight.java delete mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/ChapterRepository.java delete mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/LanguageRepository.java delete mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/PageRepository.java delete mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/PageRepositoryImpl.java delete mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/TokenRepository.java delete mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/UpcaseUserRepository.java delete mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/UpcaseUserRepositoryImpl.java delete mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/VolumeRepository.java delete mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/WordRepository.java delete mode 100755 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/WordRepositoryImpl.java create mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/CollectionRepositoryImpl.java create mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/PageRepository.java create mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/PageRepositoryImpl.java create mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/WordRepository.java create mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/security/MyInMemoryUserDetailsManager.java create mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/service/CollectionService.java create mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/service/CollectionServiceImpl.java create mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/service/OCRService.java create mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/service/SSHConnection.java delete mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/service/UpcaseUserDetails.java create mode 100644 src/main/java/de/uni_koeln/spinfo/upcase/util/HOCRParser.java delete mode 100644 src/main/webapp/WEB-INF/views/metnions.html diff --git a/.gitignore b/.gitignore index eeedc1f..bd069fc 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ buildNumber.properties *.tsv *.csv *.class -hs_err_pid* \ No newline at end of file +hs_err_pid* +/drc/ diff --git a/pom.xml b/pom.xml index 3203c73..4df03f7 100755 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,6 @@ upcase 0.0.1-SNAPSHOT war - UTF-8 UTF-8 @@ -20,7 +19,6 @@ 5.4.1 0.8.1 - org.thymeleaf.extras @@ -37,11 +35,11 @@ - - org.springframework.webflow - spring-webflow - 2.4.2.RELEASE - + + + + + com.lordofthejars nosqlunit-mongodb @@ -56,7 +54,7 @@ org.springframework.data spring-data-mongodb - 1.8.0.RELEASE + 1.9.2.RELEASE @@ -68,11 +66,11 @@ javax.servlet-api 3.0.1 - - commons-fileupload - commons-fileupload - 1.2.2 - + + + + + org.springframework spring-test @@ -114,11 +112,11 @@ ${spring.version} false - - org.springframework.data - spring-data-jpa - 1.9.0.RELEASE - + + + + + org.springframework.security spring-security-core @@ -229,20 +227,33 @@ commons-fileupload commons-fileupload - 1.3.1 + 1.3.2 commons-io commons-io 2.4 - org.jsoup jsoup 1.8.3 - + + de.flapdoodle.embed + de.flapdoodle.embed.mongo + 1.50.5 + + + com.jcraft + jsch + 0.1.53 + + + net.sourceforge.tess4j + tess4j + 3.2.1 + diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/CollectionAlreadyExistsException.java b/src/main/java/de/uni_koeln/spinfo/upcase/CollectionAlreadyExistsException.java new file mode 100644 index 0000000..172fd4c --- /dev/null +++ b/src/main/java/de/uni_koeln/spinfo/upcase/CollectionAlreadyExistsException.java @@ -0,0 +1,15 @@ +package de.uni_koeln.spinfo.upcase; + +public class CollectionAlreadyExistsException extends Exception { + + private static final long serialVersionUID = 1487724146570813552L; + + public CollectionAlreadyExistsException() { + super("Collection already exists..."); + } + + public CollectionAlreadyExistsException(String arg) { + super("Collection with " + arg + " name already exists..."); + } + +} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/config/AppConfig.java b/src/main/java/de/uni_koeln/spinfo/upcase/config/AppConfig.java deleted file mode 100644 index 3ff2d86..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/config/AppConfig.java +++ /dev/null @@ -1,10 +0,0 @@ -package de.uni_koeln.spinfo.upcase.config; - -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; - -//@Configuration -//@ComponentScan(basePackages = "de.uni_koeln") -public class AppConfig { - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/config/MongoDbConfig.java b/src/main/java/de/uni_koeln/spinfo/upcase/config/MongoDbConfig.java index 46db343..470b609 100755 --- a/src/main/java/de/uni_koeln/spinfo/upcase/config/MongoDbConfig.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/config/MongoDbConfig.java @@ -31,7 +31,7 @@ import com.mongodb.ServerAddress; @Configuration -@EnableMongoRepositories +@EnableMongoRepositories(basePackages = "de.uni_koeln.spinfo.upcase.mongodb.repository") @PropertySource("classpath:database.properties") public class MongoDbConfig extends AbstractMongoConfiguration { diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/config/PostDbHandler.java b/src/main/java/de/uni_koeln/spinfo/upcase/config/PostDbHandler.java new file mode 100644 index 0000000..c02fa3b --- /dev/null +++ b/src/main/java/de/uni_koeln/spinfo/upcase/config/PostDbHandler.java @@ -0,0 +1,51 @@ +package de.uni_koeln.spinfo.upcase.config; + +import java.util.Collection; + +import javax.annotation.PostConstruct; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.stereotype.Component; + +import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.UpcaseUser; +import de.uni_koeln.spinfo.upcase.mongodb.repository.future.UpcaseUserRepository; +import de.uni_koeln.spinfo.upcase.security.MyInMemoryUserDetailsManager; + +@Component +public class PostDbHandler { + + Logger logger = LoggerFactory.getLogger(getClass()); + + @Autowired + private MyInMemoryUserDetailsManager inMemoryUserDetailsManager; + + @Autowired + private UpcaseUserRepository upcaseUserRepository; + + @Autowired + private MongoTemplate template; + + @PostConstruct + public void postContruct() { + + Collection users = inMemoryUserDetailsManager.getUsers(); + + for (UserDetails userDetails : users) { + if (userDetails instanceof UpcaseUser) { + UpcaseUser user = (UpcaseUser) userDetails; + UpcaseUser findByEmail = upcaseUserRepository.findByEmail(user.getEmail()); + if (findByEmail == null) { + user = upcaseUserRepository.save(user); + logger.info(user + " ID :: " + user.getId()); + } + } + } + long count = template.getCollection("ref_users").count(); + logger.info("UpcaseUser :: " + count); + } + +} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/config/SecurityConfig.java b/src/main/java/de/uni_koeln/spinfo/upcase/config/SecurityConfig.java index ecfe9c3..1840471 100644 --- a/src/main/java/de/uni_koeln/spinfo/upcase/config/SecurityConfig.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/config/SecurityConfig.java @@ -1,14 +1,25 @@ package de.uni_koeln.spinfo.upcase.config; +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.web.util.matcher.AntPathRequestMatcher; +import de.uni_koeln.spinfo.upcase.model.form.RegistrationForm; +import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.UpcaseUser; +import de.uni_koeln.spinfo.upcase.security.MyInMemoryUserDetailsManager; + @Configuration @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) @@ -17,14 +28,39 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { // @formatter:off @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { - auth.inMemoryAuthentication().withUser("editor").password("editor").roles("USER"); - auth.inMemoryAuthentication().withUser("guest").password("guest").roles("USER"); - auth.inMemoryAuthentication().withUser("user").password("user").roles("USER"); - auth.inMemoryAuthentication().withUser("admin").password("admin").roles("ADMIN"); - auth.inMemoryAuthentication().withUser("superuser").password("superuser").roles("USER", "ADMIN"); - auth.inMemoryAuthentication().withUser("god").password("god").roles("USER", "ADMIN", "CREATER"); + auth.userDetailsService(inMemoryUserDetailsManager()); +// auth.inMemoryAuthentication().withUser("user").password("user").roles("USER"); +// auth.inMemoryAuthentication().withUser("admin").password("admin").roles("ADMIN"); } + @Bean + public MyInMemoryUserDetailsManager inMemoryUserDetailsManager() { + + Collection users = new ArrayList<>(); + + UpcaseUser upcaseUser1 = new UpcaseUser(new RegistrationForm("Mihail", "Atanassov", "matanass@uni-koeln.de", "Department of Computational Linguistics", "matana123", "matana123")); + UpcaseUser upcaseUser2 = new UpcaseUser(new RegistrationForm("Claes", "Neuefeind", "claesn@uni-koeln.de", "Department of Computational Linguistics", "claesn123", "claesn123")); + UpcaseUser upcaseUser3 = new UpcaseUser(new RegistrationForm("Guest", "Guest", "guest", "", "guest", "guest")); + List authorities = new ArrayList<>(); + authorities.add(new GrantedAuthority() { + + private static final long serialVersionUID = 1L; + + @Override + public String getAuthority() { + return "ROLE_ADMIN"; + } + }); + UpcaseUser upcaseUser4 = new UpcaseUser(new RegistrationForm("Admin", "Admin", "admin", "", "admin", "admin"), true, true, true, true, authorities); + + users.add(upcaseUser1); + users.add(upcaseUser2); + users.add(upcaseUser3); + users.add(upcaseUser4); + + return new MyInMemoryUserDetailsManager(users); + } + @Override public void configure(HttpSecurity http) throws Exception { http @@ -45,7 +81,7 @@ public void configure(HttpSecurity http) throws Exception { .logoutSuccessUrl("/") .and() .exceptionHandling() - .accessDeniedPage("/access_denied") + .accessDeniedPage("/something_went_wrong") .and() .logout() .logoutRequestMatcher(new AntPathRequestMatcher("/logout")) diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/config/SecurityWebApplicationInitializer.java b/src/main/java/de/uni_koeln/spinfo/upcase/config/SecurityWebApplicationInitializer.java deleted file mode 100644 index bee3780..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/config/SecurityWebApplicationInitializer.java +++ /dev/null @@ -1,7 +0,0 @@ -package de.uni_koeln.spinfo.upcase.config; - -import org.springframework.security.web.context.AbstractSecurityWebApplicationInitializer; - -public class SecurityWebApplicationInitializer /*extends AbstractSecurityWebApplicationInitializer*/ { - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/config/SpringMvcInitializer.java b/src/main/java/de/uni_koeln/spinfo/upcase/config/SpringMvcInitializer.java deleted file mode 100644 index 71bfad6..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/config/SpringMvcInitializer.java +++ /dev/null @@ -1,22 +0,0 @@ -package de.uni_koeln.spinfo.upcase.config; - -import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; - -public class SpringMvcInitializer /*extends AbstractAnnotationConfigDispatcherServletInitializer*/ { - -// @Override -// protected Class[] getRootConfigClasses() { -// return new Class[] { SecurityConfig.class, MongoDbConfig.class, ThymeLeafConfig.class }; -// } -// -// @Override -// protected Class[] getServletConfigClasses() { -// return null; -// } -// -// @Override -// protected String[] getServletMappings() { -// return new String[] { "/" }; -// } - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/config/ThymeLeafConfig.java b/src/main/java/de/uni_koeln/spinfo/upcase/config/ThymeLeafConfig.java index 54695d7..82e543b 100644 --- a/src/main/java/de/uni_koeln/spinfo/upcase/config/ThymeLeafConfig.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/config/ThymeLeafConfig.java @@ -48,7 +48,7 @@ public ServletContextTemplateResolver templateResolver() { } @Bean - public SpringTemplateEngine templateEngine() { + public SpringTemplateEngine templateEngine() { SpringTemplateEngine engine = new SpringTemplateEngine(); engine.setTemplateResolver(templateResolver()); Set dialetcs = new HashSet<>(); @@ -72,13 +72,13 @@ public MessageSource messageSource() { messageSource.setBasename("locale/messages"); return messageSource; } - - @Bean - public CommonsMultipartResolver multipartResolver() { + + @Bean(name = "filterMultipartResolver") + public CommonsMultipartResolver filterMultipartResolver() { CommonsMultipartResolver resolver = new CommonsMultipartResolver(); - resolver.setMaxUploadSize(104857600); + resolver.setMaxUploadSize(-1); resolver.setDefaultEncoding("UTF-8"); return resolver; } - + } diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/config/WebAppInitializer.java b/src/main/java/de/uni_koeln/spinfo/upcase/config/WebAppInitializer.java deleted file mode 100644 index 942a943..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/config/WebAppInitializer.java +++ /dev/null @@ -1,28 +0,0 @@ -package de.uni_koeln.spinfo.upcase.config; - -import javax.servlet.ServletContext; -import javax.servlet.ServletRegistration; - -import org.springframework.web.WebApplicationInitializer; -import org.springframework.web.context.ContextLoaderListener; -import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -import org.springframework.web.servlet.DispatcherServlet; - -public class WebAppInitializer /*implements WebApplicationInitializer*/ { - -// @Override -// public void onStartup(ServletContext context) { -// // Create the 'root' Spring application context -// AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); -// rootContext.register(AppConfig.class); -// -// // Manage the lifecycle of the root application context -// context.addListener(new ContextLoaderListener(rootContext)); -// -// // Register and map the dispatcher servlet -// ServletRegistration.Dynamic dispatcher = context.addServlet("dispatcher", new DispatcherServlet(rootContext)); -// dispatcher.setLoadOnStartup(1); -// dispatcher.addMapping("/"); -// } - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/controller/CollectionsNavController.java b/src/main/java/de/uni_koeln/spinfo/upcase/controller/CollectionsNavController.java index 142bfae..2f9501f 100755 --- a/src/main/java/de/uni_koeln/spinfo/upcase/controller/CollectionsNavController.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/controller/CollectionsNavController.java @@ -1,54 +1,43 @@ package de.uni_koeln.spinfo.upcase.controller; -import java.util.Arrays; -import java.util.List; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Chapter; -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Page; -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Volume; -import de.uni_koeln.spinfo.upcase.mongodb.util.DataBase; - @Controller -//@RequestMapping(value = "/drc") +// @RequestMapping(value = "/drc") public class CollectionsNavController { - + Logger logger = LoggerFactory.getLogger(getClass()); - @Autowired - private DataBase db; +// @Autowired +// private DataBase db; + +// @RequestMapping(value = "/chapters", method = RequestMethod.GET) +// public String getChapters(@RequestParam("volumeId") String volumeId, Model model) { +// Volume volume = db.getVolumeRepository().findOne(volumeId); +// List chapters = db.getChapterRepository().findByVolumeId(volumeId); +// model.addAttribute("chapters", chapters); +// model.addAttribute("volume", volume); +// return "fragments/chapter-list :: chapter-list"; +// } - @RequestMapping(value = "/chapters", method = RequestMethod.GET) - public String getChapters(@RequestParam("volumeId") String volumeId, Model model) { - Volume volume = db.getVolumeRepository().findOne(volumeId); - List chapters = db.getChapterRepository().findByVolumeId(volumeId); - model.addAttribute("chapters", chapters); - model.addAttribute("volume", volume); - return "fragments/chapter-list :: chapter-list"; - } - @RequestMapping(value = "/pages", method = RequestMethod.GET) public String getPages(@RequestParam("chapterId") String chapterId, - @RequestParam("chapterTitle") String chapterTitle, - @RequestParam("volumeId") String volumeId, + @RequestParam("chapterTitle") String chapterTitle, @RequestParam("volumeId") String volumeId, @RequestParam("volumeTitle") String volumeTitle, Model model) { - List pages = db.getPageRepository().findByChapterIds( - Arrays.asList(new String[] { chapterId })); - - model.addAttribute("pages", pages); - model.addAttribute("chapterTitle", chapterTitle); - model.addAttribute("chapterId", chapterId); - model.addAttribute("volumeId", volumeId); - model.addAttribute("volumeTitle", volumeTitle); +// List pages = db.getPageRepository().findByChapterIds(Arrays.asList(new String[] { chapterId })); +// +// model.addAttribute("pages", pages); +// model.addAttribute("chapterTitle", chapterTitle); +// model.addAttribute("chapterId", chapterId); +// model.addAttribute("volumeId", volumeId); +// model.addAttribute("volumeTitle", volumeTitle); return "fragments/page-list :: page-list"; } diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/controller/ContentController.java b/src/main/java/de/uni_koeln/spinfo/upcase/controller/ContentController.java index 5a84af2..eecb39a 100755 --- a/src/main/java/de/uni_koeln/spinfo/upcase/controller/ContentController.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/controller/ContentController.java @@ -1,34 +1,12 @@ package de.uni_koeln.spinfo.upcase.controller; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; - import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.servlet.ModelAndView; - -import com.fasterxml.jackson.core.JsonGenerationException; -import com.fasterxml.jackson.databind.JsonMappingException; -import de.uni_koeln.spinfo.upcase.mongodb.Constans; -import de.uni_koeln.spinfo.upcase.mongodb.data.Version; -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Chapter; -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Page; -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Word; -import de.uni_koeln.spinfo.upcase.mongodb.data.light.Letter; -import de.uni_koeln.spinfo.upcase.mongodb.data.light.RectangleLight; import de.uni_koeln.spinfo.upcase.mongodb.util.DataBase; + @Controller() -//@RequestMapping(value = "/drc") public class ContentController { @Autowired @@ -52,68 +30,68 @@ public class ContentController { // return mv; // } - @RequestMapping(value = "/correct") - public ModelAndView correctPage(@RequestParam("pageId") String pageId, - @RequestParam("chapterId") String chapterId, - @RequestParam("chapterTitle") String chapterTitle, - @RequestParam("volumeId") String volumeId, - @RequestParam("volumeTitle") String volumeTitle) - throws JsonGenerationException, JsonMappingException, IOException { - - Page page = db.getPageRepository().findByPageId(pageId); - List words = db.getWordRepository().findByRange(page.getStart(), page.getEnd()); - Collections.sort(words); - List letters = new ArrayList<>(); - List rectangles = new ArrayList<>(); - AtomicInteger textLength = new AtomicInteger(); - for (Word word : words) { - Version currentVersion = word.getCurrentVersion(); - String id = word.getId(); - int index = word.getIndex(); - rectangles.add(new RectangleLight(id, word.getRectangle())); - char[] charArray = currentVersion.getValue().toCharArray(); - AtomicInteger wordLength = new AtomicInteger(); - for (char c : charArray) { - if ((int) c != 32) { - letters.add(new Letter(id, index, c, wordLength - .getAndIncrement(), textLength.getAndIncrement())); - } - - } - } - - ModelAndView mv = new ModelAndView("correct"); - mv.addObject("letters", letters); - mv.addObject("rectangles", rectangles); - mv.addObject("page", page); - mv.addObject("chapterTitle", chapterTitle); - mv.addObject("chapterId", chapterId); - mv.addObject("chapters", getChapters(page)); - mv.addObject("volumeId", volumeId); - mv.addObject("volumeTitle", volumeTitle); - return mv; - } - - @RequestMapping(value = "/page") - public ModelAndView pageDetails(@RequestParam("pageId") String pageId) - throws JsonGenerationException, JsonMappingException, IOException { - Page page = db.getPageRepository().findByPageId(pageId); - List words = db.getWordRepository().findByRange(page.getStart(), page.getEnd()); - Collections.sort(words); - ModelAndView mv = new ModelAndView("page"); - mv.addObject("words", words); - mv.addObject("page", page); - return mv; - } - - public Iterable getChapters(Page page) { - return db.getChapterRepository().findAll(page.getChapterIds()); - } - - @RequestMapping(value = "/language", method = RequestMethod.GET) - @ResponseBody - public String getLanguage(@RequestParam("languageId") String languageId) { - return db.getLanguageRepository().findOne(languageId).getTitle(); - } +// @RequestMapping(value = "/correct") +// public ModelAndView correctPage(@RequestParam("pageId") String pageId, +// @RequestParam("chapterId") String chapterId, +// @RequestParam("chapterTitle") String chapterTitle, +// @RequestParam("volumeId") String volumeId, +// @RequestParam("volumeTitle") String volumeTitle) +// throws JsonGenerationException, JsonMappingException, IOException { +// +// Page page = db.getPageRepository().findByPageId(pageId); +// List words = db.getWordRepository().findByRange(page.getStart(), page.getEnd()); +// Collections.sort(words); +// List letters = new ArrayList<>(); +// List rectangles = new ArrayList<>(); +// AtomicInteger textLength = new AtomicInteger(); +// for (Word word : words) { +// Version currentVersion = word.getCurrentVersion(); +// String id = word.getId(); +// int index = word.getIndex(); +// rectangles.add(new RectangleLight(id, word.getRectangle())); +// char[] charArray = currentVersion.getValue().toCharArray(); +// AtomicInteger wordLength = new AtomicInteger(); +// for (char c : charArray) { +// if ((int) c != 32) { +// letters.add(new Letter(id, index, c, wordLength +// .getAndIncrement(), textLength.getAndIncrement())); +// } +// +// } +// } +// +// ModelAndView mv = new ModelAndView("correct"); +// mv.addObject("letters", letters); +// mv.addObject("rectangles", rectangles); +// mv.addObject("page", page); +// mv.addObject("chapterTitle", chapterTitle); +// mv.addObject("chapterId", chapterId); +// mv.addObject("chapters", getChapters(page)); +// mv.addObject("volumeId", volumeId); +// mv.addObject("volumeTitle", volumeTitle); +// return mv; +// } +// +// @RequestMapping(value = "/page") +// public ModelAndView pageDetails(@RequestParam("pageId") String pageId) +// throws JsonGenerationException, JsonMappingException, IOException { +// Page page = db.getPageRepository().findByPageId(pageId); +// List words = db.getWordRepository().findByRange(page.getStart(), page.getEnd()); +// Collections.sort(words); +// ModelAndView mv = new ModelAndView("page"); +// mv.addObject("words", words); +// mv.addObject("page", page); +// return mv; +// } +// +// public Iterable getChapters(Page page) { +// return db.getChapterRepository().findAll(page.getChapterIds()); +// } +// +// @RequestMapping(value = "/language", method = RequestMethod.GET) +// @ResponseBody +// public String getLanguage(@RequestParam("languageId") String languageId) { +// return db.getLanguageRepository().findOne(languageId).getTitle(); +// } } diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/controller/HomeController.java b/src/main/java/de/uni_koeln/spinfo/upcase/controller/HomeController.java new file mode 100755 index 0000000..ba72cf1 --- /dev/null +++ b/src/main/java/de/uni_koeln/spinfo/upcase/controller/HomeController.java @@ -0,0 +1,40 @@ +package de.uni_koeln.spinfo.upcase.controller; + +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.servlet.ModelAndView; + +@Controller +public class HomeController { + + @ModelAttribute("userName") + public Model userName(Model model) { + Authentication auth = SecurityContextHolder.getContext().getAuthentication(); + String userName = "unknown"; + if (auth != null) + userName = auth.getName(); + model.addAttribute("userName", userName); + return model; + } + + @RequestMapping(value = "/") + public String init() { + return "home"; + } + + @RequestMapping(value = "/about") + public ModelAndView getInfo() { + return new ModelAndView("index"); + } + + @RequestMapping(value = "/contact.html") + public @ResponseBody ModelAndView getContacts() { + return new ModelAndView("contact"); + } + +} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/controller/IndexController.java b/src/main/java/de/uni_koeln/spinfo/upcase/controller/IndexController.java deleted file mode 100755 index da7cbd1..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/controller/IndexController.java +++ /dev/null @@ -1,26 +0,0 @@ -package de.uni_koeln.spinfo.upcase.controller; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.servlet.ModelAndView; - -@Controller -public class IndexController { - - @RequestMapping(value = "/") - public ModelAndView init() { - return new ModelAndView("home"); - } - - @RequestMapping(value = "/about") - public ModelAndView getInfo() { - return new ModelAndView("index"); - } - - @RequestMapping(value = "/contact.html") - public @ResponseBody ModelAndView getContacts() { - return new ModelAndView("contact"); - } - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/controller/JsonController.java b/src/main/java/de/uni_koeln/spinfo/upcase/controller/JsonController.java index 27f4fca..85f6139 100755 --- a/src/main/java/de/uni_koeln/spinfo/upcase/controller/JsonController.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/controller/JsonController.java @@ -1,30 +1,22 @@ package de.uni_koeln.spinfo.upcase.controller; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Page; -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Word; -import de.uni_koeln.spinfo.upcase.mongodb.util.DataBase; - @RestController() public class JsonController { - @Autowired - private DataBase db; - - @RequestMapping(value="/drc/rest/word", method=RequestMethod.GET) - public Word getWordfromIndex(@RequestParam(value = "index") int index) { - return db.getWordRepository().findByIndex(index); - } - - @RequestMapping(value="/drc/rest/page", method=RequestMethod.GET) - public Page getPageWithUrl(@RequestParam(value = "url") String url) { - return db.getPageRepository().findByUrl(url); - } +// @Autowired +// private DataBase db; +// +// @RequestMapping(value="/drc/rest/word", method=RequestMethod.GET) +// public Word getWordfromIndex(@RequestParam(value = "index") int index) { +// return db.getWordRepository().findByIndex(index); +// } +// +// @RequestMapping(value="/drc/rest/page", method=RequestMethod.GET) +// public Page getPageWithUrl(@RequestParam(value = "url") String url) { +// return db.getPageRepository().findByUrl(url); +// } } \ No newline at end of file diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/controller/UserSessionController.java b/src/main/java/de/uni_koeln/spinfo/upcase/controller/UserSessionController.java deleted file mode 100644 index 7dcd64e..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/controller/UserSessionController.java +++ /dev/null @@ -1,25 +0,0 @@ -package de.uni_koeln.spinfo.upcase.controller; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.security.core.Authentication; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.ResponseBody; - -@Controller -public class UserSessionController { - - Logger logger = LoggerFactory.getLogger(getClass()); - - @RequestMapping(value = { "/login"}) - public String login() { - return "login"; - } - - @RequestMapping(value = { "/access_denied"}) - public @ResponseBody String accessDenied(Authentication auth) { - return "

Access Denied!

" + auth; - } - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/controller/VolumeController.java b/src/main/java/de/uni_koeln/spinfo/upcase/controller/VolumeController.java index 86814eb..d845156 100755 --- a/src/main/java/de/uni_koeln/spinfo/upcase/controller/VolumeController.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/controller/VolumeController.java @@ -1,34 +1,18 @@ package de.uni_koeln.spinfo.upcase.controller; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.core.Authentication; -import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.servlet.ModelAndView; - -import de.uni_koeln.spinfo.upcase.mongodb.Constans; -import de.uni_koeln.spinfo.upcase.mongodb.util.DataBase; @Controller() -//@RequestMapping(value = "/drc") public class VolumeController { - @Autowired - private DataBase db; - - @RequestMapping(value = "/volumes", method = RequestMethod.GET) - public String getVolumes(Authentication auth, Model model) { -// Authentication auth = SecurityContextHolder.getContext().getAuthentication(); - String userName = "unknown"; - if(auth != null) - userName = auth.getName(); - model.addAttribute("volumes", db.getVolumeRepository().findAll()); - model.addAttribute("userName", userName); - return "/volumes"; - } +// @Autowired +// private DataBase db; +// +// @RequestMapping(value = "/volumes", method = RequestMethod.GET) +// public String getVolumes(Authentication auth, Model model) { +// model.addAttribute("volumes", db.getVolumeRepository().findAll()); +// return "/volumes"; +// } diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/controller/administration/AdminController.java b/src/main/java/de/uni_koeln/spinfo/upcase/controller/administration/AdminController.java index 8f33374..4f5b8eb 100644 --- a/src/main/java/de/uni_koeln/spinfo/upcase/controller/administration/AdminController.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/controller/administration/AdminController.java @@ -6,7 +6,8 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import de.uni_koeln.spinfo.upcase.mongodb.repository.UpcaseUserRepository; +import de.uni_koeln.spinfo.upcase.mongodb.repository.future.UpcaseUserRepository; + @Controller() public class AdminController { diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/controller/search/SearchController.java b/src/main/java/de/uni_koeln/spinfo/upcase/controller/search/SearchController.java index 0257cca..0afd645 100755 --- a/src/main/java/de/uni_koeln/spinfo/upcase/controller/search/SearchController.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/controller/search/SearchController.java @@ -1,13 +1,8 @@ package de.uni_koeln.spinfo.upcase.controller.search; import java.io.IOException; -import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Set; -import java.util.TreeSet; -import java.util.regex.Matcher; -import java.util.regex.Pattern; import org.apache.lucene.queryparser.classic.ParseException; import org.apache.lucene.search.highlight.InvalidTokenOffsetsException; @@ -15,25 +10,12 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import de.uni_koeln.spinfo.upcase.lucene.SearchResult; import de.uni_koeln.spinfo.upcase.lucene.Searcher; -import de.uni_koeln.spinfo.upcase.mongodb.data.Version; -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Chapter; -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Language; -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Page; -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Volume; -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Word; -import de.uni_koeln.spinfo.upcase.mongodb.data.light.RectangleLight; -import de.uni_koeln.spinfo.upcase.mongodb.util.DataBase; import de.uni_koeln.spinfo.upcase.util.ChapterComparator; import de.uni_koeln.spinfo.upcase.util.PropertyReader; import de.uni_koeln.spinfo.upcase.util.VolumeComparator; @@ -52,8 +34,8 @@ public class SearchController { @Autowired private Searcher searcher; - @Autowired - private DataBase db; +// @Autowired +// private DataBase db; @Autowired PropertyReader propertyReader; @@ -66,76 +48,76 @@ public ModelAndView search() { return new ModelAndView("search"); } - @ModelAttribute("languageList") - public List getLanguageList() { - Iterable findAll = db.getLanguageRepository().findAll(); - List languages = new ArrayList<>(); - Set set = new TreeSet<>(); - findAll.forEach(l -> set.add(l.getTitle())); - languages.addAll(set); - return languages; - } - - @ModelAttribute("volumeList") - public List getVolumeList() { - Iterable findAll = db.getVolumeRepository().findAll(); - List volumes = new ArrayList<>(); - findAll.forEach(l -> volumes.add(l.getTitle())); - return volumes; - } - - @RequestMapping(value = "chapters/by/volume/title/{volumeTitle}", method = RequestMethod.GET, produces = "application/json; charset=UTF-8") - public @ResponseBody List getChapterNamesByVolTitle(@PathVariable String volumeTitle) { - Volume volume = db.getVolumeRepository().findByTitle(volumeTitle); - if (volume == null) { - return new ArrayList<>(); - } - List chapters = db.getChapterRepository().findByVolumeId(volume.getId()); - List chapterNames = new ArrayList<>(); - chapters.forEach(c -> chapterNames.add(c.getTitle())); - return chapterNames; - } - - @RequestMapping(value = "/showDocument", method = RequestMethod.GET) - public Model showDocument(Model model, @RequestParam("pageId") final String pageId, - @RequestParam("resultQuotations") String... resultQuotations) { - - Page page = db.getPageRepository().findByPageId(pageId); - List words = db.getWordRepository().findByRange(page.getStart(), page.getEnd()); - Collections.sort(words); - List rectangles = new ArrayList<>(); - - Pattern quotationFinder = Pattern.compile("]*>(.*?)", Pattern.DOTALL | Pattern.CASE_INSENSITIVE); - - List matchedTokens = new ArrayList<>(); - - for (String quotation : resultQuotations) { - Matcher regexMatcher = quotationFinder.matcher(quotation); - while (regexMatcher.find()) { - matchedTokens.add(regexMatcher.group(1)); - } - } - - for (Word word : words) { - Version currentVersion = word.getCurrentVersion(); - for (String token : matchedTokens) { - String normalized = currentVersion.getValue().replaceAll("\\W", ""); - if (normalized.equalsIgnoreCase(token)) { - String id = word.getId(); - RectangleLight rectangleLight = new RectangleLight(id, word.getRectangle()); - logger.debug("version :: '" + currentVersion.getValue() + "' rectangle :: " + rectangleLight); - rectangles.add(rectangleLight); - } - } - } - - model.addAttribute("page", page); - model.addAttribute("imgUrl", IMGS_URL + page.getUrl().replace(".xml", "")); - model.addAttribute("words", words); - model.addAttribute("rectangles", rectangles); - - return model; - } +// @ModelAttribute("languageList") +// public List getLanguageList() { +// Iterable findAll = db.getLanguageRepository().findAll(); +// List languages = new ArrayList<>(); +// Set set = new TreeSet<>(); +// findAll.forEach(l -> set.add(l.getTitle())); +// languages.addAll(set); +// return languages; +// } + +// @ModelAttribute("volumeList") +// public List getVolumeList() { +// Iterable findAll = db.getVolumeRepository().findAll(); +// List volumes = new ArrayList<>(); +// findAll.forEach(l -> volumes.add(l.getTitle())); +// return volumes; +// } + +// @RequestMapping(value = "chapters/by/volume/title/{volumeTitle}", method = RequestMethod.GET, produces = "application/json; charset=UTF-8") +// public @ResponseBody List getChapterNamesByVolTitle(@PathVariable String volumeTitle) { +// Volume volume = db.getVolumeRepository().findByTitle(volumeTitle); +// if (volume == null) { +// return new ArrayList<>(); +// } +// List chapters = db.getChapterRepository().findByVolumeId(volume.getId()); +// List chapterNames = new ArrayList<>(); +// chapters.forEach(c -> chapterNames.add(c.getTitle())); +// return chapterNames; +// } + +// @RequestMapping(value = "/showDocument", method = RequestMethod.GET) +// public Model showDocument(Model model, @RequestParam("pageId") final String pageId, +// @RequestParam("resultQuotations") String... resultQuotations) { +// +// Page page = db.getPageRepository().findByPageId(pageId); +// List words = db.getWordRepository().findByRange(page.getStart(), page.getEnd()); +// Collections.sort(words); +// List rectangles = new ArrayList<>(); +// +// Pattern quotationFinder = Pattern.compile("]*>(.*?)", Pattern.DOTALL | Pattern.CASE_INSENSITIVE); +// +// List matchedTokens = new ArrayList<>(); +// +// for (String quotation : resultQuotations) { +// Matcher regexMatcher = quotationFinder.matcher(quotation); +// while (regexMatcher.find()) { +// matchedTokens.add(regexMatcher.group(1)); +// } +// } +// +// for (Word word : words) { +// Version currentVersion = word.getCurrentVersion(); +// for (String token : matchedTokens) { +// String normalized = currentVersion.getValue().replaceAll("\\W", ""); +// if (normalized.equalsIgnoreCase(token)) { +// String id = word.getId(); +// RectangleLight rectangleLight = new RectangleLight(id, word.getRectangle()); +// logger.debug("version :: '" + currentVersion.getValue() + "' rectangle :: " + rectangleLight); +// rectangles.add(rectangleLight); +// } +// } +// } +// +// model.addAttribute("page", page); +// model.addAttribute("imgUrl", IMGS_URL + page.getUrl().replace(".xml", "")); +// model.addAttribute("words", words); +// model.addAttribute("rectangles", rectangles); +// +// return model; +// } /** * The result view diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/controller/user/CollectionController.java b/src/main/java/de/uni_koeln/spinfo/upcase/controller/user/CollectionController.java new file mode 100644 index 0000000..a3729e4 --- /dev/null +++ b/src/main/java/de/uni_koeln/spinfo/upcase/controller/user/CollectionController.java @@ -0,0 +1,82 @@ +package de.uni_koeln.spinfo.upcase.controller.user; + +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.validation.Valid; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.web.bind.WebDataBinder; +import org.springframework.web.bind.annotation.InitBinder; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.MultipartHttpServletRequest; +import org.springframework.web.multipart.support.DefaultMultipartHttpServletRequest; + +import de.uni_koeln.spinfo.upcase.CollectionAlreadyExistsException; +import de.uni_koeln.spinfo.upcase.model.form.UploadForm; +import de.uni_koeln.spinfo.upcase.model.validator.UploadFormValidator; +import de.uni_koeln.spinfo.upcase.mongodb.repository.future.CollectionRepositoryImpl; +import de.uni_koeln.spinfo.upcase.service.CollectionService; + +@Controller +public class CollectionController { + + // @ModelAttribute("encodings") + // public Encoding[] getEncodings() { + // return Encoding.values(); + // } + + Logger logger = LoggerFactory.getLogger(getClass()); + + @Autowired + private CollectionService collectionService; + + @Autowired + private CollectionRepositoryImpl collectionRepository; + + @InitBinder("uploadForm") + protected void initBinder(WebDataBinder binder) { + binder.addValidators(new UploadFormValidator()); + } + + @RequestMapping(value = "/user/collection/{id}", method = RequestMethod.GET) + public String userCollection(@PathVariable("id") String id, Model model) { + model.addAttribute("collection", collectionRepository.findbyId(id)); + return "user/userCollection"; + } + + @PreAuthorize("hasRole('USER')") + @RequestMapping(value = "/create/collection", method = RequestMethod.GET) + public String uploadFiles(UploadForm uploadForm, Model model) { + model.addAttribute("uploadForm", uploadForm); + return "upload"; + } + + @PreAuthorize("hasRole('USER')") + @RequestMapping(value = "/create/collection", method = RequestMethod.POST) + public String uploadFiles(@Valid UploadForm uploadForm, BindingResult bindingResult) throws CollectionAlreadyExistsException { + + if (bindingResult.hasErrors()) { + logger.error("Errors detected, error count: " + bindingResult.getGlobalErrorCount()); + return "upload"; + } + String collectionId = collectionService.createCollection(uploadForm); + return "redirect:/home"; + } + + private String getUserName() { + return SecurityContextHolder.getContext().getAuthentication().getName(); + } + +} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/controller/user/RegistrationController.java b/src/main/java/de/uni_koeln/spinfo/upcase/controller/user/RegistrationController.java index 0563ba6..e50e23b 100644 --- a/src/main/java/de/uni_koeln/spinfo/upcase/controller/user/RegistrationController.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/controller/user/RegistrationController.java @@ -14,10 +14,10 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; -import de.uni_koeln.spinfo.upcase.model.RegistrationForm; +import de.uni_koeln.spinfo.upcase.model.form.RegistrationForm; import de.uni_koeln.spinfo.upcase.model.validator.RegistrationFormValidator; -import de.uni_koeln.spinfo.upcase.mongodb.data.document.UpcaseUser; -import de.uni_koeln.spinfo.upcase.mongodb.repository.UpcaseUserRepository; +import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.UpcaseUser; +import de.uni_koeln.spinfo.upcase.mongodb.repository.future.UpcaseUserRepository; @Controller public class RegistrationController { @@ -26,7 +26,7 @@ public class RegistrationController { @Autowired private UpcaseUserRepository upcaseUserRepository; - + @InitBinder("registrationForm") protected void initBinder(WebDataBinder binder) { binder.addValidators(new RegistrationFormValidator()); diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/controller/user/UploadController.java b/src/main/java/de/uni_koeln/spinfo/upcase/controller/user/UploadController.java deleted file mode 100644 index 6249e72..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/controller/user/UploadController.java +++ /dev/null @@ -1,57 +0,0 @@ -package de.uni_koeln.spinfo.upcase.controller.user; - -import java.io.BufferedOutputStream; -import java.io.File; -import java.io.FileOutputStream; - -import javax.validation.Valid; - -import org.springframework.stereotype.Controller; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.servlet.ModelAndView; - -import de.uni_koeln.spinfo.upcase.model.Encoding; -import de.uni_koeln.spinfo.upcase.model.UploadForm; - -@Controller -public class UploadController { - - @ModelAttribute("encodings") - public Encoding[] getEncodings() { - return Encoding.values(); - } - - @RequestMapping(value = "/upload", method = RequestMethod.GET) - public ModelAndView uploadFiles(UploadForm uploadForm) { - ModelAndView mv = new ModelAndView("upload"); - mv.addObject("uploadForm", uploadForm); - mv.addObject(getEncodings()); - return mv; - } - - @RequestMapping(value = "/upload", method = RequestMethod.POST) - public String uploadFiles(@Valid UploadForm uploadForm, - BindingResult bindingResult) { - if (bindingResult.hasErrors()) { - return "upload"; - } - // TODO: Persist collection details to data base - // TODO: Store uploaded files in users working directory - try { - byte[] bytes = uploadForm.getMultiPart().getBytes(); - BufferedOutputStream stream = new BufferedOutputStream( - new FileOutputStream(new File("USER_COLLECTIONS_DIR/" + uploadForm.getWorkTitle(), - uploadForm.getMultiPart().getOriginalFilename()))); - stream.write(bytes); - stream.close(); - // TODO: OCR on uploaded files - } catch (Exception e) { - return e.getMessage(); - } - return "redirect:/userCollection"; - } - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/controller/user/UserCollectionController.java b/src/main/java/de/uni_koeln/spinfo/upcase/controller/user/UserCollectionController.java deleted file mode 100644 index 3f9c7f7..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/controller/user/UserCollectionController.java +++ /dev/null @@ -1,28 +0,0 @@ -package de.uni_koeln.spinfo.upcase.controller.user; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; - -import de.uni_koeln.spinfo.upcase.mongodb.repository.UpcaseUserRepository; - -@Controller -public class UserCollectionController { - - Logger logger = LoggerFactory.getLogger(getClass()); - - @Autowired - private UpcaseUserRepository upcaseUserRepository; - - @RequestMapping(value = "/user/userCollection/{id}", method = RequestMethod.GET) - public String userCollection(@PathVariable("id") String id, Model model) { - model.addAttribute("user", upcaseUserRepository.findById(id)); - return "user/userCollection"; - } - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/controller/user/UserSessionController.java b/src/main/java/de/uni_koeln/spinfo/upcase/controller/user/UserSessionController.java new file mode 100644 index 0000000..32eee55 --- /dev/null +++ b/src/main/java/de/uni_koeln/spinfo/upcase/controller/user/UserSessionController.java @@ -0,0 +1,38 @@ +package de.uni_koeln.spinfo.upcase.controller.user; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.security.core.Authentication; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +public class UserSessionController { + + Logger logger = LoggerFactory.getLogger(getClass()); + + @ModelAttribute("userName") + public Model userName(Model model) { + Authentication auth = SecurityContextHolder.getContext().getAuthentication(); + String userName = "unknown"; + if (auth != null) + userName = auth.getName(); + model.addAttribute("userName", userName); + return model; + } + + @RequestMapping(value = { "/login" }) + public String login() { + return "login"; + } + + @RequestMapping(value = { "/something_went_wrong" }) + public @ResponseBody String accessDenied() { + return "

Ups, something went wrong

Please contact your local administrator for help!

"; + } + +} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/lucene/Indexer.java b/src/main/java/de/uni_koeln/spinfo/upcase/lucene/Indexer.java index 6af530d..8978f2f 100755 --- a/src/main/java/de/uni_koeln/spinfo/upcase/lucene/Indexer.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/lucene/Indexer.java @@ -1,248 +1,225 @@ package de.uni_koeln.spinfo.upcase.lucene; -import java.io.File; -import java.io.IOException; -import java.util.List; - -import javax.annotation.PostConstruct; - -import org.apache.lucene.analysis.standard.StandardAnalyzer; -import org.apache.lucene.document.Document; -import org.apache.lucene.document.Field.Store; -import org.apache.lucene.document.StringField; -import org.apache.lucene.document.TextField; -import org.apache.lucene.index.IndexWriter; -import org.apache.lucene.index.IndexWriterConfig; -import org.apache.lucene.store.Directory; -import org.apache.lucene.store.SimpleFSDirectory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Service; -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Page; -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Volume; -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Word; -import de.uni_koeln.spinfo.upcase.mongodb.util.DataBase; -import de.uni_koeln.spinfo.upcase.util.PropertyReader; - @Service public class Indexer { Logger logger = LoggerFactory.getLogger(getClass()); - @Autowired - private DataBase db; - - @Autowired - PropertyReader propertyReader; - - private IndexWriter writer; - - /** - * Creates a new index if there is none on startup (PostConstruct = called - * after all services are initialized). - * - * @throws IOException - */ - @PostConstruct - public void initialIndex() throws IOException { - init(null); - int numdocs = (this.writer.numDocs() == 0 ? index() : this.writer.numDocs()); - logger.info("Index size: " + numdocs); - this.writer.close(); - } - - /** - * Init an indexWriter for the directory specified in properties file. - * - * @throws IOException - */ - public void init(final String path) throws IOException { - String indexDir = path == null ? propertyReader.getIndexDir() : path; - Directory dir = new SimpleFSDirectory(new File(indexDir).toPath()); - IndexWriterConfig writerConfig = new IndexWriterConfig(new StandardAnalyzer()); - this.writer = new IndexWriter(dir, writerConfig); - } - - /** - * Build index over db, optionally restricted to a predefined size (for test - * purposes). - * - * @param size - * @return Total number of indexed documents. - */ - public int index() { - - long start = System.currentTimeMillis(); - logger.info("Indexing collection..."); - logger.info("MAXSIZE: " + propertyReader.getMaxIndexSize()); - logger.info("Docs to index: " + db.getMongoTemplate().count(new Query(), Page.class)); - - Iterable volumes = db.getVolumeRepository().findAll(); - int pageCount = 0; - boolean breakInnerLoop = false; - for (Volume volume : volumes) { - List pages = db.getPageRepository().findByVolumeId( - volume.getId()); - for (Page p : pages) { - pageCount++; - if (pageCount <= propertyReader.getMaxIndexSize()) { - logger.info(pageCount + ": " + p.toString()); - indexPage(p); - } else { - breakInnerLoop = true; - break; - } - } - if (breakInnerLoop) - break; - } - logger.info("Indexing took " + (System.currentTimeMillis() - start) - + " ms."); - return this.writer.numDocs(); - } - - /** - * Convert page and add to index. - * - * @param page - * @param langTitle - */ - private void indexPage(Page page) { - Document doc = pageToLuceneDoc(page); - if (doc != null) { - logger.info("Adding doc: " + page.toString()); - try { - this.writer.addDocument(doc); - } catch (IOException e) { - e.printStackTrace(); - } - } - } - - /** - * Convert page into Lucene Document. - * - * @param page - * @param langTitle - * @return Lucene Document to be indexed. - */ - private Document pageToLuceneDoc(Page page) { - Document doc = new Document(); - doc.add(new StringField("url", page.getUrl(), Store.YES)); - doc.add(new StringField("pageId", page.getId(), Store.YES)); - doc.add(new TextField("contents", pageContent(page), Store.YES)); - doc.add(new TextField("languages", languages(page), Store.YES)); - doc.add(new TextField("chapterId", chapterIds(page), Store.YES)); - doc.add(new TextField("chapters", chapters(page), Store.YES)); - doc.add(new StringField("volumeId", page.getVolumeId(), Store.YES)); - String volume = db.getVolumeRepository().findOne(page.getVolumeId()).getTitle(); - doc.add(new TextField("volumeTitle", volume, Store.YES)); - String ppn = page.getPrintedPageNuber(); - if (ppn != null) - doc.add(new StringField("pageNumber", ppn, Store.YES)); - return doc; - } - - /** - * Retrieve chapter Id(s) a page belongs to. May contain two ids, for in - * some cases chapters start in the middle of a page. - * - * @param page - * @return (blank separated) chapter id(s) - */ - private String chapterIds(Page page) { - StringBuilder sb = new StringBuilder(); - List chapterIds = page.getChapterIds(); - for (String id : chapterIds) { - sb.append(id + " "); - } - return sb.toString().trim(); - } - - /** - * Retrieve chapter name(s) a page belongs to. May contain two chapter - * titles, for in some cases chapters start in the middle of a page. - * - * @param page - * @return (blank separated) chapter title(s) - */ - private String chapters(Page page) { - StringBuilder sb = new StringBuilder(); - List chapterIds = page.getChapterIds(); - for (String id : chapterIds) { - sb.append(db.getChapterRepository().findOne(id).getTitle() + " "); - } - return sb.toString().trim(); - } - - /** - * Retrieve page language(s) from LanguageRepository. May contain multiple - * language tags. - * - * @param page - * @return (blank separated) language tag(s) - */ - private String languages(Page page) { - StringBuilder sb = new StringBuilder(); - List languageIds = page.getLanguageIds(); - for (String id : languageIds) { - sb.append(db.getLanguageRepository().findOne(id).getTitle() + " "); - } - return sb.toString().trim(); - } - - /** - * Retrieve page contents from WordRepository. - * - * @param page - * @return page contents - */ - private String pageContent(Page page) { - long start = System.currentTimeMillis(); - StringBuilder sb = new StringBuilder(); - List words = db.getWordRepository().findByRange(page.getStart(), - page.getEnd()); - for (Word word : words) { - sb.append(word.getCurrentVersion().getValue() + " "); - } - logger.info("... parse took " + (System.currentTimeMillis() - start) - + " ms."); - return sb.toString().trim(); - } - - /** - * Index has to be closed before searching (or other operations on index). - */ - public void close() throws IOException { - this.writer.close(); - } - - /** - * @return the number of indexed documents. - */ - public int getNumDocs() { - return writer.numDocs(); - } - - /** - * Delete existing index. - */ - public void deleteIndex() { - try { - this.writer.deleteAll(); - } catch (IOException e) { - e.printStackTrace(); - } - } - - /** - * @return true, if the writer is open. - */ - public boolean isAvailable() { - return writer.isOpen(); - } +// @Autowired +// private DataBase db; +// +// @Autowired +// PropertyReader propertyReader; +// +// private IndexWriter writer; +// +// /** +// * Creates a new index if there is none on startup (PostConstruct = called +// * after all services are initialized). +// * +// * @throws IOException +// */ +// @PostConstruct +// public void initialIndex() throws IOException { +// init(null); +// int numdocs = (this.writer.numDocs() == 0 ? index() : this.writer.numDocs()); +// logger.info("Index size: " + numdocs); +// this.writer.close(); +// } +// +// /** +// * Init an indexWriter for the directory specified in properties file. +// * +// * @throws IOException +// */ +// public void init(final String path) throws IOException { +// String indexDir = path == null ? propertyReader.getIndexDir() : path; +// Directory dir = new SimpleFSDirectory(new File(indexDir).toPath()); +// IndexWriterConfig writerConfig = new IndexWriterConfig(new StandardAnalyzer()); +// this.writer = new IndexWriter(dir, writerConfig); +// } +// +// /** +// * Build index over db, optionally restricted to a predefined size (for test +// * purposes). +// * +// * @param size +// * @return Total number of indexed documents. +// */ +// public int index() { +// +// long start = System.currentTimeMillis(); +// logger.info("Indexing collection..."); +// logger.info("MAXSIZE: " + propertyReader.getMaxIndexSize()); +// logger.info("Docs to index: " + db.getMongoTemplate().count(new Query(), Page.class)); +// +// Iterable volumes = db.getVolumeRepository().findAll(); +// int pageCount = 0; +// boolean breakInnerLoop = false; +// for (Volume volume : volumes) { +// List pages = db.getPageRepository().findByVolumeId( +// volume.getId()); +// for (Page p : pages) { +// pageCount++; +// if (pageCount <= propertyReader.getMaxIndexSize()) { +// logger.info(pageCount + ": " + p.toString()); +// indexPage(p); +// } else { +// breakInnerLoop = true; +// break; +// } +// } +// if (breakInnerLoop) +// break; +// } +// logger.info("Indexing took " + (System.currentTimeMillis() - start) +// + " ms."); +// return this.writer.numDocs(); +// } +// +// /** +// * Convert page and add to index. +// * +// * @param page +// * @param langTitle +// */ +// private void indexPage(Page page) { +// Document doc = pageToLuceneDoc(page); +// if (doc != null) { +// logger.info("Adding doc: " + page.toString()); +// try { +// this.writer.addDocument(doc); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// } +// +// /** +// * Convert page into Lucene Document. +// * +// * @param page +// * @param langTitle +// * @return Lucene Document to be indexed. +// */ +// private Document pageToLuceneDoc(Page page) { +// Document doc = new Document(); +// doc.add(new StringField("url", page.getUrl(), Store.YES)); +// doc.add(new StringField("pageId", page.getId(), Store.YES)); +// doc.add(new TextField("contents", pageContent(page), Store.YES)); +// doc.add(new TextField("languages", languages(page), Store.YES)); +// doc.add(new TextField("chapterId", chapterIds(page), Store.YES)); +// doc.add(new TextField("chapters", chapters(page), Store.YES)); +// doc.add(new StringField("volumeId", page.getVolumeId(), Store.YES)); +// String volume = db.getVolumeRepository().findOne(page.getVolumeId()).getTitle(); +// doc.add(new TextField("volumeTitle", volume, Store.YES)); +// String ppn = page.getPrintedPageNuber(); +// if (ppn != null) +// doc.add(new StringField("pageNumber", ppn, Store.YES)); +// return doc; +// } +// +// /** +// * Retrieve chapter Id(s) a page belongs to. May contain two ids, for in +// * some cases chapters start in the middle of a page. +// * +// * @param page +// * @return (blank separated) chapter id(s) +// */ +// private String chapterIds(Page page) { +// StringBuilder sb = new StringBuilder(); +// List chapterIds = page.getChapterIds(); +// for (String id : chapterIds) { +// sb.append(id + " "); +// } +// return sb.toString().trim(); +// } +// +// /** +// * Retrieve chapter name(s) a page belongs to. May contain two chapter +// * titles, for in some cases chapters start in the middle of a page. +// * +// * @param page +// * @return (blank separated) chapter title(s) +// */ +// private String chapters(Page page) { +// StringBuilder sb = new StringBuilder(); +// List chapterIds = page.getChapterIds(); +// for (String id : chapterIds) { +// sb.append(db.getChapterRepository().findOne(id).getTitle() + " "); +// } +// return sb.toString().trim(); +// } +// +// /** +// * Retrieve page language(s) from LanguageRepository. May contain multiple +// * language tags. +// * +// * @param page +// * @return (blank separated) language tag(s) +// */ +// private String languages(Page page) { +// StringBuilder sb = new StringBuilder(); +// List languageIds = page.getLanguageIds(); +// for (String id : languageIds) { +// sb.append(db.getLanguageRepository().findOne(id).getTitle() + " "); +// } +// return sb.toString().trim(); +// } +// +// /** +// * Retrieve page contents from WordRepository. +// * +// * @param page +// * @return page contents +// */ +// private String pageContent(Page page) { +// long start = System.currentTimeMillis(); +// StringBuilder sb = new StringBuilder(); +// List words = db.getWordRepository().findByRange(page.getStart(), +// page.getEnd()); +// for (Word word : words) { +// sb.append(word.getCurrentVersion().getValue() + " "); +// } +// logger.info("... parse took " + (System.currentTimeMillis() - start) +// + " ms."); +// return sb.toString().trim(); +// } +// +// /** +// * Index has to be closed before searching (or other operations on index). +// */ +// public void close() throws IOException { +// this.writer.close(); +// } +// +// /** +// * @return the number of indexed documents. +// */ +// public int getNumDocs() { +// return writer.numDocs(); +// } +// +// /** +// * Delete existing index. +// */ +// public void deleteIndex() { +// try { +// this.writer.deleteAll(); +// } catch (IOException e) { +// e.printStackTrace(); +// } +// } +// +// /** +// * @return true, if the writer is open. +// */ +// public boolean isAvailable() { +// return writer.isOpen(); +// } } diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/model/UploadForm.java b/src/main/java/de/uni_koeln/spinfo/upcase/model/UploadForm.java deleted file mode 100644 index 20083d6..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/model/UploadForm.java +++ /dev/null @@ -1,158 +0,0 @@ -package de.uni_koeln.spinfo.upcase.model; - -import javax.validation.constraints.NotNull; - -import org.hibernate.validator.constraints.NotBlank; -import org.hibernate.validator.constraints.URL; -import org.springframework.web.multipart.MultipartFile; - -public class UploadForm { - - - @NotNull - private MultipartFile multiPart; - - @NotBlank - private String workTitle; - - @NotBlank - private String workAuthor; - - @URL - @NotBlank - private String source; - - private String language; - - private String encoding; - - - public UploadForm() { - - } - - public UploadForm(MultipartFile multiPart, String workTitle, - String workAuthor, String source, String language, String encoding) { - super(); - this.multiPart = multiPart; - this.workTitle = workTitle; - this.workAuthor = workAuthor; - this.source = source; - this.language = language; - this.encoding = encoding; - } - - public MultipartFile getMultiPart() { - return multiPart; - } - - public void setMultiPart(MultipartFile multiPart) { - this.multiPart = multiPart; - } - - public String getWorkTitle() { - return workTitle; - } - - public void setWorkTitle(String workTitle) { - this.workTitle = workTitle; - } - - public String getWorkAuthor() { - return workAuthor; - } - - public void setWorkAuthor(String workAuthor) { - this.workAuthor = workAuthor; - } - - public String getSource() { - return source; - } - - public void setSource(String source) { - this.source = source; - } - - public String getLanguage() { - return language; - } - - public void setLanguage(String language) { - this.language = language; - } - - public String getEncoding() { - return encoding; - } - - public void setEncoding(String encoding) { - this.encoding = encoding; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((encoding == null) ? 0 : encoding.hashCode()); - result = prime * result - + ((language == null) ? 0 : language.hashCode()); - result = prime * result - + ((multiPart == null) ? 0 : multiPart.hashCode()); - result = prime * result + ((source == null) ? 0 : source.hashCode()); - result = prime * result - + ((workAuthor == null) ? 0 : workAuthor.hashCode()); - result = prime * result - + ((workTitle == null) ? 0 : workTitle.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - UploadForm other = (UploadForm) obj; - if (encoding != other.encoding) - return false; - if (language == null) { - if (other.language != null) - return false; - } else if (!language.equals(other.language)) - return false; - if (multiPart == null) { - if (other.multiPart != null) - return false; - } else if (!multiPart.equals(other.multiPart)) - return false; - if (source == null) { - if (other.source != null) - return false; - } else if (!source.equals(other.source)) - return false; - if (workAuthor == null) { - if (other.workAuthor != null) - return false; - } else if (!workAuthor.equals(other.workAuthor)) - return false; - if (workTitle == null) { - if (other.workTitle != null) - return false; - } else if (!workTitle.equals(other.workTitle)) - return false; - return true; - } - - @Override - public String toString() { - return "UploadForm [multiPart=" + multiPart + ", workTitle=" - + workTitle + ", workAuthor=" + workAuthor + ", source=" - + source + ", language=" + language + ", encoding=" + encoding - + "]"; - } - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/model/RegistrationForm.java b/src/main/java/de/uni_koeln/spinfo/upcase/model/form/RegistrationForm.java similarity index 98% rename from src/main/java/de/uni_koeln/spinfo/upcase/model/RegistrationForm.java rename to src/main/java/de/uni_koeln/spinfo/upcase/model/form/RegistrationForm.java index 87d6734..23c0f01 100644 --- a/src/main/java/de/uni_koeln/spinfo/upcase/model/RegistrationForm.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/model/form/RegistrationForm.java @@ -1,4 +1,4 @@ -package de.uni_koeln.spinfo.upcase.model; +package de.uni_koeln.spinfo.upcase.model.form; public class RegistrationForm { diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/model/form/UploadForm.java b/src/main/java/de/uni_koeln/spinfo/upcase/model/form/UploadForm.java new file mode 100644 index 0000000..e169a6c --- /dev/null +++ b/src/main/java/de/uni_koeln/spinfo/upcase/model/form/UploadForm.java @@ -0,0 +1,89 @@ +package de.uni_koeln.spinfo.upcase.model.form; + +import org.springframework.web.multipart.MultipartFile; + +public class UploadForm { + + private MultipartFile multiPart; + private String collectionName; + private String description; + + public UploadForm() { + super(); + } + + public UploadForm(MultipartFile multiPart, String collectionName) { + super(); + this.multiPart = multiPart; + this.collectionName = collectionName; + } + + public UploadForm(MultipartFile multiPart, String collectionName, String description) { + super(); + this.multiPart = multiPart; + this.collectionName = collectionName; + this.description = description; + } + + public MultipartFile getMultiPart() { + return multiPart; + } + + public void setMultiPart(MultipartFile multiPart) { + this.multiPart = multiPart; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getCollectionName() { + return collectionName; + } + + public void setCollectionName(String collectionName) { + this.collectionName = collectionName; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((collectionName == null) ? 0 : collectionName.hashCode()); + result = prime * result + ((description == null) ? 0 : description.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + UploadForm other = (UploadForm) obj; + if (collectionName == null) { + if (other.collectionName != null) + return false; + } else if (!collectionName.equals(other.collectionName)) + return false; + if (description == null) { + if (other.description != null) + return false; + } else if (!description.equals(other.description)) + return false; + return true; + } + + @Override + public String toString() { + return "UploadForm [collectionName=" + collectionName + ", description=" + description + "]"; + } + + +} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/model/validator/RegistrationFormValidator.java b/src/main/java/de/uni_koeln/spinfo/upcase/model/validator/RegistrationFormValidator.java index 83cd969..6e9de07 100644 --- a/src/main/java/de/uni_koeln/spinfo/upcase/model/validator/RegistrationFormValidator.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/model/validator/RegistrationFormValidator.java @@ -8,7 +8,7 @@ import org.springframework.validation.ValidationUtils; import org.springframework.validation.Validator; -import de.uni_koeln.spinfo.upcase.model.RegistrationForm; +import de.uni_koeln.spinfo.upcase.model.form.RegistrationForm; @Service public class RegistrationFormValidator implements Validator { diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/model/validator/UploadFormValidator.java b/src/main/java/de/uni_koeln/spinfo/upcase/model/validator/UploadFormValidator.java new file mode 100644 index 0000000..ab8bd2a --- /dev/null +++ b/src/main/java/de/uni_koeln/spinfo/upcase/model/validator/UploadFormValidator.java @@ -0,0 +1,33 @@ +package de.uni_koeln.spinfo.upcase.model.validator; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.validation.Errors; +import org.springframework.validation.ValidationUtils; +import org.springframework.validation.Validator; + +import de.uni_koeln.spinfo.upcase.model.form.UploadForm; + +public class UploadFormValidator implements Validator { + + Logger logger = LoggerFactory.getLogger(getClass()); + + @Override + public boolean supports(Class clazz) { + return UploadForm.class.equals(clazz); + } + + @Override + public void validate(Object target, Errors errors) { + UploadForm uploadForm = (UploadForm) target; + logger.info(uploadForm.toString()); + + if(uploadForm.getMultiPart().isEmpty()) { + errors.rejectValue("multiPart", "NotBlank.uploadForm.multiPart"); + } + + ValidationUtils.rejectIfEmptyOrWhitespace(errors, "collectionName", "NotBlank.uploadForm.collectionName"); +// ValidationUtils.rejectIfEmptyOrWhitespace(errors, "multiPart", "NotBlank.uploadForm.multiPart"); + } + +} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/PoS.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/PoS.java deleted file mode 100755 index f717ea8..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/PoS.java +++ /dev/null @@ -1,27 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.data; - -import de.uni_koeln.spinfo.upcase.mongodb.data.core.AbstractDocument; - -public class PoS extends AbstractDocument implements Comparable { - - private String posTag; - - public String getPosTag() { - return posTag; - } - - public void setPosTag(final String posTag) { - this.posTag = posTag; - } - - @Override - public String toString() { - return "PoS [posTag=" + posTag + ", getDate()=" + getDate() + ", getUserId()=" + getUserId() + "]"; - } - - @Override - public int compareTo(PoS o) { - return o.getDate().compareTo(this.getDate()); - } - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/Rectangle.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/Rectangle.java deleted file mode 100755 index f3e7860..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/Rectangle.java +++ /dev/null @@ -1,61 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.data; - -import java.io.Serializable; - -public class Rectangle implements Serializable { - - private static final long serialVersionUID = -431265242483478474L; - private int x; - private int y; - private int width; - private int height; - - public Rectangle(int x, int y, int width, int height) { - super(); - this.x = x; - this.y = y; - this.width = width; - this.height = height; - } - - public int getX() { - return x; - } - - public void setX(int x) { - this.x = x; - } - - public int getY() { - return y; - } - - public void setY(int y) { - this.y = y; - } - - public int getWidth() { - return width; - } - - public void setWidth(int width) { - this.width = width; - } - - public int getHeight() { - return height; - } - - public void setHeight(int height) { - this.height = height; - } - - @Override - public String toString() { - return "Rectangle [x=" + x + ", y=" + y + ", width=" + width - + ", height=" + height + "]"; - } - - - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/Version.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/Version.java deleted file mode 100755 index 025a3db..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/Version.java +++ /dev/null @@ -1,27 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.data; - -import java.io.Serializable; - -import de.uni_koeln.spinfo.upcase.mongodb.data.core.AbstractDocument; - -public class Version extends AbstractDocument implements Comparable, Serializable { - - private static final long serialVersionUID = -3750458969837772393L; - - // THE TOKEN - private String version; - - public String getValue() { - return version; - } - - public void setValue(final String version) { - this.version = version; - } - - @Override - public int compareTo(Version o) { - return o.getDate().compareTo(this.getDate()); - } - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/core/AbstractDocument.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/core/AbstractDocument.java deleted file mode 100755 index 7907d25..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/core/AbstractDocument.java +++ /dev/null @@ -1,64 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.data.core; - -import java.util.Date; - -import org.springframework.data.annotation.Id; - -public abstract class AbstractDocument { - - @Id - private String id; - - private Date date; - private String userId; - - public Date getDate() { - return date; - } - - public void setDate(Date date) { - this.date = date; - } - - public String getUserId() { - return userId; - } - - public void setUserId(String userId) { - this.userId = userId; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - AbstractDocument other = (AbstractDocument) obj; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - return true; - } - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/core/RangeDocument.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/core/RangeDocument.java deleted file mode 100755 index 7561d9c..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/core/RangeDocument.java +++ /dev/null @@ -1,27 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.data.core; - - - -public abstract class RangeDocument extends AbstractDocument { - - private int start; - private int end; - - public int getStart() { - return start; - } - - public void setStart(int start) { - this.start = start; - } - - public int getEnd() { - return end; - } - - public void setEnd(int end) { - this.end = end; - } - - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Chapter.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Chapter.java deleted file mode 100755 index c93d3a8..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Chapter.java +++ /dev/null @@ -1,66 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.data.document; - -import java.io.Serializable; - -import org.springframework.data.annotation.PersistenceConstructor; -import org.springframework.data.mongodb.core.mapping.Document; - -import de.uni_koeln.spinfo.upcase.mongodb.data.core.RangeDocument; - -@Document(collection = "chapters") -public class Chapter extends RangeDocument implements Serializable { - - private static final long serialVersionUID = 966219871511162636L; - - private String title; - private String volumeId; - private String volumeTitle; - private int pageNumber; - - @PersistenceConstructor - public Chapter(final String title, int start, int end, final String userId) { - super(); - this.title = title; - setStart(start); - setEnd(end); - setUserId(userId); - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getVolumeId() { - return volumeId; - } - - public void setVolumeId(String volumeId) { - this.volumeId = volumeId; - } - - @Override - public String toString() { - return "Chapter {title: " + title + "}"; - } - - public void setPageNumber(int pageNumber) { - this.pageNumber = pageNumber; - } - - public int getPageNumber() { - return pageNumber; - } - - public String getVolumeTitle() { - return volumeTitle; - } - - public void setVolumeTitle(String volumeTitle) { - this.volumeTitle = volumeTitle; - } - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Language.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Language.java deleted file mode 100755 index 5589248..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Language.java +++ /dev/null @@ -1,49 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.data.document; - -import java.io.Serializable; - -import org.springframework.data.annotation.PersistenceConstructor; -import org.springframework.data.mongodb.core.mapping.Document; - -import de.uni_koeln.spinfo.upcase.mongodb.data.core.RangeDocument; - -@Document(collection = "languages") -public class Language extends RangeDocument implements Serializable { - - private static final long serialVersionUID = -2899898943742978114L; - - private String title; - private String volumeId; - - @PersistenceConstructor - public Language(final String title, int start, int end, final String userId) { - super(); - this.title = title; - setStart(start); - setEnd(end); - setUserId(userId); - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getVolumeId() { - return volumeId; - } - - public void setVolumeId(String volumeId) { - this.volumeId = volumeId; - } - - - @Override - public String toString() { - return "Language {title: " + title + ", volumeId: " + volumeId + "}"; - } - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Page.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Page.java deleted file mode 100755 index 26f2db0..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Page.java +++ /dev/null @@ -1,98 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.data.document; - -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - -import org.springframework.data.annotation.PersistenceConstructor; -import org.springframework.data.mongodb.core.mapping.Document; - -import de.uni_koeln.spinfo.upcase.mongodb.data.core.RangeDocument; - -@Document(collection = "pages") -public class Page extends RangeDocument implements Comparable, - Serializable { - - private static final long serialVersionUID = -8489134538582298484L; - private String url; - private String printedPageNuber; - private String volumeId; - private List chapterIds = new ArrayList<>(); - private List languageIds = new ArrayList<>(); - private List words = new ArrayList<>(); - - @PersistenceConstructor - public Page(final String url, int start, int end, final String userId) { - super(); - this.url = url; - setStart(start); - setEnd(end); - setUserId(userId); - } - - public String getPrintedPageNuber() { - return printedPageNuber; - } - - public void setPrintedPageNuber(final String printedPageNuber) { - this.printedPageNuber = printedPageNuber; - } - - public String getUrl() { - return url; - } - - public void setUrl(final String url) { - this.url = url; - } - - public List getChapterIds() { - return chapterIds; - } - - public void setChapterIds(List chapterIds) { - this.chapterIds = chapterIds; - } - - public boolean setChapterId(final String chapterId) { - return this.chapterIds.add(chapterId); - } - - public String getVolumeId() { - return volumeId; - } - - public void setVolumeId(String volumeId) { - this.volumeId = volumeId; - } - - public boolean setLanguageId(final String languageId) { - return languageIds.add(languageId); - } - - public List getLanguageIds() { - return languageIds; - } - - public void setLanguageIds(List languageIds) { - this.languageIds = languageIds; - } - - public List getWords() { - return words; - } - - public void setWords(List words) { - this.words = words; - } - - @Override - public int compareTo(Page o) { - return getUrl().compareToIgnoreCase(o.getUrl()); - } - - @Override - public String toString() { - return "Page {url: " + url + "}"; - } -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Token.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Token.java deleted file mode 100755 index 0df2390..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Token.java +++ /dev/null @@ -1,183 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.data.document; - -import java.io.Serializable; -import java.util.Collections; -import java.util.List; - -import org.springframework.data.annotation.Id; -import org.springframework.data.annotation.PersistenceConstructor; -import org.springframework.data.mongodb.core.index.IndexDirection; -import org.springframework.data.mongodb.core.index.Indexed; -import org.springframework.data.mongodb.core.mapping.Document; - -import de.uni_koeln.spinfo.upcase.mongodb.data.PoS; -import de.uni_koeln.spinfo.upcase.mongodb.data.Rectangle; -import de.uni_koeln.spinfo.upcase.mongodb.data.Version; - -@Document(collection = "tokens") -public class Token implements Serializable, Comparable { - - - private static final long serialVersionUID = 5528660577564011116L; - - @Id - private String id; - - @Indexed(unique=true, direction=IndexDirection.ASCENDING) - private int index; - - private String pageId; - private String chapterId; - private String volumeId; - private String languageId; - private List versions; - private List posList; - private Rectangle rectangle; - private List taggerPosOptions; - - - @PersistenceConstructor - public Token(int index, List versions, List posList, Rectangle rectangle) { - super(); - this.index = index; - this.versions = versions; - this.posList = posList; - this.rectangle = rectangle; - } - - public List getPosList() { - return posList; - } - - public void setPosList(List posList) { - this.posList = posList; - } - - public List getTaggerPosOptions() { - return taggerPosOptions; - } - - public void setTaggerPosOptions(List taggerPosOptions) { - this.taggerPosOptions = taggerPosOptions; - } - - public int getIndex() { - return index; - } - - public void setIndex(int index) { - this.index = index; - } - - public List getVersions() { - Collections.sort(versions); - return versions; - } - - public void setVersions(List versions) { - this.versions = versions; - } - - public Rectangle getRectangle() { - return rectangle; - } - - public void setRectangle(Rectangle rectangle) { - this.rectangle = rectangle; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getPageId() { - return pageId; - } - - public void setPageId(String pageId) { - this.pageId = pageId; - } - - public String getChapterId() { - return chapterId; - } - - public void setChapterId(String chapterId) { - this.chapterId = chapterId; - } - - public String getVolumeId() { - return volumeId; - } - - public void setVolumeId(String volumeId) { - this.volumeId = volumeId; - } - - public String getLanguageId() { - return languageId; - } - - public void setLanguageId(String languageId) { - this.languageId = languageId; - } - - - @Override - public String toString() { - return "Token [id=" + id + ", index=" + index + ", pageId=" + pageId - + ", chapterId=" + chapterId + ", volumeId=" + volumeId - + ", languageId=" + languageId + ", versions=" + versions - + ", posList=" + posList + ", rectangle=" + rectangle - + ", taggerPosOptions=" + taggerPosOptions + "]"; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + index; - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Token other = (Token) obj; - if (index != other.index) - return false; - return true; - } - - public Version getCurrentVersion() { - List tmp = getVersions(); - Collections.sort(tmp); // SORTED BY DATE - return tmp.get(0); - } - - public PoS getCurrentPos() { - List posList = getPosList(); - if(posList.size() > 0) { - Collections.sort(posList); // SORTED BY DATE - return posList.get(0); - } - PoS poS = new PoS(); - poS.setPosTag("not set"); - return poS; - } - - @Override - public int compareTo(Token o) { - return Integer.valueOf(this.getIndex()).compareTo(Integer.valueOf(o.getIndex())); - } - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/UpcaseUser.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/UpcaseUser.java deleted file mode 100644 index 2a9a3dd..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/UpcaseUser.java +++ /dev/null @@ -1,203 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.data.document; - -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -import org.springframework.data.annotation.Id; -import org.springframework.data.mongodb.core.mapping.Document; -import org.springframework.security.crypto.bcrypt.BCrypt; - -import de.uni_koeln.spinfo.upcase.model.RegistrationForm; -import de.uni_koeln.spinfo.upcase.model.Role; - -@Document(collection = "users") -public class UpcaseUser { - - @Id private String id; - - private Date creationDate; - private Date lastLogin; - private String email; - private String institution; - private String firstName; - private String lastName; - private String hash; - private List roles; - private boolean enabled; - - - public UpcaseUser() { - } - - public UpcaseUser(final RegistrationForm registrationForm) { - super(); - this.email = registrationForm.getEmail(); - this.creationDate = new Date(); - this.lastLogin = new Date(); - this.firstName = registrationForm.getFirstName(); - this.lastName = registrationForm.getLastName(); - this.institution = registrationForm.getInstitution(); - this.roles = new ArrayList<>(); - setRole(Role.TRUSTED.getRoleId()); - this.hash = BCrypt.hashpw(registrationForm.getPassword(), BCrypt.gensalt()); - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public Date getCreationDate() { - return creationDate; - } - - public void setCreationDate(Date creationDate) { - this.creationDate = creationDate; - } - - public Date getLastLogin() { - return lastLogin; - } - - public void setLastLogin(Date lastLogin) { - this.lastLogin = lastLogin; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getInstitution() { - return institution; - } - - public void setInstitution(String institution) { - this.institution = institution; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getHash() { - return hash; - } - - public void setHash(String hash) { - this.hash = hash; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((creationDate == null) ? 0 : creationDate.hashCode()); - result = prime * result + ((email == null) ? 0 : email.hashCode()); - result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); - result = prime * result + ((hash == null) ? 0 : hash.hashCode()); - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((institution == null) ? 0 : institution.hashCode()); - result = prime * result + ((lastLogin == null) ? 0 : lastLogin.hashCode()); - result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - UpcaseUser other = (UpcaseUser) obj; - if (creationDate == null) { - if (other.creationDate != null) - return false; - } else if (!creationDate.equals(other.creationDate)) - return false; - if (email == null) { - if (other.email != null) - return false; - } else if (!email.equals(other.email)) - return false; - if (firstName == null) { - if (other.firstName != null) - return false; - } else if (!firstName.equals(other.firstName)) - return false; - if (hash == null) { - if (other.hash != null) - return false; - } else if (!hash.equals(other.hash)) - return false; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - if (institution == null) { - if (other.institution != null) - return false; - } else if (!institution.equals(other.institution)) - return false; - if (lastLogin == null) { - if (other.lastLogin != null) - return false; - } else if (!lastLogin.equals(other.lastLogin)) - return false; - if (lastName == null) { - if (other.lastName != null) - return false; - } else if (!lastName.equals(other.lastName)) - return false; - return true; - } - - @Override - public String toString() { - return "UpcaseUser [role=" + getRoles().toString() + ", email=" + email + ", firstName=" + firstName - + ", lastName=" + lastName + "]"; - } - - public List getRoles() { - return roles; - } - - public boolean setRole(final String role) { - return this.roles.add(role); - } - - public boolean removeRole(final String role) { - return this.roles.remove(role); - } - - public boolean isEnabled() { - return enabled; - } - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Volume.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Volume.java deleted file mode 100755 index 74188e1..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Volume.java +++ /dev/null @@ -1,47 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.data.document; - -import org.springframework.data.annotation.PersistenceConstructor; -import org.springframework.data.mongodb.core.mapping.Document; - -import de.uni_koeln.spinfo.upcase.mongodb.data.core.RangeDocument; - -@Document(collection = "volumes") -public class Volume extends RangeDocument { - - private String title; - private int chapterNumber; - - public Volume() { - super(); - } - - @PersistenceConstructor - public Volume(final String title, int start, int end, final String userId) { - super(); - this.title = title; - setStart(start); - setEnd(end); - setUserId(userId); - } - - public String getTitle() { - return title; - } - - public void setTitle(final String title) { - this.title = title; - } - - @Override - public String toString() { - return "Volume {title: " + title + ", _id: " + getId() + "}"; - } - - public void setChapterNumber(int chapterNumber) { - this.chapterNumber = chapterNumber; - } - - public int getChapterNumber() { - return chapterNumber; - } -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Word.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Word.java deleted file mode 100755 index 435d79f..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/Word.java +++ /dev/null @@ -1,180 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.data.document; - -import java.io.Serializable; -import java.util.Collections; -import java.util.List; - -import org.springframework.data.annotation.Id; -import org.springframework.data.annotation.PersistenceConstructor; -import org.springframework.data.mongodb.core.mapping.Document; - -import de.uni_koeln.spinfo.upcase.mongodb.data.PoS; -import de.uni_koeln.spinfo.upcase.mongodb.data.Rectangle; -import de.uni_koeln.spinfo.upcase.mongodb.data.Version; - -@Document(collection = "words") -public class Word implements Serializable, Comparable { - - private static final long serialVersionUID = 5972674115082493109L; - - @Id - private String id; - - private int index; - private List versions; - private List posList; - private Rectangle rectangle; - - private String pageId; - private String chapterId; - private String volumeId; - private String languageId; - private List taggerPosOptions; - - - - @PersistenceConstructor - public Word(int index, List versions, List posList, Rectangle rectangle) { - super(); - this.index = index; - this.versions = versions; - this.posList = posList; - this.rectangle = rectangle; - } - - public List getPosList() { - return posList; - } - - public void setPosList(List posList) { - this.posList = posList; - } - - public List getTaggerPosOptions() { - return taggerPosOptions; - } - - public void setTaggerPosOptions(List taggerPosOptions) { - this.taggerPosOptions = taggerPosOptions; - } - - public int getIndex() { - return index; - } - - public void setIndex(int index) { - this.index = index; - } - - public List getVersions() { - Collections.sort(versions); - return versions; - } - - public void setVersions(List versions) { - this.versions = versions; - } - - public Rectangle getRectangle() { - return rectangle; - } - - public void setRectangle(Rectangle rectangle) { - this.rectangle = rectangle; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - public String getPageId() { - return pageId; - } - - public void setPageId(String pageId) { - this.pageId = pageId; - } - - public String getChapterId() { - return chapterId; - } - - public void setChapterId(String chapterId) { - this.chapterId = chapterId; - } - - public String getVolumeId() { - return volumeId; - } - - public void setVolumeId(String volumeId) { - this.volumeId = volumeId; - } - - public String getLanguageId() { - return languageId; - } - - public void setLanguageId(String languageId) { - this.languageId = languageId; - } - - - @Override - public String toString() { - return "Word [id=" + id + ", index=" + index + ", pageId=" + pageId - + ", chapterId=" + chapterId + ", volumeId=" + volumeId - + ", languageId=" + languageId + ", versions=" + versions - + ", posList=" + posList + ", rectangle=" + rectangle - + ", taggerPosOptions=" + taggerPosOptions + "]"; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + index; - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Word other = (Word) obj; - if (index != other.index) - return false; - return true; - } - - public Version getCurrentVersion() { - List tmp = getVersions(); - Collections.sort(tmp); // SORTED BY DATE - return tmp.get(0); - } - - public PoS getCurrentPos() { - List posList = getPosList(); - if(posList.size() > 0) { - Collections.sort(posList); // SORTED BY DATE - return posList.get(0); - } - PoS poS = new PoS(); - poS.setPosTag("not set"); - return poS; - } - - @Override - public int compareTo(Word o) { - return Integer.valueOf(this.getIndex()).compareTo(Integer.valueOf(o.getIndex())); - } - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Annotation.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Annotation.java index 260c5fb..13608a5 100644 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Annotation.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Annotation.java @@ -3,10 +3,14 @@ import java.util.Date; import org.springframework.data.annotation.Id; +import org.springframework.data.annotation.Transient; import org.springframework.data.mongodb.core.mapping.Document; -@Document(collection = "re_annotations") +@Document(collection = "ref_annotations") public class Annotation { + + @Transient + public static final String COLLECTION = "ref_annotations"; @Id private String id; diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Box.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Box.java index 0394d6e..e137f66 100644 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Box.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Box.java @@ -1,13 +1,7 @@ package de.uni_koeln.spinfo.upcase.mongodb.data.document.future; -import org.springframework.data.annotation.Id; -import org.springframework.data.mongodb.core.mapping.Document; - -@Document(collection = "re_boxes") public class Box { - - @Id private String id; - + private int x1; private int x2; private int y1; @@ -21,14 +15,6 @@ public Box(int x1, int x2, int y1, int y2) { this.y2 = y2; } - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - public int getX1() { return x1; } @@ -65,7 +51,6 @@ public void setY2(int y2) { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((id == null) ? 0 : id.hashCode()); result = prime * result + x1; result = prime * result + x2; result = prime * result + y1; @@ -82,11 +67,6 @@ public boolean equals(Object obj) { if (getClass() != obj.getClass()) return false; Box other = (Box) obj; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; if (x1 != other.x1) return false; if (x2 != other.x2) @@ -100,7 +80,7 @@ public boolean equals(Object obj) { @Override public String toString() { - return "Box [id=" + id + ", x1=" + x1 + ", x2=" + x2 + ", y1=" + y1 + ", y2=" + y2 + "]"; + return "Box [x1=" + x1 + ", x2=" + x2 + ", y1=" + y1 + ", y2=" + y2 + "]"; } } diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Chapter.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Chapter.java index 50f1e53..36dd09b 100644 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Chapter.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Chapter.java @@ -1,35 +1,39 @@ package de.uni_koeln.spinfo.upcase.mongodb.data.document.future; -import java.util.ArrayList; import java.util.Date; -import java.util.List; +import java.util.HashSet; +import java.util.Set; import org.springframework.data.annotation.Id; -import org.springframework.data.mongodb.core.mapping.DBRef; +import org.springframework.data.annotation.Transient; import org.springframework.data.mongodb.core.mapping.Document; -@Document(collection = "re_chapters") +@Document(collection = "ref_chapters") public class Chapter { + @Transient + public static final String COLLECTION = "ref_chapters"; + @Id private String id; private String title; private Date lastModified; - @DBRef private List pages; +// @DBRef private List pages; + private Set pages; public Chapter(String title) { super(); this.title = title; this.lastModified = new Date(); - this.pages = new ArrayList<>(); + this.pages = new HashSet<>(); } - public Chapter(String title, List pages) { + public Chapter(String title, Set pageIds) { super(); this.title = title; this.lastModified = new Date(); - this.pages = pages; + this.pages = pageIds; } public String getTitle() { @@ -56,12 +60,12 @@ public void setLastModified(Date lastModified) { this.lastModified = lastModified; } - public List getPages() { + public Set getPages() { return pages; } - public void setPages(List pages) { - this.pages = pages; + public void setPages(Set pageIds) { + this.pages = pageIds; } @Override diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Collection.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Collection.java index a13b623..e4f15da 100644 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Collection.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Collection.java @@ -1,16 +1,19 @@ package de.uni_koeln.spinfo.upcase.mongodb.data.document.future; -import java.util.ArrayList; import java.util.Date; -import java.util.List; +import java.util.HashSet; +import java.util.Set; import org.springframework.data.annotation.Id; -import org.springframework.data.mongodb.core.mapping.DBRef; +import org.springframework.data.annotation.Transient; import org.springframework.data.mongodb.core.mapping.Document; -@Document(collection = "re_collections") +@Document(collection = "ref_collections") public class Collection { + @Transient + public static final String COLLECTION = "ref_collections"; + @Id private String id; private Date creationDate; @@ -18,37 +21,50 @@ public class Collection { private boolean contributable; private String title; - @DBRef private UpcaseUser owner; - @DBRef private List contributers; +// @DBRef private UpcaseUser owner; + private String owner; + +// @DBRef private List contributers; + private Set contributers; + +// @DBRef private List pages; + private Set pages; - @DBRef private List pages; - @DBRef private List chapters; - @DBRef private List volumes; +// @DBRef private List chapters; +// @DBRef private List volumes; + public Collection(final String title) { + this.title = title; + this.creationDate = new Date(); + this.lastModified = new Date(); + this.contributable = false; + this.pages = new HashSet<>(); + this.contributers = new HashSet<>(); + } public Collection(String title, UpcaseUser owner) { this.title = title; this.creationDate = new Date(); this.lastModified = new Date(); this.contributable = false; - this.owner = owner; - this.pages = new ArrayList<>(); - this.contributers = new ArrayList<>(); - this.chapters = new ArrayList<>(); - this.volumes = new ArrayList<>(); + this.owner = owner.getId(); + this.pages = new HashSet<>(); + this.contributers = new HashSet<>(); +// this.chapters = new ArrayList<>(); +// this.volumes = new ArrayList<>(); } - public Collection(String title, UpcaseUser owner, List pages) { + public Collection(String title, UpcaseUser owner, Set pageIds) { super(); this.title = title; this.creationDate = new Date(); this.lastModified = new Date(); this.contributable = false; - this.owner = owner; - this.pages = pages; - this.contributers = new ArrayList<>(); - this.chapters = new ArrayList<>(); - this.volumes = new ArrayList<>(); + this.owner = owner.getId(); + this.pages = pageIds; + this.contributers = new HashSet<>(); +// this.chapters = new ArrayList<>(); +// this.volumes = new ArrayList<>(); } public String getTitle() { @@ -91,49 +107,53 @@ public void setContributable(boolean contributable) { this.contributable = contributable; } - public UpcaseUser getOwner() { + public String getOwnerId() { return owner; } public void setOwner(UpcaseUser owner) { - this.owner = owner; + this.owner = owner.getId(); + } + + public void setOwner(final String ownerId) { + this.owner = ownerId; } - public List getContributers() { + public Set getContributers() { return contributers; } - public void setContributers(List contributers) { + public void setContributers(Set contributers) { this.contributers = contributers; } - public void setContributer(UpcaseUser contributor) { - this.contributers.add(contributor); + public void setContributer(final String contributorId) { + this.contributers.add(contributorId); } - public List getPages() { + public Set getPages() { return pages; } - public void setPages(List pages) { + public void setPages(Set pages) { this.pages = pages; } - public List getChapters() { - return chapters; - } - - public void setChapters(List chapters) { - this.chapters = chapters; - } - - public List getVolumes() { - return volumes; - } - - public void setVolumes(List volumes) { - this.volumes = volumes; - } +// public List getChapters() { +// return chapters; +// } +// +// public void setChapters(List chapters) { +// this.chapters = chapters; +// } +// +// public List getVolumes() { +// return volumes; +// } +// +// public void setVolumes(List volumes) { +// this.volumes = volumes; +// } @Override public int hashCode() { diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/ContributionRequest.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/ContributionRequest.java index b224d46..e61193b 100644 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/ContributionRequest.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/ContributionRequest.java @@ -3,26 +3,34 @@ import java.util.Date; import org.springframework.data.annotation.Id; -import org.springframework.data.mongodb.core.mapping.DBRef; +import org.springframework.data.annotation.Transient; import org.springframework.data.mongodb.core.mapping.Document; @Document(collection = "contribution_requests") public class ContributionRequest { + @Transient + public static final String COLLECTION = "contribution_requests"; + @Id private String id; private Date creationDate; - @DBRef private Collection collection; - @DBRef private UpcaseUser requestor; - @DBRef private UpcaseUser owner; +// @DBRef private Collection collection; + private String collection; + +// @DBRef private UpcaseUser requestor; + private String requestor; + +// @DBRef private UpcaseUser owner; + private String owner; - public ContributionRequest(Collection collection, UpcaseUser requestor) { + public ContributionRequest(Collection collection, String requestorId) { super(); this.creationDate = new Date(); - this.collection = collection; - this.owner = collection.getOwner(); - this.requestor = requestor; + this.collection = collection.getId(); + this.owner = collection.getOwnerId(); + this.requestor = requestorId; } @@ -46,31 +54,36 @@ public void setCreationDate(Date creationDate) { } - public Collection getCollection() { + public String getCollection() { return collection; } - public void setCollection(Collection collection) { - this.collection = collection; + public void setCollection(final String collectionId) { + this.collection = collectionId; } - public UpcaseUser getRequestor() { + public String getRequestor() { return requestor; } - public void setRequestor(UpcaseUser requestor) { - this.requestor = requestor; + public void setRequestor(final String requestorId) { + this.requestor = requestorId; } - public UpcaseUser getOwner() { + public String getOwner() { return owner; } public void setOwner(UpcaseUser owner) { - this.owner = owner; + this.owner = owner.getId(); + } + + + public void setOwner(String ownerId) { + this.owner = ownerId; } diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Page.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Page.java index 7d52e9d..88dd63d 100644 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Page.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Page.java @@ -5,12 +5,15 @@ import java.util.List; import org.springframework.data.annotation.Id; -import org.springframework.data.mongodb.core.mapping.DBRef; +import org.springframework.data.annotation.Transient; import org.springframework.data.mongodb.core.mapping.Document; -@Document(collection = "re_pages") +@Document(collection = "ref_pages") public class Page { + @Transient + public static final String COLLECTION = "ref_pages"; + @Id private String id; private Date lastModified; @@ -18,9 +21,12 @@ public class Page { private int pageNumber; private int physicalPageNumber; private List words; + private String collection; + private String user; + +// @DBRef private Chapter chapter; +// @DBRef private Volume volume; - @DBRef private Chapter chapter; - @DBRef private Volume volume; public Page(String imageUrl, int pageNumber, int physicalPageNumber) { super(); @@ -31,12 +37,25 @@ public Page(String imageUrl, int pageNumber, int physicalPageNumber) { this.words = new ArrayList<>(); } - public Page(String imageUrl, int pageNumber, int physicalPageNumber, List words) { + public Page(String imageUrl, int pageNumber, int physicalPageNumber, String collection, String user) { super(); this.lastModified = new Date(); this.imageUrl = imageUrl; this.pageNumber = pageNumber; this.physicalPageNumber = physicalPageNumber; + this.collection = collection; + this.user = user; + this.words = new ArrayList<>(); + } + + public Page(String imageUrl, int pageNumber, int physicalPageNumber, String collection, String user, List words) { + super(); + this.lastModified = new Date(); + this.imageUrl = imageUrl; + this.pageNumber = pageNumber; + this.physicalPageNumber = physicalPageNumber; + this.collection = collection; + this.user = user; this.words = words; } @@ -49,6 +68,30 @@ public String getId() { public void setId(String id) { this.id = id; } + + /** + * + * @return userId + */ + public String getUser() { + return user; + } + + public void setUser(String user) { + this.user = user; + } + + /** + * + * @return collectionID + */ + public String getCollection() { + return collection; + } + + public void setCollection(String collection) { + this.collection = collection; + } public Date getLastModified() { @@ -101,24 +144,24 @@ public void setWords(List words) { } - public Chapter getChapter() { - return chapter; - } - - - public void setChapter(Chapter chapter) { - this.chapter = chapter; - } - - - public Volume getVolume() { - return volume; - } - - - public void setVolume(Volume volume) { - this.volume = volume; - } +// public Chapter getChapter() { +// return chapter; +// } +// +// +// public void setChapter(Chapter chapter) { +// this.chapter = chapter; +// } +// +// +// public Volume getVolume() { +// return volume; +// } +// +// +// public void setVolume(Volume volume) { +// this.volume = volume; +// } @Override @@ -168,10 +211,8 @@ public boolean equals(Object obj) { @Override public String toString() { - return "Page [id=" + id + ", lastModified=" + lastModified + ", imageUrl=" + imageUrl + ", pageNumber=" - + pageNumber + ", physicalPageNumber=" + physicalPageNumber + ", words=" + words + "]"; + return "Page [id=" + id + ", imageUrl=" + imageUrl + ", pageNumber=" + pageNumber + ", words=" + words + "]"; } - } diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/UpcaseUser.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/UpcaseUser.java index e17fb93..e6e3eef 100644 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/UpcaseUser.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/UpcaseUser.java @@ -1,36 +1,62 @@ package de.uni_koeln.spinfo.upcase.mongodb.data.document.future; +import java.io.Serializable; import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; import java.util.Date; +import java.util.HashSet; import java.util.List; +import java.util.Set; +import java.util.SortedSet; +import java.util.TreeSet; import org.springframework.data.annotation.Id; -import org.springframework.data.mongodb.core.mapping.DBRef; +import org.springframework.data.annotation.Transient; import org.springframework.data.mongodb.core.mapping.Document; -import org.springframework.security.crypto.bcrypt.BCrypt; +import org.springframework.security.core.GrantedAuthority; +import org.springframework.security.core.SpringSecurityCoreVersion; +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.util.Assert; -import de.uni_koeln.spinfo.upcase.model.RegistrationForm; -import de.uni_koeln.spinfo.upcase.model.Role; -import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.Collection; +import de.uni_koeln.spinfo.upcase.model.form.RegistrationForm; -@Document(collection = "re_users") -public class UpcaseUser { +@Document(collection = "ref_users") +public class UpcaseUser implements UserDetails { - @Id private String id; - + private static final long serialVersionUID = 7421580832939472903L; + + @Transient + public static final String COLLECTION = "ref_users"; + + @Id + private String id; private Date creationDate; private Date lastLogin; - private String email; + private String email; // username private String institution; private String firstName; private String lastName; - private String hash; - private List roles; + private String hash; // password private boolean enabled; - - @DBRef private List owns; - @DBRef private List contributes; - + + // @DBRef private List owns; + private Set owns; + + // @DBRef private List contributes; + private Set contributesTo; + + @Transient + private Set authorities; + @Transient + private boolean accountNonExpired; + @Transient + private boolean credentialsNonExpired; + @Transient + private boolean accountNonLocked; + + private Set roles; public UpcaseUser() { } @@ -43,9 +69,83 @@ public UpcaseUser(final RegistrationForm registrationForm) { this.firstName = registrationForm.getFirstName(); this.lastName = registrationForm.getLastName(); this.institution = registrationForm.getInstitution(); - this.roles = new ArrayList<>(); - setRole("ROLE_USER"); - this.hash = BCrypt.hashpw(registrationForm.getPassword(), BCrypt.gensalt()); + // this.hash = BCrypt.hashpw(registrationForm.getPassword(), + // BCrypt.gensalt()); + this.hash = registrationForm.getPassword(); + this.owns = new HashSet<>(); + this.contributesTo = new HashSet<>(); + List authorities = new ArrayList(); + this.enabled = true; + this.accountNonExpired = true; + this.credentialsNonExpired = true; + this.accountNonLocked = true; + authorities.add(new GrantedAuthority() { + private static final long serialVersionUID = 1L; + + @Override + public String getAuthority() { + return "ROLE_USER"; + } + }); + + roles = new HashSet<>(); + for (GrantedAuthority role : authorities) { + roles.add(role.getAuthority()); + } + + this.authorities = Collections.unmodifiableSet(sortAuthorities(authorities)); + } + + public UpcaseUser(final RegistrationForm registrationForm, boolean enabled, boolean accountNonExpired, + boolean credentialsNonExpired, boolean accountNonLocked, + Collection authorities) { + super(); + this.email = registrationForm.getEmail(); + this.creationDate = new Date(); + this.lastLogin = new Date(); + this.firstName = registrationForm.getFirstName(); + this.lastName = registrationForm.getLastName(); + this.institution = registrationForm.getInstitution(); + // this.hash = BCrypt.hashpw(registrationForm.getPassword(), + // BCrypt.gensalt()); + this.hash = registrationForm.getPassword(); + this.owns = new HashSet<>(); + this.contributesTo = new HashSet<>(); + this.enabled = enabled; + this.accountNonExpired = accountNonExpired; + this.credentialsNonExpired = credentialsNonExpired; + this.accountNonLocked = accountNonLocked; + + roles = new HashSet<>(); + for (GrantedAuthority role : authorities) { + roles.add(role.getAuthority()); + } + + this.authorities = Collections.unmodifiableSet(sortAuthorities(authorities)); + } + + public void addCollection(final String collectionId) { + this.owns.add(collectionId); + } + + public void removeCollection(final String collectionId) { + this.owns.remove(collectionId); + } + + public Set getCollections() { + return owns; + } + + public Set getContributions() { + return contributesTo; + } + + public void addContribution(final String collectionId) { + this.contributesTo.add(collectionId); + } + + public void removeContribution(final String collectionId) { + this.contributesTo.remove(collectionId); } public String getId() { @@ -114,95 +214,87 @@ public void setHash(String hash) { @Override public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((creationDate == null) ? 0 : creationDate.hashCode()); - result = prime * result + ((email == null) ? 0 : email.hashCode()); - result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); - result = prime * result + ((hash == null) ? 0 : hash.hashCode()); - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((institution == null) ? 0 : institution.hashCode()); - result = prime * result + ((lastLogin == null) ? 0 : lastLogin.hashCode()); - result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); - return result; + return email.hashCode(); } @Override public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - UpcaseUser other = (UpcaseUser) obj; - if (creationDate == null) { - if (other.creationDate != null) - return false; - } else if (!creationDate.equals(other.creationDate)) - return false; - if (email == null) { - if (other.email != null) - return false; - } else if (!email.equals(other.email)) - return false; - if (firstName == null) { - if (other.firstName != null) - return false; - } else if (!firstName.equals(other.firstName)) - return false; - if (hash == null) { - if (other.hash != null) - return false; - } else if (!hash.equals(other.hash)) - return false; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - if (institution == null) { - if (other.institution != null) - return false; - } else if (!institution.equals(other.institution)) - return false; - if (lastLogin == null) { - if (other.lastLogin != null) - return false; - } else if (!lastLogin.equals(other.lastLogin)) - return false; - if (lastName == null) { - if (other.lastName != null) - return false; - } else if (!lastName.equals(other.lastName)) - return false; - return true; + if (obj instanceof UpcaseUser) { + return email.equals(((UpcaseUser) obj).email); + } + return false; } @Override public String toString() { - return "UpcaseUser [role=" + getRoles().toString() + ", email=" + email + ", firstName=" + firstName + return "UpcaseUser [role=" + roles + ", email=" + email + ", firstName=" + firstName + ", lastName=" + lastName + "]"; } - public List getRoles() { - return roles; + public boolean isEnabled() { + return enabled; } - public boolean setRole(final String role) { - return this.roles.add(role); + public void setEnabled(boolean enabled) { + this.enabled = enabled; } - public boolean removeRole(final String role) { - return this.roles.remove(role); + @Override + public Collection getAuthorities() { + return authorities; } - public boolean isEnabled() { - return enabled; + @Override + public String getPassword() { + return hash; } - public void setEnabled(boolean enabled) { - this.enabled = enabled; + @Override + public String getUsername() { + return email; + } + + @Override + public boolean isAccountNonExpired() { + return accountNonExpired; + } + + @Override + public boolean isAccountNonLocked() { + return accountNonLocked; + } + + @Override + public boolean isCredentialsNonExpired() { + return credentialsNonExpired; + } + + private static SortedSet sortAuthorities(Collection authorities) { + Assert.notNull(authorities, "Cannot pass a null GrantedAuthority collection"); + SortedSet sortedAuthorities = new TreeSet(new AuthorityComparator()); + + for (GrantedAuthority grantedAuthority : authorities) { + Assert.notNull(grantedAuthority, "GrantedAuthority list cannot contain any null elements"); + sortedAuthorities.add(grantedAuthority); + } + + return sortedAuthorities; + } + + private static class AuthorityComparator implements Comparator, Serializable { + private static final long serialVersionUID = SpringSecurityCoreVersion.SERIAL_VERSION_UID; + + public int compare(GrantedAuthority g1, GrantedAuthority g2) { + if (g2.getAuthority() == null) { + return -1; + } + + if (g1.getAuthority() == null) { + return 1; + } + + return g1.getAuthority().compareTo(g2.getAuthority()); + } } } diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Word.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Word.java index 011d19b..7a4b1fd 100644 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Word.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/document/future/Word.java @@ -5,19 +5,22 @@ import java.util.List; import org.springframework.data.annotation.Id; -import org.springframework.data.mongodb.core.mapping.DBRef; +import org.springframework.data.annotation.Transient; import org.springframework.data.mongodb.core.mapping.Document; -@Document(collection = "re_words") +@Document(collection = "ref_words") public class Word { + @Transient + public static final String COLLECTION = "ref_words"; + @Id private String id; private String token; private Date lastModified; - @DBRef private List annotations; - @DBRef private Box box; + private List annotations; + private Box box; public Word(String token, Box box) { super(); @@ -106,8 +109,7 @@ public boolean equals(Object obj) { @Override public String toString() { - return "Word [id=" + id + ", token=" + token + ", lastModified=" + lastModified + ", annotations=" + annotations - + ", box=" + box + "]"; + return "Word [id=" + id + ", token=" + token + ", annotations=" + annotations + ", box=" + box + "]"; } diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/light/Letter.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/light/Letter.java deleted file mode 100755 index 58f4122..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/light/Letter.java +++ /dev/null @@ -1,78 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.data.light; - -public class Letter { - - /** - * The word id - */ - private String wordId; - - /** - * The words index - */ - private int wordIndex; - - /** - * The current word character - */ - private char character; - - /** - * The position of the current character within the page Range - */ - private int charPosInText; - - /** - * The position of the current character within the word - */ - private int charPosInWord; - - public Letter(String wordId, int wordIndex, char character, int charPosInWord, int charPosInText) { - this.wordId = wordId; - this.wordIndex = wordIndex; - this.character = character; - this.charPosInWord = charPosInWord; - this.charPosInText = charPosInText; - } - - public String getWordId() { - return wordId; - } - - public void setWordId(String wordId) { - this.wordId = wordId; - } - - public char getCharacter() { - return character; - } - - public void setCharacter(char character) { - this.character = character; - } - - public int getWordIndex() { - return wordIndex; - } - - public void setWordIndex(int wordIndex) { - this.wordIndex = wordIndex; - } - - public int getCharPosInText() { - return charPosInText; - } - - public void setCharPosInText(int charPosInText) { - this.charPosInText = charPosInText; - } - - public int getCharPosInWord() { - return charPosInWord; - } - - public void setCharPosInWord(int charPosInWord) { - this.charPosInWord = charPosInWord; - } - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/light/RectangleLight.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/light/RectangleLight.java deleted file mode 100755 index 9e390b6..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/data/light/RectangleLight.java +++ /dev/null @@ -1,107 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.data.light; - -import de.uni_koeln.spinfo.upcase.mongodb.data.Rectangle; - -public class RectangleLight { - - private int x; - private int y; - private int width; - private int height; - private String id; - - - public RectangleLight(final String id, Rectangle rectangle) { - this.id = id; - this.x = rectangle.getX(); - this.y = rectangle.getY(); - this.width = rectangle.getWidth(); - this.height = rectangle.getHeight(); - } - - public int getX() { - return x; - } - - public void setX(int x) { - this.x = x; - } - - public int getY() { - return y; - } - - public void setY(int y) { - this.y = y; - } - - public int getWidth() { - return width; - } - - public void setWidth(int width) { - this.width = width; - } - - public int getHeight() { - return height; - } - - public void setHeight(int height) { - this.height = height; - } - - public String getId() { - return id; - } - - public void setId(String id) { - this.id = id; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + height; - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + width; - result = prime * result + x; - result = prime * result + y; - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - RectangleLight other = (RectangleLight) obj; - if (height != other.height) - return false; - if (id == null) { - if (other.id != null) - return false; - } else if (!id.equals(other.id)) - return false; - if (width != other.width) - return false; - if (x != other.x) - return false; - if (y != other.y) - return false; - return true; - } - - @Override - public String toString() { - return "RectangleLight [x=" + x + ", y=" + y + ", width=" + width - + ", height=" + height + "]"; - } - - - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/ChapterRepository.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/ChapterRepository.java deleted file mode 100755 index fff8022..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/ChapterRepository.java +++ /dev/null @@ -1,19 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.repository; - -import java.util.List; - -import org.springframework.data.repository.CrudRepository; - -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Chapter; - -public interface ChapterRepository extends CrudRepository { - - public List findByTitle(String title); - - public List findByUserId(String userId); - - public List findByVolumeId(String volumeId); - - public List findByVolumeTitle(String volumeTitle); - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/LanguageRepository.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/LanguageRepository.java deleted file mode 100755 index 6d68b31..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/LanguageRepository.java +++ /dev/null @@ -1,17 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.repository; - -import java.util.List; - -import org.springframework.data.repository.CrudRepository; - -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Language; - -public interface LanguageRepository extends CrudRepository { - - public List findByUserId(String userId); - - public List findByTitle(String title); - - public List findByVolumeId(String volumeId); - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/PageRepository.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/PageRepository.java deleted file mode 100755 index c114a9c..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/PageRepository.java +++ /dev/null @@ -1,33 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.repository; - -import java.util.List; - -import org.springframework.data.repository.Repository; - -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Page; - -public interface PageRepository extends Repository { - - public Page findByUrl(String url); - - public List findByUserId(String userId); - - public List findByVolumeId(String volumeId); - - public List findByChapterIds(List chapterIds); - - public List findByLanguageIds(List LanguageIds); - - public List findAll(); - - public Page save(Page page); - - public String findOne(); - - public String findOne(String pageId); - - public Page findByPageId(String pageId); - - public List findByRange(int from, int to); - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/PageRepositoryImpl.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/PageRepositoryImpl.java deleted file mode 100755 index b505b9c..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/PageRepositoryImpl.java +++ /dev/null @@ -1,91 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.repository; - -import java.util.List; - -import javax.inject.Inject; - -import org.springframework.data.mongodb.core.MongoOperations; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; -import org.springframework.stereotype.Repository; - -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Page; - -@Repository -public class PageRepositoryImpl implements PageRepository { - - private MongoOperations operations; - - @Inject - public PageRepositoryImpl(MongoOperations operations) { - this.operations = operations; - } - - @Override - public Page findByUrl(String url) { - return operations.findOne(new Query(Criteria.where("url").is(url)), - Page.class); - } - - @Override - public List findByUserId(String userId) { - return operations.find(new Query(Criteria.where("userId").is(userId)), - Page.class); - } - - @Override - public List findByVolumeId(String volumeId) { - return operations.find(new Query(Criteria.where("volumeId") - .is(volumeId)), Page.class); - } - - @Override - public List findByChapterIds(List chapterIds) { - return operations.find( - new Query(Criteria.where("chapterIds").is(chapterIds)), - Page.class); - } - - @Override - public List findByLanguageIds(List LanguageIds) { - return operations.find( - new Query(Criteria.where("LanguageIds").is(LanguageIds)), - Page.class); - } - - @Override - public List findAll() { - return operations.find(new Query(), Page.class); - } - - @Override - public Page save(Page page) { - operations.save(page); - return page; - } - - @Override - public String findOne() { - return operations.findOne(new Query(), String.class, "pages"); - } - - @Override - public Page findByPageId(String pageId) { - return operations.findOne(new Query(Criteria.where("_id").is(pageId)), - Page.class); - } - - @Override - public String findOne(String pageId) { - return operations.findOne(new Query(Criteria.where("_id").is(pageId)), - String.class, "pages"); - } - - @Override - public List findByRange(int from, int to) { - List pages = operations.find(new Query(Criteria.where("start").gte(from) - .andOperator(Criteria.where("end").lte(to))), Page.class); - return pages; - } - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/TokenRepository.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/TokenRepository.java deleted file mode 100755 index bc1fe4c..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/TokenRepository.java +++ /dev/null @@ -1,21 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.repository; - -import java.util.List; - -import org.springframework.data.repository.CrudRepository; - -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Token; - -public interface TokenRepository extends CrudRepository { - - public List findByVolumeId(String volumeId); - - public List findByPageId(String pageId); - - public List findByChapterId(String chapterId); - - public List findByLanguageId(String languageId); - - public Token findByIndex(int index); - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/UpcaseUserRepository.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/UpcaseUserRepository.java deleted file mode 100644 index 81d16f0..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/UpcaseUserRepository.java +++ /dev/null @@ -1,32 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.repository; - -import java.util.Date; -import java.util.List; - -import org.springframework.data.repository.Repository; - -import de.uni_koeln.spinfo.upcase.mongodb.data.document.UpcaseUser; - -public interface UpcaseUserRepository extends Repository { - - public UpcaseUser findByEmail(String email); - - public UpcaseUser findById(String id); - - public List findAll(); - - public List findByCreationDate(Date creationDate); - - public UpcaseUser save(UpcaseUser upcaseUser); - - public UpcaseUser delete(UpcaseUser upcaseUser); - - public UpcaseUser deleteByEmail(String email); - - public void deleteAll(); - - public UpcaseUser update(UpcaseUser upcaseUser); - - public long count(); - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/UpcaseUserRepositoryImpl.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/UpcaseUserRepositoryImpl.java deleted file mode 100644 index e455da5..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/UpcaseUserRepositoryImpl.java +++ /dev/null @@ -1,92 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.repository; - -import java.util.Date; -import java.util.List; - -import javax.inject.Inject; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.data.mongodb.core.MongoOperations; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; -import org.springframework.stereotype.Repository; - -import de.uni_koeln.spinfo.upcase.mongodb.data.document.UpcaseUser; - -@Repository -public class UpcaseUserRepositoryImpl implements UpcaseUserRepository { - - private Logger logger = LoggerFactory.getLogger(getClass()); - - private MongoOperations operations; - - @Inject - public UpcaseUserRepositoryImpl(MongoOperations operations) { - this.operations = operations; - } - - @Override - public UpcaseUser findByEmail(final String email) { - return operations.findOne(new Query(Criteria.where("email").is(email)), UpcaseUser.class); - } - - @Override - public List findAll() { - return operations.findAll(UpcaseUser.class); - } - - @Override - public List findByCreationDate(Date creationDate) { - return operations.find(new Query(Criteria.where("creationDate").gte(creationDate)), UpcaseUser.class); - } - - @Override - public UpcaseUser save(UpcaseUser upcaseUser) { - operations.save(upcaseUser, "users"); - logger.info("SAVE: " + upcaseUser); - return upcaseUser; - } - - @Override - public UpcaseUser delete(UpcaseUser upcaseUser) { - operations.remove(upcaseUser); - return upcaseUser; - } - - @Override - public UpcaseUser deleteByEmail(final String email) { - UpcaseUser user = findByEmail(email); - delete(user); - return user; - } - - @Override - public void deleteAll() { - logger.info("DELETE_ALL: " + count()); - operations.remove(new Query(), UpcaseUser.class); - } - - @Override - public UpcaseUser update(UpcaseUser upcaseUser) { - UpcaseUser toUpdate = findById(upcaseUser); - toUpdate = upcaseUser; - save(toUpdate); - return toUpdate; - } - - @Override - public long count() { - return operations.count(new Query(), UpcaseUser.class); - } - - private UpcaseUser findById(UpcaseUser upcaseUser) { - return operations.findOne(new Query(Criteria.where("_id").is(upcaseUser.getId())), UpcaseUser.class); - } - - @Override - public UpcaseUser findById(final String id) { - return operations.findOne(new Query(Criteria.where("_id").is(id)), UpcaseUser.class); - } - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/VolumeRepository.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/VolumeRepository.java deleted file mode 100755 index 73c12a9..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/VolumeRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.repository; - -import org.springframework.data.repository.CrudRepository; - -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Volume; - -public interface VolumeRepository extends CrudRepository { - - public Volume findByTitle(String title); - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/WordRepository.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/WordRepository.java deleted file mode 100755 index f1e8f6b..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/WordRepository.java +++ /dev/null @@ -1,27 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.repository; - -import java.util.List; - -import org.springframework.data.repository.Repository; - -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Word; - -public interface WordRepository extends Repository { - - public List findByVolumeId(String volumeId); - - public List findByPageId(String pageId); - - public List findByChapterId(String chapterId); - - public List findByLanguageId(String languageId); - - public Word findByIndex(int index); - - public Word save(Word word); - - public List findByRange(int from, int to); - - public long count(); - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/WordRepositoryImpl.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/WordRepositoryImpl.java deleted file mode 100755 index 625f1b8..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/WordRepositoryImpl.java +++ /dev/null @@ -1,73 +0,0 @@ -package de.uni_koeln.spinfo.upcase.mongodb.repository; - -import java.util.List; - -import javax.inject.Inject; - -import org.springframework.data.mongodb.core.MongoOperations; -import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.data.mongodb.core.query.Query; -import org.springframework.stereotype.Repository; - -import de.uni_koeln.spinfo.upcase.mongodb.data.document.Word; - -@Repository -public class WordRepositoryImpl implements WordRepository { - - private MongoOperations operations; - - @Inject - public WordRepositoryImpl(MongoOperations operations) { - this.operations = operations; - } - - @Override - public List findByVolumeId(final String volumeId) { - return operations.find(new Query(Criteria.where("volumeId") - .is(volumeId)), Word.class); - } - - @Override - public List findByPageId(final String pageId) { - return operations.find(new Query(Criteria.where("pageId").is(pageId)), - Word.class); - } - - @Override - public List findByChapterId(final String chapterId) { - return operations.find( - new Query(Criteria.where("chapterId").is(chapterId)), - Word.class); - } - - @Override - public List findByLanguageId(final String languageId) { - return operations.find( - new Query(Criteria.where("languageId").is(languageId)), - Word.class); - } - - @Override - public Word findByIndex(int index) { - return operations.findOne(new Query(Criteria.where("index").is(index)), - Word.class); - } - - @Override - public Word save(Word word) { - operations.save(word); - return word; - } - - public List findByRange(int from, int to) { - List wordRange = operations.find(new Query(Criteria.where("index").gte(from) - .andOperator(Criteria.where("index").lte(to))), Word.class); - return wordRange; - } - - @Override - public long count() { - return operations.count(new Query(), Word.class); - } - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/CollectionRepository.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/CollectionRepository.java index 05e7fb3..7e7dba7 100644 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/CollectionRepository.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/CollectionRepository.java @@ -1,9 +1,17 @@ package de.uni_koeln.spinfo.upcase.mongodb.repository.future; -import org.springframework.data.repository.CrudRepository; +import org.springframework.data.repository.Repository; import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.Collection; -public interface CollectionRepository extends CrudRepository { +public interface CollectionRepository extends Repository { + + public Collection save(Collection collection); + + public long count(); + + public Collection findbyId(String id); + + public Collection findbyTitle(String title); } diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/CollectionRepositoryImpl.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/CollectionRepositoryImpl.java new file mode 100644 index 0000000..7951d12 --- /dev/null +++ b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/CollectionRepositoryImpl.java @@ -0,0 +1,42 @@ +package de.uni_koeln.spinfo.upcase.mongodb.repository.future; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.mongodb.core.MongoOperations; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.stereotype.Repository; + +import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.Collection; + +@Repository +public class CollectionRepositoryImpl implements CollectionRepository { + + private MongoOperations operations; + + @Autowired + public CollectionRepositoryImpl(MongoOperations operations) { + this.operations = operations; + } + + @Override + public Collection save(Collection collection) { + operations.insert(collection, Collection.COLLECTION); + return collection; + } + + @Override + public long count() { + return operations.getCollection(Collection.COLLECTION).count(); + } + + @Override + public Collection findbyId(String id) { + return operations.findOne(new Query(Criteria.where("_id").is(id)), Collection.class); + } + + @Override + public Collection findbyTitle(String title) { + return operations.findOne(new Query(Criteria.where("title").is(title)), Collection.class); + } + +} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/ContributionRequestRepository.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/ContributionRequestRepository.java index e3ee325..11482ac 100644 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/ContributionRequestRepository.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/ContributionRequestRepository.java @@ -5,10 +5,9 @@ import org.springframework.data.repository.CrudRepository; import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.ContributionRequest; -import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.UpcaseUser; public interface ContributionRequestRepository extends CrudRepository { - public List findByUpcaseUser(UpcaseUser upcaseUser); + public List findByOwner(String owner); } diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/PageRepository.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/PageRepository.java new file mode 100644 index 0000000..28708f2 --- /dev/null +++ b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/PageRepository.java @@ -0,0 +1,29 @@ +package de.uni_koeln.spinfo.upcase.mongodb.repository.future; + +import java.util.List; + +import org.springframework.data.repository.Repository; + +import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.Page; + +public interface PageRepository extends Repository { + + public Page findByPageId(String pageId); + + public List findByUser(String user); + + public Page findByImageUrl(String imageUrl); + + public List findByCollection(String collection); + + public List findAll(); + + public Page save(Page page); + + public String findOne(); + + public String findOne(String pageId); + + public List save(List pages); + +} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/PageRepositoryImpl.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/PageRepositoryImpl.java new file mode 100644 index 0000000..447a9a0 --- /dev/null +++ b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/PageRepositoryImpl.java @@ -0,0 +1,72 @@ +package de.uni_koeln.spinfo.upcase.mongodb.repository.future; + +import java.util.List; + +import javax.inject.Inject; + +import org.springframework.data.mongodb.core.MongoOperations; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.stereotype.Repository; + +import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.Page; + +@Repository +public class PageRepositoryImpl implements PageRepository { + + private MongoTemplate mongoTemplate; + + @Inject + public PageRepositoryImpl(MongoTemplate mongoTemplate) { + this.mongoTemplate = mongoTemplate; + } + + @Override + public Page findByImageUrl(String imageUrl) { + return mongoTemplate.findOne(new Query(Criteria.where("imageUrl").is(imageUrl)), Page.class); + } + + @Override + public List findByUser(String user) { + return mongoTemplate.find(new Query(Criteria.where("user").is(user)), Page.class); + } + + @Override + public List findAll() { + return mongoTemplate.find(new Query(), Page.class); + } + + @Override + public Page save(Page page) { + mongoTemplate.save(page); + return page; + } + + @Override + public String findOne() { + return mongoTemplate.findOne(new Query(), String.class, Page.COLLECTION); + } + + @Override + public Page findByPageId(String pageId) { + return mongoTemplate.findOne(new Query(Criteria.where("_id").is(pageId)), Page.class); + } + + @Override + public String findOne(String pageId) { + return mongoTemplate.findOne(new Query(Criteria.where("_id").is(pageId)), String.class, Page.COLLECTION); + } + + @Override + public List findByCollection(String collection) { + return mongoTemplate.find(new Query(Criteria.where("collection").is(collection)), Page.class); + } + + @Override + public List save(List pages) { + mongoTemplate.insert(pages, Page.class); + return pages; + } + +} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/UpcaseUserRepository.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/UpcaseUserRepository.java index fcb6390..40815e5 100644 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/UpcaseUserRepository.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/UpcaseUserRepository.java @@ -1,9 +1,23 @@ package de.uni_koeln.spinfo.upcase.mongodb.repository.future; +import java.util.List; + import org.springframework.data.repository.Repository; import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.UpcaseUser; public interface UpcaseUserRepository extends Repository { + public UpcaseUser save(UpcaseUser user); + + public UpcaseUser findByEmail(String email); + + public long count(); + + public UpcaseUser findById(String id); + + public List findAll(); + + public void deleteAll(); + } diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/UpcaseUserRepositoryImpl.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/UpcaseUserRepositoryImpl.java index 4ec3d1e..9de9c6f 100644 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/UpcaseUserRepositoryImpl.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/UpcaseUserRepositoryImpl.java @@ -1,19 +1,58 @@ package de.uni_koeln.spinfo.upcase.mongodb.repository.future; -import javax.inject.Inject; +import java.util.List; -import org.springframework.data.mongodb.core.MongoOperations; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.Criteria; +import org.springframework.data.mongodb.core.query.Query; +import org.springframework.stereotype.Repository; +import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.UpcaseUser; + +@Repository public class UpcaseUserRepositoryImpl implements UpcaseUserRepository { - - - private MongoOperations operations; - @Inject - public UpcaseUserRepositoryImpl(MongoOperations operations) { - this.operations = operations; + Logger logger = LoggerFactory.getLogger(getClass()); + + private MongoTemplate template; + + @Autowired + public UpcaseUserRepositoryImpl(MongoTemplate template) { + this.template = template; + } + + @Override + public UpcaseUser findByEmail(String email) { + return template.findOne(new Query(Criteria.where("email").is(email)), UpcaseUser.class); } + @Override + public long count() { + return template.getCollection(UpcaseUser.COLLECTION).count(); + } + + @Override + public UpcaseUser save(UpcaseUser user) { + template.save(user, UpcaseUser.COLLECTION); + return user; + } + + @Override + public UpcaseUser findById(String id) { + return template.findOne(new Query(Criteria.where("_id").is(id)), UpcaseUser.class); + } + + @Override + public List findAll() { + return template.find(new Query(), UpcaseUser.class, UpcaseUser.COLLECTION); + } + @Override + public void deleteAll() { + template.remove(new Query(), UpcaseUser.class); + } } diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/WordRepository.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/WordRepository.java new file mode 100644 index 0000000..d0ae559 --- /dev/null +++ b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/repository/future/WordRepository.java @@ -0,0 +1,9 @@ +package de.uni_koeln.spinfo.upcase.mongodb.repository.future; + +import org.springframework.data.repository.CrudRepository; + +import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.Word; + +public interface WordRepository extends CrudRepository { + +} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/util/DataBase.java b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/util/DataBase.java index a637384..ea2de37 100755 --- a/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/util/DataBase.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/mongodb/util/DataBase.java @@ -3,86 +3,25 @@ import java.util.List; import java.util.Set; -import javax.inject.Inject; - import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.mongodb.core.query.Query; -import org.springframework.data.mongodb.repository.support.MongoRepositoryFactory; import org.springframework.stereotype.Component; import com.fasterxml.jackson.core.JsonProcessingException; import com.mongodb.CommandResult; import com.mongodb.DBCollection; -import de.uni_koeln.spinfo.upcase.mongodb.repository.ChapterRepository; -import de.uni_koeln.spinfo.upcase.mongodb.repository.LanguageRepository; -import de.uni_koeln.spinfo.upcase.mongodb.repository.PageRepository; -import de.uni_koeln.spinfo.upcase.mongodb.repository.UpcaseUserRepository; -import de.uni_koeln.spinfo.upcase.mongodb.repository.VolumeRepository; -import de.uni_koeln.spinfo.upcase.mongodb.repository.WordRepository; @Component("db") public class DataBase { private Logger logger = LoggerFactory.getLogger(getClass()); - private MongoTemplate mongoTemplate; - - private ChapterRepository chapterRepository; - private LanguageRepository LanguageRepository; - private VolumeRepository volumeRepository; - - @Autowired - private WordRepository wordRepository; - - @Autowired - private UpcaseUserRepository upcaseUserRepository; - @Autowired - private PageRepository pageRepository; - - @Inject - public DataBase(MongoRepositoryFactory dbFactory, MongoTemplate mongoTemplate) { - this.mongoTemplate = mongoTemplate; - this.chapterRepository = dbFactory.getRepository(ChapterRepository.class); - this.LanguageRepository = dbFactory.getRepository(LanguageRepository.class); - this.volumeRepository = dbFactory.getRepository(VolumeRepository.class); - } - - public UpcaseUserRepository getUpcaseUserRepository() { - return upcaseUserRepository; - } - - public void setUpcaseUserRepository(UpcaseUserRepository upcaseUserRepository) { - this.upcaseUserRepository = upcaseUserRepository; - } - - public MongoTemplate getMongoTemplate() { - return mongoTemplate; - } - - public PageRepository getPageRepository() { - return pageRepository; - } - - public ChapterRepository getChapterRepository() { - return chapterRepository; - } - - public LanguageRepository getLanguageRepository() { - return LanguageRepository; - } - - public VolumeRepository getVolumeRepository() { - return volumeRepository; - } - - public WordRepository getWordRepository() { - return wordRepository; - } + private MongoTemplate mongoTemplate; /** * Returns an entry as a JSON-String from the given collection diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/security/MyInMemoryUserDetailsManager.java b/src/main/java/de/uni_koeln/spinfo/upcase/security/MyInMemoryUserDetailsManager.java new file mode 100644 index 0000000..e0eb64d --- /dev/null +++ b/src/main/java/de/uni_koeln/spinfo/upcase/security/MyInMemoryUserDetailsManager.java @@ -0,0 +1,20 @@ +package de.uni_koeln.spinfo.upcase.security; + +import java.util.Collection; + +import org.springframework.security.core.userdetails.UserDetails; +import org.springframework.security.provisioning.InMemoryUserDetailsManager; + +public class MyInMemoryUserDetailsManager extends InMemoryUserDetailsManager { + + private Collection users; + + public MyInMemoryUserDetailsManager(Collection users) { + super(users); + this.users = users; + } + + public Collection getUsers() { + return users; + } +} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/service/CollectionService.java b/src/main/java/de/uni_koeln/spinfo/upcase/service/CollectionService.java new file mode 100644 index 0000000..21e938e --- /dev/null +++ b/src/main/java/de/uni_koeln/spinfo/upcase/service/CollectionService.java @@ -0,0 +1,21 @@ +package de.uni_koeln.spinfo.upcase.service; + +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Service; + +import de.uni_koeln.spinfo.upcase.CollectionAlreadyExistsException; +import de.uni_koeln.spinfo.upcase.model.form.UploadForm; + +@Service +public interface CollectionService { + + /** + * + * @param uploadForm + * @return collectionId + * @throws CollectionAlreadyExistsException + */ + @PreAuthorize("hasRole('USER')") + public String createCollection(UploadForm uploadForm) throws CollectionAlreadyExistsException; + +} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/service/CollectionServiceImpl.java b/src/main/java/de/uni_koeln/spinfo/upcase/service/CollectionServiceImpl.java new file mode 100644 index 0000000..7dc988e --- /dev/null +++ b/src/main/java/de/uni_koeln/spinfo/upcase/service/CollectionServiceImpl.java @@ -0,0 +1,111 @@ +package de.uni_koeln.spinfo.upcase.service; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.HashSet; +import java.util.List; +import java.util.stream.Collectors; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.core.context.SecurityContextHolder; +import org.springframework.stereotype.Component; +import org.springframework.web.multipart.MultipartFile; + +import de.uni_koeln.spinfo.upcase.CollectionAlreadyExistsException; +import de.uni_koeln.spinfo.upcase.model.form.UploadForm; +import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.Collection; +import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.Page; +import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.UpcaseUser; +import de.uni_koeln.spinfo.upcase.mongodb.repository.future.CollectionRepository; +import de.uni_koeln.spinfo.upcase.mongodb.repository.future.PageRepository; +import de.uni_koeln.spinfo.upcase.mongodb.repository.future.UpcaseUserRepository; +import de.uni_koeln.spinfo.upcase.util.HOCRParser; +import net.sourceforge.tess4j.TesseractException; + +@Component +public class CollectionServiceImpl implements CollectionService { + + Logger logger = LoggerFactory.getLogger(getClass()); + + @Autowired + private UpcaseUserRepository upcaseUserRepository; + + @Autowired + private PageRepository pageRepository; + + @Autowired + private CollectionRepository collectionRepository; + + @Autowired + private OCRService ocrService; + + @Autowired + private HOCRParser hOCRParser; + + @Override + public String createCollection(UploadForm uploadForm) throws CollectionAlreadyExistsException { + final String name = SecurityContextHolder.getContext().getAuthentication().getName(); + final MultipartFile multiPart = uploadForm.getMultiPart(); + + UpcaseUser user = upcaseUserRepository.findByEmail(name); + + if (collectionExists(uploadForm)) { + throw new CollectionAlreadyExistsException(); + } else { + File userColectionDir = new File("user_" + user.getId(), uploadForm.getCollectionName()); + userColectionDir.mkdirs(); + + try { + saveToUserDir(userColectionDir, multiPart.getOriginalFilename(), multiPart.getBytes()); + } catch (IOException e) { + e.printStackTrace(); + } + + try { + File file = multipartToFile(multiPart); + String hOCR = ocrService.exctractHOCR(file); + List pages = hOCRParser.parse(hOCR, userColectionDir, file.getName()); + saveToUserDir(userColectionDir, multiPart.getOriginalFilename().replaceAll("\\..{1,4}", ".html"), hOCR.getBytes()); + pageRepository.save(pages); + List pageIds = pages.stream().map(p -> p.getId()).collect(Collectors.toList()); + Collection collection = new Collection(uploadForm.getCollectionName(), user, + new HashSet(pageIds)); + collectionRepository.save(collection); + file.delete(); + // return collection.getId(); + + } catch (IllegalStateException | IOException e) { + e.printStackTrace(); + } catch (TesseractException e) { + e.printStackTrace(); + } + } + + return "1"; + } + + private File multipartToFile(MultipartFile multiPart) throws IllegalStateException, IOException { + File convFile = new File(multiPart.getOriginalFilename()); + multiPart.transferTo(convFile); + return convFile; + } + + private void saveToUserDir(File userColectionDir, String fileName, byte[] bytes) throws IOException { + Path file = Paths.get(userColectionDir.getAbsolutePath(), fileName); + Files.write(file, bytes); + } + + private boolean collectionExists(UploadForm uploadForm) { + Collection findbyTitle = collectionRepository.findbyTitle(uploadForm.getCollectionName()); + if (findbyTitle != null) { + return true; + } + return false; + } + +} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/service/ContributionServiceImpl.java b/src/main/java/de/uni_koeln/spinfo/upcase/service/ContributionServiceImpl.java index 5c8d29e..29f013f 100644 --- a/src/main/java/de/uni_koeln/spinfo/upcase/service/ContributionServiceImpl.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/service/ContributionServiceImpl.java @@ -2,23 +2,34 @@ import java.util.List; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.Collection; import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.ContributionRequest; import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.UpcaseUser; import de.uni_koeln.spinfo.upcase.mongodb.repository.future.CollectionRepository; import de.uni_koeln.spinfo.upcase.mongodb.repository.future.ContributionRequestRepository; +@Service public class ContributionServiceImpl implements ContributionService { - @Autowired private CollectionRepository collectionRepository; + Logger logger = LoggerFactory.getLogger(getClass()); - @Autowired private ContributionRequestRepository contributionRequestRepository; + @Autowired + private CollectionRepository collectionRepository; + + @Autowired + private ContributionRequestRepository contributionRequestRepository; @Override public void accept(ContributionRequest request) { - request.getCollection().setContributer(request.getRequestor()); - collectionRepository.save(request.getCollection()); + String collectionId = request.getCollection(); + Collection collection = collectionRepository.findbyId(collectionId); + collection.setContributer(request.getRequestor()); + collectionRepository.save(collection); close(request); } @@ -29,7 +40,7 @@ public void close(ContributionRequest request) { @Override public List hasContributionRequests(UpcaseUser upcaseUser) { - return contributionRequestRepository.findByUpcaseUser(upcaseUser); + return contributionRequestRepository.findByOwner(upcaseUser.getId()); } } diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/service/LoginService.java b/src/main/java/de/uni_koeln/spinfo/upcase/service/LoginService.java index dc3ac1a..8359eb5 100644 --- a/src/main/java/de/uni_koeln/spinfo/upcase/service/LoginService.java +++ b/src/main/java/de/uni_koeln/spinfo/upcase/service/LoginService.java @@ -5,18 +5,19 @@ import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.core.userdetails.UsernameNotFoundException; -import de.uni_koeln.spinfo.upcase.mongodb.data.document.UpcaseUser; +import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.UpcaseUser; +import de.uni_koeln.spinfo.upcase.mongodb.repository.future.UpcaseUserRepository; import de.uni_koeln.spinfo.upcase.mongodb.util.DataBase; public class LoginService implements UserDetailsService { @Autowired - private DataBase db; + UpcaseUserRepository upcaseUserRepository; @Override - public UserDetails loadUserByUsername(String arg0) throws UsernameNotFoundException { - UpcaseUser user = db.getUpcaseUserRepository().findByEmail(arg0); - return new UpcaseUserDetails(user); + public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException { + UpcaseUser user = upcaseUserRepository.findByEmail(email); + return user; } } diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/service/OCRService.java b/src/main/java/de/uni_koeln/spinfo/upcase/service/OCRService.java new file mode 100644 index 0000000..24d5458 --- /dev/null +++ b/src/main/java/de/uni_koeln/spinfo/upcase/service/OCRService.java @@ -0,0 +1,66 @@ +package de.uni_koeln.spinfo.upcase.service; + +import java.io.File; +import java.io.FileFilter; +import java.util.ArrayList; +import java.util.List; + +import org.springframework.security.access.prepost.PreAuthorize; +import org.springframework.stereotype.Service; + +import com.jcraft.jsch.JSchException; + +import net.sourceforge.tess4j.Tesseract; +import net.sourceforge.tess4j.TesseractException; + +@Service +public class OCRService { + + private Tesseract tesseract; + private FileFilter filer; + + @PreAuthorize("hasRole('USER')") + public String exctractHOCR(File file) throws TesseractException { + init(); + String hOCRs = ""; + if (filer.accept(file)) { + hOCRs = tesseract.doOCR(file); + } + return hOCRs; + } + + @PreAuthorize("hasRole('USER')") + public List exctractHOCR(List files) throws TesseractException, JSchException { + init(); + List hOCRs = new ArrayList<>(); + for (File file : files) { + if (filer.accept(file)) { + hOCRs.add(tesseract.doOCR(file)); + } + } + return hOCRs; + } + + private void init() { + tesseract = new Tesseract(); +// tesseract.setLanguage("ita"); + tesseract.setDatapath("/usr/local/share/tessdata"); + tesseract.setHocr(true); + filer = new FileFilter() { + @Override + public boolean accept(File pathname) { + boolean accept = false; + if (pathname.getName().endsWith(".png")) + accept = true; + if (pathname.getName().endsWith(".jpeg")) + accept = true; + if (pathname.getName().endsWith(".jpg")) + accept = true; + if (pathname.getName().endsWith(".tiff")) + accept = true; + return accept; + } + }; + } + +} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/service/SSHConnection.java b/src/main/java/de/uni_koeln/spinfo/upcase/service/SSHConnection.java new file mode 100644 index 0000000..cefedb0 --- /dev/null +++ b/src/main/java/de/uni_koeln/spinfo/upcase/service/SSHConnection.java @@ -0,0 +1,34 @@ +package de.uni_koeln.spinfo.upcase.service; + +import java.util.Properties; + +import com.jcraft.jsch.JSch; +import com.jcraft.jsch.JSchException; +import com.jcraft.jsch.Session; + +//@Service +class SSHConnection { + + private Session session; + + public void createConnection() throws JSchException { + JSch jsch = new JSch(); + + // TODO: Externalize credentials into properties file + session = jsch.getSession("USER", "HOST"); + session.setPassword("PWD"); + + Properties prop = new Properties(); + prop.put("StrictHostKeyChecking", "no"); + session.setConfig(prop); + session.setTimeout(3000); + session.connect(); + } + + public void closeConnection() throws JSchException { + if(session != null && session.isConnected()) + session.disconnect(); + } + + +} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/service/UpcaseUserDetails.java b/src/main/java/de/uni_koeln/spinfo/upcase/service/UpcaseUserDetails.java deleted file mode 100644 index c3f736e..0000000 --- a/src/main/java/de/uni_koeln/spinfo/upcase/service/UpcaseUserDetails.java +++ /dev/null @@ -1,80 +0,0 @@ -package de.uni_koeln.spinfo.upcase.service; - -import java.util.Collection; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.springframework.security.core.GrantedAuthority; -import org.springframework.security.core.userdetails.UserDetails; - -import de.uni_koeln.spinfo.upcase.mongodb.data.document.UpcaseUser; - -public class UpcaseUserDetails implements UserDetails { - - private static final long serialVersionUID = -7841813932397898590L; - private UpcaseUser user; - - public UpcaseUserDetails(final UpcaseUser user) { - this.user = user; - } - - @Override - public Collection getAuthorities() { - - final Set grantedAuthorities = new HashSet(); - List roles = null; - if (user != null) { - roles = user.getRoles(); - } - if (roles != null) { - for (String role : roles) { - grantedAuthorities.add(new GrantedAuthority() { - - private static final long serialVersionUID = 1L; - - @Override - public String getAuthority() { - return role; - } - }); - } - } - - return grantedAuthorities; - } - - @Override - public String getPassword() { - return user.getHash(); - } - - @Override - public String getUsername() { - return user.getEmail(); - } - - @Override - public boolean isAccountNonExpired() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean isAccountNonLocked() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean isCredentialsNonExpired() { - // TODO Auto-generated method stub - return false; - } - - @Override - public boolean isEnabled() { - return user.isEnabled(); - } - -} diff --git a/src/main/java/de/uni_koeln/spinfo/upcase/util/HOCRParser.java b/src/main/java/de/uni_koeln/spinfo/upcase/util/HOCRParser.java new file mode 100644 index 0000000..ac2d047 --- /dev/null +++ b/src/main/java/de/uni_koeln/spinfo/upcase/util/HOCRParser.java @@ -0,0 +1,73 @@ +package de.uni_koeln.spinfo.upcase.util; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.jsoup.Jsoup; +import org.jsoup.nodes.Document; +import org.jsoup.nodes.Element; +import org.jsoup.select.Elements; +import org.springframework.stereotype.Component; + +import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.Box; +import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.Page; +import de.uni_koeln.spinfo.upcase.mongodb.data.document.future.Word; + +@Component +public class HOCRParser { + + private Pattern bboxPattern = Pattern.compile("\\d{1,4}\\s\\d{1,4}\\s\\d{1,4}\\s\\d{1,4}"); + + public List parse(String html, File dir, String imageUrl) throws IOException { + + List pages = new ArrayList<>(); + + int pageCount = 0; + // for (File file : data) { + + Page page = new Page(new File(dir, imageUrl).getAbsolutePath(), pageCount, 0); + List words = new ArrayList<>(); + + // hOCR document + Document hOCR = Jsoup.parse(html, "UTF-8"); + // Page + Elements ocrPage = hOCR.select(".ocr_page"); + // Paragraphs in Page + Elements ocrPars = ocrPage.select(".ocr_par"); + + for (Element parElement : ocrPars) { + // Lines in Paragraph + // Elements ocrLine = ocrPars.select(".ocr_line"); + + // Words in Line + Elements ocrxWords = parElement.select(".ocrx_word"); + for (Element wordElement : ocrxWords) { + + String title = wordElement.attr("title"); + Matcher matcher = bboxPattern.matcher(title); + matcher.find(); + + String[] bBox = matcher.group(0).trim().split(" "); + String token = wordElement.text(); + + if (!token.isEmpty()) { + int x1 = Integer.parseInt(bBox[0]); + int x2 = Integer.parseInt(bBox[2]); + int y1 = Integer.parseInt(bBox[1]); + int y2 = Integer.parseInt(bBox[3]); + words.add(new Word(token, new Box(x1, x2, y1, y2))); + } + } + page.setWords(words); + } + pages.add(page); + pageCount++; + // } + return pages; + } + +} diff --git a/src/main/resources/locale/messages.properties b/src/main/resources/locale/messages.properties index 9052e8d..e6f66ad 100644 --- a/src/main/resources/locale/messages.properties +++ b/src/main/resources/locale/messages.properties @@ -20,4 +20,8 @@ NotEqual.registrationForm.confirmPassword=Password conformation failed. #SigninForm NotBlank.signinForm.email=Please type in your email. -NotBlank.signinForm.password=Enter password. \ No newline at end of file +NotBlank.signinForm.password=Enter password. + +#UploadForm +NotBlank.uploadForm.collectionName=Field must not be empty. +NotBlank.uploadForm.multiPart=Add one or more Files to your collection. \ No newline at end of file diff --git a/src/main/resources/locale/messages_de.properties b/src/main/resources/locale/messages_de.properties index 63bfe14..4453a2e 100644 --- a/src/main/resources/locale/messages_de.properties +++ b/src/main/resources/locale/messages_de.properties @@ -20,4 +20,8 @@ NotEqual.registrationForm.confirmPassword=Passwort stimmt nicht überein. #SigninForm NotBlank.signinForm.email=Bitte geben Sie eine Email-Adresse ein. -NotBlank.signinForm.password=Bitte geben Sie ihr Passwort ein. \ No newline at end of file +NotBlank.signinForm.password=Bitte geben Sie ihr Passwort ein. + +#UploadForm +NotBlank.uploadForm.collectionName=Feld darf nicht leer sein. +NotBlank.uploadForm.multiPart=Bitte wählen Sie eine oder mehrere Dateien aus. \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/applicationContext.xml b/src/main/webapp/WEB-INF/applicationContext.xml index e0f02d9..ce2cb29 100644 --- a/src/main/webapp/WEB-INF/applicationContext.xml +++ b/src/main/webapp/WEB-INF/applicationContext.xml @@ -7,6 +7,6 @@ http://www.springframework.org/schema/beans/spring-beans.xsd"> - + \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/dispatcher-servlet.xml b/src/main/webapp/WEB-INF/dispatcher-servlet.xml index 6b76f6e..86596f0 100755 --- a/src/main/webapp/WEB-INF/dispatcher-servlet.xml +++ b/src/main/webapp/WEB-INF/dispatcher-servlet.xml @@ -4,11 +4,6 @@ xsi:schemaLocation="http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/beans - http://www.springframework.org/schema/beans/spring-beans.xsd - http://www.springframework.org/schema/security - http://www.springframework.org/schema/security/spring-security.xsd"> - - - + http://www.springframework.org/schema/beans/spring-beans.xsd"> \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/views/fragments/nav-bar-user.html b/src/main/webapp/WEB-INF/views/fragments/nav-bar-user.html index a3da02c..a0c3041 100644 --- a/src/main/webapp/WEB-INF/views/fragments/nav-bar-user.html +++ b/src/main/webapp/WEB-INF/views/fragments/nav-bar-user.html @@ -13,7 +13,7 @@ - UpCASE + UpCASE