diff --git a/.gitignore b/.gitignore index ca7505a9..ba593153 100644 --- a/.gitignore +++ b/.gitignore @@ -30,3 +30,9 @@ docs/deploying-spring-boot-apps/ setenv.sh setenv.cmd /etc/pom.xml +/src/main/java/org/woehlke/simpleworklist/project/x.txt +/src/main/java/org/woehlke/simpleworklist/task/x.txt +/src/main/java/org/woehlke/simpleworklist/taskstate/x.txt +/src/main/java/org/woehlke/simpleworklist/context/x.txt +/src/main/java/org/woehlke/simpleworklist/error/x.txt +/src/main/java/org/woehlke/simpleworklist/search/x.txt diff --git a/README.md b/README.md index 3be62202..c1b022ab 100644 --- a/README.md +++ b/README.md @@ -8,17 +8,9 @@ Your Todo List for Getting Things Done GTD® and Getting Things Done® are registered trademarks of the David Allen Company. SimpleWorklist is not affiliated with or endorsed by the David Allen Company. -## Up and Running -A Java Web App, which can easily be deployed to Heroku. - -[![Deploy to Heroku](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy) - -## URLs -### Development -* Heroku Deployment: [simpleworklist.herokuapp.com/](https://simpleworklist.herokuapp.com/) -* For Developers: [localhost:5000](http://localhost:5000/) -### Info -* [spring-framework-java-apps.github.io/simpleworklist](http://spring-framework-java-apps.github.io/simpleworklist/) +## Requirements +* [Functional Requirements](etc/requirements/Requirements.md) +* [Nonfunctional Requirements](etc/requirements/Nonfunctional_Requirements.md) ### Github Shortcuts * [Projects](https://github.com/Spring-Framework-Java-Apps/simpleworklist/projects) @@ -27,14 +19,19 @@ A Java Web App, which can easily be deployed to Heroku. * [Releases](https://github.com/Spring-Framework-Java-Apps/simpleworklist/releases) * [Branches](https://github.com/Spring-Framework-Java-Apps/simpleworklist/branches) * [CI](https://github.com/Spring-Framework-Java-Apps/simpleworklist/actions) +* [spring-framework-java-apps.github.io/simpleworklist](http://spring-framework-java-apps.github.io/simpleworklist/) -## Requirements - -### Functional Requirements -[Functional Requirements](etc/requirements/Requirements.md) +## Development +* [Requirements](etc/requirements/Requirements.md) +* [Nonfunctional_Requirements](etc/requirements/Nonfunctional_Requirements.md) +* [HOWTO](etc/development/HOWTO.md) +* [Maven_Plugins](etc/development/Maven_Plugins.md) +* [Primesfaces_JSF](etc/development/Primesfaces_JSF.md) -### Nonfunctional Requirements -[Nonfunctional Requirements](etc/requirements/Nonfunctional_Requirements.md) +## URLs: +* Heroku Deployment: [simpleworklist.herokuapp.com/](https://simpleworklist.herokuapp.com/) +* For Developers: [localhost:5000](http://localhost:5000/) -## Development -* [Changelog](etc/Changelog.md) +## Up and Running - Deployment +* A Java Web App, which can easily be deployed to Heroku. +* [![Deploy to Heroku](https://www.herokucdn.com/deploy/button.png)](https://heroku.com/deploy) diff --git a/etc/TODO.md b/etc/TODO.md index 41755fe9..2572afc5 100644 --- a/etc/TODO.md +++ b/etc/TODO.md @@ -72,3 +72,21 @@ Fixed #106, Fixed #109, Fixed #110 Deployment to heroku +# Maven Config: +## maven-changes-plugin +https://maven.apache.org/plugins/maven-changes-plugin/examples/configuring-github-report.html + +## maven-enforcer-plugin +http://maven.apache.org/enforcer/maven-enforcer-plugin/plugin-info.html +http://maven.apache.org/enforcer/enforcer-rules/ +https://maven.apache.org/enforcer/enforcer-rules/requireFilesExist.html +https://maven.apache.org/enforcer/enforcer-rules/requireEnvironmentVariable.html +https://maven.apache.org/enforcer/enforcer-rules/requireActiveProfile.html +https://maven.apache.org/enforcer/enforcer-rules/dependencyConvergence.html +https://www.baeldung.com/maven-enforcer-plugin + +# 2.3.14 +Fixed #122, Fixed #123, Fixed #127, Fixed #130, Fixed #152, Fixed #153, Fixed #154, Fixed #155, Fixed #156, Fixed #157, Fixed #158, Fixed #159, Fixed #160, Fixed #161, Fixed #162, Fixed #163, Fixed #164, Fixed #165, Fixed #166, Fixed #167 + +Fixed #129 +Fixed #126 diff --git a/etc/development/application.properties_sample.txt b/etc/config/application.properties_sample.txt similarity index 100% rename from etc/development/application.properties_sample.txt rename to etc/config/application.properties_sample.txt diff --git a/etc/development/application.properties_test_sample.txt b/etc/config/application.properties_test_sample.txt similarity index 100% rename from etc/development/application.properties_test_sample.txt rename to etc/config/application.properties_test_sample.txt diff --git a/etc/development/db-createdb-and-user-linux.sql b/etc/db/db-createdb-and-user-linux.sql similarity index 100% rename from etc/development/db-createdb-and-user-linux.sql rename to etc/db/db-createdb-and-user-linux.sql diff --git a/etc/development/db-createdb-and-user-win10.sql b/etc/db/db-createdb-and-user-win10.sql similarity index 100% rename from etc/development/db-createdb-and-user-win10.sql rename to etc/db/db-createdb-and-user-win10.sql diff --git a/etc/development/HOWTO.md b/etc/development/HOWTO.md index 3c04d669..ee477248 100644 --- a/etc/development/HOWTO.md +++ b/etc/development/HOWTO.md @@ -1,18 +1,5 @@ - Howto Reminder +# HOWTO -## github -* [Issues](https://github.com/BloodMoneyApp/bloodmoney/issues) -* [Projects](https://github.com/BloodMoneyApp/bloodmoney/projects) -* [Milestones](https://github.com/BloodMoneyApp/bloodmoney/milestones) -* [Releases](https://github.com/BloodMoneyApp/bloodmoney/releases) - -## Development -* [Changelog](etc/RELEASES.md) -* [Todo](etc/TODO.md) -* [Howto](etc/HOWTO.md) - - -## 3rd Party Software ### Howto * [Spring dependency-management-plugin](https://docs.spring.io/dependency-management-plugin/docs/current/reference/html/) * [Example on github: heroku and Gradle](https://github.com/heroku/gradle-getting-started/blob/master/build.gradle) @@ -46,6 +33,7 @@ * [liquibase-gradle-plugin](https://github.com/liquibase/liquibase-gradle-plugin) ## Database and JPA + ### DB Datatypes * [H2 Datatypes](http://www.h2database.com/html/datatypes.html) * [PostgreSQL Datatypes](https://www.postgresql.org/docs/11/datatype.html) diff --git a/etc/development/Maven_Plugins.md b/etc/development/Maven_Plugins.md new file mode 100644 index 00000000..8cdc8e46 --- /dev/null +++ b/etc/development/Maven_Plugins.md @@ -0,0 +1,34 @@ +# Maven Plugins + +| Plugin Page | mvnrepository.com | git repo | latest Version | Release Date of latest Version | +|-------------|-------------------|----------|----------------|--------------------------------| +| [apache-rat-plugin](http://creadur.apache.org/rat/apache-rat-plugin/) |   |   |   |   | +| [maven-enforcer-plugin](http://maven.apache.org/enforcer/maven-enforcer-plugin/) |   |   |   |   | +| [maven-jxr-plugin](http://maven.apache.org/jxr/maven-jxr-plugin/) |   |   |   |   | +| [maven-release-plugin](http://maven.apache.org/maven-release/maven-release-plugin/) |   |   |   |   | +| [maven-clean-plugin](http://maven.apache.org/plugins/maven-clean-plugin/) |   |   |   |   | +| [maven-dependency-plugin](http://maven.apache.org/plugins/maven-dependency-plugin/) |   |   |   |   | +| [maven-deploy-plugin](http://maven.apache.org/plugins/maven-deploy-plugin/) |   |   |   |   | +| [maven-docck-plugin](http://maven.apache.org/plugins/maven-docck-plugin/) |   |   |   |   | +| [maven-install-plugin](http://maven.apache.org/plugins/maven-install-plugin/) |   |   |   |   | +| [maven-jarsigner-plugin](http://maven.apache.org/plugins/maven-jarsigner-plugin/) |   |   |   |   | +| [maven-project-info-reports-plugin](http://maven.apache.org/plugins/maven-project-info-reports-plugin/) |   |   |   |   | +| [maven-remote-resources-plugin](http://maven.apache.org/plugins/maven-remote-resources-plugin/) |   |   |   |   | +| [maven-shade-plugin](http://maven.apache.org/plugins/maven-shade-plugin/) |   |   |   |   | +| [maven-toolchains-plugin](http://maven.apache.org/plugins/maven-toolchains-plugin/) |   |   |   |   | +| [maven-scm-plugin](http://maven.apache.org/scm/maven-scm-plugin/) |   |   |   |   | +| [maven-failsafe-plugin](http://maven.apache.org/surefire/maven-failsafe-plugin/) |   |   |   |   | +| [maven-surefire-plugin](http://maven.apache.org/surefire/maven-surefire-plugin/) |   |   |   |   | +| [maven-surefire-report-plugin](http://maven.apache.org/surefire/maven-surefire-report-plugin/) |   |   |   |   | +| [maven-changes-plugin](https://maven.apache.org/plugins/maven-changes-plugin/) |   |   |   |   | +| [maven-checkstyle-plugin](https://maven.apache.org/plugins/maven-checkstyle-plugin/) |   |   |   |   | +| [maven-compiler-plugin](https://maven.apache.org/plugins/maven-compiler-plugin/) |   |   |   |   | +| [maven-invoker-plugin](https://maven.apache.org/plugins/maven-invoker-plugin/) |   |   |   |   | +| [maven-jar-plugin](https://maven.apache.org/plugins/maven-jar-plugin/) |   |   |   |   | +| [maven-javadoc-plugin](https://maven.apache.org/plugins/maven-javadoc-plugin/) |   |   |   |   | +| [maven-pmd-plugin](https://maven.apache.org/plugins/maven-pmd-plugin/) |   |   |   |   | +| [maven-resources-plugin](https://maven.apache.org/plugins/maven-resources-plugin/) |   |   |   |   | +| [maven-scm-publish-plugin](https://maven.apache.org/plugins/maven-scm-publish-plugin/) |   |   |   |   | +| [maven-site-plugin](https://maven.apache.org/plugins/maven-site-plugin/) |   |   |   |   | +| [maven-source-plugin](https://maven.apache.org/plugins/maven-source-plugin/) |   |   |   |   | +| [maven-plugin-plugin](https://maven.apache.org/plugin-tools/maven-plugin-plugin/) |   |   |   |   | diff --git a/etc/development/Primesfaces_JSF.md b/etc/development/Primesfaces_JSF.md new file mode 100644 index 00000000..dfd81d62 --- /dev/null +++ b/etc/development/Primesfaces_JSF.md @@ -0,0 +1,2 @@ +# Primesfaces JSF + diff --git a/etc/development/db-createdb-and-user.sql b/etc/development/db-createdb-and-user.sql deleted file mode 100644 index e0aedde1..00000000 --- a/etc/development/db-createdb-and-user.sql +++ /dev/null @@ -1,45 +0,0 @@ - -CREATE USER simpleworklist WITH PASSWORD 'simpleworklistpwd' SUPERUSER INHERIT CREATEDB CREATEROLE REPLICATION; - -GRANT pg_monitor TO simpleworklist; -GRANT pg_read_all_settings TO simpleworklist; -GRANT pg_read_all_stats TO simpleworklist; -GRANT pg_signal_backend TO simpleworklist; -GRANT pg_stat_scan_tables TO simpleworklist; - - -CREATE DATABASE simpleworklist WITH OWNER simpleworklist TEMPLATE 'template1' ENCODING 'UTF8' LC_COLLATE 'de_DE.UTF-8' LC_CTYPE 'de_DE.UTF-8'; - -GRANT ALL ON DATABASE simpleworklist TO simpleworklist WITH GRANT OPTION; - -CREATE DATABASE simpleworklist_default WITH OWNER simpleworklist TEMPLATE 'template1' ENCODING 'UTF8' LC_COLLATE 'de_DE.UTF-8' LC_CTYPE 'de_DE.UTF-8'; - -GRANT ALL ON DATABASE simpleworklist_default TO simpleworklist WITH GRANT OPTION; - -CREATE DATABASE simpleworklist_branch_master WITH OWNER simpleworklist TEMPLATE 'template1' ENCODING 'UTF8' LC_COLLATE 'de_DE.UTF-8' LC_CTYPE 'de_DE.UTF-8'; - -GRANT ALL ON DATABASE simpleworklist_branch_master TO simpleworklist WITH GRANT OPTION; - -CREATE DATABASE simpleworklist_testing WITH OWNER simpleworklist TEMPLATE 'template1' ENCODING 'UTF8' LC_COLLATE 'de_DE.UTF-8' LC_CTYPE 'de_DE.UTF-8'; - -GRANT ALL ON DATABASE simpleworklist_testing TO simpleworklist WITH GRANT OPTION; - -CREATE DATABASE simpleworklist_qa WITH OWNER simpleworklist TEMPLATE 'template1' ENCODING 'UTF8' LC_COLLATE 'de_DE.UTF-8' LC_CTYPE 'de_DE.UTF-8'; - -GRANT ALL ON DATABASE simpleworklist_qa TO simpleworklist WITH GRANT OPTION; - -CREATE DATABASE simpleworklist_qa WITH OWNER simpleworklist TEMPLATE 'template1' ENCODING 'UTF8' LC_COLLATE 'de_DE.UTF-8' LC_CTYPE 'de_DE.UTF-8'; - -GRANT ALL ON DATABASE simpleworklist_qa TO simpleworklist WITH GRANT OPTION; - -CREATE DATABASE simpleworklist_heroku WITH OWNER simpleworklist TEMPLATE 'template1' ENCODING 'UTF8' LC_COLLATE 'de_DE.UTF-8' LC_CTYPE 'de_DE.UTF-8'; - -GRANT ALL ON DATABASE simpleworklist_heroku TO simpleworklist WITH GRANT OPTION; - - -GRANT ALL ON DATABASE artifactory TO artifactory WITH GRANT OPTION; - - - - - diff --git a/docker-start.sh b/etc/docker-start.sh similarity index 100% rename from docker-start.sh rename to etc/docker-start.sh diff --git a/docker-stop.sh b/etc/docker-stop.sh similarity index 100% rename from docker-stop.sh rename to etc/docker-stop.sh diff --git a/etc/java/set_java11.cmd b/etc/java/set_java11.cmd new file mode 100644 index 00000000..1de327f7 --- /dev/null +++ b/etc/java/set_java11.cmd @@ -0,0 +1,2 @@ +subst /D J: +subst J: "C:\Program Files\Java\*********" diff --git a/etc/set_java13.cmd b/etc/java/set_java13.cmd similarity index 100% rename from etc/set_java13.cmd rename to etc/java/set_java13.cmd diff --git a/etc/java/set_java14.cmd b/etc/java/set_java14.cmd new file mode 100644 index 00000000..1de327f7 --- /dev/null +++ b/etc/java/set_java14.cmd @@ -0,0 +1,2 @@ +subst /D J: +subst J: "C:\Program Files\Java\*********" diff --git a/etc/set_java1_8.cmd b/etc/java/set_java1_8.cmd similarity index 100% rename from etc/set_java1_8.cmd rename to etc/java/set_java1_8.cmd diff --git a/etc/java/set_java_windows10.md b/etc/java/set_java_windows10.md new file mode 100644 index 00000000..0c0404ff --- /dev/null +++ b/etc/java/set_java_windows10.md @@ -0,0 +1,3 @@ +# Set java on Windows10 + + diff --git a/psql.sh b/etc/psql.sh similarity index 100% rename from psql.sh rename to etc/psql.sh diff --git a/etc/requirements/Nonfunctional_Requirements.odt b/etc/requirements/Nonfunctional_Requirements.odt deleted file mode 100644 index 301152ff..00000000 Binary files a/etc/requirements/Nonfunctional_Requirements.odt and /dev/null differ diff --git a/etc/requirements/Requirements.md b/etc/requirements/Requirements.md index 3b0f73ce..5ab6fa09 100644 --- a/etc/requirements/Requirements.md +++ b/etc/requirements/Requirements.md @@ -12,23 +12,44 @@ ## F006 Page after first successful Login -## F007 Add first new Task from Inbox +## F007 Add first new Task to Inbox -## F008 Add first new Project +## F008 Add another new Task to Inbox -## F009 Add another new Task from Inbox -INBOX -> add new task -> Form -> save -> INBOX ( -> OK ) --> add new task -> Form -> save -> Project (-> NOK ) +## F009 Add Task to Project/Root -BUG: after saving to db app should show Inbox, but shows ProjectView for RootProject +## F010 Add SubProject to Project/Root -URLpaths: -http://localhost:5000/taskstate/inbox -http://localhost:5000/task/addtoproject/0 -http://localhost:5000/project/0/?listTaskTime=MIN5&listTaskTime=MIN10&listTaskTime=MIN15&listTaskTime=MIN30&listTaskTime=MIN45&listTaskTime=HOUR1&listTaskTime=HOUR2&listTaskTime=HOUR3&listTaskTime=HOUR4&listTaskTime=HOUR6&listTaskTime=HOUR8&listTaskTime=MORE&listTaskTime=NONE&numberOfNewIncomingMessages=0&listTaskEnergy=LOW&listTaskEnergy=MEDIUM&listTaskEnergy=HIGH&listTaskEnergy=NONE&context=Work&refreshMessages=false +## F011 setFocus of a Task +## F012 unSetFocus of a Task +## F013 show /taskstate/inbox +## F014 show /taskstate/today +## F015 show /taskstate/next +## F016 show /taskstate/waiting +## F017 show /taskstate/scheduled + +## F018 show /taskstate/someday + +## F019 show /taskstate/focus + +## F020 show /taskstate/completed + +## F021 show /taskstate/trash + +## F022 Task Edit + +## F023 Task Edit Form -> change Taskstate via DropDown + +## F024 Task complete + +## F025 Task incomplete + +## F026 Task delete + +## F027 Task undelete diff --git a/etc/requirements/Requirements.odt b/etc/requirements/Requirements.odt deleted file mode 100644 index 301152ff..00000000 Binary files a/etc/requirements/Requirements.odt and /dev/null differ diff --git a/etc/classpath.txt b/etc/serialversions/classpath.txt similarity index 100% rename from etc/classpath.txt rename to etc/serialversions/classpath.txt diff --git a/etc/getserialversionid.cmd b/etc/serialversions/getserialversionid.cmd similarity index 92% rename from etc/getserialversionid.cmd rename to etc/serialversions/getserialversionid.cmd index c91efd61..c70bb9cc 100644 --- a/etc/getserialversionid.cmd +++ b/etc/serialversions/getserialversionid.cmd @@ -17,11 +17,11 @@ echo %CLASSPATH% cd target\classes serialver org.woehlke.simpleworklist.language.Language > ..\..\etc\serialversions.txt serialver org.woehlke.simpleworklist.task.TaskEnergy >> ..\..\etc\serialversions.txt -serialver org.woehlke.simpleworklist.task.TaskState >> ..\..\etc\serialversions.txt +serialver org.woehlke.simpleworklist.taskstate.TaskState >> ..\..\etc\serialversions.txt serialver org.woehlke.simpleworklist.task.TaskTime >> ..\..\etc\serialversions.txt serialver org.woehlke.simpleworklist.user.resetpassword.UserPasswordRecoveryStatus >> ..\..\etc\serialversions.txt serialver org.woehlke.simpleworklist.user.register.UserRegistrationStatus >> ..\..\etc\serialversions.txt -serialver org.woehlke.simpleworklist.user.UserRole >> ..\..\etc\serialversions.txt +serialver org.woehlke.simpleworklist.user.account.UserRole >> ..\..\etc\serialversions.txt serialver org.woehlke.simpleworklist.common.AuditModel >> ..\..\etc\serialversions.txt serialver org.woehlke.simpleworklist.context.Context >> ..\..\etc\serialversions.txt serialver org.woehlke.simpleworklist.project.Project >> ..\..\etc\serialversions.txt @@ -34,7 +34,7 @@ serialver org.woehlke.simpleworklist.breadcrumb.BreadcrumbItem >> ..\..\etc\ser serialver org.woehlke.simpleworklist.breadcrumb.Breadcrumb >> ..\..\etc\serialversions.txt serialver org.woehlke.simpleworklist.user.login.LoginForm >> ..\..\etc\serialversions.txt serialver org.woehlke.simpleworklist.context.NewContextForm >> ..\..\etc\serialversions.txt -serialver org.woehlke.simpleworklist.user.messages.NewUser2UserMessage >> ..\..\etc\serialversions.txt +serialver org.woehlke.simpleworklist.user.messages.User2UserMessageFormBean >> ..\..\etc\serialversions.txt serialver org.woehlke.simpleworklist.search.SearchResult >> ..\..\etc\serialversions.txt serialver org.woehlke.simpleworklist.user.account.UserAccountForm >> ..\..\etc\serialversions.txt serialver org.woehlke.simpleworklist.context.UserChangeDefaultContextForm >> ..\..\etc\serialversions.txt diff --git a/etc/getserialversionid.sh b/etc/serialversions/getserialversionid.sh similarity index 92% rename from etc/getserialversionid.sh rename to etc/serialversions/getserialversionid.sh index 6d4a023f..ade0db35 100644 --- a/etc/getserialversionid.sh +++ b/etc/serialversions/getserialversionid.sh @@ -29,11 +29,11 @@ echo "CLASSPATH $CLASSPATH" cd $CLASSES_PATH serialver org.woehlke.simpleworklist.language.Language > $SERIALVERSIONS_FILE serialver org.woehlke.simpleworklist.task.TaskEnergy >> $SERIALVERSIONS_FILE -serialver org.woehlke.simpleworklist.task.TaskState >> $SERIALVERSIONS_FILE +serialver org.woehlke.simpleworklist.taskstate.TaskState >> $SERIALVERSIONS_FILE serialver org.woehlke.simpleworklist.task.TaskTime >> $SERIALVERSIONS_FILE serialver org.woehlke.simpleworklist.user.resetpassword.UserPasswordRecoveryStatus >> $SERIALVERSIONS_FILE serialver org.woehlke.simpleworklist.user.register.UserRegistrationStatus >> $SERIALVERSIONS_FILE -serialver org.woehlke.simpleworklist.user.UserRole >> $SERIALVERSIONS_FILE +serialver org.woehlke.simpleworklist.user.account.UserRole >> $SERIALVERSIONS_FILE serialver org.woehlke.simpleworklist.common.AuditModel >> $SERIALVERSIONS_FILE serialver org.woehlke.simpleworklist.context.Context >> $SERIALVERSIONS_FILE serialver org.woehlke.simpleworklist.project.Project >> $SERIALVERSIONS_FILE @@ -46,7 +46,7 @@ serialver org.woehlke.simpleworklist.breadcrumb.BreadcrumbItem >> $SERIALVERSIO serialver org.woehlke.simpleworklist.breadcrumb.Breadcrumb >> $SERIALVERSIONS_FILE serialver org.woehlke.simpleworklist.user.login.LoginForm >> $SERIALVERSIONS_FILE serialver org.woehlke.simpleworklist.context.NewContextForm >> $SERIALVERSIONS_FILE -serialver org.woehlke.simpleworklist.user.messages.NewUser2UserMessage >> $SERIALVERSIONS_FILE +serialver org.woehlke.simpleworklist.user.messages.User2UserMessageFormBean >> $SERIALVERSIONS_FILE serialver org.woehlke.simpleworklist.search.SearchResult >> $SERIALVERSIONS_FILE serialver org.woehlke.simpleworklist.user.account.UserAccountForm >> $SERIALVERSIONS_FILE serialver org.woehlke.simpleworklist.context.UserChangeDefaultContextForm >> $SERIALVERSIONS_FILE diff --git a/etc/serialversions.txt b/etc/serialversions/serialversions.txt similarity index 89% rename from etc/serialversions.txt rename to etc/serialversions/serialversions.txt index 4991de56..75c58f6b 100644 --- a/etc/serialversions.txt +++ b/etc/serialversions/serialversions.txt @@ -1,10 +1,10 @@ org.woehlke.simpleworklist.language.Language: private static final long serialVersionUID = 0L; org.woehlke.simpleworklist.task.TaskEnergy: private static final long serialVersionUID = 0L; -org.woehlke.simpleworklist.task.TaskState: private static final long serialVersionUID = 0L; +org.woehlke.simpleworklist.taskstate.TaskState: private static final long serialVersionUID = 0L; org.woehlke.simpleworklist.task.TaskTime: private static final long serialVersionUID = 0L; org.woehlke.simpleworklist.user.resetpassword.UserPasswordRecoveryStatus: private static final long serialVersionUID = 0L; org.woehlke.simpleworklist.user.register.UserRegistrationStatus: private static final long serialVersionUID = 0L; -org.woehlke.simpleworklist.user.UserRole: private static final long serialVersionUID = 0L; +org.woehlke.simpleworklist.user.account.UserRole: private static final long serialVersionUID = 0L; org.woehlke.simpleworklist.common.AuditModel: private static final long serialVersionUID = 4399373914714726911L; org.woehlke.simpleworklist.context.Context: private static final long serialVersionUID = -5035732370606951871L; org.woehlke.simpleworklist.project.Project: private static final long serialVersionUID = 4566653175832872422L; @@ -17,7 +17,7 @@ org.woehlke.simpleworklist.breadcrumb.BreadcrumbItem: private static final lo org.woehlke.simpleworklist.breadcrumb.Breadcrumb: private static final long serialVersionUID = 7932703111140692689L; org.woehlke.simpleworklist.user.login.LoginForm: private static final long serialVersionUID = 5936886560348238355L; org.woehlke.simpleworklist.context.NewContextForm: private static final long serialVersionUID = -937143305653156981L; -org.woehlke.simpleworklist.user.messages.NewUser2UserMessage: private static final long serialVersionUID = 1576610181966480168L; +org.woehlke.simpleworklist.user.messages.User2UserMessageFormBean: private static final long serialVersionUID = 1576610181966480168L; org.woehlke.simpleworklist.search.SearchResult: private static final long serialVersionUID = 1682809351146047764L; org.woehlke.simpleworklist.user.account.UserAccountForm: private static final long serialVersionUID = 9180383385243540190L; org.woehlke.simpleworklist.context.UserChangeDefaultContextForm: private static final long serialVersionUID = -8592295563275083292L; diff --git a/setenv-sample.cmd b/etc/setenv-sample.cmd similarity index 100% rename from setenv-sample.cmd rename to etc/setenv-sample.cmd diff --git a/setenv-sample.sh b/etc/setenv-sample.sh similarity index 100% rename from setenv-sample.sh rename to etc/setenv-sample.sh diff --git a/pom.xml b/pom.xml index 280cc0dd..70dae0e8 100644 --- a/pom.xml +++ b/pom.xml @@ -40,8 +40,8 @@ - simpleworklist.frodo.fritz.box - file://C:/xampp/x64-7.1.26-0-VC14/htdocs/p/simpleworklist + simpleworklist.public_html + file://${user.home}/public_html/p/simpleworklist @@ -50,21 +50,110 @@ 1.8 3.6.3 2.2.1 + ${project.parent.version} + 1.11.2 2.5.3 + 2.8.2 + + 1.8 + 3.1.1 + 3.1.0 + 3.8.1 + 3.1.2 + 2.8.2 + 3.0.0-M3 + 2.22.2 + 3.2.0 + 2.5.2 + 3.2.1 + 3.1.2 + 3.1.1 + 3.1.0 + 3.2.2 + 3.8.2 + 3.1.0 + 2.22.2 + 3.2.3 + 2.7 + 1.0.2 + 1.0.9.RELEASE + 3.0.1 + 2.12.1 + + 3.0.11.RELEASE + 2.0.1 + 3.0.4.RELEASE + 3.0.4.RELEASE + 2.4.1 + + Moore-SR6 + 5.2.5.RELEASE + 5.2.2.RELEASE + Corn-SR2 + + 5.5.2 + 2.6.4 + 2.36.0 + 2.1 + 1.18.12 + + 3.0.0 - 3.1.0 3.1.1 3.0.0 3.11.0 + 4.0.0 + 3.13.0 3.0.0-M4 - 2.7 - 2.8.2 - 3.0.0 + + + 4.0.0 + true + true + true + + true + + org.junit + junit-bom + ${junit-jupiter.version} + pom + import + + + org.springframework + spring-framework-bom + ${spring-framework.version} + pom + import + + + org.springframework.data + spring-data-releasetrain + ${spring-data-releasetrain.version} + pom + import + + + org.springframework.security + spring-security-bom + ${spring-security.version} + pom + import + + + org.springframework.session + spring-session-bom + ${spring-session-bom.version} + pom + import + + org.webjars font-awesome @@ -90,28 +179,162 @@ ckeditor 4.11.3 + + + org.thymeleaf + thymeleaf + ${thymeleaf.version} + + + org.thymeleaf + thymeleaf-spring5 + ${thymeleaf.version} + + + org.thymeleaf.extras + thymeleaf-extras-java8time + ${thymeleaf-extras-java8time.version} + + + org.thymeleaf.extras + thymeleaf-extras-springsecurity5 + ${thymeleaf-extras-springsecurity.version} + io.github.jpenren thymeleaf-spring-data-dialect 3.4.0 + + + org.projectlombok + lombok + ${lombok.version} + false + + org.jsoup jsoup 1.8.3 + + + org.hamcrest + hamcrest + ${hamcrest.version} + test + - org.junit.jupiter - junit-jupiter-engine - 5.4.0 + org.hamcrest + hamcrest-core + ${hamcrest.version} test - org.junit.jupiter - junit-jupiter-api - 5.4.0 + org.hamcrest + hamcrest-library + ${hamcrest.version} test + + + org.apache.maven.plugins + maven-enforcer-plugin + ${maven-enforcer-plugin.version} + maven-plugin + + + org.apache.maven.plugins + maven-invoker-plugin + ${maven-invoker-plugin.version} + maven-plugin + + + com.dkanejs.maven.plugins + docker-compose-maven-plugin + ${version.docker-compose-maven-plugin} + maven-plugin + + + org.apache.maven.plugins + maven-clean-plugin + ${maven-clean-plugin.version} + maven-plugin + + + org.apache.maven.plugins + maven-dependency-plugin + ${maven-dependency-plugin.version} + maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + ${maven-compiler-plugin.version} + maven-plugin + + + org.springframework.boot + spring-boot-maven-plugin + ${spring-boot-maven-plugin.version} + maven-plugin + + + + org.apache.maven.plugins + maven-site-plugin + 3.9.0 + maven-plugin + + + org.apache.maven.plugins + maven-project-info-reports-plugin + ${maven-project-info-reports-plugin.version} + maven-plugin + + + org.apache.maven.plugins + maven-jxr-plugin + ${maven-jxr-plugin.version} + maven-plugin + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${maven-checkstyle-plugin.version} + maven-plugin + + + com.github.spotbugs + spotbugs-maven-plugin + ${spotbugs-maven-plugin.version} + maven-plugin + + + org.apache.maven.plugins + maven-pmd-plugin + ${maven-pmd-plugin.version} + maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + ${maven-surefire-plugin.version} + maven-plugin + + + org.apache.maven.plugins + maven-surefire-report-plugin + ${maven-surefire-report-plugin.version} + maven-plugin + + + org.apache.maven.plugins + maven-changes-plugin + ${maven-changes-plugin.version} + maven-plugin + @@ -145,9 +368,27 @@ org.springframework.boot spring-boot-starter-security + + org.springframework.boot + spring-boot-devtools + runtime + true + org.springframework.boot spring-boot-starter-test + test + + + org.junit.vintage + junit-vintage-engine + + + + + org.springframework.security + spring-security-test + test org.postgresql @@ -196,22 +437,28 @@ com.github.mxab.thymeleaf.extras thymeleaf-extras-data-attribute + + + org.thymeleaf + thymeleaf + org.thymeleaf thymeleaf-spring5 org.thymeleaf.extras - thymeleaf-extras-springsecurity5 + thymeleaf-extras-java8time org.thymeleaf.extras - thymeleaf-extras-java8time + thymeleaf-extras-springsecurity5 io.github.jpenren thymeleaf-spring-data-dialect + org.jsoup jsoup @@ -226,34 +473,143 @@ junit-jupiter-api test + + + org.apache.maven.plugins + maven-enforcer-plugin + maven-plugin + + + org.apache.maven.plugins + maven-invoker-plugin + maven-plugin + + + com.dkanejs.maven.plugins + docker-compose-maven-plugin + maven-plugin + + + org.apache.maven.plugins + maven-clean-plugin + maven-plugin + + + org.apache.maven.plugins + maven-dependency-plugin + maven-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + maven-plugin + + + org.springframework.boot + spring-boot-maven-plugin + maven-plugin + + + + org.apache.maven.plugins + maven-site-plugin + maven-plugin + + + org.apache.maven.plugins + maven-project-info-reports-plugin + maven-plugin + + + org.apache.maven.plugins + maven-jxr-plugin + maven-plugin + + + org.apache.maven.plugins + maven-checkstyle-plugin + maven-plugin + + + com.github.spotbugs + spotbugs-maven-plugin + maven-plugin + + + org.apache.maven.plugins + maven-pmd-plugin + maven-plugin + + + org.apache.maven.plugins + maven-surefire-plugin + maven-plugin + + + org.apache.maven.plugins + maven-surefire-report-plugin + maven-plugin + + + org.apache.maven.plugins + maven-changes-plugin + maven-plugin + ${project.artifactId} + + org.apache.maven.plugins + maven-enforcer-plugin + ${maven-enforcer-plugin.version} + com.dkanejs.maven.plugins docker-compose-maven-plugin ${version.docker-compose-maven-plugin} + + + org.apache.maven.plugins + maven-project-info-reports-plugin + ${maven-project-info-reports-plugin.version} + + + org.apache.maven.plugins + maven-changes-plugin + ${maven-changes-plugin.version} + + + org.apache.maven.plugins + maven-jxr-plugin + ${maven-jxr-plugin.version} + + + org.apache.maven.plugins + maven-checkstyle-plugin + ${maven-checkstyle-plugin.version} + + + com.github.spotbugs + spotbugs-maven-plugin + ${spotbugs-maven-plugin.version} + + + org.apache.maven.plugins + maven-pmd-plugin + ${maven-pmd-plugin.version} + + + org.apache.maven.plugins + maven-surefire-report-plugin + ${maven-surefire-report-plugin.version} + - - org.apache.maven.plugins - maven-compiler-plugin - - ${java.version} - ${java.version} - ${project.build.sourceEncoding} - - -Xlint:all,-options,-path - - true - true - - org.apache.maven.plugins maven-enforcer-plugin @@ -307,8 +663,8 @@ docker-compose-maven-plugin ${project.basedir}/docker-compose.yml - true - true + ${docker-compose-maven-plugin.verbose} + ${docker-compose-maven-plugin.removeImages} true true true @@ -414,11 +770,25 @@ org.webjars weld-probe-core false - ${project.build.directory}/dependencies/ + ${project.build.directory}/dependency-sources/ + + org.apache.maven.plugins + maven-compiler-plugin + + ${java.version} + ${java.version} + ${project.build.sourceEncoding} + + -Xlint:all,-options,-path + + true + true + + @@ -447,6 +817,25 @@ + pre-integration-test + + start + + + ${skipTests} + + + + post-integration-test + + stop + + + ${skipTests} + + + + id-build-info build-info @@ -465,7 +854,11 @@ org.apache.maven.plugins maven-surefire-plugin - true + ${skipTests} + + default + ${skipTests} + @@ -500,10 +893,6 @@ - - org.apache.maven.plugins - maven-dependency-plugin - org.apache.maven.plugins maven-surefire-plugin @@ -517,273 +906,20 @@ - - - qa - - - - org.springframework.boot - spring-boot-maven-plugin - - true - - qa - - - - - pre-integration-test - - start - - - - post-integration-test - - stop - - - - - build-info - - - - ${project.build.sourceEncoding} - ${project.reporting.outputEncoding} - ${maven.compiler.source} - ${maven.compiler.target} - - - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - org.apache.maven.plugins - maven-surefire-plugin - - - qa - - false - - - - - - - - developing - - - - org.springframework.boot - spring-boot-maven-plugin - - true - - developing - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - unpack-dependencies - package - - analyze-only - analyze-report - - build-classpath - - - false - true - ${project.build.outputDirectory}/classpath.txt - false - - org.apache.maven.plugins:maven-surefire-plugin - org.apache.maven.scm:maven-scm - org.apache.maven.scm:maven-scm-providers-git - org.apache.maven.scm:maven-scm-providers-standard - org.apache.maven.scm:maven-scm-providers - org.apache.maven.scm:maven-scm-managers - - - org.apache.maven.plugins:maven-surefire-plugin - - - org.apache.maven.plugins:maven-surefire-plugin - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - developing - - true - - - - - - - - - travis - - - - org.springframework.boot - spring-boot-maven-plugin - - - travis - - - - - pre-integration-test - - start - - - - post-integration-test - - stop - - - - - build-info - - - - ${project.build.sourceEncoding} - ${project.reporting.outputEncoding} - ${maven.compiler.source} - ${maven.compiler.target} - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - travis - 1 - 1 - - - - - - - - - heroku - - - - org.springframework.boot - spring-boot-maven-plugin - - - default - - - - - - repackage - build-info - - - - ${project.build.sourceEncoding} - ${project.reporting.outputEncoding} - ${maven.compiler.source} - ${maven.compiler.target} - - - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - package - copy - - - unpack-dependencies - package - - analyze-only - build-classpath - - - ${project.build.directory}/classes - false - true - ${project.build.directory}/classpath.txt - false - - org.apache.maven.plugins:maven-surefire-plugin - org.apache.maven.scm:maven-scm - org.apache.maven.scm:maven-scm-providers-git - org.apache.maven.scm:maven-scm-providers-standard - org.apache.maven.scm:maven-scm-providers - org.apache.maven.scm:maven-scm-managers - - - org.apache.maven.plugins:maven-surefire-plugin - - - org.apache.maven.plugins:maven-surefire-plugin - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - - heroku - - true - - - - - + + org.apache.maven.plugins + maven-invoker-plugin + + ${project.build.directory}/it + src/it/settings.xml + ${project.build.directory}/it-repo + verify + + org.springframework.boot spring-boot-maven-plugin @@ -796,7 +932,6 @@ org.apache.maven.plugins maven-project-info-reports-plugin - 3.0.0 true true @@ -807,6 +942,22 @@ maven-dependency-plugin true + + org.apache.maven.plugins + maven-changes-plugin + + https + 443 + + + + id-github-report + + github-report + + + + org.apache.maven.plugins maven-source-plugin @@ -823,30 +974,21 @@ org.apache.maven.plugins maven-jxr-plugin - ${maven-jxr-plugin.version} org.apache.maven.plugins maven-checkstyle-plugin - ${maven-checkstyle-plugin.version} - - com.github.spotbugs - spotbugs-maven-plugin - 4.0.0 + + com.github.spotbugs + spotbugs-maven-plugin + + + - - com.github.spotbugs - spotbugs-maven-plugin - 4.0.0 - - - - org.apache.maven.plugins maven-pmd-plugin - 3.13.0 100 ${java.version} @@ -872,22 +1014,11 @@ org.apache.maven.plugins maven-surefire-report-plugin - 3.0.0-M4 true true - - org.apache.maven.plugins - maven-invoker-plugin - - ${project.build.directory}/it - src/it/settings.xml - ${project.build.directory}/it-repo - verify - - diff --git a/run.sh b/run.sh index 3c51c9c3..99ed1c96 100755 --- a/run.sh +++ b/run.sh @@ -1,11 +1,15 @@ #!/usr/bin/env bash -source setenv.sh +source etc/setenv.sh function runDev() { ./mvnw } +function runTest() { + ./mvnw -B -DskipTests=false clean dependency:list install --file pom.xml +} + function runGithubTestBuild() { ./mvnw -B -DskipTests clean dependency:list install --file pom.xml } @@ -16,7 +20,7 @@ function setupHeroku() { } function buildLikeHeroku() { - ./mvnw -DskipTests clean dependency:list install + ./mvnw -DskipTests clean dependency:list install site site:deploy } function runHerokuLocal() { @@ -27,10 +31,12 @@ function runHerokuLocal() { } function main() { - runGithubTestBuild + #runGithubTestBuild #setupHeroku - runHerokuLocal + buildLikeHeroku + #runHerokuLocal #runDev + #runTest } main diff --git a/src/main/java/org/woehlke/simpleworklist/breadcrumb/Breadcrumb.java b/src/main/java/org/woehlke/simpleworklist/breadcrumb/Breadcrumb.java index 0ce4ac16..57e62f4b 100644 --- a/src/main/java/org/woehlke/simpleworklist/breadcrumb/Breadcrumb.java +++ b/src/main/java/org/woehlke/simpleworklist/breadcrumb/Breadcrumb.java @@ -1,5 +1,8 @@ package org.woehlke.simpleworklist.breadcrumb; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; import org.woehlke.simpleworklist.project.Project; import org.woehlke.simpleworklist.task.Task; @@ -8,12 +11,14 @@ import java.util.List; import java.util.Locale; +@Getter +@EqualsAndHashCode +@ToString public class Breadcrumb implements Serializable { private static final long serialVersionUID = 7932703111140692689L; private List breadcrumb; - private final Locale locale; public Breadcrumb(Locale locale) { @@ -30,16 +35,12 @@ public Breadcrumb(Locale locale) { this.breadcrumb = breadcrumb; } - public List getBreadcrumb() { - return breadcrumb; - } - public int size(){ return breadcrumb.size(); } public void addProjectRoot(){ - String urlProject = "/project/0"; + String urlProject = "/project/root"; String name; if(this.locale == Locale.GERMAN){ name = "Projekte"; diff --git a/src/main/java/org/woehlke/simpleworklist/breadcrumb/BreadcrumbItem.java b/src/main/java/org/woehlke/simpleworklist/breadcrumb/BreadcrumbItem.java index 90937f80..d06c5c2e 100644 --- a/src/main/java/org/woehlke/simpleworklist/breadcrumb/BreadcrumbItem.java +++ b/src/main/java/org/woehlke/simpleworklist/breadcrumb/BreadcrumbItem.java @@ -1,9 +1,16 @@ package org.woehlke.simpleworklist.breadcrumb; +import lombok.*; + import javax.validation.constraints.NotNull; import java.io.Serializable; import java.util.Objects; +@Getter +@Setter +@NoArgsConstructor +@EqualsAndHashCode +@ToString public class BreadcrumbItem implements Serializable { private static final long serialVersionUID = 8276819198016077167L; @@ -14,49 +21,9 @@ public class BreadcrumbItem implements Serializable { @NotNull private String url; - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getUrl() { - return url; - } - - public void setUrl(String url) { - this.url = url; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof BreadcrumbItem)) return false; - BreadcrumbItem that = (BreadcrumbItem) o; - return getName().equals(that.getName()) && - getUrl().equals(that.getUrl()); - } - - @Override - public int hashCode() { - return Objects.hash(getName(), getUrl()); - } - - @Override - public String toString() { - return "BreadcrumbItem{" + - "name='" + name + '\'' + - ", url='" + url + '\'' + - '}'; - } - public BreadcrumbItem(@NotNull String name, @NotNull String url) { this.name = name; this.url = url; } - public BreadcrumbItem() { - } } diff --git a/src/main/java/org/woehlke/simpleworklist/breadcrumb/BreadcrumbService.java b/src/main/java/org/woehlke/simpleworklist/breadcrumb/BreadcrumbService.java index c9454993..1ba783b9 100644 --- a/src/main/java/org/woehlke/simpleworklist/breadcrumb/BreadcrumbService.java +++ b/src/main/java/org/woehlke/simpleworklist/breadcrumb/BreadcrumbService.java @@ -3,7 +3,7 @@ import org.woehlke.simpleworklist.context.Context; import org.woehlke.simpleworklist.project.Project; import org.woehlke.simpleworklist.task.Task; -import org.woehlke.simpleworklist.task.TaskState; +import org.woehlke.simpleworklist.taskstate.TaskState; import java.util.Locale; diff --git a/src/main/java/org/woehlke/simpleworklist/breadcrumb/BreadcrumbServiceImpl.java b/src/main/java/org/woehlke/simpleworklist/breadcrumb/BreadcrumbServiceImpl.java index a4b6b44d..2212bbc8 100644 --- a/src/main/java/org/woehlke/simpleworklist/breadcrumb/BreadcrumbServiceImpl.java +++ b/src/main/java/org/woehlke/simpleworklist/breadcrumb/BreadcrumbServiceImpl.java @@ -1,5 +1,6 @@ package org.woehlke.simpleworklist.breadcrumb; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.MessageSource; import org.springframework.stereotype.Service; @@ -8,11 +9,12 @@ import org.woehlke.simpleworklist.context.Context; import org.woehlke.simpleworklist.project.Project; import org.woehlke.simpleworklist.task.Task; -import org.woehlke.simpleworklist.task.TaskState; +import org.woehlke.simpleworklist.taskstate.TaskState; import java.util.Locale; import java.util.Stack; +@Slf4j @Service @Transactional(propagation = Propagation.REQUIRED, readOnly = true) public class BreadcrumbServiceImpl implements BreadcrumbService { @@ -26,6 +28,7 @@ public BreadcrumbServiceImpl(MessageSource messageSource) { @Override public Breadcrumb getBreadcrumbForShowRootProject(Locale locale) { + log.info("getBreadcrumbForShowRootProject"); Breadcrumb breadcrumb = new Breadcrumb(locale); breadcrumb.addProjectRoot(); return breadcrumb; @@ -33,6 +36,7 @@ public Breadcrumb getBreadcrumbForShowRootProject(Locale locale) { @Override public Breadcrumb getBreadcrumbForShowOneProject(Project thisProject, Locale locale) { + log.info("getBreadcrumbForShowOneProject"); Breadcrumb breadcrumb = new Breadcrumb(locale); breadcrumb.addProjectRoot(); if (thisProject.getId() > 0) { @@ -51,6 +55,7 @@ public Breadcrumb getBreadcrumbForShowOneProject(Project thisProject, Locale loc @Override public Breadcrumb getBreadcrumbForTaskstate(TaskState taskstate, Locale locale) { + log.info("getBreadcrumbForTaskstate"); Breadcrumb breadcrumb = new Breadcrumb(locale); String code = taskstate.getCode(); String name = messageSource.getMessage(code,null,locale); @@ -60,6 +65,7 @@ public Breadcrumb getBreadcrumbForTaskstate(TaskState taskstate, Locale locale) @Override public Breadcrumb getBreadcrumbForTaskInTaskstate(String taskstate, Task task, Locale locale) { + log.info("getBreadcrumbForTaskInTaskstate"); Breadcrumb breadcrumb = new Breadcrumb(locale); breadcrumb.addTaskstate(taskstate); breadcrumb.addTask(task); @@ -68,6 +74,7 @@ public Breadcrumb getBreadcrumbForTaskInTaskstate(String taskstate, Task task, L @Override public Breadcrumb getBreadcrumbForTaskstateAll(Locale locale) { + log.info("getBreadcrumbForTaskstateAll"); Breadcrumb breadcrumb = new Breadcrumb(locale); String code="layout.page.all"; String name= messageSource.getMessage(code,null,locale); @@ -78,6 +85,7 @@ public Breadcrumb getBreadcrumbForTaskstateAll(Locale locale) { @Override public Breadcrumb getBreadcrumbForTaskInProject(Project thisProject, Task task, Locale locale) { + log.info("getBreadcrumbForTaskInProject"); Breadcrumb breadcrumb = new Breadcrumb(locale); breadcrumb.addProject(thisProject); breadcrumb.addTask(task); @@ -86,6 +94,7 @@ public Breadcrumb getBreadcrumbForTaskInProject(Project thisProject, Task task, @Override public Breadcrumb getBreadcrumbForUserProfileAndMenu(Locale locale) { + log.info("getBreadcrumbForUserProfileAndMenu"); Breadcrumb breadcrumb = new Breadcrumb(locale); String code="pages.user.profile"; String name= messageSource.getMessage(code,null,locale); @@ -96,6 +105,7 @@ public Breadcrumb getBreadcrumbForUserProfileAndMenu(Locale locale) { @Override public Breadcrumb getBreadcrumbForUserChangeName(Locale locale) { + log.info("getBreadcrumbForUserChangeName"); Breadcrumb breadcrumb = new Breadcrumb(locale); String code="pages.user.profile"; String name= messageSource.getMessage(code,null,locale); @@ -110,6 +120,7 @@ public Breadcrumb getBreadcrumbForUserChangeName(Locale locale) { @Override public Breadcrumb getBreadcrumbForUserChangePassword(Locale locale) { + log.info("getBreadcrumbForUserChangePassword"); Breadcrumb breadcrumb = new Breadcrumb(locale); String code="pages.user.profile"; String name= messageSource.getMessage(code,null,locale); @@ -124,6 +135,7 @@ public Breadcrumb getBreadcrumbForUserChangePassword(Locale locale) { @Override public Breadcrumb getBreadcrumbForUserContexts(Locale locale) { + log.info("getBreadcrumbForUserContexts"); Breadcrumb breadcrumb = new Breadcrumb(locale); String code="pages.user.profile"; String name= messageSource.getMessage(code,null,locale); @@ -138,6 +150,7 @@ public Breadcrumb getBreadcrumbForUserContexts(Locale locale) { @Override public Breadcrumb getBreadcrumbForUserContextAdd(Locale locale) { + log.info("getBreadcrumbForUserContextAdd"); Breadcrumb breadcrumb = new Breadcrumb(locale); String code="pages.user.profile"; String name= messageSource.getMessage(code,null,locale); @@ -152,6 +165,7 @@ public Breadcrumb getBreadcrumbForUserContextAdd(Locale locale) { @Override public Breadcrumb getBreadcrumbForUserContextEdit(Locale locale, Context context) { + log.info("getBreadcrumbForUserContextEdit"); Breadcrumb breadcrumb = new Breadcrumb(locale); String code="pages.user.profile"; String name= messageSource.getMessage(code,null,locale); @@ -166,6 +180,7 @@ public Breadcrumb getBreadcrumbForUserContextEdit(Locale locale, Context context @Override public Breadcrumb getBreadcrumbForUserContextDelete(Locale locale, Context context) { + log.info("getBreadcrumbForUserContextDelete"); Breadcrumb breadcrumb = new Breadcrumb(locale); String code="pages.user.profile"; String name= messageSource.getMessage(code,null,locale); @@ -180,6 +195,7 @@ public Breadcrumb getBreadcrumbForUserContextDelete(Locale locale, Context conte @Override public Breadcrumb getBreadcrumbForUserChangeLanguage(Locale locale) { + log.info("getBreadcrumbForUserChangeLanguage"); Breadcrumb breadcrumb = new Breadcrumb(locale); String code="pages.user.profile"; String name= messageSource.getMessage(code,null,locale); @@ -194,6 +210,7 @@ public Breadcrumb getBreadcrumbForUserChangeLanguage(Locale locale) { @Override public Breadcrumb getBreadcrumbForMessagesBetweenCurrentAndOtherUser(Locale locale) { + log.info("getBreadcrumbForMessagesBetweenCurrentAndOtherUser"); Breadcrumb breadcrumb = new Breadcrumb(locale); String code="pages.user.profile"; String name= messageSource.getMessage(code,null,locale); @@ -208,6 +225,7 @@ public Breadcrumb getBreadcrumbForMessagesBetweenCurrentAndOtherUser(Locale loca @Override public Breadcrumb getBreadcrumbForSearchResults(Locale locale) { + log.info("getBreadcrumbForSearchResults"); Breadcrumb breadcrumb = new Breadcrumb(locale); String code="pages.user.profile"; String name= messageSource.getMessage(code,null,locale); @@ -220,5 +238,4 @@ public Breadcrumb getBreadcrumbForSearchResults(Locale locale) { return breadcrumb; } - } diff --git a/src/main/java/org/woehlke/simpleworklist/common/ComparableById.java b/src/main/java/org/woehlke/simpleworklist/common/ComparableById.java index c4d123bd..af6a9108 100644 --- a/src/main/java/org/woehlke/simpleworklist/common/ComparableById.java +++ b/src/main/java/org/woehlke/simpleworklist/common/ComparableById.java @@ -1,7 +1,5 @@ package org.woehlke.simpleworklist.common; -import org.woehlke.simpleworklist.common.AuditModel; - public interface ComparableById { boolean equalsById(T otherObject); boolean equalsByUniqueConstraint(T otherObject); diff --git a/src/main/java/org/woehlke/simpleworklist/context/Context.java b/src/main/java/org/woehlke/simpleworklist/context/Context.java index ce0dd2b7..830a47b2 100644 --- a/src/main/java/org/woehlke/simpleworklist/context/Context.java +++ b/src/main/java/org/woehlke/simpleworklist/context/Context.java @@ -1,5 +1,6 @@ package org.woehlke.simpleworklist.context; +import lombok.*; import org.hibernate.validator.constraints.Length; import javax.validation.constraints.NotBlank; import org.hibernate.validator.constraints.SafeHtml; @@ -29,6 +30,11 @@ @Index(name = "ix_context_row_created_at", columnList = "row_created_at") } ) +@Getter +@Setter +@NoArgsConstructor +@EqualsAndHashCode +@ToString public class Context extends AuditModel implements Serializable, ComparableById { private static final long serialVersionUID = -5035732370606951871L; @@ -36,19 +42,19 @@ public class Context extends AuditModel implements Serializable, ComparableById< @Id @GeneratedValue(generator = "context_generator") @SequenceGenerator( - name = "context_generator", - sequenceName = "context_sequence", - initialValue = 1000 + name = "context_generator", + sequenceName = "context_sequence", + initialValue = 1000 ) private Long id; @ManyToOne( - fetch = FetchType.LAZY, - optional = false, - cascade = { - CascadeType.MERGE, - CascadeType.REFRESH - }) + fetch = FetchType.LAZY, + optional = false, + cascade = { + CascadeType.MERGE, + CascadeType.REFRESH + }) @JoinColumn(name = "user_account_id") private UserAccount userAccount; @@ -64,9 +70,6 @@ public class Context extends AuditModel implements Serializable, ComparableById< @Column(name = "name_en", nullable = false) private String nameEn; - public Context() { - } - public Context(String nameDe, String nameEn) { this.nameDe = nameDe; this.nameEn = nameEn; @@ -99,66 +102,4 @@ public boolean equalsByUuid(Context otherObject) { return super.equalsByMyUuid(otherObject); } - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public UserAccount getUserAccount() { - return userAccount; - } - - public void setUserAccount(UserAccount userAccount) { - this.userAccount = userAccount; - } - - public String getNameDe() { - return nameDe; - } - - public void setNameDe(String name) { - this.nameDe = name; - } - - public String getNameEn() { - return nameEn; - } - - public void setNameEn(String nameEn) { - this.nameEn = nameEn; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof Context)) return false; - if (!super.equals(o)) return false; - Context context = (Context) o; - return Objects.equals(getId(), context.getId()) && - getUserAccount().equals(context.getUserAccount()) && - getNameDe().equals(context.getNameDe()) && - getNameEn().equals(context.getNameEn()); - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), getId(), getUserAccount(), getNameDe(), getNameEn()); - } - - @Override - public String toString() { - return "Context{" + - "id=" + id + - ", userAccount=" + userAccount + - ", nameDe='" + nameDe + '\'' + - ", nameEn='" + nameEn + '\'' + - ", uuid='" + uuid + '\'' + - ", rowCreatedAt=" + rowCreatedAt + - ", rowUpdatedAt=" + rowUpdatedAt + - '}'; - } - } diff --git a/src/main/java/org/woehlke/simpleworklist/context/ContextController.java b/src/main/java/org/woehlke/simpleworklist/context/ContextController.java index 5f94933c..b64d3003 100644 --- a/src/main/java/org/woehlke/simpleworklist/context/ContextController.java +++ b/src/main/java/org/woehlke/simpleworklist/context/ContextController.java @@ -1,5 +1,6 @@ package org.woehlke.simpleworklist.context; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ModelAttribute; @@ -14,8 +15,9 @@ /** * Created by tw on 13.03.16. */ +@Slf4j @Controller -@RequestMapping(value = "/context") +@RequestMapping(path = "/context") public class ContextController extends AbstractController { private final ContextService contextService; @@ -25,9 +27,13 @@ public ContextController(ContextService contextService) { this.contextService = contextService; } - @RequestMapping(value = "/choose/{newContextId}", method = RequestMethod.GET) - public String switchContxt(@PathVariable("newContextId") Context setContext, - @ModelAttribute("userSession") UserSessionBean userSession, Model model){ + @RequestMapping(path = "/choose/{newContextId}", method = RequestMethod.GET) + public String switchContxt( + @PathVariable("newContextId") Context setContext, + @ModelAttribute("userSession") UserSessionBean userSession, + Model model + ){ + log.info("switchContxt"); Context isContext = super.getContext(userSession); if (setContext != null) { userSession.setContextId(setContext.getId()); diff --git a/src/main/java/org/woehlke/simpleworklist/context/ContextService.java b/src/main/java/org/woehlke/simpleworklist/context/ContextService.java index 2e95bcab..def131bb 100644 --- a/src/main/java/org/woehlke/simpleworklist/context/ContextService.java +++ b/src/main/java/org/woehlke/simpleworklist/context/ContextService.java @@ -13,9 +13,9 @@ public interface ContextService { Context findByIdAndUserAccount(long newContextId, UserAccount userAccount); - void createNewContext(NewContextForm newContext, UserAccount user); + Context createNewContext(NewContextForm newContext, UserAccount user); - void updateContext(Context context); + Context updateContext(Context context); boolean delete(Context context); diff --git a/src/main/java/org/woehlke/simpleworklist/context/ContextServiceImpl.java b/src/main/java/org/woehlke/simpleworklist/context/ContextServiceImpl.java index f03a8c6d..10fb79cf 100644 --- a/src/main/java/org/woehlke/simpleworklist/context/ContextServiceImpl.java +++ b/src/main/java/org/woehlke/simpleworklist/context/ContextServiceImpl.java @@ -1,5 +1,6 @@ package org.woehlke.simpleworklist.context; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @@ -13,14 +14,13 @@ /** * Created by tw on 13.03.16. */ +@Slf4j @Service @Transactional(propagation = Propagation.REQUIRED, readOnly = true) public class ContextServiceImpl implements ContextService { private final ContextRepository contextRepository; - private final TaskRepository taskRepository; - private final ProjectRepository projectRepository; @Autowired @@ -32,11 +32,13 @@ public ContextServiceImpl(ContextRepository contextRepository, TaskRepository ta @Override public List getAllForUser(UserAccount user) { + log.info("getAllForUser"); return contextRepository.findByUserAccount(user); } @Override public Context findByIdAndUserAccount(long newContextId, UserAccount userAccount) { + log.info("findByIdAndUserAccount"); if(newContextId == 0){ newContextId = userAccount.getDefaultContext().getId(); } @@ -45,23 +47,26 @@ public Context findByIdAndUserAccount(long newContextId, UserAccount userAccount @Override @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) - public void createNewContext(NewContextForm newContext, UserAccount user) { + public Context createNewContext(NewContextForm newContext, UserAccount user) { + log.info("createNewContext"); Context context = new Context(); context.setNameEn(newContext.getNameEn()); context.setNameDe(newContext.getNameDe()); context.setUserAccount(user); - contextRepository.saveAndFlush(context); + return contextRepository.saveAndFlush(context); } @Override @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) - public void updateContext(Context context) { - contextRepository.saveAndFlush(context); + public Context updateContext(Context context) { + log.info("updateContext"); + return contextRepository.saveAndFlush(context); } @Override @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) public boolean delete(Context context) { + log.info("delete"); long contextId = context.getId(); contextRepository.delete(context); return (!contextRepository.existsById(contextId)); @@ -69,6 +74,7 @@ public boolean delete(Context context) { @Override public boolean contextHasItems(Context context) { + log.info("contextHasItems"); long numberOfTasks = taskRepository.findByContext(context).size(); int numberOfProjects = projectRepository.findByContext(context).size(); return ((numberOfTasks + numberOfProjects) > 0); diff --git a/src/main/java/org/woehlke/simpleworklist/context/NewContextForm.java b/src/main/java/org/woehlke/simpleworklist/context/NewContextForm.java index 3f09f728..c92d81cd 100644 --- a/src/main/java/org/woehlke/simpleworklist/context/NewContextForm.java +++ b/src/main/java/org/woehlke/simpleworklist/context/NewContextForm.java @@ -1,5 +1,6 @@ package org.woehlke.simpleworklist.context; +import lombok.*; import org.hibernate.validator.constraints.Length; import javax.validation.constraints.NotBlank; import org.hibernate.validator.constraints.SafeHtml; @@ -9,6 +10,12 @@ /** * Created by tw on 15.03.16. */ +@Getter +@Setter +@EqualsAndHashCode +@ToString +@NoArgsConstructor +@AllArgsConstructor public class NewContextForm implements Serializable { private static final long serialVersionUID = -937143305653156981L; @@ -23,46 +30,4 @@ public class NewContextForm implements Serializable { @Length(min = 1, max = 255) private String nameEn; - public String getNameDe() { - return nameDe; - } - - public void setNameDe(String nameDe) { - this.nameDe = nameDe; - } - - public String getNameEn() { - return nameEn; - } - - public void setNameEn(String nameEn) { - this.nameEn = nameEn; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof NewContextForm)) return false; - - NewContextForm that = (NewContextForm) o; - - if (nameDe != null ? !nameDe.equals(that.nameDe) : that.nameDe != null) return false; - return nameEn != null ? nameEn.equals(that.nameEn) : that.nameEn == null; - - } - - @Override - public int hashCode() { - int result = nameDe != null ? nameDe.hashCode() : 0; - result = 31 * result + (nameEn != null ? nameEn.hashCode() : 0); - return result; - } - - @Override - public String toString() { - return "NewContextForm{" + - "nameDe='" + nameDe + '\'' + - ", nameEn='" + nameEn + '\'' + - '}'; - } } diff --git a/src/main/java/org/woehlke/simpleworklist/context/UserChangeDefaultContextForm.java b/src/main/java/org/woehlke/simpleworklist/context/UserChangeDefaultContextForm.java index a2f8ddf2..b1f9cb35 100644 --- a/src/main/java/org/woehlke/simpleworklist/context/UserChangeDefaultContextForm.java +++ b/src/main/java/org/woehlke/simpleworklist/context/UserChangeDefaultContextForm.java @@ -1,11 +1,19 @@ package org.woehlke.simpleworklist.context; +import lombok.*; + import javax.validation.constraints.NotNull; import java.io.Serializable; /** * Created by Fert on 16.03.2016. */ +@Getter +@Setter +@EqualsAndHashCode +@ToString +@AllArgsConstructor +@NoArgsConstructor public class UserChangeDefaultContextForm implements Serializable { private static final long serialVersionUID = -8592295563275083292L; @@ -16,46 +24,4 @@ public class UserChangeDefaultContextForm implements Serializable { @NotNull private Context defaultContext; - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public Context getDefaultContext() { - return defaultContext; - } - - public void setDefaultContext(Context defaultContext) { - this.defaultContext = defaultContext; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof UserChangeDefaultContextForm)) return false; - - UserChangeDefaultContextForm that = (UserChangeDefaultContextForm) o; - - if (id != null ? !id.equals(that.id) : that.id != null) return false; - return defaultContext != null ? defaultContext.equals(that.defaultContext) : that.defaultContext == null; - - } - - @Override - public int hashCode() { - int result = id != null ? id.hashCode() : 0; - result = 31 * result + (defaultContext != null ? defaultContext.hashCode() : 0); - return result; - } - - @Override - public String toString() { - return "UserChangeDefaultContextForm{" + - "id=" + id + - ", defaultContext=" + defaultContext + - '}'; - } } diff --git a/src/main/java/org/woehlke/simpleworklist/error/MyErrorController.java b/src/main/java/org/woehlke/simpleworklist/error/MyErrorController.java index 998ba2bc..bd887480 100644 --- a/src/main/java/org/woehlke/simpleworklist/error/MyErrorController.java +++ b/src/main/java/org/woehlke/simpleworklist/error/MyErrorController.java @@ -5,25 +5,31 @@ import org.springframework.boot.web.servlet.error.ErrorController; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import javax.servlet.RequestDispatcher; import javax.servlet.http.HttpServletRequest; +import static javax.servlet.RequestDispatcher.*; +import static org.springframework.web.bind.annotation.RequestMethod.*; + @Slf4j @Controller +@RequestMapping(path="/fehler") public class MyErrorController implements ErrorController { - @RequestMapping(path="/fehler", method={RequestMethod.GET,RequestMethod.POST, RequestMethod.PUT}) - public String handleError(HttpServletRequest request, Model model) { - String errorMessage = (String) request.getAttribute(RequestDispatcher.ERROR_MESSAGE); + @ExceptionHandler + @RequestMapping(path="/", method={ GET, POST, PUT, HEAD, PATCH, DELETE, OPTIONS, TRACE }) + public String handleError( + HttpServletRequest request + ) { + log.info("handleError"); + String errorMessage = (String) request.getAttribute(ERROR_MESSAGE); if(errorMessage!=null){ log.warn("errorMessage :"+errorMessage); } - Integer statusCode = (Integer) request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE); + Integer statusCode = (Integer) request.getAttribute(ERROR_STATUS_CODE); if(statusCode != null){ HttpStatus httpStatus = HttpStatus.valueOf(statusCode); log.warn(httpStatus.value()+""+httpStatus.getReasonPhrase()); @@ -80,7 +86,7 @@ public String handleError(HttpServletRequest request, Model model) { return "redirect:/login?login_error=1"; } } - Throwable exception = (Throwable) request.getAttribute(RequestDispatcher.ERROR_EXCEPTION); + Throwable exception = (Throwable) request.getAttribute(ERROR_EXCEPTION); if(exception != null) { log.warn("##################################################"); log.warn("Exception :" + exception.getMessage()); diff --git a/src/main/java/org/woehlke/simpleworklist/language/UserChangeLanguageForm.java b/src/main/java/org/woehlke/simpleworklist/language/UserChangeLanguageForm.java index 59dccba7..aaaa82ed 100644 --- a/src/main/java/org/woehlke/simpleworklist/language/UserChangeLanguageForm.java +++ b/src/main/java/org/woehlke/simpleworklist/language/UserChangeLanguageForm.java @@ -1,11 +1,19 @@ package org.woehlke.simpleworklist.language; +import lombok.*; + import javax.validation.constraints.NotNull; import java.io.Serializable; /** * Created by Fert on 15.03.2016. */ +@Getter +@Setter +@EqualsAndHashCode +@ToString +@NoArgsConstructor +@AllArgsConstructor public class UserChangeLanguageForm implements Serializable { private static final long serialVersionUID = 2201123162578113187L; @@ -13,40 +21,4 @@ public class UserChangeLanguageForm implements Serializable { @NotNull private Language defaultLanguage; - public UserChangeLanguageForm(){} - - public UserChangeLanguageForm(Language defaultLanguage){ - this.defaultLanguage=defaultLanguage; - } - - public Language getDefaultLanguage() { - return defaultLanguage; - } - - public void setDefaultLanguage(Language defaultLanguage) { - this.defaultLanguage = defaultLanguage; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof UserChangeLanguageForm)) return false; - - UserChangeLanguageForm that = (UserChangeLanguageForm) o; - - return defaultLanguage == that.defaultLanguage; - - } - - @Override - public int hashCode() { - return defaultLanguage != null ? defaultLanguage.hashCode() : 0; - } - - @Override - public String toString() { - return "UserChangeLanguageForm{" + - "defaultLanguage=" + defaultLanguage + - '}'; - } } diff --git a/src/main/java/org/woehlke/simpleworklist/project/ProjectController.java b/src/main/java/org/woehlke/simpleworklist/project/ProjectController.java index c0a16e04..a43d68b4 100644 --- a/src/main/java/org/woehlke/simpleworklist/project/ProjectController.java +++ b/src/main/java/org/woehlke/simpleworklist/project/ProjectController.java @@ -3,6 +3,7 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; import org.springframework.data.web.PageableDefault; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -12,6 +13,10 @@ import org.woehlke.simpleworklist.common.AbstractController; import org.woehlke.simpleworklist.context.Context; import org.woehlke.simpleworklist.task.Task; +import org.woehlke.simpleworklist.task.TaskEnergy; +import org.woehlke.simpleworklist.task.TaskTime; +import org.woehlke.simpleworklist.taskstate.TaskMoveService; +import org.woehlke.simpleworklist.taskstate.TaskState; import org.woehlke.simpleworklist.user.account.UserAccount; import org.woehlke.simpleworklist.breadcrumb.Breadcrumb; import org.woehlke.simpleworklist.user.UserSessionBean; @@ -30,16 +35,145 @@ public class ProjectController extends AbstractController { private final ProjectControllerService projectControllerService; + private final TaskMoveService taskMoveService; @Autowired - public ProjectController(ProjectControllerService projectControllerService) { + public ProjectController(ProjectControllerService projectControllerService, TaskMoveService taskMoveService) { this.projectControllerService = projectControllerService; + this.taskMoveService = taskMoveService; + } + + @RequestMapping(path="/root", method = RequestMethod.GET) + public final String showRootProject( + @PageableDefault(sort = "orderIdProject", direction = Sort.Direction.DESC) Pageable pageable, + @RequestParam(required = false) String message, + @RequestParam(required = false) boolean isDeleted, + @ModelAttribute("userSession") UserSessionBean userSession, + Locale locale, Model model + ) { + log.info("/project/root"); + Context context = super.getContext(userSession); + userSession.setLastProjectId(0L); + model.addAttribute("userSession",userSession); + Page taskPage = taskService.findByRootProject(context,pageable); + Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForShowRootProject(locale); + model.addAttribute("breadcrumb", breadcrumb); + model.addAttribute("taskPage", taskPage); + if(message != null){ + model.addAttribute("message",message); + model.addAttribute("isDeleted",isDeleted); + model.addAttribute("myTaskState","PROJECT"); + } + return "project/root/show"; + } + + @RequestMapping(path = "/root/add/project", method = RequestMethod.GET) + public final String addNewTopLevelProjectForm( + @ModelAttribute("userSession") UserSessionBean userSession, + Locale locale, Model model + ){ + log.info("/project/root/add/project (GET)"); + Context context = super.getContext(userSession); + projectControllerService.addNewProjectToRoot(userSession, context, locale, model); + return "project/root/add/project"; + } + + @RequestMapping(path = "/root/add/project", method = RequestMethod.POST) + public final String addNewTopLevelProjectSave( + @Valid Project project, + @ModelAttribute("userSession") UserSessionBean userSession, + BindingResult result, + Locale locale, Model model + ){ + log.info("/project/root/add/project (POST)"); + Context context = super.getContext(userSession); + return projectControllerService.addNewProjectToRootPersist( + userSession, + project, + context, + result, + locale, + model, + "redirect:/project/" + ); + } + + @RequestMapping(path = "/root/add/task", method = RequestMethod.GET) + public final String addNewTaskToRootProjectGet( + @ModelAttribute("userSession") UserSessionBean userSession, + Locale locale, Model model + ) { + log.info("/project/root/add/task (GET)"); + Context context = super.getContext(userSession); + UserAccount userAccount = context.getUserAccount(); + Task task = new Task(); + task.setTaskState(TaskState.INBOX); + task.setTaskEnergy(TaskEnergy.NONE); + task.setTaskTime(TaskTime.NONE); + Project thisProject; + Boolean mustChooseArea = false; + thisProject = new Project(); + thisProject.setId(0L); + if(userSession.getContextId() == 0L){ + mustChooseArea = true; + task.setContext(userAccount.getDefaultContext()); + thisProject.setContext(userAccount.getDefaultContext()); + } else { + task.setContext(context); + thisProject.setContext(context); + } + Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForShowOneProject(thisProject,locale); + model.addAttribute("breadcrumb", breadcrumb); + model.addAttribute("mustChooseArea", mustChooseArea); + model.addAttribute("thisProject", thisProject); + model.addAttribute("thisProjectId", thisProject.getId()); + model.addAttribute("breadcrumb", breadcrumb); + model.addAttribute("task", task); + return "project/root/add/task"; + } + + @RequestMapping(path = "/root/add/task", method = RequestMethod.POST) + public final String addNewTaskToRootProjectPost( + @ModelAttribute("userSession") UserSessionBean userSession, + @Valid Task task, + BindingResult result, Locale locale, Model model + ) { + log.info("/project/root/add/task (POST)"); + Context context = super.getContext(userSession); + if (result.hasErrors()) { + for (ObjectError e : result.getAllErrors()) { + log.info(e.toString()); + } + Boolean mustChooseArea = false; + task.setContext(context); + Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForTaskstate(TaskState.INBOX,locale); + model.addAttribute("mustChooseArea", mustChooseArea); + model.addAttribute("breadcrumb", breadcrumb); + model.addAttribute("task", task); + return "project/root/add/task"; + } else { + task.setProject(null); + if(task.getDueDate()==null){ + task.setTaskState(TaskState.INBOX); + } else { + task.setTaskState(TaskState.SCHEDULED); + } + task.setFocus(false); + task.setContext(context); + long maxOrderIdProject = taskMoveService.getMaxOrderIdProject(task.getProject(),context); + task.setOrderIdProject(++maxOrderIdProject); + long maxOrderIdTaskState = taskMoveService.getMaxOrderIdTaskState(task.getTaskState(),task.getContext()); + task.setOrderIdTaskState(++maxOrderIdTaskState); + task = taskService.saveAndFlush(task); + log.info(task.toString()); + return "redirect:/project/root"; + } } @RequestMapping(path = "/{projectId}", method = RequestMethod.GET) public final String showProject( @PathVariable long projectId, - @PageableDefault(sort = "orderIdProject") Pageable pageable, + @PageableDefault(sort = "orderIdProject", direction = Sort.Direction.DESC) Pageable pageable, @RequestParam(required = false) String message, @RequestParam(required = false) boolean isDeleted, @ModelAttribute("userSession") UserSessionBean userSession, @@ -68,10 +202,10 @@ public final String showProject( model.addAttribute("message",message); model.addAttribute("isDeleted",isDeleted); } - return "project/show"; + return "project/id/show"; } - @RequestMapping(path = "/{projectId}/add/new/project", method = RequestMethod.GET) + @RequestMapping(path = "/{projectId}/add/project", method = RequestMethod.GET) public final String addNewSubProjectGet( @PathVariable long projectId, @ModelAttribute("userSession") UserSessionBean userSession, @@ -80,10 +214,10 @@ public final String addNewSubProjectGet( log.info("private addNewProjectGet (GET) projectId="+projectId); Context context = super.getContext(userSession); projectControllerService.addNewProject(projectId, userSession, context, locale, model); - return "project/add"; + return "project/id/add/project"; } - @RequestMapping(path = "/{projectId}/add/new/project", method = {RequestMethod.POST, RequestMethod.PUT}) + @RequestMapping(path = "/{projectId}/add/project", method = {RequestMethod.POST, RequestMethod.PUT}) public final String addNewSubProjectPost( @PathVariable long projectId, @ModelAttribute("userSession") UserSessionBean userSession, @@ -92,12 +226,20 @@ public final String addNewSubProjectPost( Locale locale, Model model) { log.info("private addNewProjectPost (POST) projectId="+projectId+" "+project.toString()); Context context = super.getContext(userSession); - return projectControllerService.addNewProjectPersist( projectId, userSession, project, context, - result, locale, model ,"project/add"); + return projectControllerService.addNewProjectPersist( + projectId, + userSession, + project, + context, + result, + locale, + model , + "/add/project" + ); } - @RequestMapping(path = "/{thisProjectId}/move/to/{targetProjectId}", method = RequestMethod.GET) + @RequestMapping(path = "/{thisProjectId}/move/to/project/{targetProjectId}", method = RequestMethod.GET) public final String moveProject( @PathVariable("thisProjectId") Project thisProject, @PathVariable long targetProjectId, @@ -128,7 +270,7 @@ public final String editProjectGet( model.addAttribute("breadcrumb", breadcrumb); model.addAttribute("thisProject", thisProject); model.addAttribute("project", thisProject); - return "project/edit"; + return "project/id/edit"; } @RequestMapping(path = "/{projectId}/edit", method = RequestMethod.POST) @@ -150,7 +292,7 @@ public final String editProjectPost( Project thisProject = projectService.findByProjectId(projectId); Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForShowOneProject(thisProject,locale); model.addAttribute("breadcrumb", breadcrumb); - return "project/edit"; + return "project/id/edit"; } else { Project thisProject = projectService.findByProjectId(project.getId()); thisProject.setName(project.getName()); @@ -171,49 +313,159 @@ public final String editProjectPost( @RequestMapping(path = "/{projectId}/delete", method = RequestMethod.GET) public final String deleteProject( @PathVariable("projectId") Project project, - @PageableDefault(sort = "title") Pageable request, + @PageableDefault(sort = "title", direction = Sort.Direction.DESC) Pageable request, @ModelAttribute("userSession") UserSessionBean userSession, - Locale locale, Model model) { + Locale locale, + Model model + ) { long newProjectId = project.getId(); Context context = super.getContext(userSession); userSession.setLastProjectId(project.getId()); model.addAttribute("userSession",userSession); UserAccount userAccount = context.getUserAccount(); - if(project != null){ - boolean hasNoData = taskService.projectHasNoTasks(project); - boolean hasNoChildren = project.hasNoChildren(); - if (hasNoData && hasNoChildren) { - if (!project.isRootProject()) { - newProjectId = project.getParent().getId(); - } else { - newProjectId = 0; - } - projectService.delete(project); - String message = "Project is deleted. You see its parent project now."; - model.addAttribute("message",message); - model.addAttribute("isDeleted",true); + if(project != null){ + boolean hasNoData = taskService.projectHasNoTasks(project); + boolean hasNoChildren = project.hasNoChildren(); + if (hasNoData && hasNoChildren) { + if (!project.isRootProject()) { + newProjectId = project.getParent().getId(); } else { - StringBuilder s = new StringBuilder("Deletion rejected for this Project, because "); - log.info("Deletion rejected for Project " + project.getId()); - if (!hasNoData) { - log.warn("Project " + project.getId() + " has actionItem"); - s.append("Project has actionItems."); - } - if (!hasNoChildren) { - log.info("Project " + project.getId() + " has children"); - s.append("Project has child categories."); - } - model.addAttribute("message",s.toString()); - model.addAttribute("isDeleted",false); - Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForShowOneProject(project,locale); - Page taskPage = taskService.findByProject(project, context, request); - model.addAttribute("taskPage", taskPage); - model.addAttribute("breadcrumb", breadcrumb); - model.addAttribute("thisProject", project); - return "project/show"; + newProjectId = 0; + } + projectService.delete(project); + String message = "Project is deleted. You see its parent project now."; + model.addAttribute("message",message); + model.addAttribute("isDeleted",true); + } else { + StringBuilder s = new StringBuilder("Deletion rejected for this Project, because "); + log.info("Deletion rejected for Project " + project.getId()); + if (!hasNoData) { + log.warn("Project " + project.getId() + " has actionItem"); + s.append("Project has actionItems."); + } + if (!hasNoChildren) { + log.info("Project " + project.getId() + " has children"); + s.append("Project has child categories."); } + model.addAttribute("message",s.toString()); + model.addAttribute("isDeleted",false); + Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForShowOneProject(project,locale); + Page taskPage = taskService.findByProject(project, context, request); + model.addAttribute("taskPage", taskPage); + model.addAttribute("breadcrumb", breadcrumb); + model.addAttribute("thisProject", project); + return "project/id/show"; } - return "redirect:/project/" + newProjectId; + } + if( newProjectId == 0){ + return "redirect:/project/root/tasks"; + } else { + return "redirect:/project/" + newProjectId; + } + } + + @RequestMapping(path = "/{projectId}/task/{sourceTaskId}/changeorderto/{destinationTaskId}", method = RequestMethod.GET) + public String changeTaskOrderIdWithinAProject( + @PathVariable("projectId") Project thisProject, + @PathVariable("sourceTaskId") Task sourceTask, + @PathVariable("destinationTaskId") Task destinationTask, + @ModelAttribute("userSession") UserSessionBean userSession, + Model model + ){ + if(!sourceTask.isInRootProject()){ + userSession.setLastProjectId(sourceTask.getProject().getId()); + } + model.addAttribute("userSession",userSession); + log.info("-------------------------------------------------"); + log.info(" changeTaskOrderIdWithinAProject"); + log.info("-------------------------------------------------"); + log.info(" source Task: "+sourceTask.toString()); + log.info("-------------------------------------------------"); + log.info(" destination Task: "+destinationTask.toString()); + log.info("-------------------------------------------------"); + String returnUrl = "redirect:/taskstate/inbox"; + boolean rootProject = sourceTask.isInRootProject(); + returnUrl = "redirect:/project/0"; + if(rootProject){ + taskMoveService.moveOrderIdRootProject(sourceTask, destinationTask); + } else { + taskMoveService.moveOrderIdProject(sourceTask, destinationTask); + log.info(" DONE: taskMoveService.moveOrderIdProject (2)"); + returnUrl = "redirect:/project/" + sourceTask.getProject().getId(); + } + log.info("-------------------------------------------------"); + return returnUrl; + } + + @RequestMapping(path = "/{projectId}/add/task", method = RequestMethod.GET) + public final String addNewTaskToProjectGet( + @ModelAttribute("userSession") UserSessionBean userSession, + Locale locale, Model model + ) { + UserAccount userAccount = userAccountLoginSuccessService.retrieveCurrentUser(); + Task task = new Task(); + task.setTaskState(TaskState.INBOX); + task.setTaskEnergy(TaskEnergy.NONE); + task.setTaskTime(TaskTime.NONE); + Boolean mustChooseArea = false; + if(userSession.getContextId() == 0L){ + mustChooseArea = true; + task.setContext(userAccount.getDefaultContext()); + } else { + Context context = contextService.findByIdAndUserAccount(userSession.getContextId(), userAccount); + task.setContext(context); + } + Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForShowRootProject(locale); + model.addAttribute("breadcrumb", breadcrumb); + model.addAttribute("mustChooseArea", mustChooseArea); + model.addAttribute("thisProjectId", 0L); + model.addAttribute("breadcrumb", breadcrumb); + model.addAttribute("task", task); + return "id/task/add"; + } + + @RequestMapping(path = "/{projectId}/add/task", method = RequestMethod.POST) + public final String addNewTaskToProjectPost( + @PathVariable long projectId, + @ModelAttribute("userSession") UserSessionBean userSession, + @Valid Task task, + BindingResult result, Locale locale, Model model) { + Context context = super.getContext(userSession); + UserAccount userAccount = context.getUserAccount(); + if (result.hasErrors()) { + for (ObjectError e : result.getAllErrors()) { + log.info(e.toString()); + } + Project thisProject = projectControllerService.getProject(projectId, userAccount, userSession); + Boolean mustChooseArea = false; + task.setProject(thisProject); + task.setContext(thisProject.getContext()); + Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForShowOneProject(thisProject,locale); + model.addAttribute("mustChooseArea", mustChooseArea); + model.addAttribute("thisProject", thisProject); + model.addAttribute("breadcrumb", breadcrumb); + model.addAttribute("task", task); + //return "task/addToProject"; + return "id/task/add"; + } else { + Project thisProject = projectService.findByProjectId(projectId); + task.setProject(thisProject); + task.setContext(thisProject.getContext()); + if(task.getDueDate()==null){ + task.setTaskState(TaskState.INBOX); + } else { + task.setTaskState(TaskState.SCHEDULED); + } + task.setFocus(false); + task.setContext(context); + long maxOrderIdProject = taskMoveService.getMaxOrderIdProject(task.getProject(),context); + task.setOrderIdProject(++maxOrderIdProject); + long maxOrderIdTaskState = taskMoveService.getMaxOrderIdTaskState(task.getTaskState(),task.getContext()); + task.setOrderIdTaskState(++maxOrderIdTaskState); + task = taskService.saveAndFlush(task); + log.info(task.toString()); + return "redirect:/project/" + projectId + "/"; + } } } diff --git a/src/main/java/org/woehlke/simpleworklist/project/ProjectControllerService.java b/src/main/java/org/woehlke/simpleworklist/project/ProjectControllerService.java index 37da8c39..5ca2f214 100644 --- a/src/main/java/org/woehlke/simpleworklist/project/ProjectControllerService.java +++ b/src/main/java/org/woehlke/simpleworklist/project/ProjectControllerService.java @@ -34,4 +34,21 @@ Project getProject( UserAccount userAccount, UserSessionBean userSession ); + + void addNewProjectToRoot( + UserSessionBean userSession, + Context context, + Locale locale, + Model model + ); + + String addNewProjectToRootPersist( + UserSessionBean userSession, + Project project, + Context context, + BindingResult result, + Locale locale, + Model model, + String s + ); } diff --git a/src/main/java/org/woehlke/simpleworklist/project/ProjectControllerServiceImpl.java b/src/main/java/org/woehlke/simpleworklist/project/ProjectControllerServiceImpl.java index 292c5409..b916f687 100644 --- a/src/main/java/org/woehlke/simpleworklist/project/ProjectControllerServiceImpl.java +++ b/src/main/java/org/woehlke/simpleworklist/project/ProjectControllerServiceImpl.java @@ -1,6 +1,5 @@ package org.woehlke.simpleworklist.project; -import lombok.experimental.Delegate; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -38,7 +37,7 @@ public void addNewProject( Locale locale, Model model ) { - log.info("private addNewProject projectId="+projectId); + log.info("addNewProject projectId="+projectId); UserAccount userAccount = context.getUserAccount(); userSession.setLastProjectId(projectId); model.addAttribute("userSession",userSession); @@ -113,6 +112,7 @@ public String addNewProjectPersist( } public Project getProject(long projectId, UserAccount userAccount, UserSessionBean userSession){ + log.info("getProject"); Project thisProject; if (projectId == 0) { thisProject = new Project(); @@ -128,4 +128,37 @@ public Project getProject(long projectId, UserAccount userAccount, UserSessionBe } return thisProject; } + + @Override + public void addNewProjectToRoot( + UserSessionBean userSession, + Context context, + Locale locale, + Model model + ) { + log.info("addNewProjectToRoot"); + Project project; + project = new Project(); + project.setId(0L); + Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForShowRootProject(locale); + model.addAttribute("breadcrumb", breadcrumb); + model.addAttribute("project", project); + model.addAttribute("thisProjectId", project.getId()); + model.addAttribute("breadcrumb", breadcrumb); + } + + @Override + public String addNewProjectToRootPersist( + UserSessionBean userSession, + Project project, + Context context, + BindingResult result, + Locale locale, + Model model, + String s + ) { + log.info("addNewProjectToRootPersist"); + project = projectService.saveAndFlush(project); + return s + project.getId(); + } } diff --git a/src/main/java/org/woehlke/simpleworklist/project/ProjectRootController.java b/src/main/java/org/woehlke/simpleworklist/project/ProjectRootController.java deleted file mode 100644 index 69298264..00000000 --- a/src/main/java/org/woehlke/simpleworklist/project/ProjectRootController.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.woehlke.simpleworklist.project; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.data.web.PageableDefault; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -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.bind.annotation.RequestParam; -import org.woehlke.simpleworklist.breadcrumb.Breadcrumb; -import org.woehlke.simpleworklist.common.AbstractController; -import org.woehlke.simpleworklist.context.Context; -import org.woehlke.simpleworklist.task.Task; -import org.woehlke.simpleworklist.user.UserSessionBean; - -import javax.validation.Valid; -import java.util.Locale; - -@Slf4j -@Controller -@RequestMapping(path = "/project/root") -public class ProjectRootController extends AbstractController { - - private final ProjectControllerService projectControllerService; - - private static final long rootProjectId = 0L; - - @Autowired - public ProjectRootController(ProjectControllerService projectControllerService) { - this.projectControllerService = projectControllerService; - } - - @RequestMapping(path = "/", method = RequestMethod.GET) - public final String showRootProject( - @PageableDefault(sort = "orderIdProject") Pageable pageable, - @RequestParam(required = false) String message, - @RequestParam(required = false) boolean isDeleted, - @ModelAttribute("userSession") UserSessionBean userSession, - Locale locale, Model model) { - log.info("/project/root"); - Context context = super.getContext(userSession); - userSession.setLastProjectId(0L); - model.addAttribute("userSession",userSession); - Page taskPage = taskService.findByRootProject(context,pageable); - Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForShowRootProject(locale); - model.addAttribute("breadcrumb", breadcrumb); - model.addAttribute("taskPage", taskPage); - if(message != null){ - model.addAttribute("message",message); - model.addAttribute("isDeleted",isDeleted); - model.addAttribute("myTaskState","PROJECT"); - } - return "project/root"; - } - - @RequestMapping(path = "/add/new/project", method = RequestMethod.GET) - public final String addNewTopLevelProjectForm( - @ModelAttribute("userSession") UserSessionBean userSession, - Locale locale, Model model - ){ - log.info("/project/add/new/project (GET)"); - Context context = super.getContext(userSession); - projectControllerService.addNewProject(rootProjectId, userSession, context, locale, model); - return "project/addToplevel"; - } - - @RequestMapping(path = "/add/new/project", method = {RequestMethod.POST, RequestMethod.PUT}) - public final String addNewTopLevelProjectSave( - @Valid Project project, - @ModelAttribute("userSession") UserSessionBean userSession, - BindingResult result, - Locale locale, Model model - ){ - log.info("/project/add/new/project (POST)"); - Context context = super.getContext(userSession); - return projectControllerService.addNewProjectPersist( rootProjectId, userSession, project, context, - result, locale, model, "project/addToplevel"); - } -} diff --git a/src/main/java/org/woehlke/simpleworklist/project/ProjectServiceImpl.java b/src/main/java/org/woehlke/simpleworklist/project/ProjectServiceImpl.java index abb862fc..0d038f2c 100644 --- a/src/main/java/org/woehlke/simpleworklist/project/ProjectServiceImpl.java +++ b/src/main/java/org/woehlke/simpleworklist/project/ProjectServiceImpl.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.slf4j.Logger; @@ -14,14 +15,12 @@ import org.woehlke.simpleworklist.task.Task; import org.woehlke.simpleworklist.task.TaskRepository; +@Slf4j @Service @Transactional(propagation = Propagation.REQUIRED, readOnly = true) public class ProjectServiceImpl implements ProjectService { - private static final Logger LOGGER = LoggerFactory.getLogger(ProjectServiceImpl.class); - private final ProjectRepository projectRepository; - private final TaskRepository taskRepository; @Autowired @@ -46,16 +45,19 @@ public List findAllProjectsByUserAccount(UserAccount userAccount) { @Override public List findRootProjectsByContext(Context context) { + log.info("findRootProjectsByContext"); return projectRepository.findByParentIsNullAndContext(context); } @Override public List findAllProjectsByContext(Context context) { + log.info("findAllProjectsByContext"); return projectRepository.findByContext(context); } @Override public Project findByProjectId(long projectId) { + log.info("findByProjectId"); if(projectRepository.existsById(projectId)){ return projectRepository.getOne(projectId); } else { @@ -66,12 +68,14 @@ public Project findByProjectId(long projectId) { @Override @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) public Project saveAndFlush(Project entity) { + log.info("saveAndFlush"); return projectRepository.saveAndFlush(entity); } @Override @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) public void delete(Project thisProject) { + log.info("delete"); Project oldParent = thisProject.getParent(); if (oldParent != null) { oldParent.getChildren().remove(thisProject); @@ -83,26 +87,27 @@ public void delete(Project thisProject) { @Override @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) public void moveProjectToAnotherContext(Project thisProject, Context newContext) { - LOGGER.info("----------------------------------------------------"); - LOGGER.info("moveProjectToAnotherContext: Project: "+thisProject.toString()); - LOGGER.info("----------------------------------------------------"); - LOGGER.info("moveProjectToAnotherContext: newContext: "+ newContext.toString()); - LOGGER.info("----------------------------------------------------"); - thisProject.setParent(null); - projectRepository.saveAndFlush(thisProject); - List list = getAllChildrenOfProject(thisProject); - for(Project p : list){ - List tasks = taskRepository.findByProject(p); - for(Task t:tasks){ - t.setContext(newContext); - } - taskRepository.saveAll(tasks); - p.setContext(newContext); - projectRepository.saveAndFlush(p); + log.info("----------------------------------------------------"); + log.info("moveProjectToAnotherContext: Project: "+thisProject.toString()); + log.info("----------------------------------------------------"); + log.info("moveProjectToAnotherContext: newContext: "+ newContext.toString()); + log.info("----------------------------------------------------"); + thisProject.setParent(null); + projectRepository.saveAndFlush(thisProject); + List list = getAllChildrenOfProject(thisProject); + for(Project p : list){ + List tasks = taskRepository.findByProject(p); + for(Task t:tasks){ + t.setContext(newContext); } + taskRepository.saveAll(tasks); + p.setContext(newContext); + projectRepository.saveAndFlush(p); + } } private List getAllChildrenOfProject(Project thisProject) { + log.info("getAllChildrenOfProject"); List retVal = new ArrayList<>(); retVal.add(thisProject); for(Project p : thisProject.getChildren()){ @@ -114,8 +119,11 @@ private List getAllChildrenOfProject(Project thisProject) { @Override @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) - public void moveProjectToAnotherProject(Project thisProject, - Project targetProject) { + public void moveProjectToAnotherProject( + Project thisProject, + Project targetProject + ) { + log.info("moveProjectToAnotherProject"); Project oldParent = thisProject.getParent(); if (oldParent != null) { oldParent.getChildren().remove(thisProject); diff --git a/src/main/java/org/woehlke/simpleworklist/project/ProjectTaskController.java b/src/main/java/org/woehlke/simpleworklist/project/ProjectTaskController.java deleted file mode 100644 index 3f93aa3c..00000000 --- a/src/main/java/org/woehlke/simpleworklist/project/ProjectTaskController.java +++ /dev/null @@ -1,193 +0,0 @@ -package org.woehlke.simpleworklist.project; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.validation.BindingResult; -import org.springframework.validation.ObjectError; -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.woehlke.simpleworklist.breadcrumb.Breadcrumb; -import org.woehlke.simpleworklist.common.AbstractController; -import org.woehlke.simpleworklist.context.Context; -import org.woehlke.simpleworklist.task.Task; -import org.woehlke.simpleworklist.task.TaskEnergy; -import org.woehlke.simpleworklist.task.TaskState; -import org.woehlke.simpleworklist.task.TaskTime; -import org.woehlke.simpleworklist.taskstate.TaskMoveService; -import org.woehlke.simpleworklist.user.UserSessionBean; -import org.woehlke.simpleworklist.user.account.UserAccount; - -import javax.validation.Valid; -import java.util.Locale; - - -@Slf4j -@Controller -@RequestMapping(path = "/project/task") -public class ProjectTaskController extends AbstractController { - - private final TaskMoveService taskMoveService; - private final ProjectControllerService projectControllerService; - - @Autowired - public ProjectTaskController(TaskMoveService taskMoveService, ProjectControllerService projectControllerService) { - this.taskMoveService = taskMoveService; - this.projectControllerService = projectControllerService; - } - - @RequestMapping(path = "/{sourceTaskId}/changeorderto/{destinationTaskId}", method = RequestMethod.GET) - public String changeTaskOrderIdWithinAProject( - @PathVariable("sourceTaskId") Task sourceTask, - @PathVariable("destinationTaskId") Task destinationTask, - @ModelAttribute("userSession") UserSessionBean userSession, - Model model - ){ - if(!sourceTask.isInRootProject()){ - userSession.setLastProjectId(sourceTask.getProject().getId()); - } - model.addAttribute("userSession",userSession); - log.info("-------------------------------------------------"); - log.info(" changeTaskOrderIdWithinAProject"); - log.info("-------------------------------------------------"); - log.info(" source Task: "+sourceTask.toString()); - log.info("-------------------------------------------------"); - log.info(" destination Task: "+destinationTask.toString()); - log.info("-------------------------------------------------"); - String returnUrl = "redirect:/taskstate/inbox"; - boolean rootProject = sourceTask.isInRootProject(); - returnUrl = "redirect:/project/0"; - if(rootProject){ - taskMoveService.moveOrderIdRootProject(sourceTask, destinationTask); - } else { - taskMoveService.moveOrderIdProject(sourceTask, destinationTask); - log.info(" DONE: taskMoveService.moveOrderIdProject (2)"); - returnUrl = "redirect:/project/" + sourceTask.getProject().getId(); - } - log.info("-------------------------------------------------"); - return returnUrl; - } - - - @RequestMapping(path = "/addtorootproject/", method = RequestMethod.GET) - public final String addNewTaskToProjectGet( - @ModelAttribute("userSession") UserSessionBean userSession, - Locale locale, Model model - ) { - UserAccount userAccount = userAccountLoginSuccessService.retrieveCurrentUser(); - Task task = new Task(); - task.setTaskState(TaskState.INBOX); - task.setTaskEnergy(TaskEnergy.NONE); - task.setTaskTime(TaskTime.NONE); - Boolean mustChooseArea = false; - if(userSession.getContextId() == 0L){ - mustChooseArea = true; - task.setContext(userAccount.getDefaultContext()); - } else { - Context context = contextService.findByIdAndUserAccount(userSession.getContextId(), userAccount); - task.setContext(context); - } - Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForShowRootProject(locale); - model.addAttribute("breadcrumb", breadcrumb); - model.addAttribute("mustChooseArea", mustChooseArea); - model.addAttribute("thisProjectId", 0L); - model.addAttribute("breadcrumb", breadcrumb); - model.addAttribute("task", task); - return "task/addToProject"; - } - - @RequestMapping(path = "/addtoproject/{projectId}", method = RequestMethod.GET) - public final String addNewTaskToProjectGet( - @PathVariable long projectId, - @ModelAttribute("userSession") UserSessionBean userSession, - Locale locale, Model model - ) { - Context context = super.getContext(userSession); - UserAccount userAccount = context.getUserAccount(); - Task task = new Task(); - task.setTaskState(TaskState.INBOX); - task.setTaskEnergy(TaskEnergy.NONE); - task.setTaskTime(TaskTime.NONE); - Project thisProject; - Boolean mustChooseArea = false; - if (projectId == 0) { - thisProject = new Project(); - thisProject.setId(0L); - if(userSession.getContextId() == 0L){ - mustChooseArea = true; - task.setContext(userAccount.getDefaultContext()); - thisProject.setContext(userAccount.getDefaultContext()); - } else { - task.setContext(context); - thisProject.setContext(context); - } - } else { - thisProject = projectService.findByProjectId(projectId); - task.setProject(thisProject); - task.setContext(thisProject.getContext()); - } - Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForShowOneProject(thisProject,locale); - model.addAttribute("breadcrumb", breadcrumb); - model.addAttribute("mustChooseArea", mustChooseArea); - model.addAttribute("thisProject", thisProject); - model.addAttribute("thisProjectId", thisProject.getId()); - model.addAttribute("breadcrumb", breadcrumb); - model.addAttribute("task", task); - return "task/addToProject"; - } - - @RequestMapping(path = "/addtoproject/{projectId}", method = RequestMethod.POST) - public final String addNewTaskToProjectPost( - @PathVariable long projectId, - @ModelAttribute("userSession") UserSessionBean userSession, - @Valid Task task, - BindingResult result, Locale locale, Model model) { - Context context = super.getContext(userSession); - UserAccount userAccount = context.getUserAccount(); - if (result.hasErrors()) { - for (ObjectError e : result.getAllErrors()) { - log.info(e.toString()); - } - Project thisProject = projectControllerService.getProject(projectId, userAccount, userSession); - Boolean mustChooseArea = false; - if (projectId == 0) { - task.setContext(context); - } else { - task.setProject(thisProject); - task.setContext(thisProject.getContext()); - } - Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForShowOneProject(thisProject,locale); - model.addAttribute("mustChooseArea", mustChooseArea); - model.addAttribute("thisProject", thisProject); - model.addAttribute("breadcrumb", breadcrumb); - model.addAttribute("task", task); - return "task/addToProject"; - } else { - if (projectId == 0) { - task.setProject(null); - } else { - Project thisProject = projectService.findByProjectId(projectId); - task.setProject(thisProject); - task.setContext(thisProject.getContext()); - } - if(task.getDueDate()==null){ - task.setTaskState(TaskState.INBOX); - } else { - task.setTaskState(TaskState.SCHEDULED); - } - task.setFocus(false); - task.setContext(context); - long maxOrderIdProject = taskMoveService.getMaxOrderIdProject(task.getProject(),context); - task.setOrderIdProject(++maxOrderIdProject); - long maxOrderIdTaskState = taskMoveService.getMaxOrderIdTaskState(task.getTaskState(),task.getContext()); - task.setOrderIdTaskState(++maxOrderIdTaskState); - task = taskService.saveAndFlush(task); - log.info(task.toString()); - return "redirect:/project/" + projectId + "/"; - } - } - -} diff --git a/src/main/java/org/woehlke/simpleworklist/search/SearchController.java b/src/main/java/org/woehlke/simpleworklist/search/SearchController.java index 9420a7c8..7bea38db 100644 --- a/src/main/java/org/woehlke/simpleworklist/search/SearchController.java +++ b/src/main/java/org/woehlke/simpleworklist/search/SearchController.java @@ -1,7 +1,6 @@ package org.woehlke.simpleworklist.search; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.ModelAttribute; @@ -21,11 +20,11 @@ /** * Created by tw on 14.02.16. */ +@Slf4j @Controller +@RequestMapping(path = "/search") public class SearchController extends AbstractController { - private static final Logger LOGGER = LoggerFactory.getLogger(SearchController.class); - private final SearchService searchService; @Autowired @@ -33,19 +32,20 @@ public SearchController(SearchService searchService) { this.searchService = searchService; } - @RequestMapping(value = "/search", method = RequestMethod.GET) + @RequestMapping(path = "/", method = RequestMethod.GET) public final String searchResults( @RequestParam String searchterm, @ModelAttribute("userSession") UserSessionBean userSession, Locale locale, Model model ) { + log.info("searchResults"); Context context = super.getContext(userSession); UserAccount thisUser = context.getUserAccount(); userSession.setLastSearchterm(searchterm); model.addAttribute("userSession",userSession); - LOGGER.info("Search: "+ searchterm); + log.info("Search: "+ searchterm); SearchResult searchResult = searchService.search(searchterm, thisUser); - LOGGER.info("found: "+ searchResult.toString()); + log.info("found: "+ searchResult.toString()); model.addAttribute("searchResult",searchResult); Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForSearchResults(locale); model.addAttribute("breadcrumb",breadcrumb); diff --git a/src/main/java/org/woehlke/simpleworklist/search/SearchDaoImpl.java b/src/main/java/org/woehlke/simpleworklist/search/SearchDaoImpl.java index cd15b61f..45f14e04 100644 --- a/src/main/java/org/woehlke/simpleworklist/search/SearchDaoImpl.java +++ b/src/main/java/org/woehlke/simpleworklist/search/SearchDaoImpl.java @@ -1,6 +1,7 @@ package org.woehlke.simpleworklist.search; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Repository; @@ -11,20 +12,21 @@ /** * Created by tw on 14.02.16. */ +@Slf4j @Repository public class SearchDaoImpl implements SearchDao { - private static final Logger LOGGER = LoggerFactory.getLogger(SearchDaoImpl.class); - @PersistenceContext private EntityManager em; @Override public SearchResult search(String searchterm, UserAccount userAccount) { + log.info("search"); return new SearchResult(); } @Override public void resetSearchIndex() { + log.info("resetSearchIndex"); } } diff --git a/src/main/java/org/woehlke/simpleworklist/search/SearchServiceImpl.java b/src/main/java/org/woehlke/simpleworklist/search/SearchServiceImpl.java index 8f2bac55..b325928d 100644 --- a/src/main/java/org/woehlke/simpleworklist/search/SearchServiceImpl.java +++ b/src/main/java/org/woehlke/simpleworklist/search/SearchServiceImpl.java @@ -1,7 +1,6 @@ package org.woehlke.simpleworklist.search; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @@ -12,12 +11,11 @@ /** * Created by tw on 14.02.16. */ +@Slf4j @Service @Transactional(propagation = Propagation.REQUIRES_NEW) public class SearchServiceImpl implements SearchService { - private static final Logger LOGGER = LoggerFactory.getLogger(SearchServiceImpl.class); - private final SearchDao searchDao; @Autowired @@ -28,13 +26,14 @@ public SearchServiceImpl(SearchDao searchDao) { @Override @Transactional(propagation = Propagation.REQUIRED, readOnly = true) public SearchResult search(String searchterm, UserAccount userAccount) { + log.info("search"); SearchResult searchResult = searchDao.search(searchterm, userAccount); return searchResult; } @Override public void resetSearchIndex() { - LOGGER.info("resetSearchIndex"); + log.info("resetSearchIndex"); searchDao.resetSearchIndex(); } } diff --git a/src/main/java/org/woehlke/simpleworklist/task/Task.java b/src/main/java/org/woehlke/simpleworklist/task/Task.java index c18d0958..d5f72dc9 100644 --- a/src/main/java/org/woehlke/simpleworklist/task/Task.java +++ b/src/main/java/org/woehlke/simpleworklist/task/Task.java @@ -16,6 +16,7 @@ import org.springframework.format.annotation.DateTimeFormat; import org.woehlke.simpleworklist.context.Context; import org.woehlke.simpleworklist.project.Project; +import org.woehlke.simpleworklist.taskstate.TaskState; import org.woehlke.simpleworklist.user.account.UserAccount; import org.woehlke.simpleworklist.common.AuditModel; import org.woehlke.simpleworklist.common.ComparableById; diff --git a/src/main/java/org/woehlke/simpleworklist/task/TaskAddController.java b/src/main/java/org/woehlke/simpleworklist/task/TaskAddController.java deleted file mode 100644 index d4df5c5d..00000000 --- a/src/main/java/org/woehlke/simpleworklist/task/TaskAddController.java +++ /dev/null @@ -1,98 +0,0 @@ -package org.woehlke.simpleworklist.task; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.validation.BindingResult; -import org.springframework.validation.ObjectError; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.woehlke.simpleworklist.breadcrumb.Breadcrumb; -import org.woehlke.simpleworklist.common.AbstractController; -import org.woehlke.simpleworklist.context.Context; -import org.woehlke.simpleworklist.taskstate.TaskMoveService; -import org.woehlke.simpleworklist.user.UserSessionBean; -import org.woehlke.simpleworklist.user.account.UserAccount; - -import javax.validation.Valid; -import java.util.Locale; - - -@Slf4j -@Controller -@RequestMapping(path = "/task") -public class TaskAddController extends AbstractController { - - private final TaskMoveService taskMoveService; - - @Autowired - public TaskAddController(TaskMoveService taskMoveService) { - this.taskMoveService = taskMoveService; - } - - @RequestMapping(path = "/add", method = RequestMethod.GET) - public final String addNewTaskToInboxGet( - @ModelAttribute("userSession") UserSessionBean userSession, - Locale locale, Model model - ) { - UserAccount userAccount = userAccountLoginSuccessService.retrieveCurrentUser(); - Task task = new Task(); - task.setTaskState(TaskState.INBOX); - task.setTaskEnergy(TaskEnergy.NONE); - task.setTaskTime(TaskTime.NONE); - Boolean mustChooseContext = false; - if(userSession.getContextId() == 0L){ - mustChooseContext = true; - task.setContext(userAccount.getDefaultContext()); - } else { - Context context = contextService.findByIdAndUserAccount(userSession.getContextId(), userAccount); - task.setContext(context); - } - Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForTaskstate(TaskState.INBOX,locale); - model.addAttribute("breadcrumb", breadcrumb); - model.addAttribute("mustChooseArea", mustChooseContext); - model.addAttribute("breadcrumb", breadcrumb); - model.addAttribute("task", task); - return "task/addToInbox"; - } - - @RequestMapping(path = "/add", method = RequestMethod.POST) - public final String addNewTaskToInboxPost( - @ModelAttribute("userSession") UserSessionBean userSession, - @Valid Task task, - BindingResult result, Locale locale, Model model) { - Context context = super.getContext(userSession); - if (result.hasErrors()) { - for (ObjectError e : result.getAllErrors()) { - log.info(e.toString()); - } - Boolean mustChooseArea = false; - task.setContext(context); - Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForTaskstate(TaskState.INBOX,locale); - model.addAttribute("mustChooseArea", mustChooseArea); - model.addAttribute("breadcrumb", breadcrumb); - model.addAttribute("task", task); - return "task/addToProject"; - } else { - task.setProject(null); - if(task.getDueDate()==null){ - task.setTaskState(TaskState.INBOX); - } else { - task.setTaskState(TaskState.SCHEDULED); - } - task.setFocus(false); - task.setContext(context); - //TODO: verify, that this is correct: - long maxOrderIdProject = taskMoveService.getMaxOrderIdProject(task.getProject(),context); - task.setOrderIdProject(++maxOrderIdProject); - // - long maxOrderIdTaskState = taskMoveService.getMaxOrderIdTaskState(task.getTaskState(),task.getContext()); - task.setOrderIdTaskState(++maxOrderIdTaskState); - task = taskService.saveAndFlush(task); - log.info(task.toString()); - return "redirect:/taskstate/" + task.getTaskState().name().toLowerCase(); - } - } -} diff --git a/src/main/java/org/woehlke/simpleworklist/task/TaskController.java b/src/main/java/org/woehlke/simpleworklist/task/TaskController.java index ba00cf36..8ec4178c 100644 --- a/src/main/java/org/woehlke/simpleworklist/task/TaskController.java +++ b/src/main/java/org/woehlke/simpleworklist/task/TaskController.java @@ -2,26 +2,139 @@ import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.validation.ObjectError; import org.springframework.web.bind.annotation.*; +import org.woehlke.simpleworklist.breadcrumb.Breadcrumb; import org.woehlke.simpleworklist.common.AbstractController; +import org.woehlke.simpleworklist.context.Context; import org.woehlke.simpleworklist.project.Project; +import org.woehlke.simpleworklist.taskstate.TaskMoveService; +import org.woehlke.simpleworklist.taskstate.TaskState; +import org.woehlke.simpleworklist.user.UserSessionBean; +import org.woehlke.simpleworklist.user.account.UserAccount; + +import javax.validation.Valid; +import java.util.List; +import java.util.Locale; @Slf4j @Controller @RequestMapping(path = "/task") public class TaskController extends AbstractController { - @RequestMapping(path = "/delete/{taskId}", method = RequestMethod.GET) + private final TaskMoveService taskMoveService; + private final TaskControllerService taskControllerService; + + @Autowired + public TaskController(TaskMoveService taskMoveService, TaskControllerService taskControllerService) { + this.taskMoveService = taskMoveService; + this.taskControllerService = taskControllerService; + } + + @RequestMapping(path = "/{taskId}/edit", method = RequestMethod.GET) + public final String editTaskGet( + @PathVariable("taskId") Task task, + @ModelAttribute("userSession") UserSessionBean userSession, + Locale locale, Model model + ) { + log.info("editTaskGet"); + UserAccount userAccount = userAccountLoginSuccessService.retrieveCurrentUser(); + List contexts = contextService.getAllForUser(userAccount); + if(task != null) { + Project thisProject = null; + if (task.getProject() == null) { + thisProject = new Project(); + thisProject.setId(0L); + } else { + thisProject = task.getProject(); + } + model.addAttribute("thisProject", thisProject); + Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForShowOneProject(thisProject,locale); + model.addAttribute("breadcrumb", breadcrumb); + model.addAttribute("task", task); + model.addAttribute("areas", contexts); + return "taskstate/task/edit"; + } else { + return "redirect:/taskstate/inbox"; + } + } + + @RequestMapping(path = "/{taskId}/edit", method = RequestMethod.POST) + public final String editTaskPost( + @PathVariable long taskId, + @Valid Task task, + @ModelAttribute("userSession") UserSessionBean userSession, + BindingResult result, + Locale locale, + Model model + ) { + log.info("editTaskPost"); + Task persistentTask = taskService.findOne(taskId); + long projectId = 0; + Project thisProject; + if (persistentTask.getProject() == null) { + thisProject = new Project(); + thisProject.setId(0L); + } else { + thisProject = persistentTask.getProject(); + projectId = thisProject.getId(); + } + if (result.hasErrors()) { + for (ObjectError e : result.getAllErrors()) { + log.info(e.toString()); + } + model.addAttribute("thisProject", thisProject); + Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForShowOneProject(thisProject,locale); + model.addAttribute("breadcrumb", breadcrumb); + model.addAttribute("task", task); + return "taskstate/task/edit"; + } else { + persistentTask.setTitle(task.getTitle()); + persistentTask.setText(task.getText()); + if(task.getDueDate()==null){ + persistentTask.setDueDate(null); + if(persistentTask.getTaskState().compareTo(TaskState.SCHEDULED)==0){ + persistentTask.setTaskState(TaskState.INBOX); + } + } else { + persistentTask.setDueDate(task.getDueDate()); + persistentTask.setTaskState(TaskState.SCHEDULED); + } + persistentTask.setTaskTime(task.getTaskTime()); + persistentTask.setTaskEnergy(task.getTaskEnergy()); + boolean contextChanged = persistentTask.getContext().equalsById(task.getContext()); + if(contextChanged){ + persistentTask.setContext(task.getContext()); + if(thisProject.getId()==0L) { + persistentTask.setRootProject(); + } else if(thisProject.getContext().equalsById(task.getContext())){ + persistentTask.setProject(thisProject); + } + userSession.setContextId(task.getContext().getId()); + model.addAttribute("userSession", userSession); + return "redirect:/project/root"; + } + taskService.saveAndFlush(persistentTask); + return "redirect:/project/" + projectId; + } + } + + @RequestMapping(path = "/{taskId}/delete", method = RequestMethod.GET) public final String deleteTaskGet(@PathVariable("taskId") Task task) { + log.info("deleteTaskGet"); if(task!= null){ taskService.delete(task); } return "redirect:/taskstate/trash"; } - @RequestMapping(path = "/task/undelete/{taskId}", method = RequestMethod.GET) + @RequestMapping(path = "/{taskId}/undelete", method = RequestMethod.GET) public final String undeleteTaskGet(@PathVariable("taskId") Task task) { + log.info("undeleteTaskGet"); if(task!= null) { taskService.undelete(task); return "redirect:/taskstate/completed"; @@ -30,8 +143,9 @@ public final String undeleteTaskGet(@PathVariable("taskId") Task task) { } } - @RequestMapping(path = "/transform/{taskId}", method = RequestMethod.GET) + @RequestMapping(path = "/{taskId}/transform", method = RequestMethod.GET) public final String transformTaskIntoProjectGet(@PathVariable("taskId") Task task) { + log.info("transformTaskIntoProjectGet"); if(task != null) { long projectId = 0; if (task.getProject() != null) { @@ -57,4 +171,56 @@ public final String transformTaskIntoProjectGet(@PathVariable("taskId") Task tas return "redirect:/taskstate/inbox"; } + @RequestMapping(path = "/{taskId}/complete", method = RequestMethod.GET) + public final String setDoneTaskGet( + @PathVariable("taskId") Task task + ) { + if(task != null){ + long maxOrderIdTaskState = taskMoveService.getMaxOrderIdTaskState(TaskState.COMPLETED,task.getContext()); + task.setOrderIdTaskState(++maxOrderIdTaskState); + taskService.complete(task); + } + return "redirect:/taskstate/completed"; + } + + @RequestMapping(path = "/{taskId}/incomplete", method = RequestMethod.GET) + public final String unsetDoneTaskGet( + @PathVariable("taskId") Task task + ) { + if(task !=null) { + taskService.incomplete(task); + long maxOrderIdTaskState = taskMoveService.getMaxOrderIdTaskState(task.getTaskState(),task.getContext()); + task.setOrderIdTaskState(++maxOrderIdTaskState); + taskService.saveAndFlush(task); + return "redirect:/taskstate/"+task.getTaskState().name().toLowerCase(); + } else { + return "redirect:/taskstate/inbox"; + } + } + + @RequestMapping(path = "/{taskId}/setfocus", method = RequestMethod.GET) + public final String setFocusGet( + @PathVariable("taskId") Task task, + @RequestParam(required=false) String back + ){ + if(task !=null) { + taskService.setFocus(task); + return taskControllerService.getView(task,back); + } else { + return "redirect:/taskstate/inbox"; + } + } + + @RequestMapping(path = "/{taskId}/unsetfocus", method = RequestMethod.GET) + public final String unsetFocusGet( + @PathVariable("taskId") Task task, + @RequestParam(required=false) String back + ){ + if(task !=null) { + taskService.unsetFocus(task); + return taskControllerService.getView(task,back); + } else { + return "redirect:/taskstate/inbox"; + } + } } diff --git a/src/main/java/org/woehlke/simpleworklist/task/TaskControllerService.java b/src/main/java/org/woehlke/simpleworklist/task/TaskControllerService.java index b56c1539..5a83ab75 100644 --- a/src/main/java/org/woehlke/simpleworklist/task/TaskControllerService.java +++ b/src/main/java/org/woehlke/simpleworklist/task/TaskControllerService.java @@ -2,6 +2,7 @@ import org.springframework.data.domain.Page; import org.springframework.ui.Model; +import org.woehlke.simpleworklist.taskstate.TaskState; import org.woehlke.simpleworklist.user.UserSessionBean; import java.util.Locale; diff --git a/src/main/java/org/woehlke/simpleworklist/task/TaskControllerServiceImpl.java b/src/main/java/org/woehlke/simpleworklist/task/TaskControllerServiceImpl.java index c47b7dac..efb88141 100644 --- a/src/main/java/org/woehlke/simpleworklist/task/TaskControllerServiceImpl.java +++ b/src/main/java/org/woehlke/simpleworklist/task/TaskControllerServiceImpl.java @@ -7,6 +7,7 @@ import org.springframework.ui.Model; import org.woehlke.simpleworklist.breadcrumb.Breadcrumb; import org.woehlke.simpleworklist.breadcrumb.BreadcrumbService; +import org.woehlke.simpleworklist.taskstate.TaskState; import org.woehlke.simpleworklist.user.UserSessionBean; import java.util.Locale; @@ -25,6 +26,7 @@ public String getTaskStatePage( Locale locale, Model model ){ + log.info("getTaskStatePage"); userSession.setLastTaskState(taskState); Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForTaskstate(taskState,locale); model.addAttribute("breadcrumb", breadcrumb); @@ -37,6 +39,7 @@ public String getTaskStatePage( //TODO: String back -> boolean project public String getView(Task task, String back){ + log.info("getView"); if(back != null && back.contentEquals("project")){ if(task.getProject() != null) { return "redirect:/project/" + task.getProject().getId(); diff --git a/src/main/java/org/woehlke/simpleworklist/task/TaskEditController.java b/src/main/java/org/woehlke/simpleworklist/task/TaskEditController.java deleted file mode 100644 index 3ff9103d..00000000 --- a/src/main/java/org/woehlke/simpleworklist/task/TaskEditController.java +++ /dev/null @@ -1,122 +0,0 @@ -package org.woehlke.simpleworklist.task; - -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.validation.BindingResult; -import org.springframework.validation.ObjectError; -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.woehlke.simpleworklist.breadcrumb.Breadcrumb; -import org.woehlke.simpleworklist.common.AbstractController; -import org.woehlke.simpleworklist.context.Context; -import org.woehlke.simpleworklist.project.Project; -import org.woehlke.simpleworklist.user.UserSessionBean; -import org.woehlke.simpleworklist.user.account.UserAccount; - -import javax.validation.Valid; -import java.util.List; -import java.util.Locale; - - -@Slf4j -@Controller -@RequestMapping(path = "/task") -public class TaskEditController extends AbstractController { - - private final TaskControllerService taskControllerService; - - @Autowired - public TaskEditController(TaskControllerService taskControllerService) { - this.taskControllerService = taskControllerService; - } - - @RequestMapping(path = "/{taskId}/edit", method = RequestMethod.GET) - public final String editTaskGet( - @PathVariable("taskId") Task task, - @ModelAttribute("userSession") UserSessionBean userSession, - Locale locale, Model model - ) { - UserAccount userAccount = userAccountLoginSuccessService.retrieveCurrentUser(); - List contexts = contextService.getAllForUser(userAccount); - if(task != null) { - Project thisProject = null; - if (task.getProject() == null) { - thisProject = new Project(); - thisProject.setId(0L); - } else { - thisProject = task.getProject(); - } - model.addAttribute("thisProject", thisProject); - Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForShowOneProject(thisProject,locale); - model.addAttribute("breadcrumb", breadcrumb); - model.addAttribute("task", task); - model.addAttribute("areas", contexts); - return "task/edit"; - } else { - return "redirect:/taskstate/inbox"; - } - } - - @RequestMapping(path = "/{taskId}/edit", method = RequestMethod.POST) - public final String editTaskPost( - @PathVariable long taskId, - @Valid Task task, - @ModelAttribute("userSession") UserSessionBean userSession, - BindingResult result, - Locale locale, - Model model - ) { - Task persistentTask = taskService.findOne(taskId); - long projectId = 0; - Project thisProject; - if (persistentTask.getProject() == null) { - thisProject = new Project(); - thisProject.setId(0L); - } else { - thisProject = persistentTask.getProject(); - projectId = thisProject.getId(); - } - if (result.hasErrors()) { - for (ObjectError e : result.getAllErrors()) { - log.info(e.toString()); - } - model.addAttribute("thisProject", thisProject); - Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForShowOneProject(thisProject,locale); - model.addAttribute("breadcrumb", breadcrumb); - model.addAttribute("task", task); - return "task/edit"; - } else { - persistentTask.setTitle(task.getTitle()); - persistentTask.setText(task.getText()); - if(task.getDueDate()==null){ - persistentTask.setDueDate(null); - if(persistentTask.getTaskState().compareTo(TaskState.SCHEDULED)==0){ - persistentTask.setTaskState(TaskState.INBOX); - } - } else { - persistentTask.setDueDate(task.getDueDate()); - persistentTask.setTaskState(TaskState.SCHEDULED); - } - persistentTask.setTaskTime(task.getTaskTime()); - persistentTask.setTaskEnergy(task.getTaskEnergy()); - boolean contextChanged = persistentTask.getContext().equalsById(task.getContext()); - if(contextChanged){ - persistentTask.setContext(task.getContext()); - if(thisProject.getId()==0L) { - persistentTask.setRootProject(); - } else if(thisProject.getContext().equalsById(task.getContext())){ - persistentTask.setProject(thisProject); - } - userSession.setContextId(task.getContext().getId()); - model.addAttribute("userSession", userSession); - return "redirect:/project/0/"; - } - taskService.saveAndFlush(persistentTask); - return "redirect:/project/" + projectId + "/"; - } - } -} diff --git a/src/main/java/org/woehlke/simpleworklist/task/TaskRepository.java b/src/main/java/org/woehlke/simpleworklist/task/TaskRepository.java index b8caf20a..4afb5dee 100644 --- a/src/main/java/org/woehlke/simpleworklist/task/TaskRepository.java +++ b/src/main/java/org/woehlke/simpleworklist/task/TaskRepository.java @@ -10,6 +10,7 @@ import org.springframework.stereotype.Repository; import org.woehlke.simpleworklist.context.Context; import org.woehlke.simpleworklist.project.Project; +import org.woehlke.simpleworklist.taskstate.TaskState; @Repository public interface TaskRepository extends JpaRepository { diff --git a/src/main/java/org/woehlke/simpleworklist/task/TaskServiceImpl.java b/src/main/java/org/woehlke/simpleworklist/task/TaskServiceImpl.java index a055c69c..4ca910c0 100644 --- a/src/main/java/org/woehlke/simpleworklist/task/TaskServiceImpl.java +++ b/src/main/java/org/woehlke/simpleworklist/task/TaskServiceImpl.java @@ -3,8 +3,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.Pageable; @@ -13,6 +11,7 @@ import org.springframework.transaction.annotation.Transactional; import org.woehlke.simpleworklist.context.Context; import org.woehlke.simpleworklist.project.Project; +import org.woehlke.simpleworklist.taskstate.TaskState; import java.util.ArrayList; @@ -31,6 +30,7 @@ public TaskServiceImpl(TaskRepository taskRepository) { @Override @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) public Task saveAndFlush(Task entity) { + log.info("saveAndFlush"); entity = taskRepository.saveAndFlush(entity); log.info("saved: " + entity.toString()); return entity; @@ -39,18 +39,21 @@ public Task saveAndFlush(Task entity) { @Override @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) public void delete(Task task) { + log.info("delete"); task.setTaskState(TaskState.TRASH); taskRepository.saveAndFlush(task); } @Override public boolean projectHasNoTasks(Project project) { + log.info("projectHasNoTasks"); return taskRepository.findByProject(project).isEmpty(); } @Override @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) public void undelete(Task task) { + log.info("undelete"); task.switchToLastFocusType(); taskRepository.saveAndFlush(task); } @@ -58,6 +61,7 @@ public void undelete(Task task) { @Override @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) public void complete(Task task) { + log.info("complete"); task.setTaskState(TaskState.COMPLETED); taskRepository.saveAndFlush(task); } @@ -65,6 +69,7 @@ public void complete(Task task) { @Override @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) public void incomplete(Task task) { + log.info("incomplete"); task.switchToLastFocusType(); taskRepository.saveAndFlush(task); } @@ -72,6 +77,7 @@ public void incomplete(Task task) { @Override @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) public void setFocus(Task task) { + log.info("setFocus"); task.setFocus(true); taskRepository.saveAndFlush(task); } @@ -79,6 +85,7 @@ public void setFocus(Task task) { @Override @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) public void unsetFocus(Task task) { + log.info("unsetFocus"); task.setFocus(false); taskRepository.saveAndFlush(task); } @@ -100,11 +107,13 @@ public Page findByProject(Project thisProject, Context context, Pageable r @Override public Page findByRootProject(Context context, Pageable request) { - return taskRepository.findByProjectIsNullAndContext(context,request); + log.info("findByRootProject: "); + return taskRepository.findByProjectIsNullAndContext(context,request); } @Override public Task findOne(long taskId) { + log.info("findOne: "); if(taskRepository.existsById(taskId)) { return taskRepository.getOne(taskId); } else { diff --git a/src/main/java/org/woehlke/simpleworklist/taskstate/TaskMoveController.java b/src/main/java/org/woehlke/simpleworklist/taskstate/TaskMoveController.java deleted file mode 100644 index 89c65b37..00000000 --- a/src/main/java/org/woehlke/simpleworklist/taskstate/TaskMoveController.java +++ /dev/null @@ -1,115 +0,0 @@ -package org.woehlke.simpleworklist.taskstate; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -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.woehlke.simpleworklist.common.AbstractController; -import org.woehlke.simpleworklist.context.Context; -import org.woehlke.simpleworklist.project.Project; -import org.woehlke.simpleworklist.task.Task; -import org.woehlke.simpleworklist.user.UserSessionBean; - -@Controller -@RequestMapping(value = "/task/move") -public class TaskMoveController extends AbstractController { - - private static final Logger LOGGER = LoggerFactory.getLogger(TaskMoveController.class); - - private final TaskMoveService taskMoveService; - - @Autowired - public TaskMoveController(TaskMoveService taskMoveService) { - this.taskMoveService = taskMoveService; - } - - @RequestMapping(value = "/{taskId}/to/project/{projectId}", method = RequestMethod.GET) - public final String moveTaskToAnotherProject(@PathVariable("taskId") Task task, - @PathVariable long projectId) { - if(projectId == 0) { - task = taskMoveService.moveTaskToRootProject(task); - } else { - Project project = projectService.findByProjectId(projectId); - task = taskMoveService.moveTaskToAnotherProject(task,project); - } - return "redirect:/project/" + projectId + "/"; - } - - @RequestMapping(value = "/{taskId}/to/inbox", method = RequestMethod.GET) - public final String moveTaskToInbox(@PathVariable("taskId") Task task) { - LOGGER.info("dragged and dropped "+task.getId()+" to inbox"); - task = taskMoveService.moveTaskToInbox(task); - return "redirect:/taskstate/inbox"; - } - - @RequestMapping(value = "/{taskId}/to/today", method = RequestMethod.GET) - public final String moveTaskToToday(@PathVariable("taskId") Task task) { - LOGGER.info("dragged and dropped "+task.getId()+" to today"); - task = taskMoveService.moveTaskToToday(task); - return "redirect:/taskstate/today"; - } - - @RequestMapping(value = "/{taskId}/to/next", method = RequestMethod.GET) - public final String moveTaskToNext(@PathVariable("taskId") Task task) { - LOGGER.info("dragged and dropped "+task.getId()+" to next"); - task = taskMoveService.moveTaskToNext(task); - return "redirect:/taskstate/next"; - } - - @RequestMapping(value = "/{taskId}/to/waiting", method = RequestMethod.GET) - public final String moveTaskToWaiting(@PathVariable("taskId") Task task) { - LOGGER.info("dragged and dropped "+task.getId()+" to waiting"); - task = taskMoveService.moveTaskToWaiting(task); - return "redirect:/taskstate/waiting"; - } - - @RequestMapping(value = "/{taskId}/to/someday", method = RequestMethod.GET) - public final String moveTaskToSomeday(@PathVariable("taskId") Task task) { - LOGGER.info("dragged and dropped "+task.getId()+" to someday"); - task = taskMoveService.moveTaskToSomeday(task); - return "redirect:/taskstate/someday"; - } - - @RequestMapping(value = "/{taskId}/to/focus", method = RequestMethod.GET) - public final String moveTaskToFocus(@PathVariable("taskId") Task task) { - LOGGER.info("dragged and dropped "+task.getId()+" to focus"); - task = taskMoveService.moveTaskToFocus(task); - return "redirect:/taskstate/focus"; - } - - @RequestMapping(value = "/{taskId}/to/completed", method = RequestMethod.GET) - public final String moveTaskToCompleted(@PathVariable("taskId") Task task) { - LOGGER.info("dragged and dropped "+task.getId()+" to completed"); - task = taskMoveService.moveTaskToCompleted(task); - return "redirect:/taskstate/completed"; - } - - @RequestMapping(value = "/{taskId}/to/trash", method = RequestMethod.GET) - public final String moveTaskToTrash(@PathVariable("taskId") Task task) { - LOGGER.info("dragged and dropped "+task.getId()+" to trash"); - task = taskMoveService.moveTaskToTrash(task); - return "redirect:/taskstate/trash"; - } - - @RequestMapping(value = "/completed/to/trash", method = RequestMethod.GET) - public final String deleteallCompleted( - @ModelAttribute("userSession") UserSessionBean userSession - ) { - Context context = super.getContext(userSession); - taskMoveService.deleteAllCompleted(context); - return "redirect:/taskstate/trash"; - } - - @RequestMapping(value = "/trash/to/void", method = RequestMethod.GET) - public final String emptyTrash( - @ModelAttribute("userSession") UserSessionBean userSession - ) { - Context context = super.getContext(userSession); - taskMoveService.emptyTrash(context); - return "redirect:/taskstate/trash"; - } -} diff --git a/src/main/java/org/woehlke/simpleworklist/taskstate/TaskMoveService.java b/src/main/java/org/woehlke/simpleworklist/taskstate/TaskMoveService.java index 69f253f8..9c35cb6f 100644 --- a/src/main/java/org/woehlke/simpleworklist/taskstate/TaskMoveService.java +++ b/src/main/java/org/woehlke/simpleworklist/taskstate/TaskMoveService.java @@ -3,7 +3,6 @@ import org.woehlke.simpleworklist.context.Context; import org.woehlke.simpleworklist.project.Project; import org.woehlke.simpleworklist.task.Task; -import org.woehlke.simpleworklist.task.TaskState; public interface TaskMoveService { diff --git a/src/main/java/org/woehlke/simpleworklist/taskstate/TaskMoveServiceImpl.java b/src/main/java/org/woehlke/simpleworklist/taskstate/TaskMoveServiceImpl.java index 357b9c21..da2c991d 100644 --- a/src/main/java/org/woehlke/simpleworklist/taskstate/TaskMoveServiceImpl.java +++ b/src/main/java/org/woehlke/simpleworklist/taskstate/TaskMoveServiceImpl.java @@ -1,7 +1,6 @@ package org.woehlke.simpleworklist.taskstate; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Propagation; @@ -9,22 +8,20 @@ import org.woehlke.simpleworklist.context.Context; import org.woehlke.simpleworklist.project.Project; import org.woehlke.simpleworklist.task.Task; -import org.woehlke.simpleworklist.task.TaskState; import org.woehlke.simpleworklist.task.TaskRepository; import java.util.Date; import java.util.List; +@Slf4j @Service @Transactional(propagation = Propagation.REQUIRES_NEW) public class TaskMoveServiceImpl implements TaskMoveService { - private static final Logger LOGGER = LoggerFactory.getLogger(TaskMoveServiceImpl.class); - private final TaskRepository taskRepository; @Autowired - public TaskMoveServiceImpl(TaskRepository taskRepository) { + public TaskMoveServiceImpl( TaskRepository taskRepository ) { this.taskRepository = taskRepository; } @@ -44,7 +41,8 @@ public Task moveTaskToAnotherProject(Task task, Project project) { if(okContext) { task.setProject(project); long maxOrderIdProject = this.getMaxOrderIdProject( - task.getProject(), task.getContext() + task.getProject(), + task.getContext() ); task.setOrderIdProject(++maxOrderIdProject); taskRepository.saveAndFlush(task); @@ -54,103 +52,121 @@ public Task moveTaskToAnotherProject(Task task, Project project) { @Override public Task moveTaskToInbox(Task task) { - long newOrderIdTaskState = this.getMaxOrderIdTaskState( - TaskState.INBOX, task.getContext() - ); - task.setTaskState(TaskState.INBOX); - task.setOrderIdTaskState(++newOrderIdTaskState); - task = taskRepository.saveAndFlush(task); - LOGGER.info("moved " + task.getId() + " to inbox: " + task.toString()); + long newOrderIdTaskState = this.getMaxOrderIdTaskState( + TaskState.INBOX, + task.getContext() + ); + task.setTaskState(TaskState.INBOX); + task.setOrderIdTaskState(++newOrderIdTaskState); + task = taskRepository.saveAndFlush(task); + log.info("moved " + task.getId() + " to inbox: " + task.toString()); return task; } @Override public Task moveTaskToToday(Task task) { - Date now = new Date(); - long newOrderIdTaskState = this.getMaxOrderIdTaskState( - TaskState.TODAY, task.getContext() - ); - task.setOrderIdTaskState(++newOrderIdTaskState); - task.setTaskState(TaskState.TODAY); - task.setDueDate(now); - task = taskRepository.saveAndFlush(task); - LOGGER.info("moved " + task.getId() + " to today: " + task.toString()); + Date now = new Date(); + long newOrderIdTaskState = this.getMaxOrderIdTaskState( + TaskState.TODAY, + task.getContext() + ); + task.setOrderIdTaskState(++newOrderIdTaskState); + task.setTaskState(TaskState.TODAY); + task.setDueDate(now); + task = taskRepository.saveAndFlush(task); + log.info("moved " + task.getId() + " to today: " + task.toString()); return task; } @Override public Task moveTaskToNext(Task task) { - long newOrderIdTaskState = this.getMaxOrderIdTaskState(TaskState.NEXT, task.getContext()); + long newOrderIdTaskState = this.getMaxOrderIdTaskState( + TaskState.NEXT, + task.getContext() + ); task.setOrderIdTaskState(++newOrderIdTaskState); task.setTaskState(TaskState.NEXT); task = taskRepository.saveAndFlush(task); - LOGGER.info("moved " + task.getId() + " to next: " + task.toString()); + log.info("moved " + task.getId() + " to next: " + task.toString()); return task; } @Override public Task moveTaskToWaiting(Task task) { - long newOrderIdTaskState = this.getMaxOrderIdTaskState( - TaskState.WAITING, task.getContext() - ); - task.setOrderIdTaskState(++newOrderIdTaskState); - task.setTaskState(TaskState.WAITING); - task = taskRepository.saveAndFlush(task); - LOGGER.info("moved " + task.getId() + " to next: " + task.toString()); + long newOrderIdTaskState = this.getMaxOrderIdTaskState( + TaskState.WAITING, + task.getContext() + ); + task.setOrderIdTaskState(++newOrderIdTaskState); + task.setTaskState(TaskState.WAITING); + task = taskRepository.saveAndFlush(task); + log.info("moved " + task.getId() + " to next: " + task.toString()); return task; } @Override public Task moveTaskToSomeday(Task task) { long newOrderIdTaskState = this.getMaxOrderIdTaskState( - TaskState.SOMEDAY, task.getContext() + TaskState.SOMEDAY, + task.getContext() ); task.setOrderIdTaskState(++newOrderIdTaskState); task.setTaskState(TaskState.SOMEDAY); task = taskRepository.saveAndFlush(task); - LOGGER.info("moved " + task.getId() + " to someday: " + task.toString()); + log.info("moved " + task.getId() + " to someday: " + task.toString()); return task; } @Override public Task moveTaskToFocus(Task task) { long newOrderIdTaskState = this.getMaxOrderIdTaskState( - TaskState.FOCUS, task.getContext() + TaskState.FOCUS, + task.getContext() ); task.setOrderIdTaskState(++newOrderIdTaskState); task.setFocus(true); task = taskRepository.saveAndFlush(task); - LOGGER.info("moved " + task.getId() + " to focus: " + task.toString()); + log.info("moved " + task.getId() + " to focus: " + task.toString()); return task; } @Override public Task moveTaskToCompleted(Task task) { long newOrderIdTaskState = this.getMaxOrderIdTaskState( - TaskState.COMPLETED, task.getContext() + TaskState.COMPLETED, + task.getContext() ); task.setOrderIdTaskState(++newOrderIdTaskState); task.setTaskState(TaskState.COMPLETED); task = taskRepository.saveAndFlush(task); - LOGGER.debug("moved " + task.getId() + " to completed: " + task.toString()); + log.debug("moved " + task.getId() + " to completed: " + task.toString()); return task; } @Override public Task moveTaskToTrash(Task task) { - long newOrderIdTaskState = this.getMaxOrderIdTaskState(TaskState.TRASH, task.getContext()); + long newOrderIdTaskState = this.getMaxOrderIdTaskState( + TaskState.TRASH, + task.getContext() + ); task.setOrderIdTaskState(++newOrderIdTaskState); task.setTaskState(TaskState.TRASH); task = taskRepository.saveAndFlush(task); - LOGGER.debug("moved " + task.getId() + " to trash: " + task.toString()); + log.debug("moved " + task.getId() + " to trash: " + task.toString()); return task; } @Override public void deleteAllCompleted(Context context) { - long maxOrderIdTaskState = this.getMaxOrderIdTaskStateFor(TaskState.TRASH, context); + long maxOrderIdTaskState = this.getMaxOrderIdTaskStateFor( + TaskState.TRASH, + context + ); long newOrderIdTaskState = maxOrderIdTaskState; - List taskListCompleted = taskRepository.findByTaskStateAndContextOrderByOrderIdTaskStateAsc(TaskState.COMPLETED, context); + List taskListCompleted = taskRepository.findByTaskStateAndContextOrderByOrderIdTaskStateAsc( + TaskState.COMPLETED, + context + ); for (Task task : taskListCompleted) { newOrderIdTaskState++; task.setOrderIdTaskState(newOrderIdTaskState); @@ -159,32 +175,36 @@ public void deleteAllCompleted(Context context) { taskRepository.saveAll(taskListCompleted); } - private long getMaxOrderIdTaskStateFor(TaskState taskState, Context context){ - Task task = taskRepository.findTopByTaskStateAndContextOrderByOrderIdTaskStateDesc(taskState, context); - return (task == null) ? 0 : task.getOrderIdTaskState(); - } - @Override public void emptyTrash(Context context) { - List taskList = taskRepository.findByTaskStateAndContext(TaskState.TRASH, context); + List taskList = taskRepository.findByTaskStateAndContext( + TaskState.TRASH, + context + ); taskRepository.deleteInBatch(taskList); } @Override public long getMaxOrderIdTaskState(TaskState taskState, Context context) { - Task task = taskRepository.findTopByTaskStateAndContextOrderByOrderIdTaskStateDesc(taskState, context); + Task task = taskRepository.findTopByTaskStateAndContextOrderByOrderIdTaskStateDesc( + taskState, + context + ); return (task==null) ? 0 : task.getOrderIdTaskState(); } @Override public long getMaxOrderIdProject(Project project, Context context) { - Task task = taskRepository.findTopByProjectAndContextOrderByOrderIdProjectDesc(project, context); + Task task = taskRepository.findTopByProjectAndContextOrderByOrderIdProjectDesc( + project, + context + ); return (task==null) ? 0 : task.getOrderIdProject(); } @Override @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) - public void moveOrderIdTaskState(Task sourceTask, Task destinationTask) { + public void moveOrderIdTaskState( Task sourceTask, Task destinationTask ) { boolean notEqualsId = ! sourceTask.equalsById(destinationTask); boolean notEquals = ! sourceTask.equalsByUniqueConstraint(destinationTask); boolean sameContext = sourceTask.hasSameContextAs(destinationTask); @@ -195,9 +215,43 @@ public void moveOrderIdTaskState(Task sourceTask, Task destinationTask) { sameContext && sameTaskType ) { if (srcIsBelowDestinationTask) { - this.moveTasksDownByTaskState(sourceTask, destinationTask); + this.moveTasksDownByTaskState( sourceTask, destinationTask ); } else { - this.moveTasksUpByTaskState(sourceTask, destinationTask); + this.moveTasksUpByTaskState( sourceTask, destinationTask ); + } + } + } + + @Override + @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) + public void moveOrderIdRootProject( Task sourceTask, Task destinationTask ) { + boolean sourceTaskRoot = destinationTask.isInRootProject(); + boolean destinationTaskRoot = destinationTask.isInRootProject(); + boolean sameContext = sourceTask.hasSameContextAs(destinationTask); + boolean sameProject = sourceTask.hasSameProjectAs(destinationTask); + boolean srcIsBelowDestinationTask = sourceTask.isBelowByProject(destinationTask); + if (sameContext && sameProject && sourceTaskRoot && destinationTaskRoot) { + if (srcIsBelowDestinationTask) { + this.moveTasksDownByProject(sourceTask, destinationTask); + } else { + this.moveTasksUpByProject(sourceTask, destinationTask); + } + } + } + + @Override + @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) + public void moveOrderIdProject( Task sourceTask, Task destinationTask ) { + Project project = sourceTask.getProject(); + boolean okProject = destinationTask.hasProject(project); + boolean sameContext = sourceTask.hasSameContextAs(destinationTask); + boolean sameProject = sourceTask.hasSameProjectAs(destinationTask); + boolean srcIsBelowDestinationTask = sourceTask.isBelowByProject(destinationTask); + if (sameContext && sameProject && okProject) { + if (srcIsBelowDestinationTask) { + this.moveTasksDownByProject(sourceTask, destinationTask); + } else { + this.moveTasksUpByProject(sourceTask, destinationTask); } } } @@ -209,24 +263,38 @@ public void moveOrderIdTaskState(Task sourceTask, Task destinationTask) { * @param sourceTask * @param destinationTask */ - private void moveTasksUpByTaskState(Task sourceTask, Task destinationTask) { + private void moveTasksUpByTaskState( Task sourceTask, Task destinationTask ) { TaskState taskState = sourceTask.getTaskState(); Context context = sourceTask.getContext(); long lowerOrderIdTaskState = destinationTask.getOrderIdTaskState(); long higherOrderIdTaskState = sourceTask.getOrderIdTaskState(); List tasks = taskRepository.getTasksByOrderIdTaskStateBetweenLowerTaskAndHigherTask( - lowerOrderIdTaskState,higherOrderIdTaskState,taskState,context + lowerOrderIdTaskState, + higherOrderIdTaskState, + taskState, + context ); for(Task task:tasks){ task.moveUpByTaskState(); } - sourceTask.setOrderIdTaskState(destinationTask.getOrderIdTaskState()); + sourceTask.setOrderIdTaskState( destinationTask.getOrderIdTaskState() ); destinationTask.moveDownByTaskState(); tasks.add(sourceTask); tasks.add(destinationTask); taskRepository.saveAll(tasks); } + + + + private long getMaxOrderIdTaskStateFor(TaskState taskState, Context context ){ + Task task = taskRepository.findTopByTaskStateAndContextOrderByOrderIdTaskStateDesc( + taskState, + context + ); + return (task == null) ? 0 : task.getOrderIdTaskState(); + } + /** * Before: sourceTask is dragged from below up to destinationTask, so sourceTask is below destinationTask. * After: sourceTask is placed to the position of destinationTask, all tasks between old position of sourceTask @@ -234,13 +302,16 @@ private void moveTasksUpByTaskState(Task sourceTask, Task destinationTask) { * @param sourceTask * @param destinationTask */ - private void moveTasksDownByTaskState(Task sourceTask, Task destinationTask) { + private void moveTasksDownByTaskState( Task sourceTask, Task destinationTask ) { TaskState taskState = sourceTask.getTaskState(); Context context = sourceTask.getContext(); long lowerOrderIdTaskState = sourceTask.getOrderIdTaskState(); long higherOrderIdTaskState = destinationTask.getOrderIdTaskState(); List tasks = taskRepository.getTasksByOrderIdTaskStateBetweenLowerTaskAndHigherTask( - lowerOrderIdTaskState,higherOrderIdTaskState,taskState,context + lowerOrderIdTaskState, + higherOrderIdTaskState, + taskState, + context ); for(Task task:tasks){ task.moveDownByTaskState(); @@ -252,47 +323,16 @@ private void moveTasksDownByTaskState(Task sourceTask, Task destinationTask) { taskRepository.saveAll(tasks); } - @Override - @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) - public void moveOrderIdRootProject(Task sourceTask, Task destinationTask) { - boolean sourceTaskRoot = destinationTask.isInRootProject(); - boolean destinationTaskRoot = destinationTask.isInRootProject(); - boolean sameContext = sourceTask.hasSameContextAs(destinationTask); - boolean sameProject = sourceTask.hasSameProjectAs(destinationTask); - boolean srcIsBelowDestinationTask = sourceTask.isBelowByProject(destinationTask); - if (sameContext && sameProject && sourceTaskRoot && destinationTaskRoot) { - if (srcIsBelowDestinationTask) { - this.moveTasksDownByProject(sourceTask, destinationTask); - } else { - this.moveTasksUpByProject(sourceTask, destinationTask); - } - } - } - - @Override - @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) - public void moveOrderIdProject(Task sourceTask, Task destinationTask) { - Project project = sourceTask.getProject(); - boolean okProject = destinationTask.hasProject(project); - boolean sameContext = sourceTask.hasSameContextAs(destinationTask); - boolean sameProject = sourceTask.hasSameProjectAs(destinationTask); - boolean srcIsBelowDestinationTask = sourceTask.isBelowByProject(destinationTask); - if (sameContext && sameProject && okProject) { - if (srcIsBelowDestinationTask) { - this.moveTasksDownByProject(sourceTask, destinationTask); - } else { - this.moveTasksUpByProject(sourceTask, destinationTask); - } - } - } - - private void moveTasksUpByProject(Task sourceTask, Task destinationTask) { + private void moveTasksUpByProject( Task sourceTask, Task destinationTask ) { Context context = sourceTask.getContext(); Project project = sourceTask.getProject(); long lowerOrderIdProject = destinationTask.getOrderIdProject(); long higherOrderIdProject = sourceTask.getOrderIdProject(); List tasks = taskRepository.getTasksByOrderIdProjectBetweenLowerTaskAndHigherTask( - lowerOrderIdProject,higherOrderIdProject,project,context + lowerOrderIdProject, + higherOrderIdProject, + project, + context ); for(Task task:tasks){ task.moveUpByProject(); @@ -304,13 +344,16 @@ private void moveTasksUpByProject(Task sourceTask, Task destinationTask) { taskRepository.saveAll(tasks); } - private void moveTasksDownByProject(Task sourceTask, Task destinationTask) { + private void moveTasksDownByProject( Task sourceTask, Task destinationTask ) { Context context = sourceTask.getContext(); Project project = sourceTask.getProject(); long lowerOrderIdProject = sourceTask.getOrderIdProject(); long higherOrderIdProject = destinationTask.getOrderIdProject(); List tasks = taskRepository.getTasksByOrderIdProjectBetweenLowerTaskAndHigherTask( - lowerOrderIdProject,higherOrderIdProject,project,context + lowerOrderIdProject, + higherOrderIdProject, + project, + context ); for(Task task:tasks){ task.moveDownByProject(); diff --git a/src/main/java/org/woehlke/simpleworklist/task/TaskState.java b/src/main/java/org/woehlke/simpleworklist/taskstate/TaskState.java similarity index 95% rename from src/main/java/org/woehlke/simpleworklist/task/TaskState.java rename to src/main/java/org/woehlke/simpleworklist/taskstate/TaskState.java index fdb3d4f8..852622ee 100644 --- a/src/main/java/org/woehlke/simpleworklist/task/TaskState.java +++ b/src/main/java/org/woehlke/simpleworklist/taskstate/TaskState.java @@ -1,4 +1,4 @@ -package org.woehlke.simpleworklist.task; +package org.woehlke.simpleworklist.taskstate; import javax.persistence.Enumerated; import javax.persistence.Transient; diff --git a/src/main/java/org/woehlke/simpleworklist/taskstate/TaskStateController.java b/src/main/java/org/woehlke/simpleworklist/taskstate/TaskStateController.java index fcd74932..1d75d70f 100644 --- a/src/main/java/org/woehlke/simpleworklist/taskstate/TaskStateController.java +++ b/src/main/java/org/woehlke/simpleworklist/taskstate/TaskStateController.java @@ -1,62 +1,52 @@ package org.woehlke.simpleworklist.taskstate; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; import org.springframework.data.web.PageableDefault; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.ModelAttribute; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestMethod; import org.woehlke.simpleworklist.common.AbstractController; import org.woehlke.simpleworklist.context.Context; import org.woehlke.simpleworklist.task.Task; import org.woehlke.simpleworklist.task.TaskControllerService; -import org.woehlke.simpleworklist.task.TaskState; -import org.woehlke.simpleworklist.breadcrumb.Breadcrumb; import org.woehlke.simpleworklist.user.UserSessionBean; -import org.springframework.beans.factory.annotation.Autowired; - import java.util.Locale; - -/** - * Created by tw on 21.02.16. - */ @Slf4j @Controller -@RequestMapping(value = "/taskstate") +@RequestMapping(path = "/taskstate") public class TaskStateController extends AbstractController { + private final TaskStateService taskStateService; - private final TaskMoveService taskMoveService; private final TaskControllerService taskControllerService; @Autowired - public TaskStateController( - TaskStateService taskStateService, - TaskMoveService taskMoveService, - TaskControllerService taskControllerService - ) { + public TaskStateController(TaskStateService taskStateService, TaskControllerService taskControllerService) { this.taskStateService = taskStateService; - this.taskMoveService = taskMoveService; this.taskControllerService = taskControllerService; } - @RequestMapping(value = "/inbox", method = RequestMethod.GET) + @RequestMapping(path = "/inbox", method = RequestMethod.GET) public final String inbox( - @PageableDefault(sort = "orderIdTaskState") Pageable pageable, - @ModelAttribute("userSession") UserSessionBean userSession, - Locale locale, - Model model + @PageableDefault(sort = "orderIdTaskState", direction = Sort.Direction.DESC) Pageable pageable, + @ModelAttribute("userSession") UserSessionBean userSession, + Locale locale, + Model model ) { Context context = super.getContext(userSession); Page taskPage = taskStateService.getInbox(context, pageable); return taskControllerService.getTaskStatePage(TaskState.INBOX, taskPage, userSession, locale, model); } - @RequestMapping(value = "/today", method = RequestMethod.GET) + @RequestMapping(path = "/today", method = RequestMethod.GET) public final String today( @PageableDefault(sort = "orderIdTaskState", direction = Sort.Direction.DESC) Pageable pageable, @ModelAttribute("userSession") UserSessionBean userSession, @@ -68,7 +58,7 @@ public final String today( return taskControllerService.getTaskStatePage(TaskState.TODAY, taskPage, userSession, locale, model); } - @RequestMapping(value = "/next", method = RequestMethod.GET) + @RequestMapping(path = "/next", method = RequestMethod.GET) public final String next( @PageableDefault(sort = "orderIdTaskState", direction = Sort.Direction.DESC) Pageable pageable, @ModelAttribute("userSession") UserSessionBean userSession, @@ -80,7 +70,7 @@ public final String next( return taskControllerService.getTaskStatePage(TaskState.NEXT, taskPage, userSession, locale, model); } - @RequestMapping(value = "/waiting", method = RequestMethod.GET) + @RequestMapping(path = "/waiting", method = RequestMethod.GET) public final String waiting( @PageableDefault(sort = "orderIdTaskState", direction = Sort.Direction.DESC) Pageable pageable, @ModelAttribute("userSession") UserSessionBean userSession, @@ -92,7 +82,7 @@ public final String waiting( return taskControllerService.getTaskStatePage(TaskState.WAITING, taskPage, userSession, locale, model); } - @RequestMapping(value = "/scheduled", method = RequestMethod.GET) + @RequestMapping(path = "/scheduled", method = RequestMethod.GET) public final String scheduled( @PageableDefault(sort = "orderIdTaskState", direction = Sort.Direction.DESC) Pageable pageable, @ModelAttribute("userSession") UserSessionBean userSession, @@ -104,7 +94,7 @@ public final String scheduled( return taskControllerService.getTaskStatePage(TaskState.SCHEDULED, taskPage, userSession, locale, model); } - @RequestMapping(value = "/someday", method = RequestMethod.GET) + @RequestMapping(path = "/someday", method = RequestMethod.GET) public final String someday( @PageableDefault(sort = "orderIdTaskState", direction = Sort.Direction.DESC) Pageable pageable, @ModelAttribute("userSession") UserSessionBean userSession, @@ -116,7 +106,7 @@ public final String someday( return taskControllerService.getTaskStatePage(TaskState.SOMEDAY, taskPage, userSession, locale, model); } - @RequestMapping(value = "/completed", method = RequestMethod.GET) + @RequestMapping(path = "/completed", method = RequestMethod.GET) public final String completed( @PageableDefault(sort = "orderIdTaskState", direction = Sort.Direction.DESC) Pageable pageable, @ModelAttribute("userSession") UserSessionBean userSession, @@ -128,7 +118,7 @@ public final String completed( return taskControllerService.getTaskStatePage(TaskState.COMPLETED, taskPage, userSession, locale, model); } - @RequestMapping(value = "/trash", method = RequestMethod.GET) + @RequestMapping(path = "/trash", method = RequestMethod.GET) public final String trash( @PageableDefault(sort = "orderIdTaskState", direction = Sort.Direction.DESC) Pageable pageable, @ModelAttribute("userSession") UserSessionBean userSession, @@ -140,7 +130,7 @@ public final String trash( return taskControllerService.getTaskStatePage(TaskState.TRASH, taskPage, userSession, locale, model); } - @RequestMapping(value = "/focus", method = RequestMethod.GET) + @RequestMapping(path = "/focus", method = RequestMethod.GET) public final String focus( @PageableDefault(sort = "orderIdTaskState", direction = Sort.Direction.DESC) Pageable pageable, @ModelAttribute("userSession") UserSessionBean userSession, @@ -151,76 +141,4 @@ public final String focus( Page taskPage = taskStateService.getFocus(context, pageable); return taskControllerService.getTaskStatePage(TaskState.FOCUS, taskPage, userSession, locale, model); } - - @RequestMapping(value = "/{sourceTaskId}/changeorderto/{destinationTaskId}", method = RequestMethod.GET) - public String changeTaskOrderId( - @PathVariable("sourceTaskId") Task sourceTask, - @PathVariable("destinationTaskId") Task destinationTask, - @ModelAttribute("userSession") UserSessionBean userSession, - Model model - ){ - userSession.setLastTaskState(sourceTask.getTaskState()); - model.addAttribute("userSession", userSession); - log.info("------------- changeTaskOrderId -------------"); - log.info("source Task: "+sourceTask.toString()); - log.info("---------------------------------------------"); - log.info("destination Task: "+destinationTask.toString()); - log.info("---------------------------------------------"); - taskMoveService.moveOrderIdTaskState(sourceTask, destinationTask); - return "redirect:/taskstate/" + sourceTask.getTaskState().name().toLowerCase(); - } - - @RequestMapping(path = "/complete/{taskId}", method = RequestMethod.GET) - public final String setDoneTaskGet( - @PathVariable("taskId") Task task - ) { - if(task != null){ - long maxOrderIdTaskState = taskMoveService.getMaxOrderIdTaskState(TaskState.COMPLETED,task.getContext()); - task.setOrderIdTaskState(++maxOrderIdTaskState); - taskService.complete(task); - } - return "redirect:/taskstate/completed"; - } - - @RequestMapping(path = "/incomplete/{taskId}", method = RequestMethod.GET) - public final String unsetDoneTaskGet( - @PathVariable("taskId") Task task - ) { - if(task !=null) { - taskService.incomplete(task); - long maxOrderIdTaskState = taskMoveService.getMaxOrderIdTaskState(task.getTaskState(),task.getContext()); - task.setOrderIdTaskState(++maxOrderIdTaskState); - taskService.saveAndFlush(task); - return "redirect:/taskstate/"+task.getTaskState().name().toLowerCase(); - } else { - return "redirect:/taskstate/inbox"; - } - } - - @RequestMapping(path = "/setfocus/{taskId}", method = RequestMethod.GET) - public final String setFocusGet( - @PathVariable("taskId") Task task, - @RequestParam(required=false) String back - ){ - if(task !=null) { - taskService.setFocus(task); - return taskControllerService.getView(task,back); - } else { - return "redirect:/taskstate/inbox"; - } - } - - @RequestMapping(path = "/unsetfocus/{taskId}", method = RequestMethod.GET) - public final String unsetFocusGet( - @PathVariable("taskId") Task task, - @RequestParam(required=false) String back - ){ - if(task !=null) { - taskService.unsetFocus(task); - return taskControllerService.getView(task,back); - } else { - return "redirect:/taskstate/inbox"; - } - } - } diff --git a/src/main/java/org/woehlke/simpleworklist/taskstate/TaskStateMoveController.java b/src/main/java/org/woehlke/simpleworklist/taskstate/TaskStateMoveController.java new file mode 100644 index 00000000..4f058f61 --- /dev/null +++ b/src/main/java/org/woehlke/simpleworklist/taskstate/TaskStateMoveController.java @@ -0,0 +1,214 @@ +package org.woehlke.simpleworklist.taskstate; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.BindingResult; +import org.springframework.validation.ObjectError; +import org.springframework.web.bind.annotation.*; +import org.woehlke.simpleworklist.breadcrumb.Breadcrumb; +import org.woehlke.simpleworklist.common.AbstractController; +import org.woehlke.simpleworklist.context.Context; +import org.woehlke.simpleworklist.project.Project; +import org.woehlke.simpleworklist.task.Task; +import org.woehlke.simpleworklist.task.TaskEnergy; +import org.woehlke.simpleworklist.task.TaskTime; +import org.woehlke.simpleworklist.user.UserSessionBean; + +import org.springframework.beans.factory.annotation.Autowired; +import org.woehlke.simpleworklist.user.account.UserAccount; + +import javax.validation.Valid; +import java.util.Locale; + +/** + * Created by tw on 21.02.16. + */ +@Slf4j +@Controller +@RequestMapping(path = "/taskstate/task") +public class TaskStateMoveController extends AbstractController { + + private final TaskMoveService taskMoveService; + + @Autowired + public TaskStateMoveController( + TaskMoveService taskMoveService + ) { + this.taskMoveService = taskMoveService; + } + + @RequestMapping(path = "/add", method = RequestMethod.GET) + public final String addNewTaskToInboxGet( + @ModelAttribute("userSession") UserSessionBean userSession, + Locale locale, Model model + ) { + log.info("addNewTaskToInboxGet"); + UserAccount userAccount = userAccountLoginSuccessService.retrieveCurrentUser(); + Task task = new Task(); + task.setTaskState(TaskState.INBOX); + task.setTaskEnergy(TaskEnergy.NONE); + task.setTaskTime(TaskTime.NONE); + Boolean mustChooseContext = false; + if(userSession.getContextId() == 0L){ + mustChooseContext = true; + task.setContext(userAccount.getDefaultContext()); + } else { + Context context = contextService.findByIdAndUserAccount(userSession.getContextId(), userAccount); + task.setContext(context); + } + Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForTaskstate(TaskState.INBOX,locale); + model.addAttribute("breadcrumb", breadcrumb); + model.addAttribute("mustChooseArea", mustChooseContext); + model.addAttribute("breadcrumb", breadcrumb); + model.addAttribute("task", task); + return "taskstate/task/add"; + } + + @RequestMapping(path = "/add", method = RequestMethod.POST) + public final String addNewTaskToInboxPost( + @ModelAttribute("userSession") UserSessionBean userSession, + @Valid Task task, + BindingResult result, + Locale locale, + Model model + ) { + log.info("addNewTaskToInboxPost"); + Context context = super.getContext(userSession); + if (result.hasErrors()) { + for (ObjectError e : result.getAllErrors()) { + log.info(e.toString()); + } + Boolean mustChooseArea = false; + task.setContext(context); + Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForTaskstate(TaskState.INBOX,locale); + model.addAttribute("mustChooseArea", mustChooseArea); + model.addAttribute("breadcrumb", breadcrumb); + model.addAttribute("task", task); + return "taskstate/task/add"; + } else { + task.setProject(null); + if(task.getDueDate()==null){ + task.setTaskState(TaskState.INBOX); + } else { + task.setTaskState(TaskState.SCHEDULED); + } + task.setFocus(false); + task.setContext(context); + long maxOrderIdProject = taskMoveService.getMaxOrderIdProject(task.getProject(),context); + task.setOrderIdProject(++maxOrderIdProject); + long maxOrderIdTaskState = taskMoveService.getMaxOrderIdTaskState(task.getTaskState(),task.getContext()); + task.setOrderIdTaskState(++maxOrderIdTaskState); + task = taskService.saveAndFlush(task); + log.info(task.toString()); + return "redirect:/taskstate/" + task.getTaskState().name().toLowerCase(); + } + } + + @RequestMapping(path = "/{sourceTaskId}/changeorderto/{destinationTaskId}", method = RequestMethod.GET) + public String changeTaskOrderId( + @PathVariable("sourceTaskId") Task sourceTask, + @PathVariable("destinationTaskId") Task destinationTask, + @ModelAttribute("userSession") UserSessionBean userSession, + Model model + ){ + userSession.setLastTaskState(sourceTask.getTaskState()); + model.addAttribute("userSession", userSession); + log.info("------------- changeTaskOrderId -------------"); + log.info("source Task: "+sourceTask.toString()); + log.info("---------------------------------------------"); + log.info("destination Task: "+destinationTask.toString()); + log.info("---------------------------------------------"); + taskMoveService.moveOrderIdTaskState(sourceTask, destinationTask); + return "redirect:/taskstate/" + sourceTask.getTaskState().name().toLowerCase(); + } + + @RequestMapping(path = "/{taskId}/move/to/project/{projectId}", method = RequestMethod.GET) + public final String moveTaskToAnotherProject( + @PathVariable("taskId") Task task, + @PathVariable long projectId + ) { + if(projectId == 0) { + task = taskMoveService.moveTaskToRootProject(task); + } else { + Project project = projectService.findByProjectId(projectId); + task = taskMoveService.moveTaskToAnotherProject(task,project); + } + return "redirect:/project/" + projectId + "/"; + } + + @RequestMapping(path = "/{taskId}/move/to/taskstate/inbox", method = RequestMethod.GET) + public final String moveTaskToInbox(@PathVariable("taskId") Task task) { + log.info("dragged and dropped "+task.getId()+" to inbox"); + task = taskMoveService.moveTaskToInbox(task); + return "redirect:/taskstate/inbox"; + } + + @RequestMapping(path = "/{taskId}/move/to/taskstate/today", method = RequestMethod.GET) + public final String moveTaskToToday(@PathVariable("taskId") Task task) { + log.info("dragged and dropped "+task.getId()+" to today"); + task = taskMoveService.moveTaskToToday(task); + return "redirect:/taskstate/today"; + } + + @RequestMapping(path = "/{taskId}/move/to/taskstate/next", method = RequestMethod.GET) + public final String moveTaskToNext(@PathVariable("taskId") Task task) { + log.info("dragged and dropped "+task.getId()+" to next"); + task = taskMoveService.moveTaskToNext(task); + return "redirect:/taskstate/next"; + } + + @RequestMapping(path = "/{taskId}/move/to/taskstate/waiting", method = RequestMethod.GET) + public final String moveTaskToWaiting(@PathVariable("taskId") Task task) { + log.info("dragged and dropped "+task.getId()+" to waiting"); + task = taskMoveService.moveTaskToWaiting(task); + return "redirect:/taskstate/waiting"; + } + + @RequestMapping(path = "/{taskId}/move/to/taskstate/someday", method = RequestMethod.GET) + public final String moveTaskToSomeday(@PathVariable("taskId") Task task) { + log.info("dragged and dropped "+task.getId()+" to someday"); + task = taskMoveService.moveTaskToSomeday(task); + return "redirect:/taskstate/someday"; + } + + @RequestMapping(path = "/{taskId}/move/to/taskstate/focus", method = RequestMethod.GET) + public final String moveTaskToFocus(@PathVariable("taskId") Task task) { + log.info("dragged and dropped "+task.getId()+" to focus"); + task = taskMoveService.moveTaskToFocus(task); + return "redirect:/taskstate/focus"; + } + + @RequestMapping(path = "/{taskId}/move/to/taskstate/completed", method = RequestMethod.GET) + public final String moveTaskToCompleted(@PathVariable("taskId") Task task) { + log.info("dragged and dropped "+task.getId()+" to completed"); + task = taskMoveService.moveTaskToCompleted(task); + return "redirect:/taskstate/completed"; + } + + @RequestMapping(path = "/{taskId}/move/to/trash", method = RequestMethod.GET) + public final String moveTaskToTrash(@PathVariable("taskId") Task task) { + log.info("dragged and dropped "+task.getId()+" to trash"); + task = taskMoveService.moveTaskToTrash(task); + return "redirect:/taskstate/trash"; + } + + @RequestMapping(path = "/completed/move/to/trash", method = RequestMethod.GET) + public final String deleteallCompleted( + @ModelAttribute("userSession") UserSessionBean userSession + ) { + Context context = super.getContext(userSession); + taskMoveService.deleteAllCompleted(context); + return "redirect:/taskstate/trash"; + } + + @RequestMapping(path = "/trash/empty", method = RequestMethod.GET) + public final String emptyTrash( + @ModelAttribute("userSession") UserSessionBean userSession + ) { + Context context = super.getContext(userSession); + taskMoveService.emptyTrash(context); + return "redirect:/taskstate/trash"; + } + +} diff --git a/src/main/java/org/woehlke/simpleworklist/taskstate/TaskStateServiceImpl.java b/src/main/java/org/woehlke/simpleworklist/taskstate/TaskStateServiceImpl.java index 8932a65a..cdb75395 100644 --- a/src/main/java/org/woehlke/simpleworklist/taskstate/TaskStateServiceImpl.java +++ b/src/main/java/org/woehlke/simpleworklist/taskstate/TaskStateServiceImpl.java @@ -1,5 +1,6 @@ package org.woehlke.simpleworklist.taskstate; +import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; @@ -7,7 +8,6 @@ import org.springframework.transaction.annotation.Transactional; import org.woehlke.simpleworklist.context.Context; import org.woehlke.simpleworklist.task.Task; -import org.woehlke.simpleworklist.task.TaskState; import org.woehlke.simpleworklist.task.TaskRepository; import org.springframework.beans.factory.annotation.Autowired; @@ -15,6 +15,7 @@ /** * Created by tw on 21.02.16. */ +@Slf4j @Service @Transactional(propagation = Propagation.REQUIRED, readOnly = true) public class TaskStateServiceImpl implements TaskStateService { diff --git a/src/main/java/org/woehlke/simpleworklist/testdata/TestDataController.java b/src/main/java/org/woehlke/simpleworklist/testdata/TestDataController.java index f2668f6e..e02d736e 100644 --- a/src/main/java/org/woehlke/simpleworklist/testdata/TestDataController.java +++ b/src/main/java/org/woehlke/simpleworklist/testdata/TestDataController.java @@ -1,5 +1,6 @@ package org.woehlke.simpleworklist.testdata; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -8,21 +9,24 @@ import org.springframework.beans.factory.annotation.Autowired; import org.woehlke.simpleworklist.user.login.UserAccountLoginSuccessService; +@Slf4j @Controller -@RequestMapping(value = "/test") +@RequestMapping(path = "/testdata") public class TestDataController { private final TestDataService testDataService; - private final UserAccountLoginSuccessService userAccountLoginSuccessService; @Autowired - public TestDataController(TestDataService testDataService, UserAccountLoginSuccessService userAccountLoginSuccessService) { + public TestDataController( + TestDataService testDataService, + UserAccountLoginSuccessService userAccountLoginSuccessService + ) { this.testDataService = testDataService; this.userAccountLoginSuccessService = userAccountLoginSuccessService; } - @RequestMapping(value = "/helper/project/createTree", method = RequestMethod.GET) + @RequestMapping(path = "/createTree", method = RequestMethod.GET) public String createTestCategoryTree() { UserAccount user = userAccountLoginSuccessService.retrieveCurrentUser(); testDataService.createTestCategoryTreeForUserAccount(user); diff --git a/src/main/java/org/woehlke/simpleworklist/testdata/TestDataServiceImpl.java b/src/main/java/org/woehlke/simpleworklist/testdata/TestDataServiceImpl.java index 6a30653a..0512e051 100644 --- a/src/main/java/org/woehlke/simpleworklist/testdata/TestDataServiceImpl.java +++ b/src/main/java/org/woehlke/simpleworklist/testdata/TestDataServiceImpl.java @@ -9,7 +9,7 @@ import org.woehlke.simpleworklist.project.Project; import org.woehlke.simpleworklist.task.Task; import org.woehlke.simpleworklist.task.TaskEnergy; -import org.woehlke.simpleworklist.task.TaskState; +import org.woehlke.simpleworklist.taskstate.TaskState; import org.woehlke.simpleworklist.user.account.UserAccount; import org.woehlke.simpleworklist.task.TaskTime; import org.woehlke.simpleworklist.context.ContextRepository; diff --git a/src/main/java/org/woehlke/simpleworklist/user/UserDetailsBean.java b/src/main/java/org/woehlke/simpleworklist/user/UserDetailsBean.java index d86109d2..0246c205 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/UserDetailsBean.java +++ b/src/main/java/org/woehlke/simpleworklist/user/UserDetailsBean.java @@ -1,16 +1,20 @@ package org.woehlke.simpleworklist.user; -import java.io.Serializable; import java.util.ArrayList; import java.util.Collection; import java.util.List; +import lombok.*; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.userdetails.UserDetails; import org.woehlke.simpleworklist.user.account.UserAccount; -public class UserDetailsBean implements UserDetails, Serializable { + +@Getter +@EqualsAndHashCode +@ToString(exclude = {"password"}) +public class UserDetailsBean implements UserDetails { private static final long serialVersionUID = 1L; @@ -42,68 +46,4 @@ public Collection getAuthorities() { authorities.add(new SimpleGrantedAuthority("ROLE_USER")); return authorities; } - - @Override - public String getPassword() { - return password; - } - - @Override - public String getUsername() { - return username; - } - - @Override - public boolean isAccountNonExpired() { - return accountNonExpired; - } - - @Override - public boolean isAccountNonLocked() { - return accountNonLocked; - } - - @Override - public boolean isCredentialsNonExpired() { - return credentialsNonExpired; - } - - @Override - public boolean isEnabled() { - return enabled; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((password == null) ? 0 : password.hashCode()); - result = prime * result - + ((username == null) ? 0 : username.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; - UserDetailsBean other = (UserDetailsBean) obj; - if (password == null) { - if (other.password != null) - return false; - } else if (!password.equals(other.password)) - return false; - if (username == null) { - if (other.username != null) - return false; - } else if (!username.equals(other.username)) - return false; - return true; - } - } diff --git a/src/main/java/org/woehlke/simpleworklist/user/UserSessionBean.java b/src/main/java/org/woehlke/simpleworklist/user/UserSessionBean.java index 0d9ef57c..08b77975 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/UserSessionBean.java +++ b/src/main/java/org/woehlke/simpleworklist/user/UserSessionBean.java @@ -1,24 +1,28 @@ package org.woehlke.simpleworklist.user; -import org.woehlke.simpleworklist.task.TaskState; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.woehlke.simpleworklist.taskstate.TaskState; import java.io.Serializable; -import java.util.Objects; /** * Created by tw on 13.03.16. */ +@Getter +@Setter +@EqualsAndHashCode +@ToString public class UserSessionBean implements Serializable { private static final long serialVersionUID = -6649686058228455825L; private Long contextId; - - private String lastSearchterm; - private TaskState lastTaskState; - private Long lastProjectId; + private String lastSearchterm; public UserSessionBean(){ lastSearchterm=""; @@ -34,61 +38,4 @@ public UserSessionBean(long contextId){ this.contextId = contextId; } - public Long getContextId() { - return contextId; - } - - public void setContextId(Long contextId) { - this.contextId = contextId; - } - - public String getLastSearchterm() { - return lastSearchterm; - } - - public void setLastSearchterm(String lastSearchterm) { - this.lastSearchterm = lastSearchterm; - } - - public TaskState getLastTaskState() { - return lastTaskState; - } - - public void setLastTaskState(TaskState lastTaskState) { - this.lastTaskState = lastTaskState; - } - - public Long getLastProjectId() { - return lastProjectId; - } - - public void setLastProjectId(Long lastProjectId) { - this.lastProjectId = lastProjectId; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof UserSessionBean)) return false; - UserSessionBean that = (UserSessionBean) o; - return getContextId().equals(that.getContextId()) && - getLastSearchterm().equals(that.getLastSearchterm()) && - getLastTaskState() == that.getLastTaskState() && - getLastProjectId().equals(that.getLastProjectId()); - } - - @Override - public int hashCode() { - return Objects.hash(getContextId(), getLastSearchterm(), getLastTaskState(), getLastProjectId()); - } - - @Override - public String toString() { - return "UserSessionBean{" + - "contextId=" + contextId + - ", lastSearchterm='" + lastSearchterm + '\'' + - ", lastTaskState=" + lastTaskState + - ", lastProjectId=" + lastProjectId + - '}'; - } } diff --git a/src/main/java/org/woehlke/simpleworklist/user/account/UserAccountAccessServiceImpl.java b/src/main/java/org/woehlke/simpleworklist/user/account/UserAccountAccessServiceImpl.java index e87d8e75..1cebc265 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/account/UserAccountAccessServiceImpl.java +++ b/src/main/java/org/woehlke/simpleworklist/user/account/UserAccountAccessServiceImpl.java @@ -1,7 +1,6 @@ package org.woehlke.simpleworklist.user.account; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; @@ -14,22 +13,23 @@ import org.woehlke.simpleworklist.user.login.LoginForm; import org.woehlke.simpleworklist.user.selfservice.UserChangePasswordForm; +@Slf4j @Service @Transactional(propagation = Propagation.REQUIRED, readOnly = true) public class UserAccountAccessServiceImpl implements UserAccountAccessService { - private static final Logger LOGGER = LoggerFactory.getLogger(UserAccountAccessServiceImpl.class); - private final UserAccountRepository userAccountRepository; - private final AuthenticationManager authenticationManager; - private final PasswordEncoder encoder; @Autowired - public UserAccountAccessServiceImpl(UserAccountRepository userAccountRepository, AuthenticationManager authenticationManager) { + public UserAccountAccessServiceImpl( + UserAccountRepository userAccountRepository, + AuthenticationManager authenticationManager + ) { this.userAccountRepository = userAccountRepository; this.authenticationManager = authenticationManager; + //TODO: int strength = 10; this.encoder = new BCryptPasswordEncoder(strength); } @@ -37,8 +37,14 @@ public UserAccountAccessServiceImpl(UserAccountRepository userAccountRepository, @Override @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) - public void changeUsersPassword(UserChangePasswordForm userAccountFormBean, UserAccount user) { - UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(user.getUserEmail(), userAccountFormBean.getOldUserPassword()); + public void changeUsersPassword( + UserChangePasswordForm userAccountFormBean, + UserAccount user + ) { + UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( + user.getUserEmail(), + userAccountFormBean.getOldUserPassword() + ); Authentication authenticationResult = authenticationManager.authenticate(token); if(authenticationResult.isAuthenticated()){ UserAccount ua = userAccountRepository.findByUserEmail(user.getUserEmail()); @@ -49,17 +55,26 @@ public void changeUsersPassword(UserChangePasswordForm userAccountFormBean, User } @Override - public boolean confirmUserByLoginAndPassword(String userEmail, String oldUserPassword) { - UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(userEmail, oldUserPassword); + public boolean confirmUserByLoginAndPassword( + String userEmail, + String oldUserPassword + ) { + UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken( + userEmail, + oldUserPassword + ); Authentication authenticationResult = authenticationManager.authenticate(token); String oldPwEncoded = this.encoder.encode(oldUserPassword); - LOGGER.info(userEmail+", "+oldPwEncoded); + log.info(userEmail+", "+oldPwEncoded); return authenticationResult.isAuthenticated(); } @Override public boolean authorize(LoginForm loginForm) { - UserAccount account = userAccountRepository.findByUserEmailAndUserPassword(loginForm.getUserEmail(), loginForm.getUserPassword()); + UserAccount account = userAccountRepository.findByUserEmailAndUserPassword( + loginForm.getUserEmail(), + loginForm.getUserPassword() + ); return account != null; } } diff --git a/src/main/java/org/woehlke/simpleworklist/user/account/UserAccountForm.java b/src/main/java/org/woehlke/simpleworklist/user/account/UserAccountForm.java index 640fe1c9..16b10556 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/account/UserAccountForm.java +++ b/src/main/java/org/woehlke/simpleworklist/user/account/UserAccountForm.java @@ -5,10 +5,19 @@ import javax.validation.constraints.Email; import javax.validation.constraints.NotBlank; + +import lombok.*; import org.hibernate.validator.constraints.SafeHtml; import java.io.Serializable; + +@Getter +@Setter +@EqualsAndHashCode +@AllArgsConstructor +@NoArgsConstructor +@ToString(exclude = {"userPassword"}) public class UserAccountForm implements Serializable { private static final long serialVersionUID = 9180383385243540190L; @@ -19,6 +28,12 @@ public class UserAccountForm implements Serializable { @Email(message = "Email Address is not a valid format") private String userEmail; + //TODO: Messages i18n + @SafeHtml(whitelistType= SafeHtml.WhiteListType.NONE) + @NotNull(message = "Fullname is compulsory") + @NotBlank(message = "Fullname is compulsory") + private String userFullname; + //TODO: Messages i18n @SafeHtml(whitelistType= SafeHtml.WhiteListType.NONE) @NotNull(message = "Password is compulsory") @@ -31,105 +46,9 @@ public class UserAccountForm implements Serializable { @NotBlank(message = "Password is compulsory") private String userPasswordConfirmation; - //TODO: Messages i18n - @SafeHtml(whitelistType= SafeHtml.WhiteListType.NONE) - @NotNull(message = "Fullname is compulsory") - @NotBlank(message = "Fullname is compulsory") - private String userFullname; - - public String getUserEmail() { - return userEmail; - } - - public void setUserEmail(String userEmail) { - this.userEmail = userEmail; - } - - public String getUserPassword() { - return userPassword; - } - - public void setUserPassword(String userPassword) { - this.userPassword = userPassword; - } - - public String getUserPasswordConfirmation() { - return userPasswordConfirmation; - } - - public void setUserPasswordConfirmation(String userPasswordConfirmation) { - this.userPasswordConfirmation = userPasswordConfirmation; - } - - public String getUserFullname() { - return userFullname; - } - - public void setUserFullname(String userFullname) { - this.userFullname = userFullname; - } - @Transient public boolean passwordsAreTheSame() { return this.userPassword.compareTo(userPasswordConfirmation) == 0; } - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((userEmail == null) ? 0 : userEmail.hashCode()); - result = prime * result - + ((userFullname == null) ? 0 : userFullname.hashCode()); - result = prime * result - + ((userPassword == null) ? 0 : userPassword.hashCode()); - result = prime - * result - + ((userPasswordConfirmation == null) ? 0 - : userPasswordConfirmation.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; - UserAccountForm other = (UserAccountForm) obj; - if (userEmail == null) { - if (other.userEmail != null) - return false; - } else if (!userEmail.equals(other.userEmail)) - return false; - if (userFullname == null) { - if (other.userFullname != null) - return false; - } else if (!userFullname.equals(other.userFullname)) - return false; - if (userPassword == null) { - if (other.userPassword != null) - return false; - } else if (!userPassword.equals(other.userPassword)) - return false; - if (userPasswordConfirmation == null) { - if (other.userPasswordConfirmation != null) - return false; - } else if (!userPasswordConfirmation - .equals(other.userPasswordConfirmation)) - return false; - return true; - } - - @Override - public String toString() { - return "UserAccountForm [userEmail=" + userEmail - + ", userPassword=" + userPassword - + ", userPasswordConfirmation=" + userPasswordConfirmation - + ", userFullname=" + userFullname + "]"; - } - } diff --git a/src/main/java/org/woehlke/simpleworklist/user/account/UserAccountSecurityServiceImpl.java b/src/main/java/org/woehlke/simpleworklist/user/account/UserAccountSecurityServiceImpl.java index 9dcd187d..88e771d5 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/account/UserAccountSecurityServiceImpl.java +++ b/src/main/java/org/woehlke/simpleworklist/user/account/UserAccountSecurityServiceImpl.java @@ -1,7 +1,6 @@ package org.woehlke.simpleworklist.user.account; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.userdetails.UserDetails; import org.springframework.security.core.userdetails.UsernameNotFoundException; @@ -10,12 +9,11 @@ import org.springframework.transaction.annotation.Transactional; import org.woehlke.simpleworklist.user.UserDetailsBean; +@Slf4j @Service @Transactional(propagation = Propagation.REQUIRED, readOnly = true) public class UserAccountSecurityServiceImpl implements UserAccountSecurityService { - private static final Logger log = LoggerFactory.getLogger(UserAccountSecurityServiceImpl.class); - private final UserAccountRepository userAccountRepository; @Autowired diff --git a/src/main/java/org/woehlke/simpleworklist/user/account/UserAccountServiceImpl.java b/src/main/java/org/woehlke/simpleworklist/user/account/UserAccountServiceImpl.java index ce07c728..5257edbf 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/account/UserAccountServiceImpl.java +++ b/src/main/java/org/woehlke/simpleworklist/user/account/UserAccountServiceImpl.java @@ -6,10 +6,9 @@ import java.util.List; import java.util.Map; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; @@ -23,18 +22,14 @@ import org.woehlke.simpleworklist.context.ContextRepository; import org.woehlke.simpleworklist.user.messages.User2UserMessageRepository; +@Slf4j @Service("userAccountService") @Transactional(propagation = Propagation.REQUIRED, readOnly = true) public class UserAccountServiceImpl implements UserAccountService { - private static final Logger LOGGER = LoggerFactory.getLogger(UserAccountServiceImpl.class); - private final UserAccountRepository userAccountRepository; - private final User2UserMessageRepository userMessageRepository; - private final ContextRepository contextRepository; - private final PasswordEncoder encoder; @Autowired @@ -64,19 +59,19 @@ public void createUser(UserAccountForm userAccount) { u.setAccountNonLocked(true); u.setCredentialsNonExpired(true); u.setEnabled(true); - LOGGER.info("About to save " + u.toString()); + log.info("About to save " + u.toString()); u = userAccountRepository.save(u); Context workContext = new Context("Arbeit","Work"); Context privContext = new Context("Privat","Private"); workContext.setUserAccount(u); privContext.setUserAccount(u); - LOGGER.info("About to save " + workContext.toString()); + log.info("About to save " + workContext.toString()); contextRepository.save(workContext); - LOGGER.info("About to save " + privContext.toString()); + log.info("About to save " + privContext.toString()); contextRepository.save(privContext); u.setDefaultContext(workContext); u = userAccountRepository.save(u); - LOGGER.info("Saved " + u.toString()); + log.info("Saved " + u.toString()); } @Override diff --git a/src/main/java/org/woehlke/simpleworklist/user/UserRole.java b/src/main/java/org/woehlke/simpleworklist/user/account/UserRole.java similarity index 82% rename from src/main/java/org/woehlke/simpleworklist/user/UserRole.java rename to src/main/java/org/woehlke/simpleworklist/user/account/UserRole.java index eddaaab4..9d10be86 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/UserRole.java +++ b/src/main/java/org/woehlke/simpleworklist/user/account/UserRole.java @@ -1,4 +1,4 @@ -package org.woehlke.simpleworklist.user; +package org.woehlke.simpleworklist.user.account; import javax.persistence.Enumerated; import java.io.Serializable; diff --git a/src/main/java/org/woehlke/simpleworklist/user/login/LoginForm.java b/src/main/java/org/woehlke/simpleworklist/user/login/LoginForm.java index 1312b151..930682ea 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/login/LoginForm.java +++ b/src/main/java/org/woehlke/simpleworklist/user/login/LoginForm.java @@ -4,10 +4,18 @@ import javax.validation.constraints.Email; import javax.validation.constraints.NotBlank; + +import lombok.*; import org.hibernate.validator.constraints.SafeHtml; import java.io.Serializable; +@Getter +@Setter +@EqualsAndHashCode +@AllArgsConstructor +@NoArgsConstructor +@ToString(exclude = {"userPassword"}) public class LoginForm implements Serializable { private static final long serialVersionUID = 5936886560348238355L; @@ -24,53 +32,4 @@ public class LoginForm implements Serializable { @NotBlank(message = "Password is compulsory") private String userPassword; - public String getUserEmail() { - return userEmail; - } - - public void setUserEmail(String userEmail) { - this.userEmail = userEmail; - } - - public String getUserPassword() { - return userPassword; - } - - public void setUserPassword(String userPassword) { - this.userPassword = userPassword; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((userEmail == null) ? 0 : userEmail.hashCode()); - result = prime * result - + ((userPassword == null) ? 0 : userPassword.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; - LoginForm other = (LoginForm) obj; - if (userEmail == null) { - if (other.userEmail != null) - return false; - } else if (!userEmail.equals(other.userEmail)) - return false; - if (userPassword == null) { - if (other.userPassword != null) - return false; - } else if (!userPassword.equals(other.userPassword)) - return false; - return true; - } - } diff --git a/src/main/java/org/woehlke/simpleworklist/user/login/LoginSuccessHandler.java b/src/main/java/org/woehlke/simpleworklist/user/login/LoginSuccessHandler.java index e26f0831..4e7375c8 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/login/LoginSuccessHandler.java +++ b/src/main/java/org/woehlke/simpleworklist/user/login/LoginSuccessHandler.java @@ -1,7 +1,6 @@ package org.woehlke.simpleworklist.user.login; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.springframework.security.core.Authentication; import org.springframework.security.web.authentication.AuthenticationSuccessHandler; import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler; @@ -20,13 +19,11 @@ /** * Created by tw on 19.02.16. */ +@Slf4j @Component public class LoginSuccessHandler extends SavedRequestAwareAuthenticationSuccessHandler implements AuthenticationSuccessHandler { - private static final Logger LOGGER = LoggerFactory.getLogger(LoginSuccessHandler.class); - private final UserAccountLoginSuccessService userAccountLoginSuccessService; - private final LocaleResolver localeResolver; @Autowired @@ -40,7 +37,9 @@ public LoginSuccessHandler(UserAccountLoginSuccessService userAccountLoginSucces public void onAuthenticationSuccess( HttpServletRequest request, HttpServletResponse response, - Authentication authentication) throws ServletException, IOException { + Authentication authentication + ) throws ServletException, IOException { + log.info("onAuthenticationSuccess"); super.onAuthenticationSuccess(request, response, authentication); UserAccount user = userAccountLoginSuccessService.retrieveCurrentUser(); userAccountLoginSuccessService.updateLastLoginTimestamp(user); @@ -50,7 +49,7 @@ public void onAuthenticationSuccess( default: locale = Locale.ENGLISH; break; } localeResolver.setLocale(request,response,locale); - LOGGER.info("successful logged in "+user.getUserEmail()); + log.info("successful logged in "+user.getUserEmail()); } } diff --git a/src/main/java/org/woehlke/simpleworklist/user/login/UserAccountLoginSuccessServiceImpl.java b/src/main/java/org/woehlke/simpleworklist/user/login/UserAccountLoginSuccessServiceImpl.java index ca5d0a37..a1cd9619 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/login/UserAccountLoginSuccessServiceImpl.java +++ b/src/main/java/org/woehlke/simpleworklist/user/login/UserAccountLoginSuccessServiceImpl.java @@ -1,5 +1,6 @@ package org.woehlke.simpleworklist.user.login; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; @@ -13,6 +14,7 @@ import java.util.Date; +@Slf4j @Service @Transactional(propagation = Propagation.REQUIRED, readOnly = true) public class UserAccountLoginSuccessServiceImpl implements UserAccountLoginSuccessService { @@ -24,9 +26,9 @@ public UserAccountLoginSuccessServiceImpl(UserAccountRepository userAccountRepos this.userAccountRepository = userAccountRepository; } - @Override public String retrieveUsername() { + log.info("retrieveUsername"); Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if(authentication == null) return " "; Object principal = authentication.getPrincipal(); @@ -37,18 +39,21 @@ public String retrieveUsername() { } } - @Override - @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) - public void updateLastLoginTimestamp(UserAccount user) { - user.setLastLoginTimestamp(new Date()); - userAccountRepository.saveAndFlush(user); - } - @Override public UserAccount retrieveCurrentUser() throws UsernameNotFoundException { + log.info("retrieveCurrentUser"); String username = this.retrieveUsername(); UserAccount account = userAccountRepository.findByUserEmail(username); if (account == null) throw new UsernameNotFoundException(username); return account; } + + @Override + @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) + public void updateLastLoginTimestamp(UserAccount user) { + log.info("updateLastLoginTimestamp"); + user.setLastLoginTimestamp(new Date()); + userAccountRepository.saveAndFlush(user); + } + } diff --git a/src/main/java/org/woehlke/simpleworklist/user/login/UserLoginController.java b/src/main/java/org/woehlke/simpleworklist/user/login/UserLoginController.java index 6ead386c..e730c492 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/login/UserLoginController.java +++ b/src/main/java/org/woehlke/simpleworklist/user/login/UserLoginController.java @@ -1,12 +1,11 @@ package org.woehlke.simpleworklist.user.login; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.validation.Valid; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.web.authentication.logout.SecurityContextLogoutHandler; @@ -20,14 +19,12 @@ import org.woehlke.simpleworklist.user.account.UserAccount; import org.woehlke.simpleworklist.user.account.UserAccountAccessService; - +@Slf4j @Controller +@RequestMapping(path = "/user") public class UserLoginController { - private static final Logger LOGGER = LoggerFactory.getLogger(UserLoginController.class); - private final UserAccountLoginSuccessService userAccountLoginSuccessService; - private final UserAccountAccessService userAccountAccessService; @Autowired @@ -43,8 +40,9 @@ public UserLoginController(UserAccountLoginSuccessService userAccountLoginSucces * @param model * @return Login Screen. */ - @RequestMapping(value = "/login", method = RequestMethod.GET) + @RequestMapping(path = "/login", method = RequestMethod.GET) public final String loginForm(Model model) { + log.info("loginForm"); LoginForm loginForm = new LoginForm(); model.addAttribute("loginForm", loginForm); return "user/login/loginForm"; @@ -58,14 +56,18 @@ public final String loginForm(Model model) { * @param model * @return Shows Root Project after successful login or login form with error messages. */ - @RequestMapping(value = "/login", method = RequestMethod.POST) - public final String loginPerform(@Valid LoginForm loginForm, - BindingResult result, Model model) { + @RequestMapping(path = "/login", method = RequestMethod.POST) + public final String loginPerform( + @Valid LoginForm loginForm, + BindingResult result, + Model model + ) { + log.info("loginPerform"); boolean authorized = userAccountAccessService.authorize(loginForm); if (!result.hasErrors() && authorized) { UserAccount user = userAccountLoginSuccessService.retrieveCurrentUser(); userAccountLoginSuccessService.updateLastLoginTimestamp(user); - LOGGER.info("logged in"); + log.info("logged in"); return "redirect:/"; } else { String objectName = "loginForm"; @@ -73,13 +75,18 @@ public final String loginPerform(@Valid LoginForm loginForm, String defaultMessage = "Email or Password wrong."; FieldError e = new FieldError(objectName, field, defaultMessage); result.addError(e); - LOGGER.info("not logged in"); + log.info("not logged in"); return "user/login/loginForm"; } } - @RequestMapping(value="/logout", method = RequestMethod.GET) - public String logoutPage (SessionStatus status, HttpServletRequest request, HttpServletResponse response) { + @RequestMapping(path="/logout", method = RequestMethod.GET) + public String logoutPage ( + SessionStatus status, + HttpServletRequest request, + HttpServletResponse response + ) { + log.info("logoutPages"); Authentication auth = SecurityContextHolder.getContext().getAuthentication(); if (auth != null){ new SecurityContextLogoutHandler().logout(request, response, auth); diff --git a/src/main/java/org/woehlke/simpleworklist/user/messages/NewUser2UserMessage.java b/src/main/java/org/woehlke/simpleworklist/user/messages/NewUser2UserMessage.java deleted file mode 100644 index 1d349b0d..00000000 --- a/src/main/java/org/woehlke/simpleworklist/user/messages/NewUser2UserMessage.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.woehlke.simpleworklist.user.messages; - - -import org.hibernate.validator.constraints.Length; -import org.hibernate.validator.constraints.SafeHtml; - -import javax.validation.constraints.NotBlank; -import java.io.Serializable; -import java.util.Objects; - -public class NewUser2UserMessage implements Serializable { - - private static final long serialVersionUID = 1576610181966480168L; - - @SafeHtml(whitelistType= SafeHtml.WhiteListType.SIMPLE_TEXT) - @NotBlank - @Length(min=1,max=65535) - private String messageText; - - public String getMessageText() { - return messageText; - } - - public void setMessageText(String messageText) { - this.messageText = messageText; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof NewUser2UserMessage)) return false; - NewUser2UserMessage that = (NewUser2UserMessage) o; - return getMessageText().equals(that.getMessageText()); - } - - @Override - public int hashCode() { - return Objects.hash(getMessageText()); - } - - @Override - public String toString() { - return "NewUser2UserMessage{" + - "messageText='" + messageText + '\'' + - '}'; - } -} diff --git a/src/main/java/org/woehlke/simpleworklist/user/messages/User2UserMessage.java b/src/main/java/org/woehlke/simpleworklist/user/messages/User2UserMessage.java index 30be78bb..e142452c 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/messages/User2UserMessage.java +++ b/src/main/java/org/woehlke/simpleworklist/user/messages/User2UserMessage.java @@ -1,5 +1,6 @@ package org.woehlke.simpleworklist.user.messages; +import lombok.*; import org.hibernate.validator.constraints.Length; import javax.validation.constraints.NotBlank; import org.hibernate.validator.constraints.SafeHtml; @@ -9,7 +10,6 @@ import javax.persistence.*; import javax.validation.constraints.NotNull; import java.io.Serializable; -import java.util.Objects; /** * Created by Fert on 16.02.2016. @@ -28,6 +28,12 @@ @Index(name = "ix_user_message_row_created_at", columnList = "row_created_at") } ) +@Getter +@Setter +@EqualsAndHashCode +@ToString +@NoArgsConstructor +@AllArgsConstructor public class User2UserMessage extends AuditModel implements Serializable { private static final long serialVersionUID = 4263078228257938175L; @@ -61,75 +67,4 @@ public class User2UserMessage extends AuditModel implements Serializable { @JoinColumn(name = "user_account_id_receiver", nullable = false) private UserAccount receiver; - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public String getMessageText() { - return messageText; - } - - public void setMessageText(String messageText) { - this.messageText = messageText; - } - - public Boolean isReadByReceiver() { - return readByReceiver; - } - - public void setReadByReceiver(Boolean readByReceiver) { - this.readByReceiver = readByReceiver; - } - - public UserAccount getSender() { - return sender; - } - - public void setSender(UserAccount sender) { - this.sender = sender; - } - - public UserAccount getReceiver() { - return receiver; - } - - public void setReceiver(UserAccount receiver) { - this.receiver = receiver; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof User2UserMessage)) return false; - if (!super.equals(o)) return false; - User2UserMessage that = (User2UserMessage) o; - return Objects.equals(getId(), that.getId()) && - getMessageText().equals(that.getMessageText()) && - isReadByReceiver().equals(that.isReadByReceiver()) && - getSender().equals(that.getSender()) && - getReceiver().equals(that.getReceiver()); - } - - @Override - public int hashCode() { - return Objects.hash(super.hashCode(), getId(), getMessageText(), isReadByReceiver(), getSender(), getReceiver()); - } - - @Override - public String toString() { - return "User2UserMessage{" + - "id=" + id + - ", messageText='" + messageText + '\'' + - ", readByReceiver=" + readByReceiver + - ", sender=" + sender + - ", receiver=" + receiver + - ", uuid='" + uuid + '\'' + - ", rowCreatedAt=" + rowCreatedAt + - ", rowUpdatedAt=" + rowUpdatedAt + - '}'; - } } diff --git a/src/main/java/org/woehlke/simpleworklist/user/messages/User2UserMessageController.java b/src/main/java/org/woehlke/simpleworklist/user/messages/User2UserMessageController.java index 7f86df24..e0170ff0 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/messages/User2UserMessageController.java +++ b/src/main/java/org/woehlke/simpleworklist/user/messages/User2UserMessageController.java @@ -1,7 +1,6 @@ package org.woehlke.simpleworklist.user.messages; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Sort; @@ -19,7 +18,6 @@ import org.woehlke.simpleworklist.user.UserSessionBean; import org.woehlke.simpleworklist.context.Context; import org.woehlke.simpleworklist.user.account.UserAccount; -import org.woehlke.simpleworklist.task.TaskController; import javax.validation.Valid; import java.util.Locale; @@ -28,25 +26,26 @@ * Created by * on 16.02.2016. */ +@Slf4j @Controller -@RequestMapping(value = "/user2user/") +@RequestMapping(path = "/user/messages/") public class User2UserMessageController extends AbstractController { - private static final Logger LOGGER = LoggerFactory.getLogger(TaskController.class); - - @RequestMapping(value = "/{userId}/messages/", method = RequestMethod.GET) + @RequestMapping(path = "/{userId}/", method = RequestMethod.GET) public final String getLastMessagesBetweenCurrentAndOtherUser( @PathVariable("userId") UserAccount otherUser, @PageableDefault(sort = "rowCreatedAt", direction = Sort.Direction.DESC) Pageable request, @ModelAttribute("userSession") UserSessionBean userSession, - Locale locale, Model model + Locale locale, + Model model ) { + log.info("getLastMessagesBetweenCurrentAndOtherUser"); Context context = super.getContext(userSession); UserAccount thisUser = context.getUserAccount(); model.addAttribute("userSession",userSession); - NewUser2UserMessage newUser2UserMessage = new NewUser2UserMessage(); + User2UserMessageFormBean user2UserMessageFormBean = new User2UserMessageFormBean(); Page user2UserMessagePage = user2UserMessageService.readAllMessagesBetweenCurrentAndOtherUser(thisUser,otherUser,request); - model.addAttribute("newUser2UserMessage", newUser2UserMessage); + model.addAttribute("newUser2UserMessage", user2UserMessageFormBean); model.addAttribute("otherUser", otherUser); model.addAttribute("user2UserMessagePage", user2UserMessagePage); model.addAttribute("refreshMessages",true); @@ -55,33 +54,34 @@ public final String getLastMessagesBetweenCurrentAndOtherUser( return "user/messages/all"; } - @RequestMapping(value = "/{userId}/messages/", method = RequestMethod.POST) + @RequestMapping(path = "/{userId}/", method = RequestMethod.POST) public final String sendNewMessageToOtherUser( @PathVariable("userId") UserAccount otherUser, - @Valid @ModelAttribute("newUser2UserMessage") NewUser2UserMessage newUser2UserMessage, + @Valid @ModelAttribute("newUser2UserMessage") User2UserMessageFormBean user2UserMessageFormBean, BindingResult result, @PageableDefault(sort = "rowCreatedAt", direction = Sort.Direction.DESC) Pageable request, @ModelAttribute("userSession") UserSessionBean userSession, - Locale locale, Model model + Locale locale, + Model model ) { - LOGGER.info("sendNewMessageToOtherUser"); + log.info("sendNewMessageToOtherUser"); Context context = super.getContext(userSession); UserAccount thisUser = context.getUserAccount(); model.addAttribute("userSession",userSession); Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForMessagesBetweenCurrentAndOtherUser(locale); model.addAttribute("breadcrumb",breadcrumb); if(result.hasErrors()){ - LOGGER.info("result.hasErrors"); + log.info("result.hasErrors"); for(ObjectError objectError:result.getAllErrors()){ - LOGGER.info("result.hasErrors: "+objectError.toString()); + log.info("result.hasErrors: "+objectError.toString()); } Page user2UserMessagePage = user2UserMessageService.readAllMessagesBetweenCurrentAndOtherUser(thisUser,otherUser,request); model.addAttribute("otherUser", otherUser); model.addAttribute("user2UserMessagePage", user2UserMessagePage); return "user/messages/all"; } else { - user2UserMessageService.sendNewUserMessage(thisUser, otherUser, newUser2UserMessage); - return "redirect:/user2user/"+otherUser.getId()+"/messages/"; + user2UserMessageService.sendNewUserMessage(thisUser, otherUser, user2UserMessageFormBean); + return "redirect:/user/messages/" + otherUser.getId(); } } diff --git a/src/main/java/org/woehlke/simpleworklist/user/messages/User2UserMessageFormBean.java b/src/main/java/org/woehlke/simpleworklist/user/messages/User2UserMessageFormBean.java new file mode 100644 index 00000000..bf734448 --- /dev/null +++ b/src/main/java/org/woehlke/simpleworklist/user/messages/User2UserMessageFormBean.java @@ -0,0 +1,26 @@ +package org.woehlke.simpleworklist.user.messages; + + +import lombok.*; +import org.hibernate.validator.constraints.Length; +import org.hibernate.validator.constraints.SafeHtml; + +import javax.validation.constraints.NotBlank; +import java.io.Serializable; + +@Getter +@Setter +@EqualsAndHashCode +@ToString +@AllArgsConstructor +@NoArgsConstructor +public class User2UserMessageFormBean implements Serializable { + + private static final long serialVersionUID = 1576610181966480168L; + + @SafeHtml(whitelistType= SafeHtml.WhiteListType.SIMPLE_TEXT) + @NotBlank + @Length(min=1,max=65535) + private String messageText; + +} diff --git a/src/main/java/org/woehlke/simpleworklist/user/messages/User2UserMessageService.java b/src/main/java/org/woehlke/simpleworklist/user/messages/User2UserMessageService.java index 71c19cdd..5b6117f4 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/messages/User2UserMessageService.java +++ b/src/main/java/org/woehlke/simpleworklist/user/messages/User2UserMessageService.java @@ -9,7 +9,7 @@ */ public interface User2UserMessageService { - void sendNewUserMessage(UserAccount thisUser, UserAccount otherUser, NewUser2UserMessage newUser2UserMessage); + void sendNewUserMessage(UserAccount thisUser, UserAccount otherUser, User2UserMessageFormBean user2UserMessageFormBean); int getNumberOfNewIncomingMessagesForUser(UserAccount user); diff --git a/src/main/java/org/woehlke/simpleworklist/user/messages/User2UserMessageServiceImpl.java b/src/main/java/org/woehlke/simpleworklist/user/messages/User2UserMessageServiceImpl.java index bd9fc1e7..bc132754 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/messages/User2UserMessageServiceImpl.java +++ b/src/main/java/org/woehlke/simpleworklist/user/messages/User2UserMessageServiceImpl.java @@ -1,5 +1,6 @@ package org.woehlke.simpleworklist.user.messages; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.domain.Page; @@ -15,12 +16,11 @@ /** * Created by tw on 16.02.2016. */ +@Slf4j @Service @Transactional(propagation = Propagation.REQUIRED, readOnly = true) public class User2UserMessageServiceImpl implements User2UserMessageService { - private static final Logger LOGGER = LoggerFactory.getLogger(User2UserMessageServiceImpl.class); - private final User2UserMessageRepository userMessageRepository; @Autowired @@ -30,18 +30,25 @@ public User2UserMessageServiceImpl(User2UserMessageRepository userMessageReposit @Override @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) - public void sendNewUserMessage(UserAccount thisUser, UserAccount otherUser, NewUser2UserMessage newUser2UserMessage) { - LOGGER.info("sendNewUserMessage"); + public void sendNewUserMessage( + UserAccount thisUser, + UserAccount otherUser, + User2UserMessageFormBean user2UserMessageFormBean + ) { + log.info("sendNewUserMessage"); User2UserMessage m = new User2UserMessage(); m.setSender(thisUser); m.setReceiver(otherUser); m.setReadByReceiver(false); - m.setMessageText(newUser2UserMessage.getMessageText()); + m.setMessageText(user2UserMessageFormBean.getMessageText()); userMessageRepository.saveAndFlush(m); } @Override - public int getNumberOfNewIncomingMessagesForUser(UserAccount receiver) { + public int getNumberOfNewIncomingMessagesForUser( + UserAccount receiver + ) { + log.info("getNumberOfNewIncomingMessagesForUser"); boolean readByReceiver = false; List user2UserMessageList = userMessageRepository.findByReceiverAndReadByReceiver(receiver, readByReceiver); @@ -50,10 +57,15 @@ public int getNumberOfNewIncomingMessagesForUser(UserAccount receiver) { @Override @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) - public Page readAllMessagesBetweenCurrentAndOtherUser(UserAccount receiver, UserAccount sender, Pageable request) { + public Page readAllMessagesBetweenCurrentAndOtherUser( + UserAccount receiver, + UserAccount sender, + Pageable request + ) { + log.info("readAllMessagesBetweenCurrentAndOtherUser"); Page user2UserMessagePage = userMessageRepository.findAllMessagesBetweenCurrentAndOtherUser(sender,receiver,request); for(User2UserMessage user2UserMessage : user2UserMessagePage){ - if((!user2UserMessage.isReadByReceiver()) && (receiver.getId().longValue()== user2UserMessage.getReceiver().getId().longValue())){ + if((!user2UserMessage.getReadByReceiver()) && (receiver.getId().longValue()== user2UserMessage.getReceiver().getId().longValue())){ user2UserMessage.setReadByReceiver(true); userMessageRepository.saveAndFlush(user2UserMessage); } diff --git a/src/main/java/org/woehlke/simpleworklist/user/register/UserRegistrationController.java b/src/main/java/org/woehlke/simpleworklist/user/register/UserRegistrationController.java index 9205b768..a8723d26 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/register/UserRegistrationController.java +++ b/src/main/java/org/woehlke/simpleworklist/user/register/UserRegistrationController.java @@ -1,7 +1,6 @@ package org.woehlke.simpleworklist.user.register; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -15,13 +14,12 @@ import javax.validation.Valid; +@Slf4j @Controller +@RequestMapping(path = "/user/register") public class UserRegistrationController { - private static final Logger LOGGER = LoggerFactory.getLogger(UserRegistrationController.class); - private final UserAccountService userAccountService; - private final UserRegistrationService userRegistrationService; @Autowired @@ -37,7 +35,7 @@ public UserRegistrationController(UserAccountService userAccountService, UserReg * @param model * @return Formular for entering Email-Address for Registration */ - @RequestMapping(value = "/register", method = RequestMethod.GET) + @RequestMapping(path = "/", method = RequestMethod.GET) public final String registerNewUserRequestForm(Model model) { UserRegistrationForm userRegistrationForm = new UserRegistrationForm(); model.addAttribute("userRegistrationForm", userRegistrationForm); @@ -52,10 +50,12 @@ public final String registerNewUserRequestForm(Model model) { * @param model * @return info page at success or return to form with error messages. */ - @RequestMapping(value = "/register", method = RequestMethod.POST) + @RequestMapping(path = "/", method = RequestMethod.POST) public final String registerNewUserRequestStoreAndSendEmailForVerification( @Valid UserRegistrationForm userRegistrationForm, - BindingResult result, Model model) { + BindingResult result, + Model model + ) { if (result.hasErrors()) { return "user/register/registerForm"; } else { @@ -90,10 +90,12 @@ public final String registerNewUserRequestStoreAndSendEmailForVerification( * @param model * @return Formular for Entering Account Task or Error Messages. */ - @RequestMapping(value = "/confirm/{confirmId}", method = RequestMethod.GET) + @RequestMapping(path = "/confirm/{confirmId}", method = RequestMethod.GET) public final String registerNewUserCheckResponseAndRegistrationForm( - @PathVariable String confirmId, Model model) { - LOGGER.info("GET /confirm/" + confirmId); + @PathVariable String confirmId, + Model model + ) { + log.info("GET /confirm/" + confirmId); UserRegistration o = userRegistrationService.findByToken(confirmId); if (o != null) { userRegistrationService.registrationClickedInEmail(o); @@ -115,19 +117,21 @@ public final String registerNewUserCheckResponseAndRegistrationForm( * @param model * @return login page at success or page with error messages. */ - @RequestMapping(value = "/confirm/{confirmId}", method = RequestMethod.POST) + @RequestMapping(path = "/confirm/{confirmId}", method = RequestMethod.POST) public final String registerNewUserCheckResponseAndRegistrationStore( - @PathVariable String confirmId, - @Valid UserAccountForm userAccountForm, - BindingResult result, Model model) { - LOGGER.info("POST /confirm/" + confirmId + " : " + userAccountForm.toString()); + @PathVariable String confirmId, + @Valid UserAccountForm userAccountForm, + BindingResult result, + Model model + ) { + log.info("POST /confirm/" + confirmId + " : " + userAccountForm.toString()); userRegistrationService.registrationCheckIfResponseIsInTime(userAccountForm.getUserEmail()); - UserRegistration o = userRegistrationService.findByToken(confirmId); - if (o != null) { + UserRegistration oUserRegistration = userRegistrationService.findByToken(confirmId); + if (oUserRegistration != null) { boolean passwordsMatch = userAccountForm.passwordsAreTheSame(); if (!result.hasErrors() && passwordsMatch) { userAccountService.createUser(userAccountForm); - userRegistrationService.registrationUserCreated(o); + userRegistrationService.registrationUserCreated(oUserRegistration); return "user/register/registerDone"; } else { if (!passwordsMatch) { diff --git a/src/main/java/org/woehlke/simpleworklist/user/register/UserRegistrationForm.java b/src/main/java/org/woehlke/simpleworklist/user/register/UserRegistrationForm.java index df0c8105..a40ea8f3 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/register/UserRegistrationForm.java +++ b/src/main/java/org/woehlke/simpleworklist/user/register/UserRegistrationForm.java @@ -1,11 +1,19 @@ package org.woehlke.simpleworklist.user.register; +import lombok.*; + import javax.validation.constraints.NotNull; import javax.validation.constraints.Email; import javax.validation.constraints.NotBlank; import java.io.Serializable; +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +@EqualsAndHashCode +@ToString public class UserRegistrationForm implements Serializable { private static final long serialVersionUID = 6864871862706880939L; @@ -16,43 +24,4 @@ public class UserRegistrationForm implements Serializable { @Email(message = "Email Address is not a valid format") private String email; - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((email == null) ? 0 : email.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; - UserRegistrationForm other = (UserRegistrationForm) obj; - if (email == null) { - if (other.email != null) - return false; - } else if (!email.equals(other.email)) - return false; - return true; - } - - @Override - public String toString() { - return "UserRegistrationForm [email=" + email + "]"; - } - - } diff --git a/src/main/java/org/woehlke/simpleworklist/user/register/UserRegistrationServiceImpl.java b/src/main/java/org/woehlke/simpleworklist/user/register/UserRegistrationServiceImpl.java index 5aeb7389..46da0ea9 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/register/UserRegistrationServiceImpl.java +++ b/src/main/java/org/woehlke/simpleworklist/user/register/UserRegistrationServiceImpl.java @@ -2,6 +2,7 @@ import java.util.Date; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.slf4j.Logger; @@ -16,19 +17,14 @@ import org.woehlke.simpleworklist.config.ApplicationProperties; import org.woehlke.simpleworklist.user.token.TokenGeneratorService; +@Slf4j @Service @Transactional(propagation = Propagation.REQUIRED, readOnly = true) -public class UserRegistrationServiceImpl implements - UserRegistrationService { - - private static final Logger LOGGER = LoggerFactory.getLogger(UserRegistrationServiceImpl.class); +public class UserRegistrationServiceImpl implements UserRegistrationService { private final ApplicationProperties applicationProperties; - private final UserRegistrationRepository userRegistrationRepository; - private final TokenGeneratorService tokenGeneratorService; - private final JavaMailSender mailSender; @Autowired @@ -71,9 +67,9 @@ public void registrationSendEmailTo(String email) { o.setEmail(email); String token = tokenGeneratorService.getToken(); o.setToken(token); - LOGGER.info("To be saved: " + o.toString()); + log.info("To be saved: " + o.toString()); o = userRegistrationRepository.saveAndFlush(o); - LOGGER.info("Saved: " + o.toString()); + log.info("Saved: " + o.toString()); this.sendEmailToRegisterNewUser(o); } @@ -86,7 +82,7 @@ public UserRegistration findByToken(String confirmId) { @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) public void registrationSentEmail(UserRegistration o) { o.setDoubleOptInStatus(UserRegistrationStatus.REGISTRATION_SENT_MAIL); - LOGGER.info("about to save: " + o.toString()); + log.info("about to save: " + o.toString()); userRegistrationRepository.saveAndFlush(o); } @@ -121,13 +117,13 @@ private void sendEmailToRegisterNewUser(UserRegistration o) { try { this.mailSender.send(msg); } catch (MailException ex) { - LOGGER.warn(ex.getMessage() + " for " + o.toString()); + log.warn(ex.getMessage() + " for " + o.toString()); success = false; } if (success) { this.registrationSentEmail(o); } - LOGGER.info("Sent MAIL: " + o.toString()); + log.info("Sent MAIL: " + o.toString()); } diff --git a/src/main/java/org/woehlke/simpleworklist/user/resetpassword/UserPasswordRecoveryController.java b/src/main/java/org/woehlke/simpleworklist/user/resetpassword/UserPasswordRecoveryController.java index ccb7b457..64858f7f 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/resetpassword/UserPasswordRecoveryController.java +++ b/src/main/java/org/woehlke/simpleworklist/user/resetpassword/UserPasswordRecoveryController.java @@ -1,5 +1,6 @@ package org.woehlke.simpleworklist.user.resetpassword; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Controller; @@ -17,13 +18,12 @@ import org.springframework.beans.factory.annotation.Autowired; import javax.validation.Valid; +@Slf4j @Controller +@RequestMapping(path = "/user/resetPassword") public class UserPasswordRecoveryController { - private static final Logger LOGGER = LoggerFactory.getLogger(UserPasswordRecoveryController.class); - private final UserAccountService userAccountService; - private final UserPasswordRecoveryService userPasswordRecoveryService; @Autowired @@ -39,7 +39,7 @@ public UserPasswordRecoveryController(UserAccountService userAccountService, Use * @param model * @return a Formular for entering the email-adress. */ - @RequestMapping(value = "/resetPassword", method = RequestMethod.GET) + @RequestMapping(method = RequestMethod.GET) public final String passwordForgottenForm(Model model) { UserRegistrationForm userRegistrationForm = new UserRegistrationForm(); model.addAttribute("userRegistrationForm", userRegistrationForm); @@ -54,20 +54,23 @@ public final String passwordForgottenForm(Model model) { * @param model * @return info page if without errors or formular again displaying error messages. */ - @RequestMapping(value = "/resetPassword", method = RequestMethod.POST) - public final String passwordForgottenPost(@Valid UserRegistrationForm userRegistrationForm, - BindingResult result, Model model) { + @RequestMapping(method = RequestMethod.POST) + public final String passwordForgottenPost( + @Valid UserRegistrationForm userRegistrationForm, + BindingResult result, + Model model + ) { if (result.hasErrors()) { - LOGGER.info("----------------------"); - LOGGER.info(userRegistrationForm.toString()); - LOGGER.info(result.toString()); - LOGGER.info(model.toString()); - LOGGER.info("----------------------"); + log.info("----------------------"); + log.info(userRegistrationForm.toString()); + log.info(result.toString()); + log.info(model.toString()); + log.info("----------------------"); return "user/resetPassword/resetPasswordForm"; } else { - LOGGER.info(userRegistrationForm.toString()); - LOGGER.info(result.toString()); - LOGGER.info(model.toString()); + log.info(userRegistrationForm.toString()); + log.info(result.toString()); + log.info(model.toString()); if (userAccountService.findByUserEmail(userRegistrationForm.getEmail()) == null) { String objectName = "userRegistrationForm"; String field = "email"; @@ -79,7 +82,6 @@ public final String passwordForgottenPost(@Valid UserRegistrationForm userRegist userPasswordRecoveryService.passwordRecoverySendEmailTo(userRegistrationForm.getEmail()); return "user/resetPassword/resetPasswordSentMail"; } - } } @@ -90,14 +92,17 @@ public final String passwordForgottenPost(@Valid UserRegistrationForm userRegist * @param model * @return a Formular for entering the new Password. */ - @RequestMapping(value = "/passwordResetConfirm/{confirmId}", method = RequestMethod.GET) - public final String enterNewPasswordFormular(@PathVariable String confirmId, Model model) { - UserPasswordRecovery o = userPasswordRecoveryService.findByToken(confirmId); - if (o != null) { - userPasswordRecoveryService.passwordRecoveryClickedInEmail(o); - UserAccount ua = userAccountService.findByUserEmail(o.getEmail()); + @RequestMapping(path = "/confirm/{confirmId}", method = RequestMethod.GET) + public final String enterNewPasswordFormular( + @PathVariable String confirmId, + Model model + ) { + UserPasswordRecovery oUserPasswordRecovery = userPasswordRecoveryService.findByToken(confirmId); + if (oUserPasswordRecovery != null) { + userPasswordRecoveryService.passwordRecoveryClickedInEmail(oUserPasswordRecovery); + UserAccount ua = userAccountService.findByUserEmail(oUserPasswordRecovery.getEmail()); UserAccountForm userAccountForm = new UserAccountForm(); - userAccountForm.setUserEmail(o.getEmail()); + userAccountForm.setUserEmail(oUserPasswordRecovery.getEmail()); userAccountForm.setUserFullname(ua.getUserFullname()); model.addAttribute("userAccountForm", userAccountForm); return "user/resetPassword/resetPasswordConfirmed"; @@ -115,11 +120,13 @@ public final String enterNewPasswordFormular(@PathVariable String confirmId, Mod * @param model * @return Info Page for success or back to formular with error messages. */ - @RequestMapping(value = "/passwordResetConfirm/{confirmId}", method = RequestMethod.POST) - public final String enterNewPasswordPost(@Valid UserAccountForm userAccountForm, - BindingResult result, - @PathVariable String confirmId, - Model model) { + @RequestMapping(path = "/confirm/{confirmId}", method = RequestMethod.POST) + public final String enterNewPasswordPost( + @Valid UserAccountForm userAccountForm, + BindingResult result, + @PathVariable String confirmId, + Model model + ) { UserPasswordRecovery o = userPasswordRecoveryService.findByToken(confirmId); boolean passwordsMatch = userAccountForm.passwordsAreTheSame(); if (o != null) { diff --git a/src/main/java/org/woehlke/simpleworklist/user/resetpassword/UserPasswordRecoveryServiceImpl.java b/src/main/java/org/woehlke/simpleworklist/user/resetpassword/UserPasswordRecoveryServiceImpl.java index ac49294a..4f9e475f 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/resetpassword/UserPasswordRecoveryServiceImpl.java +++ b/src/main/java/org/woehlke/simpleworklist/user/resetpassword/UserPasswordRecoveryServiceImpl.java @@ -1,5 +1,6 @@ package org.woehlke.simpleworklist.user.resetpassword; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -15,20 +16,16 @@ import java.util.Date; +@Slf4j @Service @Transactional(propagation = Propagation.REQUIRED, readOnly = true) public class UserPasswordRecoveryServiceImpl implements UserPasswordRecoveryService { private final UserPasswordRecoveryRepository userPasswordRecoveryRepository; - private final ApplicationProperties applicationProperties; - private final TokenGeneratorService tokenGeneratorService; - private final JavaMailSender mailSender; - private static final Logger LOGGER = LoggerFactory.getLogger(UserPasswordRecoveryServiceImpl.class); - @Autowired public UserPasswordRecoveryServiceImpl(UserPasswordRecoveryRepository userPasswordRecoveryRepository, ApplicationProperties applicationProperties, TokenGeneratorService tokenGeneratorService, JavaMailSender mailSender) { this.userPasswordRecoveryRepository = userPasswordRecoveryRepository; @@ -73,9 +70,9 @@ public void passwordRecoverySendEmailTo(String email) { o.setEmail(email); String token = tokenGeneratorService.getToken(); o.setToken(token); - LOGGER.info("To be saved: " + o.toString()); + log.info("To be saved: " + o.toString()); o = userPasswordRecoveryRepository.saveAndFlush(o); - LOGGER.info("Saved: " + o.toString()); + log.info("Saved: " + o.toString()); this.sendEmailForPasswordReset(o); } @@ -83,7 +80,7 @@ public void passwordRecoverySendEmailTo(String email) { @Transactional(propagation = Propagation.REQUIRES_NEW, readOnly = false) public void passwordRecoverySentEmail(UserPasswordRecovery o) { o.setDoubleOptInStatus(UserPasswordRecoveryStatus.PASSWORD_RECOVERY_SENT_EMAIL); - LOGGER.info("about to save: " + o.toString()); + log.info("about to save: " + o.toString()); userPasswordRecoveryRepository.saveAndFlush(o); } @@ -118,12 +115,12 @@ private void sendEmailForPasswordReset(UserPasswordRecovery o) { try { this.mailSender.send(msg); } catch (MailException ex) { - LOGGER.warn(ex.getMessage() + " for " + o.toString()); + log.warn(ex.getMessage() + " for " + o.toString()); success = false; } if (success) { this.passwordRecoverySentEmail(o); } - LOGGER.info("Sent MAIL: " + o.toString()); + log.info("Sent MAIL: " + o.toString()); } } diff --git a/src/main/java/org/woehlke/simpleworklist/user/selfservice/UserAccountSecurityPasswordServiceImpl.java b/src/main/java/org/woehlke/simpleworklist/user/selfservice/UserAccountSecurityPasswordServiceImpl.java index 86d88eee..89b516ea 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/selfservice/UserAccountSecurityPasswordServiceImpl.java +++ b/src/main/java/org/woehlke/simpleworklist/user/selfservice/UserAccountSecurityPasswordServiceImpl.java @@ -1,5 +1,6 @@ package org.woehlke.simpleworklist.user.selfservice; +import lombok.extern.slf4j.Slf4j; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -16,16 +17,13 @@ import org.woehlke.simpleworklist.user.UserDetailsBean; import org.woehlke.simpleworklist.user.account.UserAccountRepository; +@Slf4j @Service @Transactional(propagation = Propagation.REQUIRED, readOnly = true) public class UserAccountSecurityPasswordServiceImpl implements UserAccountSecurityPasswordService { - private static final Logger LOGGER = LoggerFactory.getLogger(UserAccountSecurityPasswordServiceImpl.class); - private final UserAccountRepository userAccountRepository; - private final PasswordEncoder encoder; - private final AuthenticationManager authenticationManager; @Autowired @@ -36,7 +34,6 @@ public UserAccountSecurityPasswordServiceImpl(UserAccountRepository userAccountR this.authenticationManager = authenticationManager; } - @Override public UserDetails updatePassword(UserDetails user, String newPassword) { UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(user.getUsername(), user.getPassword()); diff --git a/src/main/java/org/woehlke/simpleworklist/user/selfservice/UserChangeNameForm.java b/src/main/java/org/woehlke/simpleworklist/user/selfservice/UserChangeNameForm.java index f98e8875..39a9ce95 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/selfservice/UserChangeNameForm.java +++ b/src/main/java/org/woehlke/simpleworklist/user/selfservice/UserChangeNameForm.java @@ -1,6 +1,8 @@ package org.woehlke.simpleworklist.user.selfservice; import javax.validation.constraints.NotBlank; + +import lombok.*; import org.hibernate.validator.constraints.SafeHtml; import javax.validation.constraints.NotNull; @@ -9,6 +11,12 @@ /** * Created by tw on 14.03.16. */ +@Getter +@Setter +@EqualsAndHashCode +@AllArgsConstructor +@NoArgsConstructor +@ToString public class UserChangeNameForm implements Serializable { private static final long serialVersionUID = 5120488382888268418L; @@ -19,40 +27,4 @@ public class UserChangeNameForm implements Serializable { @NotBlank(message = "Fullname is compulsory") private String userFullname; - public UserChangeNameForm(){} - - public UserChangeNameForm(String userFullname){ - this.userFullname = userFullname; - } - - public String getUserFullname() { - return userFullname; - } - - public void setUserFullname(String userFullname) { - this.userFullname = userFullname; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - UserChangeNameForm that = (UserChangeNameForm) o; - - return userFullname != null ? userFullname.equals(that.userFullname) : that.userFullname == null; - - } - - @Override - public int hashCode() { - return userFullname != null ? userFullname.hashCode() : 0; - } - - @Override - public String toString() { - return "UserChangeNameForm{" + - "userFullname='" + userFullname + '\'' + - '}'; - } } diff --git a/src/main/java/org/woehlke/simpleworklist/user/selfservice/UserChangePasswordForm.java b/src/main/java/org/woehlke/simpleworklist/user/selfservice/UserChangePasswordForm.java index dc38400d..39ecdfd1 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/selfservice/UserChangePasswordForm.java +++ b/src/main/java/org/woehlke/simpleworklist/user/selfservice/UserChangePasswordForm.java @@ -1,6 +1,8 @@ package org.woehlke.simpleworklist.user.selfservice; import javax.validation.constraints.NotBlank; + +import lombok.*; import org.hibernate.validator.constraints.SafeHtml; import javax.persistence.Transient; @@ -10,6 +12,11 @@ /** * Created by tw on 15.03.16. */ +@Getter +@Setter +@EqualsAndHashCode +@AllArgsConstructor +@NoArgsConstructor public class UserChangePasswordForm implements Serializable { private static final long serialVersionUID = 9149342594823222054L; @@ -37,50 +44,4 @@ public boolean passwordsAreTheSame() { return this.userPassword.compareTo(userPasswordConfirmation) == 0; } - public String getOldUserPassword() { - return oldUserPassword; - } - - public void setOldUserPassword(String oldUserPassword) { - this.oldUserPassword = oldUserPassword; - } - - public String getUserPassword() { - return userPassword; - } - - public void setUserPassword(String userPassword) { - this.userPassword = userPassword; - } - - public String getUserPasswordConfirmation() { - return userPasswordConfirmation; - } - - public void setUserPasswordConfirmation(String userPasswordConfirmation) { - this.userPasswordConfirmation = userPasswordConfirmation; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - UserChangePasswordForm that = (UserChangePasswordForm) o; - - if (oldUserPassword != null ? !oldUserPassword.equals(that.oldUserPassword) : that.oldUserPassword != null) - return false; - if (userPassword != null ? !userPassword.equals(that.userPassword) : that.userPassword != null) return false; - return userPasswordConfirmation != null ? userPasswordConfirmation.equals(that.userPasswordConfirmation) : that.userPasswordConfirmation == null; - - } - - @Override - public int hashCode() { - int result = oldUserPassword != null ? oldUserPassword.hashCode() : 0; - result = 31 * result + (userPassword != null ? userPassword.hashCode() : 0); - result = 31 * result + (userPasswordConfirmation != null ? userPasswordConfirmation.hashCode() : 0); - return result; - } - } diff --git a/src/main/java/org/woehlke/simpleworklist/user/selfservice/UserSelfserviceController.java b/src/main/java/org/woehlke/simpleworklist/user/selfservice/UserSelfserviceController.java index efda6a25..fe4d893b 100644 --- a/src/main/java/org/woehlke/simpleworklist/user/selfservice/UserSelfserviceController.java +++ b/src/main/java/org/woehlke/simpleworklist/user/selfservice/UserSelfserviceController.java @@ -1,7 +1,6 @@ package org.woehlke.simpleworklist.user.selfservice; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -35,13 +34,11 @@ /** * Created by Fert on 14.03.2016. */ +@Slf4j @Controller -@RequestMapping(value = "/user/selfservice") +@RequestMapping(path = "/user/selfservice") public class UserSelfserviceController extends AbstractController { - private static final Logger LOGGER = LoggerFactory.getLogger(UserSelfserviceController.class); - - private final UserAccountAccessService userAccountAccessService; @Autowired @@ -49,16 +46,19 @@ public UserSelfserviceController(UserAccountAccessService userAccountAccessServi this.userAccountAccessService = userAccountAccessService; } - @RequestMapping(value = "/profile", method = RequestMethod.GET) + @RequestMapping(path = "/profile", method = RequestMethod.GET) public String userProfileAndMenu( - @PageableDefault(sort = "userFullname", direction = Sort.Direction.DESC) Pageable request, - @ModelAttribute("userSession") UserSessionBean userSession, Locale locale, Model model + @PageableDefault(sort = "userFullname", direction = Sort.Direction.DESC) Pageable request, + @ModelAttribute("userSession") UserSessionBean userSession, + Locale locale, + Model model ){ + log.info("userProfileAndMenu"); Context context = super.getContext(userSession); UserAccount user = context.getUserAccount(); Page users = userAccountService.findAll(request); for(UserAccount u:users){ - LOGGER.info(u.getUserFullname()+": "+u.getUserEmail()); + log.info(u.getUserFullname()+": "+u.getUserEmail()); } Map usersToNewMessages = userAccountService.getNewIncomingMessagesForEachOtherUser(user); Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForUserProfileAndMenu(locale); @@ -69,11 +69,13 @@ public String userProfileAndMenu( return "user/selfservice/profile"; } - @RequestMapping(value = "/name", method = RequestMethod.GET) + @RequestMapping(path = "/name", method = RequestMethod.GET) public String userNameForm( - @ModelAttribute("userSession") UserSessionBean userSession, - Locale locale, Model model + @ModelAttribute("userSession") UserSessionBean userSession, + Locale locale, + Model model ){ + log.info("userNameForm"); Context context = super.getContext(userSession); UserAccount user = context.getUserAccount(); UserChangeNameForm bean = new UserChangeNameForm(user.getUserFullname()); @@ -84,12 +86,15 @@ public String userNameForm( return "user/selfservice/name"; } - @RequestMapping(value = "/name", method = RequestMethod.POST) + @RequestMapping(path = "/name", method = RequestMethod.POST) public String userNameStore( - @Valid UserChangeNameForm username, - BindingResult result, - @ModelAttribute("userSession") UserSessionBean userSession, Locale locale, Model model + @Valid UserChangeNameForm username, + BindingResult result, + @ModelAttribute("userSession") UserSessionBean userSession, + Locale locale, + Model model ){ + log.info("userNameStore"); Context context = super.getContext(userSession); UserAccount user = context.getUserAccount(); if(result.hasErrors()) { @@ -105,10 +110,13 @@ public String userNameStore( } } - @RequestMapping(value = "/password", method = RequestMethod.GET) + @RequestMapping(path = "/password", method = RequestMethod.GET) public String userPasswordForm( - @ModelAttribute("userSession") UserSessionBean userSession, Locale locale, Model model + @ModelAttribute("userSession") UserSessionBean userSession, + Locale locale, + Model model ){ + log.info("userPasswordForm"); Context context = super.getContext(userSession); UserAccount user = context.getUserAccount(); UserChangePasswordForm userChangePasswordForm = new UserChangePasswordForm(); @@ -119,59 +127,67 @@ public String userPasswordForm( return "user/selfservice/password"; } - @RequestMapping(value = "/password", method = RequestMethod.POST) + @RequestMapping(path = "/password", method = RequestMethod.POST) public String userPasswordStore( - @Valid UserChangePasswordForm userChangePasswordForm, - BindingResult result, - @ModelAttribute("userSession") UserSessionBean userSession, Locale locale, Model model + @Valid UserChangePasswordForm userChangePasswordForm, + BindingResult result, + @ModelAttribute("userSession") UserSessionBean userSession, + Locale locale, + Model model ) { + log.info("userPasswordStore"); Context context = super.getContext(userSession); UserAccount user = context.getUserAccount(); - LOGGER.info("---------------------------------------------------------"); - LOGGER.info("userPasswordStore"); + log.info("---------------------------------------------------------"); + log.info("userPasswordStore"); Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForUserChangePassword(locale); model.addAttribute("breadcrumb", breadcrumb); model.addAttribute("thisUser", user); model.addAttribute("userChangePasswordForm", userChangePasswordForm); if(result.hasErrors()) { - LOGGER.info("result has Errors"); + log.info("result has Errors"); for(ObjectError error : result.getAllErrors()){ - LOGGER.info(error.toString()); + log.info(error.toString()); } return "user/selfservice/password"; } else { if(! userChangePasswordForm.passwordsAreTheSame()){ - LOGGER.info("passwords Are Not The Same"); + log.info("passwords Are Not The Same"); String objectName = "userChangePasswordForm"; String field = "userPassword"; String defaultMessage = "Passwords aren't the same."; FieldError e = new FieldError(objectName, field, defaultMessage); result.addError(e); for(ObjectError error : result.getAllErrors()){ - LOGGER.info(error.toString()); + log.info(error.toString()); } return "user/selfservice/password"; } if(!userAccountAccessService.confirmUserByLoginAndPassword(user.getUserEmail(), userChangePasswordForm.getOldUserPassword())){ - LOGGER.info("old Password is wrong"); + log.info("old Password is wrong"); String objectName = "userChangePasswordForm"; String field = "oldUserPassword"; String defaultMessage = "Password is incorrect"; FieldError e = new FieldError(objectName, field, defaultMessage); result.addError(e); for(ObjectError error : result.getAllErrors()){ - LOGGER.info(error.toString()); + log.info(error.toString()); } return "user/selfservice/password"; } - LOGGER.info("OK"); + log.info("OK"); userAccountAccessService.changeUsersPassword(userChangePasswordForm,user); return "redirect:/user/selfservice/profile"; } } - @RequestMapping(value = "/contexts", method = RequestMethod.GET) - public String userAreasForm(@ModelAttribute("userSession") UserSessionBean userSession, Locale locale, Model model){ + @RequestMapping(path = "/contexts", method = RequestMethod.GET) + public String userAreasForm( + @ModelAttribute("userSession") UserSessionBean userSession, + Locale locale, + Model model + ){ + log.info("userAreasForm"); Context context = super.getContext(userSession); UserAccount user = context.getUserAccount(); UserChangeDefaultContextForm bean = new UserChangeDefaultContextForm(); @@ -185,12 +201,15 @@ public String userAreasForm(@ModelAttribute("userSession") UserSessionBean userS return "user/selfservice/context/all"; } - @RequestMapping(value = "/contexts", method = RequestMethod.POST) + @RequestMapping(path = "/contexts", method = RequestMethod.POST) public String userAreasSave( @Valid @ModelAttribute("thisUser") UserChangeDefaultContextForm thisUser, BindingResult result, - @ModelAttribute("userSession") UserSessionBean userSession, Locale locale, Model model + @ModelAttribute("userSession") UserSessionBean userSession, + Locale locale, + Model model ){ + log.info("userAreasSave"); Context context = super.getContext(userSession); UserAccount user = context.getUserAccount(); List contexts = contextService.getAllForUser(user); @@ -198,9 +217,9 @@ public String userAreasSave( Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForUserContexts(locale); model.addAttribute("breadcrumb", breadcrumb); if(result.hasErrors()){ - LOGGER.info("userAreasSave: result has Errors"); + log.info("userAreasSave: result has Errors"); for(ObjectError error : result.getAllErrors()){ - LOGGER.info(error.toString()); + log.info(error.toString()); } return "user/selfservice/context/all"; } else { @@ -213,8 +232,13 @@ public String userAreasSave( } } - @RequestMapping(value = "/context/add", method = RequestMethod.GET) - public String userNewAreaForm(@ModelAttribute("userSession") UserSessionBean userSession, Locale locale, Model model){ + @RequestMapping(path = "/context/add", method = RequestMethod.GET) + public String userNewAreaForm( + @ModelAttribute("userSession") UserSessionBean userSession, + Locale locale, + Model model + ){ + log.info("userNewAreaForm"); Context context = super.getContext(userSession); UserAccount user = context.getUserAccount(); model.addAttribute("thisUser", user); @@ -225,21 +249,24 @@ public String userNewAreaForm(@ModelAttribute("userSession") UserSessionBean use return "user/selfservice/context/add"; } - @RequestMapping(value = "/context/add", method = RequestMethod.POST) + @RequestMapping(path = "/context/add", method = RequestMethod.POST) public String userNewAreaStore( - @Valid NewContextForm newContext, - BindingResult result, - @ModelAttribute("userSession") UserSessionBean userSession, Locale locale, Model model + @Valid NewContextForm newContext, + BindingResult result, + @ModelAttribute("userSession") UserSessionBean userSession, + Locale locale, + Model model ){ + log.info("userNewAreaStore"); Context context = super.getContext(userSession); UserAccount user = context.getUserAccount(); Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForUserContextAdd(locale); model.addAttribute("breadcrumb", breadcrumb); model.addAttribute("thisUser", user); if(result.hasErrors()){ - LOGGER.info("userNewAreaStore: result has Errors"); + log.info("userNewAreaStore: result has Errors"); for(ObjectError error : result.getAllErrors()){ - LOGGER.info(error.toString()); + log.info(error.toString()); } return "user/selfservice/context/add"; } else { @@ -248,11 +275,14 @@ public String userNewAreaStore( } } - @RequestMapping(value = "/context/edit/{contextId}", method = RequestMethod.GET) + @RequestMapping(path = "/context/{id}/edit", method = RequestMethod.GET) public String userEditAreaForm( - @PathVariable("contextId") Context context, - @ModelAttribute("userSession") UserSessionBean userSession, Locale locale, Model model + @PathVariable("id") Context context, + @ModelAttribute("userSession") UserSessionBean userSession, + Locale locale, + Model model ){ + log.info("userEditAreaForm"); Context contextFromSession = super.getContext(userSession); UserAccount user = contextFromSession.getUserAccount(); model.addAttribute("thisUser", user); @@ -265,19 +295,22 @@ public String userEditAreaForm( return "user/selfservice/context/edit"; } - @RequestMapping(value = "/context/edit/{contextId}", method = RequestMethod.POST) + @RequestMapping(path = "/context/{id}/edit", method = RequestMethod.POST) public String userEditAreaStore( @Valid NewContextForm editContext, - @PathVariable("contextId") Context context, + @PathVariable("id") Context context, BindingResult result, - @ModelAttribute("userSession") UserSessionBean userSession, Locale locale, Model model + @ModelAttribute("userSession") UserSessionBean userSession, + Locale locale, + Model model ){ + log.info("userEditAreaStore"); Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForUserContextEdit(locale, context); model.addAttribute("breadcrumb", breadcrumb); if(result.hasErrors()){ - LOGGER.info("userEditAreaStore: result has Errors"); + log.info("userEditAreaStore: result has Errors"); for(ObjectError error : result.getAllErrors()){ - LOGGER.info(error.toString()); + log.info(error.toString()); } return "user/selfservice/context/edit"; } else { @@ -290,29 +323,31 @@ public String userEditAreaStore( //TODO: is in session active? -> display message in frontend //TODO: has projects or tasks? -> display message in frontend - @RequestMapping(value = "/context/delete/{id}", method = RequestMethod.GET) + @RequestMapping(path = "/context/{id}/delete", method = RequestMethod.GET) public String userDeleteArea( - @PathVariable("id") Context context, - @ModelAttribute("userSession") UserSessionBean userSession, - Locale locale, Model model + @PathVariable("id") Context context, + @ModelAttribute("userSession") UserSessionBean userSession, + Locale locale, + Model model ){ + log.info("userDeleteArea"); UserAccount thisUser = context.getUserAccount(); model.addAttribute("userSession",userSession); model.addAttribute("thisUser", thisUser); Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForUserContextDelete(locale,context); model.addAttribute("breadcrumb", breadcrumb); if(userSession.getContextId() == context.getId()){ - LOGGER.info("context is active in session: "+ context); + log.info("context is active in session: "+ context); } else { if(thisUser.getDefaultContext().getId() == context.getId()){ - LOGGER.info("context is default context of this user: "+ context); + log.info("context is default context of this user: "+ context); } else { if(contextService.contextHasItems(context)){ - LOGGER.info("context has items: "+ context); + log.info("context has items: "+ context); } else { boolean deleted = contextService.delete(context); if(!deleted){ - LOGGER.info("context not deleted: "+ context); + log.info("context not deleted: "+ context); } } } @@ -320,11 +355,13 @@ public String userDeleteArea( return "redirect:/user/selfservice/contexts"; } - @RequestMapping(value = "/language", method = RequestMethod.GET) + @RequestMapping(path = "/language", method = RequestMethod.GET) public String userLanguageForm( - @ModelAttribute("userSession") UserSessionBean userSession, - Locale locale, Model model + @ModelAttribute("userSession") UserSessionBean userSession, + Locale locale, + Model model ){ + log.info("userLanguageForm"); UserAccount user = userAccountLoginSuccessService.retrieveCurrentUser(); model.addAttribute("thisUser", user); model.addAttribute("languages", Language.list()); @@ -334,20 +371,22 @@ public String userLanguageForm( return "user/selfservice/language"; } - @RequestMapping(value = "/language", method = RequestMethod.POST) + @RequestMapping(path = "/language", method = RequestMethod.POST) public String userLanguageStore( - @Valid UserChangeLanguageForm userChangeLanguageForm, - BindingResult result, - @ModelAttribute("userSession") UserSessionBean userSession, - Locale locale, Model model + @Valid UserChangeLanguageForm userChangeLanguageForm, + BindingResult result, + @ModelAttribute("userSession") UserSessionBean userSession, + Locale locale, + Model model ){ + log.info("userLanguageStore"); UserAccount user = userAccountLoginSuccessService.retrieveCurrentUser(); Breadcrumb breadcrumb = breadcrumbService.getBreadcrumbForUserChangeLanguage(locale); model.addAttribute("breadcrumb", breadcrumb); if(result.hasErrors()){ - LOGGER.info("userLanguageStore: result has Errors"); + log.info("userLanguageStore: result has Errors"); for(ObjectError error : result.getAllErrors()){ - LOGGER.info(error.toString()); + log.info(error.toString()); } return "user/selfservice/language"; } else { diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index c5c1ad5a..f3d1b472 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -58,27 +58,26 @@ org: - "/webjars" webSecurity: loginProcessingUrl: "/j_spring_security_check" - logoutUrl: "/logout" + logoutUrl: "/user/logout" cookieNamesToClear: - "JSESSIONID" invalidateHttpSession: true defaultSuccessUrl: "/" - failureForwardUrl: "/login?login_error=1" + failureForwardUrl: "/user/login?login_error=1" usernameParameter: "j_username" passwordParameter: "j_password" - loginPage: "/login" + loginPage: "/user/login" antPatternsPublic: - "/webjars/**" - "/css/**" - "/img/**" - "/js/**" - "/favicon.ico" - - "/test*/**" - - "/login*" - - "/register*" - - "/confirm*/**" - - "/resetPassword*" - - "/passwordResetConfirm*/**" + - "/user/login*" + - "/user/register*" + - "/user/register/confirm/**" + - "/user/resetPassword*" + - "/user/resetPassword/confirm/**" - "/error*" strengthBCryptPasswordEncoder: 10 --- diff --git a/src/main/resources/templates/layout/tasks.html b/src/main/resources/templates/layout/tasks.html index cfa39fe7..6305beaf 100644 --- a/src/main/resources/templates/layout/tasks.html +++ b/src/main/resources/templates/layout/tasks.html @@ -1,293 +1,293 @@ - - - -
- -
- - -
-
-
-
-
-
- -
-
- - - - - - - - - - - - - - - - - - - - - - - -
  - Title - - Due Date - - Task State - - Project -   - Context -
- - - - - - - - - - - - - - -
-
- - - - - - - - Inbox - - - - - - - - - - - - - task.context.nameDe - task.context.nameEn -
-
-
- -
- - - -
- -
-
-
- -
-
- info - -
-
-
- - \ No newline at end of file + + + +
+ +
+ + +
+
+
+
+
+
+ +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
  + Title + + Due Date + + Task State + + Project +   + Context +
+ + + + + + + + + + + + + + +
+
+ + + + + + + + Inbox + + + + + + + + + + + + + task.context.nameDe + task.context.nameEn +
+
+
+ +
+ + + +
+ +
+
+
+ +
+
+ info + +
+
+
+ + diff --git a/src/main/resources/templates/project/add.html b/src/main/resources/templates/project/id/add/project.html similarity index 95% rename from src/main/resources/templates/project/add.html rename to src/main/resources/templates/project/id/add/project.html index 4e279ecb..ccf6ebf2 100644 --- a/src/main/resources/templates/project/add.html +++ b/src/main/resources/templates/project/id/add/project.html @@ -19,7 +19,7 @@

-
+
diff --git a/src/main/resources/templates/project/edit.html b/src/main/resources/templates/project/id/edit.html similarity index 100% rename from src/main/resources/templates/project/edit.html rename to src/main/resources/templates/project/id/edit.html diff --git a/src/main/resources/templates/project/show.html b/src/main/resources/templates/project/id/show.html similarity index 92% rename from src/main/resources/templates/project/show.html rename to src/main/resources/templates/project/id/show.html index 8b92052e..cbf87493 100644 --- a/src/main/resources/templates/project/show.html +++ b/src/main/resources/templates/project/id/show.html @@ -1,63 +1,63 @@ - - - - Title - - - - - -
- -
-
-
- -
-
-
-
-

