From 0d16d694fae23c7c7fd808db57b4f1e023c711ee Mon Sep 17 00:00:00 2001 From: ikalyvas Date: Tue, 5 Mar 2019 17:33:59 +0200 Subject: [PATCH 1/2] Refactors dependency injection on backend services --- .../main/java/eu/eudat/controllers/Admin.java | 182 +++++++++--------- .../controllers/DMPProfileController.java | 10 +- .../main/java/eu/eudat/controllers/DMPs.java | 24 +-- .../controllers/DashBoardController.java | 16 +- .../eudat/controllers/DataRepositories.java | 2 +- .../controllers/DatasetProfileController.java | 2 +- .../eu/eudat/controllers/DatasetProfiles.java | 4 +- .../controllers/DatasetWizardController.java | 16 +- .../java/eu/eudat/controllers/Datasets.java | 4 +- .../eudat/controllers/ExternalDatasets.java | 8 +- .../eu/eudat/controllers/FileController.java | 8 +- .../main/java/eu/eudat/controllers/Login.java | 7 +- .../java/eu/eudat/controllers/Projects.java | 12 +- .../controllers/QuickWizardController.java | 21 +- .../java/eu/eudat/controllers/Registries.java | 2 +- .../eu/eudat/controllers/Researchers.java | 13 +- .../java/eu/eudat/controllers/Services.java | 42 ++-- .../eu/eudat/controllers/TagController.java | 8 - .../controllers/UserInvitationController.java | 10 +- .../main/java/eu/eudat/controllers/Users.java | 12 +- .../logic/managers/DashBoardManager.java | 36 +++- .../managers/DataManagementPlanManager.java | 56 ++++-- .../DataManagementProfileManager.java | 23 ++- .../logic/managers/DataRepositoryManager.java | 10 +- .../eudat/logic/managers/DatasetManager.java | 77 +++++--- .../logic/managers/DatasetProfileManager.java | 22 ++- .../eudat/logic/managers/DocumentManager.java | 16 +- .../managers/ExternalDatasetManager.java | 22 ++- .../eu/eudat/logic/managers/FileManager.java | 14 +- .../logic/managers/InvitationsManager.java | 17 +- .../eudat/logic/managers/ProjectManager.java | 39 ++-- .../logic/managers/QuickWizardManager.java | 68 ++++--- .../eudat/logic/managers/RegistryManager.java | 14 +- .../logic/managers/ResearcherManager.java | 14 +- .../eudat/logic/managers/ServiceManager.java | 13 +- .../eu/eudat/logic/managers/UserManager.java | 23 ++- 36 files changed, 525 insertions(+), 342 deletions(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java index e73c7423b..eed7ad863 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java @@ -34,106 +34,108 @@ import static eu.eudat.types.Authorities.ADMIN; @RequestMapping(value = {"/api/admin/"}) public class Admin extends BaseController { - DatasetProfileManager datasetProfileManager; + private DatasetProfileManager datasetProfileManager; + private UserManager userManager; - @Autowired - public Admin(ApiContext apiContext, DatasetProfileManager datasetProfileManager, Logger logger) { - super(apiContext); - this.datasetProfileManager = datasetProfileManager; - } + @Autowired + public Admin(ApiContext apiContext, DatasetProfileManager datasetProfileManager, UserManager userManager, Logger logger) { + super(apiContext); + this.datasetProfileManager = datasetProfileManager; + this.userManager = userManager; + } - @Transactional - @RequestMapping(method = RequestMethod.POST, value = {"/addDmp"}, consumes = "application/json", produces = "application/json") - public ResponseEntity addDmp(@Valid @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { - //this.getLoggerService().info(principal, "Admin Added Dataset Profile"); - DatasetProfile shortenProfile = profile.toShort(); - eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext()); - this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition); - return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId()); - } + @Transactional + @RequestMapping(method = RequestMethod.POST, value = {"/addDmp"}, consumes = "application/json", produces = "application/json") + public ResponseEntity addDmp(@Valid @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { + //this.getLoggerService().info(principal, "Admin Added Dataset Profile"); + DatasetProfile shortenProfile = profile.toShort(); + eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext()); + this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition); + return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId()); + } - @Transactional - @RequestMapping(method = RequestMethod.POST, value = {"/addDmp/{id}"}, consumes = "application/json", produces = "application/json") - public ResponseEntity> updateDmp(@PathVariable String id, @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { - DatasetProfile shortenProfile = profile.toShort(); - eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext()); - eu.eudat.data.entities.DatasetProfile datasetprofile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); - datasetprofile.setDefinition(modelDefinition.getDefinition()); - datasetprofile.setStatus(modelDefinition.getStatus()); - datasetprofile.setLabel(modelDefinition.getLabel()); - this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(datasetprofile); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE)); - } + @Transactional + @RequestMapping(method = RequestMethod.POST, value = {"/addDmp/{id}"}, consumes = "application/json", produces = "application/json") + public ResponseEntity> updateDmp(@PathVariable String id, @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { + DatasetProfile shortenProfile = profile.toShort(); + eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(shortenProfile, getApiContext()); + eu.eudat.data.entities.DatasetProfile datasetprofile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); + datasetprofile.setDefinition(modelDefinition.getDefinition()); + datasetprofile.setStatus(modelDefinition.getStatus()); + datasetprofile.setLabel(modelDefinition.getLabel()); + this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(datasetprofile); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE)); + } - @RequestMapping(method = RequestMethod.GET, value = {"/get/{id}"}, produces = "application/json") - public ResponseEntity> get(@PathVariable String id, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { - eu.eudat.data.entities.DatasetProfile profile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); - eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile); - datasetprofile.setLabel(profile.getLabel()); - datasetprofile.setStatus(profile.getStatus()); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(datasetprofile)); - } + @RequestMapping(method = RequestMethod.GET, value = {"/get/{id}"}, produces = "application/json") + public ResponseEntity> get(@PathVariable String id, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { + eu.eudat.data.entities.DatasetProfile profile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); + eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile); + datasetprofile.setLabel(profile.getLabel()); + datasetprofile.setStatus(profile.getStatus()); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(datasetprofile)); + } - @RequestMapping(method = RequestMethod.POST, value = {"/datasetprofiles/getPaged"}, produces = "application/json") - public @ResponseBody - ResponseEntity>> getPaged(@RequestBody DatasetProfileTableRequestItem datasetProfileTableRequestItem, Principal principal) throws Exception { - DataTableData datasetProfileTableData = this.datasetProfileManager.getPaged(this.getApiContext(), datasetProfileTableRequestItem); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileTableData)); - } + @RequestMapping(method = RequestMethod.POST, value = {"/datasetprofiles/getPaged"}, produces = "application/json") + public @ResponseBody + ResponseEntity>> getPaged(@RequestBody DatasetProfileTableRequestItem datasetProfileTableRequestItem, Principal principal) throws Exception { + DataTableData datasetProfileTableData = this.datasetProfileManager.getPaged(datasetProfileTableRequestItem); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileTableData)); + } - @RequestMapping(method = RequestMethod.POST, value = {"/preview"}, consumes = "application/json", produces = "application/json") - public ResponseEntity> getPreview(@RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { - eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(profile, getApiContext()); - eu.eudat.models.data.user.composite.DatasetProfile datasetProfile = UserManager.generateDatasetProfileModel(modelDefinition); - PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile(); - pagedDatasetProfile.buildPagedDatasetProfile(datasetProfile); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(pagedDatasetProfile)); - } + @RequestMapping(method = RequestMethod.POST, value = {"/preview"}, consumes = "application/json", produces = "application/json") + public ResponseEntity> getPreview(@RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { + eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(profile, getApiContext()); + eu.eudat.models.data.user.composite.DatasetProfile datasetProfile = userManager.generateDatasetProfileModel(modelDefinition); + PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile(); + pagedDatasetProfile.buildPagedDatasetProfile(datasetProfile); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(pagedDatasetProfile)); + } - @org.springframework.transaction.annotation.Transactional - @RequestMapping(method = RequestMethod.POST, value = {"/datasetprofile/clone/{id}"}, consumes = "application/json", produces = "application/json") - public ResponseEntity> clone(@PathVariable String id, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { - eu.eudat.data.entities.DatasetProfile profile = this.datasetProfileManager.clone(this.getApiContext(), id); - eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile); - datasetprofile.setLabel(profile.getLabel() + " new "); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().payload(datasetprofile)); - } + @org.springframework.transaction.annotation.Transactional + @RequestMapping(method = RequestMethod.POST, value = {"/datasetprofile/clone/{id}"}, consumes = "application/json", produces = "application/json") + public ResponseEntity> clone(@PathVariable String id, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { + eu.eudat.data.entities.DatasetProfile profile = this.datasetProfileManager.clone(id); + eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile); + datasetprofile.setLabel(profile.getLabel() + " new "); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().payload(datasetprofile)); + } - @Transactional - @RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json") - public @ResponseBody - ResponseEntity> inactivate(@PathVariable String id, Principal principal){ - try { - eu.eudat.data.entities.DatasetProfile ret = AdminManager.inactivate(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), id); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE)); - } catch (DatasetProfileWithDatasetsExeption exception) { - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.UNSUCCESS_DELETE).message(exception.getMessage())); - } - } + @Transactional + @RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json") + public @ResponseBody + ResponseEntity> inactivate(@PathVariable String id, Principal principal) { + try { + eu.eudat.data.entities.DatasetProfile ret = AdminManager.inactivate(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), id); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE)); + } catch (DatasetProfileWithDatasetsExeption exception) { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.UNSUCCESS_DELETE).message(exception.getMessage())); + } + } - @Transactional - @RequestMapping(method = RequestMethod.GET, value = {"/getXml/{id}"}, produces = "application/json") - public ResponseEntity getDatasetProfileXml(@PathVariable String id, @RequestHeader("Content-Type") String contentType, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws IllegalAccessException, IOException, InstantiationException { - if (contentType.equals("application/xml")) { - eu.eudat.data.entities.DatasetProfile profile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); - eu.eudat.models.data.user.composite.DatasetProfile datasetProfile = UserManager.generateDatasetProfileModel(profile); - datasetProfile.setStatus(profile.getStatus()); - return this.datasetProfileManager.getDocument(datasetProfile, profile.getLabel()); - } else { - return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message("NOT AUTHORIZE")); - } - } + @Transactional + @RequestMapping(method = RequestMethod.GET, value = {"/getXml/{id}"}, produces = "application/json") + public ResponseEntity getDatasetProfileXml(@PathVariable String id, @RequestHeader("Content-Type") String contentType, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws IllegalAccessException, IOException, InstantiationException { + if (contentType.equals("application/xml")) { + eu.eudat.data.entities.DatasetProfile profile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); + eu.eudat.models.data.user.composite.DatasetProfile datasetProfile = userManager.generateDatasetProfileModel(profile); + datasetProfile.setStatus(profile.getStatus()); + return this.datasetProfileManager.getDocument(datasetProfile, profile.getLabel()); + } else { + return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message("NOT AUTHORIZE")); + } + } - @RequestMapping(method = RequestMethod.POST, value = {"/upload"}) - public ResponseEntity setDatasetProfileXml(@RequestParam("file") MultipartFile file, - @ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws IllegalAccessException, IOException { - eu.eudat.logic.utilities.documents.xml.datasetProfileXml.datasetProfileModel.DatasetProfile datasetProfileModel = this.datasetProfileManager.createDatasetProfileFromXml(file); - eu.eudat.models.data.admin.composite.DatasetProfile datasetProfileEntity = datasetProfileModel.toAdminCompositeModel(file.getOriginalFilename()); - eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(datasetProfileEntity, getApiContext()); - this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>() - .status(ApiMessageCode.SUCCESS_MESSAGE).message("")); - } + @RequestMapping(method = RequestMethod.POST, value = {"/upload"}) + public ResponseEntity setDatasetProfileXml(@RequestParam("file") MultipartFile file, + @ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws IllegalAccessException, IOException { + eu.eudat.logic.utilities.documents.xml.datasetProfileXml.datasetProfileModel.DatasetProfile datasetProfileModel = this.datasetProfileManager.createDatasetProfileFromXml(file); + eu.eudat.models.data.admin.composite.DatasetProfile datasetProfileEntity = datasetProfileModel.toAdminCompositeModel(file.getOriginalFilename()); + eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(datasetProfileEntity, getApiContext()); + this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>() + .status(ApiMessageCode.SUCCESS_MESSAGE).message("")); + } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPProfileController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPProfileController.java index 60e9d5213..1214ac615 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPProfileController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPProfileController.java @@ -45,21 +45,21 @@ public class DMPProfileController extends BaseController { @RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> createOrUpdate(@RequestBody DataManagementPlanProfileListingModel dataManagementPlan, Principal principal) throws Exception { - this.dataManagementProfileManager.createOrUpdate(this.getApiContext(), dataManagementPlan, principal); + this.dataManagementProfileManager.createOrUpdate(dataManagementPlan, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created")); } @RequestMapping(method = RequestMethod.GET, value = {"/getSingle/{id}"}, produces = "application/json") public @ResponseBody ResponseEntity> getSingle(@PathVariable String id, Principal principal) throws IllegalAccessException, InstantiationException { - DataManagementPlanProfileListingModel dataManagementPlanProfileListingModel = this.dataManagementProfileManager.getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpProfileDao(), id, principal); + DataManagementPlanProfileListingModel dataManagementPlanProfileListingModel = this.dataManagementProfileManager.getSingle(id, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlanProfileListingModel)); } @RequestMapping(method = RequestMethod.POST, value = {"/getPaged"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity>> getPaged(@Valid @RequestBody DataManagementPlanProfileTableRequest dataManagementPlanProfileTableRequest, Principal principal) throws Exception { - DataTableData dataTable = this.dataManagementProfileManager.getPaged(this.getApiContext(), dataManagementPlanProfileTableRequest, principal); + DataTableData dataTable = this.dataManagementProfileManager.getPaged(dataManagementPlanProfileTableRequest, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable)); } @@ -67,7 +67,7 @@ public class DMPProfileController extends BaseController { public @ResponseBody ResponseEntity getXml( @RequestHeader("Content-Type") String contentType, @PathVariable String id, Principal principal) throws IllegalAccessException, InstantiationException, IOException { if (contentType.equals("application/xml")) { - DataManagementPlanProfileListingModel dataManagementPlanProfileListingModel = this.dataManagementProfileManager.getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpProfileDao(), id, principal); + DataManagementPlanProfileListingModel dataManagementPlanProfileListingModel = this.dataManagementProfileManager.getSingle(id, principal); return this.dataManagementProfileManager.getDocument(dataManagementPlanProfileListingModel,dataManagementPlanProfileListingModel.getLabel()); }else { return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message("NOT AUTHORIZE")); @@ -79,7 +79,7 @@ public class DMPProfileController extends BaseController { @ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws IllegalAccessException,IOException,Exception{ eu.eudat.logic.utilities.documents.xml.dmpXml.dmpProfileModel.DmpProfile dmpProfileModel = this.dataManagementProfileManager.createDmpProfileFromXml(file); DataManagementPlanProfileListingModel dataManagementPlan = dmpProfileModel.toDmpProfileCompositeModel(file.getOriginalFilename()); - this.dataManagementProfileManager.createOrUpdate(this.getApiContext(), dataManagementPlan, principal); + this.dataManagementProfileManager.createOrUpdate(dataManagementPlan, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>() .status(ApiMessageCode.SUCCESS_MESSAGE).message("")); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java index 3f39bd5fd..770550796 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DMPs.java @@ -49,27 +49,29 @@ public class DMPs extends BaseController { private DynamicProjectConfiguration dynamicProjectConfiguration; private Environment environment; private DataManagementPlanManager dataManagementPlanManager; - + private DatasetManager datasetManager; @Autowired - public DMPs(ApiContext apiContext, DynamicProjectConfiguration dynamicProjectConfiguration, Environment environment, DataManagementPlanManager dataManagementPlanManager) { + public DMPs(ApiContext apiContext, DynamicProjectConfiguration dynamicProjectConfiguration, Environment environment, + DataManagementPlanManager dataManagementPlanManager, DatasetManager datasetManager) { super(apiContext); this.dynamicProjectConfiguration = dynamicProjectConfiguration; this.environment = environment; this.dataManagementPlanManager = dataManagementPlanManager; + this.datasetManager = datasetManager; } @Transactional @RequestMapping(method = RequestMethod.GET, value = {"{id}/unlock"}, produces = "application/json") public @ResponseBody ResponseEntity> unlock(@PathVariable(value = "id") UUID id, Principal principal) throws Exception { - this.dataManagementPlanManager.unlock(this.getApiContext(), id); + this.dataManagementPlanManager.unlock(id); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Unlocked")); } @RequestMapping(method = RequestMethod.POST, value = {"/paged"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity>> getPaged(@Valid @RequestBody DataManagementPlanTableRequest dataManagementPlanTableRequest,@RequestParam String fieldsGroup, Principal principal) throws Exception { - DataTableData dataTable = this.dataManagementPlanManager.getPaged(this.getApiContext(), dataManagementPlanTableRequest, principal, fieldsGroup); + DataTableData dataTable = this.dataManagementPlanManager.getPaged(dataManagementPlanTableRequest, principal, fieldsGroup); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable)); } @@ -79,11 +81,11 @@ public class DMPs extends BaseController { if(contentType.equals("application/xml") || contentType.equals("application/msword")){ DMPDao dmpDao = this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(); VisibilityRuleService visibilityRuleService = this.getApiContext().getUtilitiesService().getVisibilityRuleService(); - ResponseEntity document = this.dataManagementPlanManager.getDocument(this.environment, dmpDao, id, visibilityRuleService, contentType); + ResponseEntity document = this.dataManagementPlanManager.getDocument(id, contentType); return document; } else{ - eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, principal, this.dynamicProjectConfiguration); + eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSingle(id, principal, this.dynamicProjectConfiguration); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan)); } } @@ -99,14 +101,14 @@ public class DMPs extends BaseController { @RequestMapping(method = RequestMethod.POST, value = {"/new/{id}"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> newVersion(@PathVariable UUID id, @Valid @RequestBody eu.eudat.models.data.dmp.DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception { - this.dataManagementPlanManager.newVersion(this.getApiContext(), id, dataManagementPlan, principal); + this.dataManagementPlanManager.newVersion(id, dataManagementPlan, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE)); } @RequestMapping(method = RequestMethod.POST, value = {"/clone/{id}"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> clone(@PathVariable UUID id, @RequestBody eu.eudat.models.data.dmp.DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception { - this.dataManagementPlanManager.clone(this.getApiContext(), id, dataManagementPlan, principal); + this.dataManagementPlanManager.clone(id, dataManagementPlan, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE)); } @@ -115,7 +117,7 @@ public class DMPs extends BaseController { public @ResponseBody ResponseEntity> delete(@PathVariable UUID id, Principal principal) { try{ - this.dataManagementPlanManager.delete(this.getApiContext(), id); + this.dataManagementPlanManager.delete(id); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Deleted Datamanagement Plan")); }catch (DMPWithDatasetsDeleteException exception){ return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(exception.getMessage())); @@ -153,8 +155,8 @@ public class DMPs extends BaseController { public @ResponseBody ResponseEntity getPDFDocument(@PathVariable String id, @RequestHeader("Content-Type") String contentType) throws IllegalAccessException, IOException, InstantiationException, InterruptedException { System.out.println(contentType); - File file = this.dataManagementPlanManager.getWordDocument(this.environment, this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, this.getApiContext().getUtilitiesService().getVisibilityRuleService()); - File pdffile = new DatasetManager().convertToPDF(file, environment, file.getName()); + File file = this.dataManagementPlanManager.getWordDocument(id); + File pdffile = datasetManager.convertToPDF(file, environment, file.getName()); InputStream resource = new FileInputStream(pdffile); System.out.println("Mime Type of " + file.getName() + " is " + new MimetypesFileTypeMap().getContentType(file)); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DashBoardController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DashBoardController.java index 74f56cc9d..9c2dff6a1 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DashBoardController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DashBoardController.java @@ -20,36 +20,34 @@ import java.util.List; @RequestMapping(value = {"/api"}) public class DashBoardController extends BaseController { + private DashBoardManager dashBoardManager; @Autowired - public DashBoardController(ApiContext apiContext) { + public DashBoardController(ApiContext apiContext, DashBoardManager dashBoardManager) { super(apiContext); + this.dashBoardManager = dashBoardManager; } @RequestMapping(method = RequestMethod.GET, value = {"/dashboard/getStatistics"}, produces = "application/json") public ResponseEntity> getStatistics() { - DashBoardStatistics statistics = new DashBoardManager().getStatistics(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao() - , this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao()); + DashBoardStatistics statistics = dashBoardManager.getStatistics(); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(statistics)); } @RequestMapping(method = RequestMethod.GET, value = {"/dashboard/me/getStatistics"}, produces = "application/json") public ResponseEntity> getStatistics(Principal principal) { - DashBoardStatistics statistics = new DashBoardManager().getMeStatistics(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao() - , this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), principal); + DashBoardStatistics statistics = dashBoardManager.getMeStatistics(principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(statistics)); } @RequestMapping(method = RequestMethod.GET, value = {"/user/recentActivity"}, produces = "application/json") public ResponseEntity> getRecentActivity(@RequestParam(name = "numOfActivities", required = false, defaultValue = "5") Integer numberOfActivities, Principal principal) { - RecentActivity statistics = new DashBoardManager().getRecentActivity(this.getApiContext(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao() - , this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), principal, numberOfActivities); + RecentActivity statistics = dashBoardManager.getRecentActivity(principal, numberOfActivities); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(statistics)); } @RequestMapping(method = RequestMethod.GET, value = {"/dashboard/search"}, produces = "application/json") public ResponseEntity>> search(@RequestParam(name = "like") String like, Principal principal) { - List searchBarItemList = new DashBoardManager().searchUserData(like, this.getApiContext(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao() - , this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), principal); + List searchBarItemList = dashBoardManager.searchUserData(like, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(searchBarItemList)); } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DataRepositories.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DataRepositories.java index f3db8148d..68e0d87f6 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DataRepositories.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DataRepositories.java @@ -47,7 +47,7 @@ public class DataRepositories extends BaseController { @RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> create(@RequestBody eu.eudat.models.data.datarepository.DataRepositoryModel dataRepositoryModel, Principal principal) throws Exception { - DataRepository dataRepository = this.dataRepositoryManager.create(this.getApiContext(), dataRepositoryModel); + DataRepository dataRepository = this.dataRepositoryManager.create(dataRepositoryModel); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().payload(dataRepository).status(ApiMessageCode.SUCCESS_MESSAGE)); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfileController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfileController.java index 4e29103cb..3cd7af875 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfileController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfileController.java @@ -57,7 +57,7 @@ public class DatasetProfileController extends BaseController { @Transactional @RequestMapping(method = RequestMethod.POST, value = {"/datasetprofile/clone/{id}"}, consumes = "application/json", produces = "application/json") public ResponseEntity> clone(@PathVariable String id, @ClaimedAuthorities(claims = {ADMIN})Principal principal) { - eu.eudat.data.entities.DatasetProfile profile = this.datasetProfileManager.clone(this.getApiContext(), id); + eu.eudat.data.entities.DatasetProfile profile = this.datasetProfileManager.clone(id); eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile); datasetprofile.setLabel(profile.getLabel() + " new "); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().payload(datasetprofile)); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfiles.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfiles.java index 42533ea2a..a5b458a5a 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfiles.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfiles.java @@ -33,14 +33,14 @@ public class DatasetProfiles extends BaseController { @RequestMapping(method = RequestMethod.POST, value = {"/dmps/datasetprofiles/get"}, produces = "application/json") public @ResponseBody ResponseEntity>> get(@RequestBody DatasetProfileAutocompleteRequest datasetProfileAutocompleteRequest) throws InstantiationException, IllegalAccessException { - List datasetProfileAutocompleteItems = this.datasetProfileManager.getWithCriteria(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao(), datasetProfileAutocompleteRequest); + List datasetProfileAutocompleteItems = this.datasetProfileManager.getWithCriteria(datasetProfileAutocompleteRequest); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileAutocompleteItems)); } @RequestMapping(method = RequestMethod.GET, value = {"/datasetprofiles/getAll"}, produces = "application/json") public @ResponseBody ResponseEntity>> getAll() throws InstantiationException, IllegalAccessException { - List datasetProfileTableData = this.datasetProfileManager.getAll(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao()); + List datasetProfileTableData = this.datasetProfileManager.getAll(); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileTableData)); } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetWizardController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetWizardController.java index 5ee1514e8..c79dfd0ac 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetWizardController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetWizardController.java @@ -47,12 +47,14 @@ public class DatasetWizardController extends BaseController { private Environment environment; private DatasetManager datasetManager; + private UserManager userManager; @Autowired - public DatasetWizardController(ApiContext apiContext, Environment environment, DatasetManager datasetManager) { + public DatasetWizardController(ApiContext apiContext, Environment environment, DatasetManager datasetManager, UserManager userManager) { super(apiContext); this.environment = environment; this.datasetManager = datasetManager; + this.userManager = userManager; } @RequestMapping(method = RequestMethod.POST, value = {"/userDmps"}, produces = "application/json") @@ -76,10 +78,10 @@ public class DatasetWizardController extends BaseController { DatasetDao datasetDao = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(); VisibilityRuleService visibilityRuleService = this.getApiContext().getUtilitiesService().getVisibilityRuleService(); - return this.datasetManager.getDocument(datasetDao, id, visibilityRuleService, contentType); + return this.datasetManager.getDocument(id, visibilityRuleService, contentType); } else { - DatasetWizardModel dataset = this.datasetManager.getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), this.getApiContext().getOperationsContext().getDatasetRepository(), id); + DatasetWizardModel dataset = this.datasetManager.getSingle(id); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(dataset)); } } @@ -96,15 +98,15 @@ public class DatasetWizardController extends BaseController { @RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> createOrUpdate(@RequestBody DatasetWizardModel profile, Principal principal) throws Exception { - this.datasetManager.createOrUpdate(this.getApiContext(), profile, principal); + this.datasetManager.createOrUpdate(profile, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created").payload(null)); } @RequestMapping(method = RequestMethod.GET, value = {"/getPDF/{id}"}) public @ResponseBody ResponseEntity getPDFDocument(@PathVariable String id) throws IllegalAccessException, IOException, InstantiationException, InterruptedException { - File file = new DatasetManager().getWordDocument(this.environment, this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), id, this.getApiContext().getUtilitiesService().getVisibilityRuleService()); - File pdffile = new DatasetManager().convertToPDF(file, environment, file.getName()); + File file = datasetManager.getWordDocument(this.environment, id, this.getApiContext().getUtilitiesService().getVisibilityRuleService()); + File pdffile = datasetManager.convertToPDF(file, environment, file.getName()); InputStream resource = new FileInputStream(pdffile); System.out.println("Mime Type of " + file.getName() + " is " + new MimetypesFileTypeMap().getContentType(file)); @@ -124,7 +126,7 @@ public class DatasetWizardController extends BaseController { @RequestMapping(method = RequestMethod.GET, value = {"/get/{id}"}, produces = "application/json") public ResponseEntity> getSingle(@PathVariable String id) { eu.eudat.data.entities.DatasetProfile profile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); - eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = UserManager.generateDatasetProfileModel(profile); + eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = userManager.generateDatasetProfileModel(profile); PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile(); pagedDatasetProfile.buildPagedDatasetProfile(datasetprofile); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(pagedDatasetProfile)); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/Datasets.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/Datasets.java index f0d539027..5b49595b0 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/Datasets.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/Datasets.java @@ -38,14 +38,14 @@ public class Datasets extends BaseController { @RequestMapping(method = RequestMethod.POST, value = {"paged"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity>> getPaged(@RequestBody DatasetTableRequest datasetTableRequest, Principal principal) throws Exception { - DataTableData dataTable = this.datasetManager.getPaged(this.getApiContext(), datasetTableRequest, principal); + DataTableData dataTable = this.datasetManager.getPaged(datasetTableRequest, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable)); } @RequestMapping(method = RequestMethod.POST, value = {"/public/paged"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity>> getPublicPaged(@RequestBody DatasetPublicTableRequest datasetTableRequest, @ClaimedAuthorities(claims = {Authorities.ANONYMOUS}) Principal principal) throws Exception { - DataTableData dataTable = this.datasetManager.getPaged(this.getApiContext(), datasetTableRequest, principal); + DataTableData dataTable = this.datasetManager.getPaged(datasetTableRequest, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable)); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/ExternalDatasets.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/ExternalDatasets.java index 6ece472df..c118de055 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/ExternalDatasets.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/ExternalDatasets.java @@ -39,7 +39,7 @@ public class ExternalDatasets extends BaseController { @RequestMapping(method = RequestMethod.POST, value = {"/externaldatasets/getPaged"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity>> getPaged(@RequestBody ExternalDatasetTableRequest datasetTableRequest, Principal principal) throws Exception { - DataTableData dataTable = new ExternalDatasetManager().getPaged(this.getApiContext(), datasetTableRequest); + DataTableData dataTable = externalDatasetManager.getPaged(datasetTableRequest); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable)); } @@ -48,14 +48,14 @@ public class ExternalDatasets extends BaseController { ResponseEntity>> getWithExternal( @RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type, Principal principal ) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException { - List dataTable = new ExternalDatasetManager().getWithExternal(this.getApiContext(), query, this.getApiContext().getOperationsContext().getRemoteFetcher()); + List dataTable = externalDatasetManager.getWithExternal(query); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE)); } @RequestMapping(method = RequestMethod.POST, value = {"/externaldatasets/getSingle/{id}"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseItem getWithExternal(@PathVariable UUID id, Principal principal) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException { - ExternalDatasetListingModel externalDatasetModel = new ExternalDatasetManager().getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getExternalDatasetDao(), id); + ExternalDatasetListingModel externalDatasetModel = externalDatasetManager.getSingle(id); return new ResponseItem().payload(externalDatasetModel).status(ApiMessageCode.NO_MESSAGE); } @@ -63,7 +63,7 @@ public class ExternalDatasets extends BaseController { @RequestMapping(method = RequestMethod.POST, value = {"/externaldatasets"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> create(@RequestBody eu.eudat.models.data.externaldataset.ExternalDatasetModel externalDatasetModel, Principal principal) throws Exception { - ExternalDataset externalDataset = this.externalDatasetManager.create(this.getApiContext(), externalDatasetModel); + ExternalDataset externalDataset = this.externalDatasetManager.create(externalDatasetModel); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().payload(externalDataset).status(ApiMessageCode.SUCCESS_MESSAGE)); } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/FileController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/FileController.java index 453bc903d..f41b5e6ab 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/FileController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/FileController.java @@ -25,22 +25,24 @@ import java.util.List; @RequestMapping(value = {"/api/files"}) public class FileController extends BaseController { + private FileManager fileManager; @Autowired - public FileController(ApiContext apiContext) { + public FileController(ApiContext apiContext, FileManager fileManager) { super(apiContext); + this.fileManager = fileManager; } @RequestMapping(method = RequestMethod.POST, value = {"/upload"}) public ResponseEntity>> handleFileUpload(@RequestParam("file") MultipartFile[] files) throws IOException { return ResponseEntity.status(HttpStatus.OK).body( - new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(FileManager.saveTempFile(files, getApiContext().getOperationsContext().getFileStorageService()))); + new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(fileManager.saveTempFile(files))); } @RequestMapping(method = RequestMethod.GET, value = {"/{id}"}) public ResponseEntity handleFileUpload(@PathVariable(name = "id") String id, @RequestParam(name = "type") String type, @RequestParam(name = "location", required = false, defaultValue = "final") String location) throws IOException { - Resource resource = FileManager.getFile(id, type, getApiContext().getOperationsContext().getFileStorageService(), location); + Resource resource = fileManager.getFile(id, type, location); if (!resource.exists()) resource = new UrlResource(FileController.class.getClassLoader().getResource("images/default.png")); return ResponseEntity.ok() diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/Login.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/Login.java index 43b4e75e6..15582d910 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/Login.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/Login.java @@ -38,14 +38,17 @@ public class Login { private Logger logger; + private UserManager userManager; @Autowired public Login(CustomAuthenticationProvider customAuthenticationProvider, AuthenticationServiceImpl authenticationServiceImpl, - TwitterTokenValidator twitterTokenValidator, B2AccessTokenValidator b2AccessTokenValidator, Logger logger) { + TwitterTokenValidator twitterTokenValidator, B2AccessTokenValidator b2AccessTokenValidator, + UserManager userManager ,Logger logger) { this.customAuthenticationProvider = customAuthenticationProvider; this.authenticationServiceImpl = authenticationServiceImpl; this.twitterTokenValidator = twitterTokenValidator; this.b2AccessTokenValidator = b2AccessTokenValidator; this.logger = logger; + this.userManager = userManager; } @Transactional @@ -61,7 +64,7 @@ public class Login { public @ResponseBody ResponseEntity> nativelogin(@RequestBody Credentials credentials) { this.logger.info(credentials.getUsername(), "Trying To Login"); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().payload(UserManager.authenticate(this.authenticationServiceImpl, credentials)).status(ApiMessageCode.SUCCESS_MESSAGE)); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().payload(userManager.authenticate(this.authenticationServiceImpl, credentials)).status(ApiMessageCode.SUCCESS_MESSAGE)); } @RequestMapping(method = RequestMethod.GET, value = {"/twitterRequestToken"}, produces = "application/json") diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/Projects.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/Projects.java index efe288253..a1bd460a9 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/Projects.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/Projects.java @@ -47,14 +47,14 @@ public class Projects extends BaseController { public @ResponseBody ResponseEntity>> getPaged(@Valid @RequestBody ProjectTableRequest projectTableRequest, @RequestParam String fieldsGroup, Principal principal) throws Exception { System.out.println(fieldsGroup); - DataTableData dataTable = this.projectManager.getPaged(this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), projectTableRequest, principal, fieldsGroup); + DataTableData dataTable = this.projectManager.getPaged(projectTableRequest, principal, fieldsGroup); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE)); } @RequestMapping(method = RequestMethod.GET, value = {"{id}"}, produces = "application/json") public @ResponseBody ResponseEntity> getSingle(@PathVariable String id, Principal principal) throws IllegalAccessException, InstantiationException { - eu.eudat.models.data.project.Project project = this.projectManager.getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), id); + eu.eudat.models.data.project.Project project = this.projectManager.getSingle(id); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().payload(project).status(ApiMessageCode.NO_MESSAGE)); } @@ -62,7 +62,7 @@ public class Projects extends BaseController { @RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> addProject(@Valid @RequestBody eu.eudat.models.data.project.Project project, Principal principal) throws IOException, ParseException { - this.projectManager.createOrUpdate(this.getApiContext().getOperationsContext().getFileStorageService(), this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getContentDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getUserInfoDao(), project, principal); + this.projectManager.createOrUpdate(project, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created")); } @@ -70,21 +70,21 @@ public class Projects extends BaseController { @RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> inactivate(@PathVariable String id, Principal principal) throws IllegalAccessException, InstantiationException { - this.projectManager.inactivate(this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), id); + this.projectManager.inactivate(id); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE)); } @RequestMapping(method = RequestMethod.POST, value = {"/external"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity>> getWithExternal(@RequestBody ProjectCriteriaRequest projectCriteria, Principal principal) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException { - List dataTable = this.projectManager.getCriteriaWithExternal(this.getApiContext(), projectCriteria, this.getApiContext().getOperationsContext().getRemoteFetcher(), principal); + List dataTable = this.projectManager.getCriteriaWithExternal(projectCriteria, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE)); } @RequestMapping(method = RequestMethod.POST, value = {"get"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity>> get(@RequestBody ProjectCriteriaRequest projectCriteria, @ClaimedAuthorities(claims = {ANONYMOUS}) Principal principal) throws NoURLFound, InstantiationException, HugeResultSet, IllegalAccessException { - List dataTable = this.projectManager.getCriteria(this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), projectCriteria, this.getApiContext().getOperationsContext().getRemoteFetcher()); + List dataTable = this.projectManager.getCriteria(projectCriteria); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE)); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/QuickWizardController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/QuickWizardController.java index 72d0c2533..4b6e8e37a 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/QuickWizardController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/QuickWizardController.java @@ -38,24 +38,7 @@ public class QuickWizardController extends BaseController { @RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> addQuickWizardModel(@Valid @RequestBody QuickWizardModel quickWizard, Principal principal) throws Exception { - - //Create Project - eu.eudat.data.entities.Project projectEntity = this.quickWizardManager.createOrUpdate(this.getApiContext().getOperationsContext().getFileStorageService(), - this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), - this.getApiContext().getOperationsContext().getDatabaseRepository().getContentDao(), - this.getApiContext().getOperationsContext().getDatabaseRepository().getUserInfoDao(), - quickWizard.getProject().toDataProject(), principal); - - //Create Dmp - eu.eudat.data.entities.DMP dmpEntity = this.quickWizardManager.createOrUpdate(this.getApiContext(), quickWizard.getDmp().toDataDmp(projectEntity), principal); - - //Create Datasets - quickWizard.getDmp().setId(dmpEntity.getId()); - for(DatasetDescriptionQuickWizardModel dataset : quickWizard.getDatasets().getDatasetsList()){ - this.datasetManager.createOrUpdate(this.getApiContext(), dataset.toDataModel(quickWizard.getDmp().toDataDmp(projectEntity),quickWizard.getDmp().getDatasetProfile().getId()), principal); - } - - + this.quickWizardManager.createOrUpdate(quickWizard, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created")); } @@ -65,7 +48,7 @@ public class QuickWizardController extends BaseController { public @ResponseBody ResponseEntity> addDatasetWizard(@RequestBody DatasetCreateWizardModel datasetCreateWizardModel, Principal principal) throws Exception{ for(DatasetDescriptionQuickWizardModel dataset : datasetCreateWizardModel.getDatasets().getDatasetsList()){ - this.datasetManager.createOrUpdate(this.getApiContext(), dataset.toDataModel(datasetCreateWizardModel.getDmpMeta().getDmp(), datasetCreateWizardModel.getDmpMeta().getDatasetProfile().getId()), principal); + this.datasetManager.createOrUpdate(dataset.toDataModel(datasetCreateWizardModel.getDmpMeta().getDmp(), datasetCreateWizardModel.getDmpMeta().getDatasetProfile().getId()), principal); } return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Dataset added!")); diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/Registries.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/Registries.java index 38b45f8f3..1134d4317 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/Registries.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/Registries.java @@ -45,7 +45,7 @@ public class Registries extends BaseController { @RequestMapping(method = RequestMethod.POST, value = {"/registries"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> create(@RequestBody RegistryModel registryModel, Principal principal) throws Exception { - Registry registry = this.registryManager.create(this.getApiContext(), registryModel); + Registry registry = this.registryManager.create(registryModel); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().payload(registry).status(ApiMessageCode.SUCCESS_MESSAGE)); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/Researchers.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/Researchers.java index eb89bcdc1..8a73d28f3 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/Researchers.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/Researchers.java @@ -33,19 +33,10 @@ public class Researchers extends BaseController { this.researcherManager = researcherManager; } - /*@RequestMapping(method = RequestMethod.GET, value = {"/external/researchers"}, produces = "application/json") - public @ResponseBody - ResponseEntity> listExternalResearchers( - @RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type) throws HugeResultSet, NoURLFound { - List> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getResearchers(query, type); - ResearchersExternalSourcesModel researchersExternalSourcesModel = new ResearchersExternalSourcesModel().fromExternalItem(remoteRepos); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().payload(researchersExternalSourcesModel).status(ApiMessageCode.NO_MESSAGE)); - }*/ - @RequestMapping(method = RequestMethod.POST, value = {"/getWithExternal"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity>> getWithExternal(@RequestBody ResearcherCriteriaRequest researcherCriteriaRequest, Principal principal) throws HugeResultSet, NoURLFound { - List dataTable = this.researcherManager.getCriteriaWithExternal(this.getApiContext(), this.getApiContext().getOperationsContext().getRemoteFetcher(), researcherCriteriaRequest); + List dataTable = this.researcherManager.getCriteriaWithExternal(researcherCriteriaRequest); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE)); } @@ -53,7 +44,7 @@ public class Researchers extends BaseController { @RequestMapping(method = RequestMethod.POST, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> create(@RequestBody eu.eudat.models.data.researcher.Researcher researcher, Principal principal) throws Exception { - this.researcherManager.create(this.getApiContext(), researcher); + this.researcherManager.create(researcher); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE)); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/Services.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/Services.java index 94877577d..36b2703cb 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/Services.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/Services.java @@ -1,7 +1,6 @@ package eu.eudat.controllers; import eu.eudat.data.entities.Service; -import eu.eudat.logic.managers.RegistryManager; import eu.eudat.logic.managers.ServiceManager; import eu.eudat.logic.proxy.config.exceptions.HugeResultSet; import eu.eudat.logic.proxy.config.exceptions.NoURLFound; @@ -25,26 +24,29 @@ import java.util.Map; @RequestMapping(value = {"/api"}) public class Services extends BaseController { - @Autowired - public Services(ApiContext apiContext) { - super(apiContext); - } + private ServiceManager serviceManager; - @RequestMapping(method = RequestMethod.GET, value = {"/external/services"}, produces = "application/json") - public @ResponseBody - ResponseEntity>>> listExternalServices( - @RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type - ) throws HugeResultSet, NoURLFound { - List> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getServices(query, type); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>>().payload(remoteRepos).status(ApiMessageCode.NO_MESSAGE)); - } + @Autowired + public Services(ApiContext apiContext, ServiceManager serviceManager) { + super(apiContext); + this.serviceManager = serviceManager; + } - @Transactional - @RequestMapping(method = RequestMethod.POST, value = {"/services"}, consumes = "application/json", produces = "application/json") - public @ResponseBody - ResponseEntity> create(@RequestBody ServiceModel serviceModel, Principal principal) throws Exception { - Service service = ServiceManager.create(this.getApiContext(), serviceModel); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().payload(service).status(ApiMessageCode.SUCCESS_MESSAGE)); - } + @RequestMapping(method = RequestMethod.GET, value = {"/external/services"}, produces = "application/json") + public @ResponseBody + ResponseEntity>>> listExternalServices( + @RequestParam(value = "query", required = false) String query, @RequestParam(value = "type", required = false) String type + ) throws HugeResultSet, NoURLFound { + List> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getServices(query, type); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>>().payload(remoteRepos).status(ApiMessageCode.NO_MESSAGE)); + } + + @Transactional + @RequestMapping(method = RequestMethod.POST, value = {"/services"}, consumes = "application/json", produces = "application/json") + public @ResponseBody + ResponseEntity> create(@RequestBody ServiceModel serviceModel, Principal principal) throws Exception { + Service service = serviceManager.create(serviceModel); + return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().payload(service).status(ApiMessageCode.SUCCESS_MESSAGE)); + } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/TagController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/TagController.java index 1101a634a..c2e040d45 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/TagController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/TagController.java @@ -35,14 +35,6 @@ public class TagController extends BaseController { this.datasetRepository = tagRepository; } - /*@Transactional - @RequestMapping(method = RequestMethod.POST, value = {"/tag/create"}, consumes = "application/json", produces = "application/json") - public @ResponseBody - ResponseEntity> create(@RequestBody Dataset dataset) throws IOException { - Dataset tagEntity = this.datasetRepository.createOrUpdate(dataset); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().payload(dataset).status(ApiMessageCode.SUCCESS_MESSAGE)); - }*/ - @RequestMapping(method = RequestMethod.GET, value = {"/external/tags"}, produces = "application/json") public @ResponseBody ResponseEntity> listExternalTagModel( diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/UserInvitationController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/UserInvitationController.java index a2e637ff7..3e09dd43b 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/UserInvitationController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/UserInvitationController.java @@ -23,16 +23,18 @@ import java.util.UUID; @CrossOrigin public class UserInvitationController extends BaseController { + private InvitationsManager invitationsManager; @Autowired - public UserInvitationController(ApiContext apiContext) { + public UserInvitationController(ApiContext apiContext, InvitationsManager invitationsManager) { super(apiContext); + this.invitationsManager = invitationsManager; } @Transactional @RequestMapping(method = RequestMethod.POST, value = {"/users"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> users(@RequestBody Invitation invitation, Principal principal) throws Exception { - InvitationsManager.inviteUsers(this.getApiContext(), invitation, principal); + this.invitationsManager.inviteUsers(invitation, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Users have beeen invited")); } @@ -40,14 +42,14 @@ public class UserInvitationController extends BaseController { @RequestMapping(method = RequestMethod.GET, value = {"/exchange/{invitationID}"}, produces = "application/json") public @ResponseBody ResponseEntity> exchange(@PathVariable UUID invitationID, Principal principal) { - UUID dmpId = InvitationsManager.assignUserAcceptedInvitation(this.getApiContext(), invitationID, principal); + UUID dmpId = invitationsManager.assignUserAcceptedInvitation(invitationID, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).payload(dmpId)); } @RequestMapping(method = RequestMethod.POST, value = {"/getUsers"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity>> getUsers(@RequestBody UserInfoRequestItem userInfoRequestItem) throws IllegalAccessException, InstantiationException { - List users = InvitationsManager.getUsers(this.getApiContext(), userInfoRequestItem); + List users = invitationsManager.getUsers(userInfoRequestItem); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.SUCCESS_MESSAGE).payload(users)); } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/Users.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/Users.java index 728ae9128..a54c9e0d1 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/Users.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/Users.java @@ -29,15 +29,17 @@ import static eu.eudat.types.Authorities.ADMIN; @RequestMapping(value = "api/user") public class Users extends BaseController { + private UserManager userManager; @Autowired - public Users(ApiContext apiContext) { + public Users(ApiContext apiContext, UserManager userManager) { super(apiContext); + this.userManager = userManager; } @RequestMapping(method = RequestMethod.POST, value = {"/getPaged"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity>> getPaged(@Valid @RequestBody UserInfoTableRequestItem userInfoTableRequestItem, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) throws Exception { - DataTableData dataTable = UserManager.getPaged(this.getApiContext(), userInfoTableRequestItem); + DataTableData dataTable = userManager.getPaged(userInfoTableRequestItem); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE)); } @@ -45,7 +47,7 @@ public class Users extends BaseController { @RequestMapping(method = RequestMethod.POST, value = {"/updateRoles"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> updateRoles(@Valid @RequestBody UserListingModel userListingModel, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { - UserManager.editRoles(this.getApiContext(), userListingModel); + userManager.editRoles(userListingModel); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE)); } @@ -53,7 +55,7 @@ public class Users extends BaseController { public @ResponseBody ResponseEntity> get(@PathVariable String id, Principal principal) throws Exception { UUID userId = id.equals("me") ? principal.getId() : UUID.fromString(id); - UserProfile user = UserManager.getSingle(this.getApiContext(), userId); + UserProfile user = userManager.getSingle(userId); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().payload(user).status(ApiMessageCode.NO_MESSAGE)); } @@ -61,7 +63,7 @@ public class Users extends BaseController { @RequestMapping(method = RequestMethod.POST, value = {"/settings"}, produces = "application/json") public @ResponseBody ResponseEntity> saveSettings(@RequestBody Map settings, Principal principal) throws IOException { - UserManager.updateSettings(this.getApiContext(), settings, principal); + userManager.updateSettings(settings, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE)); } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DashBoardManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DashBoardManager.java index 886d8b038..a395b4aa0 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DashBoardManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DashBoardManager.java @@ -8,39 +8,55 @@ import eu.eudat.data.dao.entities.ProjectDao; import eu.eudat.data.entities.UserInfo; import eu.eudat.logic.builders.model.models.RecentActivityDataBuilder; import eu.eudat.logic.services.ApiContext; +import eu.eudat.logic.services.operations.DatabaseRepository; import eu.eudat.models.data.dashboard.recent.RecentActivity; import eu.eudat.models.data.dashboard.recent.RecentActivityData; import eu.eudat.models.data.dashboard.searchbar.SearchBarItem; import eu.eudat.models.data.dashboard.statistics.DashBoardStatistics; import eu.eudat.models.data.security.Principal; import eu.eudat.types.searchbar.SearchBarItemType; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import java.util.LinkedList; import java.util.List; import java.util.concurrent.CompletableFuture; +@Component public class DashBoardManager { - public DashBoardStatistics getStatistics(DatasetDao datasetRepository, DMPDao dataManagementPlanRepository, ProjectDao projectRepository) { + private ApiContext apiContext; + private DatabaseRepository databaseRepository; + + @Autowired + public DashBoardManager(ApiContext apiContext) { + this.apiContext = apiContext; + this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository(); + } + + public DashBoardStatistics getStatistics() { DashBoardStatistics statistics = new DashBoardStatistics(); DatasetCriteria datasetCriteria = new DatasetCriteria(); datasetCriteria.setAllVersions(false); DataManagementPlanCriteria dataManagementPlanCriteria = new DataManagementPlanCriteria(); dataManagementPlanCriteria.setAllVersions(false); - CompletableFuture dmpFuture = dataManagementPlanRepository.getWithCriteria(dataManagementPlanCriteria).countAsync() + CompletableFuture dmpFuture = databaseRepository.getDmpDao().getWithCriteria(dataManagementPlanCriteria).countAsync() .whenComplete((dmpsStats, throwable) -> statistics.setTotalDataManagementPlanCount(dmpsStats)); - CompletableFuture datasetFuture = datasetRepository.getWithCriteria(datasetCriteria).countAsync() + CompletableFuture datasetFuture = databaseRepository.getDatasetDao().getWithCriteria(datasetCriteria).countAsync() .whenComplete((datasetsStats, throwable) -> statistics.setTotalDataSetCount(datasetsStats)); - CompletableFuture projectFuture = projectRepository.asQueryable().countAsync() + CompletableFuture projectFuture = databaseRepository.getProjectDao().asQueryable().countAsync() .whenComplete((projectsStats, throwable) -> statistics.setTotalProjectCount(projectsStats)); CompletableFuture.allOf(dmpFuture, datasetFuture, projectFuture).join(); return statistics; } - public DashBoardStatistics getMeStatistics(DatasetDao datasetRepository, DMPDao dataManagementPlanRepository, ProjectDao projectRepository, Principal principal) { + public DashBoardStatistics getMeStatistics(Principal principal) { DashBoardStatistics statistics = new DashBoardStatistics(); + DMPDao dataManagementPlanRepository = databaseRepository.getDmpDao(); + DatasetDao datasetRepository = databaseRepository.getDatasetDao(); + ProjectDao projectRepository = databaseRepository.getProjectDao(); UserInfo user = new UserInfo(); user.setId(principal.getId()); DatasetCriteria datasetCriteria = new DatasetCriteria(); @@ -58,8 +74,11 @@ public class DashBoardManager { return statistics; } - public RecentActivity getRecentActivity(ApiContext apiContext, DatasetDao datasetRepository, DMPDao dataManagementPlanRepository, ProjectDao projectRepository, Principal principal, Integer numberofactivities) { + public RecentActivity getRecentActivity(Principal principal, Integer numberofactivities) { RecentActivity activity = new RecentActivity(); + DMPDao dataManagementPlanRepository = databaseRepository.getDmpDao(); + DatasetDao datasetRepository = databaseRepository.getDatasetDao(); + ProjectDao projectRepository = databaseRepository.getProjectDao(); UserInfo user = new UserInfo(); user.setId(principal.getId()); DatasetCriteria datasetCriteria = new DatasetCriteria(); @@ -94,10 +113,13 @@ public class DashBoardManager { return activity; } - public List searchUserData(String like, ApiContext apiContext, DatasetDao datasetRepository, DMPDao dataManagementPlanRepository, ProjectDao projectRepository, Principal principal) { + public List searchUserData(String like, Principal principal) { RecentActivity activity = new RecentActivity(); UserInfo user = new UserInfo(); user.setId(principal.getId()); + DMPDao dataManagementPlanRepository = databaseRepository.getDmpDao(); + DatasetDao datasetRepository = databaseRepository.getDatasetDao(); + ProjectDao projectRepository = databaseRepository.getProjectDao(); List searchBarItems = new LinkedList<>(); CompletableFuture> dmps = dataManagementPlanRepository.getAuthenticated(dataManagementPlanRepository.asQueryable(), user) diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java index a42313f11..cfdd6cc88 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementPlanManager.java @@ -12,6 +12,8 @@ import eu.eudat.exceptions.security.UnauthorisedException; import eu.eudat.logic.builders.entity.UserInfoBuilder; import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.forms.VisibilityRuleService; +import eu.eudat.logic.services.operations.DatabaseRepository; +import eu.eudat.logic.services.utilities.UtilitiesService; import eu.eudat.logic.utilities.builders.XmlBuilder; import eu.eudat.logic.utilities.documents.helpers.FileEnvelope; import eu.eudat.logic.utilities.documents.types.ParagraphStyle; @@ -31,6 +33,7 @@ import eu.eudat.models.data.user.composite.PagedDatasetProfile; import eu.eudat.queryable.QueryableList; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.http.*; import org.springframework.stereotype.Component; @@ -51,7 +54,22 @@ import java.util.stream.Collectors; @Component public class DataManagementPlanManager { - public DataTableData getPaged(ApiContext apiContext, DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal, String fieldsGroup) throws Exception { + private ApiContext apiContext; + private DatasetManager datasetManager; + private UtilitiesService utilitiesService; + private DatabaseRepository databaseRepository; + private Environment environment; + + @Autowired + public DataManagementPlanManager(ApiContext apiContext, DatasetManager datasetManager, Environment environment) { + this.apiContext = apiContext; + this.datasetManager = datasetManager; + this.utilitiesService = apiContext.getUtilitiesService(); + this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository(); + this.environment = environment; + } + + public DataTableData getPaged(DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal, String fieldsGroup) throws Exception { UserInfo userInfo = new UserInfo(); userInfo.setId(principal.getId()); QueryableList items = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(dataManagementPlanTableRequest.getCriteria()).withHint(HintedModelFactory.getHint(DataManagementPlanListingModel.class)); @@ -88,21 +106,22 @@ public class DataManagementPlanManager { return dataTable; } - public void unlock(ApiContext apiContext, UUID uuid) throws Exception { + public void unlock(UUID uuid) throws Exception { apiContext.getOperationsContext().getDatabaseRepository().getDmpDao() .asQueryable().where((builder, root) -> builder.equal(root.get("id"), uuid)) .update(root -> root.get("status"), DMP.DMPStatus.ACTIVE.getValue()); return; } - public File getWordDocument(Environment environment, DMPDao dmpRepository, String id, VisibilityRuleService visibilityRuleService) throws InstantiationException, IllegalAccessException, IOException { + public File getWordDocument(String id) throws InstantiationException, IllegalAccessException, IOException { WordBuilder wordBuilder = new WordBuilder(); + VisibilityRuleService visibilityRuleService = this.utilitiesService.getVisibilityRuleService(); DatasetWizardModel dataset = new DatasetWizardModel(); String fileUrl = environment.getProperty("configuration.h2020template"); InputStream is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream(); XWPFDocument document = new XWPFDocument(is); - eu.eudat.data.entities.DMP dmpEntity = dmpRepository.find(UUID.fromString(id)); + eu.eudat.data.entities.DMP dmpEntity = databaseRepository.getDmpDao().find(UUID.fromString(id)); wordBuilder.addParagraphContent(dmpEntity.getLabel(), document, ParagraphStyle.TITLE, BigInteger.ZERO); wordBuilder.addParagraphContent(dmpEntity.getDescription(), document, ParagraphStyle.TEXT, BigInteger.ZERO); @@ -124,7 +143,7 @@ public class DataManagementPlanManager { wordBuilder.addParagraphContent("Title: " + datasetEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO); wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.TEXT, BigInteger.ZERO); wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER1, BigInteger.ZERO); - PagedDatasetProfile pagedDatasetProfile = new DatasetManager().getPagedProfile(dataset, datasetEntity); + PagedDatasetProfile pagedDatasetProfile = datasetManager.getPagedProfile(dataset, datasetEntity); visibilityRuleService.setProperties(properties); visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules()); try { @@ -140,8 +159,8 @@ public class DataManagementPlanManager { return exportFile; } - public eu.eudat.models.data.dmp.DataManagementPlan getSingle(DMPDao dmpsRepository, String id, Principal principal, DynamicProjectConfiguration dynamicProjectConfiguration) throws InstantiationException, IllegalAccessException { - DMP dataManagementPlanEntity = dmpsRepository.find(UUID.fromString(id)); + public eu.eudat.models.data.dmp.DataManagementPlan getSingle(String id, Principal principal, DynamicProjectConfiguration dynamicProjectConfiguration) throws InstantiationException, IllegalAccessException { + DMP dataManagementPlanEntity = databaseRepository.getDmpDao().find(UUID.fromString(id)); if (dataManagementPlanEntity.getCreator().getId() != principal.getId() && dataManagementPlanEntity.getUsers().stream().filter(userInfo -> userInfo.getId() == principal.getId()).collect(Collectors.toList()).size() == 0) throw new UnauthorisedException(); eu.eudat.models.data.dmp.DataManagementPlan datamanagementPlan = new eu.eudat.models.data.dmp.DataManagementPlan(); @@ -244,7 +263,7 @@ public class DataManagementPlanManager { apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP); } - public void newVersion(ApiContext apiContext, UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception { + public void newVersion(UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception { DMP oldDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(uuid); DMP newDmp = dataManagementPlan.toDataModel(); createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao()); @@ -259,7 +278,7 @@ public class DataManagementPlanManager { copyDatasets(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao()); } - public void clone(ApiContext apiContext, UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception { + public void clone(UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception { DMP newDmp = dataManagementPlan.toDataModel(); createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao()); createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao()); @@ -273,7 +292,7 @@ public class DataManagementPlanManager { copyDatasets(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao()); } - public void delete(ApiContext apiContext, UUID uuid) throws DMPWithDatasetsDeleteException { + public void delete(UUID uuid) throws DMPWithDatasetsDeleteException { DatasetCriteria criteria = new DatasetCriteria(); List dmpIds = Collections.singletonList(uuid); criteria.setDmpIds(dmpIds); @@ -383,9 +402,10 @@ public class DataManagementPlanManager { } } - public FileEnvelope getXmlDocument(DMPDao dmpRepository, String id, VisibilityRuleService visibilityRuleService) throws InstantiationException, IllegalAccessException, IOException { + public FileEnvelope getXmlDocument(String id) throws InstantiationException, IllegalAccessException, IOException { ExportXmlBuilder xmlBuilder = new ExportXmlBuilder(); - eu.eudat.data.entities.DMP dmp = dmpRepository.find(UUID.fromString(id)); + VisibilityRuleService visibilityRuleService = utilitiesService.getVisibilityRuleService(); + eu.eudat.data.entities.DMP dmp = databaseRepository.getDmpDao().find(UUID.fromString(id)); List datasets = dmp.getDataset().stream().collect(Collectors.toList()); File xmlFile = new File(dmp.getLabel() + ".xml"); BufferedWriter writer = new BufferedWriter(new FileWriter(xmlFile, true)); @@ -426,7 +446,7 @@ public class DataManagementPlanManager { JSONObject jobject = new JSONObject(dataset.getProperties()); properties = jobject.toMap(); } - PagedDatasetProfile pagedDatasetProfile = new DatasetManager().getPagedProfile(datasetWizardModel, dataset); + PagedDatasetProfile pagedDatasetProfile = datasetManager.getPagedProfile(datasetWizardModel, dataset); visibilityRuleService.setProperties(properties); visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules()); datasetElement.appendChild(xmlBuilder.createPages(pagedDatasetProfile.getPages(), visibilityRuleService, xmlDoc)); @@ -445,17 +465,19 @@ public class DataManagementPlanManager { return fileEnvelope; } - public ResponseEntity getDocument(Environment environment, DMPDao dmpDao, String id, VisibilityRuleService visibilityRuleService, String contentType) throws InstantiationException, IllegalAccessException, IOException{ + public ResponseEntity getDocument(String id, String contentType) throws InstantiationException, IllegalAccessException, IOException{ File file; + VisibilityRuleService visibilityRuleService = this.utilitiesService.getVisibilityRuleService(); + DMPDao dmpDao = databaseRepository.getDmpDao(); switch (contentType){ case "application/xml": - file = getXmlDocument(dmpDao, id, visibilityRuleService).getFile(); + file = getXmlDocument(id).getFile(); break; case "application/msword": - file = getWordDocument(environment, dmpDao, id, visibilityRuleService); + file = getWordDocument(id); break; default: - file = getXmlDocument(dmpDao, id, visibilityRuleService).getFile(); + file = getXmlDocument(id).getFile(); } InputStream resource = new FileInputStream(file); System.out.println("Mime Type of " + file.getName() + " is " + diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementProfileManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementProfileManager.java index ea63edae9..854bc73b8 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementProfileManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataManagementProfileManager.java @@ -4,6 +4,7 @@ import eu.eudat.data.dao.entities.DMPProfileDao; import eu.eudat.data.entities.DMPProfile; import eu.eudat.data.query.items.item.dmpprofile.DataManagementPlanProfileCriteriaRequest; import eu.eudat.data.query.items.table.dmpprofile.DataManagementPlanProfileTableRequest; +import eu.eudat.logic.services.operations.DatabaseRepository; import eu.eudat.logic.utilities.documents.helpers.FileEnvelope; import eu.eudat.logic.utilities.documents.xml.dmpXml.ExportXmlBuilderDmpProfile; import eu.eudat.logic.utilities.documents.xml.dmpXml.ImportXmlBuilderDmpProfile; @@ -12,6 +13,7 @@ import eu.eudat.models.data.listingmodels.DataManagementPlanProfileListingModel; import eu.eudat.models.data.security.Principal; import eu.eudat.queryable.QueryableList; import eu.eudat.logic.services.ApiContext; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; @@ -31,7 +33,16 @@ import org.springframework.web.multipart.MultipartFile; @Component public class DataManagementProfileManager { - public DataTableData getPaged(ApiContext apiContext, DataManagementPlanProfileTableRequest dataManagementPlanProfileTableRequest, Principal principal) throws Exception { + private ApiContext apiContext; + private DatabaseRepository databaseRepository; + + @Autowired + public DataManagementProfileManager(ApiContext apiContext) { + this.apiContext = apiContext; + this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository(); + } + + public DataTableData getPaged(DataManagementPlanProfileTableRequest dataManagementPlanProfileTableRequest, Principal principal) throws Exception { QueryableList items = apiContext.getOperationsContext().getDatabaseRepository().getDmpProfileDao().getWithCriteria(dataManagementPlanProfileTableRequest.getCriteria()); QueryableList pagedItems = PaginationManager.applyPaging(items, dataManagementPlanProfileTableRequest); @@ -50,20 +61,20 @@ public class DataManagementProfileManager { return dataTable; } - public DataManagementPlanProfileListingModel getSingle(DMPProfileDao dmpProfileDao, String id, Principal principal) throws InstantiationException, IllegalAccessException { - DMPProfile dmpProfile = dmpProfileDao.find(UUID.fromString(id)); + public DataManagementPlanProfileListingModel getSingle(String id, Principal principal) throws InstantiationException, IllegalAccessException { + DMPProfile dmpProfile = databaseRepository.getDmpProfileDao().find(UUID.fromString(id)); DataManagementPlanProfileListingModel dataManagementPlanProfileListingModel = new DataManagementPlanProfileListingModel(); dataManagementPlanProfileListingModel.fromDataModel(dmpProfile); return dataManagementPlanProfileListingModel; } - public List getWithCriteria(DMPProfileDao dmpProfileDao, DataManagementPlanProfileCriteriaRequest dataManagementPlanProfileCriteriaRequest) throws IllegalAccessException, InstantiationException { - QueryableList items = dmpProfileDao.getWithCriteria(dataManagementPlanProfileCriteriaRequest.getCriteria()); + public List getWithCriteria(DataManagementPlanProfileCriteriaRequest dataManagementPlanProfileCriteriaRequest) throws IllegalAccessException, InstantiationException { + QueryableList items = databaseRepository.getDmpProfileDao().getWithCriteria(dataManagementPlanProfileCriteriaRequest.getCriteria()); List datamanagementPlans = items.select(item -> new DataManagementPlanProfileListingModel().fromDataModel(item)); return datamanagementPlans; } - public void createOrUpdate(ApiContext apiContext, DataManagementPlanProfileListingModel dataManagementPlanProfileListingModel, Principal principal) throws Exception { + public void createOrUpdate(DataManagementPlanProfileListingModel dataManagementPlanProfileListingModel, Principal principal) throws Exception { DMPProfile dmpProfile = dataManagementPlanProfileListingModel.toDataModel(); apiContext.getOperationsContext().getDatabaseRepository().getDmpProfileDao().createOrUpdate(dmpProfile); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataRepositoryManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataRepositoryManager.java index 85542226d..53d46bc1a 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataRepositoryManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DataRepositoryManager.java @@ -4,6 +4,7 @@ import eu.eudat.data.entities.DataRepository; import eu.eudat.data.entities.Researcher; import eu.eudat.logic.services.ApiContext; import eu.eudat.models.data.datarepository.DataRepositoryModel; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; /** @@ -11,7 +12,14 @@ import org.springframework.stereotype.Component; */ @Component public class DataRepositoryManager { - public DataRepository create(ApiContext apiContext, eu.eudat.models.data.datarepository.DataRepositoryModel dataRepositoryModel) throws Exception { + private ApiContext apiContext; + + @Autowired + public DataRepositoryManager(ApiContext apiContext) { + this.apiContext = apiContext; + } + + public DataRepository create(eu.eudat.models.data.datarepository.DataRepositoryModel dataRepositoryModel) throws Exception { DataRepository dataRepository = dataRepositoryModel.toDataModel(); return apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao().createOrUpdate(dataRepository); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java index acac9ea8d..3cfb026c0 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java @@ -10,9 +10,11 @@ import eu.eudat.data.query.items.table.dataset.DatasetPublicTableRequest; import eu.eudat.data.query.items.table.dataset.DatasetTableRequest; import eu.eudat.elastic.criteria.DatasetCriteria; import eu.eudat.elastic.repository.DatasetRepository; +import eu.eudat.logic.builders.BuilderFactory; import eu.eudat.logic.builders.entity.UserInfoBuilder; import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.forms.VisibilityRuleService; +import eu.eudat.logic.services.operations.DatabaseRepository; import eu.eudat.logic.utilities.documents.helpers.FileEnvelope; import eu.eudat.logic.utilities.documents.word.WordBuilder; import eu.eudat.logic.utilities.documents.xml.ExportXmlBuilder; @@ -26,6 +28,7 @@ import eu.eudat.queryable.QueryableList; import org.apache.commons.io.IOUtils; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.core.io.FileSystemResource; import org.springframework.http.*; @@ -48,20 +51,34 @@ import java.util.zip.ZipInputStream; @Component public class DatasetManager { - public DataTableData getPaged(ApiContext apiContext, DatasetTableRequest datasetTableRequest, Principal principal) throws Exception { + private ApiContext apiContext; + private DatabaseRepository databaseRepository; + private DatasetRepository datasetRepository; + private BuilderFactory builderFactory; + private UserManager userManager; + @Autowired + public DatasetManager(ApiContext apiContext, UserManager userManager) { + this.apiContext = apiContext; + this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository(); + this.datasetRepository = apiContext.getOperationsContext().getDatasetRepository(); + this.builderFactory = apiContext.getOperationsContext().getBuilderFactory(); + this.userManager = userManager; + } + + public DataTableData getPaged(DatasetTableRequest datasetTableRequest, Principal principal) throws Exception { DatasetCriteria datasetCriteria = new DatasetCriteria(); datasetCriteria.setTags(datasetTableRequest.getCriteria().getTags()); List datasets; try { - datasets = datasetCriteria.getTags() != null && datasetCriteria.getTags().size() > 0 && apiContext.getOperationsContext().getDatasetRepository().exists() ? - apiContext.getOperationsContext().getDatasetRepository().query(datasetCriteria) : new LinkedList<>(); + datasets = datasetCriteria.getTags() != null && datasetCriteria.getTags().size() > 0 && datasetRepository.exists() ? + datasetRepository.query(datasetCriteria) : new LinkedList<>(); } catch (Exception ex){ datasets = null; } - UserInfo userInfo = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build(); - QueryableList items = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria()).withHint(HintedModelFactory.getHint(DatasetListingModel.class)); + UserInfo userInfo = builderFactory.getBuilder(UserInfoBuilder.class).id(principal.getId()).build(); + QueryableList items = databaseRepository.getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria()).withHint(HintedModelFactory.getHint(DatasetListingModel.class)); if (datasets != null && datasetTableRequest.getCriteria().getTags() != null && !datasetTableRequest.getCriteria().getTags().isEmpty()) { if (!datasets.isEmpty()){ List finalDatasets = datasets; @@ -70,7 +87,7 @@ public class DatasetManager { else items.where((builder, root) -> root.get("id").in(new UUID[]{UUID.randomUUID()})); } - QueryableList authItems = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getAuthenticated(items, userInfo); + QueryableList authItems = databaseRepository.getDatasetDao().getAuthenticated(items, userInfo); QueryableList pagedItems = PaginationManager.applyPaging(authItems, datasetTableRequest); DataTableData dataTable = new DataTableData(); @@ -88,18 +105,18 @@ public class DatasetManager { return dataTable; } - public DataTableData getPaged(ApiContext apiContext, DatasetPublicTableRequest datasetTableRequest, Principal principal) throws Exception { + public DataTableData getPaged(DatasetPublicTableRequest datasetTableRequest, Principal principal) throws Exception { DatasetCriteria datasetCriteria = new DatasetCriteria(); datasetCriteria.setTags(datasetTableRequest.getCriteria().getTags()); List datasets; try{ - datasets = datasetCriteria.getTags() != null && datasetCriteria.getTags().size() > 0 && apiContext.getOperationsContext().getDatasetRepository().exists() ? - apiContext.getOperationsContext().getDatasetRepository().query(datasetCriteria) : new LinkedList<>(); + datasets = datasetCriteria.getTags() != null && datasetCriteria.getTags().size() > 0 && datasetRepository.exists() ? + datasetRepository.query(datasetCriteria) : new LinkedList<>(); } catch (Exception ex){ datasets = null; } - datasetTableRequest.setQuery(apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class))); + datasetTableRequest.setQuery(databaseRepository.getDatasetDao().asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class))); QueryableList items = datasetTableRequest.applyCriteria(); if (datasets != null && datasetTableRequest.getCriteria().getTags() != null && !datasetTableRequest.getCriteria().getTags().isEmpty()) { if (!datasets.isEmpty()) { @@ -125,13 +142,13 @@ public class DatasetManager { return dataTable; } - public DatasetWizardModel getSingle(DatasetDao datatasetRepository, DatasetRepository elasticDatasetRepository, String id) throws InstantiationException, IllegalAccessException, IOException { + public DatasetWizardModel getSingle(String id) throws InstantiationException, IllegalAccessException, IOException { DatasetWizardModel dataset = new DatasetWizardModel(); - eu.eudat.data.entities.Dataset datasetEntity = datatasetRepository.find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); + eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); eu.eudat.elastic.entities.Dataset datasetElastic; try{ - datasetElastic = elasticDatasetRepository.exists() ? - elasticDatasetRepository.findDocument(id) : new eu.eudat.elastic.entities.Dataset(); + datasetElastic = datasetRepository.exists() ? + datasetRepository.findDocument(id) : new eu.eudat.elastic.entities.Dataset(); } catch (Exception ex){ datasetElastic = new eu.eudat.elastic.entities.Dataset(); @@ -143,7 +160,7 @@ public class DatasetManager { } public PagedDatasetProfile getPagedProfile(DatasetWizardModel dataset, eu.eudat.data.entities.Dataset datasetEntity) { - eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = UserManager.generateDatasetProfileModel(datasetEntity.getProfile()); + eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = userManager.generateDatasetProfileModel(datasetEntity.getProfile()); datasetprofile.setStatus(dataset.getStatus()); if (datasetEntity.getProperties() != null) { JSONObject jobject = new JSONObject(datasetEntity.getProperties()); @@ -155,13 +172,13 @@ public class DatasetManager { return pagedDatasetProfile; } - public File getWordDocument(Environment environment, DatasetDao datatasetRepository, String id, VisibilityRuleService visibilityRuleService) throws InstantiationException, IllegalAccessException, IOException { + public File getWordDocument(Environment environment, String id, VisibilityRuleService visibilityRuleService) throws InstantiationException, IllegalAccessException, IOException { WordBuilder wordBuilder = new WordBuilder(); DatasetWizardModel dataset = new DatasetWizardModel(); String fileUrl = environment.getProperty("configuration.h2020template"); InputStream is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream(); XWPFDocument document = new XWPFDocument(is); - eu.eudat.data.entities.Dataset datasetEntity = datatasetRepository.find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); + eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); Map properties = new HashMap<>(); if (datasetEntity.getProperties() != null) { JSONObject jobject = new JSONObject(datasetEntity.getProperties()); @@ -178,10 +195,10 @@ public class DatasetManager { return exportFile; } - public FileEnvelope getXmlDocument(DatasetDao datatasetRepository, String id, VisibilityRuleService visibilityRuleService) throws InstantiationException, IllegalAccessException, IOException { + public FileEnvelope getXmlDocument(String id, VisibilityRuleService visibilityRuleService) throws InstantiationException, IllegalAccessException, IOException { ExportXmlBuilder xmlBuilder = new ExportXmlBuilder(); DatasetWizardModel dataset = new DatasetWizardModel(); - eu.eudat.data.entities.Dataset datasetEntity = datatasetRepository.find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); + eu.eudat.data.entities.Dataset datasetEntity = databaseRepository.getDatasetDao().find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); Map properties = new HashMap<>(); if (datasetEntity.getProperties() != null) { JSONObject jobject = new JSONObject(datasetEntity.getProperties()); @@ -263,7 +280,7 @@ public class DatasetManager { return newFile; } - public eu.eudat.data.entities.Dataset createOrUpdate(ApiContext apiContext, DatasetWizardModel datasetWizardModel, Principal principal) throws Exception { + public eu.eudat.data.entities.Dataset createOrUpdate(DatasetWizardModel datasetWizardModel, Principal principal) throws Exception { eu.eudat.data.entities.Dataset dataset = datasetWizardModel.toDataModel(); propertiesModelToString(datasetWizardModel, dataset); UserInfo userInfo = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build(); @@ -271,8 +288,8 @@ public class DatasetManager { updateTags(apiContext.getOperationsContext().getDatasetRepository(), datasetWizardModel); createRegistriesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao(), dataset); createDataRepositoriesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao(), dataset); - createServicesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getDatasetServiceDao(), apiContext.getOperationsContext().getDatabaseRepository().getServiceDao(), dataset); - createExternalDatasetsIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getDatasetExternalDatasetDao(), apiContext.getOperationsContext().getDatabaseRepository().getExternalDatasetDao(), dataset); + createServicesIfTheyDontExist(dataset); + createExternalDatasetsIfTheyDontExist(dataset); return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(dataset); } @@ -328,20 +345,20 @@ public class DatasetManager { } } - private void createServicesIfTheyDontExist(DatasetServiceDao datasetServiceDao, ServiceDao serviceDao, eu.eudat.data.entities.Dataset dataset) { + private void createServicesIfTheyDontExist(eu.eudat.data.entities.Dataset dataset) { Set services = dataset.getServices(); dataset.setServices(new HashSet<>()); if (services != null && !services.isEmpty()) { for (eu.eudat.data.entities.DatasetService datasetService : services) { ServiceCriteria criteria = new ServiceCriteria(); criteria.setLike(datasetService.getService().getLabel()); - List entries = serviceDao.getWithCriteria(criteria).toList(); + List entries = databaseRepository.getServiceDao().getWithCriteria(criteria).toList(); if (entries != null && !entries.isEmpty()) { datasetService.getService().setId(entries.get(0).getId()); datasetService.setDataset(dataset); dataset.getServices().add(datasetService); } else { - Service service = serviceDao.createOrUpdate(datasetService.getService()); + Service service = databaseRepository.getServiceDao().createOrUpdate(datasetService.getService()); datasetService.setService(service); dataset.getServices().add(datasetService); } @@ -349,20 +366,20 @@ public class DatasetManager { } } - private void createExternalDatasetsIfTheyDontExist(DatasetExternalDatasetDao datasetExternalDatasetDao, ExternalDatasetDao externalDatasetDao, eu.eudat.data.entities.Dataset dataset) { + private void createExternalDatasetsIfTheyDontExist(eu.eudat.data.entities.Dataset dataset) { Set externalDatasets = dataset.getDatasetExternalDatasets(); dataset.setDatasetExternalDatasets(new HashSet<>()); if (externalDatasets != null && !externalDatasets.isEmpty()) { for (eu.eudat.data.entities.DatasetExternalDataset datasetExternalDataset : externalDatasets) { ExternalDatasetCriteria criteria = new ExternalDatasetCriteria(); criteria.setLike(datasetExternalDataset.getExternalDataset().getLabel()); - List entries = externalDatasetDao.getWithCriteria(criteria).toList(); + List entries = databaseRepository.getExternalDatasetDao().getWithCriteria(criteria).toList(); if (entries != null && !entries.isEmpty()) { datasetExternalDataset.getExternalDataset().setId(entries.get(0).getId()); datasetExternalDataset.setDataset(dataset); dataset.getDatasetExternalDatasets().add(datasetExternalDataset); } else { - ExternalDataset externalDataset = externalDatasetDao.createOrUpdate(datasetExternalDataset.getExternalDataset()); + ExternalDataset externalDataset = databaseRepository.getExternalDatasetDao().createOrUpdate(datasetExternalDataset.getExternalDataset()); datasetExternalDataset.setExternalDataset(externalDataset); dataset.getDatasetExternalDatasets().add(datasetExternalDataset); } @@ -377,8 +394,8 @@ public class DatasetManager { datasetDao.createOrUpdate(dataset); } - public ResponseEntity getDocument(DatasetDao datasetDao, String id, VisibilityRuleService visibilityRuleService, String contentType) throws IllegalAccessException, IOException, InstantiationException { - FileEnvelope envelope = getXmlDocument(datasetDao, id, visibilityRuleService); + public ResponseEntity getDocument(String id, VisibilityRuleService visibilityRuleService, String contentType) throws IllegalAccessException, IOException, InstantiationException { + FileEnvelope envelope = getXmlDocument(id, visibilityRuleService); InputStream resource = new FileInputStream(envelope.getFile()); System.out.println("Mime Type of " + envelope.getFilename() + " is " + new MimetypesFileTypeMap().getContentType(envelope.getFile())); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetProfileManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetProfileManager.java index 46a89ea40..347e69513 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetProfileManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetProfileManager.java @@ -9,6 +9,7 @@ import eu.eudat.data.query.items.item.datasetprofile.DatasetProfileAutocompleteR import eu.eudat.data.query.items.table.datasetprofile.DatasetProfileTableRequestItem; import eu.eudat.logic.builders.model.models.DataTableDataBuilder; import eu.eudat.logic.services.ApiContext; +import eu.eudat.logic.services.operations.DatabaseRepository; import eu.eudat.logic.utilities.builders.XmlBuilder; import eu.eudat.logic.utilities.documents.helpers.FileEnvelope; import eu.eudat.logic.utilities.documents.xml.datasetProfileXml.ExportXmlBuilderDatasetProfile; @@ -20,6 +21,7 @@ import eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Field; import eu.eudat.models.data.helpermodels.Tuple; import eu.eudat.models.data.helpers.common.DataTableData; import eu.eudat.queryable.QueryableList; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.*; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; @@ -39,29 +41,37 @@ import java.io.*; @Component public class DatasetProfileManager { - public List getWithCriteria(DatasetProfileDao datasetProfileRepository, DatasetProfileAutocompleteRequest datasetProfileAutocompleteRequest) throws IllegalAccessException, InstantiationException { - QueryableList items = datasetProfileRepository.getWithCriteria(datasetProfileAutocompleteRequest.getCriteria()); + private ApiContext apiContext; + private DatabaseRepository databaseRepository; + @Autowired + public DatasetProfileManager(ApiContext apiContext) { + this.apiContext = apiContext; + this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository(); + } + + public List getWithCriteria(DatasetProfileAutocompleteRequest datasetProfileAutocompleteRequest) throws IllegalAccessException, InstantiationException { + QueryableList items = databaseRepository.getDatasetProfileDao().getWithCriteria(datasetProfileAutocompleteRequest.getCriteria()); List datasetProfiles = items.select(item -> new DatasetProfileAutocompleteItem().fromDataModel(item)); return datasetProfiles; } - public DatasetProfile clone(ApiContext apiContext, String id) { + public DatasetProfile clone(String id) { DatasetProfile profile = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); apiContext.getOperationsContext().getDatabaseRepository().detachEntity(profile); profile.setId(null); return profile; } - public DataTableData getPaged(ApiContext apiContext, DatasetProfileTableRequestItem datasetProfileTableRequestItem) throws Exception { + public DataTableData getPaged(DatasetProfileTableRequestItem datasetProfileTableRequestItem) throws Exception { QueryableList items = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().getWithCriteria(datasetProfileTableRequestItem.getCriteria()); QueryableList pagedItems = PaginationManager.applyPaging(items, datasetProfileTableRequestItem); List datasetProfiles = pagedItems.select(item -> new DatasetProfileListingModel().fromDataModel(item)); return apiContext.getOperationsContext().getBuilderFactory().getBuilder(DataTableDataBuilder.class).data(datasetProfiles).totalCount(items.count()).build(); } - public List getAll(DatasetProfileDao datasetProfileRepository) throws IllegalAccessException, InstantiationException { + public List getAll() throws IllegalAccessException, InstantiationException { DatasetProfileCriteria criteria = new DatasetProfileCriteria(); - QueryableList items = datasetProfileRepository.getWithCriteria(criteria); + QueryableList items = databaseRepository.getDatasetProfileDao().getWithCriteria(criteria); List datasetProfiles = items.select(item -> new DatasetProfileListingModel().fromDataModel(item)); return datasetProfiles; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DocumentManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DocumentManager.java index aa55c92f5..87ba688ca 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DocumentManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DocumentManager.java @@ -1,6 +1,7 @@ package eu.eudat.logic.managers; import eu.eudat.data.dao.entities.DatasetDao; +import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.forms.VisibilityRuleService; import eu.eudat.logic.utilities.documents.helpers.FileEnvelope; import eu.eudat.logic.utilities.documents.word.WordBuilder; @@ -11,10 +12,12 @@ import eu.eudat.models.data.user.composite.PagedDatasetProfile; import org.apache.commons.io.IOUtils; import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.env.Environment; import org.springframework.core.io.FileSystemResource; import org.springframework.http.*; import org.springframework.http.converter.ByteArrayHttpMessageConverter; +import org.springframework.stereotype.Service; import org.springframework.util.LinkedMultiValueMap; import org.springframework.web.client.RestTemplate; @@ -31,7 +34,16 @@ import java.util.zip.ZipInputStream; /** * Created by ikalyvas on 10/16/2018. */ +@Service public class DocumentManager { + + private ApiContext context; + private DatasetManager datasetManager; + public DocumentManager(ApiContext context, DatasetManager datasetManager) { + this.context = context; + this.datasetManager = datasetManager; + } + public File getWordDocument(Environment environment, DatasetDao datatasetRepository, String id, VisibilityRuleService visibilityRuleService) throws InstantiationException, IllegalAccessException, IOException { WordBuilder wordBuilder = new WordBuilder(); DatasetWizardModel dataset = new DatasetWizardModel(); @@ -44,7 +56,7 @@ public class DocumentManager { JSONObject jobject = new JSONObject(datasetEntity.getProperties()); properties = jobject.toMap(); } - PagedDatasetProfile pagedDatasetProfile = new DatasetManager().getPagedProfile(dataset, datasetEntity); + PagedDatasetProfile pagedDatasetProfile = datasetManager.getPagedProfile(dataset, datasetEntity); visibilityRuleService.setProperties(properties); visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules()); wordBuilder.build(document, pagedDatasetProfile, visibilityRuleService); @@ -63,7 +75,7 @@ public class DocumentManager { JSONObject jobject = new JSONObject(datasetEntity.getProperties()); properties = jobject.toMap(); } - PagedDatasetProfile pagedDatasetProfile = new DatasetManager().getPagedProfile(dataset, datasetEntity); + PagedDatasetProfile pagedDatasetProfile = datasetManager.getPagedProfile(dataset, datasetEntity); visibilityRuleService.setProperties(properties); visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules()); File file = xmlBuilder.build(pagedDatasetProfile, visibilityRuleService); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ExternalDatasetManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ExternalDatasetManager.java index 43300e9d8..cab3d39b4 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ExternalDatasetManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ExternalDatasetManager.java @@ -5,6 +5,7 @@ import eu.eudat.logic.builders.model.models.DataTableDataBuilder; import eu.eudat.data.dao.entities.ExternalDatasetDao; import eu.eudat.data.entities.ExternalDataset; import eu.eudat.data.dao.criteria.ExternalDatasetCriteria; +import eu.eudat.logic.services.operations.DatabaseRepository; import eu.eudat.models.data.externaldataset.ExternalDatasetListingModel; import eu.eudat.data.query.items.table.externaldataset.ExternalDatasetTableRequest; import eu.eudat.models.data.helpers.common.DataTableData; @@ -13,6 +14,7 @@ import eu.eudat.logic.proxy.config.exceptions.NoURLFound; import eu.eudat.logic.proxy.fetching.RemoteFetcher; import eu.eudat.queryable.QueryableList; import eu.eudat.logic.services.ApiContext; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @@ -21,28 +23,38 @@ import java.util.UUID; @Component public class ExternalDatasetManager { - public DataTableData getPaged(ApiContext apiContext, ExternalDatasetTableRequest externalDatasetTableRequest) throws Exception { + private ApiContext apiContext; + private DatabaseRepository databaseRepository; + private RemoteFetcher remoteFetcher; + @Autowired + public ExternalDatasetManager(ApiContext apiContext) { + this.apiContext = apiContext; + this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository(); + this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher(); + } + + public DataTableData getPaged(ExternalDatasetTableRequest externalDatasetTableRequest) throws Exception { QueryableList items = apiContext.getOperationsContext().getDatabaseRepository().getExternalDatasetDao().getWithCriteria(externalDatasetTableRequest.getCriteria()); QueryableList pagedItems = PaginationManager.applyPaging(items, externalDatasetTableRequest); List externalDatasetListingmodels = pagedItems.select(item -> new ExternalDatasetListingModel().fromDataModel(item)); return apiContext.getOperationsContext().getBuilderFactory().getBuilder(DataTableDataBuilder.class).data(externalDatasetListingmodels).totalCount(items.count()).build(); } - public List getWithExternal(ApiContext apiContext, String query, RemoteFetcher remoteFetcher) throws HugeResultSet, NoURLFound, InstantiationException, IllegalAccessException { + public List getWithExternal(String query) throws HugeResultSet, NoURLFound, InstantiationException, IllegalAccessException { ExternalDatasetCriteria criteria = apiContext.getOperationsContext().getBuilderFactory().getBuilder(ExternalDatasetCriteriaBuilder.class).like(query).build(); QueryableList items = apiContext.getOperationsContext().getDatabaseRepository().getExternalDatasetDao().getWithCriteria(criteria); List externalDatasets = items.select(item -> new ExternalDatasetListingModel().fromDataModel(item)); return externalDatasets; } - public ExternalDatasetListingModel getSingle(ExternalDatasetDao externalDatasetDao, UUID id) throws HugeResultSet, NoURLFound, InstantiationException, IllegalAccessException { - ExternalDataset externalDataset = externalDatasetDao.find(id); + public ExternalDatasetListingModel getSingle(UUID id) throws HugeResultSet, NoURLFound, InstantiationException, IllegalAccessException { + ExternalDataset externalDataset = databaseRepository.getExternalDatasetDao().find(id); ExternalDatasetListingModel externalDatasetModel = new ExternalDatasetListingModel(); externalDatasetModel.fromDataModel(externalDataset); return externalDatasetModel; } - public ExternalDataset create(ApiContext apiContext, eu.eudat.models.data.externaldataset.ExternalDatasetModel externalDatasetModel) throws Exception { + public ExternalDataset create(eu.eudat.models.data.externaldataset.ExternalDatasetModel externalDatasetModel) throws Exception { ExternalDataset externalDataset = externalDatasetModel.toDataModel(); return apiContext.getOperationsContext().getDatabaseRepository().getExternalDatasetDao().createOrUpdate(externalDataset); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/FileManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/FileManager.java index 823cffc17..b25c4ce43 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/FileManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/FileManager.java @@ -2,7 +2,9 @@ package eu.eudat.logic.managers; import eu.eudat.models.data.files.ContentFile; import eu.eudat.logic.services.helpers.FileStorageService; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.Resource; +import org.springframework.stereotype.Component; import org.springframework.web.multipart.MultipartFile; import java.io.IOException; @@ -11,13 +13,21 @@ import java.util.List; /** * Created by ikalyvas on 3/15/2018. */ +@Component public class FileManager { - public static List saveTempFile(MultipartFile file[], FileStorageService fileStorageService) throws IOException { + private FileStorageService fileStorageService; + + @Autowired + public FileManager(FileStorageService fileStorageService) { + this.fileStorageService = fileStorageService; + } + + public List saveTempFile(MultipartFile file[]) throws IOException { return fileStorageService.writeToTempFileSystem(file); } - public static Resource getFile(String filename, String type, FileStorageService fileStorageService, String location) throws IOException { + public Resource getFile(String filename, String type, String location) throws IOException { return fileStorageService.readFromFilesystem(filename, type, location); } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/InvitationsManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/InvitationsManager.java index a31b0a220..2072bdae4 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/InvitationsManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/InvitationsManager.java @@ -9,15 +9,24 @@ import eu.eudat.models.data.userinfo.UserInfoInvitationModel; import eu.eudat.data.query.items.item.userinfo.UserInfoRequestItem; import eu.eudat.queryable.QueryableList; import eu.eudat.logic.services.ApiContext; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import java.util.List; import java.util.UUID; import java.util.stream.Collectors; - +@Component public class InvitationsManager { - public static void inviteUsers(ApiContext apiContext, Invitation invitation, Principal principal) throws Exception { + private ApiContext apiContext; + + @Autowired + public InvitationsManager(ApiContext apiContext) { + this.apiContext = apiContext; + } + + public void inviteUsers(Invitation invitation, Principal principal) throws Exception { UserInfo principalUser = new UserInfo(); principalUser.setId(principal.getId()); List alreadySignedInUsers = invitation.getUsers().stream().filter(item -> item.getId() != null).collect(Collectors.toList()); @@ -27,13 +36,13 @@ public class InvitationsManager { apiContext.getUtilitiesService().getInvitationService().assignToDmp(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao(), alreadySignedInUsersEntities, dataManagementPlan); } - public static List getUsers(ApiContext apiContext, UserInfoRequestItem userInfoRequestItem) throws InstantiationException, IllegalAccessException { + public List getUsers(UserInfoRequestItem userInfoRequestItem) throws InstantiationException, IllegalAccessException { QueryableList users = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().getWithCriteria(userInfoRequestItem.getCriteria()); List userModels = users.select(item -> new UserInfoInvitationModel().fromDataModel(item)); return userModels; } - public static UUID assignUserAcceptedInvitation(ApiContext apiContext, UUID invitationID, Principal principal) throws UnauthorisedException { + public UUID assignUserAcceptedInvitation(UUID invitationID, Principal principal) throws UnauthorisedException { eu.eudat.data.entities.Invitation invitation = apiContext.getOperationsContext().getDatabaseRepository().getInvitationDao().find(invitationID); if (invitation == null) throw new UnauthorisedException("There is no Data Management Plan assigned to this Link"); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ProjectManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ProjectManager.java index 82baf0105..29aaa494d 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ProjectManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ProjectManager.java @@ -9,6 +9,7 @@ import eu.eudat.data.dao.entities.UserInfoDao; import eu.eudat.data.entities.Content; import eu.eudat.data.entities.DMP; import eu.eudat.exceptions.files.TempFileNotFoundException; +import eu.eudat.logic.services.operations.DatabaseRepository; import eu.eudat.models.HintedModelFactory; import eu.eudat.models.data.external.ExternalSourcesItemModel; import eu.eudat.models.data.external.ProjectsExternalSourcesModel; @@ -39,12 +40,24 @@ import java.util.stream.Collectors; @Component public class ProjectManager { - public DataTableData getPaged(ProjectDao projectRepository, ProjectTableRequest projectTableRequest, Principal principal, String fieldsGroup) throws Exception { + private ApiContext apiContext; + private DatabaseRepository databaseRepository; + private FileStorageService fileStorageService; + private RemoteFetcher remoteFetcher; + + public ProjectManager(ApiContext apiContext) { + this.apiContext = apiContext; + this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository(); + this.fileStorageService = apiContext.getOperationsContext().getFileStorageService(); + this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher(); + } + + public DataTableData getPaged(ProjectTableRequest projectTableRequest, Principal principal, String fieldsGroup) throws Exception { eu.eudat.data.entities.UserInfo userInfo = new eu.eudat.data.entities.UserInfo(); userInfo.setId(principal.getId()); + ProjectDao projectRepository = databaseRepository.getProjectDao(); QueryableList items = projectRepository.getWithCriteria(projectTableRequest.getCriteria()); QueryableList authItems = projectRepository.getAuthenticated(items, userInfo); - QueryableList pagedItems = PaginationManager.applyPaging(authItems, projectTableRequest); DataTableData dataTable = new DataTableData<>(); CompletableFuture projectsFuture; @@ -75,20 +88,21 @@ public class ProjectManager { return dataTable; } - public eu.eudat.models.data.project.Project getSingle(ProjectDao projectRepository, String id) throws InstantiationException, IllegalAccessException { + public eu.eudat.models.data.project.Project getSingle(String id) throws InstantiationException, IllegalAccessException { eu.eudat.models.data.project.Project project = new eu.eudat.models.data.project.Project(); - project.fromDataModel(projectRepository.find(UUID.fromString(id))); + project.fromDataModel(databaseRepository.getProjectDao().find(UUID.fromString(id))); return project; } - public eu.eudat.data.entities.Project inactivate(ProjectDao projectRepository, String id) throws InstantiationException, IllegalAccessException { + public eu.eudat.data.entities.Project inactivate(String id) throws InstantiationException, IllegalAccessException { + ProjectDao projectRepository = databaseRepository.getProjectDao(); eu.eudat.data.entities.Project project = projectRepository.find(UUID.fromString(id)); project.setStatus(eu.eudat.data.entities.Project.Status.DELETED.getValue()); project = projectRepository.createOrUpdate(project); return project; } - public List getCriteriaWithExternal(ApiContext apiContext, ProjectCriteriaRequest projectCriteria, RemoteFetcher remoteFetcher, Principal principal) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound { + public List getCriteriaWithExternal(ProjectCriteriaRequest projectCriteria, Principal principal) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound { eu.eudat.data.entities.UserInfo userInfo = new eu.eudat.data.entities.UserInfo(); userInfo.setId(principal.getId()); QueryableList items = apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().getWithCriteria(projectCriteria.getCriteria()); @@ -109,14 +123,15 @@ public class ProjectManager { return projects; } - public List getCriteria(ProjectDao projectRepository, ProjectCriteriaRequest projectCriteria, RemoteFetcher remoteFetcher) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound { + public List getCriteria(ProjectCriteriaRequest projectCriteria) throws IllegalAccessException, InstantiationException, HugeResultSet, NoURLFound { + ProjectDao projectRepository = databaseRepository.getProjectDao(); QueryableList items = projectRepository.getWithCriteria(projectCriteria.getCriteria()); if (projectCriteria.getLength() != null) items.take(projectCriteria.getLength()); List projects = items.select(item -> new Project().fromDataModel(item)); return projects; } - public static void createOrUpdate(FileStorageService fileStorageService, ProjectDao projectRepository, ContentDao contentRepository, UserInfoDao userInfoRepository, eu.eudat.models.data.project.Project project, Principal principal) throws ParseException, IOException { + public void createOrUpdate(eu.eudat.models.data.project.Project project, Principal principal) throws ParseException, IOException { eu.eudat.data.entities.Project projectEntity = project.toDataModel(); if (project.getFiles() != null) { for (ContentFile file : project.getFiles()) { @@ -128,18 +143,18 @@ public class ProjectManager { .parentType(Content.ParentType.PROJECT.getValue()) .uri("LOCAL:" + storedFile.getId()) .build(); - projectEntity.setContent(contentRepository.createOrUpdate(content)); + projectEntity.setContent(databaseRepository.getContentDao().createOrUpdate(content)); } catch (TempFileNotFoundException e) { continue; } } } projectEntity.setType(eu.eudat.data.entities.Project.ProjectType.INTERNAL.getValue()); - projectEntity.setCreationUser(userInfoRepository.find(principal.getId())); - projectRepository.createOrUpdate(projectEntity); + projectEntity.setCreationUser(databaseRepository.getUserInfoDao().find(principal.getId())); + databaseRepository.getProjectDao().createOrUpdate(projectEntity); } - public void delete(ApiContext apiContext, UUID uuid) { + public void delete(UUID uuid) { eu.eudat.data.entities.Project oldProject = apiContext.getOperationsContext().getDatabaseRepository().getProjectDao().find(uuid); if (oldProject.getDmps().size() > 0) throw new ProjectWithDMPsDeleteException("You cannot Remove Projects with DMPs"); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/QuickWizardManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/QuickWizardManager.java index 0d3932f82..b2ab4d993 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/QuickWizardManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/QuickWizardManager.java @@ -1,15 +1,17 @@ package eu.eudat.logic.managers; -import eu.eudat.data.dao.entities.ContentDao; -import eu.eudat.data.dao.entities.ProjectDao; -import eu.eudat.data.dao.entities.UserInfoDao; -import eu.eudat.data.entities.*; +import eu.eudat.data.entities.DMP; +import eu.eudat.data.entities.Project; +import eu.eudat.data.entities.UserInfo; import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.helpers.FileStorageService; +import eu.eudat.logic.services.operations.DatabaseRepository; import eu.eudat.models.data.dmp.DataManagementPlan; +import eu.eudat.models.data.quickwizard.DatasetDescriptionQuickWizardModel; +import eu.eudat.models.data.quickwizard.QuickWizardModel; import eu.eudat.models.data.security.Principal; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import eu.eudat.data.entities.DMP; import java.io.IOException; import java.text.ParseException; @@ -17,31 +19,45 @@ import java.text.ParseException; @Component public class QuickWizardManager { + private ApiContext apiContext; + private DatabaseRepository databaseRepository; + private FileStorageService fileStorageService; + private DatasetManager datasetManager; - public static Project createOrUpdate(FileStorageService fileStorageService, ProjectDao projectRepository, ContentDao contentRepository, UserInfoDao userInfoRepository, eu.eudat.models.data.project.Project project, Principal principal) throws ParseException, IOException { - eu.eudat.data.entities.Project projectEntity = project.toDataModel(); - projectEntity.setType(eu.eudat.data.entities.Project.ProjectType.INTERNAL.getValue()); - projectEntity.setCreationUser(userInfoRepository.find(principal.getId())); - Project projectEntityRet = projectRepository.createOrUpdate(projectEntity); - return projectEntityRet; - } + @Autowired + public QuickWizardManager(ApiContext apiContext, DatasetManager datasetManager) { + this.apiContext = apiContext; + this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository(); + this.fileStorageService = apiContext.getOperationsContext().getFileStorageService(); + } - public DMP createOrUpdate(ApiContext apiContext, DataManagementPlan dataManagementPlan, Principal principal) throws Exception { - DMP newDmp = dataManagementPlan.toDataModel(); - UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId()); - newDmp.setCreator(user); - DMP dmpret = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp); - return dmpret; - } + public void createOrUpdate(QuickWizardModel quickWizard, Principal principal) throws Exception { + //Create Project + eu.eudat.data.entities.Project projectEntity = createOrUpdate(quickWizard.getProject().toDataProject(), principal); - /*public void createOrUpdate(ApiContext apiContext, DatasetDao datasetRepository,DMP dmp, eu.eudat.data.entities.DatasetProfile profile , DatasetQuickWizardModel datasetwrapper, Principal principal) throws Exception { - - for (DatasetDescriptionQuickWizardModel dataset :datasetwrapper.getDatasetsList()){ - datasetRepository.createOrUpdate(dataset.toDataModel(dmp,profile)); - } - - }*/ + //Create Dmp + eu.eudat.data.entities.DMP dmpEntity = createOrUpdate(quickWizard.getDmp().toDataDmp(projectEntity), principal); + //Create Datasets + quickWizard.getDmp().setId(dmpEntity.getId()); + for(DatasetDescriptionQuickWizardModel dataset : quickWizard.getDatasets().getDatasetsList()){ + this.datasetManager.createOrUpdate(dataset.toDataModel(quickWizard.getDmp().toDataDmp(projectEntity),quickWizard.getDmp().getDatasetProfile().getId()), principal); + } + } + private Project createOrUpdate(eu.eudat.models.data.project.Project project, Principal principal) throws ParseException, IOException { + eu.eudat.data.entities.Project projectEntity = project.toDataModel(); + projectEntity.setType(eu.eudat.data.entities.Project.ProjectType.INTERNAL.getValue()); + projectEntity.setCreationUser(databaseRepository.getUserInfoDao().find(principal.getId())); + Project projectEntityRet = databaseRepository.getProjectDao().createOrUpdate(projectEntity); + return projectEntityRet; + } + private DMP createOrUpdate(DataManagementPlan dataManagementPlan, Principal principal) throws Exception { + DMP newDmp = dataManagementPlan.toDataModel(); + UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId()); + newDmp.setCreator(user); + DMP dmpret = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp); + return dmpret; + } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/RegistryManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/RegistryManager.java index e7ffe9f44..33016f094 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/RegistryManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/RegistryManager.java @@ -5,14 +5,20 @@ import eu.eudat.data.entities.Registry; import eu.eudat.logic.services.ApiContext; import eu.eudat.models.data.datarepository.DataRepositoryModel; import eu.eudat.models.data.registries.RegistryModel; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -/** - * Created by ikalyvas on 9/3/2018. - */ @Component public class RegistryManager { - public Registry create(ApiContext apiContext, RegistryModel registryModel) throws Exception { + + private ApiContext apiContext; + + @Autowired + public RegistryManager(ApiContext apiContext) { + this.apiContext = apiContext; + } + + public Registry create(RegistryModel registryModel) throws Exception { Registry registry = registryModel.toDataModel(); return apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao().createOrUpdate(registry); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ResearcherManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ResearcherManager.java index 1671dd91d..eba923904 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ResearcherManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ResearcherManager.java @@ -10,6 +10,7 @@ import eu.eudat.logic.proxy.config.exceptions.NoURLFound; import eu.eudat.logic.proxy.fetching.RemoteFetcher; import eu.eudat.queryable.QueryableList; import eu.eudat.logic.services.ApiContext; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import java.util.List; @@ -22,12 +23,21 @@ import java.util.stream.Collectors; @Component public class ResearcherManager { - public Researcher create(ApiContext apiContext, eu.eudat.models.data.researcher.Researcher researcher) throws Exception { + private ApiContext apiContext; + private RemoteFetcher remoteFetcher; + + @Autowired + public ResearcherManager(ApiContext apiContext) { + this.apiContext = apiContext; + this.remoteFetcher = apiContext.getOperationsContext().getRemoteFetcher(); + } + + public Researcher create(eu.eudat.models.data.researcher.Researcher researcher) throws Exception { Researcher researcherEntity = researcher.toDataModel(); return apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao().createOrUpdate(researcherEntity); } - public List getCriteriaWithExternal(ApiContext apiContext, RemoteFetcher remoteFetcher, ResearcherCriteriaRequest researcherCriteriaRequest) throws HugeResultSet, NoURLFound { + public List getCriteriaWithExternal(ResearcherCriteriaRequest researcherCriteriaRequest) throws HugeResultSet, NoURLFound { QueryableList items = apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao().getWithCriteria(researcherCriteriaRequest.getCriteria()); List researchers = items.select(item -> new eu.eudat.models.data.dmp.Researcher().fromDataModel(item)); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ServiceManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ServiceManager.java index 9b42a2d90..109c972a8 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ServiceManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ServiceManager.java @@ -5,12 +5,23 @@ import eu.eudat.data.entities.Service; import eu.eudat.logic.services.ApiContext; import eu.eudat.models.data.registries.RegistryModel; import eu.eudat.models.data.services.ServiceModel; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; /** * Created by ikalyvas on 9/3/2018. */ +@Component public class ServiceManager { - public static Service create(ApiContext apiContext, ServiceModel serviceModel) throws Exception { + + private ApiContext apiContext; + + @Autowired + public ServiceManager(ApiContext apiContext) { + this.apiContext = apiContext; + } + + public Service create(ServiceModel serviceModel) throws Exception { Service service = serviceModel.toDataModel(); return apiContext.getOperationsContext().getDatabaseRepository().getServiceDao().createOrUpdate(service); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/UserManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/UserManager.java index cc237a29d..98bbf8a9f 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/UserManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/UserManager.java @@ -19,6 +19,8 @@ import eu.eudat.models.data.userinfo.UserListingModel; import eu.eudat.models.data.userinfo.UserProfile; import eu.eudat.queryable.QueryableList; import org.json.JSONObject; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -29,8 +31,17 @@ import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; +@Component public class UserManager { - public static eu.eudat.models.data.user.composite.DatasetProfile generateDatasetProfileModel(eu.eudat.data.entities.DatasetProfile profile) { + + private ApiContext apiContext; + + @Autowired + public UserManager(ApiContext apiContext) { + this.apiContext = apiContext; + } + + public eu.eudat.models.data.user.composite.DatasetProfile generateDatasetProfileModel(eu.eudat.data.entities.DatasetProfile profile) { Document viewStyleDoc = XmlBuilder.fromXml(profile.getDefinition()); Element root = (Element) viewStyleDoc.getDocumentElement(); eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.ViewStyleModel viewstyle = new eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.ViewStyleModel().fromXml(root); @@ -41,7 +52,7 @@ public class UserManager { return datasetprofile; } - public static DataTableData getPaged(ApiContext apiContext, UserInfoTableRequestItem userInfoTableRequestItem) throws Exception { + public DataTableData getPaged(UserInfoTableRequestItem userInfoTableRequestItem) throws Exception { QueryableList users = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().getWithCriteria(userInfoTableRequestItem.getCriteria()).withHint(HintedModelFactory.getHint(UserListingModel.class)); QueryableList pagedUsers = PaginationManager.applyPaging(users, userInfoTableRequestItem); @@ -49,7 +60,7 @@ public class UserManager { return apiContext.getOperationsContext().getBuilderFactory().getBuilder(DataTableDataBuilder.class).totalCount(users.count()).data(modelUsers).build(); } - public static UserProfile getSingle(ApiContext apiContext, UUID userId) throws Exception { + public UserProfile getSingle(UUID userId) throws Exception { eu.eudat.data.entities.UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(userId); UserProfile profile = new UserProfile().fromDataModel(user); List dmps = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getAuthenticated(apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().asQueryable(), user).take(5).toList(); @@ -57,7 +68,7 @@ public class UserManager { return profile; } - public static void editRoles(ApiContext apiContext, UserListingModel user) { + public void editRoles(UserListingModel user) { eu.eudat.data.entities.UserInfo userInfo = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(user.getId()); userInfo.getUserRoles().stream().forEach(item -> apiContext.getOperationsContext().getDatabaseRepository().getUserRoleDao().delete(item)); for (Integer role : user.getAppRoles()) { @@ -66,7 +77,7 @@ public class UserManager { } } - public static void updateSettings(ApiContext apiContext, Map settings, Principal principal) throws IOException { + public void updateSettings(Map settings, Principal principal) throws IOException { eu.eudat.data.entities.UserInfo userInfo = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId()); apiContext.getOperationsContext().getDatabaseRepository().detachEntity(userInfo); HashMap result = @@ -77,7 +88,7 @@ public class UserManager { .createOrUpdate(userInfo); } - public static Principal authenticate(AuthenticationServiceImpl authenticationServiceImpl, Credentials credentials) { + public Principal authenticate(AuthenticationServiceImpl authenticationServiceImpl, Credentials credentials) { Principal principal = authenticationServiceImpl.Touch(credentials); if (principal == null) throw new UnauthorisedException("Could not Sign In User"); return principal; From 90aace8e68326906e9c13144b55680de74b56d14 Mon Sep 17 00:00:00 2001 From: ikalyvas Date: Tue, 5 Mar 2019 18:08:38 +0200 Subject: [PATCH 2/2] Fixes bug with QuickWizard Profile name on backend model --- .../controllers/QuickWizardController.java | 2 - .../eudat/logic/managers/DatasetManager.java | 1 + .../data/quickwizard/DmpQuickWizardModel.java | 146 +++++++++--------- 3 files changed, 71 insertions(+), 78 deletions(-) diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/QuickWizardController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/QuickWizardController.java index d1589a1eb..eb1c6e905 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/QuickWizardController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/QuickWizardController.java @@ -51,7 +51,6 @@ public class QuickWizardController extends BaseController { //Create Dmp eu.eudat.data.entities.DMP dmpEntity = this.quickWizardManager.createOrUpdate( quickWizard.getDmp().toDataDmp( - this.getApiContext().getOperationsContext().getDatabaseRepository().getUserInfoDao(), projectEntity, principal), principal); @@ -60,7 +59,6 @@ public class QuickWizardController extends BaseController { quickWizard.getDmp().setId(dmpEntity.getId()); for (DatasetDescriptionQuickWizardModel dataset : quickWizard.getDatasets().getDatasetsList()) { this.datasetManager.createOrUpdate(dataset.toDataModel(quickWizard.getDmp().toDataDmp( - this.getApiContext().getOperationsContext().getDatabaseRepository().getUserInfoDao(), projectEntity, principal), quickWizard.getDmp().getDatasetProfile().getId()), diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java index 3cfb026c0..1d38898ba 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java @@ -56,6 +56,7 @@ public class DatasetManager { private DatasetRepository datasetRepository; private BuilderFactory builderFactory; private UserManager userManager; + @Autowired public DatasetManager(ApiContext apiContext, UserManager userManager) { this.apiContext = apiContext; diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/quickwizard/DmpQuickWizardModel.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/quickwizard/DmpQuickWizardModel.java index 757cdfcd8..e0e90f678 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/quickwizard/DmpQuickWizardModel.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/quickwizard/DmpQuickWizardModel.java @@ -1,6 +1,5 @@ package eu.eudat.models.data.quickwizard; -import eu.eudat.data.dao.entities.UserInfoDao; import eu.eudat.data.entities.Project; import eu.eudat.models.data.dmp.AssociatedProfile; import eu.eudat.models.data.security.Principal; @@ -13,98 +12,93 @@ import java.util.UUID; public class DmpQuickWizardModel { - private UUID id; - private String label; - private int status; - private AssociatedProfile profile; - private String description; - private eu.eudat.models.data.project.Project project; + private UUID id; + private String label; + private int status; + private AssociatedProfile datasetProfile; + private String description; + private eu.eudat.models.data.project.Project project; - public UUID getId() { - return id; - } + public UUID getId() { + return id; + } - public void setId(UUID id) { - this.id = id; - } + public void setId(UUID id) { + this.id = id; + } - public String getLabel() { - return label; - } + public String getLabel() { + return label; + } - public void setLabel(String label) { - this.label = label; - } + public void setLabel(String label) { + this.label = label; + } - public int getStatus() { - return status; - } + public int getStatus() { + return status; + } - public void setStatus(int status) { - this.status = status; - } + public void setStatus(int status) { + this.status = status; + } - public AssociatedProfile getProfile() { - return profile; - } + public void setDatasetProfile(AssociatedProfile datasetProfile) { + this.datasetProfile = datasetProfile; + } - public void setProfile(AssociatedProfile profile) { - this.profile = profile; - } + public String getDescription() { + return description; + } - public String getDescription() { - return description; - } + public void setDescription(String description) { + this.description = description; + } - public void setDescription(String description) { - this.description = description; - } + public eu.eudat.models.data.project.Project getProject() { + return project; + } - public eu.eudat.models.data.project.Project getProject() { - return project; - } + public void setProject(eu.eudat.models.data.project.Project project) { + this.project = project; + } - public void setProject(eu.eudat.models.data.project.Project project) { - this.project = project; - } + public eu.eudat.models.data.dmp.DataManagementPlan toDataDmp(Project project, Principal principal) { + eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlanEntity = new eu.eudat.models.data.dmp.DataManagementPlan(); - public eu.eudat.models.data.dmp.DataManagementPlan toDataDmp(UserInfoDao userInfoRepository ,Project project, Principal principal) { - eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlanEntity = new eu.eudat.models.data.dmp.DataManagementPlan(); + dataManagementPlanEntity.setId(this.id); + dataManagementPlanEntity.setVersion(0); - dataManagementPlanEntity.setId(this.id); - dataManagementPlanEntity.setVersion(0); - - dataManagementPlanEntity.setLabel(this.label); - if (project != null) { - eu.eudat.models.data.project.Project importProject = new eu.eudat.models.data.project.Project(); - dataManagementPlanEntity.setProject(importProject.fromDataModel(project)); - } - if(this.profile!=null) { - List assProfile = new LinkedList<>(); - assProfile.add(this.profile); - dataManagementPlanEntity.setProfiles(assProfile); - } - dataManagementPlanEntity.setStatus((short) this.status); - dataManagementPlanEntity.setDescription(this.description); - dataManagementPlanEntity.setProperties(null); - dataManagementPlanEntity.setCreated(new Date()); - List user = new LinkedList(); - eu.eudat.models.data.userinfo.UserInfo usetInfo = new eu.eudat.models.data.userinfo.UserInfo(); - usetInfo.fromDataModel(userInfoRepository.find(principal.getId())); - user.add(usetInfo); - dataManagementPlanEntity.setAssociatedUsers(user); - return dataManagementPlanEntity; - } + dataManagementPlanEntity.setLabel(this.label); + if (project != null) { + eu.eudat.models.data.project.Project importProject = new eu.eudat.models.data.project.Project(); + dataManagementPlanEntity.setProject(importProject.fromDataModel(project)); + } + if (this.datasetProfile != null) { + List assProfile = new LinkedList<>(); + assProfile.add(this.datasetProfile); + dataManagementPlanEntity.setProfiles(assProfile); + } + dataManagementPlanEntity.setStatus((short) this.status); + dataManagementPlanEntity.setDescription(this.description); + dataManagementPlanEntity.setProperties(null); + dataManagementPlanEntity.setCreated(new Date()); + List user = new LinkedList(); + eu.eudat.models.data.userinfo.UserInfo userInfo = new eu.eudat.models.data.userinfo.UserInfo(); + userInfo.setId(principal.getId()); + dataManagementPlanEntity.setAssociatedUsers(user); + return dataManagementPlanEntity; + } - public eu.eudat.data.entities.DatasetProfile getDatasetProfile(){ - eu.eudat.data.entities.DatasetProfile datasetProfile = new eu.eudat.data.entities.DatasetProfile(); - datasetProfile.setDefinition(this.profile.getLabel()); - datasetProfile.setLabel(this.profile.getLabel()); - datasetProfile.setId(this.profile.getId()); - return datasetProfile; - } + public eu.eudat.data.entities.DatasetProfile getDatasetProfile() { + eu.eudat.data.entities.DatasetProfile datasetProfile = new eu.eudat.data.entities.DatasetProfile(); + datasetProfile.setDefinition(this.datasetProfile.getLabel()); + datasetProfile.setLabel(this.datasetProfile.getLabel()); + datasetProfile.setId(this.datasetProfile.getId()); + return datasetProfile; + } }