Commit bdd0f00e authored by Jérémy Destin's avatar Jérémy Destin
Browse files

Merge branch 'feat/implement_germplasm_result_page' into 'master'

Feat/implement germplasm result page

See merge request !66
parents 7d3fb41b 5bfb6a2d
......@@ -105,14 +105,20 @@ public class GnpISGermplasmController {
@PostMapping(value = "/germplasm-list-csv", produces = "text/csv", consumes = APPLICATION_JSON_VALUE)
public FileSystemResource export(@RequestBody @Valid FaidareGermplasmPOSTShearchCriteria criteria, HttpServletResponse response) {
try {
File exportFile = germplasmService.exportListGermplasmCSV(criteria);
response.setHeader("Content-Disposition", "attachment; filename=germplasm.gnpis.csv");
return new FileSystemResource(exportFile);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("An error occurred when exporting germplasm: " + e.getMessage() + ".", e);
long limitResult = 50000L;
long nbResult = germplasmService.germplasmFind(criteria).getMetadata().getPagination().getTotalCount();
if (!(nbResult > limitResult)) {
try {
File exportFile = germplasmService.exportListGermplasmCSV(criteria);
response.setHeader("Content-Disposition", "attachment; filename=germplasm.gnpis.csv");
return new FileSystemResource(exportFile);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("An error occurred when exporting germplasm: " + e.getMessage() + ".", e);
}
}
return null;
}
@ApiOperation("Search list of germplasm")
......
......@@ -2,7 +2,7 @@ version: '3.3'
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.5.4
container_name: elasticsearch
container_name: elasticsearch-faidare
environment:
- discovery.type=single-node
ports:
......@@ -10,7 +10,7 @@ services:
kibana:
image: docker.elastic.co/kibana/kibana:6.5.4
container_name: kibana
container_name: kibana-faidare
environment:
- "ELASTICSEARCH_URL=http://elasticsearch:9200"
depends_on:
......
This diff is collapsed.
......@@ -9,7 +9,8 @@ import { GermplasmSearchCriteria } from '../models/gnpis.model';
export const formatFacets: {[key: string]: string} = {
'holdingInstitute': 'holding institute',
'biologicalStatus': 'biological status',
'geneticNature': 'genetic nature'
'geneticNature': 'genetic nature',
'country': 'origin country'
};
@Component({
......
......@@ -19,9 +19,12 @@
</div>
</div>
<div *ngIf="overLimitSizeExport" class="alert alert-warning alert-dismissible fade show" role="alert">
You must filter your results to have less than <strong>50,000 results</strong> before exporting the data.
</div>
<button type="button" class="btn btn-outline-success mb-2"
(click)="exportPlantMaterial(localCriteria)">
<span class="iconify" data-icon="fa-solid:file-csv" data-inline="false"></span>
Export Plant Material list
</button>
......
......@@ -39,6 +39,7 @@ export class GermplasmResultPageComponent implements OnInit {
'countryOfOriginCode'];
elementPerPage: number[] = [15, 20, 25];
loading: boolean;
overLimitSizeExport = false;
fieldSortState: object = {
germplasmName: null,
accessionNumber: null,
......@@ -81,6 +82,7 @@ export class GermplasmResultPageComponent implements OnInit {
this.germplasmSearchCriteria$
.subscribe(criteria => {
this.overLimitSizeExport = false;
this.localCriteria = criteria;
this.searchGermplasm(this.localCriteria);
});
......@@ -127,8 +129,12 @@ export class GermplasmResultPageComponent implements OnInit {
this.loading = true;
this.service.plantMaterialExport(criteria).subscribe(
result => {
const blob = new Blob([result], { type: 'text/plain;charset=utf-8' });
saveAs(blob, 'germplasm.gnpis.csv');
if (result) {
const blob = new Blob([result], { type: 'text/plain;charset=utf-8' });
saveAs(blob, 'germplasm.gnpis.csv');
} else {
this.overLimitSizeExport = true;
}
this.loading = false;
},
error => {
......
......@@ -139,6 +139,7 @@ export class GnpisService {
return this.http.get<XrefResponse>(`${BASE_URL}/xref/documentbyfulltextid?linkedRessourcesID=${xrefId}`);
}
// TODO Change the service's response to return an object with the number of results and handle here if the number is over the limit
plantMaterialExport(criteria: GermplasmSearchCriteria): Observable<any> {
const requestOptions: Object = {
/* other options here */
......
......@@ -15,7 +15,7 @@
],
"template-cyclomatic-complexity": [
true,
12
13
]
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment