use of de.symeda.sormas.app.backend.event.EventParticipant in project SORMAS-Project by hzi-braunschweig.
the class EventNewActivity method saveData.
@Override
public void saveData() {
if (saveTask != null) {
NotificationHelper.showNotification(this, WARNING, getString(R.string.message_already_saving));
// don't save multiple times
return;
}
final Event eventToSave = (Event) getActiveFragment().getPrimaryData();
EventEditFragment fragment = (EventEditFragment) getActiveFragment();
if (caseUuid != null) {
Case linkedCase = DatabaseHelper.getCaseDao().getByReferenceDto(new CaseReferenceDto(caseUuid));
if (eventToSave.getDisease() != null && !eventToSave.getDisease().equals(linkedCase.getDisease())) {
NotificationHelper.showNotification(this, WARNING, getString(R.string.message_Event_and_Case_disease_mismatch) + " " + linkedCase.getDisease());
return;
}
}
fragment.setLiveValidationDisabled(false);
try {
FragmentValidator.validate(getContext(), fragment.getContentBinding());
} catch (ValidationException e) {
NotificationHelper.showNotification(this, ERROR, e.getMessage());
return;
}
saveTask = new SavingAsyncTask(getRootView(), eventToSave) {
@Override
protected void onPreExecute() {
showPreloader();
}
@Override
public void doInBackground(TaskResultHolder resultHolder) throws DaoException {
DatabaseHelper.getEventDao().saveAndSnapshot(eventToSave);
}
@Override
protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
hidePreloader();
super.onPostExecute(taskResult);
if (taskResult.getResultStatus().isSuccess()) {
finish();
if (caseUuid != null) {
EventParticipant eventParticipantToSave = DatabaseHelper.getEventParticipantDao().build();
Case linkedCase = DatabaseHelper.getCaseDao().getByReferenceDto(new CaseReferenceDto(caseUuid));
eventParticipantToSave.setPerson(linkedCase.getPerson());
eventParticipantToSave.setEvent(eventToSave);
eventParticipantToSave.setResultingCaseUuid(linkedCase.getUuid());
EventParticipantSaver eventParticipantSaver = new EventParticipantSaver(EventNewActivity.this);
eventParticipantSaver.saveEventParticipantLinkedToCase(eventParticipantToSave);
} else {
EventEditActivity.startActivity(getContext(), eventToSave.getUuid(), EventSection.EVENT_PARTICIPANTS);
}
}
saveTask = null;
}
}.executeOnThreadPool();
}
use of de.symeda.sormas.app.backend.event.EventParticipant in project SORMAS-Project by hzi-braunschweig.
the class EventParticipantEditActivity method saveData.
@Override
public void saveData() {
if (saveTask != null) {
// don't save multiple times
NotificationHelper.showNotification(this, WARNING, getString(R.string.message_already_saving));
return;
}
final EventParticipant eventParticipant = (EventParticipant) getActiveFragment().getPrimaryData();
EventParticipantEditFragment fragment = (EventParticipantEditFragment) getActiveFragment();
try {
FragmentValidator.validate(getContext(), fragment.getContentBinding());
} catch (ValidationException e) {
NotificationHelper.showNotification(this, ERROR, e.getMessage());
return;
}
saveTask = new SavingAsyncTask(getRootView(), eventParticipant) {
@Override
protected void onPreExecute() {
showPreloader();
}
@Override
public void doInBackground(TaskResultHolder resultHolder) throws DaoException {
DatabaseHelper.getPersonDao().saveAndSnapshot(eventParticipant.getPerson());
DatabaseHelper.getEventParticipantDao().saveAndSnapshot(eventParticipant);
}
@Override
protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
hidePreloader();
super.onPostExecute(taskResult);
if (taskResult.getResultStatus().isSuccess()) {
finish();
} else {
// reload data
onResume();
}
saveTask = null;
}
}.executeOnThreadPool();
}
use of de.symeda.sormas.app.backend.event.EventParticipant in project SORMAS-Project by hzi-braunschweig.
the class EventParticipantNewActivity method saveData.
@Override
public void saveData() {
if (saveTask != null) {
NotificationHelper.showNotification(this, WARNING, getString(R.string.message_already_saving));
// don't save multiple times
return;
}
final EventParticipant eventParticipantToSave = (EventParticipant) getActiveFragment().getPrimaryData();
EventParticipantNewFragment fragment = (EventParticipantNewFragment) getActiveFragment();
fragment.setLiveValidationDisabled(false);
try {
FragmentValidator.validate(getContext(), fragment.getContentBinding());
} catch (ValidationException e) {
NotificationHelper.showNotification(this, ERROR, e.getMessage());
return;
}
SelectOrCreatePersonDialog.selectOrCreatePerson(eventParticipantToSave.getPerson(), new Consumer<Person>() {
@Override
public void accept(Person person) {
eventParticipantToSave.setPerson(person);
saveTask = new SavingAsyncTask(getRootView(), eventParticipantToSave) {
@Override
protected void onPreExecute() {
showPreloader();
}
@Override
protected void doInBackground(TaskResultHolder resultHolder) throws Exception {
DatabaseHelper.getPersonDao().saveAndSnapshot(eventParticipantToSave.getPerson());
final Event event = DatabaseHelper.getEventDao().queryUuid(eventUuid);
eventParticipantToSave.setEvent(event);
DatabaseHelper.getEventParticipantDao().saveAndSnapshot(eventParticipantToSave);
}
@Override
protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
hidePreloader();
super.onPostExecute(taskResult);
if (taskResult.getResultStatus().isSuccess()) {
EventParticipantEditActivity.startActivity(getContext(), getRootUuid(), eventUuid, EventParticipantSection.EVENT_PARTICIPANT_INFO);
}
saveTask = null;
}
}.executeOnThreadPool();
}
});
}
use of de.symeda.sormas.app.backend.event.EventParticipant in project SORMAS-Project by hzi-braunschweig.
the class EventReadPersonsInvolvedListFragment method onListItemClick.
@Override
public void onListItemClick(View view, int position, Object item) {
EventParticipant participant = (EventParticipant) item;
EventParticipantReadActivity.startActivity(getContext(), participant.getUuid(), getActivityRootData().getUuid());
}
use of de.symeda.sormas.app.backend.event.EventParticipant in project SORMAS-Project by hzi-braunschweig.
the class AbstractAdoDaoTest method testQueryForNew.
@Test
public void testQueryForNew() throws DaoException {
CaseDao caseDao = DatabaseHelper.getCaseDao();
// Case with change date 0 should be included
Case caseChangeDate0 = TestEntityCreator.createCase();
List<Case> newCases = caseDao.queryForNew();
assertEquals(1, newCases.size());
// Case with newer change date should not be included
Case caseNewChangeDate = TestEntityCreator.createCase();
caseNewChangeDate.setChangeDate(new Date());
caseDao.saveAndSnapshot(caseNewChangeDate);
newCases = caseDao.queryForNew();
assertEquals(1, newCases.size());
// Additional tests for other entities
Contact contact = TestEntityCreator.createContact(caseChangeDate0);
Visit visit = TestEntityCreator.createVisit(contact);
Sample sample = TestEntityCreator.createSample(caseChangeDate0);
Event event = TestEntityCreator.createEvent();
EventParticipant eventParticipant = TestEntityCreator.createEventParticipant(event);
assertEquals(1, DatabaseHelper.getContactDao().queryForNew().size());
assertEquals(1, DatabaseHelper.getVisitDao().queryForNew().size());
assertEquals(1, DatabaseHelper.getSampleDao().queryForNew().size());
assertEquals(1, DatabaseHelper.getEventDao().queryForNew().size());
assertEquals(1, DatabaseHelper.getEventParticipantDao().queryForNew().size());
}
Aggregations