Fixed dataset Export
This commit is contained in:
parent
78753404b5
commit
f8d343c128
|
@ -98,15 +98,17 @@ public class DatasetManager {
|
||||||
private BuilderFactory builderFactory;
|
private BuilderFactory builderFactory;
|
||||||
private UserManager userManager;
|
private UserManager userManager;
|
||||||
private ConfigLoader configLoader;
|
private ConfigLoader configLoader;
|
||||||
|
private Environment environment;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public DatasetManager(ApiContext apiContext, UserManager userManager, ConfigLoader configLoader) {
|
public DatasetManager(ApiContext apiContext, UserManager userManager, ConfigLoader configLoader, Environment environment) {
|
||||||
this.apiContext = apiContext;
|
this.apiContext = apiContext;
|
||||||
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
|
this.databaseRepository = apiContext.getOperationsContext().getDatabaseRepository();
|
||||||
this.datasetRepository = apiContext.getOperationsContext().getDatasetRepository();
|
this.datasetRepository = apiContext.getOperationsContext().getDatasetRepository();
|
||||||
this.builderFactory = apiContext.getOperationsContext().getBuilderFactory();
|
this.builderFactory = apiContext.getOperationsContext().getBuilderFactory();
|
||||||
this.userManager = userManager;
|
this.userManager = userManager;
|
||||||
this.configLoader = configLoader;
|
this.configLoader = configLoader;
|
||||||
|
this.environment = environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DataTableData<DatasetListingModel> getPaged(DatasetTableRequest datasetTableRequest, Principal principal) throws Exception {
|
public DataTableData<DatasetListingModel> getPaged(DatasetTableRequest datasetTableRequest, Principal principal) throws Exception {
|
||||||
|
@ -453,7 +455,7 @@ public class DatasetManager {
|
||||||
.collect(Collectors.toList()).size() == 0)
|
.collect(Collectors.toList()).size() == 0)
|
||||||
throw new UnauthorisedException();
|
throw new UnauthorisedException();
|
||||||
String label = datasetEntity.getLabel().replaceAll("[^a-zA-Z0-9+ ]", "");
|
String label = datasetEntity.getLabel().replaceAll("[^a-zA-Z0-9+ ]", "");
|
||||||
File exportFile = new File(label + ".docx");
|
File exportFile = new File(this.environment.getProperty("temp.temp") + label + ".docx");
|
||||||
XWPFDocument document = getWordDocument(configLoader, datasetEntity, visibilityRuleService);
|
XWPFDocument document = getWordDocument(configLoader, datasetEntity, visibilityRuleService);
|
||||||
FileOutputStream out = new FileOutputStream(exportFile);
|
FileOutputStream out = new FileOutputStream(exportFile);
|
||||||
document.write(out);
|
document.write(out);
|
||||||
|
@ -483,7 +485,7 @@ 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 = xmlBuilder.build(pagedDatasetProfile, datasetEntity.getProfile().getId(), visibilityRuleService);
|
File file = xmlBuilder.build(pagedDatasetProfile, datasetEntity.getProfile().getId(), visibilityRuleService, environment);
|
||||||
FileEnvelope fileEnvelope = new FileEnvelope();
|
FileEnvelope fileEnvelope = new FileEnvelope();
|
||||||
fileEnvelope.setFile(file);
|
fileEnvelope.setFile(file);
|
||||||
fileEnvelope.setFilename(datasetEntity.getLabel());
|
fileEnvelope.setFilename(datasetEntity.getLabel());
|
||||||
|
|
|
@ -43,11 +43,13 @@ public class DocumentManager {
|
||||||
private ApiContext context;
|
private ApiContext context;
|
||||||
private DatasetManager datasetManager;
|
private DatasetManager datasetManager;
|
||||||
private ConfigLoader configLoader;
|
private ConfigLoader configLoader;
|
||||||
|
private Environment environment;
|
||||||
|
|
||||||
public DocumentManager(ApiContext context, DatasetManager datasetManager, ConfigLoader configLoader) {
|
public DocumentManager(ApiContext context, DatasetManager datasetManager, ConfigLoader configLoader, Environment environment) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.datasetManager = datasetManager;
|
this.datasetManager = datasetManager;
|
||||||
this.configLoader = configLoader;
|
this.configLoader = configLoader;
|
||||||
|
this.environment = environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
public File getWordDocument(ConfigLoader configLoader, DatasetDao datatasetRepository, String id, VisibilityRuleService visibilityRuleService) throws InstantiationException, IllegalAccessException, IOException {
|
public File getWordDocument(ConfigLoader configLoader, DatasetDao datatasetRepository, String id, VisibilityRuleService visibilityRuleService) throws InstantiationException, IllegalAccessException, IOException {
|
||||||
|
@ -82,7 +84,7 @@ public class DocumentManager {
|
||||||
PagedDatasetProfile pagedDatasetProfile = datasetManager.getPagedProfile(dataset, datasetEntity);
|
PagedDatasetProfile pagedDatasetProfile = datasetManager.getPagedProfile(dataset, datasetEntity);
|
||||||
visibilityRuleService.setProperties(properties);
|
visibilityRuleService.setProperties(properties);
|
||||||
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
|
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
|
||||||
File file = xmlBuilder.build(pagedDatasetProfile, UUID.fromString(id), visibilityRuleService);
|
File file = xmlBuilder.build(pagedDatasetProfile, UUID.fromString(id), visibilityRuleService, environment);
|
||||||
FileEnvelope fileEnvelope = new FileEnvelope();
|
FileEnvelope fileEnvelope = new FileEnvelope();
|
||||||
fileEnvelope.setFile(file);
|
fileEnvelope.setFile(file);
|
||||||
fileEnvelope.setFilename(datasetEntity.getLabel());
|
fileEnvelope.setFilename(datasetEntity.getLabel());
|
||||||
|
|
|
@ -9,6 +9,7 @@ import eu.eudat.models.data.user.composite.DatasetProfilePage;
|
||||||
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
import org.springframework.core.env.Environment;
|
||||||
import org.w3c.dom.Document;
|
import org.w3c.dom.Document;
|
||||||
import org.w3c.dom.Element;
|
import org.w3c.dom.Element;
|
||||||
|
|
||||||
|
@ -21,9 +22,9 @@ import java.util.UUID;
|
||||||
|
|
||||||
public class ExportXmlBuilder {
|
public class ExportXmlBuilder {
|
||||||
|
|
||||||
public File build(PagedDatasetProfile pagedDatasetProfile, UUID datasetProfileId, VisibilityRuleService visibilityRuleService) throws IOException {
|
public File build(PagedDatasetProfile pagedDatasetProfile, UUID datasetProfileId, VisibilityRuleService visibilityRuleService, Environment environment) throws IOException {
|
||||||
|
|
||||||
File xmlFile = new File(UUID.randomUUID() + ".xml");
|
File xmlFile = new File(environment.getProperty("temp.temp") + UUID.randomUUID() + ".xml");
|
||||||
BufferedWriter writer = new BufferedWriter(new FileWriter(xmlFile, true));
|
BufferedWriter writer = new BufferedWriter(new FileWriter(xmlFile, true));
|
||||||
Document xmlDoc = XmlBuilder.getDocument();
|
Document xmlDoc = XmlBuilder.getDocument();
|
||||||
Element root = xmlDoc.createElement("root");
|
Element root = xmlDoc.createElement("root");
|
||||||
|
|
Loading…
Reference in New Issue