Added config to auto send email on session completion. Added route for manual mail sending.
This commit is contained in:
parent
93b0f68721
commit
449c4cf3b1
@ -178,12 +178,15 @@ class GroupSessionController {
|
|||||||
observations.add(observation)
|
observations.add(observation)
|
||||||
}
|
}
|
||||||
GroupSessionManager.invalidate()
|
GroupSessionManager.invalidate()
|
||||||
GlobalScope.launch {
|
if(this::environment.isInitialized && environment.getProperty("smtp.autosendoncomplete")!!.toBoolean())
|
||||||
if (::mailer.isInitialized)
|
GlobalScope.launch {
|
||||||
mailer.sendObservationData(observations)
|
if (::mailer.isInitialized)
|
||||||
else
|
mailer.sendObservationData(observations)
|
||||||
logger.error("Mailer has not been initialized.")
|
else
|
||||||
}
|
logger.error("Mailer has not been initialized.")
|
||||||
|
}
|
||||||
|
else
|
||||||
|
logger.debug("Environment or Mailer is unavailable")
|
||||||
websocketMessenger.convertAndSend("/ws/status", mapOf("status" to "complete"))
|
websocketMessenger.convertAndSend("/ws/status", mapOf("status" to "complete"))
|
||||||
return mapOf("success" to "The submission was successfully completed.")
|
return mapOf("success" to "The submission was successfully completed.")
|
||||||
} else if (!GroupSessionManager.dataComplete()) {
|
} else if (!GroupSessionManager.dataComplete()) {
|
||||||
|
@ -19,6 +19,7 @@ import uk.co.neviyn.observationdatabase.AfiPieChartDataset
|
|||||||
import uk.co.neviyn.observationdatabase.AverageData
|
import uk.co.neviyn.observationdatabase.AverageData
|
||||||
import uk.co.neviyn.observationdatabase.ChartData
|
import uk.co.neviyn.observationdatabase.ChartData
|
||||||
import uk.co.neviyn.observationdatabase.ChartDataset
|
import uk.co.neviyn.observationdatabase.ChartDataset
|
||||||
|
import uk.co.neviyn.observationdatabase.Email
|
||||||
import uk.co.neviyn.observationdatabase.NameValue
|
import uk.co.neviyn.observationdatabase.NameValue
|
||||||
import uk.co.neviyn.observationdatabase.NewObservation
|
import uk.co.neviyn.observationdatabase.NewObservation
|
||||||
import uk.co.neviyn.observationdatabase.NewSite
|
import uk.co.neviyn.observationdatabase.NewSite
|
||||||
@ -50,6 +51,9 @@ class ObservationsController {
|
|||||||
lateinit var observationRepository: ObservationRepository
|
lateinit var observationRepository: ObservationRepository
|
||||||
@Autowired
|
@Autowired
|
||||||
lateinit var personRepository: PersonRepository
|
lateinit var personRepository: PersonRepository
|
||||||
|
@Autowired
|
||||||
|
lateinit var mailer: Email
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of all current sites.
|
* Returns a list of all current sites.
|
||||||
@ -272,4 +276,22 @@ class ObservationsController {
|
|||||||
}
|
}
|
||||||
return AfiPieChart(AfiPieChartDataset(monitoring, knowledge, control, conservatism, teamwork))
|
return AfiPieChart(AfiPieChartDataset(monitoring, knowledge, control, conservatism, teamwork))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send current observation as a csv file to the configured email address
|
||||||
|
*/
|
||||||
|
@PostMapping("/observations/email")
|
||||||
|
fun sendObservationsByEmail(@Valid @RequestBody observationsRequest: ObservationsRequest): Boolean {
|
||||||
|
logger.info("Sending Observation data by email")
|
||||||
|
if (::mailer.isInitialized) {
|
||||||
|
val data = getObservations(observationsRequest)
|
||||||
|
if(data.isEmpty())
|
||||||
|
return false
|
||||||
|
mailer.sendObservationData(data)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
else
|
||||||
|
logger.error("Mailer has not been initialized.")
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
@ -27,6 +27,10 @@
|
|||||||
{
|
{
|
||||||
"name": "smtp.toaddress",
|
"name": "smtp.toaddress",
|
||||||
"type": "java.lang.String"
|
"type": "java.lang.String"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "smtp.autosendoncomplete",
|
||||||
|
"type": "java.lang.Boolean"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
@ -11,4 +11,5 @@ smtp.server=x
|
|||||||
smtp.port=587
|
smtp.port=587
|
||||||
smtp.username=none
|
smtp.username=none
|
||||||
smtp.password=none
|
smtp.password=none
|
||||||
smtp.toaddress=none
|
smtp.toaddress=none
|
||||||
|
smtp.autosendoncomplete=false
|
@ -15,6 +15,7 @@ import org.mockito.Mockito.times
|
|||||||
import org.mockito.Mockito.verify
|
import org.mockito.Mockito.verify
|
||||||
import org.mockito.junit.MockitoJUnitRunner
|
import org.mockito.junit.MockitoJUnitRunner
|
||||||
import org.springframework.web.server.ResponseStatusException
|
import org.springframework.web.server.ResponseStatusException
|
||||||
|
import uk.co.neviyn.observationdatabase.Email
|
||||||
import uk.co.neviyn.observationdatabase.NameValue
|
import uk.co.neviyn.observationdatabase.NameValue
|
||||||
import uk.co.neviyn.observationdatabase.NewObservation
|
import uk.co.neviyn.observationdatabase.NewObservation
|
||||||
import uk.co.neviyn.observationdatabase.NewSite
|
import uk.co.neviyn.observationdatabase.NewSite
|
||||||
@ -47,6 +48,8 @@ class ObservationsControllerTest {
|
|||||||
lateinit var observationRepository: ObservationRepository
|
lateinit var observationRepository: ObservationRepository
|
||||||
@Mock
|
@Mock
|
||||||
lateinit var personRepository: PersonRepository
|
lateinit var personRepository: PersonRepository
|
||||||
|
@Mock
|
||||||
|
lateinit var mailer: Email
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testGetSites() {
|
fun testGetSites() {
|
||||||
|
Loading…
Reference in New Issue
Block a user