Browse Source

no message

dmp-editor
Ioannis Kalyvas 4 years ago
parent
commit
8cb464c1e9
  1. 34
      dmp-backend/pom.xml
  2. 2
      dmp-backend/src/main/java/eu/eudat/configurations/DevelDatabaseConfiguration.java
  3. 24
      dmp-backend/src/main/java/eu/eudat/configurations/WebMVCConfiguration.java
  4. 8
      dmp-backend/src/main/java/eu/eudat/controllers/Admin.java
  5. 8
      dmp-backend/src/main/java/eu/eudat/controllers/BaseController.java
  6. 6
      dmp-backend/src/main/java/eu/eudat/controllers/DMPs.java
  7. 8
      dmp-backend/src/main/java/eu/eudat/controllers/DashBoardController.java
  8. 2
      dmp-backend/src/main/java/eu/eudat/controllers/DataRepositories.java
  9. 8
      dmp-backend/src/main/java/eu/eudat/controllers/DatasetProfileController.java
  10. 4
      dmp-backend/src/main/java/eu/eudat/controllers/DatasetProfiles.java
  11. 48
      dmp-backend/src/main/java/eu/eudat/controllers/DatasetWizardController.java
  12. 4
      dmp-backend/src/main/java/eu/eudat/controllers/Datasets.java
  13. 4
      dmp-backend/src/main/java/eu/eudat/controllers/ExternalDatasets.java
  14. 14
      dmp-backend/src/main/java/eu/eudat/controllers/Login.java
  15. 2
      dmp-backend/src/main/java/eu/eudat/controllers/Organisations.java
  16. 14
      dmp-backend/src/main/java/eu/eudat/controllers/Projects.java
  17. 2
      dmp-backend/src/main/java/eu/eudat/controllers/Registries.java
  18. 2
      dmp-backend/src/main/java/eu/eudat/controllers/Researchers.java
  19. 2
      dmp-backend/src/main/java/eu/eudat/controllers/Services.java
  20. 38
      dmp-backend/src/main/java/eu/eudat/controllers/controllerhandler/GeneralErrorHandler.java
  21. 33
      dmp-backend/src/main/java/eu/eudat/controllers/interceptors/RequestInterceptor.java
  22. 69
      dmp-backend/src/main/java/eu/eudat/documents/word/WordBuilder.java
  23. 3
      dmp-backend/src/main/java/eu/eudat/handlers/PrincipalArgumentResolver.java
  24. 2
      dmp-backend/src/main/java/eu/eudat/managers/AdminManager.java
  25. 46
      dmp-backend/src/main/java/eu/eudat/managers/DataManagementPlanManager.java
  26. 112
      dmp-backend/src/main/java/eu/eudat/managers/DatasetManager.java
  27. 4
      dmp-backend/src/main/java/eu/eudat/managers/DatasetProfileManager.java
  28. 8
      dmp-backend/src/main/java/eu/eudat/managers/ExternalDatasetManager.java
  29. 16
      dmp-backend/src/main/java/eu/eudat/managers/InvitationsManager.java
  30. 4
      dmp-backend/src/main/java/eu/eudat/managers/ProjectManager.java
  31. 2
      dmp-backend/src/main/java/eu/eudat/managers/ResearcherManager.java
  32. 19
      dmp-backend/src/main/java/eu/eudat/managers/UserManager.java
  33. 15
      dmp-backend/src/main/java/eu/eudat/models/helpers/responses/ResponseItem.java
  34. 10
      dmp-backend/src/main/java/eu/eudat/security/validators/b2access/B2AccessTokenValidator.java
  35. 10
      dmp-backend/src/main/java/eu/eudat/security/validators/facebook/FacebookTokenValidator.java
  36. 10
      dmp-backend/src/main/java/eu/eudat/security/validators/google/GoogleTokenValidator.java
  37. 10
      dmp-backend/src/main/java/eu/eudat/security/validators/linkedin/LinkedInTokenValidator.java
  38. 10
      dmp-backend/src/main/java/eu/eudat/security/validators/twitter/TwitterTokenValidator.java
  39. 21
      dmp-backend/src/main/java/eu/eudat/services/ApiContext.java
  40. 87
      dmp-backend/src/main/java/eu/eudat/services/ApiContextImpl.java
  41. 45
      dmp-backend/src/main/java/eu/eudat/services/forms/VisibilityContext.java
  42. 27
      dmp-backend/src/main/java/eu/eudat/services/forms/VisibilityRule.java
  43. 17
      dmp-backend/src/main/java/eu/eudat/services/forms/VisibilityRuleService.java
  44. 46
      dmp-backend/src/main/java/eu/eudat/services/forms/VisibilityRuleServiceImpl.java
  45. 25
      dmp-backend/src/main/java/eu/eudat/services/forms/VisibilityRuleSource.java
  46. 13
      dmp-backend/src/main/java/eu/eudat/services/helpers/HelpersService.java
  47. 31
      dmp-backend/src/main/java/eu/eudat/services/helpers/HelpersServiceImpl.java
  48. 12
      dmp-backend/src/main/java/eu/eudat/services/helpers/LoggerService.java
  49. 39
      dmp-backend/src/main/java/eu/eudat/services/helpers/LoggerServiceImpl.java
  50. 23
      dmp-backend/src/main/java/eu/eudat/services/operations/AuthenticationService.java
  51. 61
      dmp-backend/src/main/java/eu/eudat/services/operations/AuthenticationServiceImpl.java
  52. 2
      dmp-backend/src/main/java/eu/eudat/services/operations/DatabaseRepository.java
  53. 2
      dmp-backend/src/main/java/eu/eudat/services/operations/DatabaseRepositoryImpl.java
  54. 20
      dmp-backend/src/main/java/eu/eudat/services/operations/OperationsContext.java
  55. 48
      dmp-backend/src/main/java/eu/eudat/services/operations/OperationsContextImpl.java
  56. 2
      dmp-backend/src/main/java/eu/eudat/services/utilities/InvitationService.java
  57. 2
      dmp-backend/src/main/java/eu/eudat/services/utilities/InvitationServiceImpl.java
  58. 2
      dmp-backend/src/main/java/eu/eudat/services/utilities/MailService.java
  59. 2
      dmp-backend/src/main/java/eu/eudat/services/utilities/MailServiceImpl.java
  60. 15
      dmp-backend/src/main/java/eu/eudat/services/utilities/UtilitiesService.java
  61. 38
      dmp-backend/src/main/java/eu/eudat/services/utilities/UtilitiesServiceImpl.java
  62. 29
      dmp-backend/src/main/java/eu/eudat/types/ApiResponseType.java
  63. 8
      dmp-backend/src/main/java/eu/eudat/types/WarningLevel.java
  64. 6
      dmp-backend/src/main/java/eu/eudat/utilities/interfaces/Applier.java
  65. 8
      dmp-backend/src/main/java/eu/eudat/utilities/interfaces/ApplierWithValue.java
  66. 4
      dmp-backend/src/main/resources/application.properties
  67. BIN
      dmp-backend/src/main/resources/documents/h2020.docx
  68. 915
      dmp-frontend/package-lock.json
  69. 2
      dmp-frontend/package.json
  70. 7
      dmp-frontend/src/app/datasets/dataset-wizard/dataset-wizard.component.html
  71. 50
      dmp-frontend/src/app/datasets/dataset-wizard/dataset-wizard.component.ts
  72. 2
      dmp-frontend/src/app/form/dynamic-form/dynamic-form.component.html
  73. 6
      dmp-frontend/src/app/form/dynamic-form/dynamic-form.component.ts
  74. 22
      dmp-frontend/src/app/models/Field.ts
  75. 12
      dmp-frontend/src/app/services/dataset-wizard/dataset-wizard.service.ts
  76. 4
      dmp-frontend/src/app/shared/components/criteria/datasets/datasets-criteria.component.ts
  77. 52
      dmp-frontend/src/app/utilities/cite-http-service-module/base-http.service.ts
  78. 4
      dmp-frontend/src/app/utilities/types/ApiResponseCode.ts
  79. 6
      dmp-frontend/src/app/visibility-rules/visibility-rules.service.ts
  80. BIN
      welcome.docx

34
dmp-backend/pom.xml

@ -189,15 +189,45 @@
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.17</version>
<version>3.15</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.17</version>
<version>3.15</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/fop -->
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>fop</artifactId>
<version>2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/fr.opensagres.xdocreport/org.apache.poi.xwpf.converter.pdf -->
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>org.apache.poi.xwpf.converter.pdf</artifactId>
<version>1.0.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/fr.opensagres.xdocreport/org.apache.poi.xwpf.converter.core -->
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>org.apache.poi.xwpf.converter.core</artifactId>
<version>1.0.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/fr.opensagres.xdocreport/fr.opensagres.xdocreport.itext.extension -->
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>fr.opensagres.xdocreport.itext.extension</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.1</version>
</dependency>
</dependencies>

2
dmp-backend/src/main/java/eu/eudat/configurations/DevelDatabaseConfiguration.java

@ -67,7 +67,7 @@ public class DevelDatabaseConfiguration {
private Properties additionalProperties() {
Properties properties = new Properties();
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.PostgreSQL92Dialect");
properties.setProperty("hibernate.show_sql", "true");
properties.setProperty("hibernate.show_sql", "false");
properties.setProperty("hibernate.temp.use_jdbc_metadata_defaults", "false");
return properties;
}

24
dmp-backend/src/main/java/eu/eudat/configurations/WebMVCConfiguration.java

@ -1,11 +1,16 @@
package eu.eudat.configurations;
import eu.eudat.controllers.interceptors.RequestInterceptor;
import eu.eudat.handlers.PrincipalArgumentResolver;
import eu.eudat.services.AuthenticationService;
import eu.eudat.services.ApiContext;
import eu.eudat.services.operations.AuthenticationService;
import eu.eudat.services.operations.AuthenticationServiceImpl;
import eu.eudat.types.WarningLevel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import java.util.List;
@ -14,12 +19,25 @@ import java.util.List;
@Configuration
public class WebMVCConfiguration extends WebMvcConfigurerAdapter {
private ApiContext apiContext;
private AuthenticationService authenticationService;
@Autowired
AuthenticationService authenticationService;
public WebMVCConfiguration(ApiContext apiContext, AuthenticationService authenticationService) {
this.apiContext = apiContext;
this.authenticationService = authenticationService;
}
@Autowired
@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> argumentResolvers) {
argumentResolvers.add(new PrincipalArgumentResolver(this.authenticationService));
argumentResolvers.add(new PrincipalArgumentResolver(authenticationService));
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new RequestInterceptor(this.apiContext.getHelpersService().getLoggerService()));
}
}

8
dmp-backend/src/main/java/eu/eudat/controllers/Admin.java

@ -33,7 +33,7 @@ public class Admin extends BaseController {
public ResponseEntity<Object> addDmp(@Valid @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) {
try {
eu.eudat.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(profile, getApiContext());
this.getApiContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition);
this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(modelDefinition);
return ResponseEntity.status(HttpStatus.OK).body(modelDefinition.getId());
} catch (Exception ex) {
ex.printStackTrace();
@ -47,9 +47,9 @@ public class Admin extends BaseController {
try {
eu.eudat.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(profile, getApiContext());
eu.eudat.entities.DatasetProfile datasetprofile = this.getApiContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
eu.eudat.entities.DatasetProfile datasetprofile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
datasetprofile.setDefinition(modelDefinition.getDefinition());
this.getApiContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(datasetprofile);
this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(datasetprofile);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UUID>().status(ApiMessageCode.NO_MESSAGE));
} catch (Exception ex) {
@ -61,7 +61,7 @@ public class Admin extends BaseController {
@RequestMapping(method = RequestMethod.GET, value = {"/admin/get/{id}"}, produces = "application/json")
public ResponseEntity<ResponseItem<DatasetProfile>> get(@PathVariable String id, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) {
try {
eu.eudat.entities.DatasetProfile profile = this.getApiContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
eu.eudat.entities.DatasetProfile profile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
eu.eudat.models.admin.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile);
datasetprofile.setLabel(profile.getLabel());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetProfile>().status(ApiMessageCode.NO_MESSAGE).payload(datasetprofile));

8
dmp-backend/src/main/java/eu/eudat/controllers/BaseController.java

@ -24,13 +24,13 @@ public abstract class BaseController {
@InitBinder()
protected void initBinder(WebDataBinder binder) {
if (binder.getTarget() != null && DataManagementPlanTableRequestValidator.supportsType((binder.getTarget().getClass())))
binder.addValidators(this.apiContext.getApplicationContext().getBean("dataManagementPlanTableRequestValidator", DataManagementPlanTableRequestValidator.class));
binder.addValidators(this.apiContext.getOperationsContext().getApplicationContext().getBean("dataManagementPlanTableRequestValidator", DataManagementPlanTableRequestValidator.class));
if (binder.getTarget() != null && ProjectTableRequestValidator.supportsType((binder.getTarget().getClass())))
binder.addValidators(this.apiContext.getApplicationContext().getBean("projectTableRequestValidator", ProjectTableRequestValidator.class));
binder.addValidators(this.apiContext.getOperationsContext().getApplicationContext().getBean("projectTableRequestValidator", ProjectTableRequestValidator.class));
if (binder.getTarget() != null && DatasetProfileValidator.supportsType((binder.getTarget().getClass())))
binder.addValidators(this.apiContext.getApplicationContext().getBean("datasetProfileValidator", DatasetProfileValidator.class));
binder.addValidators(this.apiContext.getOperationsContext().getApplicationContext().getBean("datasetProfileValidator", DatasetProfileValidator.class));
if (binder.getTarget() != null && ProjectModelValidator.supportsType((binder.getTarget().getClass())))
binder.addValidators(this.apiContext.getApplicationContext().getBean("projectModelValidator", ProjectModelValidator.class));
binder.addValidators(this.apiContext.getOperationsContext().getApplicationContext().getBean("projectModelValidator", ProjectModelValidator.class));
}
}

6
dmp-backend/src/main/java/eu/eudat/controllers/DMPs.java

@ -40,7 +40,6 @@ public class DMPs extends BaseController {
try {
DataTableData<DataManagementPlanListingModel> dataTable = new DataManagementPlanManager().getPaged(this.getApiContext(), dataManagementPlanTableRequest, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<DataTableData<DataManagementPlanListingModel>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
@ -51,7 +50,7 @@ public class DMPs extends BaseController {
public @ResponseBody
ResponseEntity<ResponseItem<DataManagementPlan>> getSingle(@PathVariable String id, Principal principal) {
try {
eu.eudat.models.dmp.DataManagementPlan dataManagementPlan = new DataManagementPlanManager().getSingle(this.getApiContext().getDatabaseRepository().getDmpDao(), id, principal);
eu.eudat.models.dmp.DataManagementPlan dataManagementPlan = new DataManagementPlanManager().getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataManagementPlan>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlan));
} catch (Exception ex) {
@ -101,9 +100,8 @@ public class DMPs extends BaseController {
public @ResponseBody
ResponseEntity<ResponseItem<List<DataManagementPlan>>> getWithCriteria(@RequestBody DataManagementPlanCriteriaRequest dataManagementPlanCriteria, Principal principal) {
try {
List<DataManagementPlan> dataTable = new DataManagementPlanManager().getWithCriteria(this.getApiContext().getDatabaseRepository().getDmpDao(), dataManagementPlanCriteria);
List<DataManagementPlan> dataTable = new DataManagementPlanManager().getWithCriteria(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), dataManagementPlanCriteria);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DataManagementPlan>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
} catch (Exception ex) {
ex.printStackTrace();
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<DataManagementPlan>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));

8
dmp-backend/src/main/java/eu/eudat/controllers/DashBoardController.java

@ -27,8 +27,8 @@ public class DashBoardController extends BaseController {
@RequestMapping(method = RequestMethod.GET, value = {"/dashboard/getStatistics"}, produces = "application/json")
public ResponseEntity<ResponseItem<DashBoardStatistics>> getStatistics() {
try {
DashBoardStatistics statistics = new DashBoardManager().getStatistics(this.getApiContext().getDatabaseRepository().getDatasetDao(), this.getApiContext().getDatabaseRepository().getDmpDao()
, this.getApiContext().getDatabaseRepository().getProjectDao());
DashBoardStatistics statistics = new DashBoardManager().getStatistics(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao()
, this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DashBoardStatistics>().status(ApiMessageCode.NO_MESSAGE).payload(statistics));
} catch (Exception ex) {
ex.printStackTrace();
@ -39,8 +39,8 @@ public class DashBoardController extends BaseController {
@RequestMapping(method = RequestMethod.GET, value = {"/dashboard/me/getStatistics"}, produces = "application/json")
public ResponseEntity<ResponseItem<DashBoardStatistics>> getStatistics(Principal principal) {
try {
DashBoardStatistics statistics = new DashBoardManager().getMeStatistics(this.getApiContext().getDatabaseRepository().getDatasetDao(), this.getApiContext().getDatabaseRepository().getDmpDao()
, this.getApiContext().getDatabaseRepository().getProjectDao(), principal);
DashBoardStatistics statistics = new DashBoardManager().getMeStatistics(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao()
, this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DashBoardStatistics>().status(ApiMessageCode.NO_MESSAGE).payload(statistics));
} catch (Exception ex) {
ex.printStackTrace();

2
dmp-backend/src/main/java/eu/eudat/controllers/DataRepositories.java

@ -28,7 +28,7 @@ public class DataRepositories extends BaseController {
public @ResponseBody
ResponseEntity<ResponseItem<List<Map<String, String>>>> listExternalDataRepositories(@RequestParam(value = "query", required = false) String query) {
try {
List<Map<String, String>> remoteRepos = this.getApiContext().getRemoteFetcher().getRepositories(query);
List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getRepositories(query);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Map<String, String>>>().status(ApiMessageCode.NO_MESSAGE).payload(remoteRepos));
} catch (NoURLFound ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<Map<String, String>>>().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage()).payload(null));

8
dmp-backend/src/main/java/eu/eudat/controllers/DatasetProfileController.java

@ -34,7 +34,7 @@ public class DatasetProfileController extends BaseController {
@RequestMapping(method = RequestMethod.GET, value = {"/datasetwizard/get/{id}"}, produces = "application/json")
public ResponseEntity<ResponseItem<PagedDatasetProfile>> getSingle(@PathVariable String id) {
try {
eu.eudat.entities.DatasetProfile profile = this.getApiContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
eu.eudat.entities.DatasetProfile profile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
eu.eudat.models.user.composite.DatasetProfile datasetprofile = UserManager.generateDatasetProfileModel(profile);
PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile();
pagedDatasetProfile.buildPagedDatasetProfile(datasetprofile);
@ -49,13 +49,13 @@ public class DatasetProfileController extends BaseController {
@RequestMapping(method = RequestMethod.POST, value = {"/datasetprofile/save/{id}"}, consumes = "application/json", produces = "application/json")
public ResponseEntity<Object> updateDataset(@PathVariable String id, @RequestBody PropertiesModel properties) {
try {
eu.eudat.entities.Dataset dataset = this.getApiContext().getDatabaseRepository().getDatasetDao().find(UUID.fromString(id));
eu.eudat.entities.Dataset dataset = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao().find(UUID.fromString(id));
Map<String, Object> values = new HashMap();
properties.toMap(values);
JSONObject jobject = new JSONObject(values);
dataset.setProperties(jobject.toString());
dataset.setStatus((short) properties.getStatus());
this.getApiContext().getDatabaseRepository().getDatasetDao().createOrUpdate(dataset); //TODO
this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(dataset); //TODO
return ResponseEntity.status(HttpStatus.OK).body(properties);
} catch (Exception ex) {
ex.printStackTrace();
@ -66,7 +66,7 @@ public class DatasetProfileController extends BaseController {
@RequestMapping(method = RequestMethod.POST, value = {"/search/autocomplete"}, consumes = "application/json", produces = "application/json")
public ResponseEntity<Object> getDataForAutocomplete(@RequestBody AutoCompleteLookupItem lookupItem) {
try {
eu.eudat.entities.Dataset dataset = this.getApiContext().getDatabaseRepository().getDatasetDao().find(UUID.fromString(lookupItem.getProfileID()));
eu.eudat.entities.Dataset dataset = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao().find(UUID.fromString(lookupItem.getProfileID()));
eu.eudat.entities.xmlmodels.datasetprofiledefinition.Field modelfield = new eu.eudat.entities.xmlmodels.datasetprofiledefinition.Field();
AutoCompleteData data = new AutoCompleteData().fromData(modelfield.getData());

4
dmp-backend/src/main/java/eu/eudat/controllers/DatasetProfiles.java

@ -31,7 +31,7 @@ public class DatasetProfiles extends BaseController {
public @ResponseBody
ResponseEntity<ResponseItem<List<DatasetProfileAutocompleteItem>>> get(@RequestBody DatasetProfileAutocompleteRequest datasetProfileAutocompleteRequest) {
try {
List<DatasetProfileAutocompleteItem> datasetProfileAutocompleteItems = DatasetProfileManager.getWithCriteria(this.getApiContext().getDatabaseRepository().getDatasetProfileDao(), datasetProfileAutocompleteRequest);
List<DatasetProfileAutocompleteItem> datasetProfileAutocompleteItems = DatasetProfileManager.getWithCriteria(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao(), datasetProfileAutocompleteRequest);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DatasetProfileAutocompleteItem>>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileAutocompleteItems));
} catch (Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<DatasetProfileAutocompleteItem>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE));
@ -53,7 +53,7 @@ public class DatasetProfiles extends BaseController {
public @ResponseBody
ResponseEntity<ResponseItem<List<DatasetProfileListingModel>>> getAll() {
try {
List<DatasetProfileListingModel> datasetProfileTableData = DatasetProfileManager.getAll(this.getApiContext().getDatabaseRepository().getDatasetProfileDao());
List<DatasetProfileListingModel> datasetProfileTableData = DatasetProfileManager.getAll(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DatasetProfileListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(datasetProfileTableData));
} catch (Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<List<DatasetProfileListingModel>>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE));

48
dmp-backend/src/main/java/eu/eudat/controllers/DatasetWizardController.java

@ -12,17 +12,20 @@ import eu.eudat.models.helpers.responses.ResponseItem;
import eu.eudat.models.security.Principal;
import eu.eudat.services.ApiContext;
import eu.eudat.types.ApiMessageCode;
import org.apache.poi.util.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import javax.activation.MimetypesFileTypeMap;
import javax.transaction.Transactional;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
@ -32,16 +35,19 @@ import java.util.List;
@RequestMapping(value = {"api/datasetwizard"})
public class DatasetWizardController extends BaseController {
private Environment environment;
@Autowired
public DatasetWizardController(ApiContext apiContext) {
public DatasetWizardController(ApiContext apiContext, Environment environment) {
super(apiContext);
this.environment = environment;
}
@RequestMapping(method = RequestMethod.POST, value = {"/userDmps"}, produces = "application/json")
public @ResponseBody
ResponseEntity<ResponseItem<List<DataManagentPlanListingModel>>> getUserDmps(@RequestBody DatasetWizardAutocompleteRequest datasetWizardAutocompleteRequest, Principal principal) {
try {
List<DataManagentPlanListingModel> dataManagementPlans = DatasetWizardManager.getUserDmps(this.getApiContext().getDatabaseRepository().getDmpDao(), datasetWizardAutocompleteRequest, principal);
List<DataManagentPlanListingModel> dataManagementPlans = DatasetWizardManager.getUserDmps(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), datasetWizardAutocompleteRequest, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<DataManagentPlanListingModel>>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlans));
} catch (Exception ex) {
@ -54,7 +60,7 @@ public class DatasetWizardController extends BaseController {
public @ResponseBody
ResponseEntity<ResponseItem<List<AssociatedProfile>>> getAvailableProfiles(@RequestBody DatasetProfileWizardAutocompleteRequest datasetProfileWizardAutocompleteRequest, Principal principal) {
try {
List<AssociatedProfile> dataManagementPlans = DatasetWizardManager.getAvailableProfiles(this.getApiContext().getDatabaseRepository().getDmpDao(), datasetProfileWizardAutocompleteRequest);
List<AssociatedProfile> dataManagementPlans = DatasetWizardManager.getAvailableProfiles(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), datasetProfileWizardAutocompleteRequest);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<AssociatedProfile>>().status(ApiMessageCode.NO_MESSAGE).payload(dataManagementPlans));
} catch (Exception ex) {
@ -67,7 +73,7 @@ public class DatasetWizardController extends BaseController {
public @ResponseBody
ResponseEntity<ResponseItem<DatasetWizardModel>> getSingle(@PathVariable String id, Principal principal) {
try {
DatasetWizardModel dataset = new DatasetManager().getSingle(this.getApiContext().getDatabaseRepository().getDatasetDao(), id);
DatasetWizardModel dataset = new DatasetManager().getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DatasetWizardModel>().status(ApiMessageCode.NO_MESSAGE).payload(dataset));
} catch (Exception ex) {
ex.printStackTrace();
@ -88,21 +94,29 @@ public class DatasetWizardController extends BaseController {
}
}
@RequestMapping(method = RequestMethod.GET, value = {"/getWordDocument/{id}"}, produces = MediaType.APPLICATION_OCTET_STREAM_VALUE)
@RequestMapping(method = RequestMethod.GET, value = {"/getWordDocument/{id}"})
public @ResponseBody
ResponseEntity<InputStreamResource> getWordDocument(@PathVariable String id) {
ResponseEntity<byte[]> getWordDocument(@PathVariable String id) throws IllegalAccessException, IOException, InstantiationException {
try {
File file = new DatasetManager().getWordDocument(this.getApiContext().getDatabaseRepository().getDatasetDao(), id);
InputStreamResource resource = new InputStreamResource(new FileInputStream(file));
File file = new DatasetManager().getWordDocument(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), 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 " +
new MimetypesFileTypeMap().getContentType(file));
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(pdffile.length());
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
responseHeaders.set("Content-Disposition", "attachment;filename=" + pdffile.getName());
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
return ResponseEntity.ok()
.header(HttpHeaders.CONTENT_DISPOSITION,
"attachment;filename=" + file.getName())
.contentType(MediaType.APPLICATION_PDF).contentLength(file.length())
.body(resource);
} catch (Exception ex) {
ex.printStackTrace();
return new ResponseEntity<InputStreamResource>(HttpStatus.BAD_REQUEST);
byte[] content = IOUtils.toByteArray(resource);
return new ResponseEntity<>(content,
responseHeaders,
HttpStatus.OK);
} catch (Exception e) {
e.printStackTrace();
return ResponseEntity.badRequest().body(null);
}
}
}

4
dmp-backend/src/main/java/eu/eudat/controllers/Datasets.java

@ -47,8 +47,8 @@ public class Datasets extends BaseController {
public @ResponseBody
ResponseEntity<ResponseItem<Dataset>> makePublic(@PathVariable UUID id, Principal principal, Locale locale) {
try {
DatasetManager.makePublic(this.getApiContext().getDatabaseRepository().getDatasetDao(), id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Dataset>().status(ApiMessageCode.SUCCESS_MESSAGE).message(this.getApiContext().getMessageSource().getMessage("dataset.public", new Object[]{}, locale)));
DatasetManager.makePublic(this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Dataset>().status(ApiMessageCode.SUCCESS_MESSAGE).message(this.getApiContext().getHelpersService().getMessageSource().getMessage("dataset.public", new Object[]{}, locale)));
} catch (Exception ex) {
ex.printStackTrace();

4
dmp-backend/src/main/java/eu/eudat/controllers/ExternalDatasets.java

@ -44,7 +44,7 @@ public class ExternalDatasets extends BaseController {
public @ResponseBody
ResponseEntity<ResponseItem<List<ExternalDatasetListingModel>>> getWithExternal(@RequestParam(value = "query", required = false) String query, Principal principal) {
try {
List<ExternalDatasetListingModel> dataTable = new ExternalDatasetManager().getWithExternal(this.getApiContext(), query, this.getApiContext().getRemoteFetcher());
List<ExternalDatasetListingModel> dataTable = new ExternalDatasetManager().getWithExternal(this.getApiContext(), query, this.getApiContext().getOperationsContext().getRemoteFetcher());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<ExternalDatasetListingModel>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
} catch (Exception ex) {
ex.printStackTrace();
@ -56,7 +56,7 @@ public class ExternalDatasets extends BaseController {
public @ResponseBody
ResponseItem<ExternalDatasetListingModel> getWithExternal(@PathVariable UUID id, Principal principal) {
try {
ExternalDatasetListingModel externalDatasetModel = new ExternalDatasetManager().getSingle(this.getApiContext().getDatabaseRepository().getExternalDatasetDao(), id);
ExternalDatasetListingModel externalDatasetModel = new ExternalDatasetManager().getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getExternalDatasetDao(), id);
return new ResponseItem<ExternalDatasetListingModel>().payload(externalDatasetModel).status(ApiMessageCode.NO_MESSAGE);
} catch (Exception ex) {
ex.printStackTrace();

14
dmp-backend/src/main/java/eu/eudat/controllers/Login.java

@ -11,7 +11,7 @@ import eu.eudat.security.validators.b2access.B2AccessTokenValidator;
import eu.eudat.security.validators.b2access.helpers.B2AccessRequest;
import eu.eudat.security.validators.b2access.helpers.B2AccessResponseToken;
import eu.eudat.security.validators.twitter.TwitterTokenValidator;
import eu.eudat.services.AuthenticationService;
import eu.eudat.services.operations.AuthenticationServiceImpl;
import eu.eudat.types.ApiMessageCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
@ -29,16 +29,16 @@ public class Login {
private CustomAuthenticationProvider customAuthenticationProvider;
private AuthenticationService authenticationService;
private AuthenticationServiceImpl authenticationServiceImpl;
private TwitterTokenValidator twitterTokenValidator;
private B2AccessTokenValidator b2AccessTokenValidator;
@Autowired
public Login(CustomAuthenticationProvider customAuthenticationProvider, AuthenticationService authenticationService, TwitterTokenValidator twitterTokenValidator, B2AccessTokenValidator b2AccessTokenValidator) {
public Login(CustomAuthenticationProvider customAuthenticationProvider, AuthenticationServiceImpl authenticationServiceImpl, TwitterTokenValidator twitterTokenValidator, B2AccessTokenValidator b2AccessTokenValidator) {
this.customAuthenticationProvider = customAuthenticationProvider;
this.authenticationService = authenticationService;
this.authenticationServiceImpl = authenticationServiceImpl;
this.twitterTokenValidator = twitterTokenValidator;
this.b2AccessTokenValidator = b2AccessTokenValidator;
}
@ -62,7 +62,7 @@ public class Login {
public @ResponseBody
ResponseEntity<ResponseItem<Principal>> nativelogin(@RequestBody Credentials credentials) {
try {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().payload(UserManager.authenticate(this.authenticationService, credentials)).status(ApiMessageCode.SUCCESS_MESSAGE));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().payload(UserManager.authenticate(this.authenticationServiceImpl, credentials)).status(ApiMessageCode.SUCCESS_MESSAGE));
} catch (UnauthorisedException ex) {
throw ex;
} catch (Exception ex) {
@ -97,7 +97,7 @@ public class Login {
public @ResponseBody
ResponseEntity<ResponseItem<Principal>> authMe(Principal principal) {
try {
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().payload(this.authenticationService.Touch(principal.getToken())).status(ApiMessageCode.NO_MESSAGE));
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().payload(this.authenticationServiceImpl.Touch(principal.getToken())).status(ApiMessageCode.NO_MESSAGE));
} catch (Exception ex) {
ex.printStackTrace();
@ -110,7 +110,7 @@ public class Login {
public @ResponseBody
ResponseEntity<ResponseItem<Principal>> logout(Principal principal) {
try {
this.authenticationService.Logout(principal.getToken());
this.authenticationServiceImpl.Logout(principal.getToken());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<Principal>().status(ApiMessageCode.NO_MESSAGE));
} catch (Exception ex) {

2
dmp-backend/src/main/java/eu/eudat/controllers/Organisations.java

@ -29,7 +29,7 @@ public class Organisations extends BaseController {
public @ResponseBody
ResponseEntity<ResponseItem<OrganisationsExternalSourcesModel>> listExternalOrganisations(@RequestParam(value = "query", required = false) String query) {
try {
List<Map<String, String>> remoteRepos = this.getApiContext().getRemoteFetcher().getOrganisations(query);
List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getOrganisations(query);
OrganisationsExternalSourcesModel projectsExternalSourcesModel = new OrganisationsExternalSourcesModel().fromExternalItem(remoteRepos);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<OrganisationsExternalSourcesModel>().payload(projectsExternalSourcesModel).status(ApiMessageCode.SUCCESS_MESSAGE));
} catch (NoURLFound ex) {

14
dmp-backend/src/main/java/eu/eudat/controllers/Projects.java

@ -38,7 +38,7 @@ public class Projects extends BaseController {
public @ResponseBody
ResponseEntity<ResponseItem<DataTableData<ProjectListingModel>>> getPaged(@Valid @RequestBody ProjectTableRequest projectTableRequest, Principal principal) {
try {
DataTableData<eu.eudat.models.project.ProjectListingModel> dataTable = new ProjectManager().getPaged(this.getApiContext().getDatabaseRepository().getProjectDao(), projectTableRequest);
DataTableData<eu.eudat.models.project.ProjectListingModel> dataTable = new ProjectManager().getPaged(this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), projectTableRequest);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<eu.eudat.models.project.ProjectListingModel>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
} catch (Exception ex) {
@ -51,7 +51,7 @@ public class Projects extends BaseController {
public @ResponseBody
ResponseEntity<ResponseItem<eu.eudat.models.project.Project>> getSingle(@PathVariable String id, Principal principal) {
try {
eu.eudat.models.project.Project project = new ProjectManager().getSingle(this.getApiContext().getDatabaseRepository().getProjectDao(), id);
eu.eudat.models.project.Project project = new ProjectManager().getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.project.Project>().payload(project).status(ApiMessageCode.NO_MESSAGE));
} catch (Exception ex) {
ex.printStackTrace();
@ -65,7 +65,7 @@ public class Projects extends BaseController {
public @ResponseBody
ResponseEntity<ResponseItem<Project>> addProject(@Valid @RequestBody eu.eudat.models.project.Project project, Principal principal) {
try {
ProjectManager.createOrUpdate(this.getApiContext().getDatabaseRepository().getProjectDao(), this.getApiContext().getDatabaseRepository().getUserInfoDao(), project, principal);
ProjectManager.createOrUpdate(this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), this.getApiContext().getOperationsContext().getDatabaseRepository().getUserInfoDao(), project, principal);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.entities.Project>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
} catch (Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.entities.Project>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
@ -78,7 +78,7 @@ public class Projects extends BaseController {
public @ResponseBody
ResponseEntity<ResponseItem<Project>> inactivate(@PathVariable String id, Principal principal) {
try {
Project project = new ProjectManager().inactivate(this.getApiContext().getDatabaseRepository().getProjectDao(), id);
Project project = new ProjectManager().inactivate(this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), id);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.entities.Project>().status(ApiMessageCode.SUCCESS_MESSAGE));
} catch (Exception ex) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(new ResponseItem<eu.eudat.entities.Project>().status(ApiMessageCode.DEFAULT_ERROR_MESSAGE).message(ex.getMessage()));
@ -90,7 +90,7 @@ public class Projects extends BaseController {
public @ResponseBody
ResponseEntity<ResponseItem<List<eu.eudat.models.project.Project>>> getWithExternal(@RequestBody ProjectCriteriaRequest projectCriteria, Principal principal) {
try {
List<eu.eudat.models.project.Project> dataTable = new ProjectManager().getCriteriaWithExternal(this.getApiContext(), projectCriteria, this.getApiContext().getRemoteFetcher());
List<eu.eudat.models.project.Project> dataTable = new ProjectManager().getCriteriaWithExternal(this.getApiContext(), projectCriteria, this.getApiContext().getOperationsContext().getRemoteFetcher());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<eu.eudat.models.project.Project>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
} catch (Exception ex) {
ex.printStackTrace();
@ -102,7 +102,7 @@ public class Projects extends BaseController {
public @ResponseBody
ResponseEntity<ResponseItem<List<eu.eudat.models.project.Project>>> get(@RequestBody ProjectCriteriaRequest projectCriteria, Principal principal) {
try {
List<eu.eudat.models.project.Project> dataTable = new ProjectManager().getCriteria(this.getApiContext().getDatabaseRepository().getProjectDao(), projectCriteria, this.getApiContext().getRemoteFetcher());
List<eu.eudat.models.project.Project> dataTable = new ProjectManager().getCriteria(this.getApiContext().getOperationsContext().getDatabaseRepository().getProjectDao(), projectCriteria, this.getApiContext().getOperationsContext().getRemoteFetcher());
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<eu.eudat.models.project.Project>>().payload(dataTable).status(ApiMessageCode.NO_MESSAGE));
} catch (Exception ex) {
ex.printStackTrace();
@ -114,7 +114,7 @@ public class Projects extends BaseController {
public @ResponseBody
ResponseEntity<ResponseItem<ProjectsExternalSourcesModel>> listExternalProjects(@RequestParam(value = "query", required = false) String query, Principal principal) {
try {
List<Map<String, String>> remoteRepos = this.getApiContext().getRemoteFetcher().getProjects(query);
List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getProjects(query);
ProjectsExternalSourcesModel projectsExternalSourcesModel = new ProjectsExternalSourcesModel().fromExternalItem(remoteRepos);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ProjectsExternalSourcesModel>().payload(projectsExternalSourcesModel).status(ApiMessageCode.SUCCESS_MESSAGE));
} catch (NoURLFound ex) {

2
dmp-backend/src/main/java/eu/eudat/controllers/Registries.java

@ -29,7 +29,7 @@ public class Registries extends BaseController {
public @ResponseBody
ResponseEntity<ResponseItem<RegistriesExternalSourcesModel>> listExternalRegistries(@RequestParam(value = "query", required = false) String query) {
try {
List<Map<String, String>> remoteRepos = this.getApiContext().getRemoteFetcher().getRegistries(query);
List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getRegistries(query);
RegistriesExternalSourcesModel registriesExternalSourcesModel = new RegistriesExternalSourcesModel().fromExternalItem(remoteRepos);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<RegistriesExternalSourcesModel>().payload(registriesExternalSourcesModel).status(ApiMessageCode.NO_MESSAGE));
} catch (NoURLFound ex) {

2
dmp-backend/src/main/java/eu/eudat/controllers/Researchers.java

@ -35,7 +35,7 @@ public class Researchers extends BaseController {
public @ResponseBody
ResponseEntity<ResponseItem<ResearchersExternalSourcesModel>> listExternalResearchers(@RequestParam(value = "query", required = false) String query) {
try {
List<Map<String, String>> remoteRepos = this.getApiContext().getRemoteFetcher().getResearchers(query);
List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getResearchers(query);
ResearchersExternalSourcesModel researchersExternalSourcesModel = new ResearchersExternalSourcesModel().fromExternalItem(remoteRepos);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ResearchersExternalSourcesModel>().payload(researchersExternalSourcesModel).status(ApiMessageCode.NO_MESSAGE));
} catch (NoURLFound ex) {

2
dmp-backend/src/main/java/eu/eudat/controllers/Services.java

@ -29,7 +29,7 @@ public class Services extends BaseController {
public @ResponseBody
ResponseEntity<ResponseItem<ServiceExternalSourcesModel>> listExternalServices(@RequestParam(value = "query", required = false) String query) {
try {
List<Map<String, String>> remoteRepos = this.getApiContext().getRemoteFetcher().getServices(query);
List<Map<String, String>> remoteRepos = this.getApiContext().getOperationsContext().getRemoteFetcher().getServices(query);
ServiceExternalSourcesModel serviceExternalSourcesModel = new ServiceExternalSourcesModel().fromExternalItem(remoteRepos);
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<ServiceExternalSourcesModel>().payload(serviceExternalSourcesModel).status(ApiMessageCode.NO_MESSAGE));
} catch (NoURLFound ex) {

38
dmp-backend/src/main/java/eu/eudat/controllers/controllerhandler/GeneralErrorHandler.java

@ -0,0 +1,38 @@
package eu.eudat.controllers.controllerhandler;
import eu.eudat.models.helpers.responses.ResponseItem;
import eu.eudat.services.ApiContext;
import eu.eudat.types.ApiMessageCode;
import eu.eudat.types.WarningLevel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import javax.servlet.http.HttpServletRequest;
/**
* Created by ikalyvas on 3/1/2018.
*/
@ControllerAdvice
public class GeneralErrorHandler extends ResponseEntityExceptionHandler {
private ApiContext apiContext;
@Autowired
public GeneralErrorHandler(ApiContext apiContext) {
this.apiContext = apiContext;
}
@ExceptionHandler(Exception.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
@ResponseBody
public ResponseItem<?> processValidationError(HttpServletRequest req, Exception ex) {
apiContext.getHelpersService().getLoggerService().log(ex.getMessage(), WarningLevel.ERROR);
return new ResponseItem().status(ApiMessageCode.ERROR_MESSAGE).message(ex.getMessage());
}
}

33
dmp-backend/src/main/java/eu/eudat/controllers/interceptors/RequestInterceptor.java

@ -0,0 +1,33 @@
package eu.eudat.controllers.interceptors;
import eu.eudat.services.helpers.LoggerService;
import eu.eudat.types.WarningLevel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Date;
/**
* Created by ikalyvas on 3/1/2018.
*/
@Component
public class RequestInterceptor extends HandlerInterceptorAdapter {
private LoggerService loggerService;
@Autowired
public RequestInterceptor(LoggerService loggerService) {
this.loggerService = loggerService;
}
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
String reqUri = request.getRequestURI();
this.loggerService.log("Call to " + reqUri + " method: " + request.getMethod() + " at: " + new Date(), WarningLevel.INFO);
return super.preHandle(request, response, handler);
}
}

69
dmp-backend/src/main/java/eu/eudat/documents/word/WordBuilder.java

@ -7,7 +7,8 @@ import eu.eudat.models.user.components.datasetprofile.FieldSet;
import eu.eudat.models.user.components.datasetprofile.Section;
import eu.eudat.models.user.composite.DatasetProfilePage;
import eu.eudat.models.user.composite.PagedDatasetProfile;
import eu.eudat.utilities.interfaces.Applier;
import eu.eudat.services.forms.VisibilityRuleService;
import eu.eudat.utilities.interfaces.ApplierWithValue;
import org.apache.poi.xwpf.usermodel.*;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
@ -15,6 +16,7 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLvl;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STNumberFormat;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.math.BigInteger;
@ -27,7 +29,7 @@ import java.util.Map;
*/
public class WordBuilder {
private Map<ParagraphStyle, Applier<XWPFDocument, String, XWPFParagraph>> options = new HashMap<>();
private Map<ParagraphStyle, ApplierWithValue<XWPFDocument, String, XWPFParagraph>> options = new HashMap<>();
private CTAbstractNum cTAbstractNum;
private BigInteger numId;
@ -87,63 +89,69 @@ public class WordBuilder {
});
}
public File build(PagedDatasetProfile pagedDatasetProfile) throws IOException {
XWPFDocument document = new XWPFDocument();
public File build(PagedDatasetProfile pagedDatasetProfile, String label, VisibilityRuleService visibilityRuleService) throws IOException {
XWPFDocument document = new XWPFDocument(new FileInputStream((WordBuilder.class.getClassLoader().getResource("documents/h2020.docx")).getFile()));
this.buildOptions();
createPages(pagedDatasetProfile.getPages(), document, true);
createPages(pagedDatasetProfile.getPages(), document, true, visibilityRuleService);
XWPFAbstractNum abstractNum = new XWPFAbstractNum(cTAbstractNum);
XWPFNumbering numbering = document.createNumbering();
BigInteger abstractNumID = numbering.addAbstractNum(abstractNum);
this.numId = numbering.addNum(abstractNumID);
createPages(pagedDatasetProfile.getPages(), document, false);
File exportFile = new File("welcome.docx");
createPages(pagedDatasetProfile.getPages(), document, false, visibilityRuleService);
File exportFile = new File(label);
FileOutputStream out = new FileOutputStream(exportFile);
document.write(out);
out.close();
return exportFile;
}
public void createPages(List<DatasetProfilePage> datasetProfilePages, XWPFDocument mainDocumentPart, Boolean createListing) {
public void createPages(List<DatasetProfilePage> datasetProfilePages, XWPFDocument mainDocumentPart, Boolean createListing, VisibilityRuleService visibilityRuleService) {
//if (createListing) this.addListing(mainDocumentPart, 0, false, true);
datasetProfilePages.forEach(item -> {
createSections(item.getSections(), mainDocumentPart, ParagraphStyle.TITLE, 0, createListing);
createSections(item.getSections(), mainDocumentPart, ParagraphStyle.TITLE, 0, createListing, visibilityRuleService);
});
}
public void createSections(List<Section> sections, XWPFDocument mainDocumentPart, ParagraphStyle style, Integer indent, Boolean createListing) {
public void createSections(List<Section> sections, XWPFDocument mainDocumentPart, ParagraphStyle style, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService) {
if (createListing) this.addListing(mainDocumentPart, indent, false, true);
BigInteger listing = numId;
sections.forEach(section -> {
if (!createListing) {
XWPFParagraph paragraph = addParagraphContent(section.getTitle(), mainDocumentPart, style, listing);
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent));
if (visibilityRuleService.isElementVisible(section.getId())) {
if (!createListing) {
XWPFParagraph paragraph = addParagraphContent(section.getTitle(), mainDocumentPart, style, listing);
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent));
}
createSections(section.getSections(), mainDocumentPart, ParagraphStyle.HEADER2, 1, createListing, visibilityRuleService);
createCompositeFields(section.getCompositeFields(), mainDocumentPart, 2, createListing, visibilityRuleService);
}
createSections(section.getSections(), mainDocumentPart, ParagraphStyle.HEADER2, 1, createListing);
createCompositeFields(section.getCompositeFields(), mainDocumentPart, 2, createListing);
});
}
public void createCompositeFields(List<FieldSet> compositeFields, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing) {
public void createCompositeFields(List<FieldSet> compositeFields, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService) {
if (createListing) this.addListing(mainDocumentPart, indent, true, true);
compositeFields.forEach(compositeField -> {
if (compositeField.getTitle() != null && !compositeField.getTitle().isEmpty() && !createListing) {
XWPFParagraph paragraph = addParagraphContent(compositeField.getTitle(), mainDocumentPart, ParagraphStyle.HEADER3, numId);
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent));
if (visibilityRuleService.isElementVisible(compositeField.getId())) {
if (compositeField.getTitle() != null && !compositeField.getTitle().isEmpty() && !createListing) {
XWPFParagraph paragraph = addParagraphContent(compositeField.getTitle(), mainDocumentPart, ParagraphStyle.HEADER3, numId);
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent));
}
createFields(compositeField.getFields(), mainDocumentPart, 3, createListing, visibilityRuleService);
}
createFields(compositeField.getFields(), mainDocumentPart, 3, createListing);
});
}
public void createFields(List<Field> fields, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing) {
public void createFields(List<Field> fields, XWPFDocument mainDocumentPart, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService) {
if (createListing) this.addListing(mainDocumentPart, indent, false, false);
fields.forEach(field -> {
if (!createListing) {
XWPFParagraph paragraph = addParagraphContent(field.getValue(), mainDocumentPart, ParagraphStyle.TEXT, numId);
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent));
if (visibilityRuleService.isElementVisible(field.getId())) {
if (!createListing) {
XWPFParagraph paragraph = addParagraphContent(field.getValue() == null ? "" : field.getValue(), mainDocumentPart, ParagraphStyle.TEXT, numId);
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
number.setVal(BigInteger.valueOf(indent));
}
}
});
}
@ -173,13 +181,18 @@ public class WordBuilder {
cTLvl.addNewNumFmt().setVal(STNumberFormat.DECIMAL);
cTLvl.addNewLvlText().setVal("Q " + textLevel);
cTLvl.addNewStart().setVal(BigInteger.valueOf(1));
cTLvl.setIlvl(BigInteger.valueOf(indent));
} else if (!question && hasIndication) {
cTLvl.addNewNumFmt().setVal(STNumberFormat.DECIMAL);
cTLvl.addNewLvlText().setVal(textLevel);
cTLvl.addNewStart().setVal(BigInteger.valueOf(1));
cTLvl.setIlvl(BigInteger.valueOf(indent));
}
if (!question && !hasIndication) {
cTLvl.addNewNumFmt().setVal(STNumberFormat.NONE);
cTLvl.addNewLvlText().setVal("");
cTLvl.addNewStart().setVal(BigInteger.valueOf(1));
cTLvl.setIlvl(BigInteger.valueOf(indent));
}
/*if (this.numId == null) {

3
dmp-backend/src/main/java/eu/eudat/handlers/PrincipalArgumentResolver.java

@ -3,7 +3,8 @@ package eu.eudat.handlers;
import eu.eudat.exceptions.security.UnauthorisedException;
import eu.eudat.models.security.Principal;
import eu.eudat.security.claims.ClaimedAuthorities;
import eu.eudat.services.AuthenticationService;
import eu.eudat.services.operations.AuthenticationService;
import eu.eudat.services.operations.AuthenticationServiceImpl;
import eu.eudat.types.Authorities;
import org.springframework.core.MethodParameter;
import org.springframework.web.bind.support.WebDataBinderFactory;

2
dmp-backend/src/main/java/eu/eudat/managers/AdminManager.java

@ -22,7 +22,7 @@ public class AdminManager {
viewStyleDoc.appendChild(elementViewStyle);
String xml = XmlBuilder.generateXml(viewStyleDoc);
eu.eudat.entities.DatasetProfile datasetProfile = apiContext.getBuilderFactory().getBuilder(DatasetProfileBuilder.class).definition(xml).label(profile.getLabel())
eu.eudat.entities.DatasetProfile datasetProfile = apiContext.getOperationsContext().getBuilderFactory().getBuilder(DatasetProfileBuilder.class).definition(xml).label(profile.getLabel())
.status((short) 1).created(new Date())
.build();

46
dmp-backend/src/main/java/eu/eudat/managers/DataManagementPlanManager.java

@ -33,8 +33,8 @@ public class DataManagementPlanManager {
public DataTableData<DataManagementPlanListingModel> getPaged(ApiContext apiContext, DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal) throws Exception {
UserInfo userInfo = new UserInfo();
userInfo.setId(principal.getId());
QueryableList<DMP> items = apiContext.getDatabaseRepository().getDmpDao().getWithCriteria(dataManagementPlanTableRequest.getCriteria());
QueryableList<DMP> authItems = apiContext.getDatabaseRepository().getDmpDao().getAuthenticated(items, userInfo);
QueryableList<DMP> items = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getWithCriteria(dataManagementPlanTableRequest.getCriteria());
QueryableList<DMP> authItems = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().getAuthenticated(items, userInfo);
QueryableList<DMP> pagedItems = PaginationManager.applyPaging(authItems, dataManagementPlanTableRequest);
DataTableData<DataManagementPlanListingModel> dataTable = new DataTableData<DataManagementPlanListingModel>();
@ -68,12 +68,12 @@ public class DataManagementPlanManager {
public static void createOrUpdate(ApiContext apiContext, DataManagementPlan dataManagementPlan, Principal principal) throws Exception {
DMP newDmp = dataManagementPlan.toDataModel();
createOrganisationsIfTheyDontExist(newDmp, apiContext.getDatabaseRepository().getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, apiContext.getDatabaseRepository().getResearcherDao());
UserInfo user = apiContext.getDatabaseRepository().getUserInfoDao().find(principal.getId());
createProjectIfItDoesntExist(newDmp, apiContext.getDatabaseRepository().getProjectDao(), user);
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
UserInfo user = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().find(principal.getId());
createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao(), user);
newDmp.setCreator(user);
newDmp = apiContext.getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
if (dataManagementPlan.getAssociatedUsers().stream().filter(item -> item.getId() == principal.getId()).collect(Collectors.toList()).size() == 0)
assignUser(newDmp, user, apiContext);
}
@ -83,44 +83,44 @@ public class DataManagementPlanManager {
userDMP.setDmp(dmp);
userDMP.setUser(userInfo);
userDMP.setRole(UserDMP.UserDMPRoles.OWNER.getValue());
apiContext.getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP);
apiContext.getOperationsContext().getDatabaseRepository().getUserDmpDao().createOrUpdate(userDMP);
}
public static void newVersion(ApiContext apiContext, UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
DMP oldDmp = apiContext.getDatabaseRepository().getDmpDao().find(uuid);
DMP oldDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(uuid);
DMP newDmp = dataManagementPlan.toDataModel();
createOrganisationsIfTheyDontExist(newDmp, apiContext.getDatabaseRepository().getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, apiContext.getDatabaseRepository().getResearcherDao());
UserInfo user = apiContext.getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
createProjectIfItDoesntExist(newDmp, apiContext.getDatabaseRepository().getProjectDao(), user);
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao(), user);
newDmp.setCreator(user);
newDmp.setGroupId(oldDmp.getGroupId());
newDmp.setVersion(oldDmp.getVersion() + 1);
newDmp.setId(null);
newDmp = apiContext.getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
copyDatasets(newDmp, apiContext.getDatabaseRepository().getDatasetDao());
newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
copyDatasets(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao());
}
public static void clone(ApiContext apiContext, UUID uuid, DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
DMP newDmp = dataManagementPlan.toDataModel();
createOrganisationsIfTheyDontExist(newDmp, apiContext.getDatabaseRepository().getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, apiContext.getDatabaseRepository().getResearcherDao());
UserInfo user = apiContext.getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
createProjectIfItDoesntExist(newDmp, apiContext.getDatabaseRepository().getProjectDao(), user);
createOrganisationsIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getOrganisationDao());
createResearchersIfTheyDontExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getResearcherDao());
UserInfo user = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
createProjectIfItDoesntExist(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getProjectDao(), user);
newDmp.setCreator(user);
newDmp.setGroupId(UUID.randomUUID());
newDmp.setVersion(0);
newDmp.setId(null);
newDmp = apiContext.getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
copyDatasets(newDmp, apiContext.getDatabaseRepository().getDatasetDao());
newDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(newDmp);
copyDatasets(newDmp, apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao());
}
public static void delete(ApiContext apiContext, UUID uuid) throws DMPWithDatasetsException {
DMP oldDmp = apiContext.getDatabaseRepository().getDmpDao().find(uuid);
DMP oldDmp = apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().find(uuid);
if (oldDmp.getDataset().size() > 0)
throw new DMPWithDatasetsException("You cannot Remove Datamanagement Plan with Datasets");
oldDmp.setStatus(DMP.DMPStatus.DELETED.getValue());
apiContext.getDatabaseRepository().getDmpDao().createOrUpdate(oldDmp);
apiContext.getOperationsContext().getDatabaseRepository().getDmpDao().createOrUpdate(oldDmp);
}
private static void createResearchersIfTheyDontExist(DMP newDmp, ResearcherDao researcherRepository) {

112
dmp-backend/src/main/java/eu/eudat/managers/DatasetManager.java

@ -17,24 +17,32 @@ import eu.eudat.models.security.Principal;
import eu.eudat.models.user.composite.PagedDatasetProfile;
import eu.eudat.queryable.QueryableList;
import eu.eudat.services.ApiContext;
import eu.eudat.services.forms.VisibilityRuleService;
import org.apache.commons.io.IOUtils;
import org.json.JSONObject;
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.util.LinkedMultiValueMap;
import org.springframework.web.client.RestTemplate;
import javax.xml.bind.JAXBException;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class DatasetManager {
public DataTableData<DatasetListingModel> getPaged(ApiContext apiContext, DatasetTableRequest datasetTableRequest, Principal principal) throws Exception {
UserInfo userInfo = apiContext.getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
QueryableList<eu.eudat.entities.Dataset> items = apiContext.getDatabaseRepository().getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria());
QueryableList<eu.eudat.entities.Dataset> authItems = apiContext.getDatabaseRepository().getDatasetDao().getAuthenticated(items, userInfo);
UserInfo userInfo = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
QueryableList<eu.eudat.entities.Dataset> items = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getWithCriteria(datasetTableRequest.getCriteria());
QueryableList<eu.eudat.entities.Dataset> authItems = apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().getAuthenticated(items, userInfo);
QueryableList<eu.eudat.entities.Dataset> pagedItems = PaginationManager.applyPaging(authItems, datasetTableRequest);
DataTableData<DatasetListingModel> dataTable = new DataTableData<DatasetListingModel>();
@ -72,24 +80,94 @@ public class DatasetManager {
return pagedDatasetProfile;
}
public File getWordDocument(DatasetDao datatasetRepository, String id) throws InstantiationException, IllegalAccessException, IOException {
public File getWordDocument(DatasetDao datatasetRepository, String id, VisibilityRuleService visibilityRuleService) throws InstantiationException, IllegalAccessException, IOException {
WordBuilder wordBuilder = new WordBuilder();
DatasetWizardModel dataset = new DatasetWizardModel();
eu.eudat.entities.Dataset datasetEntity = datatasetRepository.find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
PagedDatasetProfile pagedDatasetProfile = getPagedProfile(dataset,datasetEntity);
return wordBuilder.build(pagedDatasetProfile);
Map<String, Object> properties = new HashMap<>();
if (datasetEntity.getProperties() != null) {
JSONObject jobject = new JSONObject(datasetEntity.getProperties());
properties = (Map<String, Object>) jobject.toMap();
}
PagedDatasetProfile pagedDatasetProfile = getPagedProfile(dataset, datasetEntity);
visibilityRuleService.setProperties(properties);
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
File file = wordBuilder.build(pagedDatasetProfile, datasetEntity.getLabel(),visibilityRuleService);
return file;
}
public File convertToPDF(File file, Environment environment, String label) throws IOException, InterruptedException {
LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
map.add("file", new FileSystemResource(file));
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<LinkedMultiValueMap<String, Object>>(
map, headers);
Map queueResult = new RestTemplate().postForObject(
environment.getProperty("pdf.converter.url") +
"api/v1/", requestEntity, Map.class);
Map mediaResult = new RestTemplate().getForObject(environment.getProperty("pdf.converter.url") +
"/api/v1/" + queueResult.get("id"), Map.class);
System.out.println("Status: " + mediaResult.get("status"));
while (!mediaResult.get("status").equals("finished")) {
Thread.sleep(500);
mediaResult = new RestTemplate().getForObject(environment.getProperty("pdf.converter.url") +
"api/v1/" + queueResult.get("id"), Map.class);
System.out.println("Polling");
}
RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new ByteArrayHttpMessageConverter());
HttpHeaders headers2 = new HttpHeaders();
headers.setAccept(Arrays.asList(MediaType.APPLICATION_OCTET_STREAM));
HttpEntity<String> entity = new HttpEntity<String>(headers2);
ResponseEntity<byte[]> response = restTemplate.exchange(environment.getProperty("pdf.converter.url") +
mediaResult.get("result_url"), HttpMethod.GET, entity, byte[].class, "1");
UUID uuid = UUID.randomUUID();
File zip = new File(uuid + ".zip");
if (response.getStatusCode().equals(HttpStatus.OK)) {
FileOutputStream output = new FileOutputStream(zip);
IOUtils.write(response.getBody(), output);
}
return extractFromZip(zip, label + ".pdf");
}
private File extractFromZip(File file, String filename) throws IOException {
byte[] buffer = new byte[1024];
File newFile = new File(filename);
ZipInputStream zis = new ZipInputStream(new FileInputStream(file));
ZipEntry zipEntry = zis.getNextEntry();
while (zipEntry != null) {
String zippedFileName = zipEntry.getName();
if (zippedFileName.equals("pdf")) {
FileOutputStream fos = new FileOutputStream(newFile);
int len;
while ((len = zis.read(buffer)) > 0) {
fos.write(buffer, 0, len);
}
fos.close();
zipEntry = zis.getNextEntry();
}
}
zis.closeEntry();
zis.close();
return newFile;
}
public static eu.eudat.entities.Dataset createOrUpdate(ApiContext apiContext, DatasetWizardModel profile, Principal principal) throws Exception {
eu.eudat.entities.Dataset dataset = profile.toDataModel();
propertiesModelToString(profile, dataset);
UserInfo userInfo = apiContext.getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
UserInfo userInfo = apiContext.getOperationsContext().getBuilderFactory().getBuilder(UserInfoBuilder.class).id(principal.getId()).build();
dataset.setCreator(userInfo);
createRegistriesIfTheyDontExist(apiContext.getDatabaseRepository().getRegistryDao(), dataset);
createDataRepositoriesIfTheyDontExist(apiContext.getDatabaseRepository().getDataRepositoryDao(), dataset);
createServicesIfTheyDontExist(apiContext.getDatabaseRepository().getServiceDao(), dataset);
createExternalDatasetsIfTheyDontExist(apiContext.getDatabaseRepository().getExternalDatasetDao(), dataset);
return apiContext.getDatabaseRepository().getDatasetDao().createOrUpdate(dataset);
createRegistriesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getRegistryDao(), dataset);
createDataRepositoriesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getDataRepositoryDao(), dataset);
createServicesIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getServiceDao(), dataset);
createExternalDatasetsIfTheyDontExist(apiContext.getOperationsContext().getDatabaseRepository().getExternalDatasetDao(), dataset);
return apiContext.getOperationsContext().getDatabaseRepository().getDatasetDao().createOrUpdate(dataset);
}
private static void propertiesModelToString(DatasetWizardModel datasetWizardModel, eu.eudat.entities.Dataset dataset) {

4
dmp-backend/src/main/java/eu/eudat/managers/DatasetProfileManager.java

@ -24,10 +24,10 @@ public class DatasetProfileManager {
}
public static DataTableData<DatasetProfileListingModel> getPaged(ApiContext apiContext, DatasetProfileTableRequestItem datasetProfileTableRequestItem) throws Exception {
QueryableList<DatasetProfile> items = apiContext.getDatabaseRepository().getDatasetProfileDao().getWithCriteria(datasetProfileTableRequestItem.getCriteria());
QueryableList<DatasetProfile> items = apiContext.getOperationsContext().getDatabaseRepository().getDatasetProfileDao().getWithCriteria(datasetProfileTableRequestItem.getCriteria());
QueryableList<DatasetProfile> pagedItems = PaginationManager.applyPaging(items, datasetProfileTableRequestItem);
List<DatasetProfileListingModel> datasetProfiles = pagedItems.select(item -> new DatasetProfileListingModel().fromDataModel(item));
return apiContext.getBuilderFactory().getBuilder(DataTableDataBuilder.class).data(datasetProfiles).totalCount(items.count()).build();
return apiContext.getOperationsContext().getBuilderFactory().getBuilder(DataTableDataBuilder.class).data(datasetProfiles).totalCount(items.count()).build();
}
public static List<DatasetProfileListingModel> getAll(DatasetProfileDao datasetProfileRepository) throws IllegalAccessException, InstantiationException {

8