Search in sources :

Example 1 with CampaignFormDataDto

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;
}
Also used : CampaignFormDataDto(de.symeda.sormas.api.campaign.data.CampaignFormDataDto)

Example 2 with CampaignFormDataDto

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;
}
Also used : InvalidValueException(com.vaadin.v7.data.Validator.InvalidValueException) CampaignFormDataDto(de.symeda.sormas.api.campaign.data.CampaignFormDataDto) UserDto(de.symeda.sormas.api.user.UserDto) CampaignFormDataEditForm(de.symeda.sormas.ui.campaign.campaigndata.CampaignFormDataEditForm) CommitDiscardWrapperComponent(de.symeda.sormas.ui.utils.CommitDiscardWrapperComponent)

Example 3 with CampaignFormDataDto

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;
}
Also used : CampaignFormDataDto(de.symeda.sormas.api.campaign.data.CampaignFormDataDto)

Example 4 with CampaignFormDataDto

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);
    }
}
Also used : CampaignFormDataDto(de.symeda.sormas.api.campaign.data.CampaignFormDataDto) CampaignFormMetaReferenceDto(de.symeda.sormas.api.campaign.form.CampaignFormMetaReferenceDto) CampaignFormDataEntry(de.symeda.sormas.api.campaign.data.CampaignFormDataEntry) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) CampaignReferenceDto(de.symeda.sormas.api.campaign.CampaignReferenceDto)

Example 5 with CampaignFormDataDto

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;
}
Also used : CampaignFormDataDto(de.symeda.sormas.api.campaign.data.CampaignFormDataDto)

Aggregations

CampaignFormDataDto (de.symeda.sormas.api.campaign.data.CampaignFormDataDto)8 CampaignReferenceDto (de.symeda.sormas.api.campaign.CampaignReferenceDto)2 CampaignFormDataCriteria (de.symeda.sormas.api.campaign.data.CampaignFormDataCriteria)2 CampaignFormDataEntry (de.symeda.sormas.api.campaign.data.CampaignFormDataEntry)2 CampaignFormMetaReferenceDto (de.symeda.sormas.api.campaign.form.CampaignFormMetaReferenceDto)2 ImportErrorException (de.symeda.sormas.api.importexport.ImportErrorException)2 InvalidColumnException (de.symeda.sormas.api.importexport.InvalidColumnException)2 UserDto (de.symeda.sormas.api.user.UserDto)2 ValidationRuntimeException (de.symeda.sormas.api.utils.ValidationRuntimeException)2 IOException (java.io.IOException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 CsvValidationException (com.opencsv.exceptions.CsvValidationException)1 Sizeable (com.vaadin.server.Sizeable)1 StreamResource (com.vaadin.server.StreamResource)1 UI (com.vaadin.ui.UI)1 Window (com.vaadin.ui.Window)1 InvalidValueException (com.vaadin.v7.data.Validator.InvalidValueException)1 FacadeProvider (de.symeda.sormas.api.FacadeProvider)1 CampaignFormElement (de.symeda.sormas.api.campaign.form.CampaignFormElement)1 CampaignFormElementType (de.symeda.sormas.api.campaign.form.CampaignFormElementType)1