Skip to content

Commit

Permalink
CSV data export: added option to always evalutate calculated attribut…
Browse files Browse the repository at this point in the history
…es (#166)

* CSV data export: added option to always evalutate calculated attributes

* updated changelog file

---------

Co-authored-by: Stefano Ricci <[email protected]>
  • Loading branch information
SteRiccio and SteRiccio authored Apr 13, 2024
1 parent 69ad795 commit d1f28c5
Show file tree
Hide file tree
Showing 8 changed files with 336 additions and 280 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [4.0.91] - 2024-04-13
### Added
- CSV data export: added option to always evaluate calculated attributes (useful for CE surveys);

## [4.0.90] - 2024-03-11
### Added
- Coordinate attribute: get current location from browser;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,8 @@ private void exportData(OutputStream outputStream, int entityDefId) throws Inval
List<CollectRecordSummary> summaries = recordManager.loadSummaries(recordFilter);
for (CollectRecordSummary s : summaries) {
if ( isRunning() ) {
CollectRecord record = recordManager.load(survey, s.getId(), recordFilter.getStepGreaterOrEqual(), false);
CollectRecord record = recordManager.load(survey, s.getId(), recordFilter.getStepGreaterOrEqual(),
false, parameters.isAlwaysEvaluateCalculatedAttributes());
modelWriter.printData(record);
incrementProcessedItems();
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package org.openforis.collect.io.data.csv;

public abstract class CSVDataExportParametersBase {

public enum HeadingSource {
ATTRIBUTE_NAME, INSTANCE_LABEL, REPORTING_LABEL;
}

public enum OutputFormat {
CSV, XLSX
}

private Integer entityId;

private boolean alwaysGenerateZipFile = false;
private String multipleAttributeValueSeparator = ", ";
private String fieldHeadingSeparator = "_";
Expand All @@ -25,6 +25,7 @@ public enum OutputFormat {
private boolean includeCreatedByUserColumn = false;
private boolean codeAttributeExpanded = false;
private boolean includeImages = false;
private boolean alwaysEvaluateCalculatedAttributes = false;
private int maxMultipleAttributeValues = 10;
private int maxExpandedCodeAttributeItems = 30;
private HeadingSource headingSource = HeadingSource.ATTRIBUTE_NAME;
Expand All @@ -38,47 +39,44 @@ public Integer getEntityId() {
public void setEntityId(Integer entityId) {
this.entityId = entityId;
}

public boolean isAlwaysGenerateZipFile() {
return alwaysGenerateZipFile;
}

public void setAlwaysGenerateZipFile(boolean alwaysGenerateZipFile) {
this.alwaysGenerateZipFile = alwaysGenerateZipFile;
}

public String getMultipleAttributeValueSeparator() {
return multipleAttributeValueSeparator;
}

public void setMultipleAttributeValueSeparator(
String multipleAttributeValueSeparator) {

public void setMultipleAttributeValueSeparator(String multipleAttributeValueSeparator) {
this.multipleAttributeValueSeparator = multipleAttributeValueSeparator;
}

public String getFieldHeadingSeparator() {
return fieldHeadingSeparator;
}

public void setFieldHeadingSeparator(String fieldHeadingSeparator) {
this.fieldHeadingSeparator = fieldHeadingSeparator;
}

public boolean isIncludeCodeItemPositionColumn() {
return includeCodeItemPositionColumn;
}

public void setIncludeCodeItemPositionColumn(
boolean includeCodeItemPositionColumn) {
public void setIncludeCodeItemPositionColumn(boolean includeCodeItemPositionColumn) {
this.includeCodeItemPositionColumn = includeCodeItemPositionColumn;
}

public boolean isIncludeKMLColumnForCoordinates() {
return includeKMLColumnForCoordinates;
}

public void setIncludeKMLColumnForCoordinates(
boolean includeKMLColumnForCoordinates) {
public void setIncludeKMLColumnForCoordinates(boolean includeKMLColumnForCoordinates) {
this.includeKMLColumnForCoordinates = includeKMLColumnForCoordinates;
}

Expand All @@ -97,93 +95,99 @@ public boolean isIncludeAllAncestorAttributes() {
public void setIncludeAllAncestorAttributes(boolean includeAllAncestorAttributes) {
this.includeAllAncestorAttributes = includeAllAncestorAttributes;
}

public boolean isIncludeCodeItemLabelColumn() {
return includeCodeItemLabelColumn;
}

public void setIncludeCodeItemLabelColumn(boolean includeCodeItemLabelColumn) {
this.includeCodeItemLabelColumn = includeCodeItemLabelColumn;
}


public boolean isAlwaysEvaluateCalculatedAttributes() {
return alwaysEvaluateCalculatedAttributes;
}

public void setAlwaysEvaluateCalculatedAttributes(boolean alwaysEvaluateCalculatedAttributes) {
this.alwaysEvaluateCalculatedAttributes = alwaysEvaluateCalculatedAttributes;
}

public int getMaxMultipleAttributeValues() {
return maxMultipleAttributeValues;
}

public void setMaxMultipleAttributeValues(int maxMultipleAttributeValues) {
this.maxMultipleAttributeValues = maxMultipleAttributeValues;
}

public boolean isCodeAttributeExpanded() {
return codeAttributeExpanded;
}

public void setCodeAttributeExpanded(boolean codeAttributeExpanded) {
this.codeAttributeExpanded = codeAttributeExpanded;
}

public boolean isIncludeCompositeAttributeMergedColumn() {
return includeCompositeAttributeMergedColumn;
}

public void setIncludeCompositeAttributeMergedColumn(
boolean includeCompositeAttributeMergedColumn) {

public void setIncludeCompositeAttributeMergedColumn(boolean includeCompositeAttributeMergedColumn) {
this.includeCompositeAttributeMergedColumn = includeCompositeAttributeMergedColumn;
}

public int getMaxExpandedCodeAttributeItems() {
return maxExpandedCodeAttributeItems;
}

public void setMaxExpandedCodeAttributeItems(
int maxExpandedCodeAttributeItems) {

public void setMaxExpandedCodeAttributeItems(int maxExpandedCodeAttributeItems) {
this.maxExpandedCodeAttributeItems = maxExpandedCodeAttributeItems;
}

public HeadingSource getHeadingSource() {
return headingSource;
}

public void setHeadingSource(HeadingSource headingSource) {
this.headingSource = headingSource;
}

public String getLanguageCode() {
return languageCode;
}

public void setLanguageCode(String languageCode) {
this.languageCode = languageCode;
}

public boolean isIncludeGroupingLabels() {
return includeGroupingLabels;
}

public void setIncludeGroupingLabels(boolean includeGroupingLabels) {
this.includeGroupingLabels = includeGroupingLabels;
}

public boolean isIncludeCreatedByUserColumn() {
return includeCreatedByUserColumn;
}

public void setIncludeCreatedByUserColumn(boolean includeCreatedByUserColumn) {
this.includeCreatedByUserColumn = includeCreatedByUserColumn;
}

public boolean isIncludeImages() {
return this.includeImages;
}

public void setIncludeImages(boolean includeImages) {
this.includeImages = includeImages;
}

public OutputFormat getOutputFormat() {
return outputFormat;
}

public void setOutputFormat(OutputFormat outputFormat) {
this.outputFormat = outputFormat;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,12 @@ public CollectRecord load(CollectSurvey survey, int recordId, boolean validate)
public CollectRecord load(CollectSurvey survey, int recordId, Step step) {
return load(survey, recordId, step, true);
}

public CollectRecord load(CollectSurvey survey, int recordId, Step step, boolean validate) {
return load(survey, recordId, step, validate, false);
}

public CollectRecord load(CollectSurvey survey, int recordId, Step step, boolean validate, boolean alwaysEvaluateCalculatedAttributes) {
if (survey == null) {
int surveyId = recordDao.loadSurveyId(recordId);
survey = surveyManager.getOrLoadSurveyById(surveyId);
Expand All @@ -365,6 +369,7 @@ public CollectRecord load(CollectSurvey survey, int recordId, Step step, boolean
recordConverter.convertToLatestVersion(r);
RecordUpdater updater = new RecordUpdater();
updater.setValidateAfterUpdate(validate);
updater.setAlwaysEvaluateCalculatedAttributes(alwaysEvaluateCalculatedAttributes);
updater.initializeRecord(r);
return r;
}
Expand Down
Loading

0 comments on commit d1f28c5

Please sign in to comment.