fixed bugs for Facet Search

This commit is contained in:
Ioannis Kalyvas 2018-10-08 18:14:27 +03:00
parent af99c1f418
commit aa04f65d84
9 changed files with 109 additions and 18 deletions

View File

@ -26,6 +26,7 @@ public class DatasetTableRequest extends TableQuery<DatasetCriteria, eu.eudat.da
query.initSubQuery(String.class).where((builder, root) -> builder.equal(root.get("dmp").get("version"), query.<String>subQueryMax((builder1, externalRoot, nestedRoot) -> builder1.equal(externalRoot.get("dmp").get("groupId"), nestedRoot.get("dmp").get("groupId")), Arrays.asList(new SelectionField(FieldSelectionType.COMPOSITE_FIELD, "dmp:version")), String.class)));
if (this.getCriteria().getDmpIds() != null && !this.getCriteria().getDmpIds().isEmpty())
query.where((builder, root) -> root.get("dmp").get("id").in(this.getCriteria().getDmpIds()));
query.where((builder, root) -> builder.equal(root.get("status"), Dataset.Status.FINALISED));
return query;
}

View File

@ -141,20 +141,20 @@
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.15</version>
<version>4.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.15</version>
<version>4.0.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/fop -->
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>fop</artifactId>
<version>2.2</version>
<version>2.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/fr.opensagres.xdocreport/org.apache.poi.xwpf.converter.pdf -->
<dependency>

View File

@ -9,6 +9,7 @@ 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.services.ApiContext;
import eu.eudat.logic.utilities.documents.helpers.FileEnvelope;
import eu.eudat.models.data.dmp.DataManagementPlan;
import eu.eudat.models.data.helpermodels.Tuple;
import eu.eudat.models.data.helpers.common.DataTableData;
@ -16,13 +17,20 @@ import eu.eudat.models.data.helpers.responses.ResponseItem;
import eu.eudat.models.data.listingmodels.DataManagementPlanListingModel;
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.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.activation.MimetypesFileTypeMap;
import javax.validation.Valid;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.UUID;
@ -98,5 +106,25 @@ public class DMPs extends BaseController {
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}"})
public @ResponseBody
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());
InputStream resource = new FileInputStream(envelope.getFile());
System.out.println("Mime Type of " + envelope.getFilename() + " is " +
new MimetypesFileTypeMap().getContentType(envelope.getFile()));
HttpHeaders responseHeaders = new HttpHeaders();
responseHeaders.setContentLength(envelope.getFile().length());
responseHeaders.setContentType(MediaType.APPLICATION_OCTET_STREAM);
responseHeaders.set("Content-Disposition", "attachment;filename=" + envelope.getFilename() + ".xml");
responseHeaders.set("Access-Control-Expose-Headers", "Content-Disposition");
responseHeaders.get("Access-Control-Expose-Headers").add("Content-Type");
byte[] content = IOUtils.toByteArray(resource);
return new ResponseEntity<>(content,
responseHeaders,
HttpStatus.OK);
}
}

View File

@ -14,7 +14,12 @@ import eu.eudat.exceptions.datamanagementplan.DMPWithDatasetsException;
import eu.eudat.exceptions.security.UnauthorisedException;
import eu.eudat.logic.builders.entity.UserInfoBuilder;
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.xml.ExportXmlBuilder;
import eu.eudat.models.HintedModelFactory;
import eu.eudat.models.data.datasetwizard.DatasetWizardModel;
import eu.eudat.models.data.dmp.DataManagementPlan;
import eu.eudat.models.data.dmp.DataManagementPlanNewVersionModel;
import eu.eudat.models.data.dynamicfields.DynamicFieldWithValue;
@ -23,11 +28,18 @@ import eu.eudat.models.data.helpers.common.DataTableData;
import eu.eudat.models.data.listingmodels.DataManagementPlanListingModel;
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.json.JSONObject;
import org.springframework.http.*;
import org.springframework.scheduling.annotation.Async;
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.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
@ -295,4 +307,43 @@ public class DataManagementPlanManager {
}
}
public FileEnvelope getXmlDocument(DMPDao dmpRepository, String id, VisibilityRuleService visibilityRuleService) throws InstantiationException, IllegalAccessException, IOException {
ExportXmlBuilder xmlBuilder = new ExportXmlBuilder();
eu.eudat.data.entities.DMP dmp = dmpRepository.find(UUID.fromString(id));
List<Dataset> datasets = dmp.getDataset().stream().collect(Collectors.toList());
File xmlFile = new File(UUID.randomUUID() + ".xml");
BufferedWriter writer = new BufferedWriter(new FileWriter(xmlFile, true));
Document xmlDoc = XmlBuilder.getDocument();
Element root = xmlDoc.createElement("root");
Element dmpElement = xmlDoc.createElement("dmp");
Element datasetsElement = xmlDoc.createElement("datasets");
for (Dataset dataset : datasets) {
Element datasetElement = xmlDoc.createElement("dataset");
DatasetWizardModel datasetWizardModel = new DatasetWizardModel();
Map<String, Object> properties = new HashMap<>();
if (dataset.getProperties() != null) {
JSONObject jobject = new JSONObject(dataset.getProperties());
properties = jobject.toMap();
}
PagedDatasetProfile pagedDatasetProfile = new DatasetManager().getPagedProfile(datasetWizardModel, dataset);
visibilityRuleService.setProperties(properties);
visibilityRuleService.buildVisibilityContext(pagedDatasetProfile.getRules());
datasetElement.appendChild(xmlBuilder.createPages(pagedDatasetProfile.getPages(), visibilityRuleService, xmlDoc));
datasetsElement.appendChild(datasetElement);
}
dmpElement.appendChild(datasetsElement);
root.appendChild(dmpElement);
xmlDoc.appendChild(root);
String xml = XmlBuilder.generateXml(xmlDoc);
writer.write(xml);
writer.close();
FileEnvelope fileEnvelope = new FileEnvelope();
fileEnvelope.setFile(xmlFile);
fileEnvelope.setFilename(dmp.getLabel());
return fileEnvelope;
}
}