There is nothing to do in this project.

-
-
- - - \ No newline at end of file + + + + Title + + + + + +
+ +
+
+
+ +
+
+
+
+

There is nothing to do in this project.

+
+
+ + + diff --git a/src/main/resources/templates/project/addToplevel.html b/src/main/resources/templates/project/root/add/project.html similarity index 96% rename from src/main/resources/templates/project/addToplevel.html rename to src/main/resources/templates/project/root/add/project.html index 1fff177b..786f6c03 100644 --- a/src/main/resources/templates/project/addToplevel.html +++ b/src/main/resources/templates/project/root/add/project.html @@ -19,7 +19,7 @@

- +
diff --git a/src/main/resources/templates/task/addToInbox.html b/src/main/resources/templates/project/root/add/task.html similarity index 97% rename from src/main/resources/templates/task/addToInbox.html rename to src/main/resources/templates/project/root/add/task.html index a3b9361c..df26abaa 100644 --- a/src/main/resources/templates/task/addToInbox.html +++ b/src/main/resources/templates/project/root/add/task.html @@ -18,7 +18,7 @@

- + diff --git a/src/main/resources/templates/project/root.html b/src/main/resources/templates/project/root/show.html similarity index 93% rename from src/main/resources/templates/project/root.html rename to src/main/resources/templates/project/root/show.html index 6517771e..09114ca8 100644 --- a/src/main/resources/templates/project/root.html +++ b/src/main/resources/templates/project/root/show.html @@ -1,46 +1,46 @@ - - - - Title - - - -
- -
- -
- -
-
-
- -
-
-
-
-

