Implemented Backend Api's For Downloading DMP as Docx (Ticket #37 - Export DMP as a whole)
This commit is contained in:
parent
c7115f752a
commit
8955172fec
|
@ -44,19 +44,15 @@ public class Admin extends BaseController {
|
||||||
@Transactional
|
@Transactional
|
||||||
@RequestMapping(method = RequestMethod.POST, value = {"/admin/addDmp/{id}"}, consumes = "application/json", produces = "application/json")
|
@RequestMapping(method = RequestMethod.POST, value = {"/admin/addDmp/{id}"}, consumes = "application/json", produces = "application/json")
|
||||||
public ResponseEntity<ResponseItem<UUID>> updateDmp(@PathVariable String id, @RequestBody DatasetProfile profile, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) {
|
public ResponseEntity<ResponseItem<UUID>> 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 modelDefinition = AdminManager.generateViewStyleDefinition(profile, getApiContext());
|
||||||
|
|
||||||
eu.eudat.data.entities.DatasetProfile datasetprofile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
|
eu.eudat.data.entities.DatasetProfile datasetprofile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
|
||||||
datasetprofile.setDefinition(modelDefinition.getDefinition());
|
datasetprofile.setDefinition(modelDefinition.getDefinition());
|
||||||
this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(datasetprofile);
|
this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().createOrUpdate(datasetprofile);
|
||||||
|
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UUID>().status(ApiMessageCode.NO_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<UUID>().status(ApiMessageCode.NO_MESSAGE));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = {"/admin/get/{id}"}, produces = "application/json")
|
@RequestMapping(method = RequestMethod.GET, value = {"/admin/get/{id}"}, produces = "application/json")
|
||||||
public ResponseEntity<ResponseItem<DatasetProfile>> get(@PathVariable String id, @ClaimedAuthorities(claims = {ADMIN}) Principal principal) {
|
public ResponseEntity<ResponseItem<DatasetProfile>> 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.data.entities.DatasetProfile profile = this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetProfileDao().find(UUID.fromString(id));
|
||||||
eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile);
|
eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile);
|
||||||
datasetprofile.setLabel(profile.getLabel());
|
datasetprofile.setLabel(profile.getLabel());
|
||||||
|
|
|
@ -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.item.dmp.DataManagementPlanCriteriaRequest;
|
||||||
import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest;
|
import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest;
|
||||||
import eu.eudat.logic.managers.DataManagementPlanManager;
|
import eu.eudat.logic.managers.DataManagementPlanManager;
|
||||||
|
import eu.eudat.logic.managers.DatasetManager;
|
||||||
import eu.eudat.logic.services.ApiContext;
|
import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
|
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
|
||||||
import eu.eudat.models.data.dmp.DataManagementPlan;
|
import eu.eudat.models.data.dmp.DataManagementPlan;
|
||||||
|
@ -19,6 +20,7 @@ import eu.eudat.models.data.security.Principal;
|
||||||
import eu.eudat.types.ApiMessageCode;
|
import eu.eudat.types.ApiMessageCode;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.http.HttpHeaders;
|
import org.springframework.http.HttpHeaders;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.MediaType;
|
import org.springframework.http.MediaType;
|
||||||
|
@ -28,6 +30,7 @@ import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.activation.MimetypesFileTypeMap;
|
import javax.activation.MimetypesFileTypeMap;
|
||||||
import javax.validation.Valid;
|
import javax.validation.Valid;
|
||||||
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -37,33 +40,36 @@ import java.util.UUID;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@CrossOrigin
|
@CrossOrigin
|
||||||
@RequestMapping(value = {"/api"})
|
@RequestMapping(value = {"/api/dmps/"})
|
||||||
public class DMPs extends BaseController {
|
public class DMPs extends BaseController {
|
||||||
|
|
||||||
private DynamicProjectConfiguration dynamicProjectConfiguration;
|
private DynamicProjectConfiguration dynamicProjectConfiguration;
|
||||||
|
private Environment environment;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DMPs(ApiContext apiContext, DynamicProjectConfiguration dynamicProjectConfiguration) {
|
public DMPs(ApiContext apiContext, DynamicProjectConfiguration dynamicProjectConfiguration, Environment environment) {
|
||||||
super(apiContext);
|
super(apiContext);
|
||||||
this.dynamicProjectConfiguration = dynamicProjectConfiguration;
|
this.dynamicProjectConfiguration = dynamicProjectConfiguration;
|
||||||
|
this.environment = environment;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@Transactional
|
||||||
@RequestMapping(method = RequestMethod.GET, value = {"/dmps/{id}/unlock"}, produces = "application/json")
|
@RequestMapping(method = RequestMethod.GET, value = {"{id}/unlock"}, produces = "application/json")
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<DMP>> unlock(@PathVariable(value = "id") UUID id, Principal principal) throws Exception {
|
ResponseEntity<ResponseItem<DMP>> unlock(@PathVariable(value = "id") UUID id, Principal principal) throws Exception {
|
||||||
new DataManagementPlanManager().unlock(this.getApiContext(), id);
|
new DataManagementPlanManager().unlock(this.getApiContext(), id);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Unlocked"));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().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
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanListingModel>>> getPaged(@Valid @RequestBody DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal) throws Exception {
|
ResponseEntity<ResponseItem<DataTableData<DataManagementPlanListingModel>>> getPaged(@Valid @RequestBody DataManagementPlanTableRequest dataManagementPlanTableRequest, Principal principal) throws Exception {
|
||||||
DataTableData<DataManagementPlanListingModel> dataTable = new DataManagementPlanManager().getPaged(this.getApiContext(), dataManagementPlanTableRequest, principal);
|
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));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DataTableData<DataManagementPlanListingModel>>().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
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<DataManagementPlan>> getSingle(@PathVariable String id, Principal principal) throws IllegalAccessException, InstantiationException {
|
ResponseEntity<ResponseItem<DataManagementPlan>> getSingle(@PathVariable String id, Principal principal) throws IllegalAccessException, InstantiationException {
|
||||||
eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = new DataManagementPlanManager().getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, principal, this.dynamicProjectConfiguration);
|
eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan = new DataManagementPlanManager().getSingle(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, principal, this.dynamicProjectConfiguration);
|
||||||
|
@ -71,28 +77,28 @@ public class DMPs extends BaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@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
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<DMP>> createOrUpdate(@RequestBody eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan, Principal principal) throws Exception {
|
ResponseEntity<ResponseItem<DMP>> createOrUpdate(@RequestBody eu.eudat.models.data.dmp.DataManagementPlan dataManagementPlan, Principal principal) throws Exception {
|
||||||
DataManagementPlanManager.createOrUpdate(this.getApiContext(), dataManagementPlan, principal);
|
DataManagementPlanManager.createOrUpdate(this.getApiContext(), dataManagementPlan, principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Created"));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().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
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<DMP>> newVersion(@PathVariable UUID id, @Valid @RequestBody eu.eudat.models.data.dmp.DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
ResponseEntity<ResponseItem<DMP>> newVersion(@PathVariable UUID id, @Valid @RequestBody eu.eudat.models.data.dmp.DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
||||||
DataManagementPlanManager.newVersion(this.getApiContext(), id, dataManagementPlan, principal);
|
DataManagementPlanManager.newVersion(this.getApiContext(), id, dataManagementPlan, principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.NO_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().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
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<DMP>> clone(@PathVariable UUID id, @RequestBody eu.eudat.models.data.dmp.DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
ResponseEntity<ResponseItem<DMP>> clone(@PathVariable UUID id, @RequestBody eu.eudat.models.data.dmp.DataManagementPlanNewVersionModel dataManagementPlan, Principal principal) throws Exception {
|
||||||
DataManagementPlanManager.clone(this.getApiContext(), id, dataManagementPlan, principal);
|
DataManagementPlanManager.clone(this.getApiContext(), id, dataManagementPlan, principal);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.NO_MESSAGE));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().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
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<List<DataManagementPlan>>> getWithCriteria(@RequestBody DataManagementPlanCriteriaRequest dataManagementPlanCriteria, Principal principal) throws InstantiationException, IllegalAccessException {
|
ResponseEntity<ResponseItem<List<DataManagementPlan>>> getWithCriteria(@RequestBody DataManagementPlanCriteriaRequest dataManagementPlanCriteria, Principal principal) throws InstantiationException, IllegalAccessException {
|
||||||
List<DataManagementPlan> dataTable = new DataManagementPlanManager().getWithCriteria(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), dataManagementPlanCriteria, principal);
|
List<DataManagementPlan> dataTable = new DataManagementPlanManager().getWithCriteria(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), dataManagementPlanCriteria, principal);
|
||||||
|
@ -100,21 +106,21 @@ public class DMPs extends BaseController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Transactional
|
@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
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<DMP>> delete(@PathVariable UUID id, Principal principal) {
|
ResponseEntity<ResponseItem<DMP>> delete(@PathVariable UUID id, Principal principal) {
|
||||||
DataManagementPlanManager.delete(this.getApiContext(), id);
|
DataManagementPlanManager.delete(this.getApiContext(), id);
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().status(ApiMessageCode.SUCCESS_MESSAGE).message("Successfully Deleted Dataset"));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<DMP>().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
|
public @ResponseBody
|
||||||
ResponseEntity<ResponseItem<List<Tuple<String, String>>>> getWithCriteria(@RequestBody RequestItem<DynamicFieldsCriteria> criteriaRequestItem, Principal principal) throws InstantiationException, IllegalAccessException {
|
ResponseEntity<ResponseItem<List<Tuple<String, String>>>> getWithCriteria(@RequestBody RequestItem<DynamicFieldsCriteria> criteriaRequestItem, Principal principal) throws InstantiationException, IllegalAccessException {
|
||||||
List<Tuple<String, String>> dataTable = new DataManagementPlanManager().getDynamicFields(criteriaRequestItem.getCriteria().getId(), this.dynamicProjectConfiguration, criteriaRequestItem.getCriteria());
|
List<Tuple<String, String>> dataTable = new DataManagementPlanManager().getDynamicFields(criteriaRequestItem.getCriteria().getId(), this.dynamicProjectConfiguration, criteriaRequestItem.getCriteria());
|
||||||
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Tuple<String, String>>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<List<Tuple<String, String>>>().status(ApiMessageCode.NO_MESSAGE).payload(dataTable));
|
||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = {"/dmps/getXml/{id}"})
|
@RequestMapping(method = RequestMethod.GET, value = {"/getXml/{id}"})
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<byte[]> getXml(@PathVariable String id) throws IllegalAccessException, IOException, InstantiationException {
|
ResponseEntity<byte[]> getXml(@PathVariable String id) throws IllegalAccessException, IOException, InstantiationException {
|
||||||
FileEnvelope envelope = new DataManagementPlanManager().getXmlDocument(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, this.getApiContext().getUtilitiesService().getVisibilityRuleService());
|
FileEnvelope envelope = new DataManagementPlanManager().getXmlDocument(this.getApiContext().getOperationsContext().getDatabaseRepository().getDmpDao(), id, this.getApiContext().getUtilitiesService().getVisibilityRuleService());
|
||||||
|
@ -134,5 +140,24 @@ public class DMPs extends BaseController {
|
||||||
HttpStatus.OK);
|
HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@RequestMapping(method = RequestMethod.GET, value = {"/getWord/{id}"})
|
||||||
|
public @ResponseBody
|
||||||
|
ResponseEntity<byte[]> 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class DatasetProfileController extends BaseController {
|
||||||
public ResponseEntity<ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>> clone(@PathVariable String id, @ClaimedAuthorities(claims = {ADMIN})Principal principal) {
|
public ResponseEntity<ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>> clone(@PathVariable String id, @ClaimedAuthorities(claims = {ADMIN})Principal principal) {
|
||||||
eu.eudat.data.entities.DatasetProfile profile = new DatasetProfileManager().clone(this.getApiContext(), id);
|
eu.eudat.data.entities.DatasetProfile profile = new DatasetProfileManager().clone(this.getApiContext(), id);
|
||||||
eu.eudat.models.data.admin.composite.DatasetProfile datasetprofile = AdminManager.generateDatasetProfileModel(profile);
|
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<eu.eudat.models.data.admin.composite.DatasetProfile>().payload(datasetprofile));
|
return ResponseEntity.status(HttpStatus.OK).body(new ResponseItem<eu.eudat.models.data.admin.composite.DatasetProfile>().payload(datasetprofile));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,10 +28,7 @@ import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import javax.activation.MimetypesFileTypeMap;
|
import javax.activation.MimetypesFileTypeMap;
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -82,7 +79,7 @@ public class DatasetWizardController extends BaseController {
|
||||||
|
|
||||||
@RequestMapping(method = RequestMethod.GET, value = {"/getPDF/{id}"})
|
@RequestMapping(method = RequestMethod.GET, value = {"/getPDF/{id}"})
|
||||||
public @ResponseBody
|
public @ResponseBody
|
||||||
ResponseEntity<byte[]> getWordDocument(@PathVariable String id) throws IllegalAccessException, IOException, InstantiationException, InterruptedException {
|
ResponseEntity<byte[]> 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 file = new DatasetManager().getWordDocument(this.environment, this.getApiContext().getOperationsContext().getDatabaseRepository().getDatasetDao(), id, this.getApiContext().getUtilitiesService().getVisibilityRuleService());
|
||||||
File pdffile = new DatasetManager().convertToPDF(file, environment, file.getName());
|
File pdffile = new DatasetManager().convertToPDF(file, environment, file.getName());
|
||||||
InputStream resource = new FileInputStream(pdffile);
|
InputStream resource = new FileInputStream(pdffile);
|
||||||
|
|
|
@ -10,6 +10,7 @@ import eu.eudat.data.dao.entities.*;
|
||||||
import eu.eudat.data.entities.*;
|
import eu.eudat.data.entities.*;
|
||||||
import eu.eudat.data.query.items.item.dmp.DataManagementPlanCriteriaRequest;
|
import eu.eudat.data.query.items.item.dmp.DataManagementPlanCriteriaRequest;
|
||||||
import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest;
|
import eu.eudat.data.query.items.table.dmp.DataManagementPlanTableRequest;
|
||||||
|
import eu.eudat.document.DocxDocumentBuilderAdapter;
|
||||||
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsException;
|
import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsException;
|
||||||
import eu.eudat.exceptions.security.UnauthorisedException;
|
import eu.eudat.exceptions.security.UnauthorisedException;
|
||||||
import eu.eudat.logic.builders.entity.UserInfoBuilder;
|
import eu.eudat.logic.builders.entity.UserInfoBuilder;
|
||||||
|
@ -17,6 +18,8 @@ import eu.eudat.logic.services.ApiContext;
|
||||||
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
import eu.eudat.logic.services.forms.VisibilityRuleService;
|
||||||
import eu.eudat.logic.utilities.builders.XmlBuilder;
|
import eu.eudat.logic.utilities.builders.XmlBuilder;
|
||||||
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
|
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.logic.utilities.documents.xml.ExportXmlBuilder;
|
||||||
import eu.eudat.models.HintedModelFactory;
|
import eu.eudat.models.HintedModelFactory;
|
||||||
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
|
||||||
|
@ -30,16 +33,18 @@ import eu.eudat.models.data.listingmodels.DatasetListingModel;
|
||||||
import eu.eudat.models.data.security.Principal;
|
import eu.eudat.models.data.security.Principal;
|
||||||
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
||||||
import eu.eudat.queryable.QueryableList;
|
import eu.eudat.queryable.QueryableList;
|
||||||
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.http.*;
|
import org.springframework.http.*;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.*;
|
||||||
import java.io.File;
|
import java.math.BigInteger;
|
||||||
import java.io.FileWriter;
|
import java.net.URL;
|
||||||
import java.io.IOException;
|
import java.nio.file.Paths;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -81,6 +86,51 @@ public class DataManagementPlanManager {
|
||||||
return;
|
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();
|
||||||
|
DocxDocumentBuilderAdapter document = new DocxDocumentBuilderAdapter(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<String, Object> 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 {
|
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));
|
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)
|
if (dataManagementPlanEntity.getCreator().getId() != principal.getId() && dataManagementPlanEntity.getUsers().stream().filter(userInfo -> userInfo.getId() == principal.getId()).collect(Collectors.toList()).size() == 0)
|
||||||
|
@ -102,7 +152,7 @@ public class DataManagementPlanManager {
|
||||||
datamanagementPlan.getDynamicFields().forEach(item -> {
|
datamanagementPlan.getDynamicFields().forEach(item -> {
|
||||||
Map<String, String> properties = (Map<String, String>) dmpProperties.get(item.getId());
|
Map<String, String> properties = (Map<String, String>) dmpProperties.get(item.getId());
|
||||||
if (properties != null)
|
if (properties != null)
|
||||||
item.setValue(new Tuple<String, String>(properties.get("id"), properties.get("label")));
|
item.setValue(new Tuple<>(properties.get("id"), properties.get("label")));
|
||||||
});
|
});
|
||||||
return datamanagementPlan;
|
return datamanagementPlan;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import eu.eudat.models.data.security.Principal;
|
||||||
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
||||||
import eu.eudat.queryable.QueryableList;
|
import eu.eudat.queryable.QueryableList;
|
||||||
import org.apache.commons.io.IOUtils;
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.poi.xwpf.usermodel.XWPFDocument;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
import org.springframework.core.io.FileSystemResource;
|
import org.springframework.core.io.FileSystemResource;
|
||||||
|
@ -32,10 +33,9 @@ import org.springframework.http.converter.ByteArrayHttpMessageConverter;
|
||||||
import org.springframework.util.LinkedMultiValueMap;
|
import org.springframework.util.LinkedMultiValueMap;
|
||||||
import org.springframework.web.client.RestTemplate;
|
import org.springframework.web.client.RestTemplate;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.FileInputStream;
|
import java.net.URL;
|
||||||
import java.io.FileOutputStream;
|
import java.nio.file.Paths;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -134,6 +134,9 @@ public class DatasetManager {
|
||||||
public File getWordDocument(Environment environment, DatasetDao datatasetRepository, String id, VisibilityRuleService visibilityRuleService) throws InstantiationException, IllegalAccessException, IOException {
|
public File getWordDocument(Environment environment, DatasetDao datatasetRepository, String id, VisibilityRuleService visibilityRuleService) throws InstantiationException, IllegalAccessException, IOException {
|
||||||
WordBuilder wordBuilder = new WordBuilder();
|
WordBuilder wordBuilder = new WordBuilder();
|
||||||
DatasetWizardModel dataset = new DatasetWizardModel();
|
DatasetWizardModel dataset = new DatasetWizardModel();
|
||||||
|
String fileUrl = environment.getProperty("configuration.h2020template");
|
||||||
|
InputStream is = new URL(Paths.get(fileUrl).toUri().toURL().toString()).openStream();
|
||||||
|
XWPFDocument document = new XWPFDocument(is);
|
||||||
eu.eudat.data.entities.Dataset datasetEntity = datatasetRepository.find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
|
eu.eudat.data.entities.Dataset datasetEntity = datatasetRepository.find(UUID.fromString(id), HintedModelFactory.getHint(DatasetWizardModel.class));
|
||||||
Map<String, Object> properties = new HashMap<>();
|
Map<String, Object> properties = new HashMap<>();
|
||||||
if (datasetEntity.getProperties() != null) {
|
if (datasetEntity.getProperties() != null) {
|
||||||
|
@ -143,8 +146,12 @@ public class DatasetManager {
|
||||||
PagedDatasetProfile pagedDatasetProfile = getPagedProfile(dataset, datasetEntity);
|
PagedDatasetProfile pagedDatasetProfile = getPagedProfile(dataset, datasetEntity);
|
||||||
visibilityRuleService.setProperties(properties);
|
visibilityRuleService.setProperties(properties);
|
||||||
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
|
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
|
||||||
File file = wordBuilder.build(environment, pagedDatasetProfile, datasetEntity.getLabel(), visibilityRuleService);
|
wordBuilder.build(document, pagedDatasetProfile, visibilityRuleService);
|
||||||
return file;
|
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 {
|
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) {
|
private static void createRegistriesIfTheyDontExist(RegistryDao registryDao, eu.eudat.data.entities.Dataset dataset) {
|
||||||
if (dataset.getRegistries() != null && !dataset.getRegistries().isEmpty()) {
|
if (dataset.getRegistries() != null && !dataset.getRegistries().isEmpty()) {
|
||||||
for (eu.eudat.data.entities.Registry registry : dataset.getRegistries()) {
|
for (eu.eudat.data.entities.Registry registry : dataset.getRegistries()) {
|
||||||
|
|
|
@ -14,16 +14,9 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLvl;
|
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTLvl;
|
||||||
import org.openxmlformats.schemas.wordprocessingml.x2006.main.STNumberFormat;
|
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.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
import java.math.BigInteger;
|
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.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -40,6 +33,7 @@ public class WordBuilder {
|
||||||
public WordBuilder() {
|
public WordBuilder() {
|
||||||
this.cTAbstractNum = CTAbstractNum.Factory.newInstance();
|
this.cTAbstractNum = CTAbstractNum.Factory.newInstance();
|
||||||
this.cTAbstractNum.setAbstractNumId(BigInteger.valueOf(1));
|
this.cTAbstractNum.setAbstractNumId(BigInteger.valueOf(1));
|
||||||
|
this.buildOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildOptions() {
|
private void buildOptions() {
|
||||||
|
@ -52,6 +46,8 @@ public class WordBuilder {
|
||||||
});
|
});
|
||||||
this.options.put(ParagraphStyle.TITLE, (mainDocumentPart, item) -> {
|
this.options.put(ParagraphStyle.TITLE, (mainDocumentPart, item) -> {
|
||||||
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
||||||
|
paragraph.setStyle("Title");
|
||||||
|
paragraph.setAlignment(ParagraphAlignment.CENTER);
|
||||||
XWPFRun run = paragraph.createRun();
|
XWPFRun run = paragraph.createRun();
|
||||||
run.setText(item);
|
run.setText(item);
|
||||||
run.setBold(true);
|
run.setBold(true);
|
||||||
|
@ -60,6 +56,7 @@ public class WordBuilder {
|
||||||
});
|
});
|
||||||
this.options.put(ParagraphStyle.HEADER1, (mainDocumentPart, item) -> {
|
this.options.put(ParagraphStyle.HEADER1, (mainDocumentPart, item) -> {
|
||||||
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
||||||
|
paragraph.setStyle("Heading1");
|
||||||
XWPFRun run = paragraph.createRun();
|
XWPFRun run = paragraph.createRun();
|
||||||
run.setText(item);
|
run.setText(item);
|
||||||
run.setBold(true);
|
run.setBold(true);
|
||||||
|
@ -69,6 +66,7 @@ public class WordBuilder {
|
||||||
});
|
});
|
||||||
this.options.put(ParagraphStyle.HEADER2, (mainDocumentPart, item) -> {
|
this.options.put(ParagraphStyle.HEADER2, (mainDocumentPart, item) -> {
|
||||||
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
||||||
|
paragraph.setStyle("Heading2");
|
||||||
XWPFRun run = paragraph.createRun();
|
XWPFRun run = paragraph.createRun();
|
||||||
run.setText(item);
|
run.setText(item);
|
||||||
run.setBold(true);
|
run.setBold(true);
|
||||||
|
@ -78,6 +76,7 @@ public class WordBuilder {
|
||||||
});
|
});
|
||||||
this.options.put(ParagraphStyle.HEADER3, (mainDocumentPart, item) -> {
|
this.options.put(ParagraphStyle.HEADER3, (mainDocumentPart, item) -> {
|
||||||
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
XWPFParagraph paragraph = mainDocumentPart.createParagraph();
|
||||||
|
paragraph.setStyle("Heading3");
|
||||||
XWPFRun run = paragraph.createRun();
|
XWPFRun run = paragraph.createRun();
|
||||||
run.setText(item);
|
run.setText(item);
|
||||||
run.setBold(true);
|
run.setBold(true);
|
||||||
|
@ -93,39 +92,28 @@ public class WordBuilder {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public File build(Environment environment, PagedDatasetProfile pagedDatasetProfile, String label, VisibilityRuleService visibilityRuleService) throws IOException {
|
public XWPFDocument build(XWPFDocument document, PagedDatasetProfile pagedDatasetProfile, 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();
|
|
||||||
createPages(pagedDatasetProfile.getPages(), document, true, visibilityRuleService);
|
createPages(pagedDatasetProfile.getPages(), document, true, visibilityRuleService);
|
||||||
XWPFAbstractNum abstractNum = new XWPFAbstractNum(cTAbstractNum);
|
XWPFAbstractNum abstractNum = new XWPFAbstractNum(cTAbstractNum);
|
||||||
XWPFNumbering numbering = document.createNumbering();
|
XWPFNumbering numbering = document.createNumbering();
|
||||||
BigInteger abstractNumID = numbering.addAbstractNum(abstractNum);
|
BigInteger abstractNumID = numbering.addAbstractNum(abstractNum);
|
||||||
this.numId = numbering.addNum(abstractNumID);
|
this.numId = numbering.addNum(abstractNumID);
|
||||||
createPages(pagedDatasetProfile.getPages(), document, false, visibilityRuleService);
|
createPages(pagedDatasetProfile.getPages(), document, false, visibilityRuleService);
|
||||||
File exportFile = new File(label + ".docx");
|
return document;
|
||||||
FileOutputStream out = new FileOutputStream(exportFile);
|
|
||||||
document.write(out);
|
|
||||||
out.close();
|
|
||||||
return exportFile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createPages(List<DatasetProfilePage> datasetProfilePages, XWPFDocument mainDocumentPart, Boolean createListing, VisibilityRuleService visibilityRuleService) {
|
public void createPages(List<DatasetProfilePage> datasetProfilePages, XWPFDocument mainDocumentPart, Boolean createListing, VisibilityRuleService visibilityRuleService) {
|
||||||
//if (createListing) this.addListing(mainDocumentPart, 0, false, true);
|
|
||||||
datasetProfilePages.forEach(item -> {
|
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<Section> sections, XWPFDocument mainDocumentPart, ParagraphStyle style, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService) {
|
public void createSections(List<Section> sections, XWPFDocument mainDocumentPart, ParagraphStyle style, Integer indent, Boolean createListing, VisibilityRuleService visibilityRuleService) {
|
||||||
if (createListing) this.addListing(mainDocumentPart, indent, false, true);
|
if (createListing) this.addListing(mainDocumentPart, indent, false, true);
|
||||||
BigInteger listing = numId;
|
|
||||||
sections.forEach(section -> {
|
sections.forEach(section -> {
|
||||||
if (visibilityRuleService.isElementVisible(section.getId())) {
|
if (visibilityRuleService.isElementVisible(section.getId())) {
|
||||||
if (!createListing) {
|
if (!createListing) {
|
||||||
XWPFParagraph paragraph = addParagraphContent(section.getTitle(), mainDocumentPart, style, listing);
|
XWPFParagraph paragraph = addParagraphContent(section.getTitle(), mainDocumentPart, style, numId);
|
||||||
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
||||||
number.setVal(BigInteger.valueOf(indent));
|
number.setVal(BigInteger.valueOf(indent));
|
||||||
}
|
}
|
||||||
|
@ -139,7 +127,6 @@ public class WordBuilder {
|
||||||
if (createListing) this.addListing(mainDocumentPart, indent, true, true);
|
if (createListing) this.addListing(mainDocumentPart, indent, true, true);
|
||||||
compositeFields.forEach(compositeField -> {
|
compositeFields.forEach(compositeField -> {
|
||||||
if (visibilityRuleService.isElementVisible(compositeField.getId())) {
|
if (visibilityRuleService.isElementVisible(compositeField.getId())) {
|
||||||
|
|
||||||
if (compositeField.getTitle() != null && !compositeField.getTitle().isEmpty() && !createListing) {
|
if (compositeField.getTitle() != null && !compositeField.getTitle().isEmpty() && !createListing) {
|
||||||
XWPFParagraph paragraph = addParagraphContent(compositeField.getTitle(), mainDocumentPart, ParagraphStyle.HEADER3, numId);
|
XWPFParagraph paragraph = addParagraphContent(compositeField.getTitle(), mainDocumentPart, ParagraphStyle.HEADER3, numId);
|
||||||
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
CTDecimalNumber number = paragraph.getCTP().getPPr().getNumPr().addNewIlvl();
|
||||||
|
@ -163,10 +150,12 @@ public class WordBuilder {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public XWPFParagraph addParagraphContent(String text, XWPFDocument mainDocumentPart, ParagraphStyle style, BigInteger numId) {
|
public XWPFParagraph addParagraphContent(String text, XWPFDocument mainDocumentPart, ParagraphStyle style, BigInteger numId) {
|
||||||
XWPFParagraph paragraph = this.options.get(style).apply(mainDocumentPart, text);
|
XWPFParagraph paragraph = this.options.get(style).apply(mainDocumentPart, text);
|
||||||
if (numId != null) paragraph.setNumID(numId);
|
|
||||||
|
if (numId != null) {
|
||||||
|
paragraph.setNumID(numId);
|
||||||
|
}
|
||||||
return paragraph;
|
return paragraph;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,8 +165,6 @@ public class WordBuilder {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addListing(XWPFDocument document, int indent, Boolean question, Boolean hasIndication) {
|
public void addListing(XWPFDocument document, int indent, Boolean question, Boolean hasIndication) {
|
||||||
|
|
||||||
//this.cTAbstractNum.setAbstractNumId(BigInteger.valueOf(indent));
|
|
||||||
CTLvl cTLvl = this.cTAbstractNum.addNewLvl();
|
CTLvl cTLvl = this.cTAbstractNum.addNewLvl();
|
||||||
|
|
||||||
String textLevel = "";
|
String textLevel = "";
|
||||||
|
@ -201,13 +188,6 @@ public class WordBuilder {
|
||||||
cTLvl.addNewStart().setVal(BigInteger.valueOf(1));
|
cTLvl.addNewStart().setVal(BigInteger.valueOf(1));
|
||||||
cTLvl.setIlvl(BigInteger.valueOf(indent));
|
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);
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue