Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

866: Sozialpass csv import docs #966

Merged
merged 2 commits into from
May 10, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@ object EhrenamtskarteBayern : Pipeline {
private val httpClient = HttpClient()

override fun import(config: ImportConfig, logger: Logger) {
Unit.addStep(DownloadLbe(config, logger, httpClient), logger) { logger.info("== Download lbe data ==") }
.addStep(FilterLbe(config, logger), logger) { logger.info("== Filter lbe data ==") }
.addStep(MapFromLbe(config, logger), logger) { logger.info("== Map lbe to internal data ==") }
.addStep(SanitizeAddress(config, logger), logger) { logger.info("== Sanitize address ==") }
.addStep(
SanitizeGeocode(config, logger, httpClient),
logger
) { logger.info("== Sanitize data with geocoding ==") }
.addStep(
PostSanitizeFilter(config, logger, httpClient),
logger
) { logger.info("== Filter sanitized data ==") }
.addStep(FilterDuplicates(config, logger), logger) { logger.info("== Filter duplicated data ==") }
.addStep(Store(config, logger), logger) { logger.info("== Store remaining data to db ==") }
// to speedup testing and creating csv import files for nuernberg, the bavaria import will only be executed if csvWriter is not enabled.
if (!config.backendConfig.csvWriter.enabled) {
Unit.addStep(DownloadLbe(config, logger, httpClient), logger) { logger.info("== Download lbe data ==") }
.addStep(FilterLbe(config, logger), logger) { logger.info("== Filter lbe data ==") }
.addStep(MapFromLbe(config, logger), logger) { logger.info("== Map lbe to internal data ==") }
.addStep(SanitizeAddress(config, logger), logger) { logger.info("== Sanitize address ==") }
.addStep(
SanitizeGeocode(config, logger, httpClient),
logger
) { logger.info("== Sanitize data with geocoding ==") }
.addStep(
PostSanitizeFilter(config, logger, httpClient),
logger
) { logger.info("== Filter sanitized data ==") }
.addStep(FilterDuplicates(config, logger), logger) { logger.info("== Filter duplicated data ==") }
.addStep(Store(config, logger), logger) { logger.info("== Store remaining data to db ==") }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import app.ehrenamtskarte.backend.stores.importer.nuernberg.types.CSVAcceptingSt
import org.apache.commons.csv.CSVFormat
import org.apache.commons.csv.CSVRecord
import org.slf4j.Logger
import java.io.InputStream
import java.io.InputStreamReader
import java.net.URL
import java.net.URLConnection

/**
* Downloads the CSV File.
Expand All @@ -20,10 +20,8 @@ class DownloadCsv(config: ImportConfig, private val logger: Logger) :

override fun execute(input: Unit): List<CSVAcceptingStore> {
try {
val url = URL(config.findProject().importUrl)
val urlConn: URLConnection = url.openConnection()
val inputCSV = InputStreamReader(
urlConn.getInputStream(),
getCSVInputStream(),
Charsets.UTF_8
)
val records: Iterable<CSVRecord> = CSVFormat.RFC4180.parse(inputCSV)
Expand Down Expand Up @@ -62,4 +60,16 @@ class DownloadCsv(config: ImportConfig, private val logger: Logger) :
}
return stores
}

/**
* This function decides if a local csv file will be used or a file from entitlementcard server depending if csvWriter is enabled.
* csvWriter is used to create a local csv output file with coordinates of the stores which will be uploaded to the server.
*/
private fun getCSVInputStream(): InputStream {
if (config.backendConfig.csvWriter.enabled) {
return ClassLoader.getSystemResourceAsStream("import/Akzeptanzpartner-daten.csv")!!
}
val url = URL(config.findProject().importUrl)
return url.openConnection().getInputStream()
}
}
Loading