There is nothing to do in this project.

-
-
- - - \ No newline at end of file + + + + Title + + + +
+ +
+ +
+ +
+
+
+ +
+
+
+
+

There is nothing to do in this project.

+
+
+ + + diff --git a/src/main/resources/templates/taskstate/inbox.html b/src/main/resources/templates/taskstate/inbox.html index 45aab642..3dc2fb22 100644 --- a/src/main/resources/templates/taskstate/inbox.html +++ b/src/main/resources/templates/taskstate/inbox.html @@ -16,7 +16,7 @@

Inbox

- + Add Task diff --git a/src/main/resources/templates/task/addToProject.html b/src/main/resources/templates/taskstate/task/add.html similarity index 96% rename from src/main/resources/templates/task/addToProject.html rename to src/main/resources/templates/taskstate/task/add.html index 888cb5c3..df26abaa 100644 --- a/src/main/resources/templates/task/addToProject.html +++ b/src/main/resources/templates/taskstate/task/add.html @@ -18,7 +18,7 @@

- + diff --git a/src/main/resources/templates/task/edit.html b/src/main/resources/templates/taskstate/task/edit.html similarity index 100% rename from src/main/resources/templates/task/edit.html rename to src/main/resources/templates/taskstate/task/edit.html diff --git a/src/main/resources/templates/user/messages/all.html b/src/main/resources/templates/user/messages/all.html index 305b06cb..00ec20b8 100644 --- a/src/main/resources/templates/user/messages/all.html +++ b/src/main/resources/templates/user/messages/all.html @@ -1,74 +1,74 @@ - - - - Title - - - -
-

- Your Dialog with - otherUser.userFullname -

-
- -
- - -
-
-
- -
-
-
-
-
-
- -
- -