From feba3617f4eaefe38e54c2432afa59d5c8ae3efc Mon Sep 17 00:00:00 2001 From: stebjan Date: Wed, 27 Jan 2016 15:53:39 +0100 Subject: [PATCH] #146 - removing unused old controllers --- .../eegdatabase/data/dao/ExperimentDao.java | 2 +- .../kiv/eegdatabase/data/dao/HistoryDao.java | 4 +- .../kiv/eegdatabase/data/dao/PersonDao.java | 2 +- .../kiv/eegdatabase/data/dao/ScenarioDao.java | 2 +- .../data/dao/SimpleExperimentDao.java | 2 +- .../data/dao/SimpleHistoryDao.java | 4 +- .../eegdatabase/data/dao/SimplePersonDao.java | 2 +- .../data/dao/SimpleScenarioDao.java | 6 +- .../admin/ChangeUserRoleCommand.java | 48 -- .../admin/ChangeUserRoleController.java | 62 -- .../admin/ChangeUserRoleValidator.java | 66 -- .../article/AddArticleCommentController.java | 366 ----------- .../article/AddArticleController.java | 371 ----------- .../article/AddArticleValidator.java | 53 -- .../controller/article/ArticleCommand.java | 99 --- .../article/ArticleCommentCommand.java | 88 --- .../article/ArticleMultiController.java | 597 ----------------- .../logic/controller/article/Feed.java | 95 --- .../logic/controller/article/FeedMessage.java | 81 --- .../controller/article/RSSFeedWriter.java | 149 ----- .../experiment/AddDataFileCommand.java | 59 -- .../experiment/AddDataFileController.java | 209 ------ .../experiment/AddExperimentCommand.java | 165 ----- .../experiment/AddExperimentController.java | 407 ------------ .../AddExperimentOptParamValCommand.java | 66 -- .../AddExperimentOptParamValController.java | 174 ----- .../AddExperimentOptParamValValidator.java | 90 --- .../experiment/AddExperimentValidator.java | 133 ---- .../AddExperimentWizardCommand.java | 208 ------ .../AddExperimentWizardController.java | 603 ------------------ .../experiment/AddFileMetadataCommand.java | 66 -- .../experiment/AddFileMetadataValidator.java | 69 -- .../experiment/ChooseMetadataController.java | 95 --- .../experiment/DataFileDetailController.java | 179 ------ .../DownloadMetadataZipController.java | 217 ------- .../experiment/ExperimentMultiController.java | 288 --------- .../MeasurationDataOutputController.java | 102 --- .../experiment/WizardAjaxController.java | 102 --- .../experiment/WizardAjaxMultiController.java | 280 -------- .../experiment/WizardController.java | 109 ---- .../group/AcceptRoleRequestController.java | 129 ---- .../AddBookingRoomViewParamsController.java | 221 ------- .../group/AddMemberToGroupCommand.java | 57 -- .../group/AddMemberToGroupController.java | 138 ---- .../controller/group/BookRoomCommand.java | 113 ---- .../group/BookingRoomAjaxController.java | 181 ------ .../group/BookingRoomController.java | 233 ------- .../controller/group/CreateGroupCommand.java | 57 -- .../group/CreateGroupController.java | 206 ------ .../group/CreateGroupValidator.java | 55 -- .../group/EditGroupRoleCommand.java | 77 --- .../group/EditGroupRoleController.java | 157 ----- .../group/GroupMultiController.java | 220 ------- .../group/MembershipRequestController.java | 151 ----- .../history/AbstractHistoryController.java | 193 ------ .../history/DailyHistoryController.java | 68 -- .../controller/history/GraphController.java | 133 ---- .../history/HistorySearcherCommand.java | 65 -- .../history/MonthlyHistoryController.java | 80 --- .../history/SearchHistoryController.java | 135 ---- .../history/WeeklyHistoryController.java | 69 -- .../controller/list/SelectGroupCommand.java | 57 -- .../list/artifact/AddArtifactCommand.java | 78 --- .../list/artifact/AddArtifactController.java | 153 ----- .../list/artifact/AddArtifactValidator.java | 59 -- .../artifact/ArtifactMultiController.java | 158 ----- .../AddExperimentOptParamDefCommand.java | 75 --- .../AddExperimentOptParamDefController.java | 196 ------ .../AddExperimentOptParamDefValidator.java | 46 -- .../ExperimentOptParamDefMultiController.java | 293 --------- .../AddFileMetadataParamDefCommand.java | 75 --- .../AddFileMetadataParamDefController.java | 196 ------ .../AddFileMetadataParamDefValidator.java | 46 -- .../FileMetadataParamDefMultiController.java | 208 ------ .../list/hardware/AddHardwareCommand.java | 84 --- .../list/hardware/AddHardwareController.java | 203 ------ .../list/hardware/AddHardwareValidator.java | 64 -- .../hardware/HardwareMultiController.java | 211 ------ .../AddPersonOptParamDefCommand.java | 75 --- .../AddPersonOptParamDefController.java | 196 ------ .../AddPersonOptParamDefValidator.java | 46 -- .../PersonOptParamDefMultiController.java | 208 ------ .../list/weather/AddWeatherCommand.java | 75 --- .../list/weather/AddWeatherController.java | 198 ------ .../list/weather/AddWeatherValidator.java | 77 --- .../list/weather/WeatherMultiController.java | 203 ------ .../ApplyForWritingPermissionCommand.java | 39 -- .../ApplyForWritingPermissionController.java | 163 ----- .../ApplyForWritingPermissionValidator.java | 45 -- .../myaccount/ChangeDefaultGroupCommand.java | 44 -- .../ChangeDefaultGroupController.java | 99 --- .../myaccount/ChangePasswordCommand.java | 57 -- .../myaccount/ChangePasswordController.java | 84 --- .../myaccount/ChangePasswordValidator.java | 86 --- .../AddPersonAdditionalParamValueCommand.java | 57 -- ...dPersonAdditionalParamValueController.java | 169 ----- ...ddPersonAdditionalParamValueValidator.java | 68 -- .../person/AddPersonController.java | 142 ----- .../controller/person/AddPersonValidator.java | 107 ---- .../person/EditPersonController.java | 169 ----- .../person/PersonDetailController.java | 67 -- .../person/PersonListController.java | 78 --- .../controller/root/ConfirmController.java | 82 --- .../root/ForgottenPasswordCommand.java | 39 -- .../root/ForgottenPasswordController.java | 129 ---- .../root/ForgottenPasswordValidator.java | 58 -- .../root/RegistrationController.java | 174 ----- .../root/RegistrationValidator.java | 98 --- .../root/WriteRequestsListController.java | 181 ------ .../scenario/AddScenarioCommand.java | 148 ----- .../scenario/AddScenarioController.java | 274 -------- .../scenario/AddScenarioSchemaCommand.java | 64 -- .../scenario/AddScenarioSchemaController.java | 185 ------ .../scenario/AddScenarioSchemaValidator.java | 67 -- .../scenario/AddScenarioValidator.java | 115 ---- .../scenario/ScenarioMultiController.java | 114 ---- .../ScenarioXMLDownloadController.java | 145 ----- .../search/AbstractSearchController.java | 84 --- .../search/ExperimentsSearcherCommand.java | 181 ------ .../search/ExperimentsSearcherController.java | 121 ---- .../search/FullTextSearchCommand.java | 60 -- .../search/FullTextSearchController.java | 226 ------- .../controller/search/FulltextResult.java | 113 ---- .../search/PeopleSearcherCommand.java | 142 ----- .../search/PeopleSearcherController.java | 102 --- .../search/ScenarioSearcherCommand.java | 97 --- .../search/ScenarioSearcherController.java | 108 ---- .../service/AbstractProcessingController.java | 108 ---- .../controller/service/ChooseCommand.java | 53 -- .../service/FastFourierCommand.java | 43 -- .../service/FastFourierController.java | 137 ---- .../service/MatchingPursuitCommand.java | 52 -- .../service/MatchingPursuitController.java | 148 ----- .../service/ServiceChooserController.java | 110 ---- .../controller/service/ServicesList.java | 47 -- .../controller/service/WaveletCommand.java | 45 -- .../service/WaveletProcessingController.java | 216 ------- .../controller/system/ExceptionResolver.java | 50 -- .../system/GrantPermissionController.java | 71 --- .../logic/delegate/HomePageDelegate.java | 150 ----- .../logic/delegate/MyAccountDelegate.java | 96 --- .../search/SearchRequest.java | 2 +- .../view/DownloadMetadataZipView.java | 76 --- .../eegdatabase/view/MeasurationDataView.java | 65 -- .../view/ScenarioXMLDownloadView.java | 59 -- .../view/controller/LoggedUserController.java | 50 -- .../core/experiments/ExperimentsFacade.java | 13 +- .../experiments/ExperimentsFacadeImpl.java | 2 +- .../core/experiments/ExperimentsService.java | 2 +- .../experiments/ExperimentsServiceImpl.java | 2 +- .../wui/core/history/HistoryFacade.java | 6 +- .../wui/core/history/HistoryFacadeImpl.java | 2 +- .../wui/core/history/HistoryService.java | 2 +- .../wui/core/history/HistoryServiceImpl.java | 2 +- .../wui/core/person/PersonFacade.java | 2 +- .../wui/core/person/PersonFacadeImpl.java | 2 +- .../wui/core/person/PersonService.java | 2 +- .../wui/core/person/PersonServiceImpl.java | 2 +- .../wui/core/scenarios/ScenariosFacade.java | 2 +- .../core/scenarios/ScenariosFacadeImpl.java | 2 +- .../wui/core/scenarios/ScenariosService.java | 2 +- .../core/scenarios/ScenariosServiceImpl.java | 2 +- .../webapp/WEB-INF/dispatcher-servlet.xml | 14 +- 163 files changed, 39 insertions(+), 17919 deletions(-) delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/admin/ChangeUserRoleCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/admin/ChangeUserRoleController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/admin/ChangeUserRoleValidator.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/AddArticleCommentController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/AddArticleController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/AddArticleValidator.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/ArticleCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/ArticleCommentCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/ArticleMultiController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/Feed.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/FeedMessage.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/RSSFeedWriter.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddDataFileCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddDataFileController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentOptParamValCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentOptParamValController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentOptParamValValidator.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentValidator.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentWizardCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentWizardController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddFileMetadataCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddFileMetadataValidator.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/ChooseMetadataController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/DataFileDetailController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/DownloadMetadataZipController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/ExperimentMultiController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/MeasurationDataOutputController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/WizardAjaxController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/WizardAjaxMultiController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/WizardController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/AcceptRoleRequestController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/AddBookingRoomViewParamsController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/AddMemberToGroupCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/AddMemberToGroupController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/BookRoomCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/BookingRoomAjaxController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/BookingRoomController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/CreateGroupCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/CreateGroupController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/CreateGroupValidator.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/EditGroupRoleCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/EditGroupRoleController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/GroupMultiController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/MembershipRequestController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/AbstractHistoryController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/DailyHistoryController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/GraphController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/HistorySearcherCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/MonthlyHistoryController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/SearchHistoryController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/WeeklyHistoryController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/SelectGroupCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/artifact/AddArtifactCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/artifact/AddArtifactController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/artifact/AddArtifactValidator.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/artifact/ArtifactMultiController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/experimentoptparamdef/AddExperimentOptParamDefCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/experimentoptparamdef/AddExperimentOptParamDefController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/experimentoptparamdef/AddExperimentOptParamDefValidator.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/experimentoptparamdef/ExperimentOptParamDefMultiController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/filemetadata/AddFileMetadataParamDefCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/filemetadata/AddFileMetadataParamDefController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/filemetadata/AddFileMetadataParamDefValidator.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/filemetadata/FileMetadataParamDefMultiController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/hardware/AddHardwareCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/hardware/AddHardwareController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/hardware/AddHardwareValidator.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/hardware/HardwareMultiController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/personoptparamdef/AddPersonOptParamDefCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/personoptparamdef/AddPersonOptParamDefController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/personoptparamdef/AddPersonOptParamDefValidator.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/personoptparamdef/PersonOptParamDefMultiController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/weather/AddWeatherCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/weather/AddWeatherController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/weather/AddWeatherValidator.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/weather/WeatherMultiController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ApplyForWritingPermissionCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ApplyForWritingPermissionController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ApplyForWritingPermissionValidator.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ChangeDefaultGroupCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ChangeDefaultGroupController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ChangePasswordCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ChangePasswordController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ChangePasswordValidator.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/AddPersonAdditionalParamValueCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/AddPersonAdditionalParamValueController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/AddPersonAdditionalParamValueValidator.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/AddPersonController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/AddPersonValidator.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/EditPersonController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/PersonDetailController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/PersonListController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/ConfirmController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/ForgottenPasswordCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/ForgottenPasswordController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/ForgottenPasswordValidator.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/RegistrationController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/RegistrationValidator.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/WriteRequestsListController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioSchemaCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioSchemaController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioSchemaValidator.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioValidator.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/ScenarioMultiController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/ScenarioXMLDownloadController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/AbstractSearchController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/ExperimentsSearcherCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/ExperimentsSearcherController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/FullTextSearchCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/FullTextSearchController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/FulltextResult.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/PeopleSearcherCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/PeopleSearcherController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/ScenarioSearcherCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/ScenarioSearcherController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/AbstractProcessingController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/ChooseCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/FastFourierCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/FastFourierController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/MatchingPursuitCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/MatchingPursuitController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/ServiceChooserController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/ServicesList.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/WaveletCommand.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/WaveletProcessingController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/system/ExceptionResolver.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/system/GrantPermissionController.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/delegate/HomePageDelegate.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/logic/delegate/MyAccountDelegate.java rename src/main/java/cz/zcu/kiv/eegdatabase/logic/{controller => }/search/SearchRequest.java (97%) delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/view/DownloadMetadataZipView.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/view/MeasurationDataView.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/view/ScenarioXMLDownloadView.java delete mode 100644 src/main/java/cz/zcu/kiv/eegdatabase/view/controller/LoggedUserController.java diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/ExperimentDao.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/ExperimentDao.java index 23b994e2..ae9721ab 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/ExperimentDao.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/ExperimentDao.java @@ -31,7 +31,7 @@ import cz.zcu.kiv.eegdatabase.data.pojo.DataFile; import cz.zcu.kiv.eegdatabase.data.pojo.Experiment; import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; import java.util.List; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/HistoryDao.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/HistoryDao.java index a184bd3c..461c0402 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/HistoryDao.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/HistoryDao.java @@ -29,8 +29,8 @@ import cz.zcu.kiv.eegdatabase.data.pojo.History; import cz.zcu.kiv.eegdatabase.logic.controller.history.ChoiceHistory; import cz.zcu.kiv.eegdatabase.logic.controller.history.DownloadStatistic; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; -import java.io.Serializable; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; + import java.util.List; /** diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/PersonDao.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/PersonDao.java index badbead9..ac68345b 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/PersonDao.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/PersonDao.java @@ -23,7 +23,7 @@ package cz.zcu.kiv.eegdatabase.data.dao; import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; import java.util.List; import java.util.Map; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/ScenarioDao.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/ScenarioDao.java index d5932bca..1d4bb1e8 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/ScenarioDao.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/ScenarioDao.java @@ -32,7 +32,7 @@ import cz.zcu.kiv.eegdatabase.data.pojo.Person; import cz.zcu.kiv.eegdatabase.data.pojo.Scenario; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; /** * DAO for fetching and saving objects with people. diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleExperimentDao.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleExperimentDao.java index ad253462..0c22ac3e 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleExperimentDao.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleExperimentDao.java @@ -62,7 +62,7 @@ import cz.zcu.kiv.eegdatabase.data.pojo.DataFile; import cz.zcu.kiv.eegdatabase.data.pojo.Experiment; import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; /** diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleHistoryDao.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleHistoryDao.java index 106f79c2..128647cf 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleHistoryDao.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleHistoryDao.java @@ -29,8 +29,8 @@ import cz.zcu.kiv.eegdatabase.data.pojo.History; import cz.zcu.kiv.eegdatabase.logic.controller.history.ChoiceHistory; import cz.zcu.kiv.eegdatabase.logic.controller.history.DownloadStatistic; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; -import java.io.Serializable; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; + import java.util.ArrayList; import java.util.Collections; import java.util.List; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimplePersonDao.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimplePersonDao.java index 9a987eba..f6b9b89f 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimplePersonDao.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimplePersonDao.java @@ -23,7 +23,7 @@ package cz.zcu.kiv.eegdatabase.data.dao; import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; import org.springframework.dao.support.DataAccessUtils; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleScenarioDao.java b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleScenarioDao.java index 6be6cc69..f232cd93 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleScenarioDao.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/data/dao/SimpleScenarioDao.java @@ -29,18 +29,14 @@ import cz.zcu.kiv.eegdatabase.data.pojo.Person; import cz.zcu.kiv.eegdatabase.data.pojo.Scenario; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; -import java.io.InputStream; import java.sql.Blob; -import java.sql.SQLException; import org.springframework.transaction.annotation.Transactional; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; /** * This class extends powers class SimpleGenericDao. Class is determined only diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/admin/ChangeUserRoleCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/admin/ChangeUserRoleCommand.java deleted file mode 100644 index d579a25e..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/admin/ChangeUserRoleCommand.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ChangeUserRoleCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.admin; - -/** - * @author Jindra - */ -public class ChangeUserRoleCommand { - - private String userName; - private String userRole; - - public String getUserName() { - return userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - public String getUserRole() { - return userRole; - } - - public void setUserRole(String userRole) { - this.userRole = userRole; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/admin/ChangeUserRoleController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/admin/ChangeUserRoleController.java deleted file mode 100644 index d60ed50c..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/admin/ChangeUserRoleController.java +++ /dev/null @@ -1,62 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ChangeUserRoleController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.admin; - -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; - -/** - * Controller for changing the global role of user. - * - * @author Jindra - */ -public class ChangeUserRoleController extends SimpleFormController { - - private PersonDao personDao; - - public ChangeUserRoleController() { - setCommandClass(ChangeUserRoleCommand.class); - setCommandName("changeUserRole"); - } - - @Override - protected ModelAndView onSubmit(Object command) throws Exception { - ChangeUserRoleCommand data = (ChangeUserRoleCommand) command; - - Person person = personDao.getPerson(data.getUserName()); - person.setAuthority(data.getUserRole()); - personDao.update(person); - - return new ModelAndView(getSuccessView()); - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/admin/ChangeUserRoleValidator.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/admin/ChangeUserRoleValidator.java deleted file mode 100644 index eae287c6..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/admin/ChangeUserRoleValidator.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ChangeUserRoleValidator.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.admin; - -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.logic.Util; -import org.springframework.validation.Errors; -import org.springframework.validation.Validator; - -/** - * @author Jindra - */ -public class ChangeUserRoleValidator implements Validator { - - private PersonDao personDao; - - public boolean supports(Class clazz) { - return clazz.equals(ChangeUserRoleCommand.class); - } - - public void validate(Object command, Errors errors) { - ChangeUserRoleCommand data = (ChangeUserRoleCommand) command; - - String userName = data.getUserName(); - if (userName.trim().isEmpty()) { - errors.rejectValue("userName", "required.field"); - } else if (!personDao.usernameExists(userName)) { - errors.rejectValue("userName", "userNameDoesNotExist"); - } - - if (data.getUserRole().equals("-1")) { - errors.rejectValue("userRole", "required.userRole"); - } else if (!((data.getUserRole().equals(Util.ROLE_ADMIN)) || (data.getUserRole().equals(Util.ROLE_USER)))) { - errors.rejectValue("userRole", "invalid.userRole"); - } - - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/AddArticleCommentController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/AddArticleCommentController.java deleted file mode 100644 index e4a30c64..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/AddArticleCommentController.java +++ /dev/null @@ -1,366 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddArticleCommentController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package cz.zcu.kiv.eegdatabase.logic.controller.article; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.GenericDao; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Article; -import cz.zcu.kiv.eegdatabase.data.pojo.ArticleComment; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroupMembership; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.context.HierarchicalMessageSource; -import org.springframework.mail.MailException; -import org.springframework.mail.SimpleMailMessage; -import org.springframework.mail.javamail.JavaMailSenderImpl; -import org.springframework.mail.javamail.MimeMessageHelper; -import org.springframework.validation.BindException; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; -import org.springframework.web.servlet.support.RequestContextUtils; - -import javax.mail.MessagingException; -import javax.mail.internet.MimeMessage; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.sql.Timestamp; -import java.util.Calendar; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - - -/** - * @author Jiri Vlasimsky - */ -public class AddArticleCommentController extends SimpleFormController implements Validator { - - private AuthorizationManager auth; - private GenericDao articleDao; - private GenericDao articleCommentDao; - private PersonDao personDao; - private ResearchGroupDao researchGroupDao; - private Log log = LogFactory.getLog(getClass()); - private String domain; - private JavaMailSenderImpl mailSender; - private SimpleMailMessage mailMessage; - private HierarchicalMessageSource messageSource; - - public AddArticleCommentController() { - setCommandClass(ArticleCommentCommand.class); - setCommandName("addArticleComment"); - } - - @Override - protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception { - ModelAndView mav = super.showForm(request, response, errors); - setPermissionsToView(mav); - - return mav; - } - - @Override - protected Object formBackingObject(HttpServletRequest request) throws Exception { - ArticleCommentCommand data = (ArticleCommentCommand) super.formBackingObject(request); - - String articleIdCommentString = request.getParameter("articleCommentId"); - int articleId = 0; - int parentId = 0; - - try { - articleId = Integer.parseInt(request.getParameter("articleId")); - parentId = Integer.parseInt(request.getParameter("parentId")); - } catch (Exception e) { - } - - if (articleIdCommentString != null) { - int articleCommentId = Integer.parseInt(articleIdCommentString); - if (articleCommentId > 0) { // it is a form for editing - - log.debug("Filling backing object with data from articleComment object #" + articleCommentId); - data.setCommentId(articleCommentId); - - - ArticleComment articleComment = articleCommentDao.read(articleCommentId); - - - log.debug("Setting article comment´s parent comment"); - data.setParentId(articleComment.getParent().getCommentId()); - - log.debug("Setting article comment´s text"); - data.setText(articleComment.getText()); - - log.debug("Setting article comment´s parent article"); - data.setArticleId(articleComment.getArticle().getArticleId()); - } - - - } - log.debug("Setting comment´s parent article"); - data.setArticleId(articleId); - - log.debug("Setting comment´s parent comment"); - data.setParentId(parentId); - return data; - } - - @Override - protected Map referenceData(HttpServletRequest request) throws Exception { - Map map = new HashMap(); - return map; - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception { - ModelAndView mav = new ModelAndView(getSuccessView()); - - ArticleCommentCommand data = (ArticleCommentCommand) command; - ArticleComment comment; - Article article = articleDao.read(data.getArticleId()); - Person loggedUser = personDao.getLoggedPerson(); - if (data.getCommentId() > 0) { - log.debug("Processing article comment form - editing existing comment"); - log.debug("Checking the permission level"); - } else { - comment = new ArticleComment(); -// String articleIdCommentString = request.getParameter("articleCommentId"); - - log.debug("Setting comment owner to logged user"); - comment.setPerson(personDao.getLoggedPerson()); - - log.debug("Setting comment´s parent comment"); - comment.setParent(articleCommentDao.read(data.getParentId())); - - log.debug("Setting comment parent article"); - comment.setArticle(article); - - log.debug("Setting comment text"); - comment.setText(data.getText()); - - log.debug("Setting comment time"); - Timestamp currentTimestamp = new java.sql.Timestamp(Calendar.getInstance().getTime().getTime()); - comment.setTime(currentTimestamp); - - log.debug("Processing an article comment form - adding a new article"); - articleCommentDao.create(comment); - - for (Person subscriber : article.getSubscribers()) { - if (!loggedUser.equals(subscriber)) { - this.sendNotification(subscriber.getEmail(), comment, request); - } - } - } - mav = new ModelAndView("redirect:/articles/detail.html?articleId=" + data.getArticleId()); - return mav; - } - - private void sendNotification(String email, ArticleComment comment, HttpServletRequest request) throws MessagingException { - String articleURL = "http://" + domain + "/articles/detail.html?articleId=" + comment.getArticle().getArticleId(); - //System.out.println(articleURL); - String subject = messageSource.getMessage("articles.group.email.subscribtion.subject", new String[]{comment.getArticle().getTitle(), comment.getPerson().getUsername()}, RequestContextUtils.getLocale(request)); - //System.out.println(subject); - String emailBody = ""; - - emailBody += "

" + messageSource.getMessage("articles.group.email.subscribtion.body.text.part1", - new String[]{comment.getArticle().getTitle()}, - RequestContextUtils.getLocale(request)) + ""; - emailBody += " (" + articleURL + ")


"; - emailBody += "

Text:

" + comment.getText() + "


"; - emailBody += "

" + messageSource.getMessage("articles.comments.email.subscribtion.body.text.part2", null, RequestContextUtils.getLocale(request)) + "

"; - emailBody += ""; - - //System.out.println(emailBody); - log.debug("email body: " + emailBody); - - - log.debug("Composing e-mail message"); - MimeMessage mimeMessage = mailSender.createMimeMessage(); - - MimeMessageHelper message = new MimeMessageHelper(mimeMessage); - message.setFrom(mailMessage.getFrom()); - - // message.setContent("text/html"); - message.setTo(email); - //helper.setFrom(messageSource.getMessage("registration.email.from", null, RequestContextUtils.getLocale(request))); - message.setSubject(subject); - message.setText(emailBody, true); - - try { - log.debug("Sending e-mail" + message); - log.debug("mailSender" + mailSender); - log.debug("smtp " + mailSender.getHost()); - mailSender.send(mimeMessage); - log.debug("E-mail was sent"); - } catch (MailException e) { - log.error("E-mail was NOT sent"); - log.error(e); - } - } - - /** - * Determines if the logged user can view the supposed article - * - * @param loggedUser Person object (Usually logged user) - * @param article Article object - * @return true if admin or member of group - */ - public boolean canView(Person loggedUser, Article article) { - if (loggedUser.getAuthority().equals("ROLE_ADMIN") || article.getResearchGroup() == null) { - return true; - } - Set researchGroupMemberships = article.getResearchGroup().getResearchGroupMemberships(); - for (ResearchGroupMembership member : researchGroupMemberships) { - if (member.getPerson().getPersonId() == loggedUser.getPersonId()) { - return true; - } - } - return false; - } - - /** - * Determines if the logged user can edit the supposed article - * - * @param loggedUser Person object (Usually logged user) - * @param article Article object - * @return true if admin or member of group - */ - public boolean canEdit(Person loggedUser, Article article) { - boolean isAdmin = loggedUser.getAuthority().equals("ROLE_ADMIN"); - boolean isOwner = article.getPerson().getPersonId() == loggedUser.getPersonId(); - return (isOwner || isAdmin); - } - - /** - * Checks if user is admin in any group - * - * @param mav ModelAndView for display - */ - public void setPermissionsToView(ModelAndView mav) { - // isAdmin - Person loggedUser = personDao.getLoggedPerson(); - if (loggedUser.getAuthority().equals("ROLE_ADMIN")) { - mav.addObject("userIsAdminInAnyGroup", true); - return; - } - // check all groups for admin role - Set researchGroupMemberShips = loggedUser.getResearchGroupMemberships(); - for (ResearchGroupMembership member : researchGroupMemberShips) { - if (auth.userIsAdminInGroup(member.getResearchGroup().getResearchGroupId())) { - mav.addObject("userIsAdminInAnyGroup", true); - return; - } - } - } - - public boolean supports(Class type) { - return type.equals(ArticleCommentCommand.class); - } - - public GenericDao getArticleDao() { - return articleDao; - } - - public void setArticleDao(GenericDao articleDao) { - this.articleDao = articleDao; - } - - public void validate(Object command, Errors errors) { - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "text", "required.field"); - } - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public ResearchGroupDao getResearchGroupDao() { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) { - this.researchGroupDao = researchGroupDao; - } - - public GenericDao getArticleCommentDao() { - return articleCommentDao; - } - - public void setArticleCommentDao(GenericDao articleCommentDao) { - this.articleCommentDao = articleCommentDao; - } - - public SimpleMailMessage getMailMessage() { - return mailMessage; - } - - public void setMailMessage(SimpleMailMessage mailMessage) { - this.mailMessage = mailMessage; - } - - public JavaMailSenderImpl getMailSender() { - return mailSender; - } - - public void setMailSender(JavaMailSenderImpl mailSender) { - this.mailSender = mailSender; - } - - public HierarchicalMessageSource getMessageSource() { - return messageSource; - } - - public void setMessageSource(HierarchicalMessageSource messageSource) { - this.messageSource = messageSource; - } - - public String getDomain() { - return domain; - } - - public void setDomain(String domain) { - this.domain = domain; - } - - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/AddArticleController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/AddArticleController.java deleted file mode 100644 index 88a47020..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/AddArticleController.java +++ /dev/null @@ -1,371 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddArticleController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package cz.zcu.kiv.eegdatabase.logic.controller.article; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.GenericDao; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; -import cz.zcu.kiv.eegdatabase.data.pojo.*; -import cz.zcu.kiv.eegdatabase.logic.controller.social.LinkedInManager; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.HierarchicalMessageSource; -import org.springframework.mail.MailException; -import org.springframework.mail.SimpleMailMessage; -import org.springframework.mail.javamail.JavaMailSenderImpl; -import org.springframework.mail.javamail.MimeMessageHelper; -import org.springframework.validation.BindException; -import org.springframework.validation.Errors; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; -import org.springframework.web.servlet.support.RequestContextUtils; - -import javax.mail.MessagingException; -import javax.mail.internet.MimeMessage; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.sql.Timestamp; -import java.util.*; - -/** - * @author Jiri Vlasimsky - */ -public class AddArticleController extends SimpleFormController { - - private AuthorizationManager auth; - private GenericDao articleDao; - private GenericDao articleCommentDao; - private PersonDao personDao; - private ResearchGroupDao researchGroupDao; - private Log log = LogFactory.getLog(getClass()); - private String domain; - private JavaMailSenderImpl mailSender; - private SimpleMailMessage mailMessage; - private HierarchicalMessageSource messageSource; - @Autowired - private LinkedInManager linkedin; - - - public AddArticleController() { - setCommandClass(ArticleCommand.class); - setCommandName("addArticle"); - } - - @Override - protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception { - ModelAndView mav = super.showForm(request, response, errors); - setPermissionsToView(mav); - return mav; - } - - @Override - protected Object formBackingObject(HttpServletRequest request) throws Exception { - ArticleCommand data = (ArticleCommand) super.formBackingObject(request); - String articleIdString = request.getParameter("articleId"); - if (articleIdString != null) { - int articleId = Integer.parseInt(articleIdString); - if (articleId > 0) { // it is a form for editing - - data.setArticleId(articleId); - - log.debug("Filling backing object with data from article object #" + articleId); - data.setArticleId(articleId); - Article article = articleDao.read(articleId); - - log.debug("Setting article title"); - data.setTitle(article.getTitle()); - - log.debug("Setting article text"); - data.setText(article.getText()); - } - } - return data; - } - - @Override - protected Map referenceData(HttpServletRequest request) throws Exception { - Map map = new HashMap(); - List researchGroupList = - researchGroupDao.getResearchGroupsWhereAbleToWriteInto(personDao.getLoggedPerson()); - ResearchGroup defaultGroup = personDao.getLoggedPerson().getDefaultGroup(); - int defaultGroupId = (defaultGroup != null) ? defaultGroup.getResearchGroupId() : 0; - map.put("defaultGroupId", defaultGroupId); - map.put("researchGroupList", researchGroupList); - return map; - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception { - ModelAndView mav = new ModelAndView(getSuccessView()); - - ArticleCommand data = (ArticleCommand) command; - - Article article; - - if (data.getArticleId() > 0) { - log.debug("Processing article form - editing existing article"); - log.debug("Checking the permission level."); - article = articleDao.read(data.getArticleId()); - Person loggedUser = personDao.getLoggedPerson(); - - if (!canEdit(loggedUser, article)) { - log.debug("User is not group or system admininstrator - unable to edit article. Returning MAV."); - mav.setViewName("article/unableToEditArticle"); - return mav; - } - } else { - article = new Article(); - - log.debug("Setting the owner to the logged user."); - article.setPerson(personDao.getLoggedPerson()); - - log.debug("Setting the group to which is the new article assigned"); - ResearchGroup researchGroup = new ResearchGroup(); - if (data.getResearchGroup() != 0) { - researchGroup.setResearchGroupId(data.getResearchGroup()); - article.setResearchGroup(researchGroup); - } - - - log.debug("Setting article time"); - Timestamp currentTimestamp = new java.sql.Timestamp(Calendar.getInstance().getTime().getTime()); - article.setTime(currentTimestamp); - } - - log.debug("Setting article title"); - article.setTitle(data.getTitle()); - - log.debug("Setting article text"); - article.setText(data.getText()); - - if (data.getArticleId() > 0) { - log.debug("Processing an article form - editing an existing article"); - articleDao.update(article); - } else { - log.debug("Processing an article form - adding a new article"); - articleDao.create(article); - - if (article.getResearchGroup() != null) { - ResearchGroup group = researchGroupDao.read(article.getResearchGroup().getResearchGroupId()); - for (Person subscriber : group.getArticlesSubscribers()) { - if (!subscriber.equals(article.getPerson())) { - this.sendNotification(subscriber.getEmail(), article, request); - } - } - } - } - - //Publish article on LinkedIn - if ((request.getParameter("publishOnLinkedIn") != null) && (request.getParameter("publishOnLinkedIn").equals("publish"))){ - log.debug("Publishing an article on LinkedIn"); - linkedin.publish(data.getTitle(), data.getText()); - } - - return mav; - } - - private void sendNotification(String email, Article article, HttpServletRequest request) throws MessagingException { - String articleURL = "http://" + domain + "/articles/detail.html?articleId=" + article.getArticleId(); - //System.out.println(articleURL); - String subject = messageSource.getMessage("articles.group.email.subscribtion.subject", new String[]{article.getTitle(), article.getPerson().getUsername()}, RequestContextUtils.getLocale(request)); - //System.out.println(subject); - String emailBody = ""; - - emailBody += "

" + messageSource.getMessage("articles.comments.email.subscribtion.body.text.part1", - new String[]{article.getTitle()}, - RequestContextUtils.getLocale(request)) + ""; - emailBody += " (" + articleURL + ")


"; - emailBody += "

" + article.getTitle() + "

" + article.getText() + "


"; - emailBody += "

" + messageSource.getMessage("articles.comments.email.subscribtion.body.text.part2", null, RequestContextUtils.getLocale(request)) + "

"; - emailBody += ""; - - //System.out.println(emailBody); - log.debug("email body: " + emailBody); - - - log.debug("Composing e-mail message"); - MimeMessage mimeMessage = mailSender.createMimeMessage(); - - MimeMessageHelper message = new MimeMessageHelper(mimeMessage); - message.setFrom(mailMessage.getFrom()); - - // message.setContent("text/html"); - message.setTo(email); - //helper.setFrom(messageSource.getMessage("registration.email.from", null, RequestContextUtils.getLocale(request))); - message.setSubject(subject); - message.setText(emailBody, true); - - try { - log.debug("Sending e-mail" + message); - log.debug("mailSender" + mailSender); - log.debug("smtp " + mailSender.getHost()); - mailSender.send(mimeMessage); - log.debug("E-mail was sent"); - } catch (MailException e) { - log.error("E-mail was NOT sent"); - log.error(e); - } - } - - /** - * Determines if the logged user can view the supposed article - * - * @param loggedUser Person object (Usually logged user) - * @param article Article object - * @return true if admin or member of group - */ - public boolean canView(Person loggedUser, Article article) { - if (loggedUser.getAuthority().equals("ROLE_ADMIN") || article.getResearchGroup() == null) { - return true; - } - Set researchGroupMemberships = article.getResearchGroup().getResearchGroupMemberships(); - for (ResearchGroupMembership member : researchGroupMemberships) { - if (member.getPerson().getPersonId() == loggedUser.getPersonId()) { - return true; - } - } - return false; - } - - /** - * Determines if the logged user can edit the supposed article - * - * @param loggedUser Person object (Usually logged user) - * @param article Article object - * @return true if admin or member of group - */ - public boolean canEdit(Person loggedUser, Article article) { - boolean isAdmin = loggedUser.getAuthority().equals("ROLE_ADMIN"); - boolean isOwner = article.getPerson().getPersonId() == loggedUser.getPersonId(); - return (isOwner || isAdmin); - } - - /** - * Checks if user is admin in any group - * - * @param mav ModelAndView for display - */ - public void setPermissionsToView(ModelAndView mav) { - // isAdmin - Person loggedUser = personDao.getLoggedPerson(); - if (loggedUser.getAuthority().equals("ROLE_ADMIN")) { - mav.addObject("userIsAdminInAnyGroup", true); - return; - } - // check all groups for admin role - Set researchGroupMemberShips = loggedUser.getResearchGroupMemberships(); - for (ResearchGroupMembership member : researchGroupMemberShips) { - if (auth.userIsAdminInGroup(member.getResearchGroup().getResearchGroupId())) { - mav.addObject("userIsAdminInAnyGroup", true); - return; - } - } - } - - public boolean supports(Class type) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public GenericDao getArticleDao() { - return articleDao; - } - - public void setArticleDao(GenericDao articleDao) { - this.articleDao = articleDao; - } - - public void validate(Object command, Errors errors) { - throw new UnsupportedOperationException("Not supported yet."); - } - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public ResearchGroupDao getResearchGroupDao() { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) { - this.researchGroupDao = researchGroupDao; - } - - public GenericDao getArticleCommentDao() { - return articleCommentDao; - } - - public void setArticleCommentDao(GenericDao articleCommentDao) { - this.articleCommentDao = articleCommentDao; - } - - public String getDomain() { - return domain; - } - - public void setDomain(String domain) { - this.domain = domain; - } - - public SimpleMailMessage getMailMessage() { - return mailMessage; - } - - public void setMailMessage(SimpleMailMessage mailMessage) { - this.mailMessage = mailMessage; - } - - public JavaMailSenderImpl getMailSender() { - return mailSender; - } - - public void setMailSender(JavaMailSenderImpl mailSender) { - this.mailSender = mailSender; - } - - public HierarchicalMessageSource getMessageSource() { - return messageSource; - } - - public void setMessageSource(HierarchicalMessageSource messageSource) { - this.messageSource = messageSource; - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/AddArticleValidator.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/AddArticleValidator.java deleted file mode 100644 index 27d2bd76..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/AddArticleValidator.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddArticleValidator.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.article; - -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -/** - * Created with IntelliJ IDEA. - * User: stebjan - * Date: 29.11.12 - * Time: 11:55 - * To change this template use File | Settings | File Templates. - */ -public class AddArticleValidator implements Validator { - @Override - public boolean supports(Class aClass) { - return aClass.equals(ArticleCommand.class); - } - - @Override - public void validate(Object command, Errors errors) { - ArticleCommand ac = (ArticleCommand) command; - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "title", "required.field"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "text", "required.field"); - - if (ac.getTitle().length() > 150) { - errors.rejectValue("title", "invalid.articleLength"); - } - - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/ArticleCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/ArticleCommand.java deleted file mode 100644 index bbcfbb70..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/ArticleCommand.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ArticleCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.article; - -import cz.zcu.kiv.eegdatabase.data.pojo.Person; - -import java.util.HashSet; -import java.util.Set; - -/** - * @author Jiri Vlasimsky - */ -public class ArticleCommand { - private int articleId; - private int personId; - private int researchGroup; - private String title; - private String text; - private String time; - private Set subscribers = new HashSet(0); - - public int getArticleId() { - return articleId; - } - - public void setArticleId(int articleId) { - this.articleId = articleId; - } - - public int getPersonId() { - return personId; - } - - public void setPersonId(int personId) { - this.personId = personId; - } - - public int getResearchGroup() { - return researchGroup; - } - - public void setResearchGroup(int researchGroup) { - this.researchGroup = researchGroup; - } - - public String getText() { - return text; - } - - public void setText(String text) { - this.text = text; - } - - public String getTime() { - return time; - } - - public void setTime(String time) { - this.time = time; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public Set getSubscribers() { - return subscribers; - } - - public void setSubscribers(Set subscribers) { - this.subscribers = subscribers; - } - - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/ArticleCommentCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/ArticleCommentCommand.java deleted file mode 100644 index 8fc09a26..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/ArticleCommentCommand.java +++ /dev/null @@ -1,88 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ArticleCommentCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.article; - - -/** - * @author Jiri Vlasimsky - */ -public class ArticleCommentCommand { - private int commentId; - private int articleId; - private int parentId; - private int personId; - - private String text; - private String time; - - - public int getArticleId() { - return articleId; - } - - public void setArticleId(int articleId) { - this.articleId = articleId; - } - - public int getCommentId() { - return commentId; - } - - public void setCommentId(int commentId) { - this.commentId = commentId; - } - - public int getParentId() { - return parentId; - } - - public void setParentId(int parentId) { - this.parentId = parentId; - } - - public int getPersonId() { - return personId; - } - - public void setPersonId(int personId) { - this.personId = personId; - } - - public String getText() { - return text; - } - - public void setText(String text) { - this.text = text; - } - - public String getTime() { - return time; - } - - public void setTime(String time) { - this.time = time; - } - - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/ArticleMultiController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/ArticleMultiController.java deleted file mode 100644 index 15ad9d33..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/ArticleMultiController.java +++ /dev/null @@ -1,597 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ArticleMultiController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.article; - -import cz.zcu.kiv.eegdatabase.data.dao.*; -import cz.zcu.kiv.eegdatabase.data.pojo.*; -import cz.zcu.kiv.eegdatabase.logic.controller.social.LinkedInManager; -import cz.zcu.kiv.eegdatabase.logic.util.Paginator; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.social.linkedin.api.Group; -import org.springframework.social.linkedin.api.Post; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.multiaction.MultiActionController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.xml.stream.XMLEventFactory; -import javax.xml.stream.XMLEventWriter; -import javax.xml.stream.events.Characters; -import javax.xml.stream.events.EndElement; -import javax.xml.stream.events.StartElement; -import javax.xml.stream.events.XMLEvent; -import java.io.IOException; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import java.util.Set; - -/** - * Controller for adding and editing an article - * - * @author Jiri Vlasimsky, Ladislav Janák - */ -public class ArticleMultiController extends MultiActionController { - - private Log log = LogFactory.getLog(getClass()); - private AuthorizationManager auth; - private PersonDao personDao; - private ArticleDao articleDao; - private ArticleCommentDao articleCommentDao; - private ResearchGroupDao researchGroupDao; - private SimpleKeywordsDao simpleKeywordsDao; - private String domain; - - private static final int ARTICLES_PER_PAGE = 10; - - /** - * Posts from EEG/ERP portal LinkedIn group - */ - List linkedInArticles = null; - /** - * Filtered posts from EEG/ERP portal LinkedIn group - */ - List linkedInArticlesFiltered = null; - /** - * Text with keywords - */ - List keywordsSettings = new ArrayList(); - /** - * Groip details from EEG/ERP portal LinkedIn group - */ - Group groupDetails = null; - /** - * Reference to LinkedInManager bean - */ - private final LinkedInManager linkedInManager; - /** - * Whether has to be internal articles showed - */ - boolean showInternal = true; - /** - * Whether has to be linkedIn articles showed - */ - boolean showLinkedIn = false; - - - /** - * Constructor - * @param linkedInManager Reference to linkedInManager bean - */ - public ArticleMultiController(LinkedInManager linkedInManager) throws IOException { - this.linkedInManager = linkedInManager; - } - - /* - * public void init() { keyWordsList = new ArrayList(); for - * (Enumeration en = this.propertiesHolder.keys(); en.hasMoreElements(); ) { - * String key = (String) en.nextElement(); - * this.keyWordsList.add(this.propertiesHolder.getProperty(key)); } } - */ - public ModelAndView rss(HttpServletRequest request, HttpServletResponse response) { - ModelAndView mav = new ModelAndView("articles/rss"); - SimpleDateFormat formatter = new SimpleDateFormat("dd MMM yyyy HH:mm:ss Z"); - String today = formatter.format(new Date()); - List
articleList = articleDao.getAllArticles(); - int groupId; - - String copyright = "Copyright © The University of West Bohemia"; - String title = "EEGbase articles RSS feed"; - String description = "Articles from EEGbase content management system"; - String language = "en"; - String link = domain + "/files/articles.rss"; - - Feed rssFeeder = new Feed(title, link, description, language, copyright, today); - - - // Now add one example entry - - for (Article article : articleList) { - FeedMessage feed = new FeedMessage(); - feed.setTitle(article.getTitle()); - feed.setDescription(article.getText().substring(0, (article.getText().length() > 200) ? 200 : article.getText().length() - 1)); - feed.setAuthor(article.getPerson().getUsername()); - feed.setGuid(""); - feed.setLink(domain + "/articles/detail.html?articleId=" + article.getArticleId()); - rssFeeder.getMessages().add(feed); - } - - - // Now write the file - RSSFeedWriter writer = new RSSFeedWriter(rssFeeder, request.getRealPath("/") + "/files/articles.rss"); - String rssFeedBuffer = ""; - try { - rssFeedBuffer = writer.write(); - } catch (Exception e) { - e.printStackTrace(); - } - - mav.addObject("rssFeedBuffer", rssFeedBuffer); - mav.addObject("articleList", articleList); - mav.addObject("articleListTitle", "pageTitle.internalArticles"); - mav = new ModelAndView("redirect:/files/articles.rss"); - return mav; - } - - - /** - * Get method for list.jsp form, it shows internal and linkedIn articles - * @return model and view object which shows internal and linkedIn articles - * @throws Exception - */ - @RequestMapping(value = "articles/list", method = RequestMethod.GET) - public ModelAndView list(@RequestParam(value = "page", required = false) Integer page) throws Exception { - - - ModelAndView mav = new ModelAndView("articles/list"); - Person loggedUser = personDao.getLoggedPerson(); - setPermissionsToView(mav); - Paginator paginator = new Paginator(articleDao.getArticleCountForPerson(loggedUser), ARTICLES_PER_PAGE, "list.html?page=%1$d"); - if (page == null) { - page = 1; - } - paginator.setActualPage(page); - mav.addObject("paginator", paginator.getLinks()); - List articleList = new ArrayList(); - - - if (showInternal) { - articleList = articleDao.getArticlesForList(loggedUser, paginator.getFirstItemIndex(), ARTICLES_PER_PAGE); - } - - if (showLinkedIn) { - mav.addObject("articleListTitle", "pageTitle.linkedInArticles"); - } - if (showInternal) { - mav.addObject("articleListTitle", "pageTitle.internalArticles"); - } - if (showInternal && showLinkedIn) { - mav.addObject("articleListTitle", "pageTitle.allArticles"); - } - if (!showInternal && !showLinkedIn) { - mav.addObject("articleListTitle", "pageTitle.noArticles"); - } - - mav.addObject("showLinkedIn", showLinkedIn); - mav.addObject("showInternal", showInternal); - mav.addObject("groupDetails", groupDetails); - mav.addObject("linkedInArticles", linkedInArticlesFiltered); - - mav.addObject("articleList", articleList); - mav.addObject("articleListTitle", "pageTitle.allArticles"); - mav.addObject("userIsGlobalAdmin", loggedUser.getAuthority().equals("ROLE_ADMIN")); - mav.addObject("loggedUserId", loggedUser.getPersonId()); - return mav; - } - - /** - * Post method for list.jsp form, it controls two checkboxes, which deside which articles will be showed - * From LinkedIn EEG/ERP group returns filtered articles by keywords filter, this filter is not enabled yet and is commented. - * After new release of linkedIn API can be filter uncomment - * @param request HTTP request - * @param response HTTP response - * @return new model and view - */ - @RequestMapping(value = "articles/list", method = RequestMethod.POST) - public ModelAndView submitShowArticles(HttpServletRequest request, HttpServletResponse response) { - - //shows linkedIn aricles - if (request.getParameter("showOnLinkedInArticles") != null && (request.getParameter("showOnLinkedInArticles").equals("1"))) { - - List keywords = new ArrayList(); - Person loggedUser = personDao.getLoggedPerson(); - - linkedInArticlesFiltered = new ArrayList(); - List groups = researchGroupDao.getResearchGroupsWhereMember(loggedUser); - for (ResearchGroup item : groups) { - //gets keywords from DB - keywords.add(simpleKeywordsDao.getKeywords(item.getResearchGroupId())); - } - - if (keywords.isEmpty()) - return new ModelAndView("redirect:list.html"); - - String keywordsText = keywords.get(0); - - //keywords are splitted by "," - String parseKeywords[] = keywordsText.split(","); - - //downloads posts from EEG/ERP group on linkedIn - linkedInArticles = linkedInManager.getPosts(linkedInManager.groupId); - - //***************FILTER for correct function delete this comment**************/ - /* - * for (Post item : linkedInArticles) { for (int i = 0; i < - * parseKeywords.length; i++ ){ if - * (item.getSummary().contains(parseKeywords[i].trim())){ - * linkedInArticlesPom.add(item); break; } } - } - //***************FILTER for correct function delete this comment**************/ - - groupDetails = linkedInManager.getGroupDetails(); - showLinkedIn = true; - } else { - showLinkedIn = false; - groupDetails = null; - linkedInArticles = null; - } - //shows internal articles - if (request.getParameter("showInternalArticles") != null && (request.getParameter("showInternalArticles").equals("1"))) { - showInternal = true; - } else { - showInternal = false; - } - - return new ModelAndView("redirect:list.html"); - } - - @Override - protected Object newCommandObject(Class myClass) - throws Exception { - return new ArticleCommentCommand(); - } - - @RequestMapping("articles/detail") - public ModelAndView detail(HttpServletRequest request, HttpServletResponse response) { - ArticleCommentCommand command = new ArticleCommentCommand(); - - ModelAndView mav = new ModelAndView("articles/detail"); - Person loggedUser = personDao.getLoggedPerson(); - setPermissionsToView(mav); - int id = -1; - try { - id = Integer.parseInt(request.getParameter("articleId")); - } catch (Exception e) { - log.debug("Unable to determine article id"); - } - Article article = (Article) articleDao.getArticleDetail(id, loggedUser); - // If the user is not permitted to view the article, null is returned. We will redirect to article list instead of displaying the article page. - if (article == null) { - return new ModelAndView("redirect:list.html"); - } - - command.setArticleId(id); - mav.addObject("command", command); - mav.addObject("userCanEdit", canEdit(loggedUser, article)); - mav.addObject("article", article); - - // First we load all article comments for the article, so the most of them are already loaded and don't need to be lazily loaded - List articleComments = articleCommentDao.getCommentsForArticle(id); - List noParents = new ArrayList(); - // Then we filter out the comments with no parent - for (ArticleComment comment : articleComments) { - if (comment.getParent() == null) { - noParents.add(comment); - } - } - mav.addObject("commentsList", noParents); - - mav.addObject("subscribed", article.getSubscribers().contains(loggedUser)); - return mav; - } - @RequestMapping(value = "articles/delete", method = RequestMethod.GET) - public ModelAndView delete(HttpServletRequest request, HttpServletResponse response) { - ModelAndView mav = new ModelAndView("articles/articleDeleted"); - setPermissionsToView(mav); - Person loggedUser = personDao.getLoggedPerson(); - int id = 0; - try { - id = Integer.parseInt(request.getParameter("articleId")); - } catch (Exception e) { - log.debug("Unable to determine article id"); - } - - Article article = (Article) articleDao.read(id); - if (canEdit(loggedUser, article)) { - articleDao.delete(article); - } - return mav; - } - - /** - * Post method for articleSettings.jsp form, it allows store new keywords to the database. - * It allows set up new keywords for users research groups - * If all users research group IDs already exist in Keywords are these records updated, otherwise new research group Id is stored into Keywords table - * @param request HTTP request - * @param response HTTP request - * @return new model and view - */ - @RequestMapping(value = "articles/settings", method = RequestMethod.POST) - public ModelAndView submitArticleFilterSettings(HttpServletRequest request, HttpServletResponse response) { - String keywords = request.getParameter("keywords"); - - if (keywords.equals("No keywords defined!")) - return new ModelAndView("redirect:settings.html"); - - Keywords keywordsRecord; - ResearchGroup researchGroup; - int keywordID; - Person loggedUser = personDao.getLoggedPerson(); - List groups = researchGroupDao.getResearchGroupsWhereMember(loggedUser); - - for (ResearchGroup item : groups) { - keywordID = simpleKeywordsDao.getID(item.getResearchGroupId()); - //research group id not exist in Keywords - if (keywordID == -1) { - keywordsRecord = new Keywords(); - researchGroup = new ResearchGroup(); - researchGroup.setResearchGroupId(item.getResearchGroupId()); - keywordsRecord.setKeywordsText(keywords); - keywordsRecord.setResearchGroup(researchGroup); - simpleKeywordsDao.create(keywordsRecord); - //research group already exist in keywords - } else { - researchGroup = new ResearchGroup(); - researchGroup.setResearchGroupId(item.getResearchGroupId()); - keywordsRecord = simpleKeywordsDao.read(simpleKeywordsDao.getID(item.getResearchGroupId())); - keywordsRecord.setKeywordsText(keywords); - keywordsRecord.setResearchGroup(researchGroup); - simpleKeywordsDao.update(keywordsRecord); - } - } - return new ModelAndView("redirect:settings.html"); - } - - /** - * Get method for articleSetting.jsp form, it showes keywords of users research groups in textarea - * @param request HTTP request - * @param response HTTP response - * @param model model for view - * @return new model and view - * @throws Exception - */ - @RequestMapping(value = "articles/settings", method = RequestMethod.GET) - public ModelAndView settings(HttpServletRequest request, HttpServletResponse response, ModelMap model) throws Exception { - keywordsSettings.clear(); - ModelAndView mav = new ModelAndView("articles/articleSettings"); - setPermissionsToView(mav); - Person loggedUser = personDao.getLoggedPerson(); - - List groups = researchGroupDao.getResearchGroupsWhereMember(loggedUser); - - if (groups.isEmpty()) - return new ModelAndView("redirect:list.html"); - - for (ResearchGroup item : groups) { - //gets keywords from DB - String keyword = simpleKeywordsDao.getKeywords(item.getResearchGroupId()); - keywordsSettings.add(keyword); - } - Set articlesGroupSubscriptions = loggedUser.getArticlesGroupSubscribtions(); - List list = researchGroupDao.getResearchGroupsWhereMember(loggedUser); - mav.addObject("researchGroupList", list); - mav.addObject("articlesGroupSubscribtions", articlesGroupSubscriptions); - model.addAttribute("keywords", keywordsSettings.get(0)); - return mav; - } - - @RequestMapping(value = "articles/subscribe", method = RequestMethod.GET) - public ModelAndView subscribe(HttpServletRequest request, HttpServletResponse response) { - ModelAndView mav = new ModelAndView("articles/subscribe"); - setPermissionsToView(mav); - Person loggedUser = personDao.getLoggedPerson(); - int id = 0; - try { - id = Integer.parseInt(request.getParameter("articleId")); - } catch (NumberFormatException e) { - log.debug("Unable to determine article id"); - } - Article article = (Article) articleDao.read(id); - Boolean subscribe = Boolean.parseBoolean(request.getParameter("subscribe")); - Set subscribers = article.getSubscribers(); - if (subscribe) { - subscribers.add(loggedUser); - } else { - subscribers.remove(loggedUser); - } - article.setSubscribers(subscribers); - articleDao.update(article); - - mav = new ModelAndView("redirect:/articles/detail.html?articleId=" + id); - return mav; - } - - public ModelAndView subscribeGroupArticles(HttpServletRequest request, HttpServletResponse response) { - ModelAndView mav = new ModelAndView("articles/subscribeGroupArticles"); - setPermissionsToView(mav); - Person loggedUser = personDao.getLoggedPerson(); - int id = 0; - try { - id = Integer.parseInt(request.getParameter("groupId")); - } catch (NumberFormatException e) { - log.debug("Unable to determine research group id"); - } - ResearchGroup group = (ResearchGroup) researchGroupDao.read(id); - - Boolean subscribe = Boolean.parseBoolean(request.getParameter("subscribe")); - - Set subscribers = group.getArticlesSubscribers(); - if (subscribe) { - subscribers.add(loggedUser); - } else { - subscribers.remove(loggedUser); - } - group.setArticlesSubscribers(subscribers); - researchGroupDao.update(group); - - mav = new ModelAndView("redirect:/articles/settings.html"); - return mav; - } - - /** - * Determines if the logged user can view the supposed article - * - * @param loggedUser Person object (Usually logged user) - * @param article Article object - * @return true if admin or member of group - */ - public boolean canView(Person loggedUser, Article article) { - if (loggedUser.getAuthority().equals("ROLE_ADMIN") || article.getResearchGroup() == null) { - return true; - } - Set researchGroupMemberships = article.getResearchGroup().getResearchGroupMemberships(); - for (ResearchGroupMembership member : researchGroupMemberships) { - if (member.getPerson().getPersonId() == loggedUser.getPersonId()) { - return true; - } - } - return false; - } - - /** - * Determines if the logged user can edit the supposed article - * - * @param loggedUser Person object (Usually logged user) - * @param article Article object - * @return true if admin or member of group - */ - public boolean canEdit(Person loggedUser, Article article) { - boolean isAdmin = loggedUser.getAuthority().equals("ROLE_ADMIN"); - boolean isOwner = article.getPerson().getPersonId() == loggedUser.getPersonId(); - return (isOwner || isAdmin); - } - - /** - * Checks if user is admin in any group - * - * @param mav ModelAndView for display - */ - public void setPermissionsToView(ModelAndView mav) { - // isAdmin - Person loggedUser = personDao.getLoggedPerson(); - if (loggedUser.getAuthority().equals("ROLE_ADMIN")) { - mav.addObject("userIsAdminInAnyGroup", true); - return; - } - // check all groups for admin role - Set researchGroupMemberShips = loggedUser.getResearchGroupMemberships(); - for (ResearchGroupMembership member : researchGroupMemberShips) { - if (auth.userIsAdminInGroup(member.getResearchGroup().getResearchGroupId())) { - mav.addObject("userIsAdminInAnyGroup", true); - return; - } - } - } - - private void createNode(XMLEventWriter eventWriter, String name, String value) { - try { - XMLEventFactory eventFactory = XMLEventFactory.newInstance(); - XMLEvent end = eventFactory.createDTD("\n"); - XMLEvent tab = eventFactory.createDTD("\t"); - // Create Start node - StartElement sElement = eventFactory.createStartElement("", "", name); - eventWriter.add(tab); - eventWriter.add(sElement); - // Create Content - Characters characters = eventFactory.createCharacters(value); - eventWriter.add(characters); - // Create End node - EndElement eElement = eventFactory.createEndElement("", "", name); - eventWriter.add(eElement); - eventWriter.add(end); - } catch (Exception e) { - } - } - - public ArticleDao getArticleDao() { - return articleDao; - } - - public void setArticleDao(ArticleDao articleDao) { - this.articleDao = articleDao; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } - - public ArticleCommentDao getArticleCommentDao() { - return articleCommentDao; - } - - public void setArticleCommentDao(ArticleCommentDao articleCommentDao) { - this.articleCommentDao = articleCommentDao; - } - - public ResearchGroupDao getResearchGroupDao() { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) { - this.researchGroupDao = researchGroupDao; - } - - public String getDomain() { - return domain; - } - - public void setDomain(String domain) { - this.domain = domain; - } - - public SimpleKeywordsDao getSimpleKeywordsDao() { - return simpleKeywordsDao; - } - - public void setSimpleKeywordsDao(SimpleKeywordsDao simpleKeywordsDao) { - this.simpleKeywordsDao = simpleKeywordsDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/Feed.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/Feed.java deleted file mode 100644 index 4b28edf8..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/Feed.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * Feed.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.article; - -import java.util.ArrayList; -import java.util.List; - -/** - * Created by IntelliJ IDEA. - * User: Jiri Vlasimsky (vlasimsky.jiri@gmail.com) - * Date: 25.5.11 - * Time: 20:59 - */ -/* - * Stores an RSS feed - */ -public class Feed { - - final String title; - final String link; - final String description; - final String language; - final String copyright; - final String pubDate; - final List entries = new ArrayList(); - - public Feed(String title, String link, String description, - String language, String copyright, String pubDate) { - this.title = title; - this.link = link; - this.description = description; - this.language = language; - this.copyright = copyright; - this.pubDate = pubDate; - } - - public List getMessages() { - return entries; - } - - public String getTitle() { - return title; - } - - public String getLink() { - return link; - } - - public String getDescription() { - return description; - } - - public String getLanguage() { - return language; - } - - public String getCopyright() { - return copyright; - } - - - public String getPubDate() { - return pubDate; - } - - @Override - public String toString() { - return "Feed [copyright=" + copyright + ", description=" + description - + ", language=" + language + ", link=" + link + ", pubDate=" - + pubDate + ", title=" + title + "]"; - } - - - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/FeedMessage.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/FeedMessage.java deleted file mode 100644 index e10407e0..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/FeedMessage.java +++ /dev/null @@ -1,81 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * FeedMessage.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.article; - -/** - * Created by IntelliJ IDEA. - * User: Jiri Vlasimsky (vlasimsky.jiri@gmail.com) - * Date: 25.5.11 - * Time: 20:58 - */ -/* - * Represents one RSS message - */ -public class FeedMessage { - - String title; - String description; - String link; - String author; - String guid; - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getLink() { - return link; - } - - public void setLink(String link) { - this.link = link; - } - - public String getAuthor() { - return author; - } - - public void setAuthor(String author) { - this.author = author; - } - - public String getGuid() { - return guid; - } - - public void setGuid(String guid) { - this.guid = guid; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/RSSFeedWriter.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/RSSFeedWriter.java deleted file mode 100644 index 382720eb..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/article/RSSFeedWriter.java +++ /dev/null @@ -1,149 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * RSSFeedWriter.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.article; - -import javax.xml.stream.XMLEventFactory; -import javax.xml.stream.XMLEventWriter; -import javax.xml.stream.XMLOutputFactory; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.events.*; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -public class RSSFeedWriter { - - private String outputFile; - private Feed rssfeed; - - public RSSFeedWriter(Feed rssfeed, String outputFile) { - this.rssfeed = rssfeed; - this.outputFile = outputFile; - } - - public String write() throws Exception { - - OutputStream output = new OutputStream() { - private StringBuilder string = new StringBuilder(); - - @Override - public void write(int b) throws IOException { - this.string.append((char) b); - } - - public String toString() { - return this.string.toString(); - } - }; - // Create a XMLOutputFactory - XMLOutputFactory outputFactory = XMLOutputFactory.newInstance(); - - // Create XMLEventWriter - XMLEventWriter eventWriter = outputFactory - .createXMLEventWriter(new FileOutputStream(outputFile)); - - - // Create a EventFactory - - XMLEventFactory eventFactory = XMLEventFactory.newInstance(); - XMLEvent end = eventFactory.createDTD(""); - - // Create and write Start Tag - - StartDocument startDocument = eventFactory.createStartDocument(); - - eventWriter.add(startDocument); - - // Create open tag - //eventWriter.add(end); - - StartElement rssStart = eventFactory.createStartElement("", "", "rss"); - eventWriter.add(rssStart); - eventWriter.add(eventFactory.createAttribute("version", "2.0")); - //eventWriter.add(end); - - eventWriter.add(eventFactory.createStartElement("", "", "channel")); - //eventWriter.add(end); - - // Write the different nodes - - createNode(eventWriter, "title", rssfeed.getTitle()); - - createNode(eventWriter, "link", rssfeed.getLink()); - - createNode(eventWriter, "description", rssfeed.getDescription()); - - createNode(eventWriter, "language", rssfeed.getLanguage()); - - createNode(eventWriter, "copyright", rssfeed.getCopyright()); - - createNode(eventWriter, "pubdate", rssfeed.getPubDate()); - - for (FeedMessage entry : rssfeed.getMessages()) { - eventWriter.add(eventFactory.createStartElement("", "", "item")); - //eventWriter.add(end); - createNode(eventWriter, "title", entry.getTitle()); - createNode(eventWriter, "description", entry.getDescription()); - createNode(eventWriter, "link", entry.getLink()); - createNode(eventWriter, "author", entry.getAuthor()); - createNode(eventWriter, "guid", entry.getGuid()); - //eventWriter.add(end); - eventWriter.add(eventFactory.createEndElement("", "", "item")); - //eventWriter.add(end); - - } - - //eventWriter.add(end); - eventWriter.add(eventFactory.createEndElement("", "", "channel")); - //eventWriter.add(end); - eventWriter.add(eventFactory.createEndElement("", "", "rss")); - - //eventWriter.add(end); - - eventWriter.add(eventFactory.createEndDocument()); - System.out.println(output); - - eventWriter.close(); - return output.toString(); - } - - private void createNode(XMLEventWriter eventWriter, String name, - - String value) throws XMLStreamException { - XMLEventFactory eventFactory = XMLEventFactory.newInstance(); - XMLEvent end = eventFactory.createDTD("\n"); - XMLEvent tab = eventFactory.createDTD("\t"); - // Create Start node - StartElement sElement = eventFactory.createStartElement("", "", name); - //eventWriter.add(tab); - eventWriter.add(sElement); - // Create Content - Characters characters = eventFactory.createCharacters(value); - eventWriter.add(characters); - // Create End node - EndElement eElement = eventFactory.createEndElement("", "", name); - eventWriter.add(eElement); - //eventWriter.add(end); - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddDataFileCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddDataFileCommand.java deleted file mode 100644 index 3a85aedd..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddDataFileCommand.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddDataFileCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.experiment; - -import org.springframework.web.multipart.MultipartFile; - -/** - * @author JiPER - */ -public class AddDataFileCommand { - - private int measurationId; - private String description; - private MultipartFile dataFile; - - public int getMeasurationId() { - return measurationId; - } - - public void setMeasurationId(int measurationId) { - this.measurationId = measurationId; - } - - public MultipartFile getDataFile() { - return dataFile; - } - - public void setDataFile(MultipartFile dataFile) { - this.dataFile = dataFile; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddDataFileController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddDataFileController.java deleted file mode 100644 index 502f139b..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddDataFileController.java +++ /dev/null @@ -1,209 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddDataFileController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.experiment; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.GenericDao; -import cz.zcu.kiv.eegdatabase.data.pojo.DataFile; -import cz.zcu.kiv.eegdatabase.data.pojo.Experiment; -import cz.zcu.kiv.eegdatabase.logic.util.SignalProcessingUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.Hibernate; -import org.springframework.validation.BindException; -import org.springframework.validation.Errors; -import org.springframework.validation.Validator; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.multipart.MultipartHttpServletRequest; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.ByteArrayInputStream; -import java.util.Map; -import java.util.Set; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; -import org.apache.commons.io.IOUtils; - -/** - * Controller for adding data file to database - * - * @author Jindra - */ -public class AddDataFileController - extends SimpleFormController - implements Validator { - - private static final String PARAM_ID = "experimentId"; - private AuthorizationManager auth; - private Log log = LogFactory.getLog(getClass()); - private GenericDao dataFileDao; - private static final int MAX_MIMETYPE_LENGTH = 40; - - public AddDataFileController() { - setCommandClass(AddDataFileCommand.class); - setCommandName("addData"); - } - - @Override - protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception { - ModelAndView mav = super.showForm(request, response, errors); - - mav.addObject("userIsExperimenter", auth.userIsExperimenter()); - return mav; - } - - /** - * Setting the measuratioId value into the form - */ - @Override - protected Object formBackingObject(HttpServletRequest request) throws Exception { - AddDataFileCommand adc = (AddDataFileCommand) super.formBackingObject(request); - String measurationId = request.getParameter(PARAM_ID); - if (measurationId != null) { - adc.setMeasurationId(Integer.parseInt(measurationId)); - } - return adc; - } - - /** - * Processing of the valid form - */ - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception { - log.debug("Processing form data."); - AddDataFileCommand addDataCommand = (AddDataFileCommand) command; - MultipartHttpServletRequest mpRequest = (MultipartHttpServletRequest) request; - // the map containing file names mapped to files - Map m = mpRequest.getFileMap(); - Set set = m.keySet(); - for (Object key : set) { - MultipartFile file = (MultipartFile) m.get(key); - - if (file == null) { - log.error("No file was uploaded!"); - } else { - log.debug("Creating measuration with ID " + addDataCommand.getMeasurationId()); - Experiment experiment = new Experiment(); - experiment.setExperimentId(addDataCommand.getMeasurationId()); - if (file.getOriginalFilename().endsWith(".zip")) { - ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(file.getBytes())); - ZipEntry en = zis.getNextEntry(); - while (en != null) { - if (en.isDirectory()) { - en = zis.getNextEntry(); - continue; - } - DataFile data = new DataFile(); - data.setExperiment(experiment); - String name[] = en.getName().split("/"); - data.setFilename(name[name.length - 1]); - data.setDescription(addDataCommand.getDescription()); - data.setFileContent(Hibernate.createBlob(zis)); - String[] partOfName = en.getName().split("[.]"); - data.setMimetype(partOfName[partOfName.length - 1]); - dataFileDao.create(data); - en = zis.getNextEntry(); - } - } else { - log.debug("Creating new Data object."); - DataFile data = new DataFile(); - data.setExperiment(experiment); - - log.debug("Original name of uploaded file: " + file.getOriginalFilename()); - String filename = file.getOriginalFilename().replace(" ", "_"); - data.setFilename(filename); - - log.debug("MIME type of the uploaded file: " + file.getContentType()); - if (file.getContentType().length() > MAX_MIMETYPE_LENGTH) { - int index = filename.lastIndexOf("."); - data.setMimetype(filename.substring(index)); - } else { - data.setMimetype(file.getContentType()); - } - - log.debug("Parsing the sapmling rate."); - data.setDescription(addDataCommand.getDescription()); - - log.debug("Setting the binary data to object."); - data.setFileContent(Hibernate.createBlob(file.getBytes())); - - dataFileDao.create(data); - log.debug("Data stored into database."); - } - } - } - - log.debug("Returning MAV"); - ModelAndView mav = new ModelAndView("redirect:/experiments/detail.html?experimentId=" + addDataCommand.getMeasurationId()); - return mav; - } - - public boolean supports(Class clazz) { - return clazz.equals(AddDataFileCommand.class); - } - - public void validate(Object command, Errors errors) { - AddDataFileCommand data = (AddDataFileCommand) command; - - // First check the permission - if ((!auth.userIsOwnerOrCoexperimenter(data.getMeasurationId())) && (!auth.isAdmin())) { - errors.reject("error.mustBeOwnerOfExperimentOrCoexperimenter"); - } else { - - if (data.getMeasurationId() == 0) { - log.debug("Measuration ID not inserted!"); - } else { - log.debug("Measuration ID is present."); - } - - // ValidationUtils.rejectIfEmptyOrWhitespace(errors, "samplingRate", "required.samplingRate"); - - - if (data.getDataFile().isEmpty()) { - errors.rejectValue("dataFile", "required.dataFile"); - log.debug("No data file was inserted!"); - } - } - - } - - public GenericDao getDataFileDao() { - return dataFileDao; - } - - public void setDataFileDao(GenericDao dataFileDao) { - this.dataFileDao = dataFileDao; - - } - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentCommand.java deleted file mode 100644 index a22d5ad0..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentCommand.java +++ /dev/null @@ -1,165 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddExperimentCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.experiment; - -/** - * @author JiPER - */ -public class AddExperimentCommand { - - private int measurationId; - private int researchGroup; - private String researchGroupTitle; - private String startDate; - private String startTime; - private String endDate; - private String endTime; - private int subjectPerson; - private int[] coExperimenters; - private int scenario; - private int[] hardware; - private int weather; - private String weatherNote; - private String temperature; - private boolean privateNote; - - public int getResearchGroup() { - return researchGroup; - } - - public void setResearchGroup(int researchGroup) { - this.researchGroup = researchGroup; - } - - public String getEndDate() { - return endDate; - } - - public void setEndDate(String endDate) { - this.endDate = endDate; - } - - public String getEndTime() { - return endTime; - } - - public void setEndTime(String endTime) { - this.endTime = endTime; - } - - public int[] getCoExperimenters() { - return coExperimenters; - } - - public void setCoExperimenters(int[] coExperimenters) { - this.coExperimenters = coExperimenters; - } - - public int[] getHardware() { - return hardware; - } - - public void setHardware(int[] hardware) { - this.hardware = hardware; - } - - public int getMeasurationId() { - return measurationId; - } - - public void setMeasurationId(int measurationId) { - this.measurationId = measurationId; - } - - public int getSubjectPerson() { - return subjectPerson; - } - - public void setSubjectPerson(int subjectPerson) { - this.subjectPerson = subjectPerson; - } - - public int getScenario() { - return scenario; - } - - public void setScenario(int scenario) { - this.scenario = scenario; - } - - public String getStartDate() { - return startDate; - } - - public void setStartDate(String startDate) { - this.startDate = startDate; - } - - public String getStartTime() { - return startTime; - } - - public void setStartTime(String startTime) { - this.startTime = startTime; - } - - public String getTemperature() { - return temperature; - } - - public void setPrivateNote(boolean privateNote) { - this.privateNote = privateNote; - } - - public boolean isPrivateNote() { - return privateNote; - } - - public void setTemperature(String temperature) { - this.temperature = temperature; - } - - public int getWeather() { - return weather; - } - - public void setWeather(int weather) { - this.weather = weather; - } - - public String getWeatherNote() { - return weatherNote; - } - - public void setWeatherNote(String weatherNote) { - this.weatherNote = weatherNote; - } - - public String getResearchGroupTitle() { - return researchGroupTitle; - } - - public void setResearchGroupTitle(String researchGroupTitle) { - this.researchGroupTitle = researchGroupTitle; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentController.java deleted file mode 100644 index 9e232605..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentController.java +++ /dev/null @@ -1,407 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddExperimentController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.experiment; - -import cz.zcu.kiv.eegdatabase.data.dao.*; -import cz.zcu.kiv.eegdatabase.data.pojo.*; -import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.*; - -import java.sql.Timestamp; -import java.util.Date; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -/** - * Controller which processes form for adding experiment. - * - * @author Jindra - */ -@Controller -@SessionAttributes("addMeasuration") -public class AddExperimentController { - private Log log = LogFactory.getLog(getClass()); - @Autowired - @Qualifier("experimentDao") - private GenericDao experimentDao; - @Autowired - private PersonDao personDao; - @Autowired - private ScenarioDao scenarioDao; - @Autowired - private HardwareDao hardwareDao; - @Autowired - private WeatherDao weatherDao; - @Autowired - private ResearchGroupDao researchGroupDao; - @Autowired - private AuthorizationManager auth; - private AddExperimentValidator addExperimentValidator; - - @Autowired - public AddExperimentController(AddExperimentValidator addExperimentValidator){ - this.addExperimentValidator = addExperimentValidator; - } - - /**@RequestMapping(value="experiments/add-experiment.html",method= RequestMethod.GET) - protected String showAddForm(ModelMap model) { - if (!auth.userIsExperimenter()) { - return "experiments/userNotExperimenter"; - } - model.addAttribute("userIsExperimenter", auth.userIsExperimenter()); - AddExperimentCommand data = new AddExperimentCommand(); - - model.addAttribute("addMeasuration",data); - return "experiments/addExperimentForm"; - } */ - - @RequestMapping(value="experiments/edit.html",method= RequestMethod.GET) - protected String showEditForm(@RequestParam("id") String measurationIdString, ModelMap model) { - if (!auth.userIsExperimenter()) { - return "experiments/userNotExperimenter"; - } - model.addAttribute("userIsExperimenter", auth.userIsExperimenter()); - AddExperimentCommand data = new AddExperimentCommand(); - if (measurationIdString != null) { // it is a form for editing - int measurationId = Integer.parseInt(measurationIdString); - - log.debug("Filling backing object with data from measuration object #" + measurationId); - data.setMeasurationId(measurationId); - Experiment measuration = experimentDao.read(measurationId); - - String startDate = ControllerUtils.getDateFormat().format(measuration.getStartTime()); - log.debug("Setting start date = " + startDate); - data.setStartDate(startDate); - - String startTime = ControllerUtils.getTimeFormat().format(measuration.getStartTime()); - log.debug("Setting start time = " + startTime); - data.setStartTime(startTime); - - String endDate = ControllerUtils.getDateFormat().format(measuration.getEndTime()); - log.debug("Setting start date = " + endDate); - data.setEndDate(endDate); - - String endTime = ControllerUtils.getTimeFormat().format(measuration.getEndTime()); - log.debug("Setting start time = " + endTime); - data.setEndTime(endTime); - - log.debug("Setting measured person = " + measuration.getPersonBySubjectPersonId().getPersonId()); - data.setSubjectPerson(measuration.getPersonBySubjectPersonId().getPersonId()); - - log.debug("Setting coExperimenters - count of selected coExperimenters: " + measuration.getPersons().size()); - int[] coExperimentersArray = new int[measuration.getPersons().size()]; - int i = 0; - for (Person experimenter : measuration.getPersons()) { - log.debug("Adding selected experimenter #" + experimenter.getPersonId()); - coExperimentersArray[i++] = experimenter.getPersonId(); - } - data.setCoExperimenters(coExperimentersArray); - - log.debug("Setting selected scenario = " + measuration.getScenario().getScenarioId()); - data.setScenario(measuration.getScenario().getScenarioId()); - - log.debug("Setting list of used hardware - count of selected pieces of hardware: " + measuration.getHardwares().size()); - int[] hardwareArray = new int[measuration.getHardwares().size()]; - int j = 0; - for (Hardware hardware : measuration.getHardwares()) { - log.debug("Adding selected hardware #" + hardware.getHardwareId()); - hardwareArray[j++] = hardware.getHardwareId(); - } - data.setHardware(hardwareArray); - - log.debug("Setting selected weather #" + measuration.getWeather().getWeatherId()); - data.setWeather(measuration.getWeather().getWeatherId()); - - log.debug("Setting weather note = " + measuration.getEnvironmentNote()); - data.setWeatherNote(measuration.getEnvironmentNote()); - - log.debug("Setting temperature = " + measuration.getTemperature()); - data.setTemperature("" + measuration.getTemperature()); - - data.setPrivateNote(measuration.isPrivateExperiment()); - } - model.addAttribute("addMeasuration", data); - return "experiments/addExperimentForm"; - } - - @ModelAttribute("personList") - private List populatePersonList(){ - List personList = personDao.getAllRecords(); - return personList; - } - - @ModelAttribute("scenarioList") - private List populateScenarioList(){ - List scenarioList = scenarioDao.getAllRecords(); - return scenarioList; - } - - @ModelAttribute("hardwareList") - private List populateHardwareList(@RequestParam("id") String idString){ - int experimentId = 0; - if(idString!=null){ - experimentId = Integer.parseInt(idString) ; - } - int groupId = experimentDao.read(experimentId).getResearchGroup().getResearchGroupId(); - List list = hardwareDao.getRecordsByGroup(groupId); - return list; - } - - @ModelAttribute("weatherList") - private List populateWeatherList(@RequestParam("id") String idString){ - int experimentId = 0; - if(idString!=null){ - experimentId = Integer.parseInt(idString) ; - } - int groupId = experimentDao.read(experimentId).getResearchGroup().getResearchGroupId(); - List list = weatherDao.getRecordsByGroup(groupId); - return list; - } - - @ModelAttribute("researchGroupList") - private List populateResearchGroupList(){ - List researchGroupList = researchGroupDao.getResearchGroupsWhereAbleToWriteInto(personDao.getLoggedPerson()); - return researchGroupList; - } - - @ModelAttribute("defaultGroupId") - private int populateDefaultGroupId(){ - ResearchGroup defaultGroup = personDao.getLoggedPerson().getDefaultGroup(); - int defaultGroupId = (defaultGroup != null) ? defaultGroup.getResearchGroupId() : 0; - return defaultGroupId; - } - - @ModelAttribute("researchGroupTitle") - private String fillResearchGroupTitleForExperiment(@RequestParam("id") String idString){ - log.debug("Loading experiment info"); - int experimentId = Integer.parseInt(idString); - Experiment experiment = (Experiment) experimentDao.read(experimentId); - return experiment.getResearchGroup().getTitle(); - } - - @RequestMapping(method=RequestMethod.POST) - protected String onSubmit(@ModelAttribute("addMeasuration") AddExperimentCommand data, BindingResult result, ModelMap model) throws Exception{ - addExperimentValidator.validate(data, result); - if (result.hasErrors()) { - return "experiments/addExperimentForm"; - } - - model.addAttribute("userIsExperimenter", (auth.userIsExperimenter()) || (auth.isAdmin())); - - Experiment experiment; - - boolean editing = data.getMeasurationId() > 0; - - if (editing) { - // This is the editation of experiment - log.debug("Processing measuration form - editing existing measuration"); - - log.debug("Checking the permission level."); - if ((!auth.userIsOwnerOrCoexperimenter(data.getMeasurationId()))&&(!auth.isAdmin())) { - log.debug("User is not owner or co-experimenter - unable to edit experiment. Returning MAV."); - return "experiments/unableToEditExperiment"; - } - - log.debug("Loading existing measuration object"); - experiment = experimentDao.read(data.getMeasurationId()); - - log.debug("Removing edited experiment from hardwares"); - for (Hardware hardware : experiment.getHardwares()) { - hardware.getExperiments().remove(experiment); - } - - log.debug("Removing edited experiment from persons (coexperimenters)"); - for (Person person : experiment.getPersons()) { - person.getExperiments().remove(experiment); - } - - } else { - // This is creating of new experiment - log.debug("Processing measuration form - adding new measuration"); - - log.debug("Checking the permission level."); - if ((!auth.userIsExperimenter())) { - log.debug("User is not experimenter - unable to add experiment. Returning MAV."); - return "experiments/userNotExperimenter"; - } - - log.debug("Creating new Measuration object"); - experiment = new Experiment(); - - // This assignment is commited only when new experiment is being created - log.debug("Setting the owner to the logged user."); - experiment.setPersonByOwnerId(personDao.getLoggedPerson()); - - log.debug("Setting the group, which is the new experiment being added into."); - ResearchGroup researchGroup = new ResearchGroup(); - researchGroup.setResearchGroupId(data.getResearchGroup()); - experiment.setResearchGroup(researchGroup); - - - } - - log.debug("Setting Weather object - ID " + data.getWeather()); - Weather weather = new Weather(); - weather.setWeatherId(data.getWeather()); - experiment.setWeather(weather); - - log.debug("Setting Scenario object - ID " + data.getScenario()); - Scenario scenario = new Scenario(); - scenario.setScenarioId(data.getScenario()); - experiment.setScenario(scenario); - - log.debug("Setting Person object (measured person) - ID " + data.getSubjectPerson()); - Person subjectPerson = new Person(); - subjectPerson.setPersonId(data.getSubjectPerson()); - experiment.setPersonBySubjectPersonId(subjectPerson); - - Date startDate = ControllerUtils.getDateFormatWithTime().parse(data.getStartDate() + " " + data.getStartTime()); - experiment.setStartTime(new Timestamp(startDate.getTime())); - log.debug("Setting start date - " + startDate); - - Date endDate = ControllerUtils.getDateFormatWithTime().parse(data.getEndDate() + " " + data.getEndTime()); - experiment.setEndTime(new Timestamp(endDate.getTime())); - log.debug("Setting end date - " + endDate); - - log.debug("Setting the temperature - " + data.getTemperature()); - experiment.setTemperature(Integer.parseInt(data.getTemperature())); - - log.debug("Setting the weather note - " + data.getWeatherNote()); - experiment.setEnvironmentNote(data.getWeatherNote()); - - log.debug("Started setting the Hardware objects"); - int[] hardwareArray = data.getHardware(); - Set hardwareSet = new HashSet(); - for (int hardwareId : hardwareArray) { - Hardware tempHardware = hardwareDao.read(hardwareId); - hardwareSet.add(tempHardware); - tempHardware.getExperiments().add(experiment); - log.debug("Added Hardware object - ID " + hardwareId); - } - log.debug("Setting Hardware list to Measuration object"); - experiment.setHardwares(hardwareSet); - - log.debug("Started setting the Person objects (coExperimenters)"); - int[] coExperimentersArray = data.getCoExperimenters(); - Set coExperimenterSet = new HashSet(); - for (int personId : coExperimentersArray) { - Person tempExperimenter = personDao.read(personId); - coExperimenterSet.add(tempExperimenter); - tempExperimenter.getExperiments().add(experiment); - log.debug("Added Person object - ID " + tempExperimenter.getPersonId()); - } - log.debug("Setting Person list to Measuration object"); - experiment.setPersons(coExperimenterSet); - - log.debug("Setting private/public access"); - experiment.setPrivateExperiment(data.isPrivateNote()); - - if (data.getMeasurationId() > 0) { // editing existing measuration - log.debug("Saving the Measuration object to database using DAO - update()"); - experimentDao.update(experiment); - } else { // creating new measuration - log.debug("Saving the Measuration object to database using DAO - create()"); - experimentDao.create(experiment); - } - String redirect = "redirect:/experiments/detail.html?experimentId="+experiment.getExperimentId(); - return redirect; - } - - public boolean supports(Class clazz) { - return clazz.equals(AddExperimentCommand.class); - } - - - public GenericDao getExperimentDao() { - return experimentDao; - } - - public void setExperimentDao(GenericDao experimentDao) { - this.experimentDao = experimentDao; - } - - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public ScenarioDao getScenarioDao() { - return scenarioDao; - } - - public void setScenarioDao(ScenarioDao scenarioDao) { - this.scenarioDao = scenarioDao; - } - - public HardwareDao getHardwareDao() { - return hardwareDao; - } - - public void setHardwareDao(HardwareDao hardwareDao) { - this.hardwareDao = hardwareDao; - } - - public WeatherDao getWeatherDao() { - return weatherDao; - } - - public void setWeatherDao(WeatherDao weatherDao) { - this.weatherDao = weatherDao; - } - - public AddExperimentValidator getAddExperimentValidator() { - return addExperimentValidator; - } - - public void setAddExperimentValidator(AddExperimentValidator addExperimentValidator) { - this.addExperimentValidator = addExperimentValidator; - } - - public ResearchGroupDao getResearchGroupDao() { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) { - this.researchGroupDao = researchGroupDao; - } - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentOptParamValCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentOptParamValCommand.java deleted file mode 100644 index 37082085..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentOptParamValCommand.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddExperimentOptParamValCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.experiment; - -/** - * @author Jindra - */ -public class AddExperimentOptParamValCommand { - - private int measurationFormId; - private int paramId; - private String paramValue; - private String researchGroupTitle; - - public int getMeasurationFormId() { - return measurationFormId; - } - - public void setMeasurationFormId(int measurationFormId) { - this.measurationFormId = measurationFormId; - } - - public int getParamId() { - return paramId; - } - - public void setParamId(int paramId) { - this.paramId = paramId; - } - - public String getParamValue() { - return paramValue; - } - - public void setParamValue(String paramValue) { - this.paramValue = paramValue; - } - - public String getResearchGroupTitle() { - return researchGroupTitle; - } - - public void setResearchGroupTitle(String researchGroupTitle) { - this.researchGroupTitle = researchGroupTitle; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentOptParamValController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentOptParamValController.java deleted file mode 100644 index 6b4f60d7..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentOptParamValController.java +++ /dev/null @@ -1,174 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddExperimentOptParamValController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.experiment; - -import cz.zcu.kiv.eegdatabase.data.dao.*; -import cz.zcu.kiv.eegdatabase.data.pojo.*; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.*; -import java.util.ArrayList; -import java.util.List; - -/** - * @author František Liška - */ -@Controller -@SessionAttributes("addMeasurationAdditionalParameter") -public class AddExperimentOptParamValController{ - private Log log = LogFactory.getLog(getClass()); - @Autowired - private AuthorizationManager auth; - @Autowired - private PersonDao personDao; - @Autowired - private ResearchGroupDao researchGroupDao; - @Autowired - private ExperimentDao experimentDao; - @Autowired - @Qualifier("experimentOptParamValDao") - private GenericDao experimentOptParamValDao; - @Autowired - private ExperimentOptParamDefDao experimentOptParamDefDao; - - private AddExperimentOptParamValValidator addExperimentOptParamValValidator; - - @Autowired - public AddExperimentOptParamValController(AddExperimentOptParamValValidator addExperimentOptParamValValidator){ - this.addExperimentOptParamValValidator = addExperimentOptParamValValidator; - } - - - @RequestMapping(value="experiments/add-optional-parameter.html",method= RequestMethod.GET) - protected String showForm(ModelMap model){ - log.debug("Preparing data for form"); - AddExperimentOptParamValCommand data = new AddExperimentOptParamValCommand(); - model.addAttribute("userIsExperimenter", auth.userIsExperimenter()); - model.addAttribute("addMeasurationAdditionalParameter", data); - return "experiments/optionalParams/addItemForm"; - - } - - @RequestMapping(method=RequestMethod.POST) - protected String onSubmit(@ModelAttribute("addMeasurationAdditionalParameter") AddExperimentOptParamValCommand data, BindingResult result){ - addExperimentOptParamValValidator.validate(data, result); - if (result.hasErrors()) { - return "experiments/optionalParams/addItemForm"; - } - - log.debug("Processing form data."); - - log.debug("Creating new object"); - ExperimentOptParamVal val = new ExperimentOptParamVal(); - val.setId(new ExperimentOptParamValId(data.getMeasurationFormId(), data.getParamId())); - val.setParamValue(data.getParamValue()); - - log.debug("Saving object to database"); - experimentOptParamValDao.create(val); - - String redirect = "redirect:/experiments/detail.html?experimentId="+data.getMeasurationFormId(); - return redirect; - } - - @ModelAttribute("measurationAdditionalParams") - protected List populateOptParamList(@RequestParam("experimentId") String idString){ - log.debug("Loading parameter list for select box"); - List list = new ArrayList(); - Person loggedUser = personDao.getLoggedPerson(); - if(loggedUser.getAuthority().equals("ROLE_ADMIN")){ - list.addAll(experimentOptParamDefDao.getAllRecords()); - }else{ - int experimentId = 0; - if(idString!=null){ - experimentId = Integer.parseInt(idString) ; - } - Experiment e = (Experiment)experimentDao.read(experimentId); - int groupId = e.getResearchGroup().getResearchGroupId(); - return experimentOptParamDefDao.getRecordsByGroup(groupId); - } - - return list; - } - - @ModelAttribute("measurationDetail") - private Experiment populateExperimentDetail(@RequestParam("experimentId") String idString){ - log.debug("Loading experiment info"); - int experimentId = Integer.parseInt(idString); - Experiment experiment = (Experiment) experimentDao.read(experimentId); - return experiment; - } - - @ModelAttribute("researchGroupTitle") - private String fillResearchGroupTitleForExperiment(@RequestParam("experimentId") String idString){ - log.debug("Loading experiment info"); - int experimentId = Integer.parseInt(idString); - Experiment experiment = (Experiment) experimentDao.read(experimentId); - return experiment.getResearchGroup().getTitle(); - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public ResearchGroupDao getResearchGroupDao() { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) { - this.researchGroupDao = researchGroupDao; - } - - public GenericDao getExperimentOptParamValDao() { - return experimentOptParamValDao; - } - - public void setExperimentOptParamValDao(GenericDao experimentOptParamValDao) { - this.experimentOptParamValDao = experimentOptParamValDao; - } - - public ExperimentOptParamDefDao getExperimentOptParamDefDao() { - return experimentOptParamDefDao; - } - - public void setExperimentOptParamDefDao(ExperimentOptParamDefDao experimentOptParamDefDao) { - this.experimentOptParamDefDao = experimentOptParamDefDao; - } - - public AddExperimentOptParamValValidator getAddExperimentOptParamValValidator() { - return addExperimentOptParamValValidator; - } - - public void setAddExperimentOptParamValValidator(AddExperimentOptParamValValidator addExperimentOptParamValValidator) { - this.addExperimentOptParamValValidator = addExperimentOptParamValValidator; - } -} - diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentOptParamValValidator.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentOptParamValValidator.java deleted file mode 100644 index 351dde36..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentOptParamValValidator.java +++ /dev/null @@ -1,90 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddExperimentOptParamValValidator.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.experiment; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.GenericDao; -import cz.zcu.kiv.eegdatabase.data.pojo.*; -import cz.zcu.kiv.eegdatabase.logic.controller.person.AddPersonAdditionalParamValueCommand; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -/** - * @author František Liška - */ -public class AddExperimentOptParamValValidator implements Validator { - @Autowired - private AuthorizationManager auth; - private Log log = LogFactory.getLog(getClass()); - @Autowired - @Qualifier("experimentOptParamValDao") - private GenericDao experimentOptParamValDao; - - public boolean supports(Class clazz) { - return clazz.equals(AddExperimentOptParamValCommand.class); - } - - public void validate(Object command, Errors errors) { - AddExperimentOptParamValCommand data = (AddExperimentOptParamValCommand) command; - - if ((!auth.userIsOwnerOrCoexperimenter(data.getMeasurationFormId()))&&(!auth.isAdmin())) { - // First check whether the user has permission to add data - errors.reject("error.mustBeOwnerOfExperimentOrCoexperimenter"); - } else { - - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "paramValue", "required.field"); - - if (data.getParamId() < 0) { - errors.rejectValue("paramId", "required.field"); - } - - ExperimentOptParamVal val = experimentOptParamValDao.read(new ExperimentOptParamValId(data.getMeasurationFormId(), data.getParamId())); - if (val != null) { // field already exists - errors.rejectValue("paramId", "invalid.paramIdAlreadyInserted"); - } - - } - - } - - public GenericDao getExperimentOptParamValDao() { - return experimentOptParamValDao; - } - - public void setExperimentOptParamValDao(GenericDao experimentOptParamValDao) { - this.experimentOptParamValDao = experimentOptParamValDao; - } - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentValidator.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentValidator.java deleted file mode 100644 index c7e5a539..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentValidator.java +++ /dev/null @@ -1,133 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddExperimentValidator.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.experiment; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.GenericDao; -import cz.zcu.kiv.eegdatabase.data.pojo.ExperimentOptParamVal; -import cz.zcu.kiv.eegdatabase.data.pojo.ExperimentOptParamValId; -import cz.zcu.kiv.eegdatabase.logic.controller.person.AddPersonAdditionalParamValueCommand; -import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -import java.text.ParseException; - -/** - * @author František Liška - */ -public class AddExperimentValidator implements Validator { - @Autowired - private AuthorizationManager auth; - private Log log = LogFactory.getLog(getClass()); - - public boolean supports(Class clazz) { - return clazz.equals(AddExperimentCommand.class); - } - - public void validate(Object command, Errors errors) { - AddExperimentCommand data = (AddExperimentCommand) command; - - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "startDate", "required.date"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "startTime", "required.time"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "endDate", "required.date"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "endTime", "required.time"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "temperature", "required.field"); - - if (data.getMeasurationId() > 0) { - // Edit of existing experiment - // No special actions yet - } else { - // Creating new experiment - if (data.getResearchGroup() == -1) { - // research group not chosen - errors.rejectValue("researchGroup", "required.researchGroup"); - } else if (!auth.personAbleToWriteIntoGroup(data.getResearchGroup())) { - errors.rejectValue("researchGroup", "invalid.notAbleToAddExperimentInGroup"); - } - } - - if (data.getSubjectPerson() == -1) { // measured person not chosen - errors.rejectValue("subjectPerson", "required.subjectPerson"); - } - - if (data.getScenario() == -1) { // scenario not selected - errors.rejectValue("scenario", "required.scenario"); - } - - if (data.getHardware().length == 0) { // no hardware selected - errors.rejectValue("hardware", "required.hardware"); - } - - if (data.getWeather() == -1) { // weather not selected - errors.rejectValue("weather", "required.weather"); - } - - try { - ControllerUtils.getDateFormat().parse(data.getStartDate()); - } catch (ParseException ex) { - errors.rejectValue("startDate", "invalid.date"); - } - - try { - ControllerUtils.getDateFormat().parse(data.getEndDate()); - } catch (ParseException ex) { - errors.rejectValue("endDate", "invalid.date"); - } - - try { - ControllerUtils.getTimeFormat().parse(data.getStartTime()); - } catch (ParseException ex) { - errors.rejectValue("startTime", "invalid.time"); - } - - try { - ControllerUtils.getTimeFormat().parse(data.getEndTime()); - } catch (ParseException ex) { - errors.rejectValue("endTime", "invalid.time"); - } - - try { - int temp = Integer.parseInt(data.getTemperature()); - if (temp < -273) { - errors.rejectValue("temperature", "invalid.minTemp"); - } - } catch (NumberFormatException e) { - errors.rejectValue("temperature", "invalid.temperature"); - } - - } - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentWizardCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentWizardCommand.java deleted file mode 100644 index 626bdcde..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentWizardCommand.java +++ /dev/null @@ -1,208 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddExperimentWizardCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.experiment; - -import org.springframework.web.multipart.MultipartFile; - -/** - * Object command for saving experiment from wizard - * User: pbruha - * Date: 10.3.11 - * Time: 19:18 - * To change this template use File | Settings | File Templates. - */ -public class AddExperimentWizardCommand { - private int measurationId; - private int researchGroup; - private String startDate; - private String startTime; - private String endDate; - private String endTime; - private int subjectPerson; - private int[] coExperimenters; - private int scenario; - private int[] hardware; - private int weather; - private String samplingRate; - private String weatherNote; - private String temperature; - private boolean privateNote; - - private String fileDescription; - private MultipartFile dataFile; - - private String title; - private String description; - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public int getResearchGroup() { - return researchGroup; - } - - public void setResearchGroup(int researchGroup) { - this.researchGroup = researchGroup; - } - - public String getEndDate() { - return endDate; - } - - public void setEndDate(String endDate) { - this.endDate = endDate; - } - - public String getEndTime() { - return endTime; - } - - public void setEndTime(String endTime) { - this.endTime = endTime; - } - - public int[] getCoExperimenters() { - return coExperimenters; - } - - public void setCoExperimenters(int[] coExperimenters) { - this.coExperimenters = coExperimenters; - } - - public int[] getHardware() { - return hardware; - } - - public void setHardware(int[] hardware) { - this.hardware = hardware; - } - - public int getSubjectPerson() { - return subjectPerson; - } - - public void setSubjectPerson(int subjectPerson) { - this.subjectPerson = subjectPerson; - } - - public int getScenario() { - return scenario; - } - - public void setScenario(int scenario) { - this.scenario = scenario; - } - - public String getStartDate() { - return startDate; - } - - public void setStartDate(String startDate) { - this.startDate = startDate; - } - - public String getStartTime() { - return startTime; - } - - public void setStartTime(String startTime) { - this.startTime = startTime; - } - - public String getTemperature() { - return temperature; - } - - public void setPrivateNote(boolean privateNote) { - this.privateNote = privateNote; - } - - public boolean isPrivateNote() { - return privateNote; - } - - public void setTemperature(String temperature) { - this.temperature = temperature; - } - - public int getWeather() { - return weather; - } - - public void setWeather(int weather) { - this.weather = weather; - } - - public String getWeatherNote() { - return weatherNote; - } - - public void setWeatherNote(String weatherNote) { - this.weatherNote = weatherNote; - } - - public int getMeasurationId() { - return measurationId; - } - - public void setMeasurationId(int measurationId) { - this.measurationId = measurationId; - } - - public MultipartFile getDataFile() { - return dataFile; - } - - public void setDataFile(MultipartFile dataFile) { - this.dataFile = dataFile; - } - - public String getFileDescription() { - return fileDescription; - } - - public void setFileDescription(String fileDescription) { - this.fileDescription = fileDescription; - } - - public String getSamplingRate() { - return samplingRate; - } - - public void setSamplingRate(String samplingRate) { - this.samplingRate = samplingRate; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentWizardController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentWizardController.java deleted file mode 100644 index 4663a5b0..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddExperimentWizardController.java +++ /dev/null @@ -1,603 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddExperimentWizardController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.experiment; - -import cz.zcu.kiv.eegdatabase.data.dao.*; -import cz.zcu.kiv.eegdatabase.data.pojo.*; -import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; -import cz.zcu.kiv.eegdatabase.logic.util.SignalProcessingUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.Hibernate; -import org.springframework.validation.BindException; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.multipart.MultipartHttpServletRequest; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.AbstractWizardFormController; -import org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.ByteArrayInputStream; -import java.sql.Timestamp; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.*; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - -/** - * Wizard for adding experiments - * User: pbruha - * Date: 10.3.11 - * Time: 13:38 - */ -public class AddExperimentWizardController extends AbstractWizardFormController { - - private Log log = LogFactory.getLog(getClass()); - private GenericDao experimentDao; - private ScenarioSchemasDao scenarioSchemasDao; - private PersonDao personDao; - private ScenarioDao scenarioDao; - private HardwareDao hardwareDao; - private WeatherDao weatherDao; - private ResearchGroupDao researchGroupDao; - private AuthorizationManager auth; - private DigitizationDao digitizationDao; - private ParameterMethodNameResolver methodNameResolver; - private GenericDao dataFileDao; - private GenericListDao artifactDao; - private GenericDao electrodeConfDao; - private GenericDao subjectGroupDao; - private static final int MAX_MIMETYPE_LENGTH = 40; - - public ParameterMethodNameResolver getMethodNameResolver() { - return methodNameResolver; - } - - public void setMethodNameResolver(ParameterMethodNameResolver methodNameResolver) { - this.methodNameResolver = methodNameResolver; - } - - public AddExperimentWizardController() { - setCommandClass(AddExperimentWizardCommand.class); - setCommandName("addExperimentWizard"); - } - - @Override - protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception { - ModelAndView mav = super.showForm(request, response, errors); - if (!auth.userIsExperimenter()) { - mav.setViewName("redirect:experiments/userNotExperimenter"); - } - mav.addObject("userIsExperimenter", auth.userIsExperimenter()); - return mav; - } - - @Override - protected Object formBackingObject(HttpServletRequest request) - throws Exception { - - AddExperimentWizardCommand addExperimentWizardCommand = (AddExperimentWizardCommand) super.formBackingObject(request); - - - String measurationIdString = request.getParameter("id"); - if (measurationIdString != null) { // it is a form for editing - int measurationId = Integer.parseInt(measurationIdString); - - log.debug("Filling backing object with data from measuration object #" + measurationId); - addExperimentWizardCommand.setMeasurationId(measurationId); - Experiment measuration = experimentDao.read(measurationId); - - String startDate = ControllerUtils.getDateFormat().format(measuration.getStartTime()); - log.debug("Setting start date = " + startDate); - addExperimentWizardCommand.setStartDate(startDate); - - String startTime = ControllerUtils.getTimeFormat().format(measuration.getStartTime()); - log.debug("Setting start time = " + startTime); - addExperimentWizardCommand.setStartTime(startTime); - - String endDate = ControllerUtils.getDateFormat().format(measuration.getEndTime()); - log.debug("Setting start date = " + endDate); - addExperimentWizardCommand.setEndDate(endDate); - - String endTime = ControllerUtils.getTimeFormat().format(measuration.getEndTime()); - log.debug("Setting start time = " + endTime); - addExperimentWizardCommand.setEndTime(endTime); - - log.debug("Setting measured person = " + measuration.getPersonBySubjectPersonId().getPersonId()); - addExperimentWizardCommand.setSubjectPerson(measuration.getPersonBySubjectPersonId().getPersonId()); - - log.debug("Setting coExperimenters - count of selected coExperimenters: " + measuration.getPersons().size()); - int[] coExperimentersArray = new int[measuration.getPersons().size()]; - int i = 0; - for (Person experimenter : measuration.getPersons()) { - log.debug("Adding selected experimenter #" + experimenter.getPersonId()); - coExperimentersArray[i++] = experimenter.getPersonId(); - } - addExperimentWizardCommand.setCoExperimenters(coExperimentersArray); - - log.debug("Setting selected scenario = " + measuration.getScenario().getScenarioId()); - addExperimentWizardCommand.setScenario(measuration.getScenario().getScenarioId()); - - log.debug("Setting list of used hardware - count of selected pieces of hardware: " + measuration.getHardwares().size()); - int[] hardwareArray = new int[measuration.getHardwares().size()]; - int j = 0; - for (Hardware hardware : measuration.getHardwares()) { - log.debug("Adding selected hardware #" + hardware.getHardwareId()); - hardwareArray[j++] = hardware.getHardwareId(); - } - addExperimentWizardCommand.setHardware(hardwareArray); - - log.debug("Setting selected weather #" + measuration.getWeather().getWeatherId()); - addExperimentWizardCommand.setWeather(measuration.getWeather().getWeatherId()); - - log.debug("Setting weather note = " + measuration.getEnvironmentNote()); - addExperimentWizardCommand.setWeatherNote(measuration.getEnvironmentNote()); - - log.debug("Setting temperature = " + measuration.getTemperature()); - addExperimentWizardCommand.setTemperature("" + measuration.getTemperature()); - - addExperimentWizardCommand.setPrivateNote(measuration.isPrivateExperiment()); - } - SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); - Date startDate = new Date(System.currentTimeMillis()); - - // current time + 1hour in millis - Date endDate = new Date(System.currentTimeMillis() + 3600 * 1000); - addExperimentWizardCommand.setStartDate(sdf.format(startDate)); - addExperimentWizardCommand.setEndDate(sdf.format(endDate)); - sdf = new SimpleDateFormat("HH:mm"); - addExperimentWizardCommand.setStartTime(sdf.format(startDate)); - addExperimentWizardCommand.setEndTime(sdf.format(endDate)); - addExperimentWizardCommand.setSamplingRate("1000"); - - return addExperimentWizardCommand; - - } - - @Override - protected Map referenceData(HttpServletRequest request, Object command, Errors errors, int page) throws Exception { - Map map = new HashMap(); - switch (page) { - case 0: - List personList = personDao.getAllRecords(); - Collections.sort(personList); - map.put("personList", personList); - - List researchGroupList = - researchGroupDao.getResearchGroupsWhereAbleToWriteInto(personDao.getLoggedPerson()); - map.put("researchGroupList", researchGroupList); - - ResearchGroup defaultGroup = personDao.getLoggedPerson().getDefaultGroup(); - int defaultGroupId = (defaultGroup != null) ? defaultGroup.getResearchGroupId() : 0; - map.put("defaultGroupId", defaultGroupId); - break; - case 1: - List groups = researchGroupDao.getResearchGroupsWhereAbleToWriteInto(personDao.getLoggedPerson()); - map.put("researchGroupList", groups); - List schemaNames = scenarioSchemasDao.getSchemaNames(); - map.put("schemaNamesList", schemaNames); - - ResearchGroup defaultGroup1 = personDao.getLoggedPerson().getDefaultGroup(); - int defaultGroupId1 = (defaultGroup1 != null) ? defaultGroup1.getResearchGroupId() : 0; - map.put("defaultGroupId", defaultGroupId1); - List scenarioList = scenarioDao.getAllRecords(); - Collections.sort(scenarioList); - map.put("scenarioList", scenarioList); - - AddExperimentWizardCommand data = (AddExperimentWizardCommand)command; - int researchGroupId = data.getResearchGroup(); - List hardwareList = hardwareDao.getRecordsByGroup(researchGroupId); - List weatherList = weatherDao.getRecordsByGroup(researchGroupId); - map.put("hardwareList", hardwareList); - map.put("weatherList", weatherList); - - break; - case 2: - break; - } - - - return map; - } - - @Override - protected ModelAndView processFinish(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object command, BindException e) throws Exception { - log.debug("Processing measuration form - adding new measuration"); - ModelAndView mav = new ModelAndView("redirect:/experiments/my-experiments.html"); - - mav.addObject("userIsExperimenter", auth.userIsExperimenter()); - - AddExperimentWizardCommand data = (AddExperimentWizardCommand) command; - - Experiment experiment; - - - log.debug("Checking the permission level."); - if (!auth.userIsExperimenter()) { - log.debug("User is not experimenter - unable to add experiment. Returning MAV."); - mav.setViewName("redirect:experiments/userNotExperimenter"); - return mav; - } - - log.debug("Creating new Measuration object"); - experiment = new Experiment(); - - // This assignment is commited only when new experiment is being created - log.debug("Setting the owner to the logged user."); - experiment.setPersonByOwnerId(personDao.getLoggedPerson()); - - log.debug("Setting the group, which is the new experiment being added into."); - ResearchGroup researchGroup = new ResearchGroup(); - researchGroup.setResearchGroupId(data.getResearchGroup()); - experiment.setResearchGroup(researchGroup); - - log.debug("Setting Weather object - ID " + data.getWeather()); - Weather weather = new Weather(); - weather.setWeatherId(data.getWeather()); - experiment.setWeather(weather); - - log.debug("Setting Scenario object - ID " + data.getScenario()); - Scenario scenario = new Scenario(); - scenario.setScenarioId(data.getScenario()); - experiment.setScenario(scenario); - - log.debug("Setting Person object (measured person) - ID " + data.getSubjectPerson()); - Person subjectPerson = new Person(); - subjectPerson.setPersonId(data.getSubjectPerson()); - experiment.setPersonBySubjectPersonId(subjectPerson); - - Date startDate = ControllerUtils.getDateFormatWithTime().parse(data.getStartDate() + " " + data.getStartTime()); - experiment.setStartTime(new Timestamp(startDate.getTime())); - log.debug("Setting start date - " + startDate); - - Date endDate = ControllerUtils.getDateFormatWithTime().parse(data.getEndDate() + " " + data.getEndTime()); - experiment.setEndTime(new Timestamp(endDate.getTime())); - log.debug("Setting end date - " + endDate); - - log.debug("Setting the temperature - " + data.getTemperature()); - experiment.setTemperature(Integer.parseInt(data.getTemperature())); - - log.debug("Setting the weather note - " + data.getWeatherNote()); - experiment.setEnvironmentNote(data.getWeatherNote()); - - log.debug("Started setting the Hardware objects"); - int[] hardwareArray = data.getHardware(); - Set hardwareSet = new HashSet(); - for (int hardwareId : hardwareArray) { - System.out.println("hardwareId "+ hardwareId); - Hardware tempHardware = hardwareDao.read(hardwareId); - hardwareSet.add(tempHardware); - tempHardware.getExperiments().add(experiment); - log.debug("Added Hardware object - ID " + hardwareId); - } - log.debug("Setting Hardware list to Measuration object"); - experiment.setHardwares(hardwareSet); - - log.debug("Started setting the Person objects (coExperimenters)"); - int[] coExperimentersArray = data.getCoExperimenters(); - Set coExperimenterSet = new HashSet(); - for (int personId : coExperimentersArray) { - Person tempExperimenter = personDao.read(personId); - coExperimenterSet.add(tempExperimenter); - tempExperimenter.getExperiments().add(experiment); - log.debug("Added Person object - ID " + tempExperimenter.getPersonId()); - } - log.debug("Setting Person list to Measuration object"); - experiment.setPersons(coExperimenterSet); - - log.debug("Setting private/public access"); - experiment.setPrivateExperiment(data.isPrivateNote()); - float samplingRate = Float.parseFloat(data.getSamplingRate()); - Digitization digitization = digitizationDao.getDigitizationByParams(samplingRate, -1, "NotKnown"); - if (digitization == null) { - digitization = new Digitization(); - digitization.setFilter("NotKnown"); - digitization.setGain(-1); - digitization.setSamplingRate(samplingRate); - digitizationDao.create(digitization); - } - - experiment.setDigitization(digitization); - experiment.setArtifact(artifactDao.read(1)); - experiment.setElectrodeConf(electrodeConfDao.read(1)); - experiment.setSubjectGroup(subjectGroupDao.read(1)); //default subject group - - if (data.getMeasurationId() > 0) { // editing existing measuration - log.debug("Saving the Measuration object to database using DAO - update()"); - experimentDao.update(experiment); - } else { // creating new measuration - log.debug("Saving the Measuration object to database using DAO - create()"); - experimentDao.create(experiment); - } - - // log.debug("Creating measuration with ID " + addDataCommand.getMeasurationId()); - // experiment.setExperimentId(addDataCommand.getMeasurationId()); - - log.debug("Creating new Data object."); - MultipartHttpServletRequest mpRequest = (MultipartHttpServletRequest)httpServletRequest; - // the map containing file names mapped to files - Map m = mpRequest.getFileMap(); - Set set = m.keySet(); - for (Object key: set) { - MultipartFile file = (MultipartFile) m.get(key); - if (file.getOriginalFilename().endsWith(".zip")) { - ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(file.getBytes())); - ZipEntry en = zis.getNextEntry(); - while (en != null) { - if (en.isDirectory()) { - en = zis.getNextEntry(); - continue; - } - DataFile dataFile = new DataFile(); - dataFile.setExperiment(experiment); - String name[] = en.getName().split("/"); - dataFile.setFilename(name[name.length-1]); - data.setFileDescription(data.getFileDescription()); - dataFile.setFileContent(Hibernate.createBlob(zis)); - String[] partOfName = en.getName().split("[.]"); - dataFile.setMimetype(partOfName[partOfName.length-1]); - dataFileDao.create(dataFile); - en = zis.getNextEntry(); - } - } else { - DataFile dataFile = new DataFile(); - dataFile.setExperiment(experiment); - - log.debug("Original name of uploaded file: " + file.getOriginalFilename()); - String filename = file.getOriginalFilename().replace(" ", "_"); - dataFile.setFilename(filename); - - log.debug("MIME type of the uploaded file: " + file.getContentType()); - if (file.getContentType().length() > MAX_MIMETYPE_LENGTH) { - int index = filename.lastIndexOf("."); - dataFile.setMimetype(filename.substring(index)); - } else { - dataFile.setMimetype(file.getContentType()); - } - - - log.debug("Parsing the sapmling rate."); - dataFile.setDescription(data.getFileDescription()); - - log.debug("Setting the binary data to object."); - dataFile.setFileContent(Hibernate.createBlob(file.getBytes())); - - dataFileDao.create(dataFile); - log.debug("Data stored into database."); - } - } - - log.debug("Returning MAV object"); - return mav; - } - - @Override - protected ModelAndView processCancel(HttpServletRequest request, - HttpServletResponse response, Object command, BindException errors) - throws Exception { - return new ModelAndView("redirect:/home.html"); - } - - - @Override - protected void validatePage(Object command, Errors errors, int page) { - AddExperimentWizardCommand data = (AddExperimentWizardCommand) command; - - - switch (page) { - case 0: //if page 1 , go validate with validatePage1Form - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "startDate", "required.date"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "startTime", "required.time"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "endDate", "required.date"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "endTime", "required.time"); - if (data.getResearchGroup() == -1) { - // research group not chosen - errors.rejectValue("researchGroup", "required.researchGroup"); - } else if (!auth.personAbleToWriteIntoGroup(data.getResearchGroup())) { - errors.rejectValue("researchGroup", "invalid.notAbleToAddExperimentInGroup"); - } - if (data.getSubjectPerson() == -1) { // measured person not chosen - errors.rejectValue("subjectPerson", "required.subjectPerson"); - } - try { - ControllerUtils.getDateFormat().parse(data.getStartDate()); - } catch (ParseException ex) { - errors.rejectValue("startDate", "invalid.date"); - } - - try { - ControllerUtils.getDateFormat().parse(data.getEndDate()); - } catch (ParseException ex) { - errors.rejectValue("endDate", "invalid.date"); - } - - try { - ControllerUtils.getTimeFormat().parse(data.getStartTime()); - } catch (ParseException ex) { - errors.rejectValue("startTime", "invalid.time"); - } - - try { - ControllerUtils.getTimeFormat().parse(data.getEndTime()); - } catch (ParseException ex) { - errors.rejectValue("endTime", "invalid.time"); - } - - break; - case 1: //if page 2 , go validate with validatePage2Form - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "temperature", "required.field"); - if (data.getScenario() == -1) { // scenario not selected - errors.rejectValue("scenario", "required.scenario"); - } - - if (data.getHardware().length == 0) { // no hardware selected - errors.rejectValue("hardware", "required.hardware"); - } - - if (data.getWeather() == -1) { // weather not selected - errors.rejectValue("weather", "required.weather"); - } - try { - int temp = Integer.parseInt(data.getTemperature()); - if (temp < -273) { - errors.rejectValue("temperature", "invalid.minTemp"); - } - } catch (NumberFormatException e) { - errors.rejectValue("temperature", "invalid.temperature"); - } - break; - case 2: //if page 3 , go validate with validatePage3Form - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "samplingRate", "required.samplingRate"); - try { - double rate = Double.parseDouble(data.getSamplingRate()); - if (rate <= 0) { - errors.rejectValue("samplingRate", "invalid.positiveRate"); - } - } catch (NumberFormatException e) { - errors.rejectValue("samplingRate", "invalid.invalidRate"); - } - MultipartFile file = data.getDataFile(); - if (file.getOriginalFilename().length() == 0) { - errors.rejectValue("dataFile", "required.dataFile"); - } - - break; - } - - } - - public boolean supports(Class aClass) { - return aClass.equals(AddExperimentWizardCommand.class); - } - - - public GenericDao getExperimentDao() { - return experimentDao; - } - - public void setExperimentDao(GenericDao experimentDao) { - this.experimentDao = experimentDao; - } - - public WeatherDao getWeatherDao() { - return weatherDao; - } - - public void setWeatherDao(WeatherDao weatherDao) { - this.weatherDao = weatherDao; - } - - public HardwareDao getHardwareDao() { - return hardwareDao; - } - - public void setHardwareDao(HardwareDao hardwareDao) { - this.hardwareDao = hardwareDao; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public ScenarioDao getScenarioDao() { - return scenarioDao; - } - - public void setScenarioDao(ScenarioDao scenarioDao) { - this.scenarioDao = scenarioDao; - } - - public ResearchGroupDao getResearchGroupDao() { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) { - this.researchGroupDao = researchGroupDao; - } - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } - - public GenericDao getDataFileDao() { - return dataFileDao; - } - - public void setDataFileDao(GenericDao dataFileDao) { - this.dataFileDao = dataFileDao; - - } - - public ScenarioSchemasDao getScenarioSchemasDao() { - return scenarioSchemasDao; - } - - public void setScenarioSchemasDao(ScenarioSchemasDao scenarioSchemasDao) { - this.scenarioSchemasDao = scenarioSchemasDao; - } - - public DigitizationDao getDigitizationDao() { - return digitizationDao; - } - - public void setDigitizationDao(DigitizationDao digitizationDao) { - this.digitizationDao = digitizationDao; - } - - public GenericDao getSubjectGroupDao() { - return subjectGroupDao; - } - - public void setSubjectGroupDao(GenericDao subjectGroupDao) { - this.subjectGroupDao = subjectGroupDao; - } - - - public GenericDao getElectrodeConfDao() { - return electrodeConfDao; - } - - public void setElectrodeConfDao(GenericDao electrodeConfDao) { - this.electrodeConfDao = electrodeConfDao; - } - - public GenericListDao getArtifactDao() { - return artifactDao; - } - - public void setArtifactDao(GenericListDao artifactDao) { - this.artifactDao = artifactDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddFileMetadataCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddFileMetadataCommand.java deleted file mode 100644 index ae08e48f..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddFileMetadataCommand.java +++ /dev/null @@ -1,66 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddFileMetadataCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.experiment; - -/** - * @author Jindra - */ -public class AddFileMetadataCommand { - - private int dataId; - private int paramId; - private String paramValue; - private String researchGroupTitle; - - public int getDataId() { - return dataId; - } - - public void setDataId(int dataId) { - this.dataId = dataId; - } - - public int getParamId() { - return paramId; - } - - public void setParamId(int paramId) { - this.paramId = paramId; - } - - public String getParamValue() { - return paramValue; - } - - public void setParamValue(String paramValue) { - this.paramValue = paramValue; - } - - public String getResearchGroupTitle() { - return researchGroupTitle; - } - - public void setResearchGroupTitle(String researchGroupTitle) { - this.researchGroupTitle = researchGroupTitle; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddFileMetadataValidator.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddFileMetadataValidator.java deleted file mode 100644 index d2e844ea..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/AddFileMetadataValidator.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddFileMetadataValidator.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.experiment; - -import cz.zcu.kiv.eegdatabase.data.dao.GenericDao; -import cz.zcu.kiv.eegdatabase.data.pojo.FileMetadataParamVal; -import cz.zcu.kiv.eegdatabase.data.pojo.FileMetadataParamValId; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -/** - * @author JiPER - */ -public class AddFileMetadataValidator implements Validator { - - private Log log = LogFactory.getLog(getClass()); - private GenericDao fileMetadataDao; - - public boolean supports(Class clazz) { - return clazz.equals(AddFileMetadataCommand.class); - } - - public void validate(Object command, Errors errors) { - AddFileMetadataCommand addFileMetadataCommand = (AddFileMetadataCommand) command; - log.debug("Validating form for adding file metadata."); - - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "paramValue", "required.paramValue"); - - if (addFileMetadataCommand.getParamId() <= 0) { - errors.rejectValue("paramId", "required.paramId"); - } - - FileMetadataParamVal f = fileMetadataDao.read(new FileMetadataParamValId(addFileMetadataCommand.getParamId(), addFileMetadataCommand.getDataId())); - if (f != null) { - errors.rejectValue("paramId", "invalid.paramIdAlreadyInserted"); - } - } - - public GenericDao getFileMetadataDao() { - return fileMetadataDao; - } - - public void setFileMetadataDao(GenericDao fileMetadataDao) { - this.fileMetadataDao = fileMetadataDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/ChooseMetadataController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/ChooseMetadataController.java deleted file mode 100644 index 1ece1e8a..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/ChooseMetadataController.java +++ /dev/null @@ -1,95 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ChooseMetadataController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package cz.zcu.kiv.eegdatabase.logic.controller.experiment; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.GenericDao; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Experiment; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.AbstractController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * @author Jan - */ -public class ChooseMetadataController extends AbstractController { - - private GenericDao experimentDao; - private PersonDao personDao; - private AuthorizationManager auth; - - @Override - protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - ModelAndView mav = new ModelAndView("experiments/chooseMetadata"); - int id = Integer.parseInt(request.getParameter("id")); - Experiment m = experimentDao.read(id); - Person user = personDao.getLoggedPerson(); - boolean auth = false; - if (user.getAuthority().equals("ROLE_ADMIN")) { - auth = true; - } - if (m.getPersonByOwnerId().getPersonId() == user.getPersonId()) { - auth = true; - } - if (personDao.userNameInGroup(user.getUsername(), m.getResearchGroup().getResearchGroupId())) { - auth = true; - } - // For the menu item - mav.addObject("userCanSeePersonDetail", auth); - - mav.addObject("measurationDetail", m); - return mav; - } - - public GenericDao getExperimentDao() { - return experimentDao; - } - - public void setExperimentDao(GenericDao experimentDao) { - this.experimentDao = experimentDao; - } - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/DataFileDetailController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/DataFileDetailController.java deleted file mode 100644 index 9098f4ae..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/DataFileDetailController.java +++ /dev/null @@ -1,179 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * DataFileDetailController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.experiment; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.FileMetadataParamDefDao; -import cz.zcu.kiv.eegdatabase.data.dao.GenericDao; -import cz.zcu.kiv.eegdatabase.data.pojo.*; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.validation.BindException; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; -import org.springframework.web.bind.annotation.ModelAttribute; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @author JiPER - */ -public class DataFileDetailController - extends SimpleFormController - implements Validator { - - private Log log = LogFactory.getLog(getClass()); - private AuthorizationManager auth; - private GenericDao dataFileDao; - private GenericDao fileMetadataParamValDao; - private FileMetadataParamDefDao fileMetadataParamDefDao; - - public DataFileDetailController() { - setCommandClass(AddFileMetadataCommand.class); - setCommandName("addMetadata"); - } - - @Override - protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception { - ModelAndView mav = super.showForm(request, response, errors); - - int fileId = 0; - try { - fileId = Integer.parseInt(request.getParameter("fileId")); - } catch (Exception e) { - } - - boolean val = auth.userIsOwnerOrCoexpOfCorrespExperiment(fileId); - mav.addObject("userIsOwnerOrCoexpOfCorrespExperiment", val); - - boolean userIsExperimenter = auth.userIsExperimenter(); - mav.addObject("userIsExperimenter", userIsExperimenter); - - return mav; - } - - - @Override - protected Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception { - Map map = new HashMap(); - - int fileId = Integer.parseInt(request.getParameter("fileId")); - DataFile data = dataFileDao.read(fileId); - map.put("researchGroupTitle",data.getExperiment().getResearchGroup().getTitle()); - map.put("dataDetail", data); - List list = fileMetadataParamDefDao.getRecordsByGroup(data.getExperiment().getResearchGroup().getResearchGroupId()); - map.put("fileMetadataParams", list); - - return map; - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { - AddFileMetadataCommand addFileMetadataCommand = (AddFileMetadataCommand) command; - - int fileId = Integer.parseInt(request.getParameter("fileId")); - - ModelAndView mav = new ModelAndView("redirect:/experiments/data/detail.html?fileId=" + fileId); - - log.debug("Checking the permission."); - if (!auth.userIsOwnerOrCoexpOfCorrespExperiment(fileId)) { - log.debug("User does not have permission to add metadata value - no data saved, returning MAV."); - return mav; - } - - log.debug("Creating new FileMetadata object"); - FileMetadataParamVal metadata = new FileMetadataParamVal(); - metadata.setId(new FileMetadataParamValId(addFileMetadataCommand.getParamId(), fileId)); - - log.debug("Setting the metadata value = " + addFileMetadataCommand.getParamValue()); - metadata.setMetadataValue(addFileMetadataCommand.getParamValue()); - - log.debug("Saving new file metadata entry"); - fileMetadataParamValDao.create(metadata); - - log.debug("Returning MAV"); - return mav; - } - - public boolean supports(Class clazz) { - return clazz.equals(AddFileMetadataCommand.class); - } - - public void validate(Object command, Errors errors) { - AddFileMetadataCommand data = (AddFileMetadataCommand) command; - log.debug("Validating form for adding file metadata."); - - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "paramValue", "required.paramValue"); - - if (data.getParamId() <= 0) { - errors.rejectValue("paramId", "required.paramId"); - } - - FileMetadataParamVal f = fileMetadataParamValDao.read(new FileMetadataParamValId(data.getParamId(), data.getDataId())); - if (f != null) { - errors.rejectValue("paramId", "invalid.paramIdAlreadyInserted"); - } - } - - - - public GenericDao getDataFileDao() { - return dataFileDao; - } - - public void setDataFileDao(GenericDao dataFileDao) { - this.dataFileDao = dataFileDao; - } - - public GenericDao getFileMetadataParamValDao() { - return fileMetadataParamValDao; - } - - public void setFileMetadataParamValDao(GenericDao fileMetadataParamValDao) { - this.fileMetadataParamValDao = fileMetadataParamValDao; - } - - public FileMetadataParamDefDao getFileMetadataParamDefDao() { - return fileMetadataParamDefDao; - } - - public void setFileMetadataParamDefDao(FileMetadataParamDefDao fileMetadataParamDefDao) { - this.fileMetadataParamDefDao = fileMetadataParamDefDao; - } - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/DownloadMetadataZipController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/DownloadMetadataZipController.java deleted file mode 100644 index b56f8cc3..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/DownloadMetadataZipController.java +++ /dev/null @@ -1,217 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * DownloadMetadataZipController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package cz.zcu.kiv.eegdatabase.logic.controller.experiment; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.InputStream; -import java.sql.Timestamp; -import java.util.Arrays; -import java.util.Calendar; -import java.util.HashSet; -import java.util.Set; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.commons.io.IOUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.validation.BindException; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; - -import cz.zcu.kiv.eegdatabase.data.dao.GenericDao; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.pojo.DataFile; -import cz.zcu.kiv.eegdatabase.data.pojo.Experiment; -import cz.zcu.kiv.eegdatabase.data.pojo.FileMetadataParamVal; -import cz.zcu.kiv.eegdatabase.data.pojo.FileMetadataParamValId; -import cz.zcu.kiv.eegdatabase.data.pojo.History; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; -import cz.zcu.kiv.eegdatabase.logic.zip.Generator; - -/** - * @author Petr Jezek - */ -public class DownloadMetadataZipController extends SimpleFormController { - - private Generator zipGenerator; - private Log log = LogFactory.getLog(getClass()); - private GenericDao experimentDao; - private GenericDao historyDao; - private PersonDao personDao; - - public DownloadMetadataZipController() { - setCommandClass(MetadataCommand.class); - setCommandName("chooseMetadata"); - } - - @Override - protected Object formBackingObject(HttpServletRequest request) throws Exception { - return super.formBackingObject(request); - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { -// //ModelAndView mav = new ModelAndView("downloadMetadataZipView"); - MetadataCommand mc = (MetadataCommand) command; - int id = Integer.parseInt(request.getParameter("id")); - Experiment fromDB = experimentDao.read(id); - String scenarioName = fromDB.getScenario().getTitle(); - - Set files = fromDB.getDataFiles(); - //gets a parameters from request - //contents is in the request if user wants download data file - String[] contents = request.getParameterValues("content"); - //fileParam represents file metadata params - String[] fileParam = request.getParameterValues("fileParam"); - FileMetadataParamValId[] params = null; - if (fileParam != null) { - params = new FileMetadataParamValId[fileParam.length]; - //go throws parameters and creates FileMetadataParamsValId instances - //in the request data_file_id and file_metadata_param_def_id is separated - //by # in the form file_id#file_metadata_param_def_id - // - for (int i = 0; i < fileParam.length; i++) { - String[] tmp = fileParam[i].split("#"); - params[i] = new FileMetadataParamValId(Integer.parseInt(tmp[1]), Integer.parseInt(tmp[0])); - } - } - Set newFiles = new HashSet(); - if (fileParam != null || contents != null) { - //go over data files selected from db - for (DataFile item : files) { - DataFile newItem = null; - if (contents != null) { - if (Arrays.asList(contents).contains(String.valueOf(item.getDataFileId()))) { - newItem = new DataFile(); - newItem.setDataFileId(item.getDataFileId()); - newItem.setExperiment(item.getExperiment()); - newItem.setFileContent(item.getFileContent()); - newItem.setFilename(item.getFilename()); - newItem.setMimetype(item.getMimetype()); - newItem.setDescription(item.getDescription()); - } - } - Set newVals = new HashSet(); - if (params != null) { - for (FileMetadataParamVal paramVal : item.getFileMetadataParamVals()) { - for (FileMetadataParamValId paramId : params) { - if (paramVal.getId().getDataFileId() == paramId.getDataFileId() && paramVal.getId().getFileMetadataParamDefId() == paramId.getFileMetadataParamDefId()) { - newVals.add(paramVal); - } - } - } - } - if (!newVals.isEmpty()) { - if (newItem == null) { - newItem = new DataFile(); - } - newItem.setFileMetadataParamVals(newVals); - } - if (newItem != null) { - newFiles.add(newItem); - } - } - } - Person user = personDao.getPerson(ControllerUtils.getLoggedUserName()); - Timestamp currentTimestamp = new java.sql.Timestamp(Calendar.getInstance().getTime().getTime()); - History history = new History(); - log.debug("Setting downloading metadata"); - history.setExperiment(fromDB); - log.debug("Setting user"); - history.setPerson(user); - log.debug("Setting time of download"); - history.setDateOfDownload(currentTimestamp); - log.debug("Saving download history"); - historyDao.create(history); - - File file = getZipGenerator().generate(fromDB, mc, newFiles, new byte[0], null); - InputStream dataStream = new FileInputStream(file); - - response.setHeader("Content-Type", "application/zip"); - if (scenarioName == null) { - response.setHeader("Content-Disposition", "attachment;filename=Experiment_data.zip"); - } else { - String[] names = scenarioName.split(" "); - scenarioName = names[0]; - for (int i = 1; i < names.length; i++) { - scenarioName += "_" + names[i]; - - } - response.setHeader("Content-Disposition", "attachment;filename=" + scenarioName + ".zip"); - } - - if (dataStream instanceof InputStream) { - IOUtils.copyLarge(dataStream, response.getOutputStream()); - dataStream.close(); - } - log.debug(zipGenerator); - return null; - } - - /** - * @return the zipGenerator - */ - public Generator getZipGenerator() { - return zipGenerator; - } - - /** - * @param generator the zipGenerator to set - */ - public void setZipGenerator(Generator generator) { - this.zipGenerator = generator; - } - - public GenericDao getExperimentDao() { - return experimentDao; - } - - public void setExperimentDao(GenericDao experimentDao) { - this.experimentDao = experimentDao; - } - - public GenericDao getHistoryDao() { - return historyDao; - } - - public void setHistoryDao(GenericDao historyDao) { - this.historyDao = historyDao; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/ExperimentMultiController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/ExperimentMultiController.java deleted file mode 100644 index a2387c97..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/ExperimentMultiController.java +++ /dev/null @@ -1,288 +0,0 @@ -/** - * ***************************************************************************** - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - * - * *********************************************************************************************************************** - * - * ExperimentMultiController.java, 2013/10/02 00:01 Jakub Rinkes - * **************************************************************************** - */ -package cz.zcu.kiv.eegdatabase.logic.controller.experiment; - -import cz.zcu.kiv.eegdatabase.data.dao.*; -import cz.zcu.kiv.eegdatabase.data.pojo.DataFile; -import cz.zcu.kiv.eegdatabase.data.pojo.Experiment; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.ServiceResult; -import cz.zcu.kiv.eegdatabase.logic.signal.ChannelInfo; -import cz.zcu.kiv.eegdatabase.logic.signal.EegReader; -import cz.zcu.kiv.eegdatabase.logic.signal.VhdrReader; -import cz.zcu.kiv.eegdatabase.logic.util.Paginator; -import java.io.IOException; -import java.sql.Blob; -import java.sql.SQLException; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.multiaction.MultiActionController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.ArrayList; -import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.apache.commons.io.IOUtils; - -/** - * Delegate class for multicontroller for experiments. - * - * @author Jindra - */ -public class ExperimentMultiController extends MultiActionController { - - private Log log = LogFactory.getLog(getClass()); - private AuthorizationManager auth; - private PersonDao personDao; - private ExperimentDao experimentDao; - private ServiceResultDao resultDao; - private ResearchGroupDao researchGroupDao; - private static final int ITEMS_PER_PAGE = 20; - - public ModelAndView list(HttpServletRequest request, HttpServletResponse response) { - ModelAndView mav = new ModelAndView("experiments/list"); - - Person loggedUser = personDao.getLoggedPerson(); - setPermissionsToView(mav); - log.debug("Logged user ID from database is: " + loggedUser.getPersonId()); - Paginator paginator = new Paginator(experimentDao.getCountForAllExperimentsForUser(loggedUser), ITEMS_PER_PAGE); - int page = 1; - try { - page = Integer.parseInt(request.getParameter("page")); - } catch (NumberFormatException e) { - } - paginator.setActualPage(page); - List experimentList = experimentDao.getAllExperimentsForUser(loggedUser, paginator.getFirstItemIndex(), ITEMS_PER_PAGE); - mav.addObject("paginator", paginator.getLinks()); - boolean userNotMemberOfAnyGroup = researchGroupDao.getResearchGroupsWhereMember(loggedUser, 1).isEmpty(); - - mav.addObject("experimentListTitle", "pageTitle.allExperiments"); - mav.addObject("experimentList", experimentList); - mav.addObject("userNotMemberOfAnyGroup", userNotMemberOfAnyGroup); - return mav; - } - - public ModelAndView myExperiments(HttpServletRequest request, HttpServletResponse response) { - ModelAndView mav = new ModelAndView("experiments/list"); - - Person loggedUser = personDao.getLoggedPerson(); - setPermissionsToView(mav); - log.debug("Logged user ID from database is: " + loggedUser.getPersonId()); - Paginator paginator = new Paginator(experimentDao.getCountForExperimentsWhereOwner(loggedUser), ITEMS_PER_PAGE); - int page = 1; - try { - page = Integer.parseInt(request.getParameter("page")); - } catch (NumberFormatException e) { - } - paginator.setActualPage(page); - List experimentList = experimentDao.getExperimentsWhereOwner(loggedUser, paginator.getFirstItemIndex(), ITEMS_PER_PAGE); - mav.addObject("paginator", paginator.getLinks()); - boolean userNotMemberOfAnyGroup = researchGroupDao.getResearchGroupsWhereMember(loggedUser, 1).isEmpty(); - - mav.addObject("experimentListTitle", "pageTitle.myExperiments"); - mav.addObject("experimentList", experimentList); - mav.addObject("userNotMemberOfAnyGroup", userNotMemberOfAnyGroup); - return mav; - } - - public ModelAndView meAsSubject(HttpServletRequest request, HttpServletResponse response) { - ModelAndView mav = new ModelAndView("experiments/list"); - - Person loggedUser = personDao.getLoggedPerson(); - setPermissionsToView(mav); - log.debug("Logged user ID from database is: " + loggedUser.getPersonId()); - Paginator paginator = new Paginator(experimentDao.getCountForExperimentsWhereSubject(loggedUser), ITEMS_PER_PAGE); - int page = 1; - try { - page = Integer.parseInt(request.getParameter("page")); - } catch (NumberFormatException e) { - } - paginator.setActualPage(page); - List experimentList = experimentDao.getExperimentsWhereSubject(loggedUser, paginator.getFirstItemIndex(), ITEMS_PER_PAGE); - mav.addObject("paginator", paginator.getLinks()); - boolean userNotMemberOfAnyGroup = researchGroupDao.getResearchGroupsWhereMember(loggedUser, 1).isEmpty(); - - mav.addObject("experimentListTitle", "pageTitle.myExperiments"); - mav.addObject("experimentList", experimentList); - mav.addObject("userNotMemberOfAnyGroup", userNotMemberOfAnyGroup); - return mav; - } - - public ModelAndView detail(HttpServletRequest request, HttpServletResponse response) { - ModelAndView mav = new ModelAndView("experiments/detail"); - VhdrReader vhdr = new VhdrReader(); - List channels = null; - - setPermissionsToView(mav); - int id = 0; - try { - id = Integer.parseInt(request.getParameter("experimentId")); - } catch (Exception e) { - } - Experiment m = experimentDao.getExperimentForDetail(id); - - mav.addObject("userIsOwnerOrCoexperimenter", (auth.userIsOwnerOrCoexperimenter(id)) || (auth.isAdmin())); - int subjectPersonId = m.getPersonBySubjectPersonId().getPersonId(); - Boolean filesIn = new Boolean(false); - ArrayList signalData = new ArrayList(); - for (DataFile file : m.getDataFiles()) { - if (file.getFilename().endsWith(".vhdr")) { - Blob b = file.getFileContent(); - int index = file.getFilename().lastIndexOf("."); - String fileName = file.getFilename().substring(0, index); - try { - vhdr.readVhdr(IOUtils.toByteArray(b.getBinaryStream())); - } catch (IOException ex) { - Logger.getLogger(ExperimentMultiController.class.getName()).log(Level.SEVERE, null, ex); - throw new RuntimeException(ex); - } catch (SQLException ex) { - Logger.getLogger(ExperimentMultiController.class.getName()).log(Level.SEVERE, null, ex); - throw new RuntimeException(ex); - } - channels = vhdr.getChannels(); - mav.addObject("channels", channels); - - for (DataFile file2 : m.getDataFiles()) { - if ((file2.getFilename().endsWith(".eeg")) || (file2.getFilename().endsWith(".avg"))) { - filesIn = true; - Blob b2 = file.getFileContent(); - EegReader eeg = new EegReader(vhdr); - for (ChannelInfo ch : channels) { - try { - signalData.add(eeg.readFile(IOUtils.toByteArray(b2.getBinaryStream()), ch.getNumber())); - } catch (IOException ex) { - Logger.getLogger(ExperimentMultiController.class.getName()).log(Level.SEVERE, null, ex); - throw new RuntimeException(ex); - } catch (SQLException ex) { - Logger.getLogger(ExperimentMultiController.class.getName()).log(Level.SEVERE, null, ex); - throw new RuntimeException(ex); - } - } - mav.addObject("signalData", signalData); - } - } - } - } - - mav.addObject("filesAvailable", filesIn); - mav.addObject("userCanViewPersonDetails", auth.userCanViewPersonDetails(subjectPersonId)); - - mav.addObject("experimentDetail", m); - - return mav; - } - - private void setPermissionsToView(ModelAndView mav) { - boolean userIsExperimenter = auth.userIsExperimenter(); - mav.addObject("userIsExperimenter", userIsExperimenter); - } - - public ModelAndView servicesResult(HttpServletRequest request, HttpServletResponse response) { - ModelAndView mav = new ModelAndView("services/results"); - - List results = resultDao.getResultByPerson(personDao.getLoggedPerson().getPersonId()); - mav.addObject("results", results); - mav.addObject("resultsEmpty", results.isEmpty()); - return mav; - } - - public ModelAndView download(HttpServletRequest request, HttpServletResponse response) throws Exception { - int id = 0; - try { - id = Integer.parseInt(request.getParameter("serviceId")); - - } catch (Exception e) { - } - ServiceResult service = resultDao.read(id); - if (service.getFilename().endsWith(".txt")) { - response.setHeader("Content-Type", "plain/text"); - } else { - response.setHeader("Content-Type", "application/png"); - } - response.setHeader("Content-Disposition", "attachment;filename=" + service.getFilename()); - response.getOutputStream().write(service.getContent().getBytes(1, (int)service.getContent().length())); - //return new ModelAndView("redirect:services-result.html"); - return null; - } - - public ModelAndView delete(HttpServletRequest request, HttpServletResponse response) { - ModelAndView mav = new ModelAndView("redirect:services-result.html"); - int id = 0; - try { - id = Integer.parseInt(request.getParameter("serviceId")); - - } catch (Exception e) { - } - ServiceResult service = resultDao.read(id); - resultDao.delete(service); - return mav; - } - - public ExperimentDao getExperimentDao() { - return experimentDao; - } - - public void setExperimentDao(ExperimentDao experimentDao) { - this.experimentDao = experimentDao; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } - - public ServiceResultDao getResultDao() { - return resultDao; - } - - public void setResultDao(ServiceResultDao resultDao) { - this.resultDao = resultDao; - } - - public ResearchGroupDao getResearchGroupDao() { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) { - this.researchGroupDao = researchGroupDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/MeasurationDataOutputController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/MeasurationDataOutputController.java deleted file mode 100644 index da390d51..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/MeasurationDataOutputController.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * MeasurationDataOutputController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.experiment; - -import cz.zcu.kiv.eegdatabase.data.dao.GenericDao; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.pojo.DataFile; -import cz.zcu.kiv.eegdatabase.data.pojo.History; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.AbstractController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.sql.Blob; -import java.sql.Timestamp; -import java.util.Calendar; - -/** - * This controller loads a data object for the view which serves the downloading of the data file - * - * @author Jindra - */ -public class MeasurationDataOutputController extends AbstractController { - - private GenericDao dataFileDao; - private GenericDao historyDao; - private Log log = LogFactory.getLog(getClass()); - private PersonDao personDao; - - @Override - protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - // ModelAndView mav = new ModelAndView("binaryView"); - // There should always be set integer value in this field - it is generated by view, not by user - int fileId = Integer.parseInt(request.getParameter("fileId")); - DataFile data = dataFileDao.read(fileId); - Blob b = data.getFileContent(); - Person user = personDao.getPerson(ControllerUtils.getLoggedUserName()); - Timestamp currentTimestamp = new java.sql.Timestamp(Calendar.getInstance().getTime().getTime()); - History history = new History(); - log.debug("Setting downloading data file"); - history.setDataFile(data); - log.debug("Setting user"); - history.setPerson(user); - log.debug("Setting time of download"); - history.setDateOfDownload(currentTimestamp); - log.debug("Saving download history"); - historyDao.create(history); - response.setHeader("Content-Type", data.getMimetype()); - response.setHeader("Content-Disposition", "attachment;filename=" + data.getFilename()); - response.getOutputStream().write(b.getBytes(1, (int)b.length())); - // mav.addObject("dataObject", dataFileDao.read(fileId)); - return null; - } - - public GenericDao getDataFileDao() { - return dataFileDao; - } - - public void setDataFileDao(GenericDao dataFileDao) { - this.dataFileDao = dataFileDao; - } - - public GenericDao getHistoryDao() { - return historyDao; - } - - public void setHistoryDao(GenericDao historyDao) { - this.historyDao = historyDao; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/WizardAjaxController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/WizardAjaxController.java deleted file mode 100644 index 988cb084..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/WizardAjaxController.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * WizardAjaxController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.experiment; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -/** - * Created by IntelliJ IDEA. - * User: Jakub Balhar - * Date: 19.3.13 - * Time: 15:33 - */ -@Controller -public class WizardAjaxController { - @RequestMapping(value="/experiments/wizard/json/arm") - public ModelAndView arm(){ - ModelAndView mav = new ModelAndView("experiments/json/arm"); - return mav; - } - - @RequestMapping(value="/experiments/wizard/json/disease") - public ModelAndView disease(){ - ModelAndView mav = new ModelAndView("experiments/json/disease"); - return mav; - } - - @RequestMapping(value="/experiments/wizard/json/experimentators") - public ModelAndView experimentators(){ - ModelAndView mav = new ModelAndView("experiments/json/experimentators"); - return mav; - } - - @RequestMapping(value="/experiments/wizard/json/group") - public ModelAndView group(){ - ModelAndView mav = new ModelAndView("experiments/json/group"); - return mav; - } - - @RequestMapping(value="/experiments/wizard/json/hardware") - public ModelAndView hardware(){ - ModelAndView mav = new ModelAndView("experiments/json/hardware"); - return mav; - } - - @RequestMapping(value="/experiments/wizard/json/person") - public ModelAndView person(){ - ModelAndView mav = new ModelAndView("experiments/json/person"); - return mav; - } - - @RequestMapping(value="/experiments/wizard/json/pharmaceutical") - public ModelAndView pharmaceutical(){ - ModelAndView mav = new ModelAndView("experiments/json/pharmaceutical"); - return mav; - } - - @RequestMapping(value="/experiments/wizard/json/project") - public ModelAndView project(){ - ModelAndView mav = new ModelAndView("experiments/json/project"); - return mav; - } - - @RequestMapping(value="/experiments/wizard/json/scenario") - public ModelAndView scenario(){ - ModelAndView mav = new ModelAndView("experiments/json/scenario"); - return mav; - } - - @RequestMapping(value="/experiments/wizard/json/software") - public ModelAndView software(){ - ModelAndView mav = new ModelAndView("experiments/json/software"); - return mav; - } - - @RequestMapping(value="/experiments/wizard/json/weather") - public ModelAndView weather(){ - ModelAndView mav = new ModelAndView("experiments/json/weather"); - return mav; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/WizardAjaxMultiController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/WizardAjaxMultiController.java deleted file mode 100644 index 128d683c..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/WizardAjaxMultiController.java +++ /dev/null @@ -1,280 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * WizardAjaxMultiController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.experiment; - -import cz.zcu.kiv.eegdatabase.data.dao.*; -import cz.zcu.kiv.eegdatabase.data.pojo.*; -import cz.zcu.kiv.eegdatabase.data.service.HibernatePersonService; -import cz.zcu.kiv.eegdatabase.data.service.MailService; -import cz.zcu.kiv.eegdatabase.data.service.PersonService; -import cz.zcu.kiv.eegdatabase.data.service.SpringJavaMailService; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.Hibernate; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.HierarchicalMessageSource; -import org.springframework.mail.MailException; -import org.springframework.mail.javamail.JavaMailSenderImpl; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.multipart.MultipartHttpServletRequest; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.multiaction.MultiActionController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.text.ParseException; - -import net.sf.json.JSONObject; -import org.springframework.web.servlet.support.RequestContextUtils; - -import static org.apache.commons.io.IOUtils.toByteArray; - -/** - * Adding new weather, person atd. to database - * User: pbruha - * Date: 3.4.11 - * Time: 11:00 - * To change this template use File | Settings | File Templates. - */ -public class WizardAjaxMultiController extends MultiActionController { - private Log log = LogFactory.getLog(getClass()); - @Autowired - private WeatherDao weatherDao; - @Autowired - private HardwareDao hardwareDao; - @Autowired - private PersonDao personDao; - @Autowired - private ResearchGroupDao researchGroupDao; - @Autowired - private ScenarioDao scenarioDao; - @Autowired - private JavaMailSenderImpl mailSender; - @Autowired - private HierarchicalMessageSource messageSource; - @Autowired - private MailService mailService; - @Autowired - private PersonService personService; - - /** - * Added new weather to database - * - * @param request - * @param response - * @return - * @throws IOException - */ - public ModelAndView addNewWeather(HttpServletRequest request, HttpServletResponse response) throws IOException { - ModelAndView mav = new ModelAndView("experiments/JSonView"); - log.debug("WizardAjaxMultiController - Add new weather."); - String weatherTitle; - String weatherDescription; - Weather weather = null; - weatherTitle = request.getParameter("title"); - weatherDescription = request.getParameter("description"); - AddExperimentWizardCommand data = (AddExperimentWizardCommand)request.getSession().getAttribute("cz.zcu.kiv.eegdatabase.logic.controller.experiment.AddExperimentWizardController.FORM.addExperimentWizard") ; - ResearchGroup researchGroup = researchGroupDao.read(data.getResearchGroup()); - JSONObject jo = new JSONObject(); - if (!weatherTitle.equals("") && !weatherDescription.equals("") && weatherDao.canSaveNewTitle(weatherTitle,researchGroup.getResearchGroupId())) { - log.debug("Creating new weather object."); - weather = new Weather(); - weather.setTitle(weatherTitle); - weather.setDescription(weatherDescription); - weather.setDefaultNumber(0); - weatherDao.create(weather); - - weatherDao.createGroupRel(weather, researchGroup); - log.debug("Saving attribute - success: true"); - jo.put("success", true); - log.debug("Saving attribute - weatherId: " + weather.getWeatherId()); - jo.put("weatherId", weather.getWeatherId()); - } else { - log.debug("Saving attribute - success: false"); - jo.put("success", false); - } - log.debug("Saving JSONObject: " + jo); - mav.addObject("result", jo); - return mav; - } - - /** - * Method adds new hardware to database - * - * @param request - * @param response - * @return - * @throws IOException - */ - public ModelAndView addNewHardware(HttpServletRequest request, HttpServletResponse response) throws IOException { - ModelAndView mav = new ModelAndView("experiments/JSonView"); - log.debug("WizardAjaxMultiController - Add new hardware."); - - Hardware hardware = null; - String hardwareTitle; - String hardwareType; - String hardwareDescription; - AddExperimentWizardCommand data = (AddExperimentWizardCommand)request.getSession().getAttribute("cz.zcu.kiv.eegdatabase.logic.controller.experiment.AddExperimentWizardController.FORM.addExperimentWizard") ; - ResearchGroup researchGroup = researchGroupDao.read(data.getResearchGroup()); - hardwareTitle = request.getParameter("title"); - hardwareType = request.getParameter("type"); - hardwareDescription = request.getParameter("description"); - - JSONObject jo = new JSONObject(); - if (!hardwareTitle.equals("") && !hardwareType.equals("") && !hardwareDescription.equals("") && hardwareDao.canSaveNewTitle(hardwareTitle,researchGroup.getResearchGroupId())) { - // Creating new - log.debug("Creating new hardware object."); - hardware = new Hardware(); - hardware.setTitle(hardwareTitle); - hardware.setType(hardwareType); - hardware.setDescription(hardwareDescription); - hardware.setDefaultNumber(0); - hardwareDao.create(hardware); - hardwareDao.createGroupRel(hardware, researchGroup); - log.debug("Saving attribute - success: true"); - jo.put("success", true); - log.debug("Saving attribute - hardwareId: " + hardware.getHardwareId()); - jo.put("hardwareId", hardware.getHardwareId()); - } else { - log.debug("Saving attribute - success: false"); - jo.put("success", false); - } - log.debug("Saving JSONObject: " + jo); - mav.addObject("result", jo); - return mav; - } - - /** - * Adds new person to database - * - * @param request - * @param response - * @return - * @throws IOException - */ - public ModelAndView addNewPerson(HttpServletRequest request, HttpServletResponse response) throws IOException { - ModelAndView mav = new ModelAndView("experiments/JSonView"); - log.debug("WizardAjaxMultiController - Add new person."); - - Person person = null; - try { - person = personService.createPerson( - request.getParameter("givenname"), - request.getParameter("surname"), - request.getParameter("dateOfBirth"), - request.getParameter("email"), - request.getParameter("gender"), - request.getParameter("phoneNumber"), - request.getParameter("note"), - null - ); - mailService.sendRegistrationConfirmMail(person, RequestContextUtils.getLocale(request)); - } catch (MailException e) { - log.error("E-mail was NOT sent"); - log.error(e); - e.printStackTrace(); - } catch (ParseException e) {//throw futher? (code will fail anyway) - log.error(e); - } - - JSONObject jo = new JSONObject(); - - log.debug("Saving attribute - success: true"); - jo.put("success", true); - log.debug("Saving attribute - personId: " + person.getPersonId()); - jo.put("personId", person.getPersonId()); - - //log.debug("Generating username"); - //String username = apc.getGivenname().toLowerCase() + "-" + apc.getSurname().toLowerCase(); - log.debug("Saving JSONObject: " + jo); - mav.addObject("result", jo); - return mav; - } - - public ModelAndView addNewScenario(HttpServletRequest request, HttpServletResponse response) throws IOException { - ModelAndView mav = new ModelAndView("experiments/JSonView"); - log.debug("WizardAjaxMultiController - Add new scenario."); - //System.out.println("WizardAjaxMultiController - Add new scenario."); - JSONObject jo = new JSONObject(); - Scenario scenario = new Scenario(); - - int researchGroupId = 0; - String scenarioTitle = ""; - String scenarioLength = ""; - String scenarioDescription = ""; - String dataFile; - String privateNote; - - log.debug("Setting logged person."); - scenario.setPerson(personDao.getLoggedPerson()); - - MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; - - log.debug("Setting research group."); - researchGroupId = Integer.parseInt(multipartRequest.getParameter("researchGroup")); - ResearchGroup group = new ResearchGroup(); - group.setResearchGroupId(researchGroupId); - scenario.setResearchGroup(group); - scenarioTitle = multipartRequest.getParameter("scenarioTitle"); - log.debug("Setting scenario title: " + scenarioTitle); - scenario.setTitle(scenarioTitle); - - scenarioLength = multipartRequest.getParameter("length"); - log.debug("Setting scenario length: " + scenarioLength); - scenario.setScenarioLength(Integer.parseInt(scenarioLength)); - - scenarioDescription = multipartRequest.getParameter("scenarioDescription"); - log.debug("Setting scenario description: " + scenarioDescription); - scenario.setDescription(scenarioDescription); - - MultipartFile multipartFile = multipartRequest.getFile("dataFile"); - - scenario.setScenarioName(scenarioTitle + "text.fileTypeXml"); - scenario.setMimetype("text/xml"); - - /* researchGroupId = Integer.parseInt(request.getParameter("researchGroup")); - scenarioTitle = request.getParameter("scenarioTitle"); - scenarioLength = request.getParameter("length"); - scenarioDescription = request.getParameter("scenarioDescription"); - dataFile = request.getParameter("dataFile"); - privateNote = request.getParameter("privateNote"); - */ - - - log.debug("Setting private/public access"); - scenario.setPrivateScenario(true); - scenarioDao.create(scenario); - log.debug("Saving attribute - success: true"); - jo.put("success", true); - log.debug("Saving attribute - scenarioId: " + scenario.getScenarioId()); - jo.put("personId", scenario.getScenarioId()); - - - log.debug("Saving JSONObject: " + jo); - mav.addObject("result", jo); - return mav; - } -} - - diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/WizardController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/WizardController.java deleted file mode 100644 index 0c8a34d2..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/experiment/WizardController.java +++ /dev/null @@ -1,109 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * WizardController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.experiment; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -/** - * Created by IntelliJ IDEA. - * User: Jakub Balhar - * Date: 19.3.13 - * Time: 15:20 - */ -@Controller -public class WizardController { - - @RequestMapping(value="/experiments/wizard") - public ModelAndView scenario(){ - ModelAndView mav = new ModelAndView("experiments/scenario"); - return mav; - } - - @RequestMapping(value="/experiments/wizard/addARM") - public ModelAndView addARM(){ - ModelAndView mav = new ModelAndView("experiments/addARM"); - return mav; - } - - @RequestMapping(value="/experiments/wizard/addArtifact") - public ModelAndView addArtifact(){ - ModelAndView mav = new ModelAndView("experiments/addArtifact"); - return mav; - } - - @RequestMapping(value="/experiments/wizard/addDisease") - public ModelAndView addDisease(){ - ModelAndView mav = new ModelAndView("experiments/addDisease"); - return mav; - } - - @RequestMapping(value="/experiments/wizard/addGroup") - public ModelAndView addGroup(){ - ModelAndView mav = new ModelAndView("experiments/addGroup"); - return mav; - } - - @RequestMapping(value="/experiments/wizard/addHW") - public ModelAndView addHW(){ - ModelAndView mav = new ModelAndView("experiments/addHW"); - return mav; - } - - @RequestMapping(value="/experiments/wizard/addPerson") - public ModelAndView addPerson(){ - ModelAndView mav = new ModelAndView("experiments/addPerson"); - return mav; - } - - @RequestMapping(value="/experiments/wizard/addPharmaceutical") - public ModelAndView addPharmaceutical(){ - ModelAndView mav = new ModelAndView("experiments/addPharmaceutical"); - return mav; - } - - @RequestMapping(value="/experiments/wizard/addProjectType") - public ModelAndView addProjectType(){ - ModelAndView mav = new ModelAndView("experiments/addProjectType"); - return mav; - } - - @RequestMapping(value="/experiments/wizard/addScenario") - public ModelAndView addScenario(){ - ModelAndView mav = new ModelAndView("experiments/addScenario"); - return mav; - } - - @RequestMapping(value="/experiments/wizard/addStimulus") - public ModelAndView addStimulus(){ - ModelAndView mav = new ModelAndView("experiments/addStimulus"); - return mav; - } - - @RequestMapping(value="/experiments/wizard/addSW") - public ModelAndView addSW(){ - ModelAndView mav = new ModelAndView("experiments/addSW"); - return mav; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/AcceptRoleRequestController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/AcceptRoleRequestController.java deleted file mode 100644 index b8692b19..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/AcceptRoleRequestController.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AcceptRoleRequestController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.group; - -import cz.zcu.kiv.eegdatabase.data.dao.GenericDao; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; -import cz.zcu.kiv.eegdatabase.data.pojo.GroupPermissionRequest; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroupMembership; -import org.springframework.validation.BindException; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - - -/** - * @author M.Brozek - */ -public class AcceptRoleRequestController extends SimpleFormController { - private GenericDao gpr; - private ResearchGroupDao researchGroupDao; - - private PersonDao personDao; - private int requestId; - - - // - public AcceptRoleRequestController() { - setCommandClass(EditGroupRoleCommand.class); - setCommandName("editGroupRoleCommand"); - } - - - @Override - protected Map referenceData(HttpServletRequest request) throws Exception { - Map map = new HashMap(); - requestId = Integer.parseInt(request.getParameter("id")); - GroupPermissionRequest pr = gpr.read(requestId); - Person user = pr.getPerson(); //TODO fix: when requestId is not found, throws NullPointer - String choosenGroup = pr.getResearchGroup().getTitle(); - String requestRole = pr.getRequestedPermission(); - map.put("person", user); - map.put("requestRole", requestRole); - map.put("choosenGroup", choosenGroup); - GroupMultiController.setPermissionToRequestGroupRole(map, personDao.getLoggedPerson()); - return map; - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception { - EditGroupRoleCommand groupRoleCommand = (EditGroupRoleCommand) command; - GroupPermissionRequest actual = gpr.read(requestId); -// String role; -// if (groupRoleCommand.isAdmin()){ -// role = "ROLE_ADMIN"; -// } -// else { -// role = "ROLE_EXPERIMENTER"; -// } - actual.setRequestedPermission(groupRoleCommand.getRole()); - actual.setGranted(true); - gpr.update(actual); - - Person person = actual.getPerson(); - Set groups = person.getResearchGroupMemberships(); - for (ResearchGroupMembership member : groups) { - if ((member.getPerson().getPersonId() == person.getPersonId()) && - (member.getResearchGroup().getResearchGroupId() == actual.getResearchGroup().getResearchGroupId())) { - member.setAuthority(groupRoleCommand.getRole()); - - } - } - - ModelAndView mav = new ModelAndView(getSuccessView()); - return mav; - } - - - public ResearchGroupDao getResearchGroupDao() { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) { - this.researchGroupDao = researchGroupDao; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public GenericDao getGpr() { - return gpr; - } - - public void setGpr(GenericDao gpr) { - this.gpr = gpr; - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/AddBookingRoomViewParamsController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/AddBookingRoomViewParamsController.java deleted file mode 100644 index 793bec63..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/AddBookingRoomViewParamsController.java +++ /dev/null @@ -1,221 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddBookingRoomViewParamsController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.group; - -/** - * @author Jenda Kolena - */ - -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; -import cz.zcu.kiv.eegdatabase.data.dao.ReservationDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import cz.zcu.kiv.eegdatabase.data.pojo.Reservation; -import cz.zcu.kiv.eegdatabase.logic.util.BookingRoomUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.context.HierarchicalMessageSource; -import org.springframework.validation.BindException; -import org.springframework.validation.Errors; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; -import org.springframework.web.servlet.support.RequestContextUtils; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.*; - -public class AddBookingRoomViewParamsController extends SimpleFormController -{ - private Log log = LogFactory.getLog(getClass()); - private ReservationDao reservationDao; - private ResearchGroupDao researchGroupDao; - private PersonDao personDao; - private HierarchicalMessageSource messageSource; - - public AddBookingRoomViewParamsController() - { - setCommandClass(BookRoomCommand.class); - setCommandName("bookRoomCommand"); - } - - @Override - public Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception - { - Map map = new HashMap(); - - int filterGroup = Integer.parseInt(request.getParameter("filterGroup")); - String filterDate = request.getParameter("filterDate"); - if (filterDate.compareTo("") == 0) filterDate = null; - int repType = Integer.parseInt(request.getParameter("repType")); - int repCount = Integer.parseInt(request.getParameter("repCount")); - - String date = request.getParameter("date"); - String startStr = request.getParameter("startTime"); - String endStr = request.getParameter("endTime"); - - GregorianCalendar cal = BookingRoomUtils.getCalendar(startStr); - boolean collisions = false; - - //reservations in not visible time period - if (repCount > 0) - { - GregorianCalendar nextS = BookingRoomUtils.getCalendar(startStr); - GregorianCalendar nextE = BookingRoomUtils.getCalendar(endStr); - - List coll = BookingRoomUtils.getCollisions(reservationDao, repCount, repType, nextS, nextE); - - map.put("collisionsInNext", coll); - map.put("collisionsInNextCount", coll.size()); - if (coll.size() > 0) collisions = true; - } - - //reservations in currently visible time period - cal.set(Calendar.DAY_OF_WEEK, cal.getFirstDayOfWeek()); - GregorianCalendar weekStart = BookingRoomUtils.getCalendar(BookingRoomUtils.getDate(cal) + " 00:00:00"); - - GregorianCalendar weekEnd = (GregorianCalendar) weekStart.clone(); - weekEnd.add(Calendar.DAY_OF_YEAR, 7); - weekEnd.add(Calendar.SECOND, -1); - - map.put("reservations", reservationDao.getReservationsBetween(weekStart, weekEnd, filterDate, filterGroup)); - map.put("timerange", date + " " + BookingRoomUtils.getHoursAndMinutes(startStr) + " - " + BookingRoomUtils.getHoursAndMinutes(endStr)); - - String displayed = String.format(messageSource.getMessage("bookRoom.displayed.week", null, RequestContextUtils.getLocale(request)), BookingRoomUtils.getDate(weekStart), BookingRoomUtils.getDate(weekEnd)); - - boolean filtered = false; - - if (filterDate != null) - {//filter of date - filtered = true; - displayed = messageSource.getMessage("bookRoom.displayed.day", null, RequestContextUtils.getLocale(request)) + " " + filterDate; - } - - if (filterGroup > 0) - { - filtered = true; - displayed += (filterDate == null ? "," : " and") + " " + messageSource.getMessage("bookRoom.displayed.group", null, RequestContextUtils.getLocale(request)) + " " + getResearchGroup(filterGroup).getTitle(); - } - - if (filtered) - {//we must verify that there are no reservations in selected range - GregorianCalendar start = BookingRoomUtils.getCalendar(startStr); - GregorianCalendar end = BookingRoomUtils.getCalendar(endStr); - List coll = reservationDao.getReservationsBetween(start, end); - if (coll.size() > 0) - { - //if the collision exists - collisions = true; - map.put("collisions", coll); - map.put("collisionsCount", coll.size()); - } - } - - map.put("displayed", displayed); - - map.put("collisionsExist", (collisions) ? "1" : "0"); - - - /* - -- JSP can get this from params object -- - map.put("repCount", repCount); - map.put("repType", repType); - map.put("group", group); - map.put("date", date);*/ - map.put("startTime", BookingRoomUtils.getHoursAndMinutes(startStr).replaceAll(":", "")); - map.put("endTime", BookingRoomUtils.getHoursAndMinutes(endStr).replaceAll(":", "")); - map.put("loggedUser", personDao.getLoggedPerson()); - GroupMultiController.setPermissionToRequestGroupRole(map, personDao.getLoggedPerson()); - - return map; - } - - /** - * Method to get chosen researchgroup by id. - * - * @param id ID of the researchgroup. - * @return Chosen researchgroup. - * @throws Exception When researchgroup with ID does not exist. - */ - public ResearchGroup getResearchGroup(int id) throws Exception - { - Person user = personDao.getLoggedPerson(); - List groups = researchGroupDao.getResearchGroupsWhereMember(user); - groups.addAll(researchGroupDao.getResearchGroupsWhereOwner(user)); - groups.addAll(researchGroupDao.getResearchGroupsWhereUserIsGroupAdmin(user)); - - for (ResearchGroup group : groups) - if (group.getResearchGroupId() == id) return group; - - throw new Exception("ResearchGroup with id='" + id + "' was not found!"); - } - - @Override - public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception - { - ModelAndView mav = new ModelAndView(getSuccessView()); - return mav; - } - - - public HierarchicalMessageSource getMessageSource() - { - return messageSource; - } - - public void setMessageSource(HierarchicalMessageSource messageSource) - { - this.messageSource = messageSource; - } - - public ReservationDao getReservationDao() - { - return reservationDao; - } - - public void setReservationDao(ReservationDao reservationDao) - { - this.reservationDao = reservationDao; - } - - public ResearchGroupDao getResearchGroupDao() - { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) - { - this.researchGroupDao = researchGroupDao; - } - - public PersonDao getPersonDao() - { - return personDao; - } - - public void setPersonDao(PersonDao personDao) - { - this.personDao = personDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/AddMemberToGroupCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/AddMemberToGroupCommand.java deleted file mode 100644 index 798d6df0..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/AddMemberToGroupCommand.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddMemberToGroupCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.group; - -/** - * @author Jindra - */ -public class AddMemberToGroupCommand { - - private int groupFormId = -1; - private String userName; - private String userRole; - - public int getGroupFormId() { - return groupFormId; - } - - public void setGroupFormId(int groupFormId) { - this.groupFormId = groupFormId; - } - - public String getUserName() { - return userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - public String getUserRole() { - return userRole; - } - - public void setUserRole(String userRole) { - this.userRole = userRole; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/AddMemberToGroupController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/AddMemberToGroupController.java deleted file mode 100644 index e04d00f9..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/AddMemberToGroupController.java +++ /dev/null @@ -1,138 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddMemberToGroupController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package cz.zcu.kiv.eegdatabase.logic.controller.group; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.service.DataService; -import cz.zcu.kiv.eegdatabase.logic.Util; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.BindException; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * @author Jindra - */ -public class AddMemberToGroupController - extends SimpleFormController - implements Validator { - - private AuthorizationManager auth; - @Autowired - private DataService dataService; - @Autowired - private PersonDao personDao; - - public AddMemberToGroupController() { - setCommandClass(AddMemberToGroupCommand.class); - setCommandName("addMemberToGroup"); - } - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } - - @Override - protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception { - ModelAndView mav = super.showForm(request, response, errors); - - int groupId = 0; - try { - groupId = Integer.parseInt(request.getParameter("groupId")); - } catch (NumberFormatException e) { - return new ModelAndView("redirect:/groups/list.html"); - } - mav.addObject("groupId", groupId); - mav.addObject("groupTitle", dataService.getResearchGroupTitle(groupId)); - GroupMultiController.setPermissionToRequestGroupRole(mav, personDao.getLoggedPerson()); - - return mav; - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { - ModelAndView mav = super.onSubmit(request, response, command, errors); - - int groupId = 0; - try { - groupId = Integer.parseInt(request.getParameter("groupId")); - } catch (NumberFormatException e) { - return new ModelAndView("redirect:/groups/list.html"); - } - - if (!auth.userIsAdminInGroup(groupId)) { - return new ModelAndView("redirect:/groups/detail.html?groupId=" + groupId); - } - - AddMemberToGroupCommand data = (AddMemberToGroupCommand) command; - - - // Now we can add the user into group - dataService.addMemberToResearchGroup(data.getUserName(), - data.getGroupFormId(), - data.getUserRole()); - - mav = new ModelAndView("redirect:/groups/list-of-members.html?groupId=" + groupId); - - return mav; - } - - public boolean supports(Class type) { - return type.equals(AddMemberToGroupCommand.class); - } - - public void validate(Object command, Errors errors) { - AddMemberToGroupCommand data = (AddMemberToGroupCommand) command; - - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "userName", "required.field"); - if (data.getUserRole().equals("-1")) { - errors.rejectValue("userRole", "required.userRole"); - } else if (!(data.getUserRole().equals(Util.GROUP_ADMIN) - || data.getUserRole().equals(Util.GROUP_EXPERIMENTER) - || data.getUserRole().equals(Util.GROUP_READER))) { - errors.rejectValue("userRole", "invalid.userRole"); - } - - if (!dataService.usernameExists(data.getUserName())) { - errors.rejectValue("userName", "invalid.userNameDoesNotExist"); - - } else if (dataService.userNameInGroup(data.getUserName(), data.getGroupFormId())) { - errors.rejectValue("userName", "invalid.userNameAlreadyInGroup"); - } - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/BookRoomCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/BookRoomCommand.java deleted file mode 100644 index 672d8bcf..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/BookRoomCommand.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * BookRoomCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.group; - -import cz.zcu.kiv.eegdatabase.logic.util.BookingRoomUtils; - -import java.sql.Timestamp; -import java.util.GregorianCalendar; - -/** - * @author Jenda Kolena - */ -public class BookRoomCommand { - - private int selectedGroup; - private String date; - private String startTime; - private GregorianCalendar startTimeCal; - private String endTime; - private GregorianCalendar endTimeCal; - private int repCount; - private int repType; - - public void setSelectedGroup(int selectedGroup) { - this.selectedGroup = selectedGroup; - } - - public int getSelectedGroup() { - return selectedGroup; - } - - - public void setDate(String date) throws Exception { - this.date = date; - } - - public String getDate() { - return date; - } - - public void setRepCount(int repCount) { - this.repCount = repCount; - } - - public int getRepCount() { - return repCount; - } - - public void setRepType(int repType) { - this.repType = repType; - } - - public int getRepType() { - return repType; - } - - public void setEndTime(String endTime) { - this.endTime = endTime; - endTimeCal = BookingRoomUtils.getCalendar(endTime); - } - - public String getEndTime() { - return endTime; - } - - public GregorianCalendar getEndTimeCal() { - return endTimeCal; - } - - - public Timestamp getEndTimeTimestamp() { - return new Timestamp(endTimeCal.getTimeInMillis()); - } - - - public void setStartTime(String startTime) { - this.startTime = startTime; - startTimeCal = BookingRoomUtils.getCalendar(startTime); - } - - public String getStartTime() { - return startTime; - } - - public GregorianCalendar getStartTimeCal() { - return startTimeCal; - } - - public Timestamp getStartTimeTimestamp() { - return new Timestamp(getStartTimeCal().getTimeInMillis()); - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/BookingRoomAjaxController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/BookingRoomAjaxController.java deleted file mode 100644 index 1077b3f4..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/BookingRoomAjaxController.java +++ /dev/null @@ -1,181 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * BookingRoomAjaxController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.group; - -/** - * @author Jenda Kolena - */ - -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; -import cz.zcu.kiv.eegdatabase.data.dao.ReservationDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Reservation; -import cz.zcu.kiv.eegdatabase.logic.util.BookingRoomUtils; -import cz.zcu.kiv.eegdatabase.logic.util.BookingRoomXmlUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.context.HierarchicalMessageSource; -import org.springframework.validation.BindException; -import org.springframework.validation.Errors; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; -import org.springframework.web.servlet.support.RequestContextUtils; - -import javax.naming.directory.InvalidAttributeValueException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.Calendar; -import java.util.GregorianCalendar; -import java.util.HashMap; -import java.util.Map; - -public class BookingRoomAjaxController - extends SimpleFormController -{ - - private Log log = LogFactory.getLog(getClass()); - - private ReservationDao reservationDao; - private ResearchGroupDao researchGroupDao; - private PersonDao personDao; - private HierarchicalMessageSource messageSource; - - public BookingRoomAjaxController() - { - setCommandClass(BookRoomCommand.class); - setCommandName("bookRoomCommand"); - } - - @Override - public Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception - { - Map map = new HashMap(); - GroupMultiController.setPermissionToRequestGroupRole(map, personDao.getLoggedPerson()); - - if (request.getParameter("type").compareTo("info") == 0) - { - int id = Integer.parseInt(request.getParameter("id")); - Reservation reservation = reservationDao.getReservationById(id); - GregorianCalendar created = new GregorianCalendar(); - created.setTime(reservation.getCreationTime()); - GregorianCalendar startTime = new GregorianCalendar(); - startTime.setTime(reservation.getStartTime()); - GregorianCalendar endTime = new GregorianCalendar(); - endTime.setTime(reservation.getEndTime()); - - Map data = new HashMap(); - data.put("id", id); - data.put("person", reservation.getPerson()); - data.put("created", BookingRoomUtils.getDate(created) + ", " + BookingRoomUtils.getTime(created)); - data.put("date", BookingRoomUtils.getDate(startTime)); - data.put("start", BookingRoomUtils.getHoursAndMinutes(startTime)); - data.put("end", BookingRoomUtils.getHoursAndMinutes(endTime)); - - map.put("data", data); - return map; - } - - if (request.getParameter("type").compareTo("delete") == 0) - { - int id = Integer.parseInt(request.getParameter("id")); - - if (reservationDao.deleteReservation(id)) - { - map.put("status", messageSource.getMessage("bookRoom.delete.success", null, RequestContextUtils.getLocale(request))); - } - else - { - map.put("status", messageSource.getMessage("bookRoom.delete.error", null, RequestContextUtils.getLocale(request))); - } - - return map; - } - - if (request.getParameter("type").compareTo("timeline") == 0) - { - String date = request.getParameter("date") + " 00:00:00"; - log.debug("XML DATE=" + date); - GregorianCalendar monthStart = BookingRoomUtils.getCalendar(date); - monthStart.set(Calendar.DAY_OF_MONTH, 1); - GregorianCalendar monthEnd = (GregorianCalendar) monthStart.clone(); - monthEnd.add(Calendar.MONTH, 1); - monthEnd.add(Calendar.SECOND, -1); - - String xml = BookingRoomXmlUtils.formatReservationsList(reservationDao.getReservationsBetween(monthStart, monthEnd), personDao.getLoggedPerson()); - - map.put("xmlContent", xml); - return map; - } - - throw new InvalidAttributeValueException("Attribute '" + request.getParameter("type") + "' is not allowed!"); - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception - { - - ModelAndView mav = new ModelAndView(getSuccessView()); - return mav; - } - - - public HierarchicalMessageSource getMessageSource() - { - return messageSource; - } - - public void setMessageSource(HierarchicalMessageSource messageSource) - { - this.messageSource = messageSource; - } - - public ReservationDao getReservationDao() - { - return reservationDao; - } - - public void setReservationDao(ReservationDao reservationDao) - { - this.reservationDao = reservationDao; - } - - public ResearchGroupDao getResearchGroupDao() - { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) - { - this.researchGroupDao = researchGroupDao; - } - - public PersonDao getPersonDao() - { - return personDao; - } - - public void setPersonDao(PersonDao personDao) - { - this.personDao = personDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/BookingRoomController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/BookingRoomController.java deleted file mode 100644 index 81525eb9..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/BookingRoomController.java +++ /dev/null @@ -1,233 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * BookingRoomController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.group; - -/** - * @author Jenda Kolena - */ - -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; -import cz.zcu.kiv.eegdatabase.data.dao.ReservationDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import cz.zcu.kiv.eegdatabase.data.pojo.Reservation; -import cz.zcu.kiv.eegdatabase.logic.util.BookingRoomUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.context.HierarchicalMessageSource; -import org.springframework.validation.BindException; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; -import org.springframework.web.servlet.support.RequestContextUtils; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.sql.Timestamp; -import java.util.*; - -public class BookingRoomController extends SimpleFormController -{ - private Log log = LogFactory.getLog(getClass()); - private PersonDao personDao; - private ResearchGroupDao researchGroupDao; - private ReservationDao reservationDao; - private HierarchicalMessageSource messageSource; - - private String status = null; - private String comment = null; - - public BookingRoomController() - { - setCommandClass(BookRoomCommand.class); - setCommandName("bookRoomCommand"); - } - - @Override - public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object comm, BindException bindException) throws Exception - { - try - { - BookRoomCommand command = (BookRoomCommand) comm; - status = messageSource.getMessage("bookRoom.controllerMessages.status.fail", null, RequestContextUtils.getLocale(request)); - comment = messageSource.getMessage("bookRoom.controllerMessages.comment.error.unknown", null, RequestContextUtils.getLocale(request)); - - Person user = personDao.getLoggedPerson(); - int group = command.getSelectedGroup(); - int repType = command.getRepType(); - int repCount = command.getRepCount(); - String startStr = BookingRoomUtils.getHoursAndMinutes(command.getStartTimeCal()); - String endStr = BookingRoomUtils.getHoursAndMinutes(command.getEndTimeCal()); - - Reservation res = new Reservation(); - - Timestamp createTime = new Timestamp(new GregorianCalendar().getTimeInMillis()); - res.setCreationTime(createTime); - res.setStartTime(command.getStartTimeTimestamp()); - res.setEndTime(command.getEndTimeTimestamp()); - - res.setPerson(user); - - //searching for ResearchGroup - ResearchGroup grp = getResearchGroup(group); - res.setResearchGroup(grp); - - log.debug("Reservation has been created: " + ((res == null) ? "false" : "true")); - reservationDao.create(res); - - if (repCount > 0) - { - comment = messageSource.getMessage("bookRoom.controllerMessages.comment.booked.multiple.part1", null, RequestContextUtils.getLocale(request)); - comment += command.getDate() + ", from " + startStr + " to " + endStr + "
\n"; - - GregorianCalendar nextS = command.getStartTimeCal(); - GregorianCalendar nextE = command.getEndTimeCal(); - - for (int i = 0; i < repCount; i++) - { - //shift of dates - int add = BookingRoomUtils.getWeeksAddCount(repType, i); - nextS.add(Calendar.WEEK_OF_YEAR, add); - nextE.add(Calendar.WEEK_OF_YEAR, add); - Reservation newReservation = new Reservation(); - newReservation.setCreationTime(createTime); - newReservation.setStartTime(new Timestamp(nextS.getTimeInMillis())); - newReservation.setEndTime(new Timestamp(nextE.getTimeInMillis())); - newReservation.setPerson(user); - newReservation.setResearchGroup(grp); - reservationDao.create(newReservation); - - comment += BookingRoomUtils.getDate(nextS) + ", from " + BookingRoomUtils.getHoursAndMinutes(nextS) + " to " + BookingRoomUtils.getHoursAndMinutes(nextE) + "
\n"; - } - - comment += String.format(messageSource.getMessage("bookRoom.controllerMessages.comment.booked.multiple.part2", null, RequestContextUtils.getLocale(request)), repCount + 1);//+1 because we need count "original" reservation! - } - else - { - comment = String.format(messageSource.getMessage("bookRoom.controllerMessages.comment.booked.single", null, RequestContextUtils.getLocale(request)), command.getDate(), startStr, endStr); - } - - status = messageSource.getMessage("bookRoom.controllerMessages.status.ok", null, RequestContextUtils.getLocale(request)); - } catch (Exception e) - { - log.error("Exception: " + e.getMessage() + "\n" + e.getStackTrace()[0].getFileName() + " at line " + e.getStackTrace()[0].getLineNumber(), e); - - status = messageSource.getMessage("bookRoom.controllerMessages.status.fail", null, RequestContextUtils.getLocale(request)); - comment = messageSource.getMessage("bookRoom.controllerMessages.comment.error.exception", null, RequestContextUtils.getLocale(request)) + " " + e.getMessage(); - } - - log.debug("Returning MAV" + " with status=" + status + "&comment=" + comment); - ModelAndView mav = new ModelAndView(getSuccessView()/* + "?status=" + status + "&comment=" + comment*/); - - return mav; - } - - /** - * Method to get chosen researchgroup by id. - * - * @param id ID of the researchgroup. - * @return Chosen researchgroup. - * @throws Exception When researchgroup with ID does not exist. - */ - private ResearchGroup getResearchGroup(int id) throws Exception - { - Person user = personDao.getLoggedPerson(); - List groups = researchGroupDao.getResearchGroupsWhereMember(user); - groups.addAll(researchGroupDao.getResearchGroupsWhereOwner(user)); - groups.addAll(researchGroupDao.getResearchGroupsWhereUserIsGroupAdmin(user)); - - for (ResearchGroup group : groups) - if (group.getResearchGroupId() == id) return group; - - throw new Exception("ResearchGroup with id='" + id + "' was not found!"); - } - - - @Override - public Map referenceData(HttpServletRequest request) throws Exception - { - Map map = new HashMap(); - List researchGroupList = - researchGroupDao.getResearchGroupsWhereAbleToWriteInto(personDao.getLoggedPerson()); - ResearchGroup defaultGroup = personDao.getLoggedPerson().getDefaultGroup(); - int defaultGroupId = (defaultGroup != null) ? defaultGroup.getResearchGroupId() : 0; - map.put("defaultGroupId", defaultGroupId); - map.put("researchGroupList", researchGroupList); - - //if status or comment is prepared, send then delete them - if (status != null) - { - map.put("status", new String(status)); - status = null; - } - if (comment != null) - { - map.put("comment", new String(comment)); - comment = null; - } - - GroupMultiController.setPermissionToRequestGroupRole(map, personDao.getLoggedPerson()); - return map; - } - - public HierarchicalMessageSource getMessageSource() - { - return messageSource; - } - - public void setMessageSource(HierarchicalMessageSource messageSource) - { - this.messageSource = messageSource; - } - - public PersonDao getPersonDao() - { - return personDao; - } - - public void setPersonDao(PersonDao personDao) - { - this.personDao = personDao; - } - - public ResearchGroupDao getResearchGroupDao() - { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) - { - this.researchGroupDao = researchGroupDao; - } - - - public ReservationDao getReservationDao() - { - return reservationDao; - } - - public void setReservationDao(ReservationDao reservationDao) - { - this.reservationDao = reservationDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/CreateGroupCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/CreateGroupCommand.java deleted file mode 100644 index a96e1fd1..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/CreateGroupCommand.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * CreateGroupCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.group; - -/** - * @author Jindrich Pergler - */ -public class CreateGroupCommand { - - private int id; - private String researchGroupTitle; - private String researchGroupDescription; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getResearchGroupDescription() { - return researchGroupDescription; - } - - public void setResearchGroupDescription(String researchGroupDescription) { - this.researchGroupDescription = researchGroupDescription; - } - - public String getResearchGroupTitle() { - return researchGroupTitle; - } - - public void setResearchGroupTitle(String researchGroupTitle) { - this.researchGroupTitle = researchGroupTitle; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/CreateGroupController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/CreateGroupController.java deleted file mode 100644 index d029f5dc..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/CreateGroupController.java +++ /dev/null @@ -1,206 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * CreateGroupController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.group; - -import cz.zcu.kiv.eegdatabase.data.dao.*; -import cz.zcu.kiv.eegdatabase.data.pojo.*; -import cz.zcu.kiv.eegdatabase.data.service.DataService; -import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.*; - -import java.util.List; - - -/** - * @author Jindrich Pergler - */ -@Controller -@SessionAttributes("createGroup") -public class CreateGroupController { - private Log log = LogFactory.getLog(getClass()); - @Autowired - private DataService dataService; - @Autowired - private ResearchGroupDao researchGroupDao; - @Autowired - private AuthorizationManager auth; - - @Autowired - private PersonDao personDao; - @Autowired - private HardwareDao hardwareDao; - @Autowired - private WeatherDao weatherDao; - @Autowired - private ExperimentOptParamDefDao experimentOptParamDefDao; - @Autowired - private FileMetadataParamDefDao fileMetadataParamDefDao; - @Autowired - private PersonOptParamDefDao personOptParamDefDao; - - private CreateGroupValidator createGroupValidator; - - @Autowired - public CreateGroupController(CreateGroupValidator createGroupValidator){ - this.createGroupValidator = createGroupValidator; - } - - @RequestMapping(value="groups/create-group.html",method= RequestMethod.GET) - protected String showForm(ModelMap model) { - CreateGroupCommand data = new CreateGroupCommand(); - model.addAttribute("createGroup",data); - GroupMultiController.setPermissionToRequestGroupRole(model, personDao.getLoggedPerson()); - return "groups/createGroupForm"; - } - - @RequestMapping(value="groups/edit.html",method= RequestMethod.GET) - protected String showEditForm(@RequestParam("groupId") String idString,ModelMap model) { - CreateGroupCommand data = new CreateGroupCommand(); - if (idString != null) { - // Editing existing group - int id = Integer.parseInt(idString); - if (!auth.userIsAdminInGroup(id)) { - return "redirect:/groups/detail.html?groupId=" + id; - } - } - if (idString != null) { - // Editing existing hardware - int id = Integer.parseInt(idString); - - log.debug("Loading research group to the command object for editing."); - ResearchGroup researchGroup = researchGroupDao.read(id); - - data.setId(researchGroup.getResearchGroupId()); - data.setResearchGroupTitle(researchGroup.getTitle()); - data.setResearchGroupDescription(researchGroup.getDescription()); - } - model.addAttribute("createGroup",data); - GroupMultiController.setPermissionToRequestGroupRole(model, personDao.getLoggedPerson()); - return "groups/createGroupForm"; - } - - @RequestMapping(method= RequestMethod.POST) - protected String onSubmit(@ModelAttribute("createGroup") CreateGroupCommand data, BindingResult result, ModelMap model) throws Exception { - createGroupValidator.validate(data, result); - if (result.hasErrors()) { - return "groups/createGroupForm"; - } - - log.debug("Processing form data with CreateGroupController."); - ResearchGroup researchGroup; - if (data.getId() > 0) { - // Editing - log.debug("Editing existing research group."); - researchGroup = researchGroupDao.read(data.getId()); - researchGroup.setTitle(data.getResearchGroupTitle()); - researchGroup.setDescription(data.getResearchGroupDescription()); - } else { - // Creating new - log.debug("Creating new research group."); - researchGroup = dataService.createResearchGroup(data.getResearchGroupTitle(), - data.getResearchGroupDescription(), - ControllerUtils.getLoggedUserName()); - addDefaultLists(researchGroup); - } - return "redirect:/groups/detail.html?groupId=" + researchGroup.getResearchGroupId(); - } - - private void addDefaultLists(ResearchGroup researchGroup){ - List hardwareList = hardwareDao.getDefaultRecords(); - Hardware hardware; - Weather weather; - PersonOptParamDef personOptParamDef; - FileMetadataParamDef fileMetadataParamDef; - ExperimentOptParamDef experimentOptParamDef; - - for(int i = 0;i< hardwareList.size();i++){ - hardware = new Hardware(); - hardware.setDefaultNumber(0); - hardware.setDescription(hardwareList.get(i).getDescription()); - hardware.setTitle(hardwareList.get(i).getTitle()); - hardware.setType(hardwareList.get(i).getType()); - hardwareDao.create(hardware); - hardwareDao.createGroupRel(hardware,researchGroup); - } - List weatherList = weatherDao.getDefaultRecords(); - for(int i = 0;i< weatherList.size();i++){ - weather = new Weather(); - weather.setDefaultNumber(0); - weather.setDescription(weatherList.get(i).getDescription()); - weather.setTitle(weatherList.get(i).getTitle()); - weatherDao.create(weather); - weatherDao.createGroupRel(weather,researchGroup); - } - - List personOptParamDefList = personOptParamDefDao.getDefaultRecords(); - for(int i = 0;i< personOptParamDefList.size();i++){ - personOptParamDef = new PersonOptParamDef(); - personOptParamDef.setDefaultNumber(0); - personOptParamDef.setParamDataType(personOptParamDefList.get(i).getParamDataType()); - personOptParamDef.setParamName(personOptParamDefList.get(i).getParamName()); - personOptParamDefDao.create(personOptParamDef); - personOptParamDefDao.createGroupRel(personOptParamDef,researchGroup); - } - List fileMetadataParamDefList = fileMetadataParamDefDao.getDefaultRecords(); - for(int i = 0;i< fileMetadataParamDefList.size();i++){ - fileMetadataParamDef = new FileMetadataParamDef(); - fileMetadataParamDef.setDefaultNumber(0); - fileMetadataParamDef.setParamDataType(fileMetadataParamDefList.get(i).getParamDataType()); - fileMetadataParamDef.setParamName(fileMetadataParamDefList.get(i).getParamName()); - fileMetadataParamDefDao.create(fileMetadataParamDef); - fileMetadataParamDefDao.createGroupRel(fileMetadataParamDef,researchGroup); - } - List experimentOptParamDefList = experimentOptParamDefDao.getDefaultRecords(); - for(int i = 0;i< experimentOptParamDefList.size();i++){ - experimentOptParamDef = new ExperimentOptParamDef(); - experimentOptParamDef.setDefaultNumber(0); - experimentOptParamDef.setParamDataType(experimentOptParamDefList.get(i).getParamDataType()); - experimentOptParamDef.setParamName(experimentOptParamDefList.get(i).getParamName()); - experimentOptParamDefDao.create(experimentOptParamDef); - experimentOptParamDefDao.createGroupRel(experimentOptParamDef,researchGroup); - } - } - - public ResearchGroupDao getResearchGroupDao() { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) { - this.researchGroupDao = researchGroupDao; - } - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } -} - diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/CreateGroupValidator.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/CreateGroupValidator.java deleted file mode 100644 index 81003ffb..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/CreateGroupValidator.java +++ /dev/null @@ -1,55 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * CreateGroupValidator.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.group; - -import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -public class CreateGroupValidator implements Validator { - @Autowired - private ResearchGroupDao researchGroupDao; - - public boolean supports(Class aClass) { - return aClass.equals(CreateGroupCommand.class); - } - - public void validate(Object command, Errors errors) { - CreateGroupCommand data = (CreateGroupCommand) command; - - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "researchGroupTitle", "required.field"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "researchGroupDescription", "required.field"); - - if (!researchGroupDao.canSaveTitle(data.getResearchGroupTitle(), data.getId())) { - errors.rejectValue("researchGroupTitle", "error.valueAlreadyInDatabase"); - } - if (data.getResearchGroupTitle().length() > 100) { - errors.rejectValue("researchGroupTitle", "invalid.maxGroupTitleLength"); - } - if (data.getResearchGroupDescription().length() > 250) { - errors.rejectValue("researchGroupDescription", "invalid.maxGroupDescriptionLength"); - } - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/EditGroupRoleCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/EditGroupRoleCommand.java deleted file mode 100644 index efc8cc53..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/EditGroupRoleCommand.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * EditGroupRoleCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.group; - -/** - * @author Miroslav Brozek - */ -public class EditGroupRoleCommand { - private int editedGroup; - private boolean admin; - private String role; - private String group; - private String user; - - public String getGroup() { - return group; - } - - - public void setGroup(String group) { - this.group = group; - } - - - public String getRole() { - return role; - } - - public void setRole(String role) { - this.role = role; - } - - public String getUser() { - return user; - } - - public void setUser(String user) { - this.user = user; - } - - public boolean isAdmin() { - return admin; - } - - public void setAdmin(boolean admin) { - this.admin = admin; - } - - public int getEditedGroup() { - return editedGroup; - } - - public void setEditedGroup(int editedGroup) { - this.editedGroup = editedGroup; - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/EditGroupRoleController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/EditGroupRoleController.java deleted file mode 100644 index 29f24b61..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/EditGroupRoleController.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * EditGroupRoleController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.group; - -import cz.zcu.kiv.eegdatabase.data.dao.GenericDao; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; -import cz.zcu.kiv.eegdatabase.data.pojo.GroupPermissionRequest; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import cz.zcu.kiv.eegdatabase.data.service.MailService; -import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.context.HierarchicalMessageSource; -import org.springframework.mail.MailException; -import org.springframework.mail.SimpleMailMessage; -import org.springframework.mail.javamail.JavaMailSenderImpl; -import org.springframework.mail.javamail.MimeMessageHelper; -import org.springframework.validation.BindException; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; -import org.springframework.web.servlet.support.RequestContextUtils; - -import javax.mail.internet.MimeMessage; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class EditGroupRoleController extends SimpleFormController { - private Log log = LogFactory.getLog(getClass()); - private PersonDao personDao; - private ResearchGroupDao researchGroupDao; - private GenericDao groupPermissionRequestDao; - private MailService mailService; - - /** - * Source of localized messages defined in persistence.xml - */ - private HierarchicalMessageSource messageSource; - - public EditGroupRoleController() { - setCommandClass(EditGroupRoleCommand.class); - setCommandName("editGroupRoleCommand"); - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception { - EditGroupRoleCommand groupRoleCommand = (EditGroupRoleCommand) command; - - Person user = personDao.getPerson(ControllerUtils.getLoggedUserName()); - GroupPermissionRequest gpr = new GroupPermissionRequest(); - gpr.setPerson(user); - String requestRole = groupRoleCommand.getRole(); - gpr.setRequestedPermission(requestRole); - gpr.setResearchGroup(researchGroupDao.read(groupRoleCommand.getEditedGroup())); - groupPermissionRequestDao.create(gpr); - - String researchGroupTitle = researchGroupDao.read(groupRoleCommand.getEditedGroup()).getTitle(); - String emailAdmin = researchGroupDao.read(groupRoleCommand.getEditedGroup()).getPerson().getEmail(); - - try { - mailService.sendRequestForGroupRoleMail(emailAdmin, gpr.getRequestId(), user.getUsername(), - researchGroupTitle, RequestContextUtils.getLocale(request)); - } catch (MailException e) { - log.debug("E-mail was NOT sent"); - e.printStackTrace(); - } - - log.debug("Returning MAV"); - ModelAndView mav = new ModelAndView("groups/requestSent"); - GroupMultiController.setPermissionToRequestGroupRole(mav, personDao.getLoggedPerson()); - return mav; - } - - @Override - protected Map referenceData(HttpServletRequest request) throws Exception { - Map map = new HashMap(); - List researchGroupList = - researchGroupDao.getResearchGroupsWhereMember(personDao.getLoggedPerson()); - ResearchGroup defaultGroup = personDao.getLoggedPerson().getDefaultGroup(); - int defaultGroupId = (defaultGroup != null) ? defaultGroup.getResearchGroupId() : 0; - map.put("defaultGroupId", defaultGroupId); - map.put("researchGroupList", researchGroupList); - GroupMultiController.setPermissionToRequestGroupRole(map, personDao.getLoggedPerson()); - return map; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public ResearchGroupDao getResearchGroupDao() { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) { - this.researchGroupDao = researchGroupDao; - } - - public GenericDao getGroupPermissionRequestDao() { - return groupPermissionRequestDao; - } - - public void setGroupPermissionRequestDao(GenericDao groupPermissionRequestDao) { - this.groupPermissionRequestDao = groupPermissionRequestDao; - } - - /** - * @return the messageSource - */ - public HierarchicalMessageSource getMessageSource() { - return messageSource; - } - - /** - * @param messageSource the messageSource to set - */ - public void setMessageSource(HierarchicalMessageSource messageSource) { - this.messageSource = messageSource; - } - - public MailService getMailService() { - return mailService; - } - - public void setMailService(MailService mailService) { - this.mailService = mailService; - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/GroupMultiController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/GroupMultiController.java deleted file mode 100644 index d514e02e..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/GroupMultiController.java +++ /dev/null @@ -1,220 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * GroupMultiController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.group; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.GenericDao; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroupMembership; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroupMembershipId; -import cz.zcu.kiv.eegdatabase.logic.Util; -import cz.zcu.kiv.eegdatabase.logic.util.Paginator; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.multiaction.MultiActionController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.List; -import java.util.Map; - -/** - * Delegate class for multicontroller which processes groups section. - * - * @author Jindrich Pergler - */ -public class GroupMultiController extends MultiActionController { - - private AuthorizationManager auth; - private ResearchGroupDao researchGroupDao; - private PersonDao personDao; - private GenericDao membershipDao; - private static final int ITEMS_PER_PAGE = 20; - - public ModelAndView editGroupRole(HttpServletRequest request, HttpServletResponse response) { - ModelAndView mav = new ModelAndView("groups/editGroupRole"); - setPermissionToRequestGroupRole(mav, personDao.getLoggedPerson()); - return mav; - } - - public ModelAndView list(HttpServletRequest request, HttpServletResponse response) { - ModelAndView mav = new ModelAndView("groups/list"); - setPermissionToRequestGroupRole(mav, personDao.getLoggedPerson()); - - Paginator paginator = new Paginator(researchGroupDao.getCountForList(), ITEMS_PER_PAGE); - int page = 1; - try { - page = Integer.parseInt(request.getParameter("page")); - } catch (Exception e) { - } - paginator.setActualPage(page); - - List list = researchGroupDao.getGroupsForList(paginator.getFirstItemIndex(), ITEMS_PER_PAGE); - mav.addObject("groupList", list); - mav.addObject("paginator", paginator.getLinks()); - return mav; - } - - public ModelAndView myGroups(HttpServletRequest request, HttpServletResponse response) { - ModelAndView mav = new ModelAndView("groups/myGroupsList"); - setPermissionToRequestGroupRole(mav, personDao.getLoggedPerson()); - List ownedList = researchGroupDao.getResearchGroupsWhereOwner(personDao.getLoggedPerson()); - mav.addObject("ownedList", ownedList); - List memberList = researchGroupDao.getResearchGroupsWhereMember(personDao.getLoggedPerson()); - mav.addObject("memberList", memberList); - return mav; - } - - public ModelAndView detail(HttpServletRequest request, HttpServletResponse response) { - ModelAndView mav = new ModelAndView("groups/detail"); - setPermissionToRequestGroupRole(mav, personDao.getLoggedPerson()); - int id = Integer.parseInt(request.getParameter("groupId")); - - mav.addObject("userIsMemberInGroup", auth.userIsMemberInGroup(id)); - mav.addObject("userIsExperimenterInGroup", auth.userIsExperimenterInGroup(id)); - mav.addObject("userIsAdminInGroup", auth.userIsAdminInGroup(id)); - - ResearchGroup group = researchGroupDao.read(id); - mav.addObject("researchGroup", group); - return mav; - } - - public ModelAndView listOfMembers(HttpServletRequest request, HttpServletResponse response) { - ModelAndView mav = new ModelAndView("groups/listOfMembers"); - setPermissionToRequestGroupRole(mav, personDao.getLoggedPerson()); - - int groupId = 0; - try { - groupId = Integer.parseInt(request.getParameter("groupId")); - } catch (NumberFormatException e) { - } - - if (!auth.userIsExperimenterInGroup(groupId)) { - mav.setViewName("redirect:/groups/detail.html?groupId=" + groupId); - return mav; - } -// - mav.addObject("userIsAdminInGroup", auth.userIsAdminInGroup(groupId)); - mav.addObject("memberList", researchGroupDao.getListOfGroupMembers(groupId)); - mav.addObject("groupId", groupId); - mav.addObject("groupTitle", researchGroupDao.read(groupId).getTitle()); - return mav; - } - - public ModelAndView changeRole(HttpServletRequest request, HttpServletResponse response) { - // If we don't get the group id, redirect to list of groups - ModelAndView mav = new ModelAndView("redirect:/groups/list.html"); - setPermissionToRequestGroupRole(mav, personDao.getLoggedPerson()); - - int groupId = 0; - int personId = 0; - String role = ""; - try { - groupId = Integer.parseInt(request.getParameter("groupId")); - // Now we know the group id, so we change the redirect to the list of members - mav.setViewName("redirect:/groups/list-of-members.html?groupId=" + groupId); - personId = Integer.parseInt(request.getParameter("personId")); - role = request.getParameter("role"); - } catch (NumberFormatException e) { - return mav; - } - - if (!auth.userIsAdminInGroup(groupId)) { - // If user has no permission for changing role, we will return back to the list of members - return mav; - } - - if ((!role.equals(Util.GROUP_ADMIN)) - && (!role.equals(Util.GROUP_EXPERIMENTER)) - && (!role.equals(Util.GROUP_READER)) - && (!role.equals("REMOVE"))) { - // If specified role is not correct, return MAV so we return back with no changes - return mav; - } - - // Now we can make changes - ResearchGroupMembership membership = membershipDao.read(new ResearchGroupMembershipId(personId, groupId)); - if (role.equals("REMOVE")) { - membershipDao.delete(membership); - } else { - membership.setAuthority(role); - } - - return mav; - } - - /** - * @return true if user has ROLE_ADMIN, ROLE_USER, or is part of at least 1 group - */ - private static boolean isAuthorizedToRequestGroupRole(Person loggedUser) { - return (loggedUser.getAuthority().equals(Util.ROLE_ADMIN) - || loggedUser.getAuthority().equals(Util.ROLE_USER) - || !loggedUser.getResearchGroupMemberships().isEmpty()); - } - - public static void setPermissionToRequestGroupRole(Map modelMap, Person loggedUser) { - if (isAuthorizedToRequestGroupRole(loggedUser)) { - modelMap.put("userCanRequestGroupRole", true); - } - } - - public static void setPermissionToRequestGroupRole(ModelAndView mav, Person loggedUser) { - if (isAuthorizedToRequestGroupRole(loggedUser)) { - mav.addObject("userCanRequestGroupRole", true); - } - } - - public ResearchGroupDao getResearchGroupDao() { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) { - this.researchGroupDao = researchGroupDao; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } - - public GenericDao getMembershipDao() { - return membershipDao; - } - - public void setMembershipDao(GenericDao membershipDao) { - this.membershipDao = membershipDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/MembershipRequestController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/MembershipRequestController.java deleted file mode 100644 index 2b72bee9..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/group/MembershipRequestController.java +++ /dev/null @@ -1,151 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * MembershipRequestController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.group; - -import cz.zcu.kiv.eegdatabase.data.dao.GenericDao; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; -import cz.zcu.kiv.eegdatabase.data.pojo.GroupPermissionRequest; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import cz.zcu.kiv.eegdatabase.data.service.MailService; -import cz.zcu.kiv.eegdatabase.logic.Util; -import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.context.HierarchicalMessageSource; -import org.springframework.mail.MailException; -import org.springframework.validation.BindException; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; -import org.springframework.web.servlet.support.RequestContextUtils; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class MembershipRequestController extends SimpleFormController { - private Log log = LogFactory.getLog(getClass()); - private PersonDao personDao; - private ResearchGroupDao researchGroupDao; - private GenericDao groupPermissionRequestDao; - private MailService mailService; - - private Integer groupId; - - /** - * Source of localized messages defined in persistence.xml - */ - private HierarchicalMessageSource messageSource; - - public MembershipRequestController() { - setCommandClass(EditGroupRoleCommand.class); - setCommandName("editGroupRoleCommand"); - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception { - EditGroupRoleCommand groupRoleCommand = (EditGroupRoleCommand) command; - - Person user = personDao.getPerson(ControllerUtils.getLoggedUserName()); - ResearchGroup group = researchGroupDao.read(groupId); - GroupPermissionRequest gpr = new GroupPermissionRequest(); - gpr.setPerson(user); - gpr.setRequestedPermission(Util.GROUP_EXPERIMENTER); - gpr.setResearchGroup(group); - groupPermissionRequestDao.create(gpr); - String emailAdmin = group.getPerson().getEmail(); - - try { - mailService.sendRequestForJoiningGroupMail(emailAdmin, gpr.getRequestId(), user.getUsername(), - group.getTitle(), RequestContextUtils.getLocale(request)); - } catch (MailException e) { - log.debug("E-mail was NOT sent"); - e.printStackTrace(); - } - - log.debug("Returning MAV"); - ModelAndView mav = new ModelAndView("groups/requestSent"); - GroupMultiController.setPermissionToRequestGroupRole(mav, personDao.getLoggedPerson()); - return mav; - } - - @Override - protected Map referenceData(HttpServletRequest request) throws Exception { - Map map = new HashMap(); - groupId = Integer.parseInt(request.getParameter("groupId")); - ResearchGroup group = researchGroupDao.read(groupId); - map.put("researchGroup", group); - GroupMultiController.setPermissionToRequestGroupRole(map, personDao.getLoggedPerson()); - return map; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public ResearchGroupDao getResearchGroupDao() { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) { - this.researchGroupDao = researchGroupDao; - } - - public GenericDao getGroupPermissionRequestDao() { - return groupPermissionRequestDao; - } - - public void setGroupPermissionRequestDao(GenericDao groupPermissionRequestDao) { - this.groupPermissionRequestDao = groupPermissionRequestDao; - } - - /** - * @return the messageSource - */ - public HierarchicalMessageSource getMessageSource() { - return messageSource; - } - - /** - * @param messageSource the messageSource to set - */ - public void setMessageSource(HierarchicalMessageSource messageSource) { - this.messageSource = messageSource; - } - - public MailService getMailService() { - return mailService; - } - - public void setMailService(MailService mailService) { - this.mailService = mailService; - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/AbstractHistoryController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/AbstractHistoryController.java deleted file mode 100644 index a3fe39df..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/AbstractHistoryController.java +++ /dev/null @@ -1,193 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AbstractHistoryController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package cz.zcu.kiv.eegdatabase.logic.controller.history; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.HistoryDao; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; -import cz.zcu.kiv.eegdatabase.data.pojo.History; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import cz.zcu.kiv.eegdatabase.logic.controller.myaccount.ChangeDefaultGroupCommand; -import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; - -import java.util.List; -import java.util.Map; - -/** - * Sets reference data for form view and prepared ModelAndView for action "on submit"(in section history) - * - * @author pbruha - */ -public abstract class AbstractHistoryController extends SimpleFormController { - - protected Log log = LogFactory.getLog(getClass()); - protected AuthorizationManager auth; - protected PersonDao personDao; - protected HistoryDao historyDao; - protected ResearchGroupDao researchGroupDao; - - /** - * Load reference data needed for displaying the form - * - * @param map - map from section History - * @param historyType - history type (DAILY, WEEKLY, MONTHLY) - * @return map - reference data for view - */ - protected Map setReferenceData(Map map, ChoiceHistory historyType) { - int userId; - Person user = null; - String authority = null; - String roleAdmin = "ROLE_ADMIN"; - boolean isGroupAdmin; - userId = personDao.getLoggedPerson().getPersonId(); - user = personDao.getPerson(ControllerUtils.getLoggedUserName()); - authority = user.getAuthority(); - isGroupAdmin = auth.userIsGroupAdmin(); - map.put("isAdmin", authority.equals(roleAdmin)); - - - String countOfDownloadedFiles; - List historyList = null; - List lastDownloadedFilesHistoryList = null; - List topDownloadedFilesList = null; - List researchGroupList = - researchGroupDao.getResearchGroupsWhereUserIsGroupAdmin(personDao.getLoggedPerson()); - ResearchGroup defaultGroup = personDao.getLoggedPerson().getDefaultGroup(); - int defaultGroupId = (defaultGroup != null) ? defaultGroup.getResearchGroupId() : 0; - - if (authority.equals(roleAdmin) || isGroupAdmin) { - if (authority.equals(roleAdmin)) { - defaultGroupId = 0; - isGroupAdmin = false; - } - historyList = historyDao.getHistory(historyType, isGroupAdmin, defaultGroupId); - lastDownloadedFilesHistoryList = historyDao.getLastDownloadHistory(historyType, isGroupAdmin, defaultGroupId); - topDownloadedFilesList = historyDao.getTopDownloadHistory(historyType, isGroupAdmin, defaultGroupId); - - countOfDownloadedFiles = "" + historyList.size(); - map.put("countOfDownloadedFiles", countOfDownloadedFiles); - map.put("historyList", historyList); - map.put("topDownloadedFilesList", topDownloadedFilesList); - map.put("lastDownloadedFilesHistoryList", lastDownloadedFilesHistoryList); - map.put("defaultGroupId", defaultGroupId); - map.put("researchGroupList", researchGroupList); - map.put("access", true); - return map; - } - map.put("access", false); - return map; - } - - /** - * Prepared ModelAndView for action "on submit" needed for displaying the form - * - * @param historyType - history type (DAILY, WEEKLY, MONTHLY) - * @param changeDefaultGroupCommand - object for form's atributes - * @param mav - ModelAndView instance from section History - * @return mav - ModelAndView - */ - protected ModelAndView onSubmit(ChoiceHistory historyType, ChangeDefaultGroupCommand changeDefaultGroupCommand, ModelAndView mav) { - - List researchGroupList = - researchGroupDao.getResearchGroupsWhereUserIsGroupAdmin(personDao.getLoggedPerson()); - - int defaultGroupId = changeDefaultGroupCommand.getDefaultGroup(); - mav.addObject("defaultGroupId", defaultGroupId); - mav.addObject("researchGroupList", researchGroupList); - log.debug("Show selected history"); - - String countOfDownloadedFiles; - int userId; - List historyList = null; - Person user = null; - String authority = null; - String roleAdmin = "ROLE_ADMIN"; - boolean isGroupAdmin; - List lastDownloadedFilesHistoryList = null; - List topDownloadedFilesList = null; - userId = personDao.getLoggedPerson().getPersonId(); - user = personDao.getPerson(ControllerUtils.getLoggedUserName()); - authority = user.getAuthority(); - isGroupAdmin = auth.userIsGroupAdmin(); - mav.addObject("changeDefaultGroup", changeDefaultGroupCommand); - - if ((authority.equals(roleAdmin) || isGroupAdmin)) { - historyList = historyDao.getHistory(historyType, isGroupAdmin, changeDefaultGroupCommand.getDefaultGroup()); - lastDownloadedFilesHistoryList = historyDao.getLastDownloadHistory(historyType, isGroupAdmin, changeDefaultGroupCommand.getDefaultGroup()); - topDownloadedFilesList = historyDao.getTopDownloadHistory(historyType, isGroupAdmin, changeDefaultGroupCommand.getDefaultGroup()); - - countOfDownloadedFiles = "" + historyList.size(); - mav.addObject("countOfDownloadedFiles", countOfDownloadedFiles); - mav.addObject("historyList", historyList); - mav.addObject("topDownloadedFilesList", topDownloadedFilesList); - mav.addObject("lastDownloadedFilesHistoryList", lastDownloadedFilesHistoryList); - mav.addObject("isAdmin", authority.equals(roleAdmin)); - mav.addObject("access", true); - return mav; - } - mav.addObject("access", false); - return mav; - } - - public HistoryDao getHistoryDao() { - return historyDao; - } - - public void setHistoryDao(HistoryDao historyDao) { - this.historyDao = historyDao; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } - - public ResearchGroupDao getResearchGroupDao() { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) { - this.researchGroupDao = researchGroupDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/DailyHistoryController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/DailyHistoryController.java deleted file mode 100644 index f94e3785..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/DailyHistoryController.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * DailyHistoryController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package cz.zcu.kiv.eegdatabase.logic.controller.history; - -import cz.zcu.kiv.eegdatabase.logic.controller.myaccount.ChangeDefaultGroupCommand; -import org.springframework.validation.BindException; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.HashMap; -import java.util.Map; - -/** - * Sets reference data for form view and prepared ModelAndView for action "on submit"(for choice daily history ) - * using object change default group command for saving select group id - * - * @author pbruha - */ -public class DailyHistoryController extends AbstractHistoryController { - - public DailyHistoryController() { - setCommandClass(ChangeDefaultGroupCommand.class); - setCommandName("changeDefaultGroup"); - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception { - log.debug("Processing daily download history"); - ModelAndView mav = new ModelAndView(getSuccessView()); - ChangeDefaultGroupCommand changeDefaultGroupCommand = (ChangeDefaultGroupCommand) command; - mav = super.onSubmit(ChoiceHistory.DAILY, changeDefaultGroupCommand, mav); - log.debug("Returning MAV"); - return mav; - } - - @Override - protected Map referenceData(HttpServletRequest request) throws Exception { - log.debug("Processing daily download history"); - Map map = new HashMap(); - map = super.setReferenceData(map, ChoiceHistory.DAILY); - return map; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/GraphController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/GraphController.java deleted file mode 100644 index e91043fe..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/GraphController.java +++ /dev/null @@ -1,133 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * GraphController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package cz.zcu.kiv.eegdatabase.logic.controller.history; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.dao.SimpleHistoryDao; -import cz.zcu.kiv.eegdatabase.data.pojo.History; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.jfree.chart.ChartFactory; -import org.jfree.chart.ChartUtilities; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.plot.PiePlot3D; -import org.jfree.data.general.DefaultPieDataset; -import org.jfree.util.Rotation; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.AbstractController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.List; - -/** - * Creates pie graph TOP download files by graph type(DAILY, WEEKLY, MONTHLY) - * - * @author pbruha - */ -public class GraphController extends AbstractController { - - public GraphController() { - } - - private Log log = LogFactory.getLog(getClass()); - private SimpleHistoryDao historyDao; - private AuthorizationManager auth; - private PersonDao personDao; - - protected ModelAndView handleRequestInternal( - HttpServletRequest request, - HttpServletResponse response) throws Exception { - log.debug("Processing creating pie graph"); - String graphType = ""; - - List topDownloadedFilesList = null; - boolean isGroupAdmin; - long countFile = 0; - - graphType = request.getParameter("graphType"); - int groupId = Integer.parseInt(request.getParameter("groupId")); - isGroupAdmin = auth.userIsGroupAdmin(); - response.setContentType("image/png"); - - topDownloadedFilesList = historyDao.getTopDownloadHistory(ChoiceHistory.valueOf(graphType), isGroupAdmin, groupId); - - - DefaultPieDataset dataset = new DefaultPieDataset(); - if (groupId != -1) { - for (int i = 0; i < topDownloadedFilesList.size(); i++) { - dataset.setValue(topDownloadedFilesList.get(i).getFileName(), new Long(topDownloadedFilesList.get(i).getCount())); - countFile = countFile + topDownloadedFilesList.get(i).getCount(); - } - - if (historyDao.getCountOfFilesHistory(ChoiceHistory.valueOf(graphType), isGroupAdmin, groupId) > countFile) { - dataset.setValue("Other", historyDao.getCountOfFilesHistory(ChoiceHistory.valueOf(graphType), isGroupAdmin, groupId) - countFile); - } - } - JFreeChart chart = ChartFactory.createPieChart3D( - "Daily downloads", // chart title - dataset, // data - true, // include legend - true, - false); - - PiePlot3D plot = (PiePlot3D) chart.getPlot(); - plot.setStartAngle(290); - plot.setDirection(Rotation.CLOCKWISE); - plot.setForegroundAlpha(0.5f); - plot.setNoDataMessage("No data to display"); - - ChartUtilities.writeChartAsPNG(response.getOutputStream(), chart, 600, 400); - response.getOutputStream().close(); - return null; - } - - public SimpleHistoryDao getHistoryDao() { - return historyDao; - } - - public void setHistoryDao(SimpleHistoryDao historyDao) { - this.historyDao = historyDao; - } - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/HistorySearcherCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/HistorySearcherCommand.java deleted file mode 100644 index f4d5c483..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/HistorySearcherCommand.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * HistorySearcherCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package cz.zcu.kiv.eegdatabase.logic.controller.history; - -import java.sql.Timestamp; - -/** - * @author pbruha - */ -public class HistorySearcherCommand { - private String title; - private Timestamp fromDateOfDownload; - private Timestamp toDateOfDownload; - - public Timestamp getFromDateOfDownload() { - return fromDateOfDownload; - } - - public void setFromDateOfDownload(Timestamp fromDateOfDownload) { - this.fromDateOfDownload = fromDateOfDownload; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public Timestamp getToDateOfDownload() { - return toDateOfDownload; - } - - public void setToDateOfDownload(Timestamp toDateOfDownload) { - this.toDateOfDownload = toDateOfDownload; - } - - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/MonthlyHistoryController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/MonthlyHistoryController.java deleted file mode 100644 index 9514beaf..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/MonthlyHistoryController.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * MonthlyHistoryController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package cz.zcu.kiv.eegdatabase.logic.controller.history; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.HistoryDao; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; -import cz.zcu.kiv.eegdatabase.data.pojo.History; -import cz.zcu.kiv.eegdatabase.logic.controller.myaccount.ChangeDefaultGroupCommand; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.validation.BindException; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.HashMap; -import java.util.Map; - -/** - * Sets reference data for form view and prepared ModelAndView for action "on submit"(for choice monthly history ) - * using object change default group command for saving select group id - * - * @author pbruha - */ -public class MonthlyHistoryController extends AbstractHistoryController { - - private Log log = LogFactory.getLog(getClass()); - private HistoryDao historyDao; - private AuthorizationManager auth; - private PersonDao personDao; - private ResearchGroupDao researchGroupDao; - - public MonthlyHistoryController() { - setCommandClass(ChangeDefaultGroupCommand.class); - setCommandName("changeDefaultGroup"); - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception { - log.debug("Processing daily download history"); - ModelAndView mav = new ModelAndView(getSuccessView()); - ChangeDefaultGroupCommand changeDefaultGroupCommand = (ChangeDefaultGroupCommand) command; - mav = super.onSubmit(ChoiceHistory.MONTHLY, changeDefaultGroupCommand, mav); - return mav; - } - - @Override - protected Map referenceData(HttpServletRequest request) throws Exception { - log.debug("Processing daily download history"); - Map map = new HashMap(); - map = super.setReferenceData(map, ChoiceHistory.MONTHLY); - return map; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/SearchHistoryController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/SearchHistoryController.java deleted file mode 100644 index b2fc2bc6..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/SearchHistoryController.java +++ /dev/null @@ -1,135 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * SearchHistoryController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package cz.zcu.kiv.eegdatabase.logic.controller.history; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.dao.SimpleHistoryDao; -import cz.zcu.kiv.eegdatabase.data.pojo.History; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroupMembership; -import cz.zcu.kiv.eegdatabase.logic.controller.search.AbstractSearchController; -import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; -import org.springframework.validation.BindException; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -/** - * Prepared search results - * using history searcher command for saving searching scenario(by scenario title), date interval (from date of download, to date of download) - * - * @author pbruha - */ -public class SearchHistoryController extends AbstractSearchController { - - private AuthorizationManager auth; - private PersonDao personDao; - private SimpleHistoryDao historyDao; - - public SearchHistoryController() { - setCommandClass(HistorySearcherCommand.class); - setCommandName("historySearcherCommand"); - } - - @Override - protected Object formBackingObject(HttpServletRequest request) throws Exception { - HistorySearcherCommand search = (HistorySearcherCommand) super.formBackingObject(request); - return search; - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { - log.debug("Processing advanced search download history"); - ModelAndView mav = super.onSubmit(request, response, command); - Person user = null; - String authority = null; - String roleAdmin = "ROLE_ADMIN"; - boolean isGroupAdmin; - - user = personDao.getPerson(ControllerUtils.getLoggedUserName()); - authority = user.getAuthority(); - isGroupAdmin = auth.userIsGroupAdmin(); - if (authority.equals(roleAdmin) || isGroupAdmin) { - if (authority.equals(roleAdmin)) { - isGroupAdmin = false; - } - Set rgm = user.getResearchGroupMemberships(); - List groupsId = new ArrayList(); - - for (ResearchGroupMembership member : rgm) { - if (member.getAuthority().equals("GROUP_ADMIN")) { - groupsId.add(member.getResearchGroup().getResearchGroupId()); - } - } - - - try { - List historyResults = historyDao.getHistorySearchResults(requests, isGroupAdmin, groupsId); - mav.addObject("historyResults", historyResults); - mav.addObject("resultsEmpty", historyResults.isEmpty()); - } catch (NumberFormatException e) { - mav.addObject("mistake", "Number error"); - mav.addObject("error", true); - } catch (RuntimeException e) { - mav.addObject("mistake", e.getMessage()); - mav.addObject("error", true); - } - return mav; - } - mav.setViewName("system/accessDeniedNotAdmin"); - return mav; - } - - public SimpleHistoryDao getHistoryDao() { - return historyDao; - } - - public void setHistoryDao(SimpleHistoryDao historyDao) { - this.historyDao = historyDao; - } - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/WeeklyHistoryController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/WeeklyHistoryController.java deleted file mode 100644 index e5a1e8ca..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/history/WeeklyHistoryController.java +++ /dev/null @@ -1,69 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * WeeklyHistoryController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package cz.zcu.kiv.eegdatabase.logic.controller.history; - -import cz.zcu.kiv.eegdatabase.logic.controller.myaccount.ChangeDefaultGroupCommand; -import org.springframework.validation.BindException; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.HashMap; -import java.util.Map; - -/** - * Sets reference data for form view and prepared ModelAndView for action "on submit"(for choice weekly history ) - * using object change default group command for saving select group id - * - * @author pbruha - */ -public class WeeklyHistoryController extends AbstractHistoryController { - - public WeeklyHistoryController() { - setCommandClass(ChangeDefaultGroupCommand.class); - setCommandName("changeDefaultGroup"); - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception { - log.debug("Processing daily download history"); - ModelAndView mav = new ModelAndView(getSuccessView()); - ChangeDefaultGroupCommand changeDefaultGroupCommand = (ChangeDefaultGroupCommand) command; - mav = super.onSubmit(ChoiceHistory.WEEKLY, changeDefaultGroupCommand, mav); - return mav; - } - - @Override - protected Map referenceData(HttpServletRequest request) throws Exception { - log.debug("Processing daily download history"); - Map map = new HashMap(); - map = super.setReferenceData(map, ChoiceHistory.WEEKLY); - return map; - } - - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/SelectGroupCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/SelectGroupCommand.java deleted file mode 100644 index 981a3282..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/SelectGroupCommand.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * SelectGroupCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list; - -/** - * @author František Liška - */ -public class SelectGroupCommand { - private int researchGroupId; - private String title; - private String description; - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public int getResearchGroupId() { - return researchGroupId; - } - - public void setResearchGroupId(int researchGroupId) { - this.researchGroupId = researchGroupId; - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/artifact/AddArtifactCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/artifact/AddArtifactCommand.java deleted file mode 100644 index cd71bb4c..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/artifact/AddArtifactCommand.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddArtifactCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.artifact; - -/** - * Created with IntelliJ IDEA. - * User: Honza - * Date: 24.6.12 - * Time: 18:28 - * To change this template use File | Settings | File Templates. - */ -public class AddArtifactCommand { - private int id; - private String compensation; - private String rejectCondition; - private int researchGroupId; - private String researchGroupTitle; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getCompensation() { - return compensation; - } - - public void setCompensation(String compensation) { - this.compensation = compensation; - } - - public String getRejectCondition() { - return rejectCondition; - } - - public void setRejectCondition(String rejectCondition) { - this.rejectCondition = rejectCondition; - } - - public int getResearchGroupId() { - return researchGroupId; - } - - public void setResearchGroupId(int researchGroupId) { - this.researchGroupId = researchGroupId; - } - - public String getResearchGroupTitle() { - return researchGroupTitle; - } - - public void setResearchGroupTitle(String researchGroupTitle) { - this.researchGroupTitle = researchGroupTitle; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/artifact/AddArtifactController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/artifact/AddArtifactController.java deleted file mode 100644 index b85f327e..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/artifact/AddArtifactController.java +++ /dev/null @@ -1,153 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddArtifactController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.artifact; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.GenericListDao; -import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Artifact; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.*; - -import javax.servlet.http.HttpServletRequest; -import java.util.HashSet; -import java.util.Set; - -/** - * Created with IntelliJ IDEA. - * User: Honza - * Date: 24.6.12 - * Time: 18:50 - * To change this template use File | Settings | File Templates. - */ -@Controller -@SessionAttributes("addArtifact") -public class AddArtifactController { - private Log log = LogFactory.getLog(getClass()); - @Autowired - private AuthorizationManager auth; - @Autowired - private GenericListDao artifactDao; - @Autowired - private ResearchGroupDao researchGroupDao; - - AddArtifactValidator addArtifactValidator; - - @Autowired - public AddArtifactController(AddArtifactValidator addArtifactValidator) { - this.addArtifactValidator = addArtifactValidator; - } - - @RequestMapping(value = "lists/artifact-definitions/edit.html", method = RequestMethod.GET) - protected String showEditForm(@RequestParam("id") String idString, @RequestParam("groupid") String idString2, ModelMap model, HttpServletRequest request) { - AddArtifactCommand data = new AddArtifactCommand(); - if (auth.userIsExperimenter() || auth.isAdmin()) { - model.addAttribute("userIsExperimenter", true); - int id = Integer.parseInt(idString2); - data.setResearchGroupId(id); - String title = researchGroupDao.getResearchGroupTitle(id); - data.setResearchGroupTitle(title); - - - // Editing of existing artifact - id = Integer.parseInt(idString); - - log.debug("Loading artifact to the command object for editing."); - Artifact artifact = artifactDao.read(id); - data.setId(id); - data.setCompensation(artifact.getCompensation()); - data.setRejectCondition(artifact.getRejectCondition()); - - model.addAttribute("addArtifact", data); - - return "lists/artifact/addItemForm"; - } else { - return "lists/userNotExperimenter"; - } - } - - @RequestMapping(value = "lists/artifact-definitions/add.html", method = RequestMethod.GET) - protected String showAddForm(@RequestParam("groupid") String idString, ModelMap model, HttpServletRequest request) throws Exception { - AddArtifactCommand data = new AddArtifactCommand(); - if (auth.userIsExperimenter() || auth.isAdmin()) { - if (idString != null) { - int id = Integer.parseInt(idString); - data.setResearchGroupId(id); - - String title = researchGroupDao.getResearchGroupTitle(id); - data.setResearchGroupTitle(title); - - } - model.addAttribute("userIsExperimenter", auth.userIsExperimenter()); - model.addAttribute("addArtifact", data); - return "lists/artifact/addItemForm"; - } else { - return "lists/userNotExperimenter"; - } - } - - - @RequestMapping(method = RequestMethod.POST) - protected String onSubmit(@ModelAttribute("addArtifact") AddArtifactCommand data, BindingResult result, ModelMap model) { - log.debug("Processing form data."); - - if (auth.userIsExperimenter() || auth.isAdmin()) { - addArtifactValidator.validate(data, result); - if (result.hasErrors()) { - return "lists/artifact/addItemForm"; - } - int artifactId = data.getId(); - Artifact artifact; - if (artifactId > 0) { - // Editing - log.debug("Editing existing artifact object."); - artifact = artifactDao.read(artifactId); - artifact.setCompensation(data.getCompensation()); - artifact.setRejectCondition(data.getRejectCondition()); - - artifactDao.update(artifact); - } else { - Artifact newArtifact = new Artifact(); - ResearchGroup group = researchGroupDao.read(data.getResearchGroupId()); - newArtifact.setCompensation(data.getCompensation()); - newArtifact.setRejectCondition(data.getRejectCondition()); - Set groups = new HashSet(0); - groups.add(group); - newArtifact.setResearchGroups(groups); - artifactDao.create(newArtifact); - - } - log.debug("Returning MAV"); - String redirect = "redirect:list.html?groupid=" + data.getResearchGroupId(); - return redirect; - } else { - return "lists/userNotExperimenter"; - } - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/artifact/AddArtifactValidator.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/artifact/AddArtifactValidator.java deleted file mode 100644 index b6059c57..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/artifact/AddArtifactValidator.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddArtifactValidator.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.artifact; - -import cz.zcu.kiv.eegdatabase.data.dao.GenericListDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Artifact; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -/** - * Created with IntelliJ IDEA. - * User: Honza - * Date: 24.6.12 - * Time: 18:51 - * To change this template use File | Settings | File Templates. - */ -public class AddArtifactValidator implements Validator { - private Log log = LogFactory.getLog(getClass()); - @Autowired - private GenericListDao artifactDao; - - @Override - public boolean supports(Class aClass) { - return aClass.equals(AddArtifactCommand.class); //To change body of implemented methods use File | Settings | File Templates. - } - - @Override - public void validate(Object o, Errors errors) { - AddArtifactCommand data = (AddArtifactCommand) o; - - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "compensation", "required.field"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "rejectCondition", "required.field"); - - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/artifact/ArtifactMultiController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/artifact/ArtifactMultiController.java deleted file mode 100644 index b17a0d97..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/artifact/ArtifactMultiController.java +++ /dev/null @@ -1,158 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ArtifactMultiController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.artifact; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.GenericListDao; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Artifact; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import cz.zcu.kiv.eegdatabase.logic.controller.list.SelectGroupCommand; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.context.request.WebRequest; - -import javax.servlet.http.HttpServletRequest; -import java.util.List; - -/** - * Created with IntelliJ IDEA. - * User: Honza - * Date: 24.6.12 - * Time: 19:41 - * To change this template use File | Settings | File Templates. - */ -@Controller -@SessionAttributes("selectGroupCommand") -public class ArtifactMultiController { - private Log log = LogFactory.getLog(getClass()); - @Autowired - private AuthorizationManager auth; - @Autowired - private ResearchGroupDao researchGroupDao; - @Autowired - private GenericListDao artifactDao; - @Autowired - private PersonDao personDao; - - private List researchGroupList; - private List artifactList; - - @RequestMapping(value = "lists/artifact-definitions/list.html", method = RequestMethod.GET) - public String showSelectForm(WebRequest webRequest, ModelMap model, HttpServletRequest request) { - log.debug("Processing artifact list controller"); - SelectGroupCommand selectGroupCommand = new SelectGroupCommand(); - researchGroupList = fillAuthResearchGroupList(); - String idString = webRequest.getParameter("groupid"); - if (auth.isAdmin()) { - if (idString != null) { - int id = Integer.parseInt(idString); - artifactList = fillArtifactList(id); - selectGroupCommand.setResearchGroupId(id); - model.addAttribute("userIsExperimenter", true); - } else { - int myGroup = researchGroupList.get(0).getResearchGroupId(); - artifactList = fillArtifactList(myGroup); - selectGroupCommand.setResearchGroupId(myGroup); - } - model.addAttribute("userIsExperimenter", true); - } else { - if (!researchGroupList.isEmpty()) { - if (idString != null) { - int id = Integer.parseInt(idString); - artifactList = fillArtifactList(id); - selectGroupCommand.setResearchGroupId(id); - } else { - int myGroup = researchGroupList.get(0).getResearchGroupId(); - artifactList = fillArtifactList(myGroup); - selectGroupCommand.setResearchGroupId(myGroup); - } - model.addAttribute("userIsExperimenter", auth.userIsExperimenter()); - } else { - model.addAttribute("userIsExperimenter", false); - } - } - model.addAttribute("selectGroupCommand", selectGroupCommand); - model.addAttribute("artifactList", artifactList); - model.addAttribute("researchGroupList", researchGroupList); - - - return "lists/artifact/list"; - } - - @RequestMapping(value = "lists/artifact-definitions/list.html", method = RequestMethod.POST) - public String onSubmit(@ModelAttribute("selectGroupCommand") SelectGroupCommand selectGroupCommand, ModelMap model, HttpServletRequest request) { - researchGroupList = fillAuthResearchGroupList(); - if (!researchGroupList.isEmpty()) { - artifactList = fillArtifactList(selectGroupCommand.getResearchGroupId()); - } - boolean canEdit = auth.isAdmin() || auth.userIsExperimenter(); - model.addAttribute("userIsExperimenter", canEdit); - model.addAttribute("researchGroupList", researchGroupList); - model.addAttribute("artifactList", artifactList); - return "lists/artifact/list"; - } - - @RequestMapping(value = "lists/artifact-definitions/delete.html") - public String delete(@RequestParam("id") String idString, @RequestParam("groupid") String idString2) { - log.debug("Deleting hardware."); - if (idString != null) { - int id = Integer.parseInt(idString); - - if (artifactDao.canDelete(id)) { - if (idString2 != null) { - int groupId = Integer.parseInt(idString2); - artifactDao.deleteGroupRel(artifactDao.read(id), researchGroupDao.read(groupId)); - - } - } else { - System.out.println("cannotDelete"); - return "lists/itemUsed"; - } - } - - return "lists/itemDeleted"; - } - - private List fillAuthResearchGroupList() { - Person loggedUser = personDao.getLoggedPerson(); - if (loggedUser.getAuthority().equals("ROLE_ADMIN")) { - return researchGroupDao.getAllRecords(); - } else { - return researchGroupDao.getResearchGroupsWhereMember(loggedUser); - } - } - - private List fillArtifactList(int id) { - if (!researchGroupList.isEmpty()) { - return artifactDao.getRecordsByGroup(id); - } - return null; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/experimentoptparamdef/AddExperimentOptParamDefCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/experimentoptparamdef/AddExperimentOptParamDefCommand.java deleted file mode 100644 index bc1390e5..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/experimentoptparamdef/AddExperimentOptParamDefCommand.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddExperimentOptParamDefCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.experimentoptparamdef; - -/** - * @author Jindra - */ -public class AddExperimentOptParamDefCommand { - - private int id; - private String paramName; - private String paramDataType; - private int researchGroupId; - private String researchGroupTitle; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getParamDataType() { - return paramDataType; - } - - public void setParamDataType(String paramDataType) { - this.paramDataType = paramDataType; - } - - public String getParamName() { - return paramName; - } - - public void setParamName(String paramName) { - this.paramName = paramName; - } - - public int getResearchGroupId() { - return researchGroupId; - } - - public void setResearchGroupId(int researchGroupId) { - this.researchGroupId = researchGroupId; - } - - public String getResearchGroupTitle() { - return researchGroupTitle; - } - - public void setResearchGroupTitle(String researchGroupTitle) { - this.researchGroupTitle = researchGroupTitle; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/experimentoptparamdef/AddExperimentOptParamDefController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/experimentoptparamdef/AddExperimentOptParamDefController.java deleted file mode 100644 index 9997068a..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/experimentoptparamdef/AddExperimentOptParamDefController.java +++ /dev/null @@ -1,196 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddExperimentOptParamDefController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.experimentoptparamdef; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.ExperimentOptParamDefDao; -import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; -import cz.zcu.kiv.eegdatabase.data.pojo.ExperimentOptParamDef; -import cz.zcu.kiv.eegdatabase.data.pojo.ExperimentOptParamDefGroupRel; -import cz.zcu.kiv.eegdatabase.data.pojo.ExperimentOptParamDefGroupRelId; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.HierarchicalMessageSource; -import org.springframework.ui.ModelMap; -import org.springframework.stereotype.Controller; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.servlet.support.RequestContextUtils; -import javax.servlet.http.HttpServletRequest; - -@Controller -@SessionAttributes("addExperimentOptParamDef") -public class AddExperimentOptParamDefController{ - private Log log = LogFactory.getLog(getClass()); - @Autowired - private AuthorizationManager auth; - @Autowired - private ExperimentOptParamDefDao experimentOptParamDefDao; - @Autowired - private ResearchGroupDao researchGroupDao; - @Autowired - private HierarchicalMessageSource messageSource; - - private final int DEFAULT_ID = -1; - AddExperimentOptParamDefValidator addExperimentOptParamDefValidator; - - @Autowired - public AddExperimentOptParamDefController(AddExperimentOptParamDefValidator addExperimentOptParamDefValidator){ - this.addExperimentOptParamDefValidator = addExperimentOptParamDefValidator; - } - - @RequestMapping(value="lists/experiment-optional-parameters/edit.html", method= RequestMethod.GET) - protected String showEditForm(@RequestParam("id") String idString, @RequestParam("groupid") String idString2, ModelMap model, HttpServletRequest request){ - AddExperimentOptParamDefCommand data = new AddExperimentOptParamDefCommand(); - if (auth.userIsExperimenter() || auth.isAdmin()) { - model.addAttribute("userIsExperimenter", true); - if (idString2 != null) { - int id = Integer.parseInt(idString2); - data.setResearchGroupId(id); - if(id!=DEFAULT_ID){ - String title = researchGroupDao.getResearchGroupTitle(id); - data.setResearchGroupTitle(title); - }else{ - String defaultExperimentOptParamDef = messageSource.getMessage("label.defaultExperimentOptParamDef", null, RequestContextUtils.getLocale(request)); - data.setResearchGroupTitle(defaultExperimentOptParamDef); - } - } - if (idString != null) { - // Editation of existing experimentOptParamDef - int id = Integer.parseInt(idString); - - log.debug("Loading experimentOptParamDef to the command object for editing."); - ExperimentOptParamDef experimentOptParamDef = experimentOptParamDefDao.read(id); - - data.setId(id); - data.setParamName(experimentOptParamDef.getParamName()); - data.setParamDataType(experimentOptParamDef.getParamDataType()); - } - model.addAttribute("addExperimentOptParamDef",data); - - return "lists/measurationAdditionalParams/addItemForm"; - }else{ - return "lists/userNotExperimenter"; - } - } - - @RequestMapping(value="lists/experiment-optional-parameters/add.html",method=RequestMethod.GET) - protected String showAddForm(@RequestParam("groupid") String idString, ModelMap model, HttpServletRequest request) throws Exception { - AddExperimentOptParamDefCommand data = new AddExperimentOptParamDefCommand(); - if (auth.userIsExperimenter() || auth.isAdmin()) { - if (idString != null) { - int id = Integer.parseInt(idString); - data.setResearchGroupId(id); - if(id!=DEFAULT_ID){ - String title = researchGroupDao.getResearchGroupTitle(id); - data.setResearchGroupTitle(title); - }else{ - String defaultExperimentOptParamDef = messageSource.getMessage("label.defaultExperimentOptParamDef", null, RequestContextUtils.getLocale(request)); - data.setResearchGroupTitle(defaultExperimentOptParamDef); - } - } - model.addAttribute("userIsExperimenter", auth.userIsExperimenter()); - model.addAttribute("addExperimentOptParamDef",data); - return "lists/measurationAdditionalParams/addItemForm"; - }else{ - return "lists/userNotExperimenter"; - } - } - - - @RequestMapping(method=RequestMethod.POST) - protected String onSubmit(@ModelAttribute("addExperimentOptParamDef") AddExperimentOptParamDefCommand data, BindingResult result,ModelMap model) { - log.debug("Processing form data."); - if (auth.userIsExperimenter() || auth.isAdmin()) { - addExperimentOptParamDefValidator.validate(data,result); - if (result.hasErrors()) { - return "lists/measurationAdditionalParams/addItemForm"; - } - int experimentOptParamDefId = data.getId(); - ExperimentOptParamDef experimentOptParamDef; - if (experimentOptParamDefId > 0) { - // Editing - log.debug("Editing existing experimentOptParamDef object."); - experimentOptParamDef = experimentOptParamDefDao.read(experimentOptParamDefId); - if(experimentOptParamDefDao.isDefault(experimentOptParamDefId)){ - if(data.getResearchGroupId()!=DEFAULT_ID){ - // new experimentOptParamDef - ExperimentOptParamDef newExperimentOptParamDef = new ExperimentOptParamDef(); - newExperimentOptParamDef.setDefaultNumber(0); - newExperimentOptParamDef.setParamName(data.getParamName()); - newExperimentOptParamDef.setParamDataType(data.getParamDataType()); - int newId = experimentOptParamDefDao.create(newExperimentOptParamDef); - ExperimentOptParamDefGroupRel rel = experimentOptParamDefDao.getGroupRel(experimentOptParamDefId,data.getResearchGroupId()); - // delete old rel, create new one - ExperimentOptParamDefGroupRelId newRelId = new ExperimentOptParamDefGroupRelId(); - ExperimentOptParamDefGroupRel newRel = new ExperimentOptParamDefGroupRel(); - newRelId.setExperimentOptParamDefId(newId); - newRelId.setResearchGroupId(data.getResearchGroupId()); - newRel.setId(newRelId); - newRel.setExperimentOptParamDef(newExperimentOptParamDef); - ResearchGroup r = researchGroupDao.read(data.getResearchGroupId()); - newRel.setResearchGroup(r); - experimentOptParamDefDao.deleteGroupRel(rel); - experimentOptParamDefDao.createGroupRel(newRel); - }else{ - if(!experimentOptParamDefDao.hasGroupRel(experimentOptParamDefId) && experimentOptParamDefDao.canDelete(experimentOptParamDefId)){ - experimentOptParamDef.setParamName(data.getParamName()); - experimentOptParamDef.setParamDataType(data.getParamDataType()); - }else{ - return "lists/itemUsed"; - } - } - }else{ - experimentOptParamDef.setParamName(data.getParamName()); - experimentOptParamDef.setParamDataType(data.getParamDataType()); - } - } else { - // Creating new - experimentOptParamDef = new ExperimentOptParamDef(); - experimentOptParamDef.setParamName(data.getParamName()); - experimentOptParamDef.setParamDataType(data.getParamDataType()); - int pkGroup = data.getResearchGroupId(); - if(pkGroup == DEFAULT_ID){ - log.debug("Creating new default experimentOptParamDef object."); - experimentOptParamDefDao.createDefaultRecord(experimentOptParamDef); - }else{ - log.debug("Creating new group experimentOptParamDef object."); - int pkExperimentOptParamDef = experimentOptParamDefDao.create(experimentOptParamDef); - - ExperimentOptParamDefGroupRelId experimentOptParamDefGroupRelId = new ExperimentOptParamDefGroupRelId(pkExperimentOptParamDef,pkGroup); - ResearchGroup researchGroup = researchGroupDao.read(pkGroup); - ExperimentOptParamDefGroupRel experimentOptParamDefGroupRel = new ExperimentOptParamDefGroupRel(experimentOptParamDefGroupRelId,researchGroup,experimentOptParamDef); - experimentOptParamDefDao.createGroupRel(experimentOptParamDefGroupRel); - } - - } - log.debug("Returning MAV"); - String redirect = "redirect:list.html?groupid="+data.getResearchGroupId(); - return redirect; - }else{ - return "lists/userNotExperimenter"; - } - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/experimentoptparamdef/AddExperimentOptParamDefValidator.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/experimentoptparamdef/AddExperimentOptParamDefValidator.java deleted file mode 100644 index 0ef8e38e..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/experimentoptparamdef/AddExperimentOptParamDefValidator.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddExperimentOptParamDefValidator.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.experimentoptparamdef; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -/** - * @author JiPER - */ -public class AddExperimentOptParamDefValidator implements Validator { - - private Log log = LogFactory.getLog(getClass()); - - public boolean supports(Class clazz) { - return clazz.equals(AddExperimentOptParamDefCommand.class); - } - - public void validate(Object command, Errors errors) { - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "paramName", "required.field"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "paramDataType", "required.field"); - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/experimentoptparamdef/ExperimentOptParamDefMultiController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/experimentoptparamdef/ExperimentOptParamDefMultiController.java deleted file mode 100644 index 857bb79b..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/experimentoptparamdef/ExperimentOptParamDefMultiController.java +++ /dev/null @@ -1,293 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ExperimentOptParamDefMultiController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.experimentoptparamdef; -import cz.zcu.kiv.eegdatabase.data.dao.*; -import cz.zcu.kiv.eegdatabase.data.pojo.ExperimentOptParamDef; -import cz.zcu.kiv.eegdatabase.data.pojo.ExperimentOptParamDefGroupRel; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import cz.zcu.kiv.eegdatabase.logic.controller.list.SelectGroupCommand; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.context.HierarchicalMessageSource; -import org.springframework.web.servlet.support.RequestContextUtils; -import org.springframework.stereotype.Controller; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.context.request.WebRequest; -import javax.servlet.http.HttpServletRequest; -import java.util.List; - -/** - * @author František Liška - */ -@Controller -@SessionAttributes("selectGroupCommand") -public class ExperimentOptParamDefMultiController { - private Log log = LogFactory.getLog(getClass()); - @Autowired - private AuthorizationManager auth; - @Autowired - private ResearchGroupDao researchGroupDao; - @Autowired - private ExperimentOptParamDefDao experimentOptParamDefDao; - @Autowired - private PersonDao personDao; - @Autowired - private HierarchicalMessageSource messageSource; - - private List researchGroupList; - private List experimentOptParamDefList; - private final int DEFAULT_ID = -1; - - @RequestMapping(value="lists/experiment-optional-parameters/list.html",method= RequestMethod.GET) - public String showSelectForm(WebRequest webRequest,ModelMap model, HttpServletRequest request){ - log.debug("Processing experimentOptParamDef list controller"); - SelectGroupCommand selectGroupCommand= new SelectGroupCommand(); - String defaultExperimentOptParamDef = messageSource.getMessage("label.defaultExperimentOptParamDef", null, RequestContextUtils.getLocale(request)); - fillAuthResearchGroupList(defaultExperimentOptParamDef); - String idString = webRequest.getParameter("groupid"); - if(auth.isAdmin()){ - if (idString != null) { - int id = Integer.parseInt(idString); - if(id!=DEFAULT_ID){ - fillExperimentOptParamDefList(id); - selectGroupCommand.setResearchGroupId(id); - }else{ - fillExperimentOptParamDefList(DEFAULT_ID); - selectGroupCommand.setResearchGroupId(DEFAULT_ID); - } - - }else{ - fillExperimentOptParamDefList(DEFAULT_ID); - selectGroupCommand.setResearchGroupId(DEFAULT_ID); - } - model.addAttribute("userIsExperimenter", true); - }else{ - if(!researchGroupList.isEmpty()){ - if (idString != null) { - int id = Integer.parseInt(idString); - fillExperimentOptParamDefList(id); - selectGroupCommand.setResearchGroupId(id); - }else{ - int myGroup = researchGroupList.get(0).getResearchGroupId(); - fillExperimentOptParamDefList(myGroup); - selectGroupCommand.setResearchGroupId(myGroup); - } - model.addAttribute("userIsExperimenter", auth.userIsExperimenter()); - }else{ - model.addAttribute("userIsExperimenter", false); - } - } - model.addAttribute("selectGroupCommand",selectGroupCommand); - model.addAttribute("experimentOptParamDefList", experimentOptParamDefList); - model.addAttribute("researchGroupList", researchGroupList); - - - return "lists/measurationAdditionalParams/list"; - } - - @RequestMapping(value="lists/experiment-optional-parameters/list.html",method=RequestMethod.POST) - public String onSubmit(@ModelAttribute("selectGroupCommand") SelectGroupCommand selectGroupCommand, ModelMap model, HttpServletRequest request){ - String defaultExperimentOptParamDef = messageSource.getMessage("label.defaultExperimentOptParamDef", null, RequestContextUtils.getLocale(request)); - fillAuthResearchGroupList(defaultExperimentOptParamDef); - if(!researchGroupList.isEmpty()){ - fillExperimentOptParamDefList(selectGroupCommand.getResearchGroupId()); - } - boolean canEdit = auth.isAdmin() || auth.userIsExperimenter(); - model.addAttribute("userIsExperimenter", canEdit); - model.addAttribute("researchGroupList", researchGroupList); - model.addAttribute("experimentOptParamDefList", experimentOptParamDefList); - return "lists/measurationAdditionalParams/list"; - } - - @RequestMapping(value="lists/experiment-optional-parameters/delete.html") - public String delete(@RequestParam("id") String idString, @RequestParam("groupid") String idString2) { - log.debug("Deleting experimentOptParamDef."); - if (idString != null) { - int id = Integer.parseInt(idString); - - if (experimentOptParamDefDao.canDelete(id)) { - if(idString2 !=null){ - int groupId = Integer.parseInt(idString2); - - if(groupId==DEFAULT_ID){ // delete default experimentOptParamDef if it's from default group - if(!experimentOptParamDefDao.hasGroupRel(id)){ // delete only if it doesn't have group relationship - experimentOptParamDefDao.delete(experimentOptParamDefDao.read(id)); - }else{ - return "lists/itemUsed"; - } - }else{ - ExperimentOptParamDefGroupRel h = experimentOptParamDefDao.getGroupRel(id,groupId); - if(!experimentOptParamDefDao.isDefault(id)){ // delete only non default experimentOptParamDef - experimentOptParamDefDao.delete(experimentOptParamDefDao.read(id)); - } - experimentOptParamDefDao.deleteGroupRel(h); - } - } - - } else { - return "lists/itemUsed"; - } - } - - return "lists/itemDeleted"; - } - - private void fillAuthResearchGroupList(String defaultName){ - Person loggedUser = personDao.getLoggedPerson(); - - ResearchGroup defaultGroup = new ResearchGroup(DEFAULT_ID,loggedUser,defaultName,"-"); - - if(loggedUser.getAuthority().equals("ROLE_ADMIN")){ - researchGroupList = researchGroupDao.getAllRecords(); - researchGroupList.add(0,defaultGroup); - }else{ - researchGroupList = researchGroupDao.getResearchGroupsWhereMember(loggedUser); - } - } - - private void fillExperimentOptParamDefList(int selectedGroupId){ - if(selectedGroupId == DEFAULT_ID){ - experimentOptParamDefList = experimentOptParamDefDao.getDefaultRecords(); - }else{ - if(!researchGroupList.isEmpty()){ - experimentOptParamDefList = experimentOptParamDefDao.getRecordsByGroup(selectedGroupId); - } - } - } - - public ResearchGroupDao getResearchGroupDao() { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) { - this.researchGroupDao = researchGroupDao; - } - - public ExperimentOptParamDefDao getExperimentOptParamDefDao() { - return experimentOptParamDefDao; - } - - public void setExperimentOptParamDefDao(ExperimentOptParamDefDao experimentOptParamDefDao) { - this.experimentOptParamDefDao = experimentOptParamDefDao; - } - - public HierarchicalMessageSource getMessageSource() - { - return messageSource; - } - - public void setMessageSource(HierarchicalMessageSource messageSource) - { - this.messageSource = messageSource; - } - -} - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -/** -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.ExperimentOptParamDefDao; -import cz.zcu.kiv.eegdatabase.data.pojo.ExperimentOptParamDef; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.AbstractController; -import org.springframework.web.servlet.mvc.multiaction.MultiActionController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.List; - -/** - * @author JiPER - *//* -public class ExperimentOptParamDefMultiController extends MultiActionController { - - private Log log = LogFactory.getLog(getClass()); - @Autowired - private AuthorizationManager auth; - @Autowired - private ExperimentOptParamDefDao experimentOptParamDefDao; - - public ModelAndView list(HttpServletRequest request, HttpServletResponse response) { - log.debug("Processing measuration additional parameters list controller"); - ModelAndView mav = new ModelAndView("lists/measurationAdditionalParams/list"); - - mav.addObject("userIsExperimenter", auth.userIsExperimenter()); - - List list = experimentOptParamDefDao.getItemsForList(); - mav.addObject("measurationAdditionalParamsList", list); - return mav; - } - - public ModelAndView delete(HttpServletRequest request, HttpServletResponse response) { - log.debug("Deleting experiment optional parameter."); - ModelAndView mav = new ModelAndView("lists/itemDeleted"); - - String idString = request.getParameter("id"); - if (idString != null) { - int id = Integer.parseInt(idString); - - if (experimentOptParamDefDao.canDelete(id)) { - experimentOptParamDefDao.delete(experimentOptParamDefDao.read(id)); - } else { - mav.setViewName("lists/itemUsed"); - } - } - - return mav; - } -} - */ diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/filemetadata/AddFileMetadataParamDefCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/filemetadata/AddFileMetadataParamDefCommand.java deleted file mode 100644 index 5fcec2ea..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/filemetadata/AddFileMetadataParamDefCommand.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddFileMetadataParamDefCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.filemetadata; - -/** - * @author Jindra - */ -public class AddFileMetadataParamDefCommand { - - private int id; - private String paramName; - private String paramDataType; - private int researchGroupId; - private String researchGroupTitle; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getParamDataType() { - return paramDataType; - } - - public void setParamDataType(String paramDataType) { - this.paramDataType = paramDataType; - } - - public String getParamName() { - return paramName; - } - - public void setParamName(String paramName) { - this.paramName = paramName; - } - - public int getResearchGroupId() { - return researchGroupId; - } - - public void setResearchGroupId(int researchGroupId) { - this.researchGroupId = researchGroupId; - } - - public String getResearchGroupTitle() { - return researchGroupTitle; - } - - public void setResearchGroupTitle(String researchGroupTitle) { - this.researchGroupTitle = researchGroupTitle; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/filemetadata/AddFileMetadataParamDefController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/filemetadata/AddFileMetadataParamDefController.java deleted file mode 100644 index e91efda7..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/filemetadata/AddFileMetadataParamDefController.java +++ /dev/null @@ -1,196 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddFileMetadataParamDefController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.filemetadata; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.FileMetadataParamDefDao; -import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; -import cz.zcu.kiv.eegdatabase.data.pojo.FileMetadataParamDef; -import cz.zcu.kiv.eegdatabase.data.pojo.FileMetadataParamDefGroupRel; -import cz.zcu.kiv.eegdatabase.data.pojo.FileMetadataParamDefGroupRelId; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.HierarchicalMessageSource; -import org.springframework.ui.ModelMap; -import org.springframework.stereotype.Controller; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.servlet.support.RequestContextUtils; -import javax.servlet.http.HttpServletRequest; - -@Controller -@SessionAttributes("addFileMetadataParamDef") -public class AddFileMetadataParamDefController{ - private Log log = LogFactory.getLog(getClass()); - @Autowired - private AuthorizationManager auth; - @Autowired - private FileMetadataParamDefDao fileMetadataParamDefDao; - @Autowired - private ResearchGroupDao researchGroupDao; - @Autowired - private HierarchicalMessageSource messageSource; - - private final int DEFAULT_ID = -1; - AddFileMetadataParamDefValidator addFileMetadataParamDefValidator; - - @Autowired - public AddFileMetadataParamDefController(AddFileMetadataParamDefValidator addFileMetadataParamDefValidator){ - this.addFileMetadataParamDefValidator = addFileMetadataParamDefValidator; - } - - @RequestMapping(value="lists/file-metadata-definitions/edit.html", method= RequestMethod.GET) - protected String showEditForm(@RequestParam("id") String idString, @RequestParam("groupid") String idString2, ModelMap model, HttpServletRequest request){ - AddFileMetadataParamDefCommand data = new AddFileMetadataParamDefCommand(); - if (auth.userIsExperimenter() || auth.isAdmin()) { - model.addAttribute("userIsExperimenter", true); - if (idString2 != null) { - int id = Integer.parseInt(idString2); - data.setResearchGroupId(id); - if(id!=DEFAULT_ID){ - String title = researchGroupDao.getResearchGroupTitle(id); - data.setResearchGroupTitle(title); - }else{ - String defaultFileMetadataParamDef = messageSource.getMessage("label.defaultFileMetadataParamDef", null, RequestContextUtils.getLocale(request)); - data.setResearchGroupTitle(defaultFileMetadataParamDef); - } - } - if (idString != null) { - // Editation of existing fileMetadataParamDef - int id = Integer.parseInt(idString); - - log.debug("Loading fileMetadataParamDef to the command object for editing."); - FileMetadataParamDef fileMetadataParamDef = fileMetadataParamDefDao.read(id); - - data.setId(id); - data.setParamName(fileMetadataParamDef.getParamName()); - data.setParamDataType(fileMetadataParamDef.getParamDataType()); - } - model.addAttribute("addFileMetadataParamDef",data); - - return "lists/fileMetadataParams/addItemForm"; - }else{ - return "lists/userNotExperimenter"; - } - } - - @RequestMapping(value="lists/file-metadata-definitions/add.html",method=RequestMethod.GET) - protected String showAddForm(@RequestParam("groupid") String idString, ModelMap model, HttpServletRequest request) throws Exception { - AddFileMetadataParamDefCommand data = new AddFileMetadataParamDefCommand(); - if (auth.userIsExperimenter() || auth.isAdmin()) { - if (idString != null) { - int id = Integer.parseInt(idString); - data.setResearchGroupId(id); - if(id!=DEFAULT_ID){ - String title = researchGroupDao.getResearchGroupTitle(id); - data.setResearchGroupTitle(title); - }else{ - String defaultFileMetadataParamDef = messageSource.getMessage("label.defaultFileMetadataParamDef", null, RequestContextUtils.getLocale(request)); - data.setResearchGroupTitle(defaultFileMetadataParamDef); - } - } - model.addAttribute("userIsExperimenter", auth.userIsExperimenter()); - model.addAttribute("addFileMetadataParamDef",data); - return "lists/fileMetadataParams/addItemForm"; - }else{ - return "lists/userNotExperimenter"; - } - } - - - @RequestMapping(method=RequestMethod.POST) - protected String onSubmit(@ModelAttribute("addFileMetadataParamDef") AddFileMetadataParamDefCommand data, BindingResult result,ModelMap model) { - log.debug("Processing form data."); - if (auth.userIsExperimenter() || auth.isAdmin()) { - addFileMetadataParamDefValidator.validate(data,result); - if (result.hasErrors()) { - return "lists/fileMetadataParams/addItemForm"; - } - int fileMetadataParamDefId = data.getId(); - FileMetadataParamDef fileMetadataParamDef; - if (fileMetadataParamDefId > 0) { - // Editing - log.debug("Editing existing fileMetadataParamDef object."); - fileMetadataParamDef = fileMetadataParamDefDao.read(fileMetadataParamDefId); - if(fileMetadataParamDefDao.isDefault(fileMetadataParamDefId)){ - if(data.getResearchGroupId()!=DEFAULT_ID){ - // new fileMetadataParamDef - FileMetadataParamDef newFileMetadataParamDef = new FileMetadataParamDef(); - newFileMetadataParamDef.setDefaultNumber(0); - newFileMetadataParamDef.setParamName(data.getParamName()); - newFileMetadataParamDef.setParamDataType(data.getParamDataType()); - int newId = fileMetadataParamDefDao.create(newFileMetadataParamDef); - FileMetadataParamDefGroupRel rel = fileMetadataParamDefDao.getGroupRel(fileMetadataParamDefId,data.getResearchGroupId()); - // delete old rel, create new one - FileMetadataParamDefGroupRelId newRelId = new FileMetadataParamDefGroupRelId(); - FileMetadataParamDefGroupRel newRel = new FileMetadataParamDefGroupRel(); - newRelId.setFileMetadataParamDefId(newId); - newRelId.setResearchGroupId(data.getResearchGroupId()); - newRel.setId(newRelId); - newRel.setFileMetadataParamDef(newFileMetadataParamDef); - ResearchGroup r = researchGroupDao.read(data.getResearchGroupId()); - newRel.setResearchGroup(r); - fileMetadataParamDefDao.deleteGroupRel(rel); - fileMetadataParamDefDao.createGroupRel(newRel); - }else{ - if(!fileMetadataParamDefDao.hasGroupRel(fileMetadataParamDefId) && fileMetadataParamDefDao.canDelete(fileMetadataParamDefId)){ - fileMetadataParamDef.setParamName(data.getParamName()); - fileMetadataParamDef.setParamDataType(data.getParamDataType()); - }else{ - return "lists/itemUsed"; - } - } - }else{ - fileMetadataParamDef.setParamName(data.getParamName()); - fileMetadataParamDef.setParamDataType(data.getParamDataType()); - } - } else { - // Creating new - fileMetadataParamDef = new FileMetadataParamDef(); - fileMetadataParamDef.setParamName(data.getParamName()); - fileMetadataParamDef.setParamDataType(data.getParamDataType()); - int pkGroup = data.getResearchGroupId(); - if(pkGroup == DEFAULT_ID){ - log.debug("Creating new default fileMetadataParamDef object."); - fileMetadataParamDefDao.createDefaultRecord(fileMetadataParamDef); - }else{ - log.debug("Creating new group fileMetadataParamDef object."); - int pkFileMetadataParamDef = fileMetadataParamDefDao.create(fileMetadataParamDef); - - FileMetadataParamDefGroupRelId fileMetadataParamDefGroupRelId = new FileMetadataParamDefGroupRelId(pkFileMetadataParamDef,pkGroup); - ResearchGroup researchGroup = researchGroupDao.read(pkGroup); - FileMetadataParamDefGroupRel fileMetadataParamDefGroupRel = new FileMetadataParamDefGroupRel(fileMetadataParamDefGroupRelId,researchGroup,fileMetadataParamDef); - fileMetadataParamDefDao.createGroupRel(fileMetadataParamDefGroupRel); - } - - } - log.debug("Returning MAV"); - String redirect = "redirect:list.html?groupid="+data.getResearchGroupId(); - return redirect; - }else{ - return "lists/userNotExperimenter"; - } - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/filemetadata/AddFileMetadataParamDefValidator.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/filemetadata/AddFileMetadataParamDefValidator.java deleted file mode 100644 index e0614cf4..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/filemetadata/AddFileMetadataParamDefValidator.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddFileMetadataParamDefValidator.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.filemetadata; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -/** - * @author JiPER - */ -public class AddFileMetadataParamDefValidator implements Validator { - - private Log log = LogFactory.getLog(getClass()); - - public boolean supports(Class clazz) { - return clazz.equals(AddFileMetadataParamDefCommand.class); - } - - public void validate(Object command, Errors errors) { - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "paramName", "required.field"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "paramDataType", "required.field"); - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/filemetadata/FileMetadataParamDefMultiController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/filemetadata/FileMetadataParamDefMultiController.java deleted file mode 100644 index e2cc9d62..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/filemetadata/FileMetadataParamDefMultiController.java +++ /dev/null @@ -1,208 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * FileMetadataParamDefMultiController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.filemetadata; - -import cz.zcu.kiv.eegdatabase.data.dao.*; -import cz.zcu.kiv.eegdatabase.data.pojo.FileMetadataParamDef; -import cz.zcu.kiv.eegdatabase.data.pojo.FileMetadataParamDefGroupRel; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import cz.zcu.kiv.eegdatabase.logic.controller.list.SelectGroupCommand; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.context.HierarchicalMessageSource; -import org.springframework.web.servlet.support.RequestContextUtils; -import org.springframework.stereotype.Controller; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.context.request.WebRequest; -import javax.servlet.http.HttpServletRequest; -import java.util.List; - -/** - * @author František Liška - */ -@Controller -@SessionAttributes("selectGroupCommand") -public class FileMetadataParamDefMultiController { - private Log log = LogFactory.getLog(getClass()); - @Autowired - private AuthorizationManager auth; - @Autowired - private ResearchGroupDao researchGroupDao; - @Autowired - private FileMetadataParamDefDao fileMetadataParamDefDao; - @Autowired - private PersonDao personDao; - @Autowired - private HierarchicalMessageSource messageSource; - - private List researchGroupList; - private List fileMetadataParamDefList; - private final int DEFAULT_ID = -1; - - @RequestMapping(value="lists/file-metadata-definitions/list.html",method= RequestMethod.GET) - public String showSelectForm(WebRequest webRequest,ModelMap model, HttpServletRequest request){ - log.debug("Processing fileMetadataParamDef list controller"); - SelectGroupCommand selectGroupCommand= new SelectGroupCommand(); - String defaultFileMetadataParamDef = messageSource.getMessage("label.defaultFileMetadataParamDef", null, RequestContextUtils.getLocale(request)); - fillAuthResearchGroupList(defaultFileMetadataParamDef); - String idString = webRequest.getParameter("groupid"); - if(auth.isAdmin()){ - if (idString != null) { - int id = Integer.parseInt(idString); - if(id!=DEFAULT_ID){ - fillFileMetadataParamDefList(id); - selectGroupCommand.setResearchGroupId(id); - }else{ - fillFileMetadataParamDefList(DEFAULT_ID); - selectGroupCommand.setResearchGroupId(DEFAULT_ID); - } - - }else{ - fillFileMetadataParamDefList(DEFAULT_ID); - selectGroupCommand.setResearchGroupId(DEFAULT_ID); - } - model.addAttribute("userIsExperimenter", true); - }else{ - if(!researchGroupList.isEmpty()){ - if (idString != null) { - int id = Integer.parseInt(idString); - fillFileMetadataParamDefList(id); - selectGroupCommand.setResearchGroupId(id); - }else{ - int myGroup = researchGroupList.get(0).getResearchGroupId(); - fillFileMetadataParamDefList(myGroup); - selectGroupCommand.setResearchGroupId(myGroup); - } - model.addAttribute("userIsExperimenter", auth.userIsExperimenter()); - }else{ - model.addAttribute("userIsExperimenter", false); - } - } - model.addAttribute("selectGroupCommand",selectGroupCommand); - model.addAttribute("fileMetadataParamDefList", fileMetadataParamDefList); - model.addAttribute("researchGroupList", researchGroupList); - - - return "lists/fileMetadataParams/list"; - } - - @RequestMapping(value="lists/file-metadata-definitions/list.html",method=RequestMethod.POST) - public String onSubmit(@ModelAttribute("selectGroupCommand") SelectGroupCommand selectGroupCommand, ModelMap model, HttpServletRequest request){ - String defaultFileMetadataParamDef = messageSource.getMessage("label.defaultFileMetadataParamDef", null, RequestContextUtils.getLocale(request)); - fillAuthResearchGroupList(defaultFileMetadataParamDef); - if(!researchGroupList.isEmpty()){ - fillFileMetadataParamDefList(selectGroupCommand.getResearchGroupId()); - } - boolean canEdit = auth.isAdmin() || auth.userIsExperimenter(); - model.addAttribute("userIsExperimenter", canEdit); - model.addAttribute("researchGroupList", researchGroupList); - model.addAttribute("fileMetadataParamDefList", fileMetadataParamDefList); - return "lists/fileMetadataParams/list"; - } - - @RequestMapping(value="lists/file-metadata-definitions/delete.html") - public String delete(@RequestParam("id") String idString, @RequestParam("groupid") String idString2) { - log.debug("Deleting fileMetadataParamDef."); - if (idString != null) { - int id = Integer.parseInt(idString); - - if (fileMetadataParamDefDao.canDelete(id)) { - if(idString2 !=null){ - int groupId = Integer.parseInt(idString2); - - if(groupId==DEFAULT_ID){ // delete default fileMetadataParamDef if it's from default group - if(!fileMetadataParamDefDao.hasGroupRel(id)){ // delete only if it doesn't have group relationship - fileMetadataParamDefDao.delete(fileMetadataParamDefDao.read(id)); - }else{ - return "lists/itemUsed"; - } - }else{ - FileMetadataParamDefGroupRel h = fileMetadataParamDefDao.getGroupRel(id,groupId); - if(!fileMetadataParamDefDao.isDefault(id)){ // delete only non default fileMetadataParamDef - fileMetadataParamDefDao.delete(fileMetadataParamDefDao.read(id)); - } - fileMetadataParamDefDao.deleteGroupRel(h); - } - } - - } else { - return "lists/itemUsed"; - } - } - - return "lists/itemDeleted"; - } - - private void fillAuthResearchGroupList(String defaultName){ - Person loggedUser = personDao.getLoggedPerson(); - - ResearchGroup defaultGroup = new ResearchGroup(DEFAULT_ID,loggedUser,defaultName,"-"); - - if(loggedUser.getAuthority().equals("ROLE_ADMIN")){ - researchGroupList = researchGroupDao.getAllRecords(); - researchGroupList.add(0,defaultGroup); - }else{ - researchGroupList = researchGroupDao.getResearchGroupsWhereMember(loggedUser); - } - } - - private void fillFileMetadataParamDefList(int selectedGroupId){ - if(selectedGroupId == DEFAULT_ID){ - fileMetadataParamDefList = fileMetadataParamDefDao.getDefaultRecords(); - }else{ - if(!researchGroupList.isEmpty()){ - fileMetadataParamDefList = fileMetadataParamDefDao.getRecordsByGroup(selectedGroupId); - } - } - } - - public ResearchGroupDao getResearchGroupDao() { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) { - this.researchGroupDao = researchGroupDao; - } - - public FileMetadataParamDefDao getFileMetadataParamDefDao() { - return fileMetadataParamDefDao; - } - - public void setFileMetadataParamDefDao(FileMetadataParamDefDao fileMetadataParamDefDao) { - this.fileMetadataParamDefDao = fileMetadataParamDefDao; - } - - public HierarchicalMessageSource getMessageSource() - { - return messageSource; - } - - public void setMessageSource(HierarchicalMessageSource messageSource) - { - this.messageSource = messageSource; - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/hardware/AddHardwareCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/hardware/AddHardwareCommand.java deleted file mode 100644 index bf42ed6c..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/hardware/AddHardwareCommand.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddHardwareCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.hardware; - -/** - * @author Jindra - */ -public class AddHardwareCommand { - - private int id; - private String title; - private String type; - private String description; - private int researchGroupId; - private String researchGroupTitle; - - public int getResearchGroupId() { - return researchGroupId; - } - - public void setResearchGroupId(int researchGroupId) { - this.researchGroupId = researchGroupId; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getType() { - return type; - } - - public void setType(String type) { - this.type = type; - } - - public String getResearchGroupTitle() { - return researchGroupTitle; - } - - public void setResearchGroupTitle(String researchGroupTitle) { - this.researchGroupTitle = researchGroupTitle; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/hardware/AddHardwareController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/hardware/AddHardwareController.java deleted file mode 100644 index 4e24498f..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/hardware/AddHardwareController.java +++ /dev/null @@ -1,203 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddHardwareController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.hardware; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.HardwareDao; -import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Hardware; -import cz.zcu.kiv.eegdatabase.data.pojo.HardwareGroupRel; -import cz.zcu.kiv.eegdatabase.data.pojo.HardwareGroupRelId; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.HierarchicalMessageSource; -import org.springframework.ui.ModelMap; -import org.springframework.stereotype.Controller; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.servlet.support.RequestContextUtils; - -import javax.servlet.http.HttpServletRequest; - -@Controller -@SessionAttributes("addHardware") -public class AddHardwareController{ - private Log log = LogFactory.getLog(getClass()); - @Autowired - private AuthorizationManager auth; - @Autowired - private HardwareDao hardwareDao; - @Autowired - private ResearchGroupDao researchGroupDao; - @Autowired - private HierarchicalMessageSource messageSource; - - private final int DEFAULT_ID = -1; - AddHardwareValidator addHardwareValidator; - - @Autowired - public AddHardwareController(AddHardwareValidator addHardwareValidator){ - this.addHardwareValidator = addHardwareValidator; - } - - @RequestMapping(value="lists/hardware-definitions/edit.html", method=RequestMethod.GET) - protected String showEditForm(@RequestParam("id") String idString, @RequestParam("groupid") String idString2, ModelMap model,HttpServletRequest request){ - AddHardwareCommand data = new AddHardwareCommand(); - if (auth.userIsExperimenter() || auth.isAdmin()) { - model.addAttribute("userIsExperimenter", true); - if (idString2 != null) { - int id = Integer.parseInt(idString2); - data.setResearchGroupId(id); - if(id!=DEFAULT_ID){ - String title = researchGroupDao.getResearchGroupTitle(id); - data.setResearchGroupTitle(title); - }else{ - String defaultHardware = messageSource.getMessage("label.defaultHardware", null, RequestContextUtils.getLocale(request)); - data.setResearchGroupTitle(defaultHardware); - } - } - if (idString != null) { - // Editation of existing hardware - int id = Integer.parseInt(idString); - - log.debug("Loading hardware to the command object for editing."); - Hardware hardware = hardwareDao.read(id); - data.setId(id); - data.setDescription(hardware.getDescription()); - data.setTitle(hardware.getTitle()); - data.setType(hardware.getType()); - } - model.addAttribute("addHardware",data); - - return "lists/hardware/addItemForm"; - }else{ - return "lists/userNotExperimenter"; - } - } - - @RequestMapping(value="lists/hardware-definitions/add.html",method=RequestMethod.GET) - protected String showAddForm(@RequestParam("groupid") String idString, ModelMap model, HttpServletRequest request) throws Exception { - AddHardwareCommand data = new AddHardwareCommand(); - if (auth.userIsExperimenter() || auth.isAdmin()) { - if (idString != null) { - int id = Integer.parseInt(idString); - data.setResearchGroupId(id); - if(id!=DEFAULT_ID){ - String title = researchGroupDao.getResearchGroupTitle(id); - data.setResearchGroupTitle(title); - }else{ - String defaultHardware = messageSource.getMessage("label.defaultHardware", null, RequestContextUtils.getLocale(request)); - data.setResearchGroupTitle(defaultHardware); - } - } - model.addAttribute("userIsExperimenter", auth.userIsExperimenter()); - model.addAttribute("addHardware",data); - return "lists/hardware/addItemForm"; - }else{ - return "lists/userNotExperimenter"; - } - } - - - @RequestMapping(method=RequestMethod.POST) - protected String onSubmit(@ModelAttribute("addHardware") AddHardwareCommand data, BindingResult result,ModelMap model) { - log.debug("Processing form data."); - - if (auth.userIsExperimenter() || auth.isAdmin()) { - addHardwareValidator.validate(data,result); - if (result.hasErrors()) { - return "lists/hardware/addItemForm"; - } - int hwId = data.getId(); - Hardware hardware; - if (hwId > 0) { - // Editing - log.debug("Editing existing hardware object."); - hardware = hardwareDao.read(hwId); - - if(hardwareDao.isDefault(hwId)){ - if(data.getResearchGroupId()!=DEFAULT_ID){ - // new hw - Hardware newHw = new Hardware(); - newHw.setDefaultNumber(0); - newHw.setDescription(data.getDescription()); - newHw.setTitle(data.getTitle()); - newHw.setType(data.getType()); - int newId = hardwareDao.create(newHw); - HardwareGroupRel rel = hardwareDao.getGroupRel(hwId,data.getResearchGroupId()); - // delete old rel, create new one - HardwareGroupRelId newRelId = new HardwareGroupRelId(); - HardwareGroupRel newRel = new HardwareGroupRel(); - newRelId.setHardwareId(newId); - newRelId.setResearchGroupId(data.getResearchGroupId()); - newRel.setId(newRelId); - newRel.setHardware(newHw); - ResearchGroup r = researchGroupDao.read(data.getResearchGroupId()); - newRel.setResearchGroup(r); - hardwareDao.deleteGroupRel(rel); - hardwareDao.createGroupRel(newRel); - }else{ - if(!hardwareDao.hasGroupRel(hwId) && hardwareDao.canDelete(hwId)){ - hardware.setDescription(data.getDescription()); - hardware.setTitle(data.getTitle()); - hardware.setType(data.getType()); - }else{ - return "lists/itemUsed"; - } - } - }else{ - hardware.setDescription(data.getDescription()); - hardware.setTitle(data.getTitle()); - hardware.setType(data.getType()); - } - } else { - // Creating new - hardware = new Hardware(); - hardware.setTitle(data.getTitle()); - hardware.setType(data.getType()); - hardware.setDescription(data.getDescription()); - int pkGroup = data.getResearchGroupId(); - if(pkGroup == DEFAULT_ID){ - log.debug("Creating new default hardware object."); - hardwareDao.createDefaultRecord(hardware); - }else{ - log.debug("Creating new group hardware object."); - int pkHardware = hardwareDao.create(hardware); - - HardwareGroupRelId hardwareGroupRelId = new HardwareGroupRelId(pkHardware,pkGroup); - ResearchGroup researchGroup = researchGroupDao.read(pkGroup); - HardwareGroupRel hardwareGroupRel = new HardwareGroupRel(hardwareGroupRelId,researchGroup,hardware); - hardwareDao.createGroupRel(hardwareGroupRel); - } - - } - log.debug("Returning MAV"); - String redirect = "redirect:list.html?groupid="+data.getResearchGroupId(); - return redirect; - }else{ - return "lists/userNotExperimenter"; - } - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/hardware/AddHardwareValidator.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/hardware/AddHardwareValidator.java deleted file mode 100644 index 7a9f0303..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/hardware/AddHardwareValidator.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddHardwareValidator.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.hardware; - -import cz.zcu.kiv.eegdatabase.data.dao.HardwareDao; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -/** - * @author JiPER - */ -public class AddHardwareValidator implements Validator { - - private Log log = LogFactory.getLog(getClass()); - @Autowired - private HardwareDao hardwareDao; - private final int DEFAULT_ID = -1; - - public boolean supports(Class clazz) { - return clazz.equals(AddHardwareCommand.class); - } - - public void validate(Object command, Errors errors) { - AddHardwareCommand data = (AddHardwareCommand) command; - - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "title", "required.field"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "type", "required.field"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "required.field"); - - if(data.getResearchGroupId()==DEFAULT_ID){ - if (!hardwareDao.canSaveDefaultTitle(data.getTitle(),data.getId())) { - errors.rejectValue("title", "error.valueAlreadyInDatabase"); - } - }else{ - if (!hardwareDao.canSaveTitle(data.getTitle(), data.getResearchGroupId(),data.getId())) { - errors.rejectValue("title", "error.valueAlreadyInDatabase"); - } - } - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/hardware/HardwareMultiController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/hardware/HardwareMultiController.java deleted file mode 100644 index d3121d99..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/hardware/HardwareMultiController.java +++ /dev/null @@ -1,211 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * HardwareMultiController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.hardware; - -import cz.zcu.kiv.eegdatabase.data.dao.*; -import cz.zcu.kiv.eegdatabase.data.pojo.Hardware; -import cz.zcu.kiv.eegdatabase.data.pojo.HardwareGroupRel; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import cz.zcu.kiv.eegdatabase.logic.controller.list.SelectGroupCommand; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.context.HierarchicalMessageSource; -import org.springframework.stereotype.Controller; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.context.request.WebRequest; -import org.springframework.web.servlet.support.RequestContextUtils; - -import javax.servlet.http.HttpServletRequest; -import java.util.List; - -/** - * @author František Liška - */ -@Controller -@SessionAttributes("selectGroupCommand") -public class HardwareMultiController { - private Log log = LogFactory.getLog(getClass()); - @Autowired - private AuthorizationManager auth; - @Autowired - private ResearchGroupDao researchGroupDao; - @Autowired - private HardwareDao hardwareDao; - @Autowired - private PersonDao personDao; - @Autowired - private HierarchicalMessageSource messageSource; - - private List researchGroupList; - private List hardwareList; - private final int DEFAULT_ID = -1; - - @RequestMapping(value="lists/hardware-definitions/list.html",method=RequestMethod.GET) - public String showSelectForm(WebRequest webRequest,ModelMap model, HttpServletRequest request){ - log.debug("Processing hardware list controller"); - SelectGroupCommand selectGroupCommand= new SelectGroupCommand(); - String defaultHardware = messageSource.getMessage("label.defaultHardware", null, RequestContextUtils.getLocale(request)); - fillAuthResearchGroupList(defaultHardware); - String idString = webRequest.getParameter("groupid"); - if(auth.isAdmin()){ - if (idString != null) { - int id = Integer.parseInt(idString); - if(id!=DEFAULT_ID){ - fillHardwareList(id); - selectGroupCommand.setResearchGroupId(id); - }else{ - fillHardwareList(DEFAULT_ID); - selectGroupCommand.setResearchGroupId(DEFAULT_ID); - } - - }else{ - fillHardwareList(DEFAULT_ID); - selectGroupCommand.setResearchGroupId(DEFAULT_ID); - } - model.addAttribute("userIsExperimenter", true); - }else{ - if(!researchGroupList.isEmpty()){ - if (idString != null) { - int id = Integer.parseInt(idString); - fillHardwareList(id); - selectGroupCommand.setResearchGroupId(id); - }else{ - int myGroup = researchGroupList.get(0).getResearchGroupId(); - fillHardwareList(myGroup); - selectGroupCommand.setResearchGroupId(myGroup); - } - model.addAttribute("userIsExperimenter", auth.userIsExperimenter()); - }else{ - model.addAttribute("userIsExperimenter", false); - } - } - model.addAttribute("selectGroupCommand",selectGroupCommand); - model.addAttribute("hardwareList", hardwareList); - model.addAttribute("researchGroupList", researchGroupList); - - - return "lists/hardware/list"; - } - - @RequestMapping(value="lists/hardware-definitions/list.html",method=RequestMethod.POST) - public String onSubmit(@ModelAttribute("selectGroupCommand") SelectGroupCommand selectGroupCommand, ModelMap model, HttpServletRequest request){ - String defaultHardware = messageSource.getMessage("label.defaultHardware", null, RequestContextUtils.getLocale(request)); - fillAuthResearchGroupList(defaultHardware); - if(!researchGroupList.isEmpty()){ - fillHardwareList(selectGroupCommand.getResearchGroupId()); - } - boolean canEdit = auth.isAdmin() || auth.userIsExperimenter(); - model.addAttribute("userIsExperimenter", canEdit); - model.addAttribute("researchGroupList", researchGroupList); - model.addAttribute("hardwareList", hardwareList); - return "lists/hardware/list"; - } - - @RequestMapping(value="lists/hardware-definitions/delete.html") - public String delete(@RequestParam("id") String idString, @RequestParam("groupid") String idString2) { - log.debug("Deleting hardware."); - if (idString != null) { - int id = Integer.parseInt(idString); - - if (hardwareDao.canDelete(id)) { - if(idString2 !=null){ - int groupId = Integer.parseInt(idString2); - - if(groupId==DEFAULT_ID){ // delete default hardware if it's from default group - if(!hardwareDao.hasGroupRel(id)){ // delete only if it doesn't have group relationship - hardwareDao.delete(hardwareDao.read(id)); - }else{ - System.out.println("hasGroupRel"); - return "lists/itemUsed"; - } - }else{ - HardwareGroupRel h = hardwareDao.getGroupRel(id,groupId); - if(!hardwareDao.isDefault(id)){ // delete only non default hardware - hardwareDao.delete(hardwareDao.read(id)); - } - hardwareDao.deleteGroupRel(h); - } - } - - } else { - System.out.println("cannotDelete"); - return "lists/itemUsed"; - } - } - - return "lists/itemDeleted"; - } - - private void fillAuthResearchGroupList(String defaultName){ - Person loggedUser = personDao.getLoggedPerson(); - ResearchGroup defaultGroup = new ResearchGroup(DEFAULT_ID,loggedUser,defaultName,"-"); - - if(loggedUser.getAuthority().equals("ROLE_ADMIN")){ - researchGroupList = researchGroupDao.getAllRecords(); - researchGroupList.add(0,defaultGroup); - }else{ - researchGroupList = researchGroupDao.getResearchGroupsWhereMember(loggedUser); - } - } - - private void fillHardwareList(int selectedGroupId){ - if(selectedGroupId == DEFAULT_ID){ - hardwareList = hardwareDao.getDefaultRecords(); - }else{ - if(!researchGroupList.isEmpty()){ - hardwareList = hardwareDao.getRecordsByGroup(selectedGroupId); - } - } - } - - public ResearchGroupDao getResearchGroupDao() { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) { - this.researchGroupDao = researchGroupDao; - } - - public HardwareDao getHardwareDao() { - return hardwareDao; - } - - public void setHardwareDao(HardwareDao hardwareDao) { - this.hardwareDao = hardwareDao; - } - - public HierarchicalMessageSource getMessageSource() - { - return messageSource; - } - - public void setMessageSource(HierarchicalMessageSource messageSource) - { - this.messageSource = messageSource; - } - - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/personoptparamdef/AddPersonOptParamDefCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/personoptparamdef/AddPersonOptParamDefCommand.java deleted file mode 100644 index 45205a8c..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/personoptparamdef/AddPersonOptParamDefCommand.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddPersonOptParamDefCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.personoptparamdef; - -/** - * @author Jindra - */ -public class AddPersonOptParamDefCommand { - - private int id; - private String paramName; - private String paramDataType; - private int researchGroupId; - private String researchGroupTitle; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getParamDataType() { - return paramDataType; - } - - public void setParamDataType(String paramDataType) { - this.paramDataType = paramDataType; - } - - public String getParamName() { - return paramName; - } - - public void setParamName(String paramName) { - this.paramName = paramName; - } - - public int getResearchGroupId() { - return researchGroupId; - } - - public void setResearchGroupId(int researchGroupId) { - this.researchGroupId = researchGroupId; - } - - public String getResearchGroupTitle() { - return researchGroupTitle; - } - - public void setResearchGroupTitle(String researchGroupTitle) { - this.researchGroupTitle = researchGroupTitle; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/personoptparamdef/AddPersonOptParamDefController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/personoptparamdef/AddPersonOptParamDefController.java deleted file mode 100644 index 29d700be..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/personoptparamdef/AddPersonOptParamDefController.java +++ /dev/null @@ -1,196 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddPersonOptParamDefController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.personoptparamdef; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.PersonOptParamDefDao; -import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; -import cz.zcu.kiv.eegdatabase.data.pojo.PersonOptParamDef; -import cz.zcu.kiv.eegdatabase.data.pojo.PersonOptParamDefGroupRel; -import cz.zcu.kiv.eegdatabase.data.pojo.PersonOptParamDefGroupRelId; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.HierarchicalMessageSource; -import org.springframework.ui.ModelMap; -import org.springframework.stereotype.Controller; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.servlet.support.RequestContextUtils; -import javax.servlet.http.HttpServletRequest; - -@Controller -@SessionAttributes("addPersonOptParamDef") -public class AddPersonOptParamDefController{ - private Log log = LogFactory.getLog(getClass()); - @Autowired - private AuthorizationManager auth; - @Autowired - private PersonOptParamDefDao personOptParamDefDao; - @Autowired - private ResearchGroupDao researchGroupDao; - @Autowired - private HierarchicalMessageSource messageSource; - - private final int DEFAULT_ID = -1; - AddPersonOptParamDefValidator addPersonOptParamDefValidator; - - @Autowired - public AddPersonOptParamDefController(AddPersonOptParamDefValidator addPersonOptParamDefValidator){ - this.addPersonOptParamDefValidator = addPersonOptParamDefValidator; - } - - @RequestMapping(value="lists/person-optional-parameters/edit.html", method= RequestMethod.GET) - protected String showEditForm(@RequestParam("id") String idString, @RequestParam("groupid") String idString2, ModelMap model, HttpServletRequest request){ - AddPersonOptParamDefCommand data = new AddPersonOptParamDefCommand(); - if (auth.userIsExperimenter() || auth.isAdmin()) { - model.addAttribute("userIsExperimenter", true); - if (idString2 != null) { - int id = Integer.parseInt(idString2); - data.setResearchGroupId(id); - if(id!=DEFAULT_ID){ - String title = researchGroupDao.getResearchGroupTitle(id); - data.setResearchGroupTitle(title); - }else{ - String defaultPersonOptParamDef = messageSource.getMessage("label.defaultPersonOptParamDef", null, RequestContextUtils.getLocale(request)); - data.setResearchGroupTitle(defaultPersonOptParamDef); - } - } - if (idString != null) { - // Editation of existing personOptParamDef - int id = Integer.parseInt(idString); - - log.debug("Loading personOptParamDef to the command object for editing."); - PersonOptParamDef personOptParamDef = personOptParamDefDao.read(id); - - data.setId(id); - data.setParamName(personOptParamDef.getParamName()); - data.setParamDataType(personOptParamDef.getParamDataType()); - } - model.addAttribute("addPersonOptParamDef",data); - - return "lists/personAdditionalParams/addItemForm"; - }else{ - return "lists/userNotExperimenter"; - } - } - - @RequestMapping(value="lists/person-optional-parameters/add.html",method=RequestMethod.GET) - protected String showAddForm(@RequestParam("groupid") String idString, ModelMap model, HttpServletRequest request) throws Exception { - AddPersonOptParamDefCommand data = new AddPersonOptParamDefCommand(); - if (auth.userIsExperimenter() || auth.isAdmin()) { - if (idString != null) { - int id = Integer.parseInt(idString); - data.setResearchGroupId(id); - if(id!=DEFAULT_ID){ - String title = researchGroupDao.getResearchGroupTitle(id); - data.setResearchGroupTitle(title); - }else{ - String defaultPersonOptParamDef = messageSource.getMessage("label.defaultPersonOptParamDef", null, RequestContextUtils.getLocale(request)); - data.setResearchGroupTitle(defaultPersonOptParamDef); - } - } - model.addAttribute("userIsExperimenter", auth.userIsExperimenter()); - model.addAttribute("addPersonOptParamDef",data); - return "lists/personAdditionalParams/addItemForm"; - }else{ - return "lists/userNotExperimenter"; - } - } - - - @RequestMapping(method=RequestMethod.POST) - protected String onSubmit(@ModelAttribute("addPersonOptParamDef") AddPersonOptParamDefCommand data, BindingResult result,ModelMap model) { - log.debug("Processing form data."); - if (auth.userIsExperimenter() || auth.isAdmin()) { - addPersonOptParamDefValidator.validate(data,result); - if (result.hasErrors()) { - return "lists/personAdditionalParams/addItemForm"; - } - int personOptParamDefId = data.getId(); - PersonOptParamDef personOptParamDef; - if (personOptParamDefId > 0) { - // Editing - log.debug("Editing existing personOptParamDef object."); - personOptParamDef = personOptParamDefDao.read(personOptParamDefId); - if(personOptParamDefDao.isDefault(personOptParamDefId)){ - if(data.getResearchGroupId()!=DEFAULT_ID){ - // new personOptParamDef - PersonOptParamDef newPersonOptParamDef = new PersonOptParamDef(); - newPersonOptParamDef.setDefaultNumber(0); - newPersonOptParamDef.setParamName(data.getParamName()); - newPersonOptParamDef.setParamDataType(data.getParamDataType()); - int newId = personOptParamDefDao.create(newPersonOptParamDef); - PersonOptParamDefGroupRel rel = personOptParamDefDao.getGroupRel(personOptParamDefId,data.getResearchGroupId()); - // delete old rel, create new one - PersonOptParamDefGroupRelId newRelId = new PersonOptParamDefGroupRelId(); - PersonOptParamDefGroupRel newRel = new PersonOptParamDefGroupRel(); - newRelId.setPersonOptParamDefId(newId); - newRelId.setResearchGroupId(data.getResearchGroupId()); - newRel.setId(newRelId); - newRel.setPersonOptParamDef(newPersonOptParamDef); - ResearchGroup r = researchGroupDao.read(data.getResearchGroupId()); - newRel.setResearchGroup(r); - personOptParamDefDao.deleteGroupRel(rel); - personOptParamDefDao.createGroupRel(newRel); - }else{ - if(!personOptParamDefDao.hasGroupRel(personOptParamDefId) && personOptParamDefDao.canDelete(personOptParamDefId)){ - personOptParamDef.setParamName(data.getParamName()); - personOptParamDef.setParamDataType(data.getParamDataType()); - }else{ - return "lists/itemUsed"; - } - } - }else{ - personOptParamDef.setParamName(data.getParamName()); - personOptParamDef.setParamDataType(data.getParamDataType()); - } - } else { - // Creating new - personOptParamDef = new PersonOptParamDef(); - personOptParamDef.setParamName(data.getParamName()); - personOptParamDef.setParamDataType(data.getParamDataType()); - int pkGroup = data.getResearchGroupId(); - if(pkGroup == DEFAULT_ID){ - log.debug("Creating new default personOptParamDef object."); - personOptParamDefDao.createDefaultRecord(personOptParamDef); - }else{ - log.debug("Creating new group personOptParamDef object."); - int pkPersonOptParamDef = personOptParamDefDao.create(personOptParamDef); - - PersonOptParamDefGroupRelId personOptParamDefGroupRelId = new PersonOptParamDefGroupRelId(pkPersonOptParamDef,pkGroup); - ResearchGroup researchGroup = researchGroupDao.read(pkGroup); - PersonOptParamDefGroupRel personOptParamDefGroupRel = new PersonOptParamDefGroupRel(personOptParamDefGroupRelId,researchGroup,personOptParamDef); - personOptParamDefDao.createGroupRel(personOptParamDefGroupRel); - } - - } - log.debug("Returning MAV"); - String redirect = "redirect:list.html?groupid="+data.getResearchGroupId(); - return redirect; - }else{ - return "lists/userNotExperimenter"; - } - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/personoptparamdef/AddPersonOptParamDefValidator.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/personoptparamdef/AddPersonOptParamDefValidator.java deleted file mode 100644 index dd0f466a..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/personoptparamdef/AddPersonOptParamDefValidator.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddPersonOptParamDefValidator.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.personoptparamdef; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -/** - * @author JiPER - */ -public class AddPersonOptParamDefValidator implements Validator { - - private Log log = LogFactory.getLog(getClass()); - - public boolean supports(Class clazz) { - return clazz.equals(AddPersonOptParamDefCommand.class); - } - - public void validate(Object command, Errors errors) { - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "paramName", "required.field"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "paramDataType", "required.field"); - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/personoptparamdef/PersonOptParamDefMultiController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/personoptparamdef/PersonOptParamDefMultiController.java deleted file mode 100644 index cd24b08b..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/personoptparamdef/PersonOptParamDefMultiController.java +++ /dev/null @@ -1,208 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * PersonOptParamDefMultiController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.personoptparamdef; - -import cz.zcu.kiv.eegdatabase.data.dao.*; -import cz.zcu.kiv.eegdatabase.data.pojo.PersonOptParamDef; -import cz.zcu.kiv.eegdatabase.data.pojo.PersonOptParamDefGroupRel; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import cz.zcu.kiv.eegdatabase.logic.controller.list.SelectGroupCommand; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.context.HierarchicalMessageSource; -import org.springframework.web.servlet.support.RequestContextUtils; -import org.springframework.stereotype.Controller; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.context.request.WebRequest; -import javax.servlet.http.HttpServletRequest; -import java.util.List; - -/** - * @author František Liška - */ -@Controller -@SessionAttributes("selectGroupCommand") -public class PersonOptParamDefMultiController { - private Log log = LogFactory.getLog(getClass()); - @Autowired - private AuthorizationManager auth; - @Autowired - private ResearchGroupDao researchGroupDao; - @Autowired - private PersonOptParamDefDao personOptParamDefDao; - @Autowired - private PersonDao personDao; - @Autowired - private HierarchicalMessageSource messageSource; - - private List researchGroupList; - private List personOptParamDefList; - private final int DEFAULT_ID = -1; - - @RequestMapping(value="lists/person-optional-parameters/list.html",method= RequestMethod.GET) - public String showSelectForm(WebRequest webRequest,ModelMap model, HttpServletRequest request){ - log.debug("Processing personOptParamDef list controller"); - SelectGroupCommand selectGroupCommand= new SelectGroupCommand(); - String defaultPersonOptParamDef = messageSource.getMessage("label.defaultPersonOptParamDef", null, RequestContextUtils.getLocale(request)); - fillAuthResearchGroupList(defaultPersonOptParamDef); - String idString = webRequest.getParameter("groupid"); - if(auth.isAdmin()){ - if (idString != null) { - int id = Integer.parseInt(idString); - if(id!=DEFAULT_ID){ - fillPersonOptParamDefList(id); - selectGroupCommand.setResearchGroupId(id); - }else{ - fillPersonOptParamDefList(DEFAULT_ID); - selectGroupCommand.setResearchGroupId(DEFAULT_ID); - } - - }else{ - fillPersonOptParamDefList(DEFAULT_ID); - selectGroupCommand.setResearchGroupId(DEFAULT_ID); - } - model.addAttribute("userIsExperimenter", true); - }else{ - if(!researchGroupList.isEmpty()){ - if (idString != null) { - int id = Integer.parseInt(idString); - fillPersonOptParamDefList(id); - selectGroupCommand.setResearchGroupId(id); - }else{ - int myGroup = researchGroupList.get(0).getResearchGroupId(); - fillPersonOptParamDefList(myGroup); - selectGroupCommand.setResearchGroupId(myGroup); - } - model.addAttribute("userIsExperimenter", auth.userIsExperimenter()); - }else{ - model.addAttribute("userIsExperimenter", false); - } - } - model.addAttribute("selectGroupCommand",selectGroupCommand); - model.addAttribute("personOptParamDefList", personOptParamDefList); - model.addAttribute("researchGroupList", researchGroupList); - - - return "lists/personAdditionalParams/list"; - } - - @RequestMapping(value="lists/person-optional-parameters/list.html",method=RequestMethod.POST) - public String onSubmit(@ModelAttribute("selectGroupCommand") SelectGroupCommand selectGroupCommand, ModelMap model, HttpServletRequest request){ - String defaultPersonOptParamDef = messageSource.getMessage("label.defaultPersonOptParamDef", null, RequestContextUtils.getLocale(request)); - fillAuthResearchGroupList(defaultPersonOptParamDef); - if(!researchGroupList.isEmpty()){ - fillPersonOptParamDefList(selectGroupCommand.getResearchGroupId()); - } - boolean canEdit = auth.isAdmin() || auth.userIsExperimenter(); - model.addAttribute("userIsExperimenter", canEdit); - model.addAttribute("researchGroupList", researchGroupList); - model.addAttribute("personOptParamDefList", personOptParamDefList); - return "lists/personAdditionalParams/list"; - } - - @RequestMapping(value="lists/person-optional-parameters/delete.html") - public String delete(@RequestParam("id") String idString, @RequestParam("groupid") String idString2) { - log.debug("Deleting personOptParamDef."); - if (idString != null) { - int id = Integer.parseInt(idString); - - if (personOptParamDefDao.canDelete(id)) { - if(idString2 !=null){ - int groupId = Integer.parseInt(idString2); - - if(groupId==DEFAULT_ID){ // delete default personOptParamDef if it's from default group - if(!personOptParamDefDao.hasGroupRel(id)){ // delete only if it doesn't have group relationship - personOptParamDefDao.delete(personOptParamDefDao.read(id)); - }else{ - return "lists/itemUsed"; - } - }else{ - PersonOptParamDefGroupRel h = personOptParamDefDao.getGroupRel(id,groupId); - if(!personOptParamDefDao.isDefault(id)){ // delete only non default personOptParamDef - personOptParamDefDao.delete(personOptParamDefDao.read(id)); - } - personOptParamDefDao.deleteGroupRel(h); - } - } - - } else { - return "lists/itemUsed"; - } - } - - return "lists/itemDeleted"; - } - - private void fillAuthResearchGroupList(String defaultName){ - Person loggedUser = personDao.getLoggedPerson(); - - ResearchGroup defaultGroup = new ResearchGroup(DEFAULT_ID,loggedUser,defaultName,"-"); - - if(loggedUser.getAuthority().equals("ROLE_ADMIN")){ - researchGroupList = researchGroupDao.getAllRecords(); - researchGroupList.add(0,defaultGroup); - }else{ - researchGroupList = researchGroupDao.getResearchGroupsWhereMember(loggedUser); - } - } - - private void fillPersonOptParamDefList(int selectedGroupId){ - if(selectedGroupId == DEFAULT_ID){ - personOptParamDefList = personOptParamDefDao.getDefaultRecords(); - }else{ - if(!researchGroupList.isEmpty()){ - personOptParamDefList = personOptParamDefDao.getRecordsByGroup(selectedGroupId); - } - } - } - - public ResearchGroupDao getResearchGroupDao() { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) { - this.researchGroupDao = researchGroupDao; - } - - public PersonOptParamDefDao getPersonOptParamDefDao() { - return personOptParamDefDao; - } - - public void setPersonOptParamDefDao(PersonOptParamDefDao personOptParamDefDao) { - this.personOptParamDefDao = personOptParamDefDao; - } - - public HierarchicalMessageSource getMessageSource() - { - return messageSource; - } - - public void setMessageSource(HierarchicalMessageSource messageSource) - { - this.messageSource = messageSource; - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/weather/AddWeatherCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/weather/AddWeatherCommand.java deleted file mode 100644 index 29cc7047..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/weather/AddWeatherCommand.java +++ /dev/null @@ -1,75 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddWeatherCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.weather; - -/** - * @author Jindra - */ -public class AddWeatherCommand { - - private int id; - private String title; - private String description; - private int researchGroupId; - private String researchGroupTitle; - - public void setId(int id) { - this.id = id; - } - - public int getId() { - return id; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public int getResearchGroupId() { - return researchGroupId; - } - - public void setResearchGroupId(int researchGroupId) { - this.researchGroupId = researchGroupId; - } - - public String getResearchGroupTitle() { - return researchGroupTitle; - } - - public void setResearchGroupTitle(String researchGroupTitle) { - this.researchGroupTitle = researchGroupTitle; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/weather/AddWeatherController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/weather/AddWeatherController.java deleted file mode 100644 index 37761722..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/weather/AddWeatherController.java +++ /dev/null @@ -1,198 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddWeatherController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.weather; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.WeatherDao; -import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Weather; -import cz.zcu.kiv.eegdatabase.data.pojo.WeatherGroupRel; -import cz.zcu.kiv.eegdatabase.data.pojo.WeatherGroupRelId; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.HierarchicalMessageSource; -import org.springframework.ui.ModelMap; -import org.springframework.stereotype.Controller; -import org.springframework.validation.BindingResult; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.servlet.support.RequestContextUtils; -import javax.servlet.http.HttpServletRequest; - -@Controller -@SessionAttributes("addWeather") -public class AddWeatherController{ - private Log log = LogFactory.getLog(getClass()); - @Autowired - private AuthorizationManager auth; - @Autowired - private WeatherDao weatherDao; - @Autowired - private ResearchGroupDao researchGroupDao; - @Autowired - private HierarchicalMessageSource messageSource; - - private final int DEFAULT_ID = -1; - AddWeatherValidator addWeatherValidator; - - @Autowired - public AddWeatherController(AddWeatherValidator addWeatherValidator){ - this.addWeatherValidator = addWeatherValidator; - } - - @RequestMapping(value="lists/weather-definitions/edit.html", method= RequestMethod.GET) - protected String showEditForm(@RequestParam("id") String idString, @RequestParam("groupid") String idString2, ModelMap model, HttpServletRequest request){ - AddWeatherCommand data = new AddWeatherCommand(); - if (auth.userIsExperimenter() || auth.isAdmin()) { - model.addAttribute("userIsExperimenter", true); - if (idString2 != null) { - int id = Integer.parseInt(idString2); - data.setResearchGroupId(id); - if(id!=DEFAULT_ID){ - String title = researchGroupDao.getResearchGroupTitle(id); - data.setResearchGroupTitle(title); - }else{ - String defaultWeather = messageSource.getMessage("label.defaultWeather", null, RequestContextUtils.getLocale(request)); - data.setResearchGroupTitle(defaultWeather); - } - } - if (idString != null) { - // Editation of existing weather - int id = Integer.parseInt(idString); - - log.debug("Loading weather to the command object for editing."); - Weather weather = weatherDao.read(id); - - data.setId(id); - data.setTitle(weather.getTitle()); - data.setDescription(weather.getDescription()); - } - model.addAttribute("addWeather",data); - - return "lists/weather/addItemForm"; - }else{ - return "lists/userNotExperimenter"; - } - } - - @RequestMapping(value="lists/weather-definitions/add.html",method=RequestMethod.GET) - protected String showAddForm(@RequestParam("groupid") String idString, ModelMap model, HttpServletRequest request) throws Exception { - AddWeatherCommand data = new AddWeatherCommand(); - if (auth.userIsExperimenter() || auth.isAdmin()) { - if (idString != null) { - int id = Integer.parseInt(idString); - data.setResearchGroupId(id); - if(id!=DEFAULT_ID){ - String title = researchGroupDao.getResearchGroupTitle(id); - data.setResearchGroupTitle(title); - }else{ - String defaultWeather = messageSource.getMessage("label.defaultWeather", null, RequestContextUtils.getLocale(request)); - data.setResearchGroupTitle(defaultWeather); - } - } - model.addAttribute("userIsExperimenter", auth.userIsExperimenter()); - model.addAttribute("addWeather",data); - return "lists/weather/addItemForm"; - }else{ - return "lists/userNotExperimenter"; - } - } - - - @RequestMapping(method=RequestMethod.POST) - protected String onSubmit(@ModelAttribute("addWeather") AddWeatherCommand data, BindingResult result,ModelMap model) { - log.debug("Processing form data."); - - if (auth.userIsExperimenter() || auth.isAdmin()) { - addWeatherValidator.validate(data,result); - if (result.hasErrors()) { - return "lists/weather/addItemForm"; - } - int weatherId = data.getId(); - Weather weather; - if (weatherId > 0) { - // Editing - log.debug("Editing existing weather object."); - weather = weatherDao.read(weatherId); - - if(weatherDao.isDefault(weatherId)){ - if(data.getResearchGroupId()!=DEFAULT_ID){ - // new weather - Weather newWeather = new Weather(); - newWeather.setDefaultNumber(0); - newWeather.setTitle(data.getTitle()); - newWeather.setDescription(data.getDescription()); - int newId = weatherDao.create(newWeather); - WeatherGroupRel rel = weatherDao.getGroupRel(weatherId,data.getResearchGroupId()); - // delete old rel, create new one - WeatherGroupRelId newRelId = new WeatherGroupRelId(); - WeatherGroupRel newRel = new WeatherGroupRel(); - newRelId.setWeatherId(newId); - newRelId.setResearchGroupId(data.getResearchGroupId()); - newRel.setId(newRelId); - newRel.setWeather(newWeather); - ResearchGroup r = researchGroupDao.read(data.getResearchGroupId()); - newRel.setResearchGroup(r); - weatherDao.deleteGroupRel(rel); - weatherDao.createGroupRel(newRel); - }else{ - if(!weatherDao.hasGroupRel(weatherId) && weatherDao.canDelete(weatherId)){ - weather.setTitle(data.getTitle()); - weather.setDescription(data.getDescription()); - }else{ - return "lists/itemUsed"; - } - } - }else{ - weather.setTitle(data.getTitle()); - weather.setDescription(data.getDescription()); - } - } else { - // Creating new - weather = new Weather(); - weather.setTitle(data.getTitle()); - weather.setDescription(data.getDescription()); - int pkGroup = data.getResearchGroupId(); - if(pkGroup == DEFAULT_ID){ - log.debug("Creating new default weather object."); - weatherDao.createDefaultRecord(weather); - }else{ - log.debug("Creating new group weather object."); - int pkWeather = weatherDao.create(weather); - - WeatherGroupRelId weatherGroupRelId = new WeatherGroupRelId(pkWeather,pkGroup); - ResearchGroup researchGroup = researchGroupDao.read(pkGroup); - WeatherGroupRel weatherGroupRel = new WeatherGroupRel(weatherGroupRelId,researchGroup,weather); - weatherDao.createGroupRel(weatherGroupRel); - } - - } - log.debug("Returning MAV"); - String redirect = "redirect:list.html?groupid="+data.getResearchGroupId(); - return redirect; - }else{ - return "lists/userNotExperimenter"; - } - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/weather/AddWeatherValidator.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/weather/AddWeatherValidator.java deleted file mode 100644 index dc6791c8..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/weather/AddWeatherValidator.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddWeatherValidator.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.weather; - -import cz.zcu.kiv.eegdatabase.data.dao.WeatherDao; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -/** - * @author JiPER - */ -public class AddWeatherValidator implements Validator { - - private Log log = LogFactory.getLog(getClass()); - @Autowired - private WeatherDao weatherDao; - private final int DEFAULT_ID = -1; - - public boolean supports(Class clazz) { - return clazz.equals(AddWeatherCommand.class); - } - - public void validate(Object command, Errors errors) { - AddWeatherCommand data = (AddWeatherCommand) command; - - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "title", "required.field"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "required.field"); - - if (data.getTitle().length() > 30) { - errors.rejectValue("title", "invalid.fieldLength30"); - } - if (data.getDescription().length() > 30) { - errors.rejectValue("description", "invalid.fieldLength30"); - } - - if(data.getResearchGroupId()==DEFAULT_ID){ - if (!weatherDao.canSaveDefaultTitle(data.getTitle(),data.getId())) { - errors.rejectValue("title", "error.valueAlreadyInDatabase"); - } - if (!weatherDao.canSaveDefaultDescription(data.getDescription(),data.getId())){ - errors.rejectValue("description", "error.valueAlreadyInDatabase"); - } - }else{ - if (!weatherDao.canSaveTitle(data.getTitle(), data.getResearchGroupId(),data.getId())) { - errors.rejectValue("title", "error.valueAlreadyInDatabase"); - } - if (!weatherDao.canSaveDescription(data.getTitle(), data.getResearchGroupId(),data.getId())) { - errors.rejectValue("description", "error.valueAlreadyInDatabase"); - } - } - - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/weather/WeatherMultiController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/weather/WeatherMultiController.java deleted file mode 100644 index 8bf0cb0d..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/list/weather/WeatherMultiController.java +++ /dev/null @@ -1,203 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * WeatherMultiController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.list.weather; - -import cz.zcu.kiv.eegdatabase.data.dao.*; -import cz.zcu.kiv.eegdatabase.data.pojo.Weather; -import cz.zcu.kiv.eegdatabase.data.pojo.WeatherGroupRel; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import cz.zcu.kiv.eegdatabase.logic.controller.list.SelectGroupCommand; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.context.HierarchicalMessageSource; -import org.springframework.web.servlet.support.RequestContextUtils; -import org.springframework.stereotype.Controller; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.ui.ModelMap; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.context.request.WebRequest; -import javax.servlet.http.HttpServletRequest; -import java.util.List; - -/** - * @author František Liška - */ -@Controller -@SessionAttributes("selectGroupCommand") -public class WeatherMultiController { - private Log log = LogFactory.getLog(getClass()); - @Autowired - private AuthorizationManager auth; - @Autowired - private ResearchGroupDao researchGroupDao; - @Autowired - private WeatherDao weatherDao; - @Autowired - private PersonDao personDao; - @Autowired - private HierarchicalMessageSource messageSource; - - private List researchGroupList; - private List weatherList; - private final int DEFAULT_ID = -1; - - @RequestMapping(value="lists/weather-definitions/list.html",method=RequestMethod.GET) - public String showSelectForm(WebRequest webRequest,ModelMap model){ - log.debug("Processing weather list controller"); - SelectGroupCommand selectGroupCommand= new SelectGroupCommand(); - String idString = webRequest.getParameter("groupid"); - if(auth.isAdmin()){ - if (idString != null) { - int id = Integer.parseInt(idString); - if(id!=DEFAULT_ID){ - fillWeatherList(id); - selectGroupCommand.setResearchGroupId(id); - }else{ - fillWeatherList(DEFAULT_ID); - selectGroupCommand.setResearchGroupId(DEFAULT_ID); - } - - }else{ - fillWeatherList(DEFAULT_ID); - selectGroupCommand.setResearchGroupId(DEFAULT_ID); - } - model.addAttribute("userIsExperimenter", true); - }else{ - if(!researchGroupList.isEmpty()){ - if (idString != null) { - int id = Integer.parseInt(idString); - fillWeatherList(id); - selectGroupCommand.setResearchGroupId(id); - }else{ - int myGroup = researchGroupList.get(0).getResearchGroupId(); - fillWeatherList(myGroup); - selectGroupCommand.setResearchGroupId(myGroup); - } - model.addAttribute("userIsExperimenter", auth.userIsExperimenter()); - }else{ - model.addAttribute("userIsExperimenter", false); - } - } - model.addAttribute("selectGroupCommand",selectGroupCommand); - model.addAttribute("weatherList", weatherList); - return "lists/weather/list"; - } - - @RequestMapping(value="lists/weather-definitions/list.html",method=RequestMethod.POST) - public String onSubmit(@ModelAttribute("selectGroupCommand") SelectGroupCommand selectGroupCommand, ModelMap model, HttpServletRequest request){ - if(!researchGroupList.isEmpty()){ - fillWeatherList(selectGroupCommand.getResearchGroupId()); - } - boolean canEdit = auth.isAdmin() || auth.userIsExperimenter(); - model.addAttribute("userIsExperimenter", canEdit); - model.addAttribute("weatherList", weatherList); - return "lists/weather/list"; - } - - @RequestMapping(value="lists/weather-definitions/delete.html") - public String delete(@RequestParam("id") String idString, @RequestParam("groupid") String idString2) { - log.debug("Deleting weather."); - if (idString != null) { - int id = Integer.parseInt(idString); - - if (weatherDao.canDelete(id)) { - if(idString2 !=null){ - int groupId = Integer.parseInt(idString2); - - if(groupId==DEFAULT_ID){ // delete default weather if it's from default group - if(!weatherDao.hasGroupRel(id)){ // delete only if it doesn't have group relationship - weatherDao.delete(weatherDao.read(id)); - }else{ - System.out.println("hasGroupRel"); - return "lists/itemUsed"; - } - }else{ - WeatherGroupRel h = weatherDao.getGroupRel(id,groupId); - if(!weatherDao.isDefault(id)){ // delete only non default weather - weatherDao.delete(weatherDao.read(id)); - } - weatherDao.deleteGroupRel(h); - } - } - - } else { - System.out.println("cannotDelete"); - return "lists/itemUsed"; - } - } - - return "lists/itemDeleted"; - } - - @ModelAttribute("researchGroupList") - private List fillAuthResearchGroupList(HttpServletRequest request){ - String defaultName = messageSource.getMessage("label.defaultWeather", null, RequestContextUtils.getLocale(request)); - Person loggedUser = personDao.getLoggedPerson(); - if(loggedUser.getAuthority().equals("ROLE_ADMIN")){ - ResearchGroup defaultGroup = new ResearchGroup(DEFAULT_ID,loggedUser,defaultName,"-"); - researchGroupList = researchGroupDao.getAllRecords(); - researchGroupList.add(0,defaultGroup); - }else{ - researchGroupList = researchGroupDao.getResearchGroupsWhereMember(loggedUser); - } - return researchGroupList; - } - - private void fillWeatherList(int selectedGroupId){ - if(selectedGroupId == DEFAULT_ID){ - weatherList = weatherDao.getDefaultRecords(); - }else{ - if(!researchGroupList.isEmpty()){ - weatherList = weatherDao.getRecordsByGroup(selectedGroupId); - } - } - } - - public ResearchGroupDao getResearchGroupDao() { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) { - this.researchGroupDao = researchGroupDao; - } - - public WeatherDao getWeatherDao() { - return weatherDao; - } - - public void setWeatherDao(WeatherDao weatherDao) { - this.weatherDao = weatherDao; - } - - public HierarchicalMessageSource getMessageSource() - { - return messageSource; - } - - public void setMessageSource(HierarchicalMessageSource messageSource) - { - this.messageSource = messageSource; - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ApplyForWritingPermissionCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ApplyForWritingPermissionCommand.java deleted file mode 100644 index d4c09fdc..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ApplyForWritingPermissionCommand.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ApplyForWritingPermissionCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.myaccount; - -/** - * @author Jindra - */ -public class ApplyForWritingPermissionCommand { - - private String reason; - - public String getReason() { - return reason; - } - - public void setReason(String reason) { - this.reason = reason; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ApplyForWritingPermissionController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ApplyForWritingPermissionController.java deleted file mode 100644 index 391e49df..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ApplyForWritingPermissionController.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ApplyForWritingPermissionController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.myaccount; - -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.logic.delegate.MyAccountDelegate; -import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.mail.MailException; -import org.springframework.mail.MailSender; -import org.springframework.mail.SimpleMailMessage; -import org.springframework.validation.BindException; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.List; - -public class ApplyForWritingPermissionController extends SimpleFormController { - - private Log log = LogFactory.getLog(getClass()); - private PersonDao personDao; - private String requestNotNeededView; - private String failView; - private MailSender mailSender; - private SimpleMailMessage mailMessage; - - public ApplyForWritingPermissionController() { - setCommandClass(ApplyForWritingPermissionCommand.class); - setCommandName("applyForWritingPermission"); - } - - @Override - protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception { - log.debug("Processing showForm method"); - - log.debug("Loading actual user from database"); - Person user = personDao.getPerson(ControllerUtils.getLoggedUserName()); - - ModelAndView mav = super.showForm(request, response, errors); - log.debug("Checking permission level"); - if (user.getAuthority().equals("ROLE_READER")) { - log.debug("User ha ROLE_READER authority - show form for apply"); - mav.setViewName(getFormView()); - } else { - log.debug("User has another authority than ROLE_READER - no need of request"); - mav.setViewName(getRequestNotNeededView()); - } - MyAccountDelegate.setUserIsInAnyGroup(mav, personDao.getLoggedPerson()); - return mav; - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception { - log.debug("Processing the form"); - ApplyForWritingPermissionCommand afwpc = (ApplyForWritingPermissionCommand) command; - - log.debug("Loading Person object of actual logged user from database"); - Person user = personDao.getPerson(ControllerUtils.getLoggedUserName()); - - log.debug("Composing e-mail message"); - SimpleMailMessage mail = new SimpleMailMessage(mailMessage); - mail.setFrom(user.getEmail()); - - log.debug("Loading list of supervisors"); - List supervisors = personDao.getSupervisors(); - String[] emails = new String[supervisors.size()]; - int i = 0; - for (Person supervisor : supervisors) { - emails[i++] = supervisor.getEmail(); - } - mail.setTo(emails); - - log.debug("Setting subject to e-mail message"); - mail.setSubject(mail.getSubject() + " - Write permission request from user " + user.getUsername()); - - String messageBody = "User " + user.getUsername() + " has requested permission for adding data into EEGbase system.\n" + - "Reason is: " + afwpc.getReason() + "\n" + - "Use the address below to grant the write permission.\n"; - String linkAddress = "http://" + request.getLocalAddr() + ":" + request.getLocalPort() + request.getContextPath() + "/system/grant-permission.html?id=" + user.getPersonId(); - log.debug("Address is: " + linkAddress); - messageBody += linkAddress; - mail.setText(messageBody); - - String mavName = ""; - try { - log.debug("Sending message"); - mailSender.send(mail); - log.debug("Mail was sent"); - mavName = getSuccessView(); - } catch (MailException e) { - log.debug("Mail was not sent"); - mavName = getFailView(); - } - - log.debug("Returning MAV"); - ModelAndView mav = new ModelAndView(mavName); - return mav; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public String getRequestNotNeededView() { - return requestNotNeededView; - } - - public void setRequestNotNeededView(String requestNotNeededView) { - this.requestNotNeededView = requestNotNeededView; - } - - public SimpleMailMessage getMailMessage() { - return mailMessage; - } - - public void setMailMessage(SimpleMailMessage mailMessage) { - this.mailMessage = mailMessage; - } - - public MailSender getMailSender() { - return mailSender; - } - - public void setMailSender(MailSender mailSender) { - this.mailSender = mailSender; - } - - public String getFailView() { - return failView; - } - - public void setFailView(String failView) { - this.failView = failView; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ApplyForWritingPermissionValidator.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ApplyForWritingPermissionValidator.java deleted file mode 100644 index ab397c3d..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ApplyForWritingPermissionValidator.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ApplyForWritingPermissionValidator.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.myaccount; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -/** - * @author JiPER - */ -public class ApplyForWritingPermissionValidator implements Validator { - - private Log log = LogFactory.getLog(getClass()); - - public boolean supports(Class clazz) { - return clazz.equals(ApplyForWritingPermissionCommand.class); - } - - public void validate(Object command, Errors errors) { - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "reason", "required.requestReason"); - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ChangeDefaultGroupCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ChangeDefaultGroupCommand.java deleted file mode 100644 index 6891cee6..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ChangeDefaultGroupCommand.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ChangeDefaultGroupCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package cz.zcu.kiv.eegdatabase.logic.controller.myaccount; - -/** - * @author Jiri Vlasimsky - */ -public class ChangeDefaultGroupCommand { - private int defaultGroup; - - public int getDefaultGroup() { - return defaultGroup; - } - - public void setDefaultGroup(int defaultGroup) { - this.defaultGroup = defaultGroup; - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ChangeDefaultGroupController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ChangeDefaultGroupController.java deleted file mode 100644 index dcf49236..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ChangeDefaultGroupController.java +++ /dev/null @@ -1,99 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ChangeDefaultGroupController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.myaccount; - -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import cz.zcu.kiv.eegdatabase.logic.delegate.MyAccountDelegate; -import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.validation.BindException; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class ChangeDefaultGroupController extends SimpleFormController { - - private Log log = LogFactory.getLog(getClass()); - private PersonDao personDao; - private ResearchGroupDao researchGroupDao; - - - public ChangeDefaultGroupController() { - setCommandClass(ChangeDefaultGroupCommand.class); - setCommandName("changeDefaultGroup"); - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception { - ChangeDefaultGroupCommand changeDefaultGroupCommand = (ChangeDefaultGroupCommand) command; - - log.debug("Changing default group for user"); - Person user = personDao.getPerson(ControllerUtils.getLoggedUserName()); - user.setDefaultGroup(researchGroupDao.read(changeDefaultGroupCommand.getDefaultGroup())); - personDao.update(user); - //personDao.update(user); - - log.debug("Returning MAV"); - ModelAndView mav = new ModelAndView(getSuccessView()); - return mav; - } - - @Override - protected Map referenceData(HttpServletRequest request) throws Exception { - Map map = new HashMap(); - List researchGroupList = - researchGroupDao.getResearchGroupsWhereAbleToWriteInto(personDao.getLoggedPerson()); - ResearchGroup defaultGroup = personDao.getLoggedPerson().getDefaultGroup(); - int defaultGroupId = (defaultGroup != null) ? defaultGroup.getResearchGroupId() : 0; - map.put("defaultGroupId", defaultGroupId); - map.put("researchGroupList", researchGroupList); - MyAccountDelegate.setUserIsInAnyGroup(map,personDao.getLoggedPerson()); - return map; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public ResearchGroupDao getResearchGroupDao() { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) { - this.researchGroupDao = researchGroupDao; - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ChangePasswordCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ChangePasswordCommand.java deleted file mode 100644 index e292ea74..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ChangePasswordCommand.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ChangePasswordCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.myaccount; - -/** - * @author Jindra - */ -public class ChangePasswordCommand { - - private String oldPassword; - private String newPassword; - private String newPassword2; - - public String getNewPassword() { - return newPassword; - } - - public void setNewPassword(String newPassword) { - this.newPassword = newPassword; - } - - public String getNewPassword2() { - return newPassword2; - } - - public void setNewPassword2(String newPassword2) { - this.newPassword2 = newPassword2; - } - - public String getOldPassword() { - return oldPassword; - } - - public void setOldPassword(String oldPassword) { - this.oldPassword = oldPassword; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ChangePasswordController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ChangePasswordController.java deleted file mode 100644 index 43b73283..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ChangePasswordController.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ChangePasswordController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.myaccount; - -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import cz.zcu.kiv.eegdatabase.logic.delegate.MyAccountDelegate; -import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.validation.BindException; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class ChangePasswordController extends SimpleFormController { - - private Log log = LogFactory.getLog(getClass()); - private PersonDao personDao; - - public ChangePasswordController() { - setCommandClass(ChangePasswordCommand.class); - setCommandName("myAccount"); - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception { - ChangePasswordCommand changePasswordCommand = (ChangePasswordCommand) command; - - log.debug("Saving new password for actual user"); - String newPassword = changePasswordCommand.getNewPassword(); - String passwordHash = new BCryptPasswordEncoder().encode(newPassword); - Person user = personDao.getPerson(ControllerUtils.getLoggedUserName()); - user.setPassword(passwordHash); - log.debug("Setting password hash [" + passwordHash + "] for user [" + user.getUsername() + "]"); - personDao.update(user); - - log.debug("Returning MAV"); - ModelAndView mav = new ModelAndView(getSuccessView()); - return mav; - } - - @Override - protected Map referenceData(HttpServletRequest request) throws Exception { - Map map = new HashMap(); - MyAccountDelegate.setUserIsInAnyGroup(map, personDao.getLoggedPerson()); - return map; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ChangePasswordValidator.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ChangePasswordValidator.java deleted file mode 100644 index b6c14a9e..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/myaccount/ChangePasswordValidator.java +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ChangePasswordValidator.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.myaccount; - -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -/** - * @author JiPER - */ -public class ChangePasswordValidator implements Validator { - - private Log log = LogFactory.getLog(getClass()); - private PersonDao personDao; - BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(); - - public boolean supports(Class clazz) { - return clazz.equals(ChangePasswordCommand.class); - } - - public void validate(Object command, Errors errors) { - log.debug("Started validation of My account form"); - ChangePasswordCommand changePasswordCommand = (ChangePasswordCommand) command; - - Person user = personDao.getPerson(ControllerUtils.getLoggedUserName()); - log.debug("Matching inserted old password and actual password in database [" + user.getPassword() + "]"); - if (!encoder.matches(changePasswordCommand.getOldPassword(),user.getPassword())) { - log.debug("Inserted password REJECTED"); - errors.rejectValue("oldPassword", "invalid.oldPassword"); - } - - log.debug("Validation whether the new password differs from the old one"); - if (changePasswordCommand.getNewPassword().equals(changePasswordCommand.getOldPassword())) { - log.debug("New and old passwords are the same"); - errors.rejectValue("newPassword", "invalid.newAndOldPasswordsAreTheSame"); - } - - log.debug("Validating new password if it is not empty"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "newPassword", "required.field"); - - log.debug("Validating twice inserted new password"); - if (!changePasswordCommand.getNewPassword().equals(changePasswordCommand.getNewPassword2())) { - log.debug("New passwords don't match"); - errors.rejectValue("newPassword2", "invalid.passwordMatch"); - } - - if (changePasswordCommand.getNewPassword().length()< ControllerUtils.MINIMUM_PASSWORD_LENGTH) { - errors.rejectValue("newPassword", "invalid.minimumPasswordLength6"); - } - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/AddPersonAdditionalParamValueCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/AddPersonAdditionalParamValueCommand.java deleted file mode 100644 index 4558a705..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/AddPersonAdditionalParamValueCommand.java +++ /dev/null @@ -1,57 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddPersonAdditionalParamValueCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.person; - -/** - * @author Jindra - */ -public class AddPersonAdditionalParamValueCommand { - - private int personFormId; - private int paramId; - private String paramValue; - - public int getParamId() { - return paramId; - } - - public void setParamId(int paramId) { - this.paramId = paramId; - } - - public String getParamValue() { - return paramValue; - } - - public void setParamValue(String paramValue) { - this.paramValue = paramValue; - } - - public int getPersonFormId() { - return personFormId; - } - - public void setPersonFormId(int personFormId) { - this.personFormId = personFormId; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/AddPersonAdditionalParamValueController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/AddPersonAdditionalParamValueController.java deleted file mode 100644 index f2dd06cd..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/AddPersonAdditionalParamValueController.java +++ /dev/null @@ -1,169 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddPersonAdditionalParamValueController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.person; - -import cz.zcu.kiv.eegdatabase.data.dao.GenericDao; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.dao.PersonOptParamDefDao; -import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; -import cz.zcu.kiv.eegdatabase.data.pojo.*; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Controller; -import org.springframework.ui.ModelMap; -import org.springframework.validation.BindException; -import org.springframework.validation.BindingResult; -import org.springframework.validation.Errors; -import org.springframework.web.bind.annotation.*; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @author František Liška - */ -@Controller -@SessionAttributes("addPersonAdditionalParameter") -public class AddPersonAdditionalParamValueController{ - - private Log log = LogFactory.getLog(getClass()); - @Autowired - private PersonDao personDao; - @Autowired - private ResearchGroupDao researchGroupDao; - @Autowired - @Qualifier("personOptParamValDao") - private GenericDao personOptParamValDao; - @Autowired - private PersonOptParamDefDao personOptParamDefDao; - private AddPersonAdditionalParamValueValidator addPersonAdditionalParamValueValidator; - - @Autowired - public AddPersonAdditionalParamValueController(AddPersonAdditionalParamValueValidator addPersonAdditionalParamValueValidator){ - this.addPersonAdditionalParamValueValidator = addPersonAdditionalParamValueValidator; - } - - - @RequestMapping(value="people/add-optional-parameter.html",method= RequestMethod.GET) - protected String showForm(ModelMap model){ - log.debug("Preparing data for form"); - AddPersonAdditionalParamValueCommand data = new AddPersonAdditionalParamValueCommand(); - model.addAttribute("addPersonAdditionalParameter", data); - return "people/optionalParams/addItemForm"; - - } - - @RequestMapping(method=RequestMethod.POST) - protected String onSubmit(@ModelAttribute("addPersonAdditionalParameter") AddPersonAdditionalParamValueCommand data, BindingResult result){ - addPersonAdditionalParamValueValidator.validate(data, result); - if (result.hasErrors()) { - return "people/optionalParams/addItemForm"; - } - - log.debug("Processing form data."); - - log.debug("Creating new object"); - PersonOptParamVal val = new PersonOptParamVal(); - val.setId(new PersonOptParamValId(data.getPersonFormId(), data.getParamId())); - val.setParamValue(data.getParamValue()); - - log.debug("Saving object to database"); - personOptParamValDao.create(val); - - String redirect = "redirect:/people/detail.html?personId="+data.getPersonFormId(); - return redirect; - } - - @ModelAttribute("personAdditionalParams") - protected List populateOptParamList(){ - log.debug("Loading parameter list for select box"); - List list = new ArrayList(); - Person loggedUser = personDao.getLoggedPerson(); - if(loggedUser.getAuthority().equals("ROLE_ADMIN")){ - list.addAll(personOptParamDefDao.getAllRecords()); - }else{ - List researchGroups = researchGroupDao.getResearchGroupsWhereMember(loggedUser); - for(int i =0; i getPersonOptParamValDao() { - return personOptParamValDao; - } - - public void setPersonOptParamValDao(GenericDao personOptParamValDao) { - this.personOptParamValDao = personOptParamValDao; - } - - public PersonOptParamDefDao getPersonOptParamDefDao() { - return personOptParamDefDao; - } - - public void setPersonOptParamDefDao(PersonOptParamDefDao personOptParamDefDao) { - this.personOptParamDefDao = personOptParamDefDao; - } - - public AddPersonAdditionalParamValueValidator getAddPersonAdditionalParamValueValidator() { - return addPersonAdditionalParamValueValidator; - } - - public void setAddPersonAdditionalParamValueValidator(AddPersonAdditionalParamValueValidator addPersonAdditionalParamValueValidator) { - this.addPersonAdditionalParamValueValidator = addPersonAdditionalParamValueValidator; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/AddPersonAdditionalParamValueValidator.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/AddPersonAdditionalParamValueValidator.java deleted file mode 100644 index 98291992..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/AddPersonAdditionalParamValueValidator.java +++ /dev/null @@ -1,68 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddPersonAdditionalParamValueValidator.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.person; - -import cz.zcu.kiv.eegdatabase.data.dao.GenericDao; -import cz.zcu.kiv.eegdatabase.data.pojo.PersonOptParamVal; -import cz.zcu.kiv.eegdatabase.data.pojo.PersonOptParamValId; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -/** - * @author JiPER - */ -public class AddPersonAdditionalParamValueValidator implements Validator { - - private Log log = LogFactory.getLog(getClass()); - private GenericDao personOptParamValDao; - - public boolean supports(Class clazz) { - return clazz.equals(AddPersonAdditionalParamValueCommand.class); - } - - public void validate(Object command, Errors errors) { - AddPersonAdditionalParamValueCommand data = (AddPersonAdditionalParamValueCommand) command; - - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "paramValue", "required.field"); - - if (data.getParamId() < 0) { - errors.rejectValue("paramId", "required.field"); - } - - PersonOptParamVal val = personOptParamValDao.read(new PersonOptParamValId(data.getPersonFormId(), data.getParamId())); - if (val != null) { // field already exists - errors.rejectValue("paramId", "invalid.paramIdAlreadyInserted"); - } - } - - public GenericDao getPersonOptParamValDao() { - return personOptParamValDao; - } - - public void setPersonOptParamValDao(GenericDao personOptParamValDao) { - this.personOptParamValDao = personOptParamValDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/AddPersonController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/AddPersonController.java deleted file mode 100644 index fcafc485..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/AddPersonController.java +++ /dev/null @@ -1,142 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddPersonController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.person; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.EducationLevelDao; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.pojo.EducationLevel; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.service.MailService; -import cz.zcu.kiv.eegdatabase.data.service.PersonService; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.HierarchicalMessageSource; -import org.springframework.mail.MailException; -import org.springframework.validation.BindException; -import org.springframework.validation.Errors; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; -import org.springframework.web.servlet.support.RequestContextUtils; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class AddPersonController extends SimpleFormController { - - private Log log = LogFactory.getLog(getClass()); - private PersonDao personDao; - private EducationLevelDao educationLevelDao; - private HierarchicalMessageSource messageSource; - private MailService mailService; - private PersonService personService; - @Autowired - private AuthorizationManager auth; - - public AddPersonController() { - setCommandClass(AddPersonCommand.class); - setCommandName("addPerson"); - } - - @Override - protected Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception { - Map map = new HashMap(); - List list = educationLevelDao.getAllRecords(); - map.put("education", list); - return map; - } - - @Override - protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception { - ModelAndView mav = super.showForm(request, response, errors); - boolean userIsExperimenter = auth.userIsExperimenter(); - mav.addObject("userIsExperimenter", userIsExperimenter); - - return mav; - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception { - AddPersonCommand apc = (AddPersonCommand) command; - boolean userIsExperimenter = auth.userIsExperimenter(); - - Person person = personService.createPerson(apc); - - try { - mailService.sendRegistrationConfirmMail(person, RequestContextUtils.getLocale(request)); - } catch (MailException e) { - log.error("E-mail was NOT sent"); - log.error(e); - e.printStackTrace(); - } - - log.debug("Returning MAV"); - ModelAndView mav = new ModelAndView(getSuccessView() + person.getPersonId()); - mav.addObject("userIsExperimenter", userIsExperimenter); - return mav; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public EducationLevelDao getEducationLevelDao() { - return educationLevelDao; - } - - public void setEducationLevelDao(EducationLevelDao educationLevelDao) { - this.educationLevelDao = educationLevelDao; - } - - public HierarchicalMessageSource getMessageSource() { - return messageSource; - } - - public void setMessageSource(HierarchicalMessageSource messageSource) { - this.messageSource = messageSource; - } - - public MailService getMailService() { - return mailService; - } - - public void setMailService(MailService mailService) { - this.mailService = mailService; - } - - public PersonService getPersonService() { - return personService; - } - - public void setPersonService(PersonService personService) { - this.personService = personService; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/AddPersonValidator.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/AddPersonValidator.java deleted file mode 100644 index f8d58c61..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/AddPersonValidator.java +++ /dev/null @@ -1,107 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddPersonValidator.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.person; - -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -import java.text.ParseException; -import java.util.Date; -import java.util.regex.Pattern; - -/** - * @author JiPER - */ -public class AddPersonValidator implements Validator { - - private Log log = LogFactory.getLog(this.getClass()); - private PersonDao personDao; - - public boolean supports(Class clazz) { - return clazz.equals(AddPersonCommand.class); - } - - public void validate(Object command, Errors errors) { - AddPersonCommand apc = (AddPersonCommand) command; - - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "givenname", "required.field"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "surname", "required.field"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "dateOfBirth", "required.field"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "gender", "required.field"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "required.field"); - - try { - Date d = ControllerUtils.getDateFormat().parse(apc.getDateOfBirth()); - if (d.getTime() >= System.currentTimeMillis()) { - errors.rejectValue("dateOfBirth", "invalid.dateOfBirth"); - } - } catch (ParseException e) { - errors.rejectValue("dateOfBirth", "invalid.dateOfBirth"); - } - if (apc.getNote().length() > 255) { - errors.rejectValue("note", "invalid.maxLength"); - } - if (!apc.getPhoneNumber().isEmpty()) { - try { - if (apc.getPhoneNumber().charAt(0) == '+') { - Long.parseLong(apc.getPhoneNumber().substring(1)); - } else { - Long.parseLong(apc.getPhoneNumber()); - } - - } catch (NumberFormatException ex) { - errors.rejectValue("phoneNumber", "invalid.phoneNumber"); - } - - } - if (!Pattern.matches("[a-zA-Z][a-zA-Z\\s]*", apc.getGivenname())) { - errors.rejectValue("givenname", "invalid.givenname"); - } - if (!Pattern.matches("[a-zA-Z][a-zA-Z\\s]*", apc.getSurname())) { - errors.rejectValue("surname", "invalid.surname"); - } - - if (!Pattern.matches("^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$", apc.getEmail())) { - errors.rejectValue("email", "invalid.email"); - } - if (!apc.getEmail().equals(apc.getOldEmail())) { - if (personDao.usernameExists(apc.getEmail())) { - errors.rejectValue("email", "inUse.email"); - } - } - apc.setOldEmail(""); - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/EditPersonController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/EditPersonController.java deleted file mode 100644 index 09dce789..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/EditPersonController.java +++ /dev/null @@ -1,169 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * EditPersonController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.person; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.EducationLevelDao; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.pojo.EducationLevel; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.validation.BindException; -import org.springframework.validation.Errors; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.sql.Timestamp; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class EditPersonController extends SimpleFormController { - - private Log log = LogFactory.getLog(getClass()); - @Qualifier("personDao") - @Autowired - private PersonDao personDao; - @Qualifier("educationLevelDao") - @Autowired - private EducationLevelDao educationLevelDao; - @Autowired - private AuthorizationManager auth; - - - public EditPersonController() { - setCommandClass(AddPersonCommand.class); - setCommandName("addPerson"); - } - - @Override - protected Object formBackingObject(HttpServletRequest request) throws Exception { - AddPersonCommand data = (AddPersonCommand) super.formBackingObject(request); - - String idString = request.getParameter("id"); - if (idString != null) { - int id = Integer.parseInt(idString); - - log.debug("Loading person to command object for editing."); - Person person = personDao.read(id); - - data.setId(id); - data.setGivenname(person.getGivenname()); - data.setSurname(person.getSurname()); - data.setDateOfBirth(ControllerUtils.getDateFormat().format(person.getDateOfBirth())); - data.setGender(new Character(person.getGender()).toString()); - data.setEmail(person.getUsername()); - data.setPhoneNumber(person.getPhoneNumber()); - data.setNote(person.getNote()); - data.setOldEmail(person.getUsername()); - } - - return data; - } - - @Override - protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception { - ModelAndView mav = super.showForm(request, response, errors); - - String idString = request.getParameter("id"); - if (idString != null) { - int id = Integer.parseInt(idString); - if (!auth.userCanEditPerson(id)) { - mav.setViewName("redirect:/people/list.html"); - } - } - boolean userIsExperimenter = auth.userIsExperimenter(); - mav.addObject("userIsExperimenter", userIsExperimenter); - - return mav; - } - @Override - protected Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception { - Map map = new HashMap(); - List list = educationLevelDao.getAllRecords(); - map.put("education", list); - return map; - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception { - ModelAndView mav = new ModelAndView(getSuccessView()); - - AddPersonCommand data = (AddPersonCommand) command; - boolean userIsExperimenter = auth.userIsExperimenter(); - mav.addObject("userIsExperimenter", userIsExperimenter); - String idString = request.getParameter("id"); - if (idString != null) { - int id = Integer.parseInt(idString); - if (!auth.userCanEditPerson(id)) { - mav.setViewName("redirect:/people/list.html"); - return mav; - } - - log.debug("Loading existing person from database."); - Person person = personDao.read(id); - - log.debug("Setting givenname = " + data.getGivenname()); - person.setGivenname(data.getGivenname()); - - log.debug("Setting surname = " + data.getSurname()); - person.setSurname(data.getSurname()); - - Date dateOfBirth = ControllerUtils.getDateFormat().parse(data.getDateOfBirth()); - person.setDateOfBirth(new Timestamp(dateOfBirth.getTime())); - log.debug("Setting date of birth = " + dateOfBirth); - - log.debug("Setting gender = " + data.getGender()); - person.setGender(data.getGender().charAt(0)); - - log.debug("Setting username/email = " + data.getEmail()); - person.setUsername(data.getEmail()); - - log.debug("Setting phone number = " + data.getPhoneNumber()); - person.setPhoneNumber(data.getPhoneNumber()); - - log.debug("Setting note = " + data.getNote()); - person.setNote(data.getNote()); - person.setLaterality(data.getLaterality().charAt(0)); - person.setEducationLevel(educationLevelDao.read(data.getEducationLevel())); - - log.debug("Creating new Person object"); - personDao.update(person); - - mav.setViewName(getSuccessView() + person.getPersonId()); - } - - log.debug("Returning MAV"); - return mav; - } - public void setEducationLevelDao(EducationLevelDao educationLevelDao) { - this.educationLevelDao = educationLevelDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/PersonDetailController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/PersonDetailController.java deleted file mode 100644 index ebe12807..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/PersonDetailController.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * PersonDetailController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.person; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.AbstractController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * @author JiPER - */ -public class PersonDetailController extends AbstractController { - - private Log log = LogFactory.getLog(getClass()); - @Autowired - private PersonDao personDao; - @Autowired - private AuthorizationManager auth; - - @Override - protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - ModelAndView mav = new ModelAndView("people/detail"); - - int id = 0; - try { - id = Integer.parseInt(request.getParameter("personId")); - } catch (Exception e) { - } - Person p = personDao.read(id); - - boolean userIsExperimenter = auth.userIsExperimenter(); - mav.addObject("userIsExperimenter", userIsExperimenter); - mav.addObject("personDetail", p); - mav.addObject("canEdit", auth.userCanEditPerson(id)); - - return mav; - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/PersonListController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/PersonListController.java deleted file mode 100644 index 23963d9a..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/person/PersonListController.java +++ /dev/null @@ -1,78 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * PersonListController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.person; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.logic.util.Paginator; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.AbstractController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.List; - -/** - * @author JiPER - */ -public class PersonListController extends AbstractController { - - private PersonDao personDao; - private AuthorizationManager auth; - private static final int ITEMS_PER_PAGE = 20; - - @Override - protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - ModelAndView mav = new ModelAndView("people/list"); - - Paginator paginator = new Paginator(personDao.getCountForList(), ITEMS_PER_PAGE); - - int page = 1; - try { - page = Integer.parseInt(request.getParameter("page")); - } catch (Exception e) { - e.printStackTrace(); - } - paginator.setActualPage(page); - List list = personDao.getDataForList(paginator.getFirstItemIndex(), ITEMS_PER_PAGE); - - mav.addObject("personList", list); - boolean userIsExperimenter = auth.userIsExperimenter(); - mav.addObject("userIsExperimenter", userIsExperimenter); - mav.addObject("paginator", paginator.getLinks()); - return mav; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/ConfirmController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/ConfirmController.java deleted file mode 100644 index b03eae47..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/ConfirmController.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ConfirmController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.root; - -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.AbstractController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - - -public class ConfirmController extends AbstractController { - private Log log = LogFactory.getLog(getClass()); - - private PersonDao personDao; - - - @Override - protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - log.debug("Processing ConfirmController controller"); - ModelAndView mav; - - Person person = personDao.getPersonByHash(request.getParameter("activation")); - - if (person == null) { - return new ModelAndView("system/registrationFalse"); - } - - if (person.isConfirmed()) { - return new ModelAndView("system/registrationConfirmRepeated"); - } - if (confirmedInTime(System.currentTimeMillis(), person)) { - person.setConfirmed(true); - mav = new ModelAndView("system/confirmationSuccessfull"); - } else { - mav = new ModelAndView("system/registrationFalse"); - personDao.delete(person); - } - - return mav; - } - - public boolean confirmedInTime(long clickTime, Person person) { - long requestTime = person.getRegistrationDate().getTime(); - //8 days in ms - long maximumDelay = 691200000; - return (clickTime - requestTime < maximumDelay); - } - - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/ForgottenPasswordCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/ForgottenPasswordCommand.java deleted file mode 100644 index f79f8f27..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/ForgottenPasswordCommand.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ForgottenPasswordCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.root; - -/** - * @author Jindra - */ -public class ForgottenPasswordCommand { - - private String username; - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/ForgottenPasswordController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/ForgottenPasswordController.java deleted file mode 100644 index c7b32fb5..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/ForgottenPasswordController.java +++ /dev/null @@ -1,129 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ForgottenPasswordController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.root; - -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.mail.MailException; -import org.springframework.mail.MailSender; -import org.springframework.mail.SimpleMailMessage; -import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; -import org.springframework.validation.BindException; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -public class ForgottenPasswordController extends SimpleFormController { - - private Log log = LogFactory.getLog(getClass()); - private PersonDao personDao; - private MailSender mailSender; - private SimpleMailMessage mailMessage; - private String failedView; - - public ForgottenPasswordController() { - setCommandClass(ForgottenPasswordCommand.class); - setCommandName("forgottenPassword"); - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception { - ForgottenPasswordCommand fpc = (ForgottenPasswordCommand) command; - - Person user = personDao.getPerson(fpc.getUsername()); - - log.debug("Creating new mail object"); - SimpleMailMessage mail = new SimpleMailMessage(mailMessage); - - String recipient = user.getEmail(); - log.debug("Composing e-mail - TO: " + recipient); - mail.setTo(recipient); - - String subject = mail.getSubject() + " - Password reset"; - log.debug("Composing e-mail - SUBJECT: " + subject); - mail.setSubject(subject); - - String password = ControllerUtils.getRandomPassword(); - String text = "Your password for EEGbase portal was reset. Your new password (within brackets) is [" + password + "]\n\n" + - "Please change the password after logging into system."; - log.debug("Composing e-mail - TEXT: " + text); - mail.setText(text); - - String mavName = getSuccessView(); - try { - log.debug("Sending e-mail message"); - mailSender.send(mail); - log.debug("E-mail message sent successfully"); - - log.debug("Updating new password into database"); - user.setPassword(new BCryptPasswordEncoder().encode(password)); - personDao.update(user); - log.debug("Password updated"); - } catch (MailException e) { - log.debug("E-mail message was NOT sent"); - log.debug("Password was NOT changed"); - mavName = getFailedView(); - } - - log.debug("Returning MAV"); - ModelAndView mav = new ModelAndView(mavName); - return mav; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public MailSender getMailSender() { - return mailSender; - } - - public void setMailSender(MailSender mailSender) { - this.mailSender = mailSender; - } - - public SimpleMailMessage getMailMessage() { - return mailMessage; - } - - public void setMailMessage(SimpleMailMessage mailMessage) { - this.mailMessage = mailMessage; - } - - public String getFailedView() { - return failedView; - } - - public void setFailedView(String failedView) { - this.failedView = failedView; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/ForgottenPasswordValidator.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/ForgottenPasswordValidator.java deleted file mode 100644 index e6ec21a4..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/ForgottenPasswordValidator.java +++ /dev/null @@ -1,58 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ForgottenPasswordValidator.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.root; - -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.validation.Errors; -import org.springframework.validation.Validator; - -/** - * @author JiPER - */ -public class ForgottenPasswordValidator implements Validator { - - private Log log = LogFactory.getLog(getClass()); - private PersonDao personDao; - - public boolean supports(Class clazz) { - return clazz.equals(ForgottenPasswordCommand.class); - } - - public void validate(Object command, Errors errors) { - ForgottenPasswordCommand fpc = (ForgottenPasswordCommand) command; - - if (!personDao.usernameExists(fpc.getUsername())) { - errors.rejectValue("username", "invalid.username"); - } - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/RegistrationController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/RegistrationController.java deleted file mode 100644 index 584a662d..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/RegistrationController.java +++ /dev/null @@ -1,174 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * RegistrationController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.root; - -import com.octo.captcha.service.CaptchaServiceException; -import com.octo.captcha.service.image.ImageCaptchaService; -import cz.zcu.kiv.eegdatabase.data.dao.EducationLevelDao; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.pojo.EducationLevel; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.service.HibernatePersonService; -import cz.zcu.kiv.eegdatabase.data.service.MailService; -import cz.zcu.kiv.eegdatabase.data.service.PersonService; -import cz.zcu.kiv.eegdatabase.data.service.SpringJavaMailService; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.context.HierarchicalMessageSource; -import org.springframework.mail.MailException; -import org.springframework.validation.BindException; -import org.springframework.validation.Errors; -import org.springframework.validation.ObjectError; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; -import org.springframework.web.servlet.support.RequestContextUtils; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class RegistrationController extends SimpleFormController { - - private Log log = LogFactory.getLog(getClass()); - private PersonDao personDao; - private EducationLevelDao educationLevelDao; - private HierarchicalMessageSource messageSource; - private MailService mailService; - private PersonService personService; - private static final String DEFAULT_CAPTCHA_RESPONSE_PARAMETER_NAME = "j_captcha_response"; - protected ImageCaptchaService captchaService; - protected String captchaResponseParameterName = DEFAULT_CAPTCHA_RESPONSE_PARAMETER_NAME; - - public RegistrationController() { - setCommandClass(RegistrationCommand.class); - setCommandName("registration"); - } - - @Override - protected void onBindAndValidate(HttpServletRequest request, Object command, BindException errors) throws Exception { - validateCaptcha(request, errors); - } - @Override - protected Map referenceData(HttpServletRequest request, Object command, Errors errors) throws Exception { - Map map = new HashMap(); - List list = educationLevelDao.getAllRecords(); - map.put("education", list); - return map; - } - - - //validates captch image text - protected void validateCaptcha(HttpServletRequest request, BindException errors) { - boolean isResponseCorrect = false; - String captchaId = request.getSession().getId(); - String response = request.getParameter(captchaResponseParameterName); - log.debug("captchaId " + captchaId); - log.debug("captha response " + response); - try { - if (response != null) { - isResponseCorrect = - captchaService.validateResponseForID(captchaId, response); - } - } catch (CaptchaServiceException e) { - log.error(e); - } - if (!isResponseCorrect) { - String objectName = "Captcha"; - String[] codes = {"invalid"}; - Object[] arguments = {}; - String defaultMessage = "Invalid image test entered!"; - ObjectError oe = new ObjectError(objectName, codes, arguments, defaultMessage); - errors.addError(oe); - } - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception { - RegistrationCommand rc = (RegistrationCommand) command; - - Person person = personService.createPerson(rc); - - try { - mailService.sendRegistrationConfirmMail(person, RequestContextUtils.getLocale(request)); - } catch (MailException e) { - log.error("E-mail was NOT sent"); - log.error(e); - e.printStackTrace(); - } - - log.debug("Returning MAV"); - ModelAndView mav = new ModelAndView(getSuccessView()); - mav.addObject("personEmail", person.getEmail()); - return mav; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public EducationLevelDao getEducationLevelDao() { - return educationLevelDao; - } - - public void setEducationLevelDao(EducationLevelDao educationLevelDao) { - this.educationLevelDao = educationLevelDao; - } - - public HierarchicalMessageSource getMessageSource() { - return messageSource; - } - - public void setMessageSource(HierarchicalMessageSource messageSource) { - this.messageSource = messageSource; - } - - public void setCaptchaService(ImageCaptchaService captchaService) { - this.captchaService = captchaService; - } - - public void setCaptchaResponseParameterName(String captchaResponseParameterName) { - this.captchaResponseParameterName = captchaResponseParameterName; - } - - public MailService getMailService() { - return mailService; - } - - public void setMailService(MailService mailService) { - this.mailService = mailService; - } - - public PersonService getPersonService() { - return personService; - } - - public void setPersonService(PersonService personService) { - this.personService = personService; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/RegistrationValidator.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/RegistrationValidator.java deleted file mode 100644 index 0ed1d16b..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/RegistrationValidator.java +++ /dev/null @@ -1,98 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * RegistrationValidator.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.root; - -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -import java.text.ParseException; -import java.util.Date; -import java.util.regex.Pattern; - -/** - * @author JiPER - */ -public class RegistrationValidator implements Validator { - - private Log log = LogFactory.getLog(getClass()); - private PersonDao personDao; - - public boolean supports(Class clazz) { - return clazz.equals(RegistrationCommand.class); - } - - public void validate(Object command, Errors errors) { - RegistrationCommand registrationCommand = (RegistrationCommand) command; - - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "givenname", "required.field"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "surname", "required.field"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "dateOfBirth", "required.field"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "gender", "required.field"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email", "required.field"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "required.field"); - - try { - Date d = ControllerUtils.getDateFormat().parse(registrationCommand.getDateOfBirth()); - if (d.getTime() >= System.currentTimeMillis()) { - errors.rejectValue("dateOfBirth", "invalid.dateOfBirth"); - } - } catch (ParseException e) { - errors.rejectValue("dateOfBirth", "invalid.dateOfBirth"); - } - - if (!registrationCommand.getPassword().equals(registrationCommand.getPassword2())) { - errors.rejectValue("password2", "invalid.passwordMatch"); - } - if (!Pattern.matches("[a-zA-Z][a-zA-Z\\s]*", registrationCommand.getGivenname())) { - errors.rejectValue("givenname", "invalid.givenname"); - } - if (!Pattern.matches("[a-zA-Z][a-zA-Z\\s]*", registrationCommand.getSurname())) { - errors.rejectValue("surname", "invalid.surname"); - } - - if (!Pattern.matches("^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,4}$", registrationCommand.getEmail())) { - errors.rejectValue("email", "invalid.email"); - } - - if (personDao.usernameExists(registrationCommand.getEmail())) { - errors.rejectValue("email", "inUse.email"); - } - - if (registrationCommand.getPassword().length() < ControllerUtils.MINIMUM_PASSWORD_LENGTH) { - errors.rejectValue("password", "invalid.minimumPasswordLength6"); - } - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/WriteRequestsListController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/WriteRequestsListController.java deleted file mode 100644 index 44d43dad..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/root/WriteRequestsListController.java +++ /dev/null @@ -1,181 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * WriteRequestsListController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.root; - -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.mail.MailException; -import org.springframework.mail.MailSender; -import org.springframework.mail.SimpleMailMessage; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.AbstractController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.List; - -/** - * @author JiPER - */ -public class WriteRequestsListController extends AbstractController { - - private Log log = LogFactory.getLog(getClass()); - private PersonDao personDao; - private MailSender mailSender; - private SimpleMailMessage mailMessage; - - @Override - protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - log.debug("Processing request"); - ModelAndView mav = new ModelAndView("system/writeRequestsList"); - - log.debug("Checking parameter 'grant'"); - String grantParameter = request.getParameter("grant"); - if (grantParameter != null) { // parameter "grant" was set - log.debug("Parameter 'grant' was set"); - int personId = Integer.parseInt(grantParameter); // parameter is set programatically, so it should be integer - grantPermission(personId); - mav.setViewName("system/permissionGranted"); - } - - log.debug("Checking parameter 'reject'"); - String rejectParameter = request.getParameter("reject"); - if (rejectParameter != null) { // parameter "reject" was set - log.debug("Parameter 'reject' was set"); - int personId = Integer.parseInt(rejectParameter); // parameter is set programatically, so it should be integer - rejectPermission(personId); - mav.setViewName("system/permissionRejected"); - } - - log.debug("Loading requests list"); - List requirements = personDao.getPersonsWherePendingRequirement(); - mav.addObject("personList", requirements); - - log.debug("Returning MAV"); - return mav; - } - - /** - * Grants permission for the person - sets propriate values to the database - * and sends e-mail to the registered e-mail address - * - * @param personId ID of the person for granting the permission - */ - private void grantPermission(int personId) { - log.debug("Loading Person object from database"); - Person user = personDao.read(personId); - - log.debug("Loaded Person - user name = " + user.getUsername()); - log.debug("Setting the authority to ROLE_EXPERIMENTER"); - user.setAuthority("ROLE_EXPERIMENTER"); - - log.debug("Updating Person in database"); - personDao.update(user); - - String email = user.getEmail(); - sendEmail(email, true); - } - - /** - * Rejects permission for the person - sets propriate values to the database - * and sends e-mail to the registered e-mail address - * - * @param personId ID of the person for rejecting the permission - */ - private void rejectPermission(int personId) { - log.debug("Loading Person object from database"); - Person user = personDao.read(personId); - - log.debug("Loaded Person - user name = " + user.getUsername()); - log.debug("Setting the authority to ROLE_READER"); - user.setAuthority("ROLE_READER"); - - log.debug("Updating Person in database"); - personDao.update(user); - - String email = user.getEmail(); - sendEmail(email, false); - } - - /** - * Sends e-mail with granting message or rejecting message to the recipient - * - * @param recipient E-mail address of the recipient - * @param grant If true, granting message will be sent, - * if false, rejecting message will be sent - */ - private boolean sendEmail(String recipient, boolean grant) { - log.debug("Sending e-mail"); - SimpleMailMessage mail = new SimpleMailMessage(mailMessage); - mail.setTo(recipient); - - log.debug("Setting the parameters of the e-mail message"); - String subject = ""; - String text = ""; - if (grant) { - subject = mail.getSubject() + " - Write permission granted"; - text = "Congratulation, the write permission for the EEGbase portal was granted. You can now submit your data. Thank you for your interest."; - } else { - subject = mail.getSubject() + " - Write permission rejected"; - text = "We are sorry, but the write permission for the EEGbase portal was rejected. You can apply again, try to better explain your reasons. Thank you."; - } - mail.setSubject(subject); - mail.setText(text); - - try { - log.debug("Sending the e-mail"); - mailSender.send(mail); - log.debug("E-mail was sent"); - return true; - } catch (MailException e) { - log.debug("E-mail was NOT sent"); - return false; - } - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public SimpleMailMessage getMailMessage() { - return mailMessage; - } - - public void setMailMessage(SimpleMailMessage mailMessage) { - this.mailMessage = mailMessage; - } - - public MailSender getMailSender() { - return mailSender; - } - - public void setMailSender(MailSender mailSender) { - this.mailSender = mailSender; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioCommand.java deleted file mode 100644 index f9965ca0..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioCommand.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddScenarioCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.scenario; - -import org.springframework.web.multipart.MultipartFile; -import org.w3c.dom.Document; - -public class AddScenarioCommand { - - private int id; - private int researchGroup; - private String title; - private String length; - private String description; - private MultipartFile dataFile; - private MultipartFile dataFileXml; - private boolean privateNote; - private int scenarioSchema; - private boolean dataFileAvailable; - private boolean xmlFileCheckBox; - private String scenarioOption; - private String schemaDescription; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public int getResearchGroup() { - return researchGroup; - } - - public void setResearchGroup(int researchGroup) { - this.researchGroup = researchGroup; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getLength() { - return length; - } - - public void setLength(String length) { - this.length = length; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public MultipartFile getDataFile() { - return dataFile; - } - - public void setDataFile(MultipartFile dataFile) { - this.dataFile = dataFile; - } - - public boolean getPrivateNote() { - return this.privateNote; - } - - public void setPrivateNote(boolean privateNote) { - this.privateNote = privateNote; - } - - public int getScenarioSchema() { - return scenarioSchema; - } - - public void setScenarioSchema(int scenarioSchema) { - this.scenarioSchema = scenarioSchema; - } - - public boolean isDataFileAvailable() { - return dataFileAvailable; - } - - public void setDataFileAvailable(boolean dataFileAvailable) { - this.dataFileAvailable = dataFileAvailable; - } - - public MultipartFile getDataFileXml() { - return dataFileXml; - } - - public void setDataFileXml(MultipartFile dataFileXml) { - this.dataFileXml = dataFileXml; - } - - public boolean isXmlFileCheckBox() { - return xmlFileCheckBox; - } - - public void setXmlFileCheckBox(boolean xmlFileCheckBox) { - this.xmlFileCheckBox = xmlFileCheckBox; - } - - public String getScenarioOption() { - return scenarioOption; - } - - public void setScenarioOption(String scenarioOption) { - this.scenarioOption = scenarioOption; - } - - public String getSchemaDescription() { - return schemaDescription; - } - - public void setSchemaDescription(String schemaDescription) { - this.schemaDescription = schemaDescription; - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioController.java deleted file mode 100644 index 093f817e..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioController.java +++ /dev/null @@ -1,274 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddScenarioController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.scenario; - -import cz.zcu.kiv.eegdatabase.data.dao.*; -import cz.zcu.kiv.eegdatabase.data.pojo.*; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.Hibernate; -import org.springframework.validation.BindException; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; -import org.w3c.dom.Document; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import java.io.InputStream; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - - -/** - * Controller which processes form for adding a measuration - * - * @author Jindra - */ -public class AddScenarioController - extends SimpleFormController { - - private Log log = LogFactory.getLog(getClass()); - private AuthorizationManager auth; - private ScenarioDao scenarioDao; - private PersonDao personDao; - private ResearchGroupDao researchGroupDao; - private ScenarioSchemasDao scenarioSchemasDao; - private static final int MAX_MIMETYPE_LENGTH = 30; - - public AddScenarioController() { - setCommandClass(AddScenarioCommand.class); - setCommandName("addScenario"); - } - - @Override - protected Object formBackingObject(HttpServletRequest request) throws Exception { - AddScenarioCommand data = (AddScenarioCommand) super.formBackingObject(request); - - String idString = request.getParameter("id"); - - if (idString != null) { - // Editing existing scenario - int id = Integer.parseInt(idString); - - log.debug("Loading scenario to the command object for editing."); - Scenario scenario = scenarioDao.read(id); - - data.setId(id); - data.setTitle(scenario.getTitle()); - data.setLength(new Integer(scenario.getScenarioLength()).toString()); - data.setDescription(scenario.getDescription()); - data.setPrivateNote(scenario.isPrivateScenario()); - data.setResearchGroup(scenario.getResearchGroup().getResearchGroupId()); - } - - return data; - } - - @Override - protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception { - ModelAndView mav = super.showForm(request, response, errors); - - String idString = request.getParameter("id"); - if (idString != null) { - if (!auth.isAdmin()) { - int id = Integer.parseInt(idString); - - if ((id > 0) && (!auth.userIsOwnerOfScenario(id))) { - // Editing existing scenario and user is not owner - mav.setViewName("redirect:/scenarios/list.html"); - return mav; - } - } - } - - // Creating new scenario - if (!auth.userIsExperimenter()) { - mav.setViewName("scenario/userNotExperimenter"); - } - mav.addObject("userIsExperimenter", auth.userIsExperimenter()); - - return mav; - } - - @Override - protected Map referenceData(HttpServletRequest request) throws Exception { - Map map = new HashMap(); - String idString = request.getParameter("id"); - Person owner = null; - Scenario scen = null; - if (idString != null) { - scen = scenarioDao.read(Integer.parseInt(idString)); - owner = scen.getPerson(); - } - if (owner == null) { - owner = personDao.getLoggedPerson(); - } - List groups = researchGroupDao.getResearchGroupsWhereAbleToWriteInto(owner); - map.put("researchGroupList", groups); - - List schemaNames = scenarioSchemasDao.getSchemaNames(); - map.put("schemaNamesList", schemaNames); - - List schemaDescriptions = scenarioSchemasDao.getSchemaDescriptions(); - map.put("schemaDescriptionsList", schemaDescriptions); - - ResearchGroup defaultGroup = personDao.getLoggedPerson().getDefaultGroup(); - if (scen != null) { - defaultGroup = scen.getResearchGroup(); - } - int defaultGroupId = (defaultGroup != null) ? defaultGroup.getResearchGroupId() : 0; - map.put("defaultGroupId", defaultGroupId); - - return map; - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception { - ModelAndView mav = new ModelAndView(getSuccessView()); - log.debug("Processing form data"); - AddScenarioCommand data = (AddScenarioCommand) command; - - String idString = request.getParameter("id"); - int id = 0; - if (idString != null) { - id = Integer.parseInt(idString); - } - if (!auth.isAdmin()) { - if ((id > 0) && (!auth.userIsOwnerOfScenario(id))) { - // Editing existing scenario and user is not owner - mav.setViewName("redirect:/scenarios/list.html"); - return mav; - } - - if (!auth.userIsExperimenter()) { - mav.setViewName("scenario/userNotExperimenter"); - return mav; - } - } - - MultipartFile file = data.getDataFile(); - MultipartFile xmlFile = data.getDataFileXml(); - - Scenario scenario; - if (id > 0) { - // Editing existing - log.debug("Editing existing scenario."); - scenario = scenarioDao.read(id); - } else { - // Creating new - log.debug("Creating new scenario object"); - scenario = new Scenario(); - - log.debug("Setting owner to the logged user."); - scenario.setPerson(personDao.getLoggedPerson()); - - } - - log.debug("Setting research group."); - ResearchGroup group = new ResearchGroup(); - group.setResearchGroupId(data.getResearchGroup()); - scenario.setResearchGroup(group); - - log.debug("Setting scenario title: " + data.getTitle()); - scenario.setTitle(data.getTitle()); - - log.debug("Setting scenario description: " + data.getDescription()); - scenario.setDescription(data.getDescription()); - - log.debug("Setting scenario length: " + data.getLength()); - scenario.setScenarioLength(Integer.parseInt(data.getLength())); - //loading non-XML - if ((file != null) && (!file.isEmpty())) { - - } - - //loading XML - if ((xmlFile != null) && (!xmlFile.isEmpty())) { - - } - - log.debug("Setting private/public access"); - scenario.setPrivateScenario(data.getPrivateNote()); - - log.debug("Saving scenario object"); - if (!data.isDataFileAvailable()) { - - } - if (id > 0) { - // Editing existing - scenarioDao.update(scenario); - } else { - // Creating new - - scenarioDao.create(scenario); - } - - log.debug("Returning MAV"); - return mav; - } - - - public ScenarioDao getScenarioDao() { - return scenarioDao; - } - - public void setScenarioDao(ScenarioDao scenarioDao) { - this.scenarioDao = scenarioDao; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public ResearchGroupDao getResearchGroupDao() { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) { - this.researchGroupDao = researchGroupDao; - } - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } - - public ScenarioSchemasDao getScenarioSchemasDao() { - return scenarioSchemasDao; - } - - public void setScenarioSchemasDao(ScenarioSchemasDao scenarioSchemasDao) { - this.scenarioSchemasDao = scenarioSchemasDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioSchemaCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioSchemaCommand.java deleted file mode 100644 index 7b65431f..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioSchemaCommand.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddScenarioSchemaCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.scenario; - -import org.springframework.web.multipart.MultipartFile; - -/** - * Created by IntelliJ IDEA. - * User: Toshiba - * Date: 8.6.11 - * Time: 10:57 - * To change this template use File | Settings | File Templates. - */ -public class AddScenarioSchemaCommand { - - private int id; - private String schemaDescription; - private MultipartFile schemaFile; - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getSchemaDescription() { - return schemaDescription; - } - - public void setSchemaDescription(String schemaDescription) { - this.schemaDescription = schemaDescription; - } - - public MultipartFile getSchemaFile() { - return schemaFile; - } - - public void setSchemaFile(MultipartFile schemaFile) { - this.schemaFile = schemaFile; - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioSchemaController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioSchemaController.java deleted file mode 100644 index 5e5cc886..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioSchemaController.java +++ /dev/null @@ -1,185 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddScenarioSchemaController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.scenario; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.ScenarioSchemasDao; -import cz.zcu.kiv.eegdatabase.data.pojo.ScenarioSchemas; -import cz.zcu.kiv.eegdatabase.logic.schemagen.ScenarioSchemaGenerator; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.hibernate.Hibernate; -import org.springframework.context.ApplicationContext; -import org.springframework.validation.BindException; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; -import org.w3c.dom.Document; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import java.io.InputStream; -import java.sql.Clob; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -/** - * Created by IntelliJ IDEA. - * User: Toshiba - * Date: 8.6.11 - * Time: 10:57 - * To change this template use File | Settings | File Templates. - */ -public class AddScenarioSchemaController extends SimpleFormController { - - private Log log = LogFactory.getLog(getClass()); - private AuthorizationManager auth; - private ScenarioSchemasDao scenarioSchemasDao; - - public AddScenarioSchemaController() { - setCommandClass(AddScenarioSchemaCommand.class); - setCommandName("addScenarioSchema"); - } - - @Override - protected Object formBackingObject(HttpServletRequest request) throws Exception { - AddScenarioSchemaCommand data = (AddScenarioSchemaCommand) super.formBackingObject(request); - - String idString = request.getParameter("id"); - - if (idString != null) { - // Editing existing scenario schema - int id = Integer.parseInt(idString); - - log.debug("Loading scenario schema to the command object for editing."); - ScenarioSchemas schema = scenarioSchemasDao.read(id); - - data.setId(id); - data.setSchemaDescription(schema.getDescription()); - } - - return data; - } - - @Override - protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception { - ModelAndView mav = super.showForm(request, response, errors); - - // Creating new scenario schema - if (!auth.userIsExperimenter()) { - mav.setViewName("scenario/userNotExperimenter"); - } - mav.addObject("userIsExperimenter", auth.userIsExperimenter()); - - return mav; - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException bindException) throws Exception { - ModelAndView mav = new ModelAndView(getSuccessView()); - - log.debug("Processing form data"); - AddScenarioSchemaCommand data = (AddScenarioSchemaCommand) command; - - String idString = request.getParameter("id"); - int id = 0; - if (idString != null) { - id = Integer.parseInt(idString); - } - - MultipartFile schemaFile = data.getSchemaFile(); - - ScenarioSchemas scenarioSchema; - - if (id > 0) { - // Editing existing - log.debug("Editing existing scenario schema."); - scenarioSchema = scenarioSchemasDao.read(id); - - } else { - // Creating new - log.debug("Creating new scenario schema object"); - scenarioSchema = new ScenarioSchemas(); - } - - log.debug("Setting scenario schema description: " + data.getSchemaDescription()); - scenarioSchema.setDescription(data.getSchemaDescription()); - - //set scenario schema file - if((schemaFile != null) && (!schemaFile.isEmpty())) { - log.debug("Setting the scenario schema file"); - String schemaName = schemaFile.getOriginalFilename(); - scenarioSchema.setSchemaName(schemaName); - byte[] schemaContent = schemaFile.getBytes(); - //Clob schemaContent = Hibernate.createClob(schemaFile.getBytes().toString()); - - int newSchemaId = scenarioSchemasDao.getNextSchemaId(); - System.out.println(newSchemaId); - ScenarioSchemaGenerator schemaGenerator = new ScenarioSchemaGenerator(newSchemaId, schemaName, - schemaContent); - String sql = schemaGenerator.generateSql(); - String hbmXml = schemaGenerator.generateHbmXml(); - String pojo = schemaGenerator.generatePojo(); - String bean = schemaGenerator.generateBean(); - - scenarioSchema.setSql(Hibernate.createClob(sql)); - scenarioSchema.setHbmXml(Hibernate.createClob(hbmXml)); - scenarioSchema.setPojo(Hibernate.createClob(pojo)); - scenarioSchema.setBean(bean); - scenarioSchema.setApproved('n'); - } - - log.debug("Saving scenario schema object"); - - if (id > 0) { - // Editing existing - scenarioSchemasDao.update(scenarioSchema); - } else { - // Creating new - scenarioSchemasDao.create(scenarioSchema); - } - - log.debug("Returning MAV"); - return mav; - } - - public ScenarioSchemasDao getScenarioSchemasDao() { - return scenarioSchemasDao; - } - - public void setScenarioSchemasDao(ScenarioSchemasDao scenarioSchemasDao) { - this.scenarioSchemasDao = scenarioSchemasDao; - } - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioSchemaValidator.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioSchemaValidator.java deleted file mode 100644 index 3facc42e..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioSchemaValidator.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddScenarioSchemaValidator.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.scenario; - -import cz.zcu.kiv.eegdatabase.data.dao.ScenarioSchemasDao; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -/** - * Created by IntelliJ IDEA. - * User: Toshiba - * Date: 8.6.11 - * Time: 12:55 - * To change this template use File | Settings | File Templates. - */ -public class AddScenarioSchemaValidator implements Validator { - - private Log log = LogFactory.getLog(getClass()); - @Autowired - private ScenarioSchemasDao scenarioSchemasDao; - - public boolean supports(Class clazz) { - return clazz.equals(AddScenarioSchemaCommand.class); - } - - public void validate(Object command, Errors errors) { - log.debug("Validating scenario schema form"); - AddScenarioSchemaCommand data = (AddScenarioSchemaCommand) command; - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "schemaDescription", "required.field"); - - int len = data.getSchemaDescription().length(); - if (len > 2000) { - errors.rejectValue("schemaDescription", "invalid.maxScenSchemaLen"); - } - - if ((!(data.getId() > 0)) && (data.getSchemaFile().isEmpty()) - && (data.getSchemaFile().isEmpty())) { - // Creating new scenario and no file was uploaded - errors.rejectValue("schemaFile", "required.dataFileXsd"); - log.debug("No data file was inserted!"); - } - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioValidator.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioValidator.java deleted file mode 100644 index 5979ac58..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/AddScenarioValidator.java +++ /dev/null @@ -1,115 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AddScenarioValidator.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.scenario; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.ScenarioDao; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; - -/** - * @author JiPER - */ -public class AddScenarioValidator implements Validator { - - private Log log = LogFactory.getLog(getClass()); - private AuthorizationManager auth; - @Autowired - private ScenarioDao scenarioDao; - - public boolean supports(Class clazz) { - return clazz.equals(AddScenarioCommand.class); - } - - public void validate(Object command, Errors errors) { - log.debug("Validating scenario form"); - AddScenarioCommand data = (AddScenarioCommand) command; - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "title", "required.field"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "length", "required.field"); - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "description", "required.field"); - - if (data.getResearchGroup() == -1) { - // research group not chosen - errors.rejectValue("researchGroup", "required.researchGroup"); - } -// else if (!auth.personAbleToWriteIntoGroup(data.getResearchGroup())) { -// errors.rejectValue("researchGroup", "invalid.notAbleToAddExperimentInGroup"); -// } - - try { - int len = Integer.parseInt(data.getLength()); - if (len <= 0) { - errors.rejectValue("length", "invalid.lengthValue"); - } - } catch (NumberFormatException ex) { - errors.rejectValue("length", "invalid.scenarioLength"); - log.debug("Scenario length is not in parseable format!"); - } - int len = data.getDescription().length(); - if (len > 255) { - errors.rejectValue("description", "invalid.maxScenLen"); - } - - if (!scenarioDao.canSaveTitle(data.getTitle(), data.getId())) { - errors.rejectValue("title", "error.valueAlreadyInDatabase"); - } - - if ((!(data.getId() > 0)) && (data.isDataFileAvailable()) - && ((!data.isXmlFileCheckBox()))) { - if (data.getDataFile().isEmpty()) { - // Creating new scenario and no file was uploaded - errors.rejectValue("dataFile", "required.dataFile"); - log.debug("No data file was inserted!"); - } - } - - if ((!(data.getId() > 0)) && (data.isDataFileAvailable()) - && (data.isXmlFileCheckBox())) { - if (data.getDataFileXml().isEmpty()) { - // Creating new scenario and no file was uploaded - errors.rejectValue("dataFileXml", "required.dataFileXml"); - log.debug("No XML data file was inserted!"); - } - } - - if (data.isXmlFileCheckBox()) { - if (data.getScenarioSchema() == 0 && (data.getScenarioOption().equals("fromList"))) { - //scenario schema name is not chosen - errors.rejectValue("scenarioSchema", "required.scenarioSchema"); - log.debug("No scenario schema was selected!"); - } - } - } - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/ScenarioMultiController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/ScenarioMultiController.java deleted file mode 100644 index f00513c9..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/ScenarioMultiController.java +++ /dev/null @@ -1,114 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ScenarioMultiController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.scenario; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.dao.ScenarioDao; -import cz.zcu.kiv.eegdatabase.data.pojo.*; -import cz.zcu.kiv.eegdatabase.logic.util.Paginator; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.multiaction.MultiActionController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.List; -import java.util.Set; - -/** - * @author Jindra - */ -public class ScenarioMultiController extends MultiActionController { - - private AuthorizationManager auth; - private ScenarioDao scenarioDao; - private PersonDao personDao; - - private static final int ITEMS_PER_PAGE = 20; - - public ModelAndView list(HttpServletRequest request, HttpServletResponse response) { - ModelAndView mav = new ModelAndView("scenario/list"); - Person loggedUser = personDao.getLoggedPerson(); - mav.addObject("userIsExperimenter", auth.userIsExperimenter()); - - Paginator paginator = new Paginator(scenarioDao.getScenarioCountForList(loggedUser), ITEMS_PER_PAGE); - int page = 1; - try { - page = Integer.parseInt(request.getParameter("page")); - } catch (Exception e) { - } - paginator.setActualPage(page); - mav.addObject("paginator", paginator.getLinks()); - List list = scenarioDao.getScenariosForList(loggedUser, paginator.getFirstItemIndex(), ITEMS_PER_PAGE); - mav.addObject("scenarioList", list); - return mav; - } - - public ModelAndView detail(HttpServletRequest request, HttpServletResponse response) { - ModelAndView mav = new ModelAndView("scenario/detail"); - mav.addObject("userIsExperimenter", auth.userIsExperimenter()); - - int id = 0; - try { - id = Integer.parseInt(request.getParameter("scenarioId")); - } catch (Exception e) { - } - Scenario scenario = scenarioDao.read(id); - mav.addObject("scenarioDetail", scenario); - mav.addObject("isOwner", (auth.userIsOwnerOfScenario(id))||(auth.isAdmin())); - - return mav; - } - - public ModelAndView myScenarios(HttpServletRequest request, HttpServletResponse response) { - ModelAndView mav = new ModelAndView("scenario/myScenarios"); - mav.addObject("userIsExperimenter", auth.userIsExperimenter()); - List list = scenarioDao.getScenariosWhereOwner(personDao.getLoggedPerson()); - mav.addObject("scenarioList", list); - return mav; - } - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public ScenarioDao getScenarioDao() { - return scenarioDao; - } - - public void setScenarioDao(ScenarioDao scenarioDao) { - this.scenarioDao = scenarioDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/ScenarioXMLDownloadController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/ScenarioXMLDownloadController.java deleted file mode 100644 index 24856dbf..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/scenario/ScenarioXMLDownloadController.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ScenarioXMLDownloadController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.scenario; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.GenericDao; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.pojo.History; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.Scenario; -import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.AbstractController; -import org.w3c.dom.Document; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.xml.transform.*; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; -import java.io.ByteArrayOutputStream; -import java.io.StringWriter; -import java.sql.Blob; -import java.sql.SQLException; -import java.sql.Timestamp; -import java.util.Calendar; - -/** - * This controller loads a data object for the view which serves the downloading of the data file - * - * @author Jindra - */ -public class ScenarioXMLDownloadController extends AbstractController { - - private GenericDao scenarioDao; - private GenericDao historyDao; - private PersonDao personDao; - private Log log = LogFactory.getLog(getClass()); - private AuthorizationManager auth; - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } - - @Override - protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - // ModelAndView mav = new ModelAndView("scenarioXMLDownloadView"); - // There should always be set integer value in this field - it is generated by view, not by user - log.debug("Processing download scenario."); - int scenarioId = Integer.parseInt(request.getParameter("scenarioId")); - Scenario scenario = scenarioDao.read(scenarioId); - //TODO set Blob or XMLType - //Document xmlType = (Document) scenario.getScenarioType().getScenarioXml(); - //Blob c = (Blob) scenario.getScenarioType().getScenarioXml(); - - Person user = personDao.getPerson(ControllerUtils.getLoggedUserName()); - Timestamp currentTimestamp = new java.sql.Timestamp(Calendar.getInstance().getTime().getTime()); - History history = new History(); - log.debug("Setting downloading scenario"); - history.setScenario(scenario); - log.debug("Setting user"); - history.setPerson(user); - log.debug("Setting time of download"); - history.setDateOfDownload(currentTimestamp); - log.debug("Saving download history"); - historyDao.create(history); - response.setHeader("Content-Type", scenario.getMimetype()); - response.setHeader("Content-Disposition", "attachment;filename=" + scenario.getScenarioName()); - response.flushBuffer(); - // mav.addObject("dataObject", scenarioDao.read(scenarioId)); - - return null; - } - - private byte[] toByteArray(Object o) throws Exception { - if(o instanceof Blob) { - return ((Blob) o).getBytes(1, (int) ((Blob) o).length()); - } - else if(o instanceof Document) { - Source source = new DOMSource((Document) o); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - StringWriter stringWriter = new StringWriter(); - Result result = new StreamResult(out); - TransformerFactory factory = TransformerFactory.newInstance(); - Transformer transformer = factory.newTransformer(); - transformer.transform(source, result); - - return out.toByteArray(); - } - - return null; - } - - public GenericDao getScenarioDao() { - return scenarioDao; - } - - public void setScenarioDao(GenericDao scenarioDao) { - this.scenarioDao = scenarioDao; - } - - public GenericDao getHistoryDao() { - return historyDao; - } - - public void setHistoryDao(GenericDao historyDao) { - this.historyDao = historyDao; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/AbstractSearchController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/AbstractSearchController.java deleted file mode 100644 index cc6204ba..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/AbstractSearchController.java +++ /dev/null @@ -1,84 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AbstractSearchController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package cz.zcu.kiv.eegdatabase.logic.controller.search; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.ArrayList; -import java.util.Collections; -import java.util.Enumeration; -import java.util.List; - -/** - * @author Honza - */ -public class AbstractSearchController extends SimpleFormController { - - protected Log log = LogFactory.getLog(getClass()); - - protected List requests; - - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command) throws Exception { - logger.debug("Search scenario controller"); - ModelAndView mav = new ModelAndView(getSuccessView()); - - List source = new ArrayList(); - List condition = new ArrayList(); - List andOr = new ArrayList(); - Enumeration enumer = request.getParameterNames(); - while (enumer.hasMoreElements()) { - String param = (String) enumer.nextElement(); - if (param.startsWith("source")) { - source.add(param); - } else if (param.startsWith("condition")) { - condition.add(param); - } else { - andOr.add(param); - } - } - Collections.sort(andOr); - Collections.sort(source); - Collections.sort(condition); - requests = new ArrayList(); - requests.add(new SearchRequest(request.getParameter(condition.get(0)), - (request.getParameter(source.get(0))), "")); - for (int i = 1; i < condition.size(); i++) { - requests.add(new SearchRequest(request.getParameter(condition.get(i)), - (request.getParameter(source.get(i))), - (request.getParameter(andOr.get(i - 1))))); - } - return mav; - } - - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/ExperimentsSearcherCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/ExperimentsSearcherCommand.java deleted file mode 100644 index 31bcb8e8..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/ExperimentsSearcherCommand.java +++ /dev/null @@ -1,181 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ExperimentsSearcherCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package cz.zcu.kiv.eegdatabase.logic.controller.search; - -/** - * @author pbruha - */ -public class ExperimentsSearcherCommand { - - private String startDate; - private String startTime; - private String endDate; - private String endTime; - private int scenario; - private int[] hardware; - private String gender; - private int dateOption; - private int genderOption; - private int scenarioOption; - private int hardwareOption; - private int ageOption; - private String fromDate; - private String toDate; - private int scenarioLenghtFrom; - private int scenarioLenghtTo; - - - public String getEndDate() { - return endDate; - } - - public void setEndDate(String endDate) { - this.endDate = endDate; - } - - public String getEndTime() { - return endTime; - } - - public void setEndTime(String endTime) { - this.endTime = endTime; - } - - public String getGender() { - return gender; - } - - public void setGender(String gender) { - this.gender = gender; - } - - public int[] getHardware() { - return hardware; - } - - public void setHardware(int[] hardware) { - this.hardware = hardware; - } - - public int getScenario() { - return scenario; - } - - public void setScenario(int scenario) { - this.scenario = scenario; - } - - public String getStartDate() { - return startDate; - } - - public void setStartDate(String startDate) { - this.startDate = startDate; - } - - public String getStartTime() { - return startTime; - } - - public void setStartTime(String startTime) { - this.startTime = startTime; - } - - public int getDateOption() { - return dateOption; - } - - public void setDateOption(int dateOption) { - this.dateOption = dateOption; - } - - public int getGenderOption() { - return genderOption; - } - - public void setGenderOption(int genderOption) { - this.genderOption = genderOption; - } - - public int getScenarioOption() { - return scenarioOption; - } - - public void setScenarioOption(int scenarioOption) { - this.scenarioOption = scenarioOption; - } - - public int getHardwareOption() { - return hardwareOption; - } - - public void setHardwareOption(int hardwareOption) { - this.hardwareOption = hardwareOption; - } - - public int getAgeOption() { - return ageOption; - } - - public void setAgeOption(int ageOption) { - this.ageOption = ageOption; - } - - public String getFromDate() { - return fromDate; - } - - public void setFromDate(String fromDate) { - this.fromDate = fromDate; - } - - public String getToDate() { - return toDate; - } - - public void setToDate(String toDate) { - this.toDate = toDate; - } - - public int getScenarioLenghtFrom() { - return scenarioLenghtFrom; - } - - public void setScenarioLenghtFrom(int scenarioLenghtFrom) { - this.scenarioLenghtFrom = scenarioLenghtFrom; - } - - public int getScenarioLenghtTo() { - return scenarioLenghtTo; - } - - public void setScenarioLenghtTo(int scenarioLenghtTo) { - this.scenarioLenghtTo = scenarioLenghtTo; - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/ExperimentsSearcherController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/ExperimentsSearcherController.java deleted file mode 100644 index 387294ab..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/ExperimentsSearcherController.java +++ /dev/null @@ -1,121 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ExperimentsSearcherController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package cz.zcu.kiv.eegdatabase.logic.controller.search; - -import cz.zcu.kiv.eegdatabase.data.dao.ExperimentDao; -import cz.zcu.kiv.eegdatabase.data.dao.GenericDao; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Experiment; -import cz.zcu.kiv.eegdatabase.data.pojo.Hardware; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.Scenario; -import cz.zcu.kiv.eegdatabase.logic.util.SignalProcessingUtils; -import org.springframework.validation.BindException; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @author pbruha - */ -public class ExperimentsSearcherController extends AbstractSearchController { - - private PersonDao personDao; - private ExperimentDao experimentDao; - private GenericDao scenarioDao; - private GenericDao hardwareDao; - - public ExperimentsSearcherController() { - setCommandClass(ExperimentsSearcherCommand.class); - setCommandName("experimentsSearcherCommand"); - } - - - @Override - protected Map referenceData(HttpServletRequest request) throws Exception { - Map map = new HashMap(); - return map; - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { - logger.debug("Search experiments controller"); - ModelAndView mav = super.onSubmit(request, response, command); - try { - List experimentResults = experimentDao.getExperimentSearchResults(requests, personDao.getLoggedPerson().getPersonId()); - SignalProcessingUtils.splitExperimentToView(mav, experimentResults); - mav.addObject("resultsEmpty", experimentResults.isEmpty()); - - } catch (NumberFormatException e) { - mav.addObject("mistake", "Number error"); - mav.addObject("error", true); - - } catch (RuntimeException e) { - mav.addObject("mistake", e.getMessage()); - mav.addObject("error", true); - - } - return mav; - } - - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public GenericDao getScenarioDao() { - return scenarioDao; - } - - public void setScenarioDao(GenericDao scenarioDao) { - this.scenarioDao = scenarioDao; - } - - public ExperimentDao getExperimentDao() { - return experimentDao; - } - - public void setExperimentDao(ExperimentDao experimentDao) { - this.experimentDao = experimentDao; - } - - public GenericDao getHardwareDao() { - return hardwareDao; - } - - public void setHardwareDao(GenericDao hardwareDao) { - this.hardwareDao = hardwareDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/FullTextSearchCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/FullTextSearchCommand.java deleted file mode 100644 index c6670f0b..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/FullTextSearchCommand.java +++ /dev/null @@ -1,60 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * FullTextSearchCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package cz.zcu.kiv.eegdatabase.logic.controller.search; - -/** - * @author Petr Ježek - */ -public class FullTextSearchCommand { - - private String searchTI; - private String weathernote; - - public String getWeathernote() { - return weathernote; - } - - public void setWeathernote(String weathernote) { - this.weathernote = weathernote; - } - - /** - * @return the searchTI - */ - public String getSearchTI() { - return searchTI; - } - - /** - * @param searchTI the searchTI to set - */ - public void setSearchTI(String searchTI) { - this.searchTI = searchTI; - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/FullTextSearchController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/FullTextSearchController.java deleted file mode 100644 index 6af24287..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/FullTextSearchController.java +++ /dev/null @@ -1,226 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * FullTextSearchController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package cz.zcu.kiv.eegdatabase.logic.controller.search; - -import cz.zcu.kiv.eegdatabase.data.dao.GenericDao; -import cz.zcu.kiv.eegdatabase.data.pojo.*; -import cz.zcu.kiv.eegdatabase.logic.wrapper.*; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.validation.BindException; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -/** - * - * @author Petr Brůha - */ -public class FullTextSearchController extends SimpleFormController { - - Log log = LogFactory.getLog(getClass()); - //private GenericDao genericDao; - private GenericDao personDao; - private GenericDao experimentDao; - private GenericDao scenarioDao; - private GenericDao articleDao; - private GenericDao hardwareDao; - private GenericDao weatherDao; - private GenericDao experimentOptParamDef; - private GenericDao commentDao; - - public FullTextSearchController() { - setCommandClass(FullTextSearchCommand.class); - setCommandName("fullTextSearchCommand"); - } - - @Override - protected Object formBackingObject(HttpServletRequest request) throws Exception { - FullTextSearchCommand search = (FullTextSearchCommand) super.formBackingObject(request); - return search; - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { - logger.debug("Full text search controller"); - ModelAndView mav = new ModelAndView(getSuccessView()); - ArrayList mistakes = new ArrayList(); - FullTextSearchCommand fullTextSearchCommand = (FullTextSearchCommand) command; - logger.debug("I have fullTextSearchCommand: " + fullTextSearchCommand); - String fullTextQuery = fullTextSearchCommand.getSearchTI(); - if (!fullTextQuery.equals("") && !fullTextQuery.startsWith("*")) { - Set results = new HashSet(); - Wrapper w; - - - Map scen = scenarioDao.getFulltextResults(fullTextQuery); - for (Map.Entry entry : scen.entrySet()) { - w = new ScenarioWrapper(entry.getKey()); - results.add(new FulltextResult(entry.getKey().getScenarioId(), entry.getValue(), w.className(), w.getPath(), w.getTitle())); - } - - Map exp = experimentDao.getFulltextResults(fullTextQuery); - for (Map.Entry entry : exp.entrySet()) { - w = new ExperimentWrapper(entry.getKey()); - results.add(new FulltextResult(entry.getKey().getExperimentId(), entry.getValue(), w.className(), w.getPath(), w.getTitle())); - } - - Map per = personDao.getFulltextResults(fullTextQuery); - for (Map.Entry entry : per.entrySet()) { - w = new PersonWrapper(entry.getKey()); - results.add(new FulltextResult(entry.getKey().getPersonId(), entry.getValue(), w.className(), w.getPath(), w.getTitle())); - } - - Map art = articleDao.getFulltextResults(fullTextQuery); - for (Map.Entry entry : art.entrySet()) { - w = new ArticleWrapper(entry.getKey()); - results.add(new FulltextResult(entry.getKey().getArticleId(), entry.getValue(), w.className(), w.getPath(), w.getTitle())); - } - - Map hw = hardwareDao.getFulltextResults(fullTextQuery); - for (Map.Entry entry : hw.entrySet()) { - for (Experiment e : entry.getKey().getExperiments()) { - w = new ExperimentWrapper(e); - results.add(new FulltextResult(e.getExperimentId(), entry.getValue(), w.className(), w.getPath(), w.getTitle())); - } - } - -// Map vis = eyesDefectDao.getFulltextResults(fullTextQuery); -// for (Map.Entry entry : vis.entrySet()) { -// for (Person p : entry.getKey().getPersons()) { -// w = new PersonWrapper(p); -// results.add(new FulltextResult(p.getPersonId(), entry.getValue(), w.className(), w.getPath(), w.getTitle())); -// } -// } -// -// Map hear = hearingImpairmentDao.getFulltextResults(fullTextQuery); -// for (Map.Entry entry : hear.entrySet()) { -// for (Person p : entry.getKey().getPersons()) { -// w = new PersonWrapper(p); -// results.add(new FulltextResult(p.getPersonId(), entry.getValue(), w.className(), w.getPath(), w.getTitle())); -// } -// } - - Map wea = weatherDao.getFulltextResults(fullTextQuery); - for (Map.Entry entry : wea.entrySet()) { - for (Experiment e : entry.getKey().getExperiments()) { - w = new ExperimentWrapper(e); - results.add(new FulltextResult(e.getExperimentId(), entry.getValue(), w.className(), w.getPath(), w.getTitle())); - } - } - - Map com = commentDao.getFulltextResults(fullTextQuery); - for (Map.Entry entry : com.entrySet()) { - w = new ArticleWrapper(entry.getKey().getArticle()); - results.add(new FulltextResult(entry.getKey().getArticle().getArticleId(), entry.getValue(), w.className(), w.getPath(), w.getTitle())); - } - - logger.debug("I have results: " + results); - - mav.addObject("searchedString", fullTextQuery); - mav.addObject("searchResults", results); - mav.addObject("resultsEmpty", results.isEmpty()); - } else { - mistakes.add("Unable to parse query: " + fullTextQuery); - logger.debug("Unable to parse query: " + fullTextQuery); - mav.addObject("errors", mistakes); - } - return mav; - } - - public GenericDao getPersonDao() { - return personDao; - } - - public void setPersonDao(GenericDao personDao) { - this.personDao = personDao; - } - - public GenericDao getScenarioDao() { - return scenarioDao; - } - - public void setScenarioDao(GenericDao scenarioDao) { - this.scenarioDao = scenarioDao; - } - - public GenericDao getExperimentDao() { - return experimentDao; - } - - public void setExperimentDao(GenericDao experimentDao) { - this.experimentDao = experimentDao; - } - - public GenericDao getArticleDao() { - return articleDao; - } - - public void setArticleDao(GenericDao articleDao) { - this.articleDao = articleDao; - } - - public GenericDao getHardwareDao() { - return hardwareDao; - } - - public void setHardwareDao(GenericDao hardwareDao) { - this.hardwareDao = hardwareDao; - } - - - public GenericDao getWeatherDao() { - return weatherDao; - } - - public void setWeatherDao(GenericDao weatherDao) { - this.weatherDao = weatherDao; - } - - public GenericDao getExperimentOptParamDef() { - return experimentOptParamDef; - } - - public void setExperimentOptParamDef(GenericDao experimentOptParamDef) { - this.experimentOptParamDef = experimentOptParamDef; - } - - public GenericDao getCommentDao() { - return commentDao; - } - - public void setCommentDao(GenericDao commentDao) { - this.commentDao = commentDao; - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/FulltextResult.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/FulltextResult.java deleted file mode 100644 index 70729451..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/FulltextResult.java +++ /dev/null @@ -1,113 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * FulltextResult.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package cz.zcu.kiv.eegdatabase.logic.controller.search; - - -/** - * @author Honza - */ -public class FulltextResult { - - private int id; - private String foundString; - private String section; - private String path; - private String title; - - - public FulltextResult(int id, String foundString) { - this.id = id; - this.foundString = foundString; - } - - public FulltextResult(int id, String foundString, String section, String path, String title) { - this.id = id; - this.foundString = foundString; - this.section = section; - this.path = path; - this.title = title; - } - - public String getSection() { - return section; - } - - public void setSection(String section) { - this.section = section; - } - - public String getFoundString() { - return foundString; - } - - public void setFoundString(String foundString) { - this.foundString = foundString; - } - - public int getId() { - return id; - } - - public void setId(int id) { - this.id = id; - } - - public String getPath() { - return path; - } - - public void setPath(String path) { - this.path = path; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - @Override - public boolean equals(Object obj) { - if (obj == this) return true; - if (!(obj instanceof FulltextResult)) return false; - FulltextResult fr = (FulltextResult) obj; - if ((this.section.equals(fr.section)) && (this.id == fr.id)) return true; - return false; - } - - @Override - public int hashCode() { - int hash = 5; - hash = 97 * hash + this.id; - hash = 97 * hash + (this.section != null ? this.section.hashCode() : 0); - return hash; - } - - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/PeopleSearcherCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/PeopleSearcherCommand.java deleted file mode 100644 index db56b884..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/PeopleSearcherCommand.java +++ /dev/null @@ -1,142 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * PeopleSearcherCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package cz.zcu.kiv.eegdatabase.logic.controller.search; - -/** - * @author pbruha - */ -public class PeopleSearcherCommand { - - private int givennameOption; - private String givenname; - private int surnameOption; - private String surname; - private int emailOption; - private String email; - private int genderOption; - private String gender; - private int ageOption; - private String fromDate; - private String toDate; - private int withoutDefectOption; - - public int getAgeOption() { - return ageOption; - } - - public void setAgeOption(int ageOption) { - this.ageOption = ageOption; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public int getEmailOption() { - return emailOption; - } - - public void setEmailOption(int emailOption) { - this.emailOption = emailOption; - } - - public String getFromDate() { - return fromDate; - } - - public void setFromDate(String fromDate) { - this.fromDate = fromDate; - } - - public String getGender() { - return gender; - } - - public void setGender(String gender) { - this.gender = gender; - } - - public int getGenderOption() { - return genderOption; - } - - public void setGenderOption(int genderOption) { - this.genderOption = genderOption; - } - - public String getGivenname() { - return givenname; - } - - public void setGivenname(String givenname) { - this.givenname = givenname; - } - - public int getGivennameOption() { - return givennameOption; - } - - public void setGivennameOption(int givennameOption) { - this.givennameOption = givennameOption; - } - - public String getSurname() { - return surname; - } - - public void setSurname(String surname) { - this.surname = surname; - } - - public int getSurnameOption() { - return surnameOption; - } - - public void setSurnameOption(int surnameOption) { - this.surnameOption = surnameOption; - } - - public String getToDate() { - return toDate; - } - - public void setToDate(String toDate) { - this.toDate = toDate; - } - - public int getWithoutDefectOption() { - return withoutDefectOption; - } - - public void setWithoutDefectOption(int withoutDefectOption) { - this.withoutDefectOption = withoutDefectOption; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/PeopleSearcherController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/PeopleSearcherController.java deleted file mode 100644 index e98d8a7f..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/PeopleSearcherController.java +++ /dev/null @@ -1,102 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * PeopleSearcherController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package cz.zcu.kiv.eegdatabase.logic.controller.search; - -import cz.zcu.kiv.eegdatabase.data.dao.AuthorizationManager; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.validation.BindException; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.List; - -/** - * @author pbruha - */ -public class PeopleSearcherController extends AbstractSearchController { - - private PersonDao personDao; - @Autowired - private AuthorizationManager auth; - - public PeopleSearcherController() { - setCommandClass(PeopleSearcherCommand.class); - setCommandName("peopleSearcherCommand"); - } - - @Override - protected Object formBackingObject(HttpServletRequest request) throws Exception { - PeopleSearcherCommand search = (PeopleSearcherCommand) super.formBackingObject(request); - return search; - } - - @Override - protected ModelAndView showForm(HttpServletRequest request, HttpServletResponse response, BindException errors) throws Exception { - ModelAndView mav = super.showForm(request, response, errors); - boolean userIsExperimenter = auth.userIsExperimenter(); - mav.addObject("userIsExperimenter", userIsExperimenter); - - return mav; - } - - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { - logger.debug("Search people controller"); - ModelAndView mav = super.onSubmit(request, response, command); - - try { - List personResults = personDao.getPersonSearchResults(requests); - mav.addObject("personResults", personResults); - mav.addObject("resultsEmpty", personResults.isEmpty()); - } catch (NumberFormatException e) { - mav.addObject("mistake", "Number error"); - mav.addObject("error", true); - } catch (RuntimeException e) { - mav.addObject("mistake", e.getMessage()); - mav.addObject("error", true); - } - boolean userIsExperimenter = auth.userIsExperimenter(); - mav.addObject("userIsExperimenter", userIsExperimenter); - return mav; - } - - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/ScenarioSearcherCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/ScenarioSearcherCommand.java deleted file mode 100644 index 6363ff31..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/ScenarioSearcherCommand.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ScenarioSearcherCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ -package cz.zcu.kiv.eegdatabase.logic.controller.search; - -/** - * @author pbruha - */ -public class ScenarioSearcherCommand { - - private int scenarioOption; - private int scenario; - private int lenghtOption; - private int scenarioLenghtFrom; - private int scenarioLenghtTo; - private int authorScenarioOption; - private int authorsScenario; - - public int getAuthorScenarioOption() { - return authorScenarioOption; - } - - public void setAuthorScenarioOption(int authorScenarioOption) { - this.authorScenarioOption = authorScenarioOption; - } - - public int getAuthorsScenario() { - return authorsScenario; - } - - public void setAuthorsScenario(int authorsScenario) { - this.authorsScenario = authorsScenario; - } - - public int getLenghtOption() { - return lenghtOption; - } - - public void setLenghtOption(int lenghtOption) { - this.lenghtOption = lenghtOption; - } - - public int getScenario() { - return scenario; - } - - public void setScenario(int scenario) { - this.scenario = scenario; - } - - public int getScenarioLenghtFrom() { - return scenarioLenghtFrom; - } - - public void setScenarioLenghtFrom(int scenarioLenghtFrom) { - this.scenarioLenghtFrom = scenarioLenghtFrom; - } - - public int getScenarioLenghtTo() { - return scenarioLenghtTo; - } - - public void setScenarioLenghtTo(int scenarioLenghtTo) { - this.scenarioLenghtTo = scenarioLenghtTo; - } - - public int getScenarioOption() { - return scenarioOption; - } - - public void setScenarioOption(int scenarioOption) { - this.scenarioOption = scenarioOption; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/ScenarioSearcherController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/ScenarioSearcherController.java deleted file mode 100644 index 88793e76..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/ScenarioSearcherController.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ScenarioSearcherController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package cz.zcu.kiv.eegdatabase.logic.controller.search; - -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.dao.ScenarioDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.Scenario; -import org.springframework.validation.BindException; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @author pbruha - */ -public class ScenarioSearcherController extends AbstractSearchController { - private PersonDao personDao; - private ScenarioDao scenarioDao; - - public ScenarioSearcherController() { - setCommandClass(ScenarioSearcherCommand.class); - setCommandName("scenarioSearcherCommand"); - } - - @Override - protected Object formBackingObject(HttpServletRequest request) throws Exception { - ScenarioSearcherCommand search = (ScenarioSearcherCommand) super.formBackingObject(request); - return search; - } - - @Override - protected Map referenceData(HttpServletRequest request) throws Exception { - Map map = new HashMap(); - return map; - } - - @Override - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { - ModelAndView mav = null; - try { - mav = super.onSubmit(request, response, command); - } catch (Exception e) { - e.printStackTrace(); - } - try { - - List scenarioResults = scenarioDao.getScenarioSearchResults - (requests, personDao.getLoggedPerson().getPersonId()); - mav.addObject("scenarioResults", scenarioResults); - mav.addObject("resultsEmpty", scenarioResults.isEmpty()); - } catch (NumberFormatException e) { - mav.addObject("mistake", "Number error"); - mav.addObject("error", true); - } catch (RuntimeException e) { - mav.addObject("mistake", e.getMessage()); - mav.addObject("error", true); - } - - return mav; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public ScenarioDao getScenarioDao() { - return scenarioDao; - } - - public void setScenarioDao(ScenarioDao scenarioDao) { - this.scenarioDao = scenarioDao; - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/AbstractProcessingController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/AbstractProcessingController.java deleted file mode 100644 index fad9b670..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/AbstractProcessingController.java +++ /dev/null @@ -1,108 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * AbstractProcessingController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.service; - -import cz.zcu.kiv.eegdatabase.data.dao.GenericDao; -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.dao.ServiceResultDao; -import cz.zcu.kiv.eegdatabase.data.pojo.DataFile; -import cz.zcu.kiv.eegdatabase.data.pojo.Experiment; -import cz.zcu.kiv.eegdatabase.logic.signal.ChannelInfo; -import cz.zcu.kiv.eegdatabase.logic.signal.DataTransformer; -import org.springframework.web.servlet.mvc.SimpleFormController; - -import javax.servlet.http.HttpServletRequest; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.RandomAccessFile; -import java.sql.Blob; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - - -public abstract class AbstractProcessingController extends SimpleFormController { - - protected GenericDao experimentDao; - protected ServiceResultDao resultDao; - protected PersonDao personDao; - protected DataTransformer transformer; - protected String fileName; - - protected Map referenceData(HttpServletRequest request) throws Exception { - String header = request.getParameter("headerName"); - Map map = new HashMap(); - int id = Integer.parseInt(request.getParameter("experimentId")); - Experiment experiment = experimentDao.read(id); - byte[] bytes = null; - for (DataFile d : experiment.getDataFiles()) { - if ((d.getFilename().endsWith(".vhdr"))&&(d.getFilename().startsWith(header))) { - bytes = d.getFileContent().getBytes(1, (int)d.getFileContent().length()); - int index = d.getFilename().lastIndexOf("."); - fileName = d.getFilename().substring(0, index); - break; - } - } - transformer.readVhdr(bytes); - List channels = transformer.getChannelInfo(); - map.put("channels", channels); - map.put("experimentId", id); - - return map; - } - - public GenericDao getExperimentDao() { - return experimentDao; - } - - public void setExperimentDao(GenericDao experimentDao) { - this.experimentDao = experimentDao; - } - - public DataTransformer getTransformer() { - return transformer; - } - - public void setTransformer(DataTransformer transformer) { - this.transformer = transformer; - } - - public ServiceResultDao getResultDao() { - return resultDao; - } - - public void setResultDao(ServiceResultDao resultDao) { - this.resultDao = resultDao; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/ChooseCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/ChooseCommand.java deleted file mode 100644 index 1be53a92..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/ChooseCommand.java +++ /dev/null @@ -1,53 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ChooseCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.service; - -/** - * Created by IntelliJ IDEA. - * User: Honza - * Date: 16.9.11 - * Time: 15:46 - * To change this template use File | Settings | File Templates. - */ -public class ChooseCommand { - - String headerName; - - String service; - - public String getHeaderName() { - return headerName; - } - - public void setHeaderName(String headerName) { - this.headerName = headerName; - } - - public String getService() { - return service; - } - - public void setService(String service) { - this.service = service; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/FastFourierCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/FastFourierCommand.java deleted file mode 100644 index 48ccf686..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/FastFourierCommand.java +++ /dev/null @@ -1,43 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * FastFourierCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.service; - -/** - * Created by IntelliJ IDEA. - * User: Honza - * Date: 29.4.2011 - * Time: 9:53:40 - * To change this template use File | Settings | File Templates. - */ -public class FastFourierCommand { - - private int channel; - - public void setChannel(int channel) { - this.channel = channel; - } - - public int getChannel() { - return channel; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/FastFourierController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/FastFourierController.java deleted file mode 100644 index 5dbd3e92..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/FastFourierController.java +++ /dev/null @@ -1,137 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * FastFourierController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.service; - -import cz.zcu.kiv.eegdatabase.data.pojo.DataFile; -import cz.zcu.kiv.eegdatabase.data.pojo.Experiment; -import cz.zcu.kiv.eegdatabase.data.pojo.ServiceResult; -import cz.zcu.kiv.eegdsp.common.ISignalProcessingResult; -import cz.zcu.kiv.eegdsp.common.ISignalProcessor; -import cz.zcu.kiv.eegdsp.main.SignalProcessingFactory; -import org.jfree.chart.ChartFactory; -import org.jfree.chart.ChartUtilities; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.data.xy.XYSeries; -import org.jfree.data.xy.XYSeriesCollection; -import org.springframework.validation.BindException; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.ByteArrayOutputStream; -import java.util.Map; -import org.hibernate.Hibernate; - - -public class FastFourierController extends AbstractProcessingController { - - public FastFourierController() { - setCommandClass(FastFourierCommand.class); - setCommandName("fastFourier"); - } - - protected Map referenceData(HttpServletRequest request) throws Exception { - - return super.referenceData(request); - } - - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { - FastFourierCommand cmd = (FastFourierCommand) command; - ModelAndView mav = new ModelAndView(getSuccessView()); - int id = Integer.parseInt(request.getParameter("experimentId")); - Experiment ex = experimentDao.read(id); - byte[] data = null; - for (DataFile dataFile : ex.getDataFiles()) { - int index = dataFile.getFilename().lastIndexOf("."); - if (dataFile.getFilename().substring(0, index).equals(super.fileName)) { - if ((dataFile.getFilename().endsWith(".avg"))||(dataFile.getFilename().endsWith(".eeg"))) { - data = dataFile.getFileContent().getBytes(1, (int)dataFile.getFileContent().length()); - break; - } - } - } - ServiceResult service = new ServiceResult(); - service.setOwner(personDao.getLoggedPerson()); - service.setStatus("running"); - service.setTitle(super.fileName + "_Fast_Fourier"); - service.setFilename(super.fileName + "_FFT.png"); - resultDao.create(service); - double signal[] = transformer.readBinaryData(data, cmd.getChannel()); - new FFTProcess(service, signal).start(); - - return mav; - } - private class FFTProcess extends Thread { - private ServiceResult service; - private double[] signal; - - public FFTProcess(ServiceResult result, double[] signal) { - this.service = result; - this.signal = signal; - } - - public void run() { - ISignalProcessor fft = SignalProcessingFactory.getInstance().getFastFourier(); - ISignalProcessingResult res; - res = fft.processSignal(signal); - Map map = res.toHashMap(); - Double[][] result = map.get("coefficients"); - double[] real = new double[result.length]; - double[] imag = new double[result.length]; - for (int i = 0; i < result.length; i++) { - real[i] = result[i][0]; - imag[i] = result[i][1]; - } - XYSeries XYreal = new XYSeries("Real part"); - XYSeries XYimag = new XYSeries("Imaginary part"); - for (int i = 200; i < real.length - 200; i++) { - XYreal.add(i, real[i]); - XYimag.add(i, imag[i]); - } - XYSeriesCollection dataset = new XYSeriesCollection(); - dataset.addSeries(XYreal); - dataset.addSeries(XYimag); - // Generate the graph - JFreeChart chart = ChartFactory.createXYLineChart("Fast Fourier Transformation", // Title - "time", // x-axis Label - "value", // y-axis Label - dataset, // Dataset - PlotOrientation.VERTICAL, // Plot Orientation - true, // Show Legend - true, // Use tooltips - false // Configure chart to generate URLs? - ); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - try { - ChartUtilities.writeChartAsPNG(out, chart, 800, 500); - } catch (Exception e) { - - } - service.setContent(Hibernate.createBlob(out.toByteArray())); - service.setStatus("finished"); - resultDao.update(service); - - } - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/MatchingPursuitCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/MatchingPursuitCommand.java deleted file mode 100644 index 8e3a1edf..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/MatchingPursuitCommand.java +++ /dev/null @@ -1,52 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * MatchingPursuitCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.service; - -/** - * Created by IntelliJ IDEA. - * User: Honza - * Date: 28.4.2011 - * Time: 20:29:28 - * To change this template use File | Settings | File Templates. - */ -public class MatchingPursuitCommand { - - private int channel; - private int atom; - - public int getChannel() { - return channel; - } - - public void setChannel(int channel) { - this.channel = channel; - } - - public int getAtom() { - return atom; - } - - public void setAtom(int atom) { - this.atom = atom; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/MatchingPursuitController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/MatchingPursuitController.java deleted file mode 100644 index 80494f7c..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/MatchingPursuitController.java +++ /dev/null @@ -1,148 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * MatchingPursuitController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.service; - -import cz.zcu.kiv.eegdatabase.data.pojo.DataFile; -import cz.zcu.kiv.eegdatabase.data.pojo.Experiment; -import cz.zcu.kiv.eegdatabase.data.pojo.ServiceResult; -import cz.zcu.kiv.eegdsp.common.ISignalProcessingResult; -import cz.zcu.kiv.eegdsp.common.ISignalProcessor; -import cz.zcu.kiv.eegdsp.main.SignalProcessingFactory; -import cz.zcu.kiv.eegdsp.matchingpursuit.MatchingPursuit; -import org.jfree.chart.ChartFactory; -import org.jfree.chart.ChartUtilities; -import org.jfree.chart.JFreeChart; -import org.jfree.chart.plot.PlotOrientation; -import org.jfree.data.xy.XYSeries; -import org.jfree.data.xy.XYSeriesCollection; -import org.springframework.validation.BindException; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.ByteArrayOutputStream; -import java.util.Map; -import org.hibernate.Hibernate; - - - -public class MatchingPursuitController extends AbstractProcessingController { - - private final int MAX_SIGNAL_LENGTH = 10240; - - public MatchingPursuitController() { - setCommandClass(MatchingPursuitCommand.class); - setCommandName("matchingPursuit"); - } - - protected Map referenceData(HttpServletRequest request) throws Exception { - return super.referenceData(request); - } - - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { - MatchingPursuitCommand cmd = (MatchingPursuitCommand) command; - ModelAndView mav = new ModelAndView(getSuccessView()); - int id = Integer.parseInt(request.getParameter("experimentId")); - Experiment ex = experimentDao.read(id); - byte[] data = null; - for (DataFile dataFile : ex.getDataFiles()) { - int index = dataFile.getFilename().lastIndexOf("."); - if (dataFile.getFilename().substring(0, index).equals(super.fileName)) { - if ((dataFile.getFilename().endsWith(".avg")) || (dataFile.getFilename().endsWith(".eeg"))) { - data = dataFile.getFileContent().getBytes(1,(int) dataFile.getFileContent().length()); - break; - } - } - } - ServiceResult service = new ServiceResult(); - service.setOwner(personDao.getLoggedPerson()); - service.setStatus("running"); - service.setTitle(super.fileName + "_Matching_Pursuit"); - service.setFilename(super.fileName + "_MP.png"); - resultDao.create(service); - double signal[] = transformer.readBinaryData(data, cmd.getChannel()); - - new MPProcess(service, signal, cmd.getAtom()).start(); - - return mav; - } - - private class MPProcess extends Thread { - private ServiceResult service; - private double[] signal; - private int atoms; - - public MPProcess(ServiceResult result, double[] signal, int atoms) { - this.service = result; - this.atoms = atoms; - this.signal = signal; - } - - public void run() { - if (signal.length > MAX_SIGNAL_LENGTH) { - service.setStatus("failed"); - service.setFilename("errorLog.txt"); - String errorText = "Not enough memory for analysed signal."; - service.setContent(Hibernate.createBlob(errorText.getBytes())); - resultDao.update(service); - return; - } - ISignalProcessingResult res = null; - ISignalProcessor mp = SignalProcessingFactory.getInstance().getMatchingPursuit(); - ((MatchingPursuit) mp).setIterationCount(atoms); - res = mp.processSignal(signal); - Map result = res.toHashMap(); - Double[][] atoms = result.get("atoms"); - Double[][] rec = result.get("reconstruction"); - XYSeries XYatom = new XYSeries("Gabor atom"); - XYSeries XYrec = new XYSeries("Reconstructed signal"); - for (int i = 0; i < signal.length; i++) { - XYatom.add(i, atoms[0][i]); - XYrec.add(i, rec[0][i]); - } - XYSeriesCollection dataset = new XYSeriesCollection(); - dataset.addSeries(XYatom); - dataset.addSeries(XYrec); - // Generate the graph - JFreeChart chart = ChartFactory.createXYLineChart("Matching Pursuit", // Title - "time", // x-axis Label - "value", // y-axis Label - dataset, // Dataset - PlotOrientation.VERTICAL, // Plot Orientation - true, // Show Legend - true, // Use tooltips - false // Configure chart to generate URLs? - ); - ByteArrayOutputStream out = new ByteArrayOutputStream(); - try { - ChartUtilities.writeChartAsPNG(out, chart, 800, 500); - } catch (Exception e) { - - } - service.setContent(Hibernate.createBlob(out.toByteArray())); - service.setStatus("finished"); - resultDao.update(service); - - } - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/ServiceChooserController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/ServiceChooserController.java deleted file mode 100644 index e5e866e0..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/ServiceChooserController.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ServiceChooserController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.service; - -import cz.zcu.kiv.eegdatabase.data.dao.GenericDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Experiment; -import cz.zcu.kiv.eegdatabase.logic.util.SignalProcessingUtils; -import org.springframework.validation.BindException; -import org.springframework.validation.Errors; -import org.springframework.validation.ValidationUtils; -import org.springframework.validation.Validator; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.SimpleFormController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.HashMap; -import java.util.Map; - -/** - * Created by IntelliJ IDEA. - * User: Honza - * Date: 16.9.11 - * Time: 15:47 - * To change this template use File | Settings | File Templates. - */ -public class ServiceChooserController extends SimpleFormController implements Validator { - - protected GenericDao experimentDao; - - public ServiceChooserController() { - setCommandClass(ChooseCommand.class); - setCommandName("chooseCmd"); - } - - protected Map referenceData(HttpServletRequest request) throws Exception { - Map map = new HashMap(); - int id = Integer.parseInt(request.getParameter("experimentId")); - Experiment experiment = experimentDao.read(id); - map.put("headers", SignalProcessingUtils.getHeaders(experiment)); - ServicesList[] services = ServicesList.values(); - map.put("services", services); - map.put("experimentId", id); - return map; - } - - protected Object formBackingObject(HttpServletRequest request) throws Exception { - return super.formBackingObject(request); - } - - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { - ChooseCommand cmd = (ChooseCommand) command; - int id = Integer.parseInt(request.getParameter("experimentId")); - String service = cmd.getService(); - ModelAndView mav = null; - if (service.equals(ServicesList.MATCHING_PURSUIT.getName())) { - mav = new ModelAndView("redirect:matchingForm.html?experimentId="+id); - } - if (service.equals(ServicesList.DISCRETE_WAVELET.getName())) { - mav = new ModelAndView("redirect:waveletForm.html?experimentId="+id+"&type=DWT"); - } - if (service.equals(ServicesList.CONTINUOUS_WAVELET.getName())) { - mav = new ModelAndView("redirect:waveletForm.html?experimentId="+id+"&type=CWT"); - } - if (service.equals(ServicesList.FAST_FOURIER.getName())) { - mav = new ModelAndView("redirect:fourierForm.html?experimentId="+id); - } - mav.addObject("headerName", cmd.getHeaderName()); - return mav; - - } - - public GenericDao getExperimentDao() { - return experimentDao; - } - - public void setExperimentDao(GenericDao experimentDao) { - this.experimentDao = experimentDao; - } - - public boolean supports(Class aClass) { - return aClass.equals(ChooseCommand.class); - } - - public void validate(Object o, Errors errors) { - ChooseCommand cmd = (ChooseCommand) o; - ValidationUtils.rejectIfEmptyOrWhitespace(errors, "headerName", "required.header"); - - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/ServicesList.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/ServicesList.java deleted file mode 100644 index d99a57a0..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/ServicesList.java +++ /dev/null @@ -1,47 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ServicesList.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.service; - -/** - * Created by IntelliJ IDEA. - * User: Honza - * Date: 17.9.11 - * Time: 20:52 - * To change this template use File | Settings | File Templates. - */ -public enum ServicesList { - MATCHING_PURSUIT("Matching Pursuit"), - DISCRETE_WAVELET("Discrete Wavelet Transformation"), - CONTINUOUS_WAVELET("Continuous Wavelet Transformation"), - FAST_FOURIER("Fast Fourier"); - - private final String name; - - ServicesList(String name) { - this.name = name; - } - - public String getName() { - return name; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/WaveletCommand.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/WaveletCommand.java deleted file mode 100644 index 614d97ca..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/WaveletCommand.java +++ /dev/null @@ -1,45 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * WaveletCommand.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.service; - -public class WaveletCommand { - - private int channel; - private String wavelet; - - public int getChannel() { - return channel; - } - - public String getWavelet() { - return wavelet; - } - - public void setChannel(int channel) { - this.channel = channel; - } - - public void setWavelet(String wavelet) { - this.wavelet = wavelet; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/WaveletProcessingController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/WaveletProcessingController.java deleted file mode 100644 index 0090f387..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/service/WaveletProcessingController.java +++ /dev/null @@ -1,216 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * WaveletProcessingController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.service; - -import cz.zcu.kiv.eegdatabase.data.pojo.DataFile; -import cz.zcu.kiv.eegdatabase.data.pojo.Experiment; -import cz.zcu.kiv.eegdatabase.data.pojo.ServiceResult; -import cz.zcu.kiv.eegdsp.common.ISignalProcessor; -import cz.zcu.kiv.eegdsp.main.SignalProcessingFactory; -import cz.zcu.kiv.eegdsp.wavelet.continuous.WaveletTransformationContinuous; -import cz.zcu.kiv.eegdsp.wavelet.continuous.algorithm.wavelets.WaveletCWT; -import cz.zcu.kiv.eegdsp.wavelet.discrete.WaveletTransformationDiscrete; -import cz.zcu.kiv.eegdsp.wavelet.discrete.algorithm.wavelets.WaveletDWT; -import org.springframework.validation.BindException; -import org.springframework.web.servlet.ModelAndView; - -import javax.imageio.ImageIO; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.awt.*; -import java.awt.geom.Rectangle2D; -import java.awt.image.BufferedImage; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.Map; -import org.hibernate.Hibernate; - - -public class WaveletProcessingController extends AbstractProcessingController { - - private String type; - - public WaveletProcessingController() { - setCommandClass(WaveletCommand.class); - setCommandName("wavelet"); - } - - protected Map referenceData(HttpServletRequest request) throws Exception { - Map map = super.referenceData(request); - String[] names; - if (request.getParameter("type").equals("DWT")) { - ISignalProcessor dwt = SignalProcessingFactory.getInstance().getWaveletDiscrete(); - names = ((WaveletTransformationDiscrete) dwt).getWaveletGenerator().getWaveletNames(); - } else { - ISignalProcessor dwt = SignalProcessingFactory.getInstance().getWaveletContinuous(); - names = ((WaveletTransformationContinuous) dwt).getWaveletGenerator().getWaveletNames(); - } - map.put("wavelets", names); - map.put("type", request.getParameter("type")); - type = request.getParameter("type"); - - return map; - } - - protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception { - WaveletCommand cmd = (WaveletCommand) command; - ModelAndView mav = new ModelAndView(getSuccessView()); - int id = Integer.parseInt(request.getParameter("experimentId")); - Experiment ex = experimentDao.read(id); - byte[] data = null; - for (DataFile dataFile : ex.getDataFiles()) { - int index = dataFile.getFilename().lastIndexOf("."); - if (dataFile.getFilename().substring(0, index).equals(super.fileName)) { - if ((dataFile.getFilename().endsWith(".avg")) || (dataFile.getFilename().endsWith(".eeg"))) { - data = dataFile.getFileContent().getBytes(1, (int)dataFile.getFileContent().length()); - break; - } - } - } - ServiceResult service = new ServiceResult(); - service.setOwner(personDao.getLoggedPerson()); - service.setStatus("running"); - service.setTitle(super.fileName + "_Wavelet"); - service.setFilename(super.fileName + "_WT.png"); - resultDao.create(service); - double signal[] = transformer.readBinaryData(data, cmd.getChannel()); - new WTProcess(type, service, signal, cmd.getWavelet()).start(); - - - return mav; - } - - private class WTProcess extends Thread { - - private String type; - private ServiceResult service; - private double[] signal; - private String wavelet; - private final int MAX_LENGTH = 10240; - - public WTProcess(String type, ServiceResult service, double[] signal, String wavelet) { - this.type = type; - this.service = service; - this.signal = signal; - this.wavelet = wavelet; - } - - public void run() { - ISignalProcessor wt = null; - if (type.equals("CWT")) { - if (signal.length > MAX_LENGTH) { - service.setStatus("failed"); - service.setFilename("errorLog.txt"); - String errorText = "Not enough memory for analysed signal."; - service.setContent(Hibernate.createBlob(errorText.getBytes())); - resultDao.update(service); - return; - } - wt = SignalProcessingFactory.getInstance().getWaveletContinuous(); - WaveletCWT wavelet = ((WaveletTransformationContinuous) wt).getWaveletGenerator().getWaveletByName(this.wavelet); - ((WaveletTransformationContinuous) wt).setWavelet(wavelet); - } else { - wt = SignalProcessingFactory.getInstance().getWaveletDiscrete(); - WaveletDWT wavelet = ((WaveletTransformationDiscrete) wt).getWaveletGenerator().getWaveletByName(this.wavelet); - ((WaveletTransformationDiscrete) wt).setWavelet(wavelet); - } - byte[] image = createImage(wt.processSignal(signal).toHashMap()); - if (image == null) { - service.setStatus("failed"); - service.setFilename("errorLog.txt"); - String errorText = "Error while creating an image."; - service.setContent(Hibernate.createBlob(errorText.getBytes())); - resultDao.update(service); - return; - } - service.setContent(Hibernate.createBlob(image)); - service.setStatus("finished"); - resultDao.update(service); - } - - private byte[] createImage(Map result) { - int width = signal.length; - if (type.equals("DWT")) { - width = 800; - } - int height = 400; - BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); - Graphics2D g2 = img.createGraphics(); - g2.setPaint(Color.BLACK); - g2.fill(new Rectangle2D.Float(0, 0, width, height)); - if (type.equals("DWT")) { - Double[] highest = result.get("highestCoefficients")[0]; - Double[] DWTCoefficients = result.get("dwtCoefficients")[0]; - float xstep; - float ystep = (float) (height / highest.length); - float x; - float y = ystep * highest.length; - int start = DWTCoefficients.length / 2; - int end = DWTCoefficients.length; - int level = 2; - for (int i = highest.length - 1; i >= 0; i--) { - xstep = (float) (width / (DWTCoefficients.length / level)); - x = 0; - for (int j = start; j < end; j++) { - - int color = (int) Math.abs(255 * DWTCoefficients[j] / highest[i]); - g2.setPaint(new Color(color, color, color)); - g2.fill(new Rectangle2D.Float(x, y - ystep, xstep, ystep)); - x += xstep; - } - start /= 2; - end /= 2; - level *= 2; - y -= ystep; - } - } else { - Double[] highest = result.get("highestCoeficients")[0]; - Double[][] CWTReal = result.get("real"); - float xstep; - float ystep = (float) (height / highest.length); - float x; - float y = ystep * highest.length + 1; - for (int i = 0; i < highest.length; i++) { - xstep = (float) (width / CWTReal[i].length); - x = 0; - for (int index = 0; index < CWTReal[i].length; index++) { - double base = Math.abs(CWTReal[i][index] / highest[i]); - int color = (int) (255 * base); - g2.setPaint(new Color(color, color, color)); - g2.fill(new Rectangle2D.Float(x, y - ystep, xstep, ystep)); - x += xstep; - } - y -= ystep; - } - } - - ByteArrayOutputStream out = new ByteArrayOutputStream(); - try { - ImageIO.write(img, "PNG", out); - } catch (IOException e) { - return null; - } - return out.toByteArray(); - } - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/system/ExceptionResolver.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/system/ExceptionResolver.java deleted file mode 100644 index d84511de..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/system/ExceptionResolver.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ExceptionResolver.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.system; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * Extends Spring MVC SimpleMappingExceptionResolver to log all received exceptions - * Created by IntelliJ IDEA. - * User: jnovotny - */ -public class ExceptionResolver extends org.springframework.web.servlet.handler.SimpleMappingExceptionResolver { - private Log log = LogFactory.getLog(getClass()); - - - @Override - protected ModelAndView doResolveException(HttpServletRequest request, HttpServletResponse response, - Object handler, Exception ex) { - - log.warn("An exception occured", ex);//Log the exception - ex.printStackTrace();//Show also in the error output - - return super.doResolveException(request,response,handler,ex); - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/system/GrantPermissionController.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/system/GrantPermissionController.java deleted file mode 100644 index fd735691..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/system/GrantPermissionController.java +++ /dev/null @@ -1,71 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * GrantPermissionController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.controller.system; - -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.web.servlet.ModelAndView; -import org.springframework.web.servlet.mvc.AbstractController; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -/** - * @author JiPER - */ -public class GrantPermissionController extends AbstractController { - - Log log = LogFactory.getLog(getClass()); - private PersonDao personDao; - - @Override - protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { - log.debug("Running controller for granting permission"); - ModelAndView mav = new ModelAndView("system/permissionGranted"); - - log.debug("Loading parameter from database"); - int personId = Integer.parseInt(request.getParameter("id")); - - log.debug("Updating person authority"); - Person person = personDao.read(personId); - person.setAuthority("ROLE_EXPERIMENTER"); - - log.debug("Saving changes to database"); - personDao.update(person); - - mav.addObject("person", person); - - log.debug("Returning MAV"); - return mav; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/delegate/HomePageDelegate.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/delegate/HomePageDelegate.java deleted file mode 100644 index 91e5482b..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/delegate/HomePageDelegate.java +++ /dev/null @@ -1,150 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * HomePageDelegate.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.delegate; - -import cz.zcu.kiv.eegdatabase.data.dao.*; -import cz.zcu.kiv.eegdatabase.data.pojo.Article; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroup; -import cz.zcu.kiv.eegdatabase.data.pojo.ResearchGroupMembership; -import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.List; -import java.util.Set; - -/** - * Delegate class for multicontroller which processes groups section. - * - * @author Jindrich Pergler - */ -public class HomePageDelegate { - - private static final int LIMIT = 5; - private ExperimentDao experimentDao; - private ScenarioDao scenarioDao; - private ResearchGroupDao researchGroupDao; - private PersonDao personDao; - private ArticleDao articleDao; - private AuthorizationManager auth; - - public ModelAndView home(HttpServletRequest request, HttpServletResponse response) { - ModelAndView mav = new ModelAndView("homePage/homePage"); - - if (ControllerUtils.isUserLogged()) { - Person person = personDao.getLoggedPerson(); - - List myExperiments = experimentDao.getExperimentsWhereOwner(person, LIMIT); - mav.addObject("myExperiments", myExperiments); - mav.addObject("myExperimentsEmpty", myExperiments.isEmpty()); - - List meAsSubjectList = experimentDao.getExperimentsWhereSubject(person, LIMIT); - mav.addObject("meAsSubjectList", meAsSubjectList); - mav.addObject("meAsSubjectListEmpty", meAsSubjectList.isEmpty()); - - List myScenarios = scenarioDao.getScenariosWhereOwner(person, LIMIT); - mav.addObject("myScenarios", myScenarios); - mav.addObject("myScenariosEmpty", myScenarios.isEmpty()); - - List list = researchGroupDao.getResearchGroupsWhereMember(person, LIMIT); - mav.addObject("groupList", list); - mav.addObject("groupListEmpty", list.isEmpty()); - - List articles = articleDao.getArticlesForUser(person, LIMIT); - mav.addObject("articleList", articles); - } - return mav; - } - - /** - * Checks if user is admin in any group - * - * @param mav ModelAndView for display - */ - public void setPermissionsToView(ModelAndView mav) { - // isAdmin - Person loggedUser = personDao.getLoggedPerson(); - if (loggedUser.getAuthority().equals("ROLE_ADMIN")) { - mav.addObject("userIsAdminInAnyGroup", true); - return; - } - // check all groups for admin role - Set researchGroupMemberShips = loggedUser.getResearchGroupMemberships(); - for (ResearchGroupMembership member : researchGroupMemberShips) { - if (auth.userIsAdminInGroup(member.getResearchGroup().getResearchGroupId())) { - mav.addObject("userIsAdminInAnyGroup", true); - return; - } - } - } - - public ExperimentDao getExperimentDao() { - return experimentDao; - } - - public void setExperimentDao(ExperimentDao experimentDao) { - this.experimentDao = experimentDao; - } - - public ScenarioDao getScenarioDao() { - return scenarioDao; - } - - public void setScenarioDao(ScenarioDao scenarioDao) { - this.scenarioDao = scenarioDao; - } - - public ResearchGroupDao getResearchGroupDao() { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) { - this.researchGroupDao = researchGroupDao; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public ArticleDao getArticleDao() { - return articleDao; - } - - public void setArticleDao(ArticleDao articleDao) { - this.articleDao = articleDao; - } - - public AuthorizationManager getAuth() { - return auth; - } - - public void setAuth(AuthorizationManager auth) { - this.auth = auth; - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/delegate/MyAccountDelegate.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/delegate/MyAccountDelegate.java deleted file mode 100644 index 1d640ba0..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/delegate/MyAccountDelegate.java +++ /dev/null @@ -1,96 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * MyAccountDelegate.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.logic.delegate; - -import cz.zcu.kiv.eegdatabase.data.dao.PersonDao; -import cz.zcu.kiv.eegdatabase.data.dao.ResearchGroupDao; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import org.springframework.web.servlet.ModelAndView; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.util.List; -import java.util.Map; - -/** - * Delegate class for multicontroller which processes My account section. - * - * @author Jindrich Pergler - */ -public class MyAccountDelegate { - - private ResearchGroupDao researchGroupDao; - private PersonDao personDao; - - public ResearchGroupDao getResearchGroupDao() { - return researchGroupDao; - } - - public void setResearchGroupDao(ResearchGroupDao researchGroupDao) { - this.researchGroupDao = researchGroupDao; - } - - public PersonDao getPersonDao() { - return personDao; - } - - public void setPersonDao(PersonDao personDao) { - this.personDao = personDao; - } - - public ModelAndView overview(HttpServletRequest request, HttpServletResponse response) { - ModelAndView mav = new ModelAndView("myAccount/overview"); - - Map userInfo = personDao.getInfoForAccountOverview(personDao.getLoggedPerson()); - mav.addObject("userInfo", userInfo); - - Person person = personDao.getLoggedPerson(); - mav.addObject("facebookConnected", (person.getFacebookId() != null)); - mav.addObject("userFacebookId", person.getFacebookId()); - - List list = researchGroupDao.getGroupDataForAccountOverview(personDao.getLoggedPerson()); - mav.addObject("membershipList", list); - mav.addObject("membershipListEmpty", list.isEmpty()); - setUserIsInAnyGroup(mav,personDao.getLoggedPerson()); - return mav; - } - - public ModelAndView status(HttpServletRequest request, HttpServletResponse response) { - ModelAndView mav = new ModelAndView("redirect:/connect.html"); - - - return mav; - } - - public static void setUserIsInAnyGroup(ModelAndView mav, Person loggedUser) { - if(!loggedUser.getResearchGroupMemberships().isEmpty()){ - mav.addObject("userIsInAnyGroup", true); - } - } - - public static void setUserIsInAnyGroup(Map map, Person loggedUser) { - if(!loggedUser.getResearchGroupMemberships().isEmpty()){ - map.put("userIsInAnyGroup", true); - } - } -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/SearchRequest.java b/src/main/java/cz/zcu/kiv/eegdatabase/logic/search/SearchRequest.java similarity index 97% rename from src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/SearchRequest.java rename to src/main/java/cz/zcu/kiv/eegdatabase/logic/search/SearchRequest.java index 7cc71acc..f587e598 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/logic/controller/search/SearchRequest.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/logic/search/SearchRequest.java @@ -25,7 +25,7 @@ * and open the template in the editor. */ -package cz.zcu.kiv.eegdatabase.logic.controller.search; +package cz.zcu.kiv.eegdatabase.logic.search; /** * @author Honza diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/view/DownloadMetadataZipView.java b/src/main/java/cz/zcu/kiv/eegdatabase/view/DownloadMetadataZipView.java deleted file mode 100644 index b54aeea4..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/view/DownloadMetadataZipView.java +++ /dev/null @@ -1,76 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * DownloadMetadataZipView.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -/* - * To change this template, choose Tools | Templates - * and open the template in the editor. - */ - -package cz.zcu.kiv.eegdatabase.view; -import cz.zcu.kiv.eegdatabase.data.pojo.Experiment; -import cz.zcu.kiv.eegdatabase.logic.zip.Generator; -import java.io.ByteArrayOutputStream; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.springframework.web.servlet.view.AbstractView; -/** - * - * @author Jan Štěbeták - */ -public class DownloadMetadataZipView extends AbstractView{ - - private Generator zipGenerator; - - @Override - protected void renderMergedOutputModel(Map map, HttpServletRequest request, HttpServletResponse response) throws Exception { - Experiment meas = (Experiment) map.get("dataObject"); - List meases = new ArrayList(); - meases.add(meas); -// OutputStream out = getZipGenerator().generate(meases, true); -// ByteArrayOutputStream bout = null; -// response.setHeader("Content-Type", "application/zip"); -// if (out instanceof ByteArrayOutputStream) { -// bout = (ByteArrayOutputStream) out; -// response.getOutputStream().write(bout.toByteArray()); -// } - } - - /** - * @return the zipGenerator - */ - public Generator getZipGenerator() { - return zipGenerator; - } - - /** - * @param zipGenerator the zipGenerator to set - */ - public void setZipGenerator(Generator zipGenerator) { - this.zipGenerator = zipGenerator; - } - - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/view/MeasurationDataView.java b/src/main/java/cz/zcu/kiv/eegdatabase/view/MeasurationDataView.java deleted file mode 100644 index c5e0827f..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/view/MeasurationDataView.java +++ /dev/null @@ -1,65 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * MeasurationDataView.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.view; - -import java.sql.Blob; -import java.util.Map; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.web.servlet.view.AbstractView; -import cz.zcu.kiv.eegdatabase.data.pojo.DataFile; - -/** - * This view serves for downloading the data files. - * - * @author Jindra - */ -public class MeasurationDataView extends AbstractView { - Log log = LogFactory.getLog(getClass()); - - @Override - protected void renderMergedOutputModel(Map map, HttpServletRequest request, HttpServletResponse response) throws Exception { - // Loading the DataFile object loaded by Controller - DataFile data = (DataFile) map.get("dataObject"); - byte[] b = data.getFileContent().getBytes(1, (int)data.getFileContent().length()); - log.debug("Loading Data object - ID " + data.getDataFileId()); - - /** Downloading the bytes for writing to output */ - - // Setting the content type, so the download dialog opens and user is able to download data file - /* TODO: load the original MIME type from database when the POJO object is ready */ - log.debug("Data MIME type is: " + data.getMimetype()); - response.setHeader("Content-Type", data.getMimetype()); - - // Setting the original filename - /* TODO: load the original filename from database when the POJO object is ready */ - log.debug("Data filename is: " + data.getFilename()); - response.setHeader("Content-Disposition", "attachment;filename=" + data.getFilename()); - - // Writing the bytes to the output stream - response.getOutputStream().write(b); - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/view/ScenarioXMLDownloadView.java b/src/main/java/cz/zcu/kiv/eegdatabase/view/ScenarioXMLDownloadView.java deleted file mode 100644 index 952b130d..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/view/ScenarioXMLDownloadView.java +++ /dev/null @@ -1,59 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * ScenarioXMLDownloadView.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.view; - -import java.sql.Blob; -import java.util.Map; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.web.servlet.view.AbstractView; -import cz.zcu.kiv.eegdatabase.data.pojo.Scenario; - -/** - * This view serves for downloading the data files. - * - * @author Jindra - */ -public class ScenarioXMLDownloadView extends AbstractView { - Log log = LogFactory.getLog(getClass()); - - @Override - protected void renderMergedOutputModel(Map map, HttpServletRequest request, HttpServletResponse response) throws Exception { - log.debug("Processing view for scenario XML output"); - - Scenario scenario = (Scenario) map.get("dataObject"); - - log.debug("Loading Scenario object - ID " + scenario.getScenarioId()); - - log.debug("Setting MIME to XML"); - response.setHeader("Content-Type", "text/xml"); - - log.debug("Setting filename"); - response.setHeader("Content-Disposition", "attachment;filename=scenario-" + scenario.getScenarioId()); - - log.debug("End of the view"); - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/view/controller/LoggedUserController.java b/src/main/java/cz/zcu/kiv/eegdatabase/view/controller/LoggedUserController.java deleted file mode 100644 index 2851d57d..00000000 --- a/src/main/java/cz/zcu/kiv/eegdatabase/view/controller/LoggedUserController.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * This file is part of the EEG-database project - * - * ========================================== - * - * Copyright (C) 2013 by University of West Bohemia (http://www.zcu.cz/en/) - * - * *********************************************************************************************************************** - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on - * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the - * specific language governing permissions and limitations under the License. - * - * *********************************************************************************************************************** - * - * LoggedUserController.java, 2013/10/02 00:01 Jakub Rinkes - ******************************************************************************/ -package cz.zcu.kiv.eegdatabase.view.controller; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import org.apache.struts.tiles.ComponentContext; -import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.security.core.userdetails.UserDetails; -import org.springframework.web.servlet.view.tiles.ComponentControllerSupport; - -/** - * - * @author JiPER - */ -public class LoggedUserController extends ComponentControllerSupport { - - @Override - protected void doPerform(ComponentContext context, HttpServletRequest request, HttpServletResponse response) throws Exception { - Object o = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); - String userName = null; - if (o instanceof UserDetails) { - userName = ((UserDetails) o).getUsername(); - } else { - userName = o.toString(); - } - context.putAttribute("loggedUserName", userName); - } - -} diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/ExperimentsFacade.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/ExperimentsFacade.java index ea3648de..7acdfec8 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/ExperimentsFacade.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/ExperimentsFacade.java @@ -22,16 +22,12 @@ ******************************************************************************/ package cz.zcu.kiv.eegdatabase.wui.core.experiments; -import java.util.List; - -import cz.zcu.kiv.eegdatabase.data.pojo.DataFile; -import cz.zcu.kiv.eegdatabase.data.pojo.Experiment; -import cz.zcu.kiv.eegdatabase.data.pojo.ExperimentPackage; -import cz.zcu.kiv.eegdatabase.data.pojo.License; -import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; +import cz.zcu.kiv.eegdatabase.data.pojo.*; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; import cz.zcu.kiv.eegdatabase.wui.core.GenericFacade; +import java.util.List; + public interface ExperimentsFacade extends GenericFacade { Experiment getExperimentForDetail(int experimentId); @@ -73,7 +69,6 @@ public interface ExperimentsFacade extends GenericFacade { /** * Returns list of experiments that are not members of the given package. - * @param packageId id of the package * @return list of experiments or empty list */ List getExperimentsWithoutPackage(ExperimentPackage pckg); diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/ExperimentsFacadeImpl.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/ExperimentsFacadeImpl.java index 5eddb0f9..fc3ca3e4 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/ExperimentsFacadeImpl.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/ExperimentsFacadeImpl.java @@ -27,7 +27,7 @@ import cz.zcu.kiv.eegdatabase.data.pojo.ExperimentPackage; import cz.zcu.kiv.eegdatabase.data.pojo.License; import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/ExperimentsService.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/ExperimentsService.java index 4c473070..1590b533 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/ExperimentsService.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/ExperimentsService.java @@ -26,7 +26,7 @@ import cz.zcu.kiv.eegdatabase.data.pojo.Experiment; import cz.zcu.kiv.eegdatabase.data.pojo.License; import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; import cz.zcu.kiv.eegdatabase.wui.core.GenericService; import java.util.List; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/ExperimentsServiceImpl.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/ExperimentsServiceImpl.java index beb5ad42..9e32a61c 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/ExperimentsServiceImpl.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/experiments/ExperimentsServiceImpl.java @@ -31,7 +31,7 @@ import cz.zcu.kiv.eegdatabase.data.dao.*; import cz.zcu.kiv.eegdatabase.data.pojo.*; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; public class ExperimentsServiceImpl implements ExperimentsService { diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/history/HistoryFacade.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/history/HistoryFacade.java index 017289aa..ec4defed 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/history/HistoryFacade.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/history/HistoryFacade.java @@ -22,14 +22,14 @@ ******************************************************************************/ package cz.zcu.kiv.eegdatabase.wui.core.history; -import java.util.List; - import cz.zcu.kiv.eegdatabase.data.pojo.History; import cz.zcu.kiv.eegdatabase.logic.controller.history.ChoiceHistory; import cz.zcu.kiv.eegdatabase.logic.controller.history.DownloadStatistic; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; import cz.zcu.kiv.eegdatabase.wui.core.GenericFacade; +import java.util.List; + public interface HistoryFacade extends GenericFacade{ List getHistory(ChoiceHistory historyType, boolean isGroupAdmin, int groupId); diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/history/HistoryFacadeImpl.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/history/HistoryFacadeImpl.java index 2c586a31..f2cf1fbd 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/history/HistoryFacadeImpl.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/history/HistoryFacadeImpl.java @@ -25,7 +25,7 @@ import cz.zcu.kiv.eegdatabase.data.pojo.History; import cz.zcu.kiv.eegdatabase.logic.controller.history.ChoiceHistory; import cz.zcu.kiv.eegdatabase.logic.controller.history.DownloadStatistic; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; import org.springframework.beans.factory.annotation.Required; import java.util.List; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/history/HistoryService.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/history/HistoryService.java index c70d560f..7101dbe1 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/history/HistoryService.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/history/HistoryService.java @@ -27,7 +27,7 @@ import cz.zcu.kiv.eegdatabase.data.pojo.History; import cz.zcu.kiv.eegdatabase.logic.controller.history.ChoiceHistory; import cz.zcu.kiv.eegdatabase.logic.controller.history.DownloadStatistic; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; import cz.zcu.kiv.eegdatabase.wui.core.GenericService; public interface HistoryService extends GenericService { diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/history/HistoryServiceImpl.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/history/HistoryServiceImpl.java index 1cf6aa8d..b913f085 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/history/HistoryServiceImpl.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/history/HistoryServiceImpl.java @@ -26,7 +26,7 @@ import cz.zcu.kiv.eegdatabase.data.pojo.History; import cz.zcu.kiv.eegdatabase.logic.controller.history.ChoiceHistory; import cz.zcu.kiv.eegdatabase.logic.controller.history.DownloadStatistic; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; import org.springframework.beans.factory.annotation.Required; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/person/PersonFacade.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/person/PersonFacade.java index b735d2e5..c9d25521 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/person/PersonFacade.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/person/PersonFacade.java @@ -26,7 +26,7 @@ import java.util.Map; import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; import cz.zcu.kiv.eegdatabase.wui.core.GenericFacade; public interface PersonFacade extends GenericFacade { diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/person/PersonFacadeImpl.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/person/PersonFacadeImpl.java index 08105e0c..f76fb134 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/person/PersonFacadeImpl.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/person/PersonFacadeImpl.java @@ -23,7 +23,7 @@ package cz.zcu.kiv.eegdatabase.wui.core.person; import cz.zcu.kiv.eegdatabase.data.pojo.Person; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.annotation.Required; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/person/PersonService.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/person/PersonService.java index 3de63555..6dbded41 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/person/PersonService.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/person/PersonService.java @@ -28,7 +28,7 @@ import cz.zcu.kiv.eegdatabase.data.pojo.Person; import cz.zcu.kiv.eegdatabase.logic.controller.person.AddPersonCommand; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; import cz.zcu.kiv.eegdatabase.logic.controller.social.SocialUser; import cz.zcu.kiv.eegdatabase.wui.core.GenericService; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/person/PersonServiceImpl.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/person/PersonServiceImpl.java index b7d3dc54..51475eb3 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/person/PersonServiceImpl.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/person/PersonServiceImpl.java @@ -29,7 +29,7 @@ import cz.zcu.kiv.eegdatabase.data.service.MailService; import cz.zcu.kiv.eegdatabase.logic.Util; import cz.zcu.kiv.eegdatabase.logic.controller.person.AddPersonCommand; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; import cz.zcu.kiv.eegdatabase.logic.controller.social.SocialUser; import cz.zcu.kiv.eegdatabase.logic.util.ControllerUtils; import org.apache.commons.logging.Log; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/scenarios/ScenariosFacade.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/scenarios/ScenariosFacade.java index 13e1ebf4..426f0d4e 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/scenarios/ScenariosFacade.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/scenarios/ScenariosFacade.java @@ -32,7 +32,7 @@ import cz.zcu.kiv.eegdatabase.data.pojo.Person; import cz.zcu.kiv.eegdatabase.data.pojo.Scenario; import cz.zcu.kiv.eegdatabase.data.pojo.ScenarioSchemas; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; import cz.zcu.kiv.eegdatabase.wui.core.GenericFacade; import cz.zcu.kiv.eegdatabase.wui.core.file.FileDTO; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/scenarios/ScenariosFacadeImpl.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/scenarios/ScenariosFacadeImpl.java index 029ebb48..a4952ea9 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/scenarios/ScenariosFacadeImpl.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/scenarios/ScenariosFacadeImpl.java @@ -36,7 +36,7 @@ import cz.zcu.kiv.eegdatabase.data.pojo.Person; import cz.zcu.kiv.eegdatabase.data.pojo.Scenario; import cz.zcu.kiv.eegdatabase.data.pojo.ScenarioSchemas; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; import cz.zcu.kiv.eegdatabase.wui.core.file.FileDTO; public class ScenariosFacadeImpl implements ScenariosFacade { diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/scenarios/ScenariosService.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/scenarios/ScenariosService.java index d4d2130f..ea5aa7f9 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/scenarios/ScenariosService.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/scenarios/ScenariosService.java @@ -32,7 +32,7 @@ import cz.zcu.kiv.eegdatabase.data.pojo.Person; import cz.zcu.kiv.eegdatabase.data.pojo.Scenario; import cz.zcu.kiv.eegdatabase.data.pojo.ScenarioSchemas; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; import cz.zcu.kiv.eegdatabase.wui.core.GenericService; import cz.zcu.kiv.eegdatabase.wui.core.file.FileDTO; diff --git a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/scenarios/ScenariosServiceImpl.java b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/scenarios/ScenariosServiceImpl.java index 859222e5..b708ec98 100644 --- a/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/scenarios/ScenariosServiceImpl.java +++ b/src/main/java/cz/zcu/kiv/eegdatabase/wui/core/scenarios/ScenariosServiceImpl.java @@ -48,7 +48,7 @@ import cz.zcu.kiv.eegdatabase.data.pojo.Person; import cz.zcu.kiv.eegdatabase.data.pojo.Scenario; import cz.zcu.kiv.eegdatabase.data.pojo.ScenarioSchemas; -import cz.zcu.kiv.eegdatabase.logic.controller.search.SearchRequest; +import cz.zcu.kiv.eegdatabase.logic.search.SearchRequest; import cz.zcu.kiv.eegdatabase.wui.core.file.FileDTO; public class ScenariosServiceImpl implements ScenariosService { diff --git a/src/main/webapp/WEB-INF/dispatcher-servlet.xml b/src/main/webapp/WEB-INF/dispatcher-servlet.xml index ed005b0e..2290def3 100644 --- a/src/main/webapp/WEB-INF/dispatcher-servlet.xml +++ b/src/main/webapp/WEB-INF/dispatcher-servlet.xml @@ -33,16 +33,16 @@ - - - - + + + + - + - + - +