Skip to content
Snippets Groups Projects
Commit 5545f85f authored by Lene Wasskog's avatar Lene Wasskog
Browse files

feat: Add description column to excel file

parent 80bf328d
No related branches found
No related tags found
1 merge request!191Add map module and Open-Meteo support
......@@ -703,6 +703,7 @@ public class Observation implements Serializable, no.nibio.vips.observation.Obse
// choice of the observer
this.location != null && this.geoinfo == null ? this.location.getGeoJSON() : this.getGeoinfo(),
this.getObservationHeading(),
this.getObservationText(),
this.getBroadcastMessage(),
this.getLocationIsPrivate(),
this.getIsPositive(),
......
......@@ -33,6 +33,7 @@ public class ObservationListItem implements Comparable{
private String observationTimeSeriesLabel;
private String geoInfo;
private String observationHeading;
private String observationText;
private String observationData;
private ObservationDataSchema observationDataSchema;
private Boolean broadcastMessage;
......@@ -50,6 +51,7 @@ public class ObservationListItem implements Comparable{
String observationTimeSeriesLabel,
String geoinfo,
String observationHeading,
String observationText,
Boolean broadcastMessage,
Boolean locationIsPrivate,
Boolean isPositive,
......@@ -66,6 +68,7 @@ public class ObservationListItem implements Comparable{
this.observationTimeSeriesLabel = observationTimeSeriesLabel;
this.geoInfo = geoinfo;
this.observationHeading = observationHeading;
this.observationText = observationText;
this.broadcastMessage = broadcastMessage;
this.locationIsPrivate = locationIsPrivate;
this.isPositive = isPositive;
......@@ -190,6 +193,20 @@ public class ObservationListItem implements Comparable{
this.observationHeading = observationHeading;
}
/**
* @return the observation text
*/
public String getObservationText() {
return observationText;
}
/**
* @param observationText The observation text to set
*/
public void setObservationText(String observationText) {
this.observationText = observationText;
}
/**
* @return the organismId
*/
......
......@@ -200,7 +200,7 @@ public class ObservationService {
try {
List<ObservationListItem> observations = getFilteredObservationListItems(organizationId, observationTimeSeriesId, pestId, cropId, cropCategoryId, fromStr, toStr, userUUID, localeStr, isPositive);
byte[] excelFile = ExcelFileGenerator.generateExcel(observations, locale);
byte[] excelFile = ExcelFileGenerator.generateExcel(user, locale, observations);
return Response
.ok(excelFile)
......
......@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.ibm.icu.util.ULocale;
import no.nibio.vips.logic.entity.VipsLogicUser;
import no.nibio.vips.logic.entity.rest.ObservationListItem;
import no.nibio.vips.observationdata.ObservationDataSchema;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
......@@ -26,9 +27,10 @@ public final class ExcelFileGenerator {
private static final int COL_INDEX_ORGANISM = 2;
private static final int COL_INDEX_CROP_ORGANISM = 3;
private static final int COL_INDEX_HEADING = 4;
private static final int COL_START_INDEX_DATA = 5;
private static final int COL_INDEX_DESCRIPTION = 5;
private static final int COL_START_INDEX_DATA = 6;
public static byte[] generateExcel(List<ObservationListItem> observations, ULocale locale) throws IOException {
public static byte[] generateExcel(VipsLogicUser user, ULocale locale, List<ObservationListItem> observations) throws IOException {
ResourceBundle rb = ResourceBundle.getBundle("no.nibio.vips.logic.i18n.vipslogictexts", locale.toLocale());
try (XSSFWorkbook workbook = new XSSFWorkbook();
......@@ -43,7 +45,7 @@ public final class ExcelFileGenerator {
for (ObservationListItem item : observations) {
createItemRow(mainSheet, mainSheetRowIndex++, item);
}
autoSizeColumns(mainSheet, 0, COL_INDEX_HEADING);
autoSizeColumns(mainSheet, 0, COL_INDEX_DESCRIPTION);
// Prepare list of observations for each type of pest
Map<Integer, List<ObservationListItem>> pestObservations = getObservationsForEachPest(observations);
......@@ -161,6 +163,24 @@ public final class ExcelFileGenerator {
return pestObservations;
}
/**
* Create first row of given sheet, with standard set of column titles
*
* @param sheet The sheet to which a row will be added
* @param rb A resource bundle enabling localized messages
* @return the newly created header row
*/
public static Row createHeaderRow(Sheet sheet, ResourceBundle rb) {
Row headerRow = sheet.createRow(0);
headerRow.createCell(COL_INDEX_DATE).setCellValue(rb.getString("timeOfObservation"));
headerRow.createCell(COL_INDEX_LOCATION).setCellValue(rb.getString("location"));
headerRow.createCell(COL_INDEX_ORGANISM).setCellValue(rb.getString("organism"));
headerRow.createCell(COL_INDEX_CROP_ORGANISM).setCellValue(rb.getString("cropOrganismId"));
headerRow.createCell(COL_INDEX_HEADING).setCellValue(rb.getString("observationHeading"));
headerRow.createCell(COL_INDEX_DESCRIPTION).setCellValue(rb.getString("observationText"));
return headerRow;
}
/**
* Create row with given index, for given observation list item
*
......@@ -179,23 +199,8 @@ public final class ExcelFileGenerator {
row.createCell(COL_INDEX_ORGANISM).setCellValue(item.getOrganismName());
row.createCell(COL_INDEX_CROP_ORGANISM).setCellValue(item.getCropOrganismName());
row.createCell(COL_INDEX_HEADING).setCellValue(item.getObservationHeading());
row.createCell(COL_INDEX_DESCRIPTION).setCellValue(item.getObservationText());
return row;
}
/**
* Create first row of given sheet, with standard set of column titles
*
* @param sheet The sheet to which a row will be added
* @param rb A resource bundle enabling localized messages
* @return the newly created header row
*/
public static Row createHeaderRow(Sheet sheet, ResourceBundle rb) {
Row headerRow = sheet.createRow(0);
headerRow.createCell(COL_INDEX_DATE).setCellValue(rb.getString("timeOfObservation"));
headerRow.createCell(COL_INDEX_LOCATION).setCellValue(rb.getString("location"));
headerRow.createCell(COL_INDEX_ORGANISM).setCellValue(rb.getString("organism"));
headerRow.createCell(COL_INDEX_CROP_ORGANISM).setCellValue(rb.getString("cropOrganismId"));
headerRow.createCell(COL_INDEX_HEADING).setCellValue(rb.getString("observationHeading"));
return headerRow;
}
}
......@@ -594,7 +594,7 @@ observationSiteStored = Observation site was successfully updated
observationStored = Observation was stored
observationText = Observation text
observationText = Description
observations = Observations
......
......@@ -594,7 +594,7 @@ observationSiteStored = Rogneb\u00e6rm\u00f8llstasjonen ble oppdatert
observationStored = Observasjonen ble lagret
observationText = Observasjonstekst
observationText = Beskrivelse
observations = Observasjoner/f\u00f8rstefunn
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment