Search in sources :

Example 1 with ContinentReferenceDto

use of de.symeda.sormas.api.infrastructure.continent.ContinentReferenceDto in project SORMAS-Project by hzi-braunschweig.

the class DataImporter method executeDefaultInvoke.

/**
 * Contains checks for the most common data types for entries in the import file. This method should be called
 * in every subclass whenever data from the import file is supposed to be written to the entity in question.
 * Additional invokes need to be executed manually in the subclass.
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
protected boolean executeDefaultInvoke(PropertyDescriptor pd, Object element, String entry, String[] entryHeaderPath) throws InvocationTargetException, IllegalAccessException, ImportErrorException {
    Class<?> propertyType = pd.getPropertyType();
    if (propertyType.isEnum()) {
        Enum enumValue = null;
        Class<Enum> enumType = (Class<Enum>) propertyType;
        try {
            enumValue = Enum.valueOf(enumType, entry.toUpperCase());
        } catch (IllegalArgumentException e) {
        // ignore
        }
        if (enumValue == null) {
            enumValue = enumCaptionCache.getEnumByCaption(enumType, entry);
        }
        pd.getWriteMethod().invoke(element, enumValue);
        return true;
    }
    if (propertyType.isAssignableFrom(Date.class)) {
        String dateFormat = I18nProperties.getUserLanguage().getDateFormat();
        try {
            pd.getWriteMethod().invoke(element, DateHelper.parseDateWithException(entry, dateFormat));
            return true;
        } catch (ParseException e) {
            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importInvalidDate, pd.getName(), DateHelper.getAllowedDateFormats(dateFormat)));
        }
    }
    if (propertyType.isAssignableFrom(Integer.class)) {
        pd.getWriteMethod().invoke(element, Integer.parseInt(entry));
        return true;
    }
    if (propertyType.isAssignableFrom(Double.class)) {
        pd.getWriteMethod().invoke(element, Double.parseDouble(entry));
        return true;
    }
    if (propertyType.isAssignableFrom(Float.class)) {
        pd.getWriteMethod().invoke(element, Float.parseFloat(entry));
        return true;
    }
    if (propertyType.isAssignableFrom(Boolean.class) || propertyType.isAssignableFrom(boolean.class)) {
        pd.getWriteMethod().invoke(element, DataHelper.parseBoolean(entry));
        return true;
    }
    if (propertyType.isAssignableFrom(AreaReferenceDto.class)) {
        List<AreaReferenceDto> areas = FacadeProvider.getAreaFacade().getByName(entry, false);
        if (areas.isEmpty()) {
            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExist, entry, buildEntityProperty(entryHeaderPath)));
        } else if (areas.size() > 1) {
            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importAreaNotUnique, entry, buildEntityProperty(entryHeaderPath)));
        } else {
            pd.getWriteMethod().invoke(element, areas.get(0));
            return true;
        }
    }
    if (propertyType.isAssignableFrom(SubcontinentReferenceDto.class)) {
        List<SubcontinentReferenceDto> subcontinents = FacadeProvider.getSubcontinentFacade().getByDefaultName(entry, false);
        if (subcontinents.isEmpty()) {
            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExist, entry, buildEntityProperty(entryHeaderPath)));
        } else if (subcontinents.size() > 1) {
            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importSubcontinentNotUnique, entry, buildEntityProperty(entryHeaderPath)));
        } else {
            pd.getWriteMethod().invoke(element, subcontinents.get(0));
            return true;
        }
    }
    if (propertyType.isAssignableFrom(CountryReferenceDto.class)) {
        List<CountryReferenceDto> countries = FacadeProvider.getCountryFacade().getByDefaultName(entry, false);
        if (countries.isEmpty()) {
            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExist, entry, buildEntityProperty(entryHeaderPath)));
        } else if (countries.size() > 1) {
            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importSubcontinentNotUnique, entry, buildEntityProperty(entryHeaderPath)));
        } else {
            pd.getWriteMethod().invoke(element, countries.get(0));
            return true;
        }
    }
    if (propertyType.isAssignableFrom(ContinentReferenceDto.class)) {
        List<ContinentReferenceDto> continents = FacadeProvider.getContinentFacade().getByDefaultName(entry, false);
        if (continents.isEmpty()) {
            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExist, entry, buildEntityProperty(entryHeaderPath)));
        } else if (continents.size() > 1) {
            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importSubcontinentNotUnique, entry, buildEntityProperty(entryHeaderPath)));
        } else {
            pd.getWriteMethod().invoke(element, continents.get(0));
            return true;
        }
    }
    if (propertyType.isAssignableFrom(RegionReferenceDto.class)) {
        List<RegionDto> regions = FacadeProvider.getRegionFacade().getByName(entry, false);
        if (regions.isEmpty()) {
            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExist, entry, buildEntityProperty(entryHeaderPath)));
        } else if (regions.size() > 1) {
            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importRegionNotUnique, entry, buildEntityProperty(entryHeaderPath)));
        } else {
            RegionDto region = regions.get(0);
            CountryReferenceDto serverCountry = FacadeProvider.getCountryFacade().getServerCountry();
            if (region.getCountry() != null && !region.getCountry().equals(serverCountry)) {
                throw new ImportErrorException(I18nProperties.getValidationError(Validations.importRegionNotInServerCountry, entry, buildEntityProperty(entryHeaderPath)));
            } else {
                pd.getWriteMethod().invoke(element, region.toReference());
                return true;
            }
        }
    }
    if (propertyType.isAssignableFrom(UserReferenceDto.class)) {
        UserDto user = FacadeProvider.getUserFacade().getByUserName(entry);
        if (user != null) {
            pd.getWriteMethod().invoke(element, user.toReference());
            return true;
        } else {
            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExist, entry, buildEntityProperty(entryHeaderPath)));
        }
    }
    if (propertyType.isAssignableFrom(String.class)) {
        pd.getWriteMethod().invoke(element, entry);
        return true;
    }
    return false;
}
Also used : ImportErrorException(de.symeda.sormas.api.importexport.ImportErrorException) SubcontinentReferenceDto(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentReferenceDto) UserDto(de.symeda.sormas.api.user.UserDto) RegionDto(de.symeda.sormas.api.infrastructure.region.RegionDto) CountryReferenceDto(de.symeda.sormas.api.infrastructure.country.CountryReferenceDto) ContinentReferenceDto(de.symeda.sormas.api.infrastructure.continent.ContinentReferenceDto) AreaReferenceDto(de.symeda.sormas.api.infrastructure.area.AreaReferenceDto) ParseException(java.text.ParseException)

Example 2 with ContinentReferenceDto

use of de.symeda.sormas.api.infrastructure.continent.ContinentReferenceDto in project SORMAS-Project by hzi-braunschweig.

the class LocationEditForm method addFields.

@SuppressWarnings("deprecation")
@Override
protected void addFields() {
    addressType = addField(LocationDto.ADDRESS_TYPE, ComboBox.class);
    addressType.setVisible(false);
    final PersonAddressType[] personAddressTypeValues = PersonAddressType.getValues(FacadeProvider.getConfigFacade().getCountryCode());
    if (!isConfiguredServer("ch")) {
        addressType.removeAllItems();
        addressType.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ID);
        addressType.addItems(personAddressTypeValues);
    }
    TextField addressTypeDetails = addField(LocationDto.ADDRESS_TYPE_DETAILS, TextField.class);
    addressTypeDetails.setVisible(false);
    FieldHelper.setVisibleWhen(getFieldGroup(), LocationDto.ADDRESS_TYPE_DETAILS, addressType, Arrays.stream(personAddressTypeValues).filter(pat -> !pat.equals(PersonAddressType.HOME)).collect(Collectors.toList()), true);
    FieldHelper.setRequiredWhen(getFieldGroup(), addressType, Arrays.asList(LocationDto.ADDRESS_TYPE_DETAILS), Arrays.asList(PersonAddressType.OTHER_ADDRESS));
    facilityTypeGroup = ComboBoxHelper.createComboBoxV7();
    ;
    facilityTypeGroup.setId("typeGroup");
    facilityTypeGroup.setCaption(I18nProperties.getCaption(Captions.Facility_typeGroup));
    facilityTypeGroup.setWidth(100, Unit.PERCENTAGE);
    facilityTypeGroup.addItems(FacilityTypeGroup.values());
    getContent().addComponent(facilityTypeGroup, FACILITY_TYPE_GROUP_LOC);
    facilityType = addField(LocationDto.FACILITY_TYPE);
    facility = addInfrastructureField(LocationDto.FACILITY);
    facility.setImmediate(true);
    facilityDetails = addField(LocationDto.FACILITY_DETAILS, TextField.class);
    facilityDetails.setVisible(false);
    addressType.addValueChangeListener(e -> {
        FacilityTypeGroup oldGroup = (FacilityTypeGroup) facilityTypeGroup.getValue();
        FacilityType oldType = (FacilityType) facilityType.getValue();
        FacilityReferenceDto oldFacility = (FacilityReferenceDto) facility.getValue();
        String oldDetails = facilityDetails.getValue();
        if (PersonAddressType.HOME.equals(addressType.getValue())) {
            facilityTypeGroup.removeAllItems();
            facilityTypeGroup.addItems(FacilityTypeGroup.getAccomodationGroups());
            setOldFacilityValuesIfPossible(oldGroup, oldType, oldFacility, oldDetails);
        } else {
            facilityTypeGroup.removeAllItems();
            facilityTypeGroup.addItems(FacilityTypeGroup.values());
            setOldFacilityValuesIfPossible(oldGroup, oldType, oldFacility, oldDetails);
        }
    });
    TextField streetField = addField(LocationDto.STREET, TextField.class);
    TextField houseNumberField = addField(LocationDto.HOUSE_NUMBER, TextField.class);
    TextField additionalInformationField = addField(LocationDto.ADDITIONAL_INFORMATION, TextField.class);
    addField(LocationDto.DETAILS, TextField.class);
    TextField cityField = addField(LocationDto.CITY, TextField.class);
    TextField postalCodeField = addField(LocationDto.POSTAL_CODE, TextField.class);
    ComboBox areaType = addField(LocationDto.AREA_TYPE, ComboBox.class);
    areaType.setDescription(I18nProperties.getDescription(getPropertyI18nPrefix() + "." + LocationDto.AREA_TYPE));
    contactPersonFirstName = addField(LocationDto.CONTACT_PERSON_FIRST_NAME, TextField.class);
    contactPersonLastName = addField(LocationDto.CONTACT_PERSON_LAST_NAME, TextField.class);
    contactPersonPhone = addField(LocationDto.CONTACT_PERSON_PHONE, TextField.class);
    contactPersonPhone.addValidator(new PhoneNumberValidator(I18nProperties.getValidationError(Validations.validPhoneNumber, contactPersonPhone.getCaption())));
    contactPersonEmail = addField(LocationDto.CONTACT_PERSON_EMAIL, TextField.class);
    contactPersonEmail.addValidator(new EmailValidator(I18nProperties.getValidationError(Validations.validEmailAddress, contactPersonEmail.getCaption())));
    final AccessibleTextField tfLatitude = addField(LocationDto.LATITUDE, AccessibleTextField.class);
    final AccessibleTextField tfLongitude = addField(LocationDto.LONGITUDE, AccessibleTextField.class);
    final AccessibleTextField tfAccuracy = addField(LocationDto.LAT_LON_ACCURACY, AccessibleTextField.class);
    final StringToAngularLocationConverter stringToAngularLocationConverter = new StringToAngularLocationConverter();
    tfLatitude.setConverter(stringToAngularLocationConverter);
    tfLongitude.setConverter(stringToAngularLocationConverter);
    tfAccuracy.setConverter(stringToAngularLocationConverter);
    continent = addInfrastructureField(LocationDto.CONTINENT);
    subcontinent = addInfrastructureField(LocationDto.SUB_CONTINENT);
    country = addInfrastructureField(LocationDto.COUNTRY);
    ComboBox region = addInfrastructureField(LocationDto.REGION);
    ComboBox district = addInfrastructureField(LocationDto.DISTRICT);
    ComboBox community = addInfrastructureField(LocationDto.COMMUNITY);
    continent.setVisible(false);
    subcontinent.setVisible(false);
    initializeVisibilitiesAndAllowedVisibilities();
    initializeAccessAndAllowedAccesses();
    if (!isEditableAllowed(LocationDto.COMMUNITY)) {
        setEnabled(false, LocationDto.COUNTRY, LocationDto.REGION, LocationDto.DISTRICT);
    }
    ValueChangeListener continentValueListener = e -> {
        if (continent.isVisible()) {
            ContinentReferenceDto continentReferenceDto = (ContinentReferenceDto) e.getProperty().getValue();
            if (subcontinent.getValue() == null) {
                FieldHelper.updateItems(country, continentReferenceDto != null ? FacadeProvider.getCountryFacade().getAllActiveByContinent(continentReferenceDto.getUuid()) : FacadeProvider.getCountryFacade().getAllActiveAsReference());
                country.setValue(null);
            }
            subcontinent.setValue(null);
            FieldHelper.updateItems(subcontinent, continentReferenceDto != null ? FacadeProvider.getSubcontinentFacade().getAllActiveByContinent(continentReferenceDto.getUuid()) : FacadeProvider.getSubcontinentFacade().getAllActiveAsReference());
        }
    };
    ValueChangeListener subContinentValueListener = e -> {
        if (subcontinent.isVisible()) {
            SubcontinentReferenceDto subcontinentReferenceDto = (SubcontinentReferenceDto) e.getProperty().getValue();
            if (subcontinentReferenceDto != null) {
                continent.removeValueChangeListener(continentValueListener);
                continent.setValue(FacadeProvider.getContinentFacade().getBySubcontinent(subcontinentReferenceDto));
                continent.addValueChangeListener(continentValueListener);
            }
            country.setValue(null);
            ContinentReferenceDto continentValue = (ContinentReferenceDto) continent.getValue();
            FieldHelper.updateItems(country, subcontinentReferenceDto != null ? FacadeProvider.getCountryFacade().getAllActiveBySubcontinent(subcontinentReferenceDto.getUuid()) : continentValue == null ? FacadeProvider.getCountryFacade().getAllActiveAsReference() : FacadeProvider.getCountryFacade().getAllActiveByContinent(continentValue.getUuid()));
        }
    };
    continent.addValueChangeListener(continentValueListener);
    subcontinent.addValueChangeListener(subContinentValueListener);
    skipCountryValueChange = false;
    country.addValueChangeListener(e -> {
        if (!skipCountryValueChange) {
            CountryReferenceDto countryDto = (CountryReferenceDto) e.getProperty().getValue();
            if (countryDto != null) {
                final ContinentReferenceDto countryContinent = FacadeProvider.getContinentFacade().getByCountry(countryDto);
                final SubcontinentReferenceDto countrySubcontinent = FacadeProvider.getSubcontinentFacade().getByCountry(countryDto);
                if (countryContinent != null) {
                    continent.removeValueChangeListener(continentValueListener);
                    if (continent.isVisible()) {
                        skipCountryValueChange = true;
                        FieldHelper.updateItems(country, FacadeProvider.getCountryFacade().getAllActiveByContinent(countryContinent.getUuid()));
                        skipCountryValueChange = false;
                    }
                    continent.setValue(countryContinent);
                    continent.addValueChangeListener(continentValueListener);
                }
                if (countrySubcontinent != null) {
                    subcontinent.removeValueChangeListener(subContinentValueListener);
                    if (subcontinent.isVisible()) {
                        skipCountryValueChange = true;
                        if (countryContinent != null) {
                            FieldHelper.updateItems(subcontinent, FacadeProvider.getSubcontinentFacade().getAllActiveByContinent(countryContinent.getUuid()));
                        }
                        FieldHelper.updateItems(country, FacadeProvider.getCountryFacade().getAllActiveBySubcontinent(countrySubcontinent.getUuid()));
                        skipCountryValueChange = false;
                    }
                    subcontinent.setValue(countrySubcontinent);
                    subcontinent.addValueChangeListener(subContinentValueListener);
                }
            }
        }
    });
    region.addValueChangeListener(e -> {
        RegionReferenceDto regionDto = (RegionReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(district, regionDto != null ? FacadeProvider.getDistrictFacade().getAllActiveByRegion(regionDto.getUuid()) : null);
    });
    district.addValueChangeListener(e -> {
        DistrictReferenceDto districtDto = (DistrictReferenceDto) e.getProperty().getValue();
        FieldHelper.updateItems(community, districtDto != null ? FacadeProvider.getCommunityFacade().getAllActiveByDistrict(districtDto.getUuid()) : null);
        if (districtDto == null) {
            FieldHelper.removeItems(facility);
            // Add a visual indictator reminding the user to select a district
            facility.setComponentError(new ErrorMessage() {

                @Override
                public ErrorLevel getErrorLevel() {
                    return ErrorLevel.INFO;
                }

                @Override
                public String getFormattedHtmlMessage() {
                    return I18nProperties.getString(Strings.infoFacilityNeedsDistrict);
                }
            });
        } else if (facilityType.getValue() != null) {
            facility.setComponentError(null);
            facility.markAsDirty();
            FieldHelper.updateItems(facility, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType(districtDto, (FacilityType) facilityType.getValue(), true, false));
        }
    });
    community.addValueChangeListener(e -> {
        CommunityReferenceDto communityDto = (CommunityReferenceDto) e.getProperty().getValue();
        if (facilityType.getValue() != null) {
            FieldHelper.updateItems(facility, communityDto != null ? FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType(communityDto, (FacilityType) facilityType.getValue(), true, true) : district.getValue() != null ? FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType((DistrictReferenceDto) district.getValue(), (FacilityType) facilityType.getValue(), true, false) : null);
        }
    });
    skipFacilityTypeUpdate = false;
    facilityTypeGroup.addValueChangeListener(e -> {
        if (!skipFacilityTypeUpdate) {
            FieldHelper.removeItems(facility);
            FieldHelper.updateEnumData(facilityType, FacilityType.getTypes((FacilityTypeGroup) facilityTypeGroup.getValue()));
            facilityType.setRequired(facilityTypeGroup.getValue() != null);
        }
    });
    facilityType.addValueChangeListener(e -> {
        FieldHelper.removeItems(facility);
        facility.setComponentError(null);
        facility.markAsDirty();
        if (facilityType.getValue() != null && facilityTypeGroup.getValue() == null) {
            facilityTypeGroup.setValue(((FacilityType) facilityType.getValue()).getFacilityTypeGroup());
        }
        if (facilityType.getValue() != null && district.getValue() != null) {
            if (community.getValue() != null) {
                FieldHelper.updateItems(facility, FacadeProvider.getFacilityFacade().getActiveFacilitiesByCommunityAndType((CommunityReferenceDto) community.getValue(), (FacilityType) facilityType.getValue(), true, false));
            } else {
                FieldHelper.updateItems(facility, FacadeProvider.getFacilityFacade().getActiveFacilitiesByDistrictAndType((DistrictReferenceDto) district.getValue(), (FacilityType) facilityType.getValue(), true, false));
            }
        } else if (facilityType.getValue() != null && district.getValue() == null) {
            // Add a visual indictator reminding the user to select a district
            facility.setComponentError(new ErrorMessage() {

                @Override
                public ErrorLevel getErrorLevel() {
                    return ErrorLevel.INFO;
                }

                @Override
                public String getFormattedHtmlMessage() {
                    return I18nProperties.getString(Strings.infoFacilityNeedsDistrict);
                }
            });
        }
        // Only show contactperson-details if at least a faciltytype has been set
        if (facilityType.getValue() != null) {
            setFacilityContactPersonFieldsVisible(true, true);
        } else {
            setFacilityContactPersonFieldsVisible(false, true);
        }
    });
    facility.addValueChangeListener(e -> {
        if (facility.getValue() != null) {
            boolean visibleAndRequired = areFacilityDetailsRequired();
            facilityDetails.setVisible(visibleAndRequired);
            facilityDetails.setRequired(visibleAndRequired);
            if (!visibleAndRequired) {
                facilityDetails.clear();
            } else {
                String facilityDetailsValue = getValue() != null ? getValue().getFacilityDetails() : null;
                facilityDetails.setValue(facilityDetailsValue);
            }
        } else {
            facilityDetails.setVisible(false);
            facilityDetails.setRequired(false);
            facilityDetails.clear();
        }
        // value because of this field dependencies to other fields and the way updateEnumValues works
        if (facility.isAttached() && !disableFacilityAddressCheck) {
            if (facility.getValue() != null) {
                FacilityDto facilityDto = FacadeProvider.getFacilityFacade().getByUuid(((FacilityReferenceDto) getField(LocationDto.FACILITY).getValue()).getUuid());
                // Only if the facility's address is set
                if (StringUtils.isNotEmpty(facilityDto.getCity()) || StringUtils.isNotEmpty(facilityDto.getPostalCode()) || StringUtils.isNotEmpty(facilityDto.getStreet()) || StringUtils.isNotEmpty(facilityDto.getHouseNumber()) || StringUtils.isNotEmpty(facilityDto.getAdditionalInformation()) || facilityDto.getAreaType() != null || facilityDto.getLatitude() != null || facilityDto.getLongitude() != null || (StringUtils.isNotEmpty(facilityDto.getContactPersonFirstName()) && StringUtils.isNotEmpty(facilityDto.getContactPersonLastName()))) {
                    // Show a confirmation popup if the location's address is already set and different from the facility one
                    if ((StringUtils.isNotEmpty(cityField.getValue()) && !cityField.getValue().equals(facilityDto.getCity())) || (StringUtils.isNotEmpty(postalCodeField.getValue()) && !postalCodeField.getValue().equals(facilityDto.getPostalCode())) || (StringUtils.isNotEmpty(streetField.getValue()) && !streetField.getValue().equals(facilityDto.getStreet())) || (StringUtils.isNotEmpty(houseNumberField.getValue()) && !houseNumberField.getValue().equals(facilityDto.getHouseNumber())) || (StringUtils.isNotEmpty(additionalInformationField.getValue()) && !additionalInformationField.getValue().equals(facilityDto.getAdditionalInformation())) || (areaType.getValue() != null && areaType.getValue() != facilityDto.getAreaType()) || (StringUtils.isNotEmpty(contactPersonFirstName.getValue()) && StringUtils.isNotEmpty(contactPersonLastName.getValue())) || (tfLatitude.getConvertedValue() != null && Double.compare((Double) tfLatitude.getConvertedValue(), facilityDto.getLatitude()) != 0) || (tfLongitude.getConvertedValue() != null && Double.compare((Double) tfLongitude.getConvertedValue(), facilityDto.getLongitude()) != 0)) {
                        VaadinUiUtil.showConfirmationPopup(I18nProperties.getString(Strings.headingLocation), new Label(I18nProperties.getString(Strings.confirmationLocationFacilityAddressOverride)), I18nProperties.getString(Strings.yes), I18nProperties.getString(Strings.no), 640, confirmationEvent -> {
                            if (confirmationEvent) {
                                overrideLocationDetailsWithFacilityOnes(facilityDto);
                            }
                        });
                    } else {
                        overrideLocationDetailsWithFacilityOnes(facilityDto);
                    }
                }
            }
        }
    });
    final List<ContinentReferenceDto> continents = FacadeProvider.getContinentFacade().getAllActiveAsReference();
    if (continents.isEmpty()) {
        continent.setVisible(false);
        continent.clear();
    } else {
        continent.addItems(continents);
    }
    final List<SubcontinentReferenceDto> subcontinents = FacadeProvider.getSubcontinentFacade().getAllActiveAsReference();
    if (subcontinents.isEmpty()) {
        subcontinent.setVisible(false);
        subcontinent.clear();
    } else {
        subcontinent.addItems(subcontinents);
    }
    country.addItems(FacadeProvider.getCountryFacade().getAllActiveAsReference());
    updateRegionCombo(region, country);
    country.addValueChangeListener(e -> {
        updateRegionCombo(region, country);
        region.setValue(null);
    });
    Stream.of(LocationDto.LATITUDE, LocationDto.LONGITUDE).<Field<?>>map(this::getField).forEach(f -> f.addValueChangeListener(e -> this.updateLeafletMapContent()));
    // Set initial visiblity of facility-contactperson-details (should only be visible if at least a facilityType has been selected)
    setFacilityContactPersonFieldsVisible(facilityType.getValue() != null, true);
}
Also used : AbstractEditForm(de.symeda.sormas.ui.utils.AbstractEditForm) Arrays(java.util.Arrays) AbstractField(com.vaadin.v7.ui.AbstractField) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) Alignment(com.vaadin.ui.Alignment) InfrastructureFieldsHelper(de.symeda.sormas.ui.utils.InfrastructureFieldsHelper) LeafletMarker(de.symeda.sormas.ui.map.LeafletMarker) StringUtils(org.apache.commons.lang3.StringUtils) CountryReferenceDto(de.symeda.sormas.api.infrastructure.country.CountryReferenceDto) CssStyles(de.symeda.sormas.ui.utils.CssStyles) GeoLatLon(de.symeda.sormas.api.geo.GeoLatLon) VaadinIcons(com.vaadin.icons.VaadinIcons) ComboBoxHelper(de.symeda.sormas.ui.utils.ComboBoxHelper) LeafletMap(de.symeda.sormas.ui.map.LeafletMap) LayoutUtil.fluidRow(de.symeda.sormas.ui.utils.LayoutUtil.fluidRow) ValoTheme(com.vaadin.ui.themes.ValoTheme) LayoutUtil.divs(de.symeda.sormas.ui.utils.LayoutUtil.divs) PopupView(com.vaadin.ui.PopupView) ComboBox(com.vaadin.v7.ui.ComboBox) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType) Field(com.vaadin.v7.ui.Field) FieldHelper(de.symeda.sormas.ui.utils.FieldHelper) Collectors(java.util.stream.Collectors) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) List(java.util.List) PersonAddressType(de.symeda.sormas.api.person.PersonAddressType) Stream(java.util.stream.Stream) LayoutUtil.fluidColumnLoc(de.symeda.sormas.ui.utils.LayoutUtil.fluidColumnLoc) TextField(com.vaadin.v7.ui.TextField) AbstractSelect(com.vaadin.v7.ui.AbstractSelect) SubcontinentReferenceDto(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentReferenceDto) UiFieldAccessCheckers(de.symeda.sormas.api.utils.fieldaccess.UiFieldAccessCheckers) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) VaadinUiUtil(de.symeda.sormas.ui.utils.VaadinUiUtil) FacadeProvider(de.symeda.sormas.api.FacadeProvider) EntityRelevanceStatus(de.symeda.sormas.api.EntityRelevanceStatus) ContinentCriteria(de.symeda.sormas.api.infrastructure.continent.ContinentCriteria) ErrorLevel(com.vaadin.shared.ui.ErrorLevel) CustomLayout(com.vaadin.ui.CustomLayout) EmailValidator(com.vaadin.v7.data.validator.EmailValidator) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Label(com.vaadin.ui.Label) LayoutUtil.fluidRowLocs(de.symeda.sormas.ui.utils.LayoutUtil.fluidRowLocs) ButtonHelper(de.symeda.sormas.ui.utils.ButtonHelper) LocationDto(de.symeda.sormas.api.location.LocationDto) ContentMode(com.vaadin.shared.ui.ContentMode) Validations(de.symeda.sormas.api.i18n.Validations) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) ErrorMessage(com.vaadin.server.ErrorMessage) Captions(de.symeda.sormas.api.i18n.Captions) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) Button(com.vaadin.ui.Button) MarkerIcon(de.symeda.sormas.ui.map.MarkerIcon) HorizontalLayout(com.vaadin.ui.HorizontalLayout) SubcontinentCriteria(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentCriteria) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) StringToAngularLocationConverter(de.symeda.sormas.ui.utils.StringToAngularLocationConverter) PhoneNumberValidator(de.symeda.sormas.ui.utils.PhoneNumberValidator) FieldVisibilityCheckers(de.symeda.sormas.api.utils.fieldvisibility.FieldVisibilityCheckers) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) ContinentReferenceDto(de.symeda.sormas.api.infrastructure.continent.ContinentReferenceDto) Component(com.vaadin.ui.Component) EmailValidator(com.vaadin.v7.data.validator.EmailValidator) FacilityReferenceDto(de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto) PhoneNumberValidator(de.symeda.sormas.ui.utils.PhoneNumberValidator) Label(com.vaadin.ui.Label) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) StringToAngularLocationConverter(de.symeda.sormas.ui.utils.StringToAngularLocationConverter) TextField(com.vaadin.v7.ui.TextField) SubcontinentReferenceDto(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentReferenceDto) ComboBox(com.vaadin.v7.ui.ComboBox) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) RegionReferenceDto(de.symeda.sormas.api.infrastructure.region.RegionReferenceDto) PersonAddressType(de.symeda.sormas.api.person.PersonAddressType) CountryReferenceDto(de.symeda.sormas.api.infrastructure.country.CountryReferenceDto) ContinentReferenceDto(de.symeda.sormas.api.infrastructure.continent.ContinentReferenceDto) ErrorLevel(com.vaadin.shared.ui.ErrorLevel) FacilityTypeGroup(de.symeda.sormas.api.infrastructure.facility.FacilityTypeGroup) ErrorMessage(com.vaadin.server.ErrorMessage) FacilityType(de.symeda.sormas.api.infrastructure.facility.FacilityType)

Example 3 with ContinentReferenceDto

use of de.symeda.sormas.api.infrastructure.continent.ContinentReferenceDto in project SORMAS-Project by hzi-braunschweig.

the class SubcontinentsView method createFilterBar.

private HorizontalLayout createFilterBar() {
    filterLayout = new HorizontalLayout();
    filterLayout.setMargin(false);
    filterLayout.setSpacing(true);
    filterLayout.setWidth(100, Unit.PERCENTAGE);
    searchField = new SearchField();
    searchField.addTextChangeListener(e -> {
        criteria.nameLike(e.getText());
        grid.reload();
    });
    filterLayout.addComponent(searchField);
    continentFilter = ComboBoxHelper.createComboBoxV7();
    continentFilter.setId(SubcontinentDto.CONTINENT);
    continentFilter.setWidth(140, Unit.PIXELS);
    continentFilter.setCaption(I18nProperties.getPrefixCaption(SubcontinentDto.I18N_PREFIX, SubcontinentDto.CONTINENT));
    continentFilter.addItems(FacadeProvider.getContinentFacade().getAllActiveAsReference());
    continentFilter.addValueChangeListener(e -> {
        criteria.continent((ContinentReferenceDto) e.getProperty().getValue());
        navigateTo(criteria);
    });
    filterLayout.addComponent(continentFilter);
    resetButton = ButtonHelper.createButton(Captions.actionResetFilters, event -> {
        ViewModelProviders.of(SubcontinentsView.class).remove(SubcontinentCriteria.class);
        navigateTo(null);
    }, CssStyles.FORCE_CAPTION);
    resetButton.setVisible(false);
    filterLayout.addComponent(resetButton);
    HorizontalLayout actionButtonsLayout = new HorizontalLayout();
    actionButtonsLayout.setSpacing(true);
    {
        // Show active/archived/all dropdown
        if (UserProvider.getCurrent().hasUserRight(UserRight.INFRASTRUCTURE_VIEW)) {
            relevanceStatusFilter = ComboBoxHelper.createComboBoxV7();
            relevanceStatusFilter.setId("relevanceStatus");
            relevanceStatusFilter.setWidth(220, Unit.PERCENTAGE);
            relevanceStatusFilter.setNullSelectionAllowed(false);
            relevanceStatusFilter.addItems((Object[]) EntityRelevanceStatus.values());
            relevanceStatusFilter.setItemCaption(EntityRelevanceStatus.ACTIVE, I18nProperties.getCaption(Captions.subcontinentActiveSubcontinents));
            relevanceStatusFilter.setItemCaption(EntityRelevanceStatus.ARCHIVED, I18nProperties.getCaption(Captions.subcontinentArchivedSubcontinents));
            relevanceStatusFilter.setItemCaption(EntityRelevanceStatus.ALL, I18nProperties.getCaption(Captions.subcontinentAllSubcontinents));
            relevanceStatusFilter.addValueChangeListener(e -> {
                criteria.relevanceStatus((EntityRelevanceStatus) e.getProperty().getValue());
                navigateTo(criteria);
            });
            actionButtonsLayout.addComponent(relevanceStatusFilter);
            // Bulk operation dropdown
            if (UserProvider.getCurrent().hasUserRight(UserRight.PERFORM_BULK_OPERATIONS)) {
                bulkOperationsDropdown = MenuBarHelper.createDropDown(Captions.bulkActions, new MenuBarHelper.MenuBarItem(I18nProperties.getCaption(Captions.actionArchive), VaadinIcons.ARCHIVE, selectedItem -> {
                    ControllerProvider.getInfrastructureController().archiveOrDearchiveAllSelectedItems(true, grid.asMultiSelect().getSelectedItems(), InfrastructureType.SUBCONTINENT, () -> navigateTo(criteria));
                }, EntityRelevanceStatus.ACTIVE.equals(criteria.getRelevanceStatus())), new MenuBarHelper.MenuBarItem(I18nProperties.getCaption(Captions.actionDearchive), VaadinIcons.ARCHIVE, selectedItem -> {
                    ControllerProvider.getInfrastructureController().archiveOrDearchiveAllSelectedItems(false, grid.asMultiSelect().getSelectedItems(), InfrastructureType.SUBCONTINENT, () -> navigateTo(criteria));
                }, EntityRelevanceStatus.ARCHIVED.equals(criteria.getRelevanceStatus())));
                bulkOperationsDropdown.setVisible(isBulkOperationsDropdownVisible());
                actionButtonsLayout.addComponent(bulkOperationsDropdown);
            }
        }
    }
    filterLayout.addComponent(actionButtonsLayout);
    filterLayout.setComponentAlignment(actionButtonsLayout, Alignment.BOTTOM_RIGHT);
    filterLayout.setExpandRatio(actionButtonsLayout, 1);
    return filterLayout;
}
Also used : FeatureType(de.symeda.sormas.api.feature.FeatureType) RowCount(de.symeda.sormas.ui.utils.RowCount) StreamResource(com.vaadin.server.StreamResource) SearchField(de.symeda.sormas.ui.configuration.infrastructure.components.SearchField) VaadinUiUtil(de.symeda.sormas.ui.utils.VaadinUiUtil) FacadeProvider(de.symeda.sormas.api.FacadeProvider) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) VerticalLayout(com.vaadin.ui.VerticalLayout) Alignment(com.vaadin.ui.Alignment) GridExportStreamResource(de.symeda.sormas.ui.utils.GridExportStreamResource) Window(com.vaadin.ui.Window) EntityRelevanceStatus(de.symeda.sormas.api.EntityRelevanceStatus) ControllerProvider(de.symeda.sormas.ui.ControllerProvider) ExportEntityName(de.symeda.sormas.ui.utils.ExportEntityName) ViewConfiguration(de.symeda.sormas.ui.utils.ViewConfiguration) ViewModelProviders(de.symeda.sormas.ui.ViewModelProviders) CssStyles(de.symeda.sormas.ui.utils.CssStyles) MenuBarHelper(de.symeda.sormas.ui.utils.MenuBarHelper) Label(com.vaadin.ui.Label) VaadinIcons(com.vaadin.icons.VaadinIcons) ComboBoxHelper(de.symeda.sormas.ui.utils.ComboBoxHelper) ViewChangeListener(com.vaadin.navigator.ViewChangeListener) SubcontinentDto(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentDto) AbstractConfigurationView(de.symeda.sormas.ui.configuration.AbstractConfigurationView) SubcontinentIndexDto(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentIndexDto) UserProvider(de.symeda.sormas.ui.UserProvider) ButtonHelper(de.symeda.sormas.ui.utils.ButtonHelper) ValoTheme(com.vaadin.ui.themes.ValoTheme) MenuBar(com.vaadin.ui.MenuBar) ComboBox(com.vaadin.v7.ui.ComboBox) InfrastructureType(de.symeda.sormas.api.infrastructure.InfrastructureType) Captions(de.symeda.sormas.api.i18n.Captions) UserRight(de.symeda.sormas.api.user.UserRight) Button(com.vaadin.ui.Button) HorizontalLayout(com.vaadin.ui.HorizontalLayout) SubcontinentCriteria(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentCriteria) FileDownloader(com.vaadin.server.FileDownloader) Descriptions(de.symeda.sormas.api.i18n.Descriptions) Strings(de.symeda.sormas.api.i18n.Strings) Collections(java.util.Collections) ContinentReferenceDto(de.symeda.sormas.api.infrastructure.continent.ContinentReferenceDto) SearchField(de.symeda.sormas.ui.configuration.infrastructure.components.SearchField) MenuBarHelper(de.symeda.sormas.ui.utils.MenuBarHelper) EntityRelevanceStatus(de.symeda.sormas.api.EntityRelevanceStatus) SubcontinentCriteria(de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentCriteria) HorizontalLayout(com.vaadin.ui.HorizontalLayout)

Aggregations

ContinentReferenceDto (de.symeda.sormas.api.infrastructure.continent.ContinentReferenceDto)3 VaadinIcons (com.vaadin.icons.VaadinIcons)2 Alignment (com.vaadin.ui.Alignment)2 Button (com.vaadin.ui.Button)2 HorizontalLayout (com.vaadin.ui.HorizontalLayout)2 Label (com.vaadin.ui.Label)2 ValoTheme (com.vaadin.ui.themes.ValoTheme)2 ComboBox (com.vaadin.v7.ui.ComboBox)2 EntityRelevanceStatus (de.symeda.sormas.api.EntityRelevanceStatus)2 FacadeProvider (de.symeda.sormas.api.FacadeProvider)2 Captions (de.symeda.sormas.api.i18n.Captions)2 I18nProperties (de.symeda.sormas.api.i18n.I18nProperties)2 Strings (de.symeda.sormas.api.i18n.Strings)2 CountryReferenceDto (de.symeda.sormas.api.infrastructure.country.CountryReferenceDto)2 SubcontinentCriteria (de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentCriteria)2 SubcontinentReferenceDto (de.symeda.sormas.api.infrastructure.subcontinent.SubcontinentReferenceDto)2 ButtonHelper (de.symeda.sormas.ui.utils.ButtonHelper)2 ComboBoxHelper (de.symeda.sormas.ui.utils.ComboBoxHelper)2 CssStyles (de.symeda.sormas.ui.utils.CssStyles)2 VaadinUiUtil (de.symeda.sormas.ui.utils.VaadinUiUtil)2