From 339f65f49922462db47432ff252ecb3b2e5fc2e2 Mon Sep 17 00:00:00 2001 From: dtziotzios Date: Tue, 29 Jan 2019 13:05:36 +0200 Subject: [PATCH] Dependency injection applied on DMPs and some API route name changes. --- .../main/java/eu/eudat/controllers/DMPs.java | 37 ++++++++++--------- .../managers/DataManagementPlanManager.java | 20 +++++----- .../src/app/core/services/dmp/dmp.service.ts | 8 ++-- 3 files changed, 34 insertions(+), 31 deletions(-) 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 d9a4a2cd2..18c9d64bc 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 @@ -46,72 +46,73 @@ public class DMPs extends BaseController { private DynamicProjectConfiguration dynamicProjectConfiguration; private Environment environment; + private DataManagementPlanManager dataManagementPlanManager; @Autowired - public DMPs(ApiContext apiContext, DynamicProjectConfiguration dynamicProjectConfiguration, Environment environment) { + public DMPs(ApiContext apiContext, DynamicProjectConfiguration dynamicProjectConfiguration, Environment environment, DataManagementPlanManager dataManagementPlanManager) { super(apiContext); this.dynamicProjectConfiguration = dynamicProjectConfiguration; this.environment = environment; - + this.dataManagementPlanManager = dataManagementPlanManager; } @Transactional @RequestMapping(method = RequestMethod.GET, value = {"{id}/unlock"}, produces = "application/json") public @ResponseBody ResponseEntity> unlock(@PathVariable(value = "id") UUID id, Principal principal) throws Exception { - new DataManagementPlanManager().unlock(this.getApiContext(), id); + this.dataManagementPlanManager.unlock(this.getApiContext(), id); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Unlocked")); } - @RequestMapping(method = RequestMethod.POST, value = {"/getPaged"}, consumes = "application/json", produces = "application/json") + @RequestMapping(method = RequestMethod.POST, value = {"/paged"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity>> getPaged(@Valid @RequestBody DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal) throws Exception { - DataTableData dataTable = new DataManagementPlanManager().getPaged(this.getApiContext(), dataManagementPlanTableRequest, principal); + DataTableData dataTable = this.dataManagementPlanManager.getPaged(this.getApiContext(), dataManagementPlanTableRequest, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable)); } - @RequestMapping(method = RequestMethod.GET, value = {"/getSingle/{id}"}, produces = "application/json") + @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.dmp.DataManagementPlan dataManagementPlan = new DataManagementPlanManager().getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, principal, this.dynamicProjectConfiguration); + eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = this.dataManagementPlanManager.getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, principal, this.dynamicProjectConfiguration); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan)); } @Transactional - @RequestMapping(method = RequestMethod.POST, value = {"/createOrUpdate"}, consumes = "application/json", produces = "application/json") + @RequestMapping(method = RequestMethod.POST, value = {"/post"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> createOrUpdate(@RequestBody eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan, Principal principal) throws Exception { - DataManagementPlanManager.createOrUpdate(this.getApiContext(), dataManagementPlan, principal); + this.dataManagementPlanManager.createOrUpdate(this.getApiContext(), dataManagementPlan, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created")); } @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 { - DataManagementPlanManager.newVersion(this.getApiContext(), id, dataManagementPlan, principal); + this.dataManagementPlanManager.newVersion(this.getApiContext(), 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 { - DataManagementPlanManager.clone(this.getApiContext(), id, dataManagementPlan, principal); + this.dataManagementPlanManager.clone(this.getApiContext(), id, dataManagementPlan, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE)); } @RequestMapping(method = RequestMethod.POST, value = {"/get"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity>> getWithCriteria(@RequestBody DataManagementPlanCriteriaRequest dataManagementPlanCriteria, Principal principal) throws InstantiationException, IllegalAccessException { - List dataTable = new DataManagementPlanManager().getWithCriteria(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), dataManagementPlanCriteria, principal); + List dataTable = this.dataManagementPlanManager.getWithCriteria(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), dataManagementPlanCriteria, principal); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable)); } @Transactional - @RequestMapping(method = RequestMethod.DELETE, value = {"/delete/{id}"}, consumes = "application/json", produces = "application/json") + @RequestMapping(method = RequestMethod.DELETE, value = {"{id}"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> delete(@PathVariable UUID id, Principal principal) { try{ - DataManagementPlanManager.delete(this.getApiContext(), id); + this.dataManagementPlanManager.delete(this.getApiContext(), 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())); @@ -122,14 +123,14 @@ public class DMPs extends BaseController { @RequestMapping(method = RequestMethod.POST, value = {"/dynamic"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity>>> getWithCriteria(@RequestBody RequestItem criteriaRequestItem, Principal principal) throws InstantiationException, IllegalAccessException { - List> dataTable = new DataManagementPlanManager().getDynamicFields(criteriaRequestItem.getCriteria().getId(), this.dynamicProjectConfiguration, criteriaRequestItem.getCriteria()); + List> dataTable = this.dataManagementPlanManager.getDynamicFields(criteriaRequestItem.getCriteria().getId(), this.dynamicProjectConfiguration, criteriaRequestItem.getCriteria()); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable)); } @RequestMapping(method = RequestMethod.GET, value = {"/getXml/{id}"}) public @ResponseBody ResponseEntity getXml(@PathVariable String id) throws IllegalAccessException, IOException, InstantiationException { - FileEnvelope envelope = new DataManagementPlanManager().getXmlDocument(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, this.getApiContext().getUtilitiesService().getVisibilityRuleService()); + FileEnvelope envelope = this.dataManagementPlanManager.getXmlDocument(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, this.getApiContext().getUtilitiesService().getVisibilityRuleService()); InputStream resource = new FileInputStream(envelope.getFile()); System.out.println("Mime Type of " + envelope.getFilename() + " is " + new MimetypesFileTypeMap().getContentType(envelope.getFile())); @@ -149,7 +150,7 @@ public class DMPs extends BaseController { @RequestMapping(method = RequestMethod.GET, value = {"/getWord/{id}"}) public @ResponseBody ResponseEntity getWordDocument(@PathVariable String id) throws IOException, IllegalAccessException, InstantiationException { - File file = new DataManagementPlanManager().getWordDocument(this.environment, this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, this.getApiContext().getUtilitiesService().getVisibilityRuleService()); + File file = this.dataManagementPlanManager.getWordDocument(this.environment, this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, this.getApiContext().getUtilitiesService().getVisibilityRuleService()); InputStream resource = new FileInputStream(file); System.out.println("Mime Type of " + file.getName() + " is " + new MimetypesFileTypeMap().getContentType(file)); @@ -169,7 +170,7 @@ public class DMPs extends BaseController { @RequestMapping(method = RequestMethod.GET, value = {"/getPDF/{id}"}) public @ResponseBody ResponseEntity getPDFDocument(@PathVariable String id) throws IllegalAccessException, IOException, InstantiationException, InterruptedException { - File file = new DataManagementPlanManager().getWordDocument(this.environment, this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, this.getApiContext().getUtilitiesService().getVisibilityRuleService()); + 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()); InputStream resource = new FileInputStream(pdffile); System.out.println("Mime Type of " + file.getName() + " is " + 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 8de44dc13..b884e5289 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 @@ -36,6 +36,7 @@ import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.json.JSONObject; import org.springframework.core.env.Environment; import org.springframework.http.*; +import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -48,6 +49,7 @@ import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; +@Component public class DataManagementPlanManager { public DataTableData getPaged(ApiContext apiContext, DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal) throws Exception { @@ -208,7 +210,7 @@ public class DataManagementPlanManager { return result; } - public static void createOrUpdate(ApiContext apiContext, DataManagementPlan dataManagementPlan, Principal principal) throws Exception { + public void createOrUpdate(ApiContext apiContext, DataManagementPlan dataManagementPlan, Principal principal) throws Exception { DMP newDmp = dataManagementPlan.toDataModel(); createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao()); createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao()); @@ -226,7 +228,7 @@ public class DataManagementPlanManager { assignUser(newDmp, user, apiContext); } - public static void assignUser(DMP dmp, UserInfo userInfo, ApiContext apiContext) { + public void assignUser(DMP dmp, UserInfo userInfo, ApiContext apiContext) { UserDMP userDMP = new UserDMP(); userDMP.setDmp(dmp); userDMP.setUser(userInfo); @@ -234,7 +236,7 @@ public class DataManagementPlanManager { apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP); } - public static void newVersion(ApiContext apiContext, UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception { + public void newVersion(ApiContext apiContext, 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()); @@ -249,7 +251,7 @@ public class DataManagementPlanManager { copyDatasets(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao()); } - public static void clone(ApiContext apiContext, UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception { + public void clone(ApiContext apiContext, UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception { DMP newDmp = dataManagementPlan.toDataModel(); createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao()); createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao()); @@ -263,7 +265,7 @@ public class DataManagementPlanManager { copyDatasets(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao()); } - public static void delete(ApiContext apiContext, UUID uuid) throws DMPWithDatasetsDeleteException { + public void delete(ApiContext apiContext, UUID uuid) throws DMPWithDatasetsDeleteException { DMP oldDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(uuid); if (oldDmp.getDataset().size() > 0) throw new DMPWithDatasetsDeleteException("You cannot Remove Datamanagement Plan with Datasets"); @@ -271,7 +273,7 @@ public class DataManagementPlanManager { apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(oldDmp); } - private static void createResearchersIfTheyDontExist(DMP newDmp, ResearcherDao researcherRepository) { + private void createResearchersIfTheyDontExist(DMP newDmp, ResearcherDao researcherRepository) { if (newDmp.getResearchers() != null && !newDmp.getResearchers().isEmpty()) { for (eu.eudat.data.entities.Researcher researcher : newDmp.getResearchers()) { ResearcherCriteria criteria = new ResearcherCriteria(); @@ -283,7 +285,7 @@ public class DataManagementPlanManager { } } - private static void createOrganisationsIfTheyDontExist(DMP newDmp, OrganisationDao organisationRepository) { + private void createOrganisationsIfTheyDontExist(DMP newDmp, OrganisationDao organisationRepository) { if (newDmp.getOrganisations() != null && !newDmp.getOrganisations().isEmpty()) { for (eu.eudat.data.entities.Organisation organisation : newDmp.getOrganisations()) { OrganisationCriteria criteria = new OrganisationCriteria(); @@ -295,7 +297,7 @@ public class DataManagementPlanManager { } } - private static void createProjectIfItDoesntExist(DMP newDmp, ProjectDao projectDao, UserInfo userInfo) { + private void createProjectIfItDoesntExist(DMP newDmp, ProjectDao projectDao, UserInfo userInfo) { if (newDmp.getProject() != null) { Project project = newDmp.getProject(); ProjectCriteria criteria = new ProjectCriteria(); @@ -310,7 +312,7 @@ public class DataManagementPlanManager { } - private static void copyDatasets(DMP newDmp, DatasetDao datasetDao) { + private void copyDatasets(DMP newDmp, DatasetDao datasetDao) { List> futures = new LinkedList<>(); for (Dataset dataset : newDmp.getDataset()) { datasetDao.asQueryable().withHint(HintedModelFactory.getHint(DatasetListingModel.class)).where((builder, root) -> builder.equal(root.get("id"), dataset.getId())).getSingleAsync() diff --git a/dmp-frontend/src/app/core/services/dmp/dmp.service.ts b/dmp-frontend/src/app/core/services/dmp/dmp.service.ts index 78df66786..b8b369231 100644 --- a/dmp-frontend/src/app/core/services/dmp/dmp.service.ts +++ b/dmp-frontend/src/app/core/services/dmp/dmp.service.ts @@ -24,18 +24,18 @@ export class DmpService { } getPaged(dataTableRequest: DataTableRequest): Observable> { - return this.http.post>(this.actionUrl + 'getPaged', dataTableRequest, { headers: this.headers }); + return this.http.post>(this.actionUrl + 'paged', dataTableRequest, { headers: this.headers }); } getSingle(id: String): Observable { - return this.http.get(this.actionUrl + 'getSingle/' + id, { headers: this.headers }); + return this.http.get(this.actionUrl + id, { headers: this.headers }); //'getSingle/' + } unlock(id: String): Observable { return this.http.get(this.actionUrl + id + '/unlock', { headers: this.headers }); } createDmp(dataManagementPlanModel: DmpModel): Observable { - return this.http.post(this.actionUrl + 'createOrUpdate', dataManagementPlanModel, { headers: this.headers }); + return this.http.post(this.actionUrl + 'post', dataManagementPlanModel, { headers: this.headers }); } inactivate(id: String): Observable { @@ -55,7 +55,7 @@ export class DmpService { } delete(id: String): Observable { - return this.http.delete(this.actionUrl + 'delete/' + id, { headers: this.headers }); + return this.http.delete(this.actionUrl + id, { headers: this.headers }); // + 'delete/' } getDynamicField(requestItem: RequestItem): any {