View File

@ -106,7 +106,7 @@ public class DatasetManager {
return dataset;
}
private PagedDatasetProfile getPagedProfile(DatasetWizardModel dataset, eu.eudat.data.entities.Dataset datasetEntity) {
public PagedDatasetProfile getPagedProfile(DatasetWizardModel dataset, eu.eudat.data.entities.Dataset datasetEntity) {
eu.eudat.models.data.user.composite.DatasetProfile datasetprofile = UserManager.generateDatasetProfileModel(datasetEntity.getProfile());
datasetprofile.setStatus(dataset.getStatus());
if (datasetEntity.getProperties() != null) {
@ -159,9 +159,13 @@ public class DatasetManager {
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<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<LinkedMultiValueMap<String, Object>>(
map, headers);
Map queueResult = new RestTemplate().postForObject(
environment.getProperty("pdf.converter.url") +
"api/v1/", requestEntity, Map.class);

View File

@ -1,14 +1,14 @@
package eu.eudat.logic.utilities.documents.word;
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.user.components.datasetprofile.Field;
import eu.eudat.models.data.user.components.datasetprofile.FieldSet;
import eu.eudat.models.data.user.components.datasetprofile.Section;
import eu.eudat.models.data.user.composite.DatasetProfilePage;
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import eu.eudat.logic.services.forms.VisibilityRuleService;
import eu.eudat.logic.utilities.interfaces.ApplierWithValue;
import org.apache.poi.xwpf.usermodel.*;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTAbstractNum;
import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDecimalNumber;
@ -16,9 +16,13 @@ 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.*;
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;
@ -91,6 +95,7 @@ public class WordBuilder {
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();
@ -100,7 +105,7 @@ public class WordBuilder {
BigInteger abstractNumID = numbering.addAbstractNum(abstractNum);
this.numId = numbering.addNum(abstractNumID);
createPages(pagedDatasetProfile.getPages(), document, false, visibilityRuleService);
File exportFile = new File(label);
File exportFile = new File(label + ".docx");
FileOutputStream out = new FileOutputStream(exportFile);
document.write(out);
out.close();

View File

@ -1,12 +1,12 @@
package eu.eudat.logic.utilities.documents.xml;
import eu.eudat.logic.services.forms.VisibilityRuleService;
import eu.eudat.logic.utilities.builders.XmlBuilder;
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;
import eu.eudat.models.data.user.composite.DatasetProfilePage;
import eu.eudat.models.data.user.composite.PagedDatasetProfile;
import eu.eudat.logic.services.forms.VisibilityRuleService;
import eu.eudat.logic.utilities.builders.XmlBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
@ -27,7 +27,8 @@ public class ExportXmlBuilder {
File xmlFile = new File(UUID.randomUUID() + ".xml");
BufferedWriter writer = new BufferedWriter(new FileWriter(xmlFile, true));
Document xmlDoc = XmlBuilder.getDocument();
Element root = createPages(pagedDatasetProfile.getPages(), visibilityRuleService, xmlDoc);
Element root = xmlDoc.createElement("root");
root.appendChild(createPages(pagedDatasetProfile.getPages(), visibilityRuleService, xmlDoc));
xmlDoc.appendChild(root);
String xml = XmlBuilder.generateXml(xmlDoc);
writer.write(xml);
@ -36,15 +37,13 @@ public class ExportXmlBuilder {
}
public Element createPages(List<DatasetProfilePage> datasetProfilePages, VisibilityRuleService visibilityRuleService, Document element) {
Element root = element.createElement("root");
Element pages = element.createElement("pages");
datasetProfilePages.forEach(item -> {
Element page = element.createElement("page");
page.appendChild(createSections(item.getSections(), visibilityRuleService, element));
pages.appendChild(page);
});
root.appendChild(pages);
return root;
return pages;
}
public Element createSections(List<Section> sections, VisibilityRuleService visibilityRuleService, Document element) {

View File

@ -15,6 +15,9 @@ export class FacetSearchSectionComponent implements OnInit {
@Input()
searchEnabled = false;
@Input()
requestDelay = 200;
@Input()
multipleSelect = true;
@ -45,7 +48,8 @@ export class FacetSearchSectionComponent implements OnInit {
ngOnInit(): void {
if (!this.multipleSelect) { this.selectionList.selectedOptions = new SelectionModel<MatListOption>(this.multipleSelect); }
this.optionSearchControl.valueChanges.subscribe(x => { if (this.filterOptions) { this.options = this.filterOptions(x); } });
this.optionSearchControl.valueChanges.debounceTime(this.requestDelay)
.distinctUntilChanged().subscribe(x => { if (this.filterOptions) { this.options = this.filterOptions(x); } });
}
public selectionChanged(event: any) {

View File

@ -29,8 +29,7 @@
</mat-panel-title>
</mat-expansion-panel-header>
<app-facet-section-component [options]="this.profiles" (selectedChanged)="profileChanged($event)" [filterOptions]="profileSearch.bind(this)"
[searchEnabled]="true" (optionRemoved)="removeProfile($event)" [displayTitleFunc]="displayProfileLabel"
[displayValueFunc]="displayProfileValue">
(optionRemoved)="removeProfile($event)" [displayTitleFunc]="displayProfileLabel" [displayValueFunc]="displayProfileValue">
</app-facet-section-component>
</mat-expansion-panel>
<mat-expansion-panel>