Skip to content
This repository has been archived by the owner on Oct 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #23 from EHJ-52n/feature/gui-support-for-sample-ba…
Browse files Browse the repository at this point in the history
…sed-files

Feature/gui support for sample based files

Fixes #21 and #16 to some extent
  • Loading branch information
EHJ-52n committed Apr 28, 2014
2 parents 639d66b + 00b8fc0 commit 75d1a3e
Show file tree
Hide file tree
Showing 15 changed files with 1,558 additions and 163 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@
<xs:annotation>
<xs:documentation>
Defines the pattern used to parse the date information
of the current pattern.
of the current sample.
</xs:documentation>
</xs:annotation>
</xs:attribute>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@ public boolean isFinished() {
return false;
}

if(step2Model.isSampleBased() &&
(step2Model.getSampleBasedStartRegEx() == null ||
step2Model.getSampleBasedStartRegEx().isEmpty() ||
step2Model.getSampleBasedDateOffset() < 1 ||
step2Model.getSampleBasedDateExtractionRegEx() == null ||
step2Model.getSampleBasedDateExtractionRegEx().isEmpty() ||
step2Model.getSampleBasedDateExtractionRegEx().indexOf("(") < 0 ||
step2Model.getSampleBasedDateExtractionRegEx().indexOf(")") < 1 ||
step2Model.getSampleBasedDatePattern() == null ||
step2Model.getSampleBasedDatePattern().isEmpty() ||
step2Model.getSampleBasedDataOffset() < 1 ||
step2Model.getSampleBasedSampleSizeOffset() < 1 ||
step2Model.getSampleBasedSampleSizeRegEx() == null ||
step2Model.getSampleBasedSampleSizeRegEx().isEmpty() ||
step2Model.getSampleBasedSampleSizeRegEx().indexOf("(") < 0 ||
step2Model.getSampleBasedSampleSizeRegEx().indexOf(")") < 1
)) {
return false;
}

return true;
}

Expand All @@ -93,7 +113,7 @@ public StepController getNextStepController() {
step2Model.getFirstLineWithData());
return new Step3Controller(0,
step2Model.getFirstLineWithData(),
step2Model.getUseHeader());
step2Model.isUseHeader());
}

@Override
Expand All @@ -118,12 +138,23 @@ public void loadSettings() {
final String csvFileContent = step2Model.getCSVFileContent();
step2Panel.setCSVFileContent(csvFileContent);

final boolean useHeader = step2Model.getUseHeader();
final boolean useHeader = step2Model.isUseHeader();
step2Panel.setUseHeader(useHeader);
step2Panel.setCSVFileHighlight(firstLineWithData);

final char decimalSeparator = step2Model.getDecimalSeparator();
step2Panel.setDecimalSeparator(decimalSeparator+"");

if (step2Model.isSampleBased()) {
step2Panel.setSampleBased(true);
step2Panel.setSampleBasedStartRegEx(step2Model.getSampleBasedStartRegEx());
step2Panel.setSampleBasedDateOffset(step2Model.getSampleBasedDateOffset());
step2Panel.setSampleBasedDateExtractionRegEx(step2Model.getSampleBasedDateExtractionRegEx());
step2Panel.setSampleBasedDatePattern(step2Model.getSampleBasedDatePattern());
step2Panel.setSampleBasedDataOffset(step2Model.getSampleBasedDataOffset());
step2Panel.setSampleBasedSampleSizeOffset(step2Model.getSampleBasedSampleSizeOffset());
step2Panel.setSampleBasedSampleSizeRegEx(step2Model.getSampleBasedSampleSizeRegEx());
}
}

@Override
Expand Down Expand Up @@ -164,6 +195,17 @@ public void saveSettings() {
Constants.THOUSANDS_SEPARATOR = '.';
}

if (step2Panel.isSampleBased()) {
step2Model.setSampleBased(true);
step2Model.setSampleBasedStartRegEx(step2Panel.getSampleBasedStartRegEx());
step2Model.setSampleBasedDateOffset(step2Panel.getSampleBasedDateOffset());
step2Model.setSampleBasedDateExtractionRegEx(step2Panel.getSampleBasedDateExtractionRegEx());
step2Model.setSampleBasedDatePattern(step2Panel.getSampleBasedDatePattern());
step2Model.setSampleBasedDataOffset(step2Panel.getSampleBasedDataOffset());
step2Model.setSampleBasedSampleSizeOffset(step2Panel.getSampleBasedSampleSizeOffset());
step2Model.setSampleBasedSampleSizeRegEx(step2Panel.getSampleBasedSampleSizeRegEx());
}

