use of de.symeda.sormas.api.campaign.data.CampaignFormDataEntry in project SORMAS-Project by hzi-braunschweig.
the class CampaignStatisticsService method getCampaignStatistics.
public List<CampaignStatisticsDto> getCampaignStatistics(CampaignStatisticsCriteria criteria) {
Query campaignsStatisticsQuery = em.createNativeQuery(buildStatisticsQuery(criteria));
final CampaignJurisdictionLevel groupingLevel = criteria.getGroupingLevel();
Map<CampaignStatisticsGroupingDto, CampaignStatisticsDto> results = new LinkedHashMap<>();
((Stream<Object[]>) campaignsStatisticsQuery.getResultStream()).forEach(result -> {
CampaignStatisticsGroupingDto campaignStatisticsGroupingDto = new CampaignStatisticsGroupingDto((String) result[1], (String) result[2], (String) result[3], shouldIncludeRegion(groupingLevel) ? (String) result[4] : "", shouldIncludeDistrict(groupingLevel) ? (String) result[5] : "", shouldIncludeCommunity(groupingLevel) ? (String) result[6] : "");
if (!results.containsKey(campaignStatisticsGroupingDto)) {
CampaignStatisticsDto campaignStatisticsDto = new CampaignStatisticsDto(campaignStatisticsGroupingDto, result[0] != null ? ((Number) result[0]).intValue() : null);
results.put(campaignStatisticsGroupingDto, campaignStatisticsDto);
}
int length = result.length;
CampaignFormDataEntry campaignFormDataEntry = new CampaignFormDataEntry((String) result[length - 2], result[length - 1]);
results.get(campaignStatisticsGroupingDto).addStatisticsData(campaignFormDataEntry);
});
return results.values().stream().collect(Collectors.toList());
}
use of de.symeda.sormas.api.campaign.data.CampaignFormDataEntry in project SORMAS-Project by hzi-braunschweig.
the class CampaignFormDataEditActivity 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 CampaignFormData campaignFormDataToSave = getStoredRootEntity();
try {
FragmentValidator.validate(getContext(), getActiveFragment().getContentBinding());
} catch (ValidationException e) {
NotificationHelper.showNotification(this, ERROR, e.getMessage());
return;
}
final List<CampaignFormDataEntry> formValues = campaignFormDataToSave.getFormValues();
final List<CampaignFormDataEntry> filledFormValues = new ArrayList<>();
formValues.forEach(campaignFormDataEntry -> {
if (campaignFormDataEntry.getId() != null && campaignFormDataEntry.getValue() != null) {
filledFormValues.add(campaignFormDataEntry);
}
});
campaignFormDataToSave.setFormValues(filledFormValues);
saveTask = new SavingAsyncTask(getRootView(), campaignFormDataToSave) {
@Override
public void doInBackground(TaskResultHolder resultHolder) throws DaoException {
DatabaseHelper.getCampaignFormDataDao().saveAndSnapshot(campaignFormDataToSave);
}
@Override
protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
super.onPostExecute(taskResult);
if (taskResult.getResultStatus().isSuccess()) {
finish();
} else {
// reload data
onResume();
}
saveTask = null;
}
}.executeOnThreadPool();
}
use of de.symeda.sormas.api.campaign.data.CampaignFormDataEntry in project SORMAS-Project by hzi-braunschweig.
the class CampaignFormDataNewActivity 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 CampaignFormData campaignFormDataToSave = getStoredRootEntity();
try {
FragmentValidator.validate(getContext(), getActiveFragment().getContentBinding());
} catch (ValidationException e) {
NotificationHelper.showNotification(this, ERROR, e.getMessage());
return;
}
final List<CampaignFormDataEntry> formValues = campaignFormDataToSave.getFormValues();
final List<CampaignFormDataEntry> filledFormValues = new ArrayList<>();
formValues.forEach(campaignFormDataEntry -> {
if (campaignFormDataEntry.getId() != null && campaignFormDataEntry.getValue() != null) {
filledFormValues.add(campaignFormDataEntry);
}
});
campaignFormDataToSave.setFormValues(filledFormValues);
CampaignFormDataNewFragment activeFragment = (CampaignFormDataNewFragment) getActiveFragment();
activeFragment.setLiveValidationDisabled(true);
saveTask = new SavingAsyncTask(getRootView(), campaignFormDataToSave) {
@Override
public void doInBackground(TaskResultHolder resultHolder) throws DaoException {
DatabaseHelper.getCampaignFormDataDao().saveAndSnapshot(campaignFormDataToSave);
}
@Override
protected void onPostExecute(AsyncTaskResult<TaskResultHolder> taskResult) {
hidePreloader();
super.onPostExecute(taskResult);
if (taskResult.getResultStatus().isSuccess()) {
finish();
CampaignFormDataEditActivity.startActivity(getContext(), campaignFormDataToSave.getUuid());
}
saveTask = null;
}
}.executeOnThreadPool();
}
use of de.symeda.sormas.api.campaign.data.CampaignFormDataEntry in project SORMAS-Project by hzi-braunschweig.
the class ExpressionProcessorTest method setup.
@Before
public void setup() throws IOException {
GridLayout campaignFormLayout = new GridLayout(12, 1);
ObjectMapper objectMapper = new ObjectMapper();
List<CampaignFormElement> campaignFormElements = createData(objectMapper, this.getClass().getResourceAsStream("/campaign/expressions/formelements.json"), CampaignFormElement.class);
List<CampaignFormDataEntry> campaignFormDataEntries = createData(objectMapper, this.getClass().getResourceAsStream("/campaign/expressions/formvalues.json"), CampaignFormDataEntry.class);
campaignFormBuilder = new CampaignFormBuilder(campaignFormElements, campaignFormDataEntries, campaignFormLayout, Collections.emptyList());
campaignFormBuilder.buildForm();
expressionProcessor = new ExpressionProcessor(campaignFormBuilder);
}
use of de.symeda.sormas.api.campaign.data.CampaignFormDataEntry in project SORMAS-Project by hzi-braunschweig.
the class CampaignFormDataFragmentUtils method getOrCreateCampaignFormDataEntry.
public static CampaignFormDataEntry getOrCreateCampaignFormDataEntry(List<CampaignFormDataEntry> formValues, CampaignFormElement campaignFormElement) {
for (CampaignFormDataEntry campaignFormDataEntry : formValues) {
if (campaignFormDataEntry.getId().equals(campaignFormElement.getId())) {
return campaignFormDataEntry;
}
}
final CampaignFormDataEntry newCampaignFomDataEntry = new CampaignFormDataEntry(campaignFormElement.getId(), null);
formValues.add(newCampaignFomDataEntry);
return newCampaignFomDataEntry;
}
Aggregations