use of de.symeda.sormas.api.infrastructure.country.CountryReferenceDto in project SORMAS-Project by hzi-braunschweig.
the class StartupShutdownService method upgrade.
private void upgrade() {
@SuppressWarnings("unchecked") List<Integer> versionsNeedingUpgrade = em.createNativeQuery("SELECT version_number FROM schema_version WHERE upgradeNeeded").getResultList();
for (Integer versionNeedingUpgrade : versionsNeedingUpgrade) {
switch(versionNeedingUpgrade) {
case 95:
// update follow up and status for all contacts
for (Contact contact : contactService.getAll()) {
contactService.updateFollowUpDetails(contact, false);
contactService.udpateContactStatus(contact);
}
break;
case 354:
CountryReferenceDto serverCountry = countryFacade.getServerCountry();
if (serverCountry != null) {
Country country = countryService.getByUuid(serverCountry.getUuid());
em.createQuery("UPDATE Region set country = :server_country, changeDate = :change_date WHERE country is null").setParameter("server_country", country).setParameter("change_date", new Timestamp(new Date().getTime())).executeUpdate();
}
break;
default:
throw new NoSuchElementException(DataHelper.toStringNullable(versionNeedingUpgrade));
}
int updatedRows = em.createNativeQuery("UPDATE schema_version SET upgradeNeeded=false WHERE version_number=?1").setParameter(1, versionNeedingUpgrade).executeUpdate();
if (updatedRows != 1) {
logger.error("Could not UPDATE schema_version table. Missing user rights?");
}
}
}
use of de.symeda.sormas.api.infrastructure.country.CountryReferenceDto 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;
}
use of de.symeda.sormas.api.infrastructure.country.CountryReferenceDto 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);
}
use of de.symeda.sormas.api.infrastructure.country.CountryReferenceDto in project SORMAS-Project by hzi-braunschweig.
the class PersonEditForm method addFields.
@Override
protected void addFields() {
personInformationHeadingLabel = new Label(I18nProperties.getString(Strings.headingPersonInformation));
personInformationHeadingLabel.addStyleName(H3);
getContent().addComponent(personInformationHeadingLabel, PERSON_INFORMATION_HEADING_LOC);
addField(PersonDto.UUID).setReadOnly(true);
firstNameField = addField(PersonDto.FIRST_NAME, TextField.class);
lastNameField = addField(PersonDto.LAST_NAME, TextField.class);
addFields(PersonDto.SALUTATION, PersonDto.OTHER_SALUTATION);
FieldHelper.setVisibleWhen(getFieldGroup(), PersonDto.OTHER_SALUTATION, PersonDto.SALUTATION, Salutation.OTHER, true);
ComboBox sex = addField(PersonDto.SEX, ComboBox.class);
addField(PersonDto.BIRTH_NAME, TextField.class);
addField(PersonDto.NICKNAME, TextField.class);
addField(PersonDto.MOTHERS_MAIDEN_NAME, TextField.class);
addFields(PersonDto.MOTHERS_NAME, PersonDto.FATHERS_NAME);
addFields(PersonDto.NAMES_OF_GUARDIANS);
ComboBox presentCondition = addField(PersonDto.PRESENT_CONDITION, ComboBox.class);
birthDateDay = addField(PersonDto.BIRTH_DATE_DD, ComboBox.class);
// @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
birthDateDay.setNullSelectionAllowed(true);
birthDateDay.setInputPrompt(I18nProperties.getString(Strings.day));
birthDateDay.setCaption("");
ComboBox birthDateMonth = addField(PersonDto.BIRTH_DATE_MM, ComboBox.class);
// @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
birthDateMonth.setNullSelectionAllowed(true);
birthDateMonth.addItems(DateHelper.getMonthsInYear());
birthDateMonth.setPageLength(12);
birthDateMonth.setInputPrompt(I18nProperties.getString(Strings.month));
birthDateMonth.setCaption("");
setItemCaptionsForMonths(birthDateMonth);
ComboBox birthDateYear = addField(PersonDto.BIRTH_DATE_YYYY, ComboBox.class);
birthDateYear.setCaption(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.BIRTH_DATE));
// @TODO: Done for nullselection Bug, fixed in Vaadin 7.7.3
birthDateYear.setNullSelectionAllowed(true);
birthDateYear.addItems(DateHelper.getYearsToNow());
birthDateYear.setItemCaptionMode(ItemCaptionMode.ID_TOSTRING);
birthDateYear.setInputPrompt(I18nProperties.getString(Strings.year));
birthDateDay.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) birthDateYear.getValue(), (Integer) birthDateMonth.getValue(), (Integer) e));
birthDateMonth.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) birthDateYear.getValue(), (Integer) e, (Integer) birthDateDay.getValue()));
birthDateYear.addValidator(e -> ControllerProvider.getPersonController().validateBirthDate((Integer) e, (Integer) birthDateMonth.getValue(), (Integer) birthDateDay.getValue()));
DateField deathDate = addField(PersonDto.DEATH_DATE, DateField.class);
TextField approximateAgeField = addField(PersonDto.APPROXIMATE_AGE, TextField.class);
approximateAgeField.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, approximateAgeField.getCaption()));
ComboBox approximateAgeTypeField = addField(PersonDto.APPROXIMATE_AGE_TYPE, ComboBox.class);
addField(PersonDto.APPROXIMATE_AGE_REFERENCE_DATE, DateField.class);
approximateAgeField.addValidator(new ApproximateAgeValidator(approximateAgeField, approximateAgeTypeField, I18nProperties.getValidationError(Validations.softApproximateAgeTooHigh)));
TextField tfGestationAgeAtBirth = addField(PersonDto.GESTATION_AGE_AT_BIRTH, TextField.class);
tfGestationAgeAtBirth.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, tfGestationAgeAtBirth.getCaption()));
TextField tfBirthWeight = addField(PersonDto.BIRTH_WEIGHT, TextField.class);
tfBirthWeight.setConversionError(I18nProperties.getValidationError(Validations.onlyIntegerNumbersAllowed, tfBirthWeight.getCaption()));
AbstractSelect deathPlaceType = addField(PersonDto.DEATH_PLACE_TYPE, ComboBox.class);
deathPlaceType.setNullSelectionAllowed(true);
TextField deathPlaceDesc = addField(PersonDto.DEATH_PLACE_DESCRIPTION, TextField.class);
DateField burialDate = addField(PersonDto.BURIAL_DATE, DateField.class);
TextField burialPlaceDesc = addField(PersonDto.BURIAL_PLACE_DESCRIPTION, TextField.class);
ComboBox burialConductor = addField(PersonDto.BURIAL_CONDUCTOR, ComboBox.class);
addField(PersonDto.ADDRESS, LocationEditForm.class).setCaption(null);
addField(PersonDto.ADDRESSES, LocationsField.class).setCaption(null);
PersonContactDetailsField personContactDetailsField = new PersonContactDetailsField(getValue(), fieldVisibilityCheckers, fieldAccessCheckers);
personContactDetailsField.setId(PersonDto.PERSON_CONTACT_DETAILS);
personContactDetailsField.setPseudonymized(isPseudonymized);
getFieldGroup().bind(personContactDetailsField, PersonDto.PERSON_CONTACT_DETAILS);
getContent().addComponent(personContactDetailsField, PersonDto.PERSON_CONTACT_DETAILS);
addFields(PersonDto.OCCUPATION_TYPE, PersonDto.OCCUPATION_DETAILS, PersonDto.ARMED_FORCES_RELATION_TYPE, PersonDto.EDUCATION_TYPE, PersonDto.EDUCATION_DETAILS);
List<CountryReferenceDto> countries = FacadeProvider.getCountryFacade().getAllActiveAsReference();
addInfrastructureField(PersonDto.BIRTH_COUNTRY).addItems(countries);
addInfrastructureField(PersonDto.CITIZENSHIP).addItems(countries);
addFields(PersonDto.PASSPORT_NUMBER, PersonDto.NATIONAL_HEALTH_ID);
Field externalId = addField(PersonDto.EXTERNAL_ID);
if (FacadeProvider.getExternalSurveillanceToolFacade().isFeatureEnabled()) {
externalId.setEnabled(false);
}
TextField externalTokenField = addField(PersonDto.EXTERNAL_TOKEN);
Label externalTokenWarningLabel = new Label(I18nProperties.getString(Strings.messagePersonExternalTokenWarning));
externalTokenWarningLabel.addStyleNames(VSPACE_3, LABEL_WHITE_SPACE_NORMAL);
getContent().addComponent(externalTokenWarningLabel, EXTERNAL_TOKEN_WARNING_LOC);
addField(PersonDto.INTERNAL_TOKEN);
addField(PersonDto.HAS_COVID_APP).addStyleName(CssStyles.FORCE_CAPTION_CHECKBOX);
addField(PersonDto.COVID_CODE_DELIVERED).addStyleName(CssStyles.FORCE_CAPTION_CHECKBOX);
if (personContext != PersonContext.CASE) {
setVisible(false, PersonDto.HAS_COVID_APP, PersonDto.COVID_CODE_DELIVERED);
}
ComboBox cbPlaceOfBirthRegion = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_REGION);
ComboBox cbPlaceOfBirthDistrict = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_DISTRICT);
ComboBox cbPlaceOfBirthCommunity = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_COMMUNITY);
ComboBox placeOfBirthFacilityType = addField(PersonDto.PLACE_OF_BIRTH_FACILITY_TYPE);
FieldHelper.removeItems(placeOfBirthFacilityType);
placeOfBirthFacilityType.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ID);
placeOfBirthFacilityType.addItems(FacilityType.getPlaceOfBirthTypes());
cbPlaceOfBirthFacility = addInfrastructureField(PersonDto.PLACE_OF_BIRTH_FACILITY);
TextField tfPlaceOfBirthFacilityDetails = addField(PersonDto.PLACE_OF_BIRTH_FACILITY_DETAILS, TextField.class);
causeOfDeathField = addField(PersonDto.CAUSE_OF_DEATH, ComboBox.class);
causeOfDeathDiseaseField = addDiseaseField(PersonDto.CAUSE_OF_DEATH_DISEASE, true);
causeOfDeathDetailsField = addField(PersonDto.CAUSE_OF_DEATH_DETAILS, TextField.class);
// Set requirements that don't need visibility changes and read only status
setReadOnly(true, PersonDto.APPROXIMATE_AGE_REFERENCE_DATE);
setRequired(true, PersonDto.FIRST_NAME, PersonDto.LAST_NAME, PersonDto.SEX);
setVisible(false, PersonDto.OCCUPATION_DETAILS, PersonDto.DEATH_DATE, PersonDto.DEATH_PLACE_TYPE, PersonDto.DEATH_PLACE_DESCRIPTION, PersonDto.BURIAL_DATE, PersonDto.BURIAL_PLACE_DESCRIPTION, PersonDto.BURIAL_CONDUCTOR, PersonDto.CAUSE_OF_DEATH, PersonDto.CAUSE_OF_DEATH_DETAILS, PersonDto.CAUSE_OF_DEATH_DISEASE);
FieldHelper.setVisibleWhen(getFieldGroup(), PersonDto.EDUCATION_DETAILS, PersonDto.EDUCATION_TYPE, Arrays.asList(EducationType.OTHER), true);
FieldHelper.addSoftRequiredStyle(presentCondition, sex, deathDate, deathPlaceDesc, deathPlaceType, causeOfDeathField, causeOfDeathDiseaseField, causeOfDeathDetailsField, burialDate, burialPlaceDesc, burialConductor);
// Set initial visibilities
initializeVisibilitiesAndAllowedVisibilities();
initializeAccessAndAllowedAccesses();
if (!getField(PersonDto.OCCUPATION_TYPE).isVisible() && !getField(PersonDto.ARMED_FORCES_RELATION_TYPE).isVisible() && !getField(PersonDto.EDUCATION_TYPE).isVisible())
occupationHeader.setVisible(false);
if (!getField(PersonDto.ADDRESS).isVisible())
addressHeader.setVisible(false);
if (!getField(PersonDto.ADDRESSES).isVisible())
addressesHeader.setVisible(false);
// Add listeners
FieldHelper.setRequiredWhenNotNull(getFieldGroup(), PersonDto.APPROXIMATE_AGE, PersonDto.APPROXIMATE_AGE_TYPE);
addFieldListeners(PersonDto.APPROXIMATE_AGE, e -> {
@SuppressWarnings("unchecked") Field<ApproximateAgeType> ageTypeField = (Field<ApproximateAgeType>) getField(PersonDto.APPROXIMATE_AGE_TYPE);
if (!ageTypeField.isReadOnly()) {
if (e.getProperty().getValue() == null) {
ageTypeField.clear();
} else {
if (ageTypeField.isEmpty()) {
ageTypeField.setValue(ApproximateAgeType.YEARS);
}
}
}
});
addFieldListeners(PersonDto.BIRTH_DATE_DD, e -> {
updateApproximateAge();
updateReadyOnlyApproximateAge();
});
addFieldListeners(PersonDto.BIRTH_DATE_MM, e -> {
updateApproximateAge();
updateReadyOnlyApproximateAge();
});
addFieldListeners(PersonDto.BIRTH_DATE_YYYY, e -> {
updateApproximateAge();
updateReadyOnlyApproximateAge();
});
addFieldListeners(PersonDto.DEATH_DATE, e -> updateApproximateAge());
addFieldListeners(PersonDto.OCCUPATION_TYPE, e -> {
updateOccupationFieldCaptions();
toogleOccupationMetaFields();
});
addListenersToInfrastructureFields(cbPlaceOfBirthRegion, cbPlaceOfBirthDistrict, cbPlaceOfBirthCommunity, placeOfBirthFacilityType, cbPlaceOfBirthFacility, tfPlaceOfBirthFacilityDetails, true);
cbPlaceOfBirthRegion.addItems(FacadeProvider.getRegionFacade().getAllActiveByServerCountry());
addFieldListeners(PersonDto.PRESENT_CONDITION, e -> toogleDeathAndBurialFields());
causeOfDeathField.addValueChangeListener(e -> {
toggleCauseOfDeathFields(presentCondition.getValue() != PresentCondition.ALIVE && presentCondition.getValue() != null);
});
causeOfDeathDiseaseField.addValueChangeListener(e -> {
toggleCauseOfDeathFields(presentCondition.getValue() != PresentCondition.ALIVE && presentCondition.getValue() != null);
});
addValueChangeListener(e -> {
fillDeathAndBurialFields(deathPlaceType, deathPlaceDesc, burialPlaceDesc);
});
deathDate.addValidator(new DateComparisonValidator(deathDate, this::calcBirthDateValue, false, false, I18nProperties.getValidationError(Validations.afterDate, deathDate.getCaption(), birthDateYear.getCaption())));
burialDate.addValidator(new DateComparisonValidator(burialDate, deathDate, false, false, I18nProperties.getValidationError(Validations.afterDate, burialDate.getCaption(), deathDate.getCaption())));
// Update the list of days according to the selected month and year
birthDateYear.addValueChangeListener(e -> {
updateListOfDays((Integer) e.getProperty().getValue(), (Integer) birthDateMonth.getValue());
birthDateMonth.markAsDirty();
birthDateDay.markAsDirty();
});
birthDateMonth.addValueChangeListener(e -> {
updateListOfDays((Integer) birthDateYear.getValue(), (Integer) e.getProperty().getValue());
birthDateYear.markAsDirty();
birthDateDay.markAsDirty();
});
birthDateDay.addValueChangeListener(e -> {
birthDateYear.markAsDirty();
birthDateMonth.markAsDirty();
});
addValueChangeListener((e) -> {
ValidationUtils.initComponentErrorValidator(externalTokenField, getValue().getExternalToken(), Validations.duplicateExternalToken, externalTokenWarningLabel, (externalToken) -> FacadeProvider.getPersonFacade().doesExternalTokenExist(externalToken, getValue().getUuid()));
personContactDetailsField.setThisPerson((PersonDto) e.getProperty().getValue());
});
Label generalCommentLabel = new Label(I18nProperties.getPrefixCaption(PersonDto.I18N_PREFIX, PersonDto.ADDITIONAL_DETAILS));
generalCommentLabel.addStyleName(H3);
getContent().addComponent(generalCommentLabel, GENERAL_COMMENT_LOC);
TextArea additionalDetails = addField(PersonDto.ADDITIONAL_DETAILS, TextArea.class, new ResizableTextAreaWrapper<>(false));
additionalDetails.setRows(6);
additionalDetails.setDescription(I18nProperties.getPrefixDescription(PersonDto.I18N_PREFIX, PersonDto.ADDITIONAL_DETAILS, "") + "\n" + I18nProperties.getDescription(Descriptions.descGdpr));
CssStyles.style(additionalDetails, CssStyles.CAPTION_HIDDEN);
}
use of de.symeda.sormas.api.infrastructure.country.CountryReferenceDto in project SORMAS-Project by hzi-braunschweig.
the class PointOfEntryService method buildCriteriaFilter.
@Override
public Predicate buildCriteriaFilter(PointOfEntryCriteria criteria, CriteriaBuilder cb, Root<PointOfEntry> pointOfEntry) {
Predicate filter = null;
CountryReferenceDto country = criteria.getCountry();
if (country != null) {
CountryReferenceDto serverCountry = countryFacade.getServerCountry();
Path<Object> countryUuid = pointOfEntry.join(PointOfEntry.REGION, JoinType.LEFT).join(Region.COUNTRY, JoinType.LEFT).get(Country.UUID);
Predicate countryFilter = cb.equal(countryUuid, country.getUuid());
if (country.equals(serverCountry)) {
filter = CriteriaBuilderHelper.and(cb, filter, CriteriaBuilderHelper.or(cb, countryFilter, countryUuid.isNull()));
} else {
filter = CriteriaBuilderHelper.and(cb, filter, countryFilter);
}
}
if (criteria.getRegion() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(pointOfEntry.join(PointOfEntry.REGION, JoinType.LEFT).get(Region.UUID), criteria.getRegion().getUuid()));
}
if (criteria.getDistrict() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(pointOfEntry.join(PointOfEntry.DISTRICT, JoinType.LEFT).get(District.UUID), criteria.getDistrict().getUuid()));
}
if (criteria.getType() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(pointOfEntry.get(PointOfEntry.POINT_OF_ENTRY_TYPE), criteria.getType()));
}
if (criteria.getActive() != null) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(pointOfEntry.get(PointOfEntry.ACTIVE), criteria.getActive()));
}
if (criteria.getNameLike() != null) {
String[] textFilters = criteria.getNameLike().split("\\s+");
for (String textFilter : textFilters) {
if (DataHelper.isNullOrEmpty(textFilter)) {
continue;
}
Predicate likeFilters = CriteriaBuilderHelper.unaccentedIlike(cb, pointOfEntry.get(PointOfEntry.NAME), textFilter);
filter = CriteriaBuilderHelper.and(cb, filter, likeFilters);
}
}
if (criteria.getRelevanceStatus() != null) {
if (criteria.getRelevanceStatus() == EntityRelevanceStatus.ACTIVE) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.or(cb.equal(pointOfEntry.get(PointOfEntry.ARCHIVED), false), cb.isNull(pointOfEntry.get(PointOfEntry.ARCHIVED))));
} else if (criteria.getRelevanceStatus() == EntityRelevanceStatus.ARCHIVED) {
filter = CriteriaBuilderHelper.and(cb, filter, cb.equal(pointOfEntry.get(PointOfEntry.ARCHIVED), true));
}
}
return filter;
}
Aggregations