Moved csv header definition to nested function.

This commit is contained in:
neviyn 2018-10-30 15:57:06 +00:00
parent 42ce7bd8df
commit 770e4546e8
2 changed files with 9 additions and 9 deletions

View File

@ -192,9 +192,17 @@ class Controller {
@PostMapping("/observations/csv") @PostMapping("/observations/csv")
fun getObservationsCsvDump(@Valid @RequestBody observationsRequest: ObservationsRequest): String? { fun getObservationsCsvDump(@Valid @RequestBody observationsRequest: ObservationsRequest): String? {
fun csvHeaderString(): String {
return "Ob ID,Observerfull,Observer,obDate,Title,Type,Department,Station,Station Focus,Scores-Monitoring,Scores-Control Procedural," +
"Scores-Control,Scores-Conservatism,Scores-Teamwork Comms,Scores-Teamwork Leadership,Scores-Teamwork Workload,\"Scores-Knowledge, Skills and Attitudes\"," +
"Strengths-Monitoring,Strengths-Control Procedural,Strengths-Control,Strengths-Conservatism,Strengths-Teamwork Comms," +
"Strengths-Teamwork Leadership,Strengths-Teamwork Workload,\"Strengths-Knowledge, Skills and Attitudes\"," +
"Develop-Monitoring,Develop-Control Procedural,Develop-Control,Develop-Conservatism,Develop-Teamwork Comms," +
"Develop-Teamwork Leadership,Develop-Teamwork Workload,\"Develop-Knowledge, Skills and Attitudes\""
}
val data = getObservations(observationsRequest) val data = getObservations(observationsRequest)
if(data.isEmpty()) return null if(data.isEmpty()) return null
val builder = StringBuilder(data[0].csvHeaderString()) val builder = StringBuilder(csvHeaderString())
data.forEach { data.forEach {
builder.append('\n') builder.append('\n')
builder.append(it.toCsvFormat()) builder.append(it.toCsvFormat())

View File

@ -97,14 +97,6 @@ data class Observation(
@ManyToMany @ManyToMany
val persons: Set<Person> val persons: Set<Person>
) { ) {
fun csvHeaderString(): String {
return "Ob ID,Observerfull,Observer,obDate,Title,Type,Department,Station,Station Focus,Scores-Monitoring,Scores-Control Procedural," +
"Scores-Control,Scores-Conservatism,Scores-Teamwork Comms,Scores-Teamwork Leadership,Scores-Teamwork Workload,\"Scores-Knowledge, Skills and Attitudes\"," +
"Strengths-Monitoring,Strengths-Control Procedural,Strengths-Control,Strengths-Conservatism,Strengths-Teamwork Comms," +
"Strengths-Teamwork Leadership,Strengths-Teamwork Workload,\"Strengths-Knowledge, Skills and Attitudes\"," +
"Develop-Monitoring,Develop-Control Procedural,Develop-Control,Develop-Conservatism,Develop-Teamwork Comms," +
"Develop-Teamwork Leadership,Develop-Teamwork Workload,\"Develop-Knowledge, Skills and Attitudes\""
}
fun toCsvFormat(): String { fun toCsvFormat(): String {
return ",,${tutors.elementAt(0).name},$date,\"$observed\",\"Training\",\"Performance Improvement - Training\",\"${site.name}\",\"N/A\"," + return ",,${tutors.elementAt(0).name},$date,\"$observed\",\"Training\",\"Performance Improvement - Training\",\"${site.name}\",\"N/A\"," +
"${roundScore(monitoring)},${roundScore(controlProcedural)},${roundScore(control)}," + "${roundScore(monitoring)},${roundScore(controlProcedural)},${roundScore(control)}," +