step2Panel = null;
}

Expand Down Expand Up @@ -241,7 +283,7 @@ private CsvData parseCSVFile() {
final String quoteChar = step2Model.getCommentIndicator();
final String escape = step2Model.getTextQualifier();
final int firstLineWithData = step2Model.getFirstLineWithData();
final boolean useHeader = step2Model.getUseHeader();
final boolean useHeader = step2Model.isUseHeader();

logger.info("Parse CSV file: " +
"column separator: '" + separator + "', " +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,22 @@ public class Step2Model implements StepModel {

private boolean useHeader;

private boolean isSampleBased;

private String sampleBasedStartRegEx = "";

private int dateOffset = 0;

private String sampleBasedDateExtractionRegEx = "";

private String sampleBasedDatePattern = "";

private int dataOffset = 0;

private int sampleSizeOffset = 0;

private String sampleBasedSampleSizeRegEx = "";

public Step2Model(final String csvFileContent, final int csvFileRowCount) {
this.csvFileContent = csvFileContent;

Expand All @@ -58,63 +74,145 @@ public int getCsvFileRowRount() {
return csvFileRowRount;
}

public void setCsvFileRowRount(final int csvFileRowRount) {
public Step2Model setCsvFileRowRount(final int csvFileRowRount) {
this.csvFileRowRount = csvFileRowRount;
return this;
}

public String getColumnSeparator() {
return columnSeparator;
}

public void setColumnSeparator(final String selectedColumnSeparator) {
public Step2Model setColumnSeparator(final String selectedColumnSeparator) {
columnSeparator = selectedColumnSeparator;
return this;
}

public String getCommentIndicator() {
return commentIndicator;
}

public void setCommentIndicator(final String selectedCommentIndicator) {
public Step2Model setCommentIndicator(final String selectedCommentIndicator) {
commentIndicator = selectedCommentIndicator;
return this;
}

public int getFirstLineWithData() {
return firstLineWithData;
}

public void setFirstLineWithData(final int firstLineWithData) {
public Step2Model setFirstLineWithData(final int firstLineWithData) {
this.firstLineWithData = firstLineWithData;
return this;
}

public String getTextQualifier() {
return textQualifier;
}

public void setTextQualifier(final String selectedTextQualifier) {
public Step2Model setTextQualifier(final String selectedTextQualifier) {
textQualifier = selectedTextQualifier;
return this;
}

public String getCSVFileContent() {
return csvFileContent;
}

public void setCSVFileContent(final String cSVFileContent) {
public Step2Model setCSVFileContent(final String cSVFileContent) {
csvFileContent = cSVFileContent;
return this;
}

public boolean getUseHeader() {
public boolean isUseHeader() {
return useHeader;
}

public void setUseHeader(final boolean useHeader) {
public Step2Model setUseHeader(final boolean useHeader) {
this.useHeader = useHeader;
return this;
}

public char getDecimalSeparator() {
return decimalSeparator;
}

public void setDecimalSeparator(final char decimalSeparator) {
public Step2Model setDecimalSeparator(final char decimalSeparator) {
this.decimalSeparator = decimalSeparator;
return this;
}

public boolean isSampleBased() {
return isSampleBased;
}

public Step2Model setSampleBased(final boolean isSampleBased) {
this.isSampleBased = isSampleBased;
return this;
}

public Step2Model setSampleBasedStartRegEx(final String sampleBasedStartRegEx) {
this.sampleBasedStartRegEx = sampleBasedStartRegEx;
return this;
}

public String getSampleBasedStartRegEx() {
return sampleBasedStartRegEx;
}

public Step2Model setSampleBasedDateOffset(final int dateOffset) {
this.dateOffset = dateOffset;
return this;
}

public int getSampleBasedDateOffset() {
return dateOffset;
}

public Step2Model setSampleBasedDateExtractionRegEx(final String sampleBasedDateExtractionRegEx) {
this.sampleBasedDateExtractionRegEx = sampleBasedDateExtractionRegEx;
return this;
}

public String getSampleBasedDateExtractionRegEx() {
return sampleBasedDateExtractionRegEx;
}

public Step2Model setSampleBasedDatePattern(final String sampleBasedDateDatePattern) {
sampleBasedDatePattern = sampleBasedDateDatePattern;
return this;
}

public String getSampleBasedDatePattern() {
return sampleBasedDatePattern;
}

public Step2Model setSampleBasedDataOffset(final int dataOffset) {
this.dataOffset = dataOffset;
return this;
}

public int getSampleBasedDataOffset() {
return dataOffset;
}

public Step2Model setSampleBasedSampleSizeOffset(final int sampleSizeOffset) {
this.sampleSizeOffset = sampleSizeOffset;
return this;
}

public int getSampleBasedSampleSizeOffset() {
return sampleSizeOffset;
}

public Step2Model setSampleBasedSampleSizeRegEx(final String sampleBasedSampleSizeRegEx) {
this.sampleBasedSampleSizeRegEx = sampleBasedSampleSizeRegEx;
return this;
}

public String getSampleBasedSampleSizeRegEx() {
return sampleBasedSampleSizeRegEx;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.x52North.sensorweb.sos.importer.x02.CsvMetadataDocument.CsvMetadata;
import org.x52North.sensorweb.sos.importer.x02.DataFileDocument.DataFile;
import org.x52North.sensorweb.sos.importer.x02.ParameterDocument.Parameter;
import org.x52North.sensorweb.sos.importer.x02.SosImportConfigurationDocument.SosImportConfiguration;

Expand All @@ -40,7 +41,7 @@
* @author <a href="mailto:[email protected]">Eike Hinderk J&uuml;rrens</a>
*/
public class Step2ModelHandler implements ModelHandler<Step2Model> {

private static final Logger logger = LoggerFactory.getLogger(Step2ModelHandler.class);

@Override
Expand All @@ -49,24 +50,38 @@ public void handleModel(final Step2Model stepModel,
if (logger.isTraceEnabled()) {
logger.trace("handleModel()");
}
CsvMetadata cM = sosImportConf.getCsvMetadata();
Parameter p = null;
CsvMetadata csvMetadata = sosImportConf.getCsvMetadata();
Parameter parameter = null;
//
if (cM == null) {
cM = sosImportConf.addNewCsvMetadata();
p = cM.addNewParameter();
if (csvMetadata == null) {
csvMetadata = sosImportConf.addNewCsvMetadata();
parameter = csvMetadata.addNewParameter();
} else {
p = cM.getParameter();
parameter = csvMetadata.getParameter();
}
if (parameter == null) {
parameter = csvMetadata.addNewParameter();
}
if (p == null) {
p = cM.addNewParameter();
csvMetadata.setFirstLineWithData(stepModel.getFirstLineWithData());
csvMetadata.setUseHeader(stepModel.isUseHeader());
csvMetadata.setDecimalSeparator(stepModel.getDecimalSeparator()+"");
parameter.setCommentIndicator(stepModel.getCommentIndicator());
parameter.setColumnSeparator(stepModel.getColumnSeparator());
parameter.setTextIndicator(stepModel.getTextQualifier());
if (stepModel.isSampleBased()) {
// add other sampling parameters
if (sosImportConf.getDataFile() == null) {
sosImportConf.addNewDataFile();
}
final DataFile dataFile = sosImportConf.getDataFile();
dataFile.setSampleStartRegEx(stepModel.getSampleBasedStartRegEx());
dataFile.setSampleDateOffset(stepModel.getSampleBasedDateOffset());
dataFile.setSampleDateExtractionRegEx(stepModel.getSampleBasedDateExtractionRegEx());
dataFile.setSampleDatePattern(stepModel.getSampleBasedDatePattern());
dataFile.setSampleDataOffset(stepModel.getSampleBasedDataOffset());
dataFile.setSampleSizeOffset(stepModel.getSampleBasedSampleSizeOffset());
dataFile.setSampleSizeRegEx(stepModel.getSampleBasedSampleSizeRegEx());
}
cM.setFirstLineWithData(stepModel.getFirstLineWithData());
cM.setUseHeader(stepModel.getUseHeader());
cM.setDecimalSeparator(stepModel.getDecimalSeparator()+"");
p.setCommentIndicator(stepModel.getCommentIndicator());
p.setColumnSeparator(stepModel.getColumnSeparator());
p.setTextIndicator(stepModel.getTextQualifier());
}

}
Loading

0 comments on commit 75d1a3e

Please sign in to comment.