diff --git a/.gitignore b/.gitignore index 10071e274..4d5ad0218 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ temp/ *.jar *.lst dmp-frontend/.vscode/ +*.docx diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDaoImpl.java b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDaoImpl.java index 43dddd194..55f6670cc 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDaoImpl.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/dao/entities/DMPDaoImpl.java @@ -40,7 +40,9 @@ public class DMPDaoImpl extends DatabaseAccess implements DMPDao { if (criteria.getProjects() != null && !criteria.getProjects().isEmpty()) query.where(((builder, root) -> root.get("project").in(criteria.getProjects()))); if (!criteria.getAllVersions()) - query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("version"), query.subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("groupId"), nestedRoot.get("groupId")), Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "version")), String.class))); + query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("version"), + query.subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("groupId"), + nestedRoot.get("groupId")), Arrays.asList(new SelectionField(FieldSelectionType.FIELD, "version")), String.class))); if (criteria.getGroupIds() != null && !criteria.getGroupIds().isEmpty()) query.where((builder, root) -> root.get("groupId").in(criteria.getGroupIds())); query.where((builder, root) -> builder.notEqual(root.get("status"), DMP.DMPStatus.DELETED.getValue())); diff --git a/dmp-backend/data/src/main/java/eu/eudat/data/entities/Dataset.java b/dmp-backend/data/src/main/java/eu/eudat/data/entities/Dataset.java index 3a555cdf1..53bc5af63 100644 --- a/dmp-backend/data/src/main/java/eu/eudat/data/entities/Dataset.java +++ b/dmp-backend/data/src/main/java/eu/eudat/data/entities/Dataset.java @@ -15,11 +15,13 @@ import java.util.stream.Collectors; @NamedEntityGraphs({ @NamedEntityGraph( name = "datasetListingModel", - attributeNodes = {@NamedAttributeNode("services"), @NamedAttributeNode(value = "datasetDataRepositories", subgraph = "datasetDataRepositories"), @NamedAttributeNode("datasetExternalDatasets"), @NamedAttributeNode("registries"), + attributeNodes = {@NamedAttributeNode("services"), @NamedAttributeNode(value = "datasetDataRepositories", subgraph = "datasetDataRepositories"), + @NamedAttributeNode(value = "datasetExternalDatasets", subgraph = "datasetExternalDatasets"), @NamedAttributeNode("registries"), @NamedAttributeNode(value = "dmp", subgraph = "dmp"), @NamedAttributeNode("profile"), @NamedAttributeNode("creator")}, subgraphs = { @NamedSubgraph(name = "dmp", attributeNodes = {@NamedAttributeNode("creator"), @NamedAttributeNode("users"), @NamedAttributeNode("project"), @NamedAttributeNode("organisations")}), - @NamedSubgraph(name = "datasetDataRepositories", attributeNodes = {@NamedAttributeNode("dataRepository")}) + @NamedSubgraph(name = "datasetDataRepositories", attributeNodes = {@NamedAttributeNode("dataRepository")}), + @NamedSubgraph(name = "datasetExternalDatasets", attributeNodes = {@NamedAttributeNode("externalDataset")}) }), @NamedEntityGraph( diff --git a/dmp-backend/web/src/main/java/eu/eudat/configurations/DevelDatabaseConfiguration.java b/dmp-backend/web/src/main/java/eu/eudat/configurations/DevelDatabaseConfiguration.java index 7227b8a69..aff90c1ff 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/configurations/DevelDatabaseConfiguration.java +++ b/dmp-backend/web/src/main/java/eu/eudat/configurations/DevelDatabaseConfiguration.java @@ -72,7 +72,6 @@ public class DevelDatabaseConfiguration { properties.setProperty("hibernate.c3p0.maxPoolSize", "70"); properties.setProperty("hibernate.c3p0.timeout", "5000"); properties.setProperty("hibernate.connection.release_mode", "after_transaction"); - //properties.setProperty("hibernate.connection.provider_class", "org.hibernate.c3p0.internal.C3P0ConnectionProvider"); return properties; } } \ No newline at end of file diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java index b12957671..aa9b021ea 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/Admin.java @@ -44,19 +44,15 @@ public class Admin extends BaseController { @Transactional @RequestMapping(method = RequestMethod.POST, value = {"/admin/addDmp/{id}"}, consumes = "application/json", produces = "application/json") public ResponseEntity> updateDmp(@PathVariable String id, @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { - //this.getLoggerService().info(principal, "Admin Edited Dataset Profile"); eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(profile, getApiContext()); - eu.eudat.data.entities.DatasetProfile datasetprofile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); datasetprofile.setDefinition(modelDefinition.getDefinition()); this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(datasetprofile); - return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE)); } @RequestMapping(method = RequestMethod.GET, value = {"/admin/get/{id}"}, produces = "application/json") public ResponseEntity> get(@PathVariable String id, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { - //this.getLoggerService().info(principal, "Admin Open Dataset Profile"); eu.eudat.data.entities.DatasetProfile profile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id)); eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile); datasetprofile.setLabel(profile.getLabel()); @@ -65,7 +61,6 @@ public class Admin extends BaseController { @RequestMapping(method = RequestMethod.POST, value = {"/admin/preview"}, consumes = "application/json",produces = "application/json") public ResponseEntity> getPreview(@RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) { - //this.getLoggerService().info(principal, "Admin Previewed Dataset Profile"); eu.eudat.data.entities.DatasetProfile modelDefinition = AdminManager.generateViewStyleDefinition(profile, getApiContext()); eu.eudat.models.data.user.composite.DatasetProfile datasetProfile = UserManager.generateDatasetProfileModel(modelDefinition); PagedDatasetProfile pagedDatasetProfile = new PagedDatasetProfile(); 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 d385fd97d..8e7b07b6b 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 @@ -8,6 +8,7 @@ import eu.eudat.data.entities.DMP; import eu.eudat.data.query.items.item.dmp.DataManagementPlanCriteriaRequest; import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest; import eu.eudat.logic.managers.DataManagementPlanManager; +import eu.eudat.logic.managers.DatasetManager; import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.utilities.documents.helpers.FileEnvelope; import eu.eudat.models.data.dmp.DataManagementPlan; @@ -19,6 +20,7 @@ import eu.eudat.models.data.security.Principal; import eu.eudat.types.ApiMessageCode; import org.apache.commons.io.IOUtils; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; @@ -28,6 +30,7 @@ import org.springframework.web.bind.annotation.*; import javax.activation.MimetypesFileTypeMap; import javax.validation.Valid; +import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; @@ -37,33 +40,36 @@ import java.util.UUID; @RestController @CrossOrigin -@RequestMapping(value = {"/api"}) +@RequestMapping(value = {"/api/dmps/"}) public class DMPs extends BaseController { private DynamicProjectConfiguration dynamicProjectConfiguration; + private Environment environment; @Autowired - public DMPs(ApiContext apiContext, DynamicProjectConfiguration dynamicProjectConfiguration) { + public DMPs(ApiContext apiContext, DynamicProjectConfiguration dynamicProjectConfiguration, Environment environment) { super(apiContext); this.dynamicProjectConfiguration = dynamicProjectConfiguration; + this.environment = environment; + } @Transactional - @RequestMapping(method = RequestMethod.GET, value = {"/dmps/{id}/unlock"}, produces = "application/json") + @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); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Unlocked")); } - @RequestMapping(method = RequestMethod.POST, value = {"/dmps/getPaged"}, consumes = "application/json", produces = "application/json") + @RequestMapping(method = RequestMethod.POST, value = {"/getPaged"}, 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); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable)); } - @RequestMapping(method = RequestMethod.GET, value = {"/dmps/getSingle/{id}"}, produces = "application/json") + @RequestMapping(method = RequestMethod.GET, value = {"/getSingle/{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); @@ -71,28 +77,28 @@ public class DMPs extends BaseController { } @Transactional - @RequestMapping(method = RequestMethod.POST, value = {"/dmps/createOrUpdate"}, consumes = "application/json", produces = "application/json") + @RequestMapping(method = RequestMethod.POST, value = {"/createOrUpdate"}, 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); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created")); } - @RequestMapping(method = RequestMethod.POST, value = {"/dmps/new/{id}"}, consumes = "application/json", produces = "application/json") + @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); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE)); } - @RequestMapping(method = RequestMethod.POST, value = {"/dmps/clone/{id}"}, consumes = "application/json", produces = "application/json") + @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); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.NO_MESSAGE)); } - @RequestMapping(method = RequestMethod.POST, value = {"/dmps/get"}, consumes = "application/json", produces = "application/json") + @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); @@ -100,21 +106,21 @@ public class DMPs extends BaseController { } @Transactional - @RequestMapping(method = RequestMethod.DELETE, value = {"/dmps/delete/{id}"}, consumes = "application/json", produces = "application/json") + @RequestMapping(method = RequestMethod.DELETE, value = {"/delete/{id}"}, consumes = "application/json", produces = "application/json") public @ResponseBody ResponseEntity> delete(@PathVariable UUID id, Principal principal) { DataManagementPlanManager.delete(this.getApiContext(), id); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Deleted Dataset")); } - @RequestMapping(method = RequestMethod.POST, value = {"/dmps/dynamic"}, consumes = "application/json", produces = "application/json") + @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()); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable)); } - @RequestMapping(method = RequestMethod.GET, value = {"/dmps/getXml/{id}"}) + @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()); @@ -134,5 +140,45 @@ public class DMPs extends BaseController { HttpStatus.OK); } + @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()); + InputStream resource = new FileInputStream(file); + System.out.println("Mime Type of " + file.getName() + " is " + + new MimetypesFileTypeMap().getContentType(file)); + HttpHeaders responseHeaders = new HttpHeaders(); + responseHeaders.setContentLength(file.length()); + responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM); + responseHeaders.set("Content-Disposition", "attachment;filename=" + file.getName()); + responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition"); + responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type"); + + byte[] content = org.apache.poi.util.IOUtils.toByteArray(resource); + return new ResponseEntity<>(content, + responseHeaders, + HttpStatus.OK); + } + + @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 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"); + + byte[] content = org.apache.poi.util.IOUtils.toByteArray(resource); + return new ResponseEntity<>(content, + responseHeaders, + HttpStatus.OK); + } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfileController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfileController.java index 82dd345f7..1a72ac2a5 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfileController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetProfileController.java @@ -68,7 +68,7 @@ public class DatasetProfileController extends BaseController { public ResponseEntity> clone(@PathVariable String id, @ClaimedAuthorities(claims = {ADMIN})Principal principal) { eu.eudat.data.entities.DatasetProfile profile = new DatasetProfileManager().clone(this.getApiContext(), id); eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile); - datasetprofile.setLabel(profile.getLabel()); + datasetprofile.setLabel(profile.getLabel() + " new "); return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem().payload(datasetprofile)); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetWizardController.java b/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetWizardController.java index 81a095192..1e156e2f5 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetWizardController.java +++ b/dmp-backend/web/src/main/java/eu/eudat/controllers/DatasetWizardController.java @@ -28,10 +28,7 @@ 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.io.*; import java.util.List; import java.util.UUID; @@ -82,7 +79,7 @@ public class DatasetWizardController extends BaseController { @RequestMapping(method = RequestMethod.GET, value = {"/getPDF/{id}"}) public @ResponseBody - ResponseEntity getWordDocument(@PathVariable String id) throws IllegalAccessException, IOException, InstantiationException, InterruptedException { + ResponseEntity getPDFDocument(@PathVariable String id) throws IllegalAccessException, IOException, InstantiationException, InterruptedException { File file = new DatasetManager().getWordDocument(this.environment, this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), id, this.getApiContext().getUtilitiesService().getVisibilityRuleService()); File pdffile = new DatasetManager().convertToPDF(file, environment, file.getName()); InputStream resource = new FileInputStream(pdffile); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/handlers/PrincipalArgumentResolver.java b/dmp-backend/web/src/main/java/eu/eudat/logic/handlers/PrincipalArgumentResolver.java index 35f85e4bc..44784769f 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/handlers/PrincipalArgumentResolver.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/handlers/PrincipalArgumentResolver.java @@ -44,13 +44,7 @@ public final class PrincipalArgumentResolver implements HandlerMethodArgumentRes if (principal == null) throw new UnauthorisedException("Authentication Information Missing"); if (!claimList.contains(Authorities.ANONYMOUS) && !principal.isAuthorized(claimList)) throw new UnauthorisedException("You are not Authorized For this Action"); - /*Principal principal1 = new Principal(); - principal1.setId(UUID.fromString("46366b8a-a712-4e0c-a499-1a3a0f209325")); - principal1.setToken(UUID.fromString("19031e80-6534-4aa5-b68a-78e97042c968")); - principal1.setName("Ioannis Kalyvas"); - principal1.setAvatarUrl("https://lh5.googleusercontent.com/-X65vX1QO_Ew/AAAAAAAAAAI/AAAAAAAAAAA/AAN31DU5lFIOwD_fZiYW96D410pn6v4E-Q/s96-c/photo.jpg"); - principal1.setAuthorities(new HashSet<>(Arrays.asList(Authorities.ADMIN, Authorities.USER))); - principal1.setExpiresAt(addADay(new Date()));*/ + return principal; } 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 b153291eb..54816ac81 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 @@ -17,6 +17,8 @@ import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.forms.VisibilityRuleService; import eu.eudat.logic.utilities.builders.XmlBuilder; import eu.eudat.logic.utilities.documents.helpers.FileEnvelope; +import eu.eudat.logic.utilities.documents.types.ParagraphStyle; +import eu.eudat.logic.utilities.documents.word.WordBuilder; import eu.eudat.logic.utilities.documents.xml.ExportXmlBuilder; import eu.eudat.models.HintedModelFactory; import eu.eudat.models.data.datasetwizard.DatasetWizardModel; @@ -30,16 +32,18 @@ import eu.eudat.models.data.listingmodels.DatasetListingModel; import eu.eudat.models.data.security.Principal; import eu.eudat.models.data.user.composite.PagedDatasetProfile; import eu.eudat.queryable.QueryableList; +import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.json.JSONObject; +import org.springframework.core.env.Environment; import org.springframework.http.*; import org.springframework.web.client.RestTemplate; import org.w3c.dom.Document; import org.w3c.dom.Element; -import java.io.BufferedWriter; -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; +import java.io.*; +import java.math.BigInteger; +import java.net.URL; +import java.nio.file.Paths; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; @@ -81,6 +85,51 @@ public class DataManagementPlanManager { return; } + public File getWordDocument(Environment environment, DMPDao dmpRepository, String id, VisibilityRuleService visibilityRuleService) throws InstantiationException, IllegalAccessException, IOException { + WordBuilder wordBuilder = new WordBuilder(); + DatasetWizardModel dataset = new DatasetWizardModel(); + String fileUrl = environment.getProperty("configuration.h2020template"); + InputStream is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream(); + XWPFDocument document = new XWPFDocument(is); + + eu.eudat.data.entities.DMP dmpEntity = dmpRepository.find(UUID.fromString(id)); + wordBuilder.addParagraphContent(dmpEntity.getLabel(), document, ParagraphStyle.TITLE, BigInteger.ZERO); + wordBuilder.addParagraphContent(dmpEntity.getDescription(), document, ParagraphStyle.TEXT, BigInteger.ZERO); + + wordBuilder.addParagraphContent("Organisations", document, ParagraphStyle.HEADER2, BigInteger.ZERO); + wordBuilder.addParagraphContent(dmpEntity.getOrganisations().stream().map(x -> x.getLabel()).collect(Collectors.joining(",")) + , document, ParagraphStyle.TEXT, BigInteger.ZERO); + + wordBuilder.addParagraphContent("Researchers", document, ParagraphStyle.HEADER2, BigInteger.ZERO); + wordBuilder.addParagraphContent(dmpEntity.getResearchers().stream().map(x -> x.getLabel()).collect(Collectors.joining(",")) + , document, ParagraphStyle.TEXT, BigInteger.ZERO); + + wordBuilder.addParagraphContent("Datasets", document, ParagraphStyle.TITLE, BigInteger.ZERO); + dmpEntity.getDataset().stream().forEach(datasetEntity -> { + Map properties = new HashMap<>(); + if (datasetEntity.getProperties() != null) { + JSONObject jobject = new JSONObject(datasetEntity.getProperties()); + properties = jobject.toMap(); + } + wordBuilder.addParagraphContent("Title: " + datasetEntity.getLabel(), document, ParagraphStyle.HEADER1, BigInteger.ZERO); + wordBuilder.addParagraphContent(datasetEntity.getDescription(), document, ParagraphStyle.TEXT, BigInteger.ZERO); + wordBuilder.addParagraphContent("Dataset Description", document, ParagraphStyle.HEADER1, BigInteger.ZERO); + PagedDatasetProfile pagedDatasetProfile = new DatasetManager().getPagedProfile(dataset, datasetEntity); + visibilityRuleService.setProperties(properties); + visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules()); + try { + wordBuilder.build(document, pagedDatasetProfile, visibilityRuleService); + } catch (IOException e) { + e.printStackTrace(); + } + }); + File exportFile = new File(dmpEntity.getLabel() + ".docx"); + FileOutputStream out = new FileOutputStream(exportFile); + document.write(out); + out.close(); + return exportFile; + } + public eu.eudat.models.data.dmp.DataManagementPlan getSingle(DMPDao dmpsRepository, String id, Principal principal, DynamicProjectConfiguration dynamicProjectConfiguration) throws InstantiationException, IllegalAccessException { DMP dataManagementPlanEntity = dmpsRepository.find(UUID.fromString(id)); if (dataManagementPlanEntity.getCreator().getId() != principal.getId() && dataManagementPlanEntity.getUsers().stream().filter(userInfo -> userInfo.getId() == principal.getId()).collect(Collectors.toList()).size() == 0) @@ -102,7 +151,7 @@ public class DataManagementPlanManager { datamanagementPlan.getDynamicFields().forEach(item -> { Map properties = (Map) dmpProperties.get(item.getId()); if (properties != null) - item.setValue(new Tuple(properties.get("id"), properties.get("label"))); + item.setValue(new Tuple<>(properties.get("id"), properties.get("label"))); }); return datamanagementPlan; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java index 405b12265..30b02e94c 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DatasetManager.java @@ -24,6 +24,7 @@ import eu.eudat.models.data.security.Principal; import eu.eudat.models.data.user.composite.PagedDatasetProfile; import eu.eudat.queryable.QueryableList; import org.apache.commons.io.IOUtils; +import org.apache.poi.xwpf.usermodel.XWPFDocument; import org.json.JSONObject; import org.springframework.core.env.Environment; import org.springframework.core.io.FileSystemResource; @@ -32,10 +33,9 @@ import org.springframework.http.converter.ByteArrayHttpMessageConverter; import org.springframework.util.LinkedMultiValueMap; import org.springframework.web.client.RestTemplate; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; +import java.io.*; +import java.net.URL; +import java.nio.file.Paths; import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; @@ -91,7 +91,7 @@ public class DatasetManager { else items.where((builder, root) -> root.get("id").in(new UUID[]{UUID.randomUUID()})); } - QueryableList pagedItems = PaginationManager.applyPaging(items , datasetTableRequest); + QueryableList pagedItems = PaginationManager.applyPaging(items, datasetTableRequest); DataTableData dataTable = new DataTableData<>(); CompletableFuture> itemsFuture = pagedItems. @@ -134,6 +134,9 @@ public class DatasetManager { public File getWordDocument(Environment environment, DatasetDao datatasetRepository, String id, VisibilityRuleService visibilityRuleService) throws InstantiationException, IllegalAccessException, IOException { WordBuilder wordBuilder = new WordBuilder(); DatasetWizardModel dataset = new DatasetWizardModel(); + String fileUrl = environment.getProperty("configuration.h2020template"); + InputStream is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream(); + XWPFDocument document = new XWPFDocument(is); eu.eudat.data.entities.Dataset datasetEntity = datatasetRepository.find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); Map properties = new HashMap<>(); if (datasetEntity.getProperties() != null) { @@ -143,8 +146,12 @@ public class DatasetManager { PagedDatasetProfile pagedDatasetProfile = getPagedProfile(dataset, datasetEntity); visibilityRuleService.setProperties(properties); visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules()); - File file = wordBuilder.build(environment, pagedDatasetProfile, datasetEntity.getLabel(), visibilityRuleService); - return file; + wordBuilder.build(document, pagedDatasetProfile, visibilityRuleService); + File exportFile = new File(datasetEntity.getLabel() + ".docx"); + FileOutputStream out = new FileOutputStream(exportFile); + document.write(out); + out.close(); + return exportFile; } public FileEnvelope getXmlDocument(DatasetDao datatasetRepository, String id, VisibilityRuleService visibilityRuleService) throws InstantiationException, IllegalAccessException, IOException { @@ -262,7 +269,6 @@ public class DatasetManager { } } - private static void createRegistriesIfTheyDontExist(RegistryDao registryDao, eu.eudat.data.entities.Dataset dataset) { if (dataset.getRegistries() != null && !dataset.getRegistries().isEmpty()) { for (eu.eudat.data.entities.Registry registry : dataset.getRegistries()) { diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DocumentManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DocumentManager.java new file mode 100644 index 000000000..aa55c92f5 --- /dev/null +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/DocumentManager.java @@ -0,0 +1,141 @@ +package eu.eudat.logic.managers; + +import eu.eudat.data.dao.entities.DatasetDao; +import eu.eudat.logic.services.forms.VisibilityRuleService; +import eu.eudat.logic.utilities.documents.helpers.FileEnvelope; +import eu.eudat.logic.utilities.documents.word.WordBuilder; +import eu.eudat.logic.utilities.documents.xml.ExportXmlBuilder; +import eu.eudat.models.HintedModelFactory; +import eu.eudat.models.data.datasetwizard.DatasetWizardModel; +import eu.eudat.models.data.user.composite.PagedDatasetProfile; +import org.apache.commons.io.IOUtils; +import org.apache.poi.xwpf.usermodel.XWPFDocument; +import org.json.JSONObject; +import org.springframework.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 java.io.*; +import java.net.URL; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +/** + * Created by ikalyvas on 10/16/2018. + */ +public class DocumentManager { + public File getWordDocument(Environment environment, DatasetDao datatasetRepository, String id, VisibilityRuleService visibilityRuleService) throws InstantiationException, IllegalAccessException, IOException { + WordBuilder wordBuilder = new WordBuilder(); + DatasetWizardModel dataset = new DatasetWizardModel(); + String fileUrl = environment.getProperty("configuration.h2020template"); + InputStream is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream(); + XWPFDocument document = new XWPFDocument(is); + eu.eudat.data.entities.Dataset datasetEntity = datatasetRepository.find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class)); + Map properties = new HashMap<>(); + if (datasetEntity.getProperties() != null) { + JSONObject jobject = new JSONObject(datasetEntity.getProperties()); + properties = jobject.toMap(); + } + PagedDatasetProfile pagedDatasetProfile = new DatasetManager().getPagedProfile(dataset, datasetEntity); + visibilityRuleService.setProperties(properties); + visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules()); + wordBuilder.build(document, pagedDatasetProfile, visibilityRuleService); + File exportFile = new File(dataset.getLabel() + ".docx"); + FileOutputStream out = new FileOutputStream(exportFile); + document.write(out); + out.close(); + return exportFile; + } + + public FileEnvelope getXmlDocument(eu.eudat.data.entities.Dataset datasetEntity, String id, VisibilityRuleService visibilityRuleService) throws InstantiationException, IllegalAccessException, IOException { + ExportXmlBuilder xmlBuilder = new ExportXmlBuilder(); + DatasetWizardModel dataset = new DatasetWizardModel(); + Map properties = new HashMap<>(); + if (datasetEntity.getProperties() != null) { + JSONObject jobject = new JSONObject(datasetEntity.getProperties()); + properties = jobject.toMap(); + } + PagedDatasetProfile pagedDatasetProfile = new DatasetManager().getPagedProfile(dataset, datasetEntity); + visibilityRuleService.setProperties(properties); + visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules()); + File file = xmlBuilder.build(pagedDatasetProfile, visibilityRuleService); + FileEnvelope fileEnvelope = new FileEnvelope(); + fileEnvelope.setFile(file); + fileEnvelope.setFilename(datasetEntity.getLabel()); + return fileEnvelope; + } + + public File convertToPDF(File file, Environment environment, String label) throws IOException, InterruptedException { + LinkedMultiValueMap map = new LinkedMultiValueMap<>(); + map.add("file", new FileSystemResource(file)); + HttpHeaders headers = new HttpHeaders(); + headers.setContentType(MediaType.MULTIPART_FORM_DATA); + headers.add("Content-disposition", "attachment; filename=" + label + ".docx"); + + headers.add("Content-type", "application/vnd.openxmlformats-officedocument.wordprocessingml.document"); + + HttpEntity> requestEntity = new HttpEntity>( + 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 entity = new HttpEntity(headers2); + + ResponseEntity 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; + } +} diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ProjectManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ProjectManager.java index b70928c79..08f15cbf1 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ProjectManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/ProjectManager.java @@ -27,6 +27,7 @@ import eu.eudat.logic.services.helpers.FileStorageService; import java.io.IOException; import java.text.ParseException; +import java.util.Comparator; import java.util.List; import java.util.Map; import java.util.UUID; @@ -91,7 +92,7 @@ public class ProjectManager { projects.add(project); } - + projects.sort(Comparator.comparing(x-> x.getLabel())); return projects; } diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/UserManager.java b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/UserManager.java index 27c0c06be..cc237a29d 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/managers/UserManager.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/managers/UserManager.java @@ -10,6 +10,7 @@ import eu.eudat.logic.builders.model.models.DataTableDataBuilder; import eu.eudat.logic.services.ApiContext; import eu.eudat.logic.services.operations.AuthenticationServiceImpl; import eu.eudat.logic.utilities.builders.XmlBuilder; +import eu.eudat.models.HintedModelFactory; import eu.eudat.models.data.dmp.DataManagementPlan; import eu.eudat.models.data.helpers.common.DataTableData; import eu.eudat.models.data.login.Credentials; @@ -41,7 +42,7 @@ public class UserManager { } public static DataTableData getPaged(ApiContext apiContext, UserInfoTableRequestItem userInfoTableRequestItem) throws Exception { - QueryableList users = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().getWithCriteria(userInfoTableRequestItem.getCriteria()); + QueryableList users = apiContext.getOperationsContext().getDatabaseRepository().getUserInfoDao().getWithCriteria(userInfoTableRequestItem.getCriteria()).withHint(HintedModelFactory.getHint(UserListingModel.class)); QueryableList pagedUsers = PaginationManager.applyPaging(users, userInfoTableRequestItem); List modelUsers = pagedUsers.select(item -> new UserListingModel().fromDataModel(item)); diff --git a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java index d61b3bb1d..9791c4904 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java +++ b/dmp-backend/web/src/main/java/eu/eudat/logic/utilities/documents/word/WordBuilder.java @@ -1,9 +1,13 @@ package eu.eudat.logic.utilities.documents.word; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.ObjectMapper; import eu.eudat.logic.services.forms.VisibilityRuleService; import eu.eudat.logic.utilities.documents.types.ParagraphStyle; import eu.eudat.logic.utilities.documents.types.TextStyle; import eu.eudat.logic.utilities.interfaces.ApplierWithValue; +import eu.eudat.models.data.components.commons.datafield.CheckBoxData; +import eu.eudat.models.data.components.commons.datafield.ComboBoxData; import eu.eudat.models.data.user.components.datasetprofile.Field; import eu.eudat.models.data.user.components.datasetprofile.FieldSet; import eu.eudat.models.data.user.components.datasetprofile.Section; @@ -14,16 +18,9 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber; import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLvl; import org.openxmlformats.schemas.wordprocessingml.x2006.main.STNumberFormat; -import org.springframework.core.env.Environment; -import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; -import java.io.InputStream; import java.math.BigInteger; -import java.net.URL; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -40,6 +37,7 @@ public class WordBuilder { public WordBuilder() { this.cTAbstractNum = CTAbstractNum.Factory.newInstance(); this.cTAbstractNum.setAbstractNumId(BigInteger.valueOf(1)); + this.buildOptions(); } private void buildOptions() { @@ -52,6 +50,8 @@ public class WordBuilder { }); this.options.put(ParagraphStyle.TITLE, (mainDocumentPart, item) -> { XWPFParagraph paragraph = mainDocumentPart.createParagraph(); + paragraph.setStyle("Title"); + paragraph.setAlignment(ParagraphAlignment.CENTER); XWPFRun run = paragraph.createRun(); run.setText(item); run.setBold(true); @@ -60,29 +60,29 @@ public class WordBuilder { }); this.options.put(ParagraphStyle.HEADER1, (mainDocumentPart, item) -> { XWPFParagraph paragraph = mainDocumentPart.createParagraph(); + paragraph.setStyle("Heading1"); XWPFRun run = paragraph.createRun(); run.setText(item); run.setBold(true); run.setFontSize(12); - run.setUnderline(UnderlinePatterns.SINGLE); return paragraph; }); this.options.put(ParagraphStyle.HEADER2, (mainDocumentPart, item) -> { XWPFParagraph paragraph = mainDocumentPart.createParagraph(); + paragraph.setStyle("Heading2"); XWPFRun run = paragraph.createRun(); run.setText(item); run.setBold(true); run.setFontSize(12); - run.setUnderline(UnderlinePatterns.SINGLE); return paragraph; }); this.options.put(ParagraphStyle.HEADER3, (mainDocumentPart, item) -> { XWPFParagraph paragraph = mainDocumentPart.createParagraph(); + paragraph.setStyle("Heading3"); XWPFRun run = paragraph.createRun(); run.setText(item); run.setBold(true); run.setFontSize(11); - run.setUnderline(UnderlinePatterns.SINGLE); return paragraph; }); this.options.put(ParagraphStyle.FOOTER, (mainDocumentPart, item) -> { @@ -91,41 +91,37 @@ public class WordBuilder { run.setText(item); return paragraph; }); + this.options.put(ParagraphStyle.COMMENT, (mainDocumentPart, item) -> { + XWPFParagraph paragraph = mainDocumentPart.createParagraph(); + XWPFRun run = paragraph.createRun(); + run.setText(item); + run.setItalic(true); + return paragraph; + }); } - public File build(Environment environment, PagedDatasetProfile pagedDatasetProfile, String label, VisibilityRuleService visibilityRuleService) throws IOException { - String fileUrl = environment.getProperty("configuration.h2020template"); - - InputStream is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream(); - XWPFDocument document = new XWPFDocument(is); - this.buildOptions(); + public XWPFDocument build(XWPFDocument document, PagedDatasetProfile pagedDatasetProfile, VisibilityRuleService visibilityRuleService) throws IOException { 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, visibilityRuleService); - File exportFile = new File(label + ".docx"); - FileOutputStream out = new FileOutputStream(exportFile); - document.write(out); - out.close(); - return exportFile; + return document; } public void createPages(List 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, visibilityRuleService); + createSections(item.getSections(), mainDocumentPart, ParagraphStyle.HEADER1, 0, createListing, visibilityRuleService); }); } public void createSections(List
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 (visibilityRuleService.isElementVisible(section.getId())) { if (!createListing) { - XWPFParagraph paragraph = addParagraphContent(section.getTitle(), mainDocumentPart, style, listing); + XWPFParagraph paragraph = addParagraphContent(section.getNumbering() + " " + section.getTitle(), mainDocumentPart, style, numId); CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl(); number.setVal(BigInteger.valueOf(indent)); } @@ -139,13 +135,17 @@ public class WordBuilder { if (createListing) this.addListing(mainDocumentPart, indent, true, true); compositeFields.forEach(compositeField -> { if (visibilityRuleService.isElementVisible(compositeField.getId())) { - if (compositeField.getTitle() != null && !compositeField.getTitle().isEmpty() && !createListing) { - XWPFParagraph paragraph = addParagraphContent(compositeField.getTitle(), mainDocumentPart, ParagraphStyle.HEADER3, numId); + XWPFParagraph paragraph = addParagraphContent(compositeField.getNumbering() + " " + 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); + if (compositeField.getHasCommentField() && compositeField.getCommentFieldValue() != null && !compositeField.getCommentFieldValue().isEmpty() && !createListing) { + XWPFParagraph paragraph = addParagraphContent("Comment: " + compositeField.getCommentFieldValue(), mainDocumentPart, ParagraphStyle.COMMENT, numId); + CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl(); + number.setVal(BigInteger.valueOf(indent)); + } } }); } @@ -155,18 +155,23 @@ public class WordBuilder { fields.forEach(field -> { 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)); + try { + XWPFParagraph paragraph = addParagraphContent(this.formatter(field), mainDocumentPart, ParagraphStyle.TEXT, numId); + CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl(); + number.setVal(BigInteger.valueOf(indent)); + } catch (IOException e) { + e.printStackTrace(); + } } } }); } - public XWPFParagraph addParagraphContent(String text, XWPFDocument mainDocumentPart, ParagraphStyle style, BigInteger numId) { XWPFParagraph paragraph = this.options.get(style).apply(mainDocumentPart, text); - if (numId != null) paragraph.setNumID(numId); + if (numId != null) { + paragraph.setNumID(numId); + } return paragraph; } @@ -176,8 +181,6 @@ public class WordBuilder { } public void addListing(XWPFDocument document, int indent, Boolean question, Boolean hasIndication) { - - //this.cTAbstractNum.setAbstractNumId(BigInteger.valueOf(indent)); CTLvl cTLvl = this.cTAbstractNum.addNewLvl(); String textLevel = ""; @@ -186,28 +189,50 @@ public class WordBuilder { } if (question) { 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) { - XWPFAbstractNum abstractNum = new XWPFAbstractNum(cTAbstractNum); - XWPFNumbering numbering = document.createNumbering(); - BigInteger abstractNumID = numbering.addAbstractNum(abstractNum); - this.numId = numbering.addNum(abstractNumID); - }*/ + public String formatter(Field field) throws IOException { + switch (field.getViewStyle().getRenderStyle()) { + case "combobox": { + String comboboxType = ((ComboBoxData) field.getData()).getType(); + if (comboboxType.equals("autocomplete")) { + ObjectMapper mapper = new ObjectMapper(); + if (field.getValue() == null) return null; + Map map = mapper.readValue(field.getValue(), new TypeReference>() { + }); + return map.get("label"); + } else if (comboboxType.equals("wordlist")) { + ObjectMapper mapper = new ObjectMapper(); + if (field.getValue() == null) return null; + Map map = mapper.readValue(field.getValue(), new TypeReference>() { + }); + return map.get("label"); + } + } + case "booleanDecision": + if (field.getValue() != null && field.getValue().equals("true")) return "Yes"; + else return "No"; + case "radiobox": + return field.getValue(); + case "checkBox": + CheckBoxData data = (CheckBoxData) field.getData(); + if (field.getValue() == null || field.getValue().equals("false")) return null; + return data.getLabel(); + case "freetext": + return field.getValue(); + case "textarea": + return field.getValue(); + } + return null; } } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/admin/components/datasetprofile/FieldSet.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/admin/components/datasetprofile/FieldSet.java index e7188125f..e24691dd8 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/admin/components/datasetprofile/FieldSet.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/admin/components/datasetprofile/FieldSet.java @@ -88,7 +88,6 @@ public class FieldSet implements Comparable, ViewStyleDefinition viewStylefields = new ModelBuilder().toViewStyleDefinition(this.fields, eu.eudat.models.data.entities.xmlmodels.datasetprofiledefinition.Field.class); item.setFields(viewStylefields); item.setId(this.id); diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/entities/xmlmodels/datasetprofiledefinition/Field.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/entities/xmlmodels/datasetprofiledefinition/Field.java index 7e7e9aa55..ce530fbc9 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/entities/xmlmodels/datasetprofiledefinition/Field.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/entities/xmlmodels/datasetprofiledefinition/Field.java @@ -18,6 +18,7 @@ import java.util.List; public class Field implements DatabaseViewStyleDefinition, XmlSerializable { private String id; private int ordinal; + private String numbering; private ViewStyle viewStyle; private DefaultValue defaultValue; private Visibility visible; @@ -80,6 +81,14 @@ public class Field implements DatabaseViewStyleDefinition, XmlSerializable fields; + private String numbering; private String title; private String description; private String extendedDescription; @@ -94,6 +95,14 @@ public class FieldSet implements DatabaseViewStyleDefinition, XmlSerializable { Element sections = doc.createElement("sections"); Element pages = doc.createElement("pages"); for (Section section : this.sections) { + section.setNumbering("" + (this.sections.indexOf(section) + 1)); sections.appendChild(section.toXml(doc)); } diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java index 2624c2e31..6c7e2c636 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Field.java @@ -20,6 +20,7 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin private String value; private ViewStyle viewStyle; private String datatype; + private String numbering; private int page; private DefaultValue defaultValue; private Multiplicity multiplicity; @@ -128,6 +129,13 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin this.validations = eu.eudat.models.data.admin.components.datasetprofile.Field.ValidationType.fromIntegers(validations); } + public String getNumbering() { + return numbering; + } + + public void setNumbering(String numbering) { + this.numbering = numbering; + } public Field cloneForMultiplicity(String key, Map properties) { Field newField = new Field(); @@ -160,6 +168,7 @@ public class Field implements Comparable, PropertiesModelBuilder, ViewStyleDefin this.id = item.getId(); this.ordinal = item.getOrdinal(); this.viewStyle = item.getViewStyle(); + this.numbering = item.getNumbering(); this.data = item.getData(); this.defaultValue = item.getDefaultValue(); this.visible = item.getVisible(); diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/FieldSet.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/FieldSet.java index 32e44adf4..d3a60acba 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/FieldSet.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/FieldSet.java @@ -13,6 +13,7 @@ public class FieldSet implements Comparable, PropertiesModelBuilder, ViewStyleDe private String id; private Integer ordinal; private String title; + private String numbering; private String description; private String extendedDescription; private Multiplicity multiplicity; @@ -83,6 +84,14 @@ public class FieldSet implements Comparable, PropertiesModelBuilder, ViewStyleDe return multiplicityItems; } + public String getNumbering() { + return numbering; + } + + public void setNumbering(String numbering) { + this.numbering = numbering; + } + public void setMultiplicityItems(List
multiplicityItems) { this.multiplicityItems = multiplicityItems; } @@ -126,6 +135,7 @@ public class FieldSet implements Comparable, PropertiesModelBuilder, ViewStyleDe this.ordinal = item.getOrdinal(); this.title = item.getTitle(); this.description = item.getDescription(); + this.numbering = item.getNumbering(); this.extendedDescription = item.getExtendedDescription(); this.hasCommentField = item.getHasCommentField(); this.multiplicity = item.getMultiplicity(); diff --git a/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Section.java b/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Section.java index a1559be83..72d61ac75 100644 --- a/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Section.java +++ b/dmp-backend/web/src/main/java/eu/eudat/models/data/user/components/datasetprofile/Section.java @@ -13,6 +13,7 @@ public class Section implements Comparable, ViewStyleDefinition sections; private List
compositeFields; private Boolean defaultVisibility; + private String numbering; private String page; private Integer ordinal; private String id; @@ -85,6 +86,14 @@ public class Section implements Comparable, ViewStyleDefinition implements Validator { @Override public void validate(Object target, Errors errors) { List validatorResults = new LinkedList<>(); - this.fluentValidatorBuilders.forEach(x-> validatorResults.addAll(x.validate(target))); - validatorResults.forEach(x-> errors.rejectValue(x.getField(),x.getError())); + //this.fluentValidatorBuilders.forEach(x-> validatorResults.addAll(x.validate(target))); + //validatorResults.forEach(x-> errors.rejectValue(x.getField(),x.getError())); } } diff --git a/dmp-frontend/src/app/app-routing.module.ts b/dmp-frontend/src/app/app-routing.module.ts index 1b615e573..c7e7d0e6f 100644 --- a/dmp-frontend/src/app/app-routing.module.ts +++ b/dmp-frontend/src/app/app-routing.module.ts @@ -79,7 +79,10 @@ const appRoutes: Routes = [ }, { path: 'users', - loadChildren: './users/users.module#UsersModule' + loadChildren: './users/users.module#UsersModule', + data: { + breadcrumb: true + }, }, { path: 'welcome', diff --git a/dmp-frontend/src/app/dataset-profile-form/form/form.component.html b/dmp-frontend/src/app/dataset-profile-form/form/form.component.html index 671172935..706477395 100644 --- a/dmp-frontend/src/app/dataset-profile-form/form/form.component.html +++ b/dmp-frontend/src/app/dataset-profile-form/form/form.component.html @@ -1,60 +1,72 @@ -
+
- + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + -
- - - {{i + - 1}}.{{form.get('pages').at(i).get('title').value}} -
- + {{'DATASET-PROFILE.PAGES-DESCRIPTION' | translate}} +
+
+ + + {{i + + 1}}.{{form.get('pages').at(i).get('title').value}} +
+ +
+
+
+
+ +
- -
-
- -
-
-
-
-
- + +
+
+ +
+ {{'DATASET-PROFILE.FORM-DESCRIPTION' | translate}}
- - - {{i + 1}}. - {{form.get('sections').get(''+i).get('title').value}} -
- +
+ + + {{i + 1}}. + {{form.get('sections').get(''+i).get('title').value}} +
+ +
+
+
+
+ +
- -
-
- -
-
-
+ +
+
+ +
-
- + + + {{'DATASET-PROFILE.PREVIEW' | translate}} +
+
- - +
diff --git a/dmp-frontend/src/app/dataset-profile-form/form/form.component.ts b/dmp-frontend/src/app/dataset-profile-form/form/form.component.ts index 80b9a9286..c45a1fa11 100644 --- a/dmp-frontend/src/app/dataset-profile-form/form/form.component.ts +++ b/dmp-frontend/src/app/dataset-profile-form/form/form.component.ts @@ -2,14 +2,17 @@ import { DatasetProfileService } from '../../services/dataset-profile.service'; import { DatasetProfileModelAdmin } from '../../models/datasetProfileAdmin/DatasetProfileModelAdmin'; import { Page } from '../../models/datasetProfileAdmin/Page'; -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core'; import { FormGroup, FormControl } from '@angular/forms'; import { FormArray } from '@angular/forms'; import { Router, ActivatedRoute } from '@angular/router'; import { DatasetProfileAdmin } from '../../services/datasetProfileAdmin/datasetProfileAfmin.service'; import { Section } from '../../models/datasetProfileAdmin/Section'; -import { MatDialog } from '@angular/material'; +import { MatDialog, MatHorizontalStepper, MatStepper } from '@angular/material'; import { DatasetProfilePreviewerComponent } from '../previewer/dataset-profile-previewer.component'; +import { Observable } from 'rxjs'; +import { DatasetWizardModel } from '../../models/datasets/DatasetWizardModel'; +import { DatasetProfileDefinitionModel } from '../../models/DatasetProfileDefinitionModel'; @Component({ selector: 'app-form-component', @@ -18,16 +21,20 @@ import { DatasetProfilePreviewerComponent } from '../previewer/dataset-profile-p styleUrls: ['./form.component.scss'] }) -export class FormComponent implements OnInit { +export class FormComponent implements OnInit, AfterViewInit { + dataModel: DatasetProfileModelAdmin; form: FormGroup; + previewerFormGroup: FormGroup; private profileID: string; private cloneId: string; - + dataWizardModel: DatasetWizardModel; + @ViewChild('stepper') stepper: MatHorizontalStepper; constructor( public datasetprofileAdmin: DatasetProfileAdmin, private datasetProfileService: DatasetProfileService, + private datasetProfileAdminService: DatasetProfileAdmin, private route: ActivatedRoute, private router: Router, public dialog: MatDialog, @@ -36,19 +43,40 @@ export class FormComponent implements OnInit { this.cloneId = route.snapshot.params['cloneid']; } + ngAfterViewInit(): void { + console.log(this.stepper); + } + ngOnInit() { this.dataModel = JsonSerializer.fromJSONObject(new DatasetProfileModelAdmin(), DatasetProfileModelAdmin); - this.form = this.dataModel.buildForm(); if (this.profileID) { this.datasetProfileService.getDatasetProfileById(this.profileID).subscribe((data) => { this.dataModel = JsonSerializer.fromJSONObject(data, DatasetProfileModelAdmin); this.form = this.dataModel.buildForm(); + this.form.valueChanges.subscribe(change => { + this.datasetProfileAdminService.preview(this.dataModel).subscribe(dataset => { + const datasetModel = new DatasetWizardModel(); + datasetModel.datasetProfileDefinition = JsonSerializer.fromJSONObject(dataset, DatasetProfileDefinitionModel); + this.dataWizardModel = datasetModel; + this.previewerFormGroup = this.dataWizardModel.buildForm().get('datasetProfileDefinition'); + }); + }); + this.form.updateValueAndValidity(); }); } else if (this.cloneId) { this.datasetprofileAdmin.clone(this.cloneId).subscribe((data) => { this.dataModel = JsonSerializer.fromJSONObject(data, DatasetProfileModelAdmin); this.form = this.dataModel.buildForm(); + this.form.valueChanges.subscribe(change => { + this.datasetProfileAdminService.preview(this.dataModel).subscribe(dataset => { + const datasetModel = new DatasetWizardModel(); + datasetModel.datasetProfileDefinition = JsonSerializer.fromJSONObject(dataset, DatasetProfileDefinitionModel); + this.dataWizardModel = datasetModel; + this.previewerFormGroup = this.dataWizardModel.buildForm().get('datasetProfileDefinition'); + }); + }); + this.form.updateValueAndValidity(); }); } else { this.addSection(); @@ -97,23 +125,16 @@ export class FormComponent implements OnInit { if (this.profileID) { this.updateForm(this.profileID, data).subscribe(() => { - this.router.navigate(['/datasetsProfiles']); + this.router.navigate(['/dataset-profile']); }); } else { this.createForm(data).subscribe(() => { - this.router.navigate(['/datasetsProfiles']); + this.router.navigate(['/dataset-profile']); }); } } - preview() { - const dialogRef = this.dialog.open(DatasetProfilePreviewerComponent, { - height: '355px', - width: '700px', - data: { - model: this.dataModel - } - }); + isStepActive(step: number) { + return this.stepper && this.stepper.selectedIndex === step; } - } diff --git a/dmp-frontend/src/app/datasets/dataset-public/dataset-public-listing.component.ts b/dmp-frontend/src/app/datasets/dataset-public/dataset-public-listing.component.ts index bf2353758..adc5be160 100644 --- a/dmp-frontend/src/app/datasets/dataset-public/dataset-public-listing.component.ts +++ b/dmp-frontend/src/app/datasets/dataset-public/dataset-public-listing.component.ts @@ -12,6 +12,7 @@ import { DataSource } from '@angular/cdk/table'; import { DatasetListingModel } from '../../models/datasets/DatasetListingModel'; import { DataTableRequest } from '../../models/data-table/DataTableRequest'; import { FacetSearchCriteriaModel } from '../../models/facet-search/FacetSearchCriteriaModel'; +import { IBreadCrumbComponent } from '../../shared/components/breadcrumb/definition/IBreadCrumbComponent'; @Component({ @@ -21,7 +22,6 @@ import { FacetSearchCriteriaModel } from '../../models/facet-search/FacetSearchC }) export class DatasetPublicListingComponent implements OnInit { - @ViewChild(MatPaginator) _paginator: MatPaginator; @ViewChild(MatSort) sort: MatSort; criteria: FacetSearchCriteriaModel; @@ -44,6 +44,7 @@ export class DatasetPublicListingComponent implements OnInit { } ngOnInit() { + this.route.params.subscribe(async (params: Params) => { this.dmpId = params['dmpId']; this.refresh(); diff --git a/dmp-frontend/src/app/datasets/dataset-wizard/dataset-wizard.component.html b/dmp-frontend/src/app/datasets/dataset-wizard/dataset-wizard.component.html index 3052a0cb5..5f9130052 100644 --- a/dmp-frontend/src/app/datasets/dataset-wizard/dataset-wizard.component.html +++ b/dmp-frontend/src/app/datasets/dataset-wizard/dataset-wizard.component.html @@ -15,228 +15,243 @@
- - + +
- -
-
- - - {{'DATASET-WIZARD.FIRST-STEP.TITLE' | translate}} - - - - {{profile.label}} - - - {{baseErrorModel['Criteria.status']}} - - - -
+
+
+ + + {{'DATASET-WIZARD.FIRST-STEP.TITLE' | translate}} + + + + {{profile.label}} + + + {{baseErrorModel['Criteria.status']}} + + + +
+
-
- {{'DATASET-WIZARD.SECOND-STEP.TITLE' | translate}} +
+ + {{'DATASET-WIZARD.SECOND-STEP.TITLE' | translate}} - - - - {{'DATASET-EDITOR.FIELDS.DATAREPOSITORIES' | translate}} - - - - - + + + + {{'DATASET-EDITOR.FIELDS.DATAREPOSITORIES' | translate}} + + + + + - -
-

- {{i+1}}) {{suggestion.get('label').value}} -

-
-
- - - -
-
- -
-
-
- - - - {{'DATASET-EDITOR.FIELDS.EXTERNAL-DATASETS' | translate}} - - - - - + +
+

+ {{i+1}}) {{suggestion.get('label').value}} +

+
+
+ + + +
+
+ +
+
+
+ + + + {{'DATASET-EDITOR.FIELDS.EXTERNAL-DATASETS' | translate}} + + + + + - -
-

- {{i+1}}) {{suggestion.get('label').value}} -

-
-
- - - -
+ +
+

+ {{i+1}}) {{suggestion.get('label').value}} +

+
+
+ + + +
-
- - - {{'TYPES.EXTERNAL-DATASET-TYPE.SOURCE' | translate}} - {{'TYPES.EXTERNAL-DATASET-TYPE.OUTPUT' | translate}} - - -
-
- -
-
-
+
+ + + {{'TYPES.EXTERNAL-DATASET-TYPE.SOURCE' | translate}} + {{'TYPES.EXTERNAL-DATASET-TYPE.OUTPUT' | translate}} + + +
+
+ +
+ +
- - - - {{'DATASET-EDITOR.FIELDS.REGISTRIES' | translate}} - - - - - + + + + {{'DATASET-EDITOR.FIELDS.REGISTRIES' | translate}} + + + + + - -
-

- {{i+1}}) {{suggestion.get('label').value}} -

-
-
- -
-
-
+ +
+

+ {{i+1}}) {{suggestion.get('label').value}} +

+
+
+ +
+
+
- - - - {{'DATASET-EDITOR.FIELDS.SERVICES' | translate}} - - - - - + + + + {{'DATASET-EDITOR.FIELDS.SERVICES' | translate}} + + + + + - -
-

- {{i+1}}) {{suggestion.get('label').value}} -

-
-
- -
-
-
+ +
+

+ {{i+1}}) {{suggestion.get('label').value}} +

+
+
+ +
+
+
- - - - {{'DATASET-EDITOR.FIELDS.TAGS' | translate}} - - - - + + + + {{'DATASET-EDITOR.FIELDS.TAGS' | translate}} + + + + - -
-

- {{i+1}}) {{suggestion.get('name').value}} -

-
-
- -
-
-
+ +
+

+ {{i+1}}) {{suggestion.get('name').value}} +

+
+
+ +
+
+
- - + + +
- {{'DATASET-WIZARD.THIRD-STEP.TITLE' | translate}} - - diff --git a/dmp-frontend/src/app/dmps/editor/dmp-editor.component.html b/dmp-frontend/src/app/dmps/editor/dmp-editor.component.html index e2ce888d3..0750f5c9f 100644 --- a/dmp-frontend/src/app/dmps/editor/dmp-editor.component.html +++ b/dmp-frontend/src/app/dmps/editor/dmp-editor.component.html @@ -34,6 +34,12 @@ + +
- diff --git a/dmp-frontend/src/app/dmps/editor/dmp-editor.component.ts b/dmp-frontend/src/app/dmps/editor/dmp-editor.component.ts index d7878d7d1..aa1255e4b 100644 --- a/dmp-frontend/src/app/dmps/editor/dmp-editor.component.ts +++ b/dmp-frontend/src/app/dmps/editor/dmp-editor.component.ts @@ -343,6 +343,24 @@ export class DataManagementPlanEditorComponent implements AfterViewInit, IBreadC }); } + downloadDocx(id: string) { + this.dataManagementPlanService.downloadDocx(id).subscribe(response => { + const blob = new Blob([response.body], { type: 'application/octet-stream' }); + const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); + + FileSaver.saveAs(blob, filename); + }); + } + + downloadPDF(id: string) { + this.dataManagementPlanService.downloadPDF(id).subscribe(response => { + const blob = new Blob([response.body], { type: 'application/octet-stream' }); + const filename = this.getFilenameFromContentDispositionHeader(response.headers.get('Content-Disposition')); + + FileSaver.saveAs(blob, filename); + }); + } + getFilenameFromContentDispositionHeader(header: string): string { const regex: RegExp = new RegExp(/filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/g); diff --git a/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-checkbox/dynamic-field-checkbox.html b/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-checkbox/dynamic-field-checkbox.html index e4aaf4246..df5d98780 100644 --- a/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-checkbox/dynamic-field-checkbox.html +++ b/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-checkbox/dynamic-field-checkbox.html @@ -3,4 +3,4 @@
- \ No newline at end of file + diff --git a/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-checkbox/dynamic-field-checkbox.ts b/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-checkbox/dynamic-field-checkbox.ts index 1cfb626d6..da219fee6 100644 --- a/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-checkbox/dynamic-field-checkbox.ts +++ b/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-checkbox/dynamic-field-checkbox.ts @@ -10,8 +10,12 @@ import { Component, Input, ViewEncapsulation, OnInit } from '@angular/core'; ], encapsulation: ViewEncapsulation.None }) -export class DynamicFieldCheckBoxComponent { +export class DynamicFieldCheckBoxComponent implements OnInit { + @Input() field: Field; @Input() form: FormGroup; + ngOnInit(): void { + if (this.form.get('value').value === null) { this.form.get('value').patchValue(false); } + } } diff --git a/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-dropdown/dynamic-field-dropdown.css b/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-dropdown/dynamic-field-dropdown.css index bf67b66d0..e69de29bb 100644 --- a/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-dropdown/dynamic-field-dropdown.css +++ b/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-dropdown/dynamic-field-dropdown.css @@ -1 +0,0 @@ -@CHARSET "UTF-8"; \ No newline at end of file diff --git a/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-dropdown/dynamic-field-dropdown.html b/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-dropdown/dynamic-field-dropdown.html index a0ba2b0fd..77a558544 100644 --- a/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-dropdown/dynamic-field-dropdown.html +++ b/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-dropdown/dynamic-field-dropdown.html @@ -1,9 +1,9 @@
- - - {{opt.label}} - - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - + + + {{opt.label}} + + {{'GENERAL.VALIDATION.REQUIRED' | translate}} + -
\ No newline at end of file +
diff --git a/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-dropdown/dynamic-field-dropdown.ts b/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-dropdown/dynamic-field-dropdown.ts index dcca8a330..55e8a8d44 100644 --- a/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-dropdown/dynamic-field-dropdown.ts +++ b/dmp-frontend/src/app/form/dynamic-fields/dynamic-field-dropdown/dynamic-field-dropdown.ts @@ -17,4 +17,13 @@ export class DynamicFieldDropdownComponent implements OnInit { ngOnInit() { } + + assign(item: any) { + if (!item) { return null; } + return this.transform(item); + } + + transform(item: any) { + if (typeof item === 'string') { return JSON.parse(item); } else { return JSON.stringify(item); } + } } diff --git a/dmp-frontend/src/app/form/dynamic-fields/dynamic-form-field.component.html b/dmp-frontend/src/app/form/dynamic-fields/dynamic-form-field.component.html index 29044d937..ddab9d76d 100644 --- a/dmp-frontend/src/app/form/dynamic-fields/dynamic-form-field.component.html +++ b/dmp-frontend/src/app/form/dynamic-fields/dynamic-form-field.component.html @@ -1,67 +1,73 @@
- + -
-
{{field.description}}
-
- {{field.extendedDescription}} -
+
+
{{field.description}}
+
+ {{field.extendedDescription}} +
-
- - - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - -
+
+ + + {{'GENERAL.VALIDATION.REQUIRED' + | translate}} + +
-
- -
- -
-
- -
+
+ +
+ +
+
+ +
+
+ +
+ +
+ +
+ + - - {{'GENERAL.VALIDATION.REQUIRED' | translate}} - + + {{'GENERAL.VALIDATION.REQUIRED' + | translate}} + -
+
-
- -
+
+ +
-
- -
+
+ +
-
+
- -
+