use of de.symeda.sormas.api.campaign.data.CampaignFormDataDto in project SORMAS-Project by hzi-braunschweig.
the class CampaignFormDataEditForm method getValue.
@Override
public CampaignFormDataDto getValue() {
CampaignFormDataDto value = super.getValue();
if (campaignFormBuilder == null) {
throw new RuntimeException("Campaign form builder has not been initialized");
}
value.setFormValues(campaignFormBuilder.getFormValues());
return value;
}
use of de.symeda.sormas.api.campaign.data.CampaignFormDataDto in project SORMAS-Project by hzi-braunschweig.
the class CampaignController method getCampaignFormDataComponent.
public CommitDiscardWrapperComponent<CampaignFormDataEditForm> getCampaignFormDataComponent(CampaignFormDataDto campaignFormData, CampaignReferenceDto campaign, CampaignFormMetaReferenceDto campaignForm, boolean revertFormOnDiscard, boolean showDeleteButton, Runnable commitCallback, Runnable discardCallback) {
CampaignFormDataEditForm form = new CampaignFormDataEditForm(campaignFormData == null);
if (campaignFormData == null) {
final UserDto currentUser = UserProvider.getCurrent().getUser();
campaignFormData = CampaignFormDataDto.build(campaign, campaignForm, currentUser.getRegion(), currentUser.getDistrict(), currentUser.getCommunity());
campaignFormData.setCreatingUser(UserProvider.getCurrent().getUserReference());
}
form.setValue(campaignFormData);
final CommitDiscardWrapperComponent<CampaignFormDataEditForm> component = new CommitDiscardWrapperComponent<>(form, form.getFieldGroup());
component.addCommitListener(() -> {
if (!form.getFieldGroup().isModified()) {
try {
form.validate();
} catch (InvalidValueException e) {
Notification.show(I18nProperties.getValidationError(Validations.errorsInForm), Type.ERROR_MESSAGE);
return;
}
CampaignFormDataDto formData = form.getValue();
FacadeProvider.getCampaignFormDataFacade().saveCampaignFormData(formData);
if (commitCallback != null) {
commitCallback.run();
UI.getCurrent().getNavigator().navigateTo(CampaignDataView.VIEW_NAME + "/?" + CAMPAIGN + "=" + campaign.getUuid());
}
}
});
component.addDiscardListener(() -> UI.getCurrent().getNavigator().navigateTo(CampaignDataView.VIEW_NAME + "/?" + CAMPAIGN + "=" + campaign.getUuid()));
if (revertFormOnDiscard) {
component.addDiscardListener(form::resetFormValues);
}
if (discardCallback != null) {
component.addDiscardListener(discardCallback::run);
}
if (showDeleteButton && UserProvider.getCurrent().hasUserRight(UserRight.CAMPAIGN_DELETE)) {
String campaignFormDataUuid = campaignFormData.getUuid();
component.addDeleteListener(() -> {
FacadeProvider.getCampaignFormDataFacade().deleteCampaignFormData(campaignFormDataUuid);
UI.getCurrent().getNavigator().navigateTo(CampaignFormDataView.VIEW_NAME);
}, I18nProperties.getString(Strings.entityCampaignDataForm));
}
return component;
}
use of de.symeda.sormas.api.campaign.data.CampaignFormDataDto in project SORMAS-Project by hzi-braunschweig.
the class CampaignFormDataFacadeEjb method toDto.
public CampaignFormDataDto toDto(CampaignFormData source) {
if (source == null) {
return null;
}
CampaignFormDataDto target = new CampaignFormDataDto();
DtoHelper.fillDto(target, source);
target.setFormValues(source.getFormValues());
target.setCampaign(CampaignFacadeEjb.toReferenceDto(source.getCampaign()));
target.setCampaignFormMeta(CampaignFormMetaFacadeEjb.toReferenceDto(source.getCampaignFormMeta()));
target.setFormDate(source.getFormDate());
target.setRegion(RegionFacadeEjb.toReferenceDto(source.getRegion()));
target.setDistrict(DistrictFacadeEjb.toReferenceDto(source.getDistrict()));
target.setCommunity(CommunityFacadeEjb.toReferenceDto(source.getCommunity()));
target.setCreatingUser(UserFacadeEjb.toReferenceDto(source.getCreatingUser()));
return target;
}
use of de.symeda.sormas.api.campaign.data.CampaignFormDataDto in project SORMAS-Project by hzi-braunschweig.
the class TestDataCreator method buildCampaignFormDataDto.
public CampaignFormDataDto buildCampaignFormDataDto(CampaignDto campaign, CampaignFormMetaDto campaignForm, RDCF rdcf, String formData) {
CampaignReferenceDto campaignReferenceDto = new CampaignReferenceDto(campaign.getUuid());
CampaignFormMetaReferenceDto campaignFormMetaReferenceDto = new CampaignFormMetaReferenceDto(campaignForm.getUuid());
CampaignFormDataDto campaignFormData = CampaignFormDataDto.build(campaignReferenceDto, campaignFormMetaReferenceDto, rdcf.region, rdcf.district, rdcf.community);
try {
ObjectMapper mapper = new ObjectMapper();
campaignFormData.setFormValues(Arrays.asList(mapper.readValue(formData, CampaignFormDataEntry[].class)));
return campaignFormData;
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of de.symeda.sormas.api.campaign.data.CampaignFormDataDto in project SORMAS-Project by hzi-braunschweig.
the class TestDataCreator method createCampaignFormData.
public CampaignFormDataDto createCampaignFormData(CampaignDto campaign, CampaignFormMetaDto campaignForm, RDCF rdcf, String formData) {
CampaignFormDataDto campaignFormData = buildCampaignFormDataDto(campaign, campaignForm, rdcf, formData);
campaignFormData = beanTest.getCampaignFormDataFacade().saveCampaignFormData(campaignFormData);
return campaignFormData;
}
Aggregations