use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.
the class SessionFilter method doFilter.
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
HttpSession session = ((HttpServletRequest) request).getSession();
final HttpServletResponse res = (HttpServletResponse) response;
res.addHeader("X-Content-Type-Options", "nosniff");
res.addHeader("X-Frame-Options", "SAMEORIGIN");
res.addHeader("Referrer-Policy", "same-origin");
ControllerProvider controllerProvider = Optional.of(session).map(s -> (ControllerProvider) s.getAttribute("controllerProvider")).orElseGet(() -> {
ControllerProvider cp = new ControllerProvider();
session.setAttribute("controllerProvider", cp);
return cp;
});
try {
sessionFilterBean.doFilter((req, resp) -> {
Language userLanguage = Optional.of(FacadeProvider.getUserFacade()).map(UserFacade::getCurrentUser).map(UserDto::getLanguage).orElse(null);
I18nProperties.setUserLanguage(userLanguage);
FacadeProvider.getI18nFacade().setUserLanguage(userLanguage);
try (Closeable bc = BaseControllerProvider.requestStart(controllerProvider)) {
chain.doFilter(req, response);
}
}, request, response);
} finally {
I18nProperties.removeUserLanguage();
FacadeProvider.getI18nFacade().removeUserLanguage();
}
}
use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.
the class ActionEditForm method updateByCreating.
private void updateByCreating() {
ActionDto value = getValue();
if (value != null) {
boolean creating = value.getCreationDate() == null;
UserDto user = UserProvider.getCurrent().getUser();
boolean creator = user.equals(value.getCreatorUser());
setVisible(!creating, ActionDto.REPLY);
if (creating) {
discard(ActionDto.REPLY);
} else {
updateCreationInfo();
}
setReadOnly(!creator, ActionDto.DESCRIPTION, ActionDto.TITLE);
}
}
use of de.symeda.sormas.api.user.UserDto 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.user.UserDto in project SORMAS-Project by hzi-braunschweig.
the class ExposuresField method createEntry.
@Override
protected ExposureDto createEntry() {
UserDto user = UserProvider.getCurrent().getUser();
ExposureDto exposure = ExposureDto.build(null);
exposure.getLocation().setRegion(user.getRegion());
exposure.getLocation().setDistrict(user.getDistrict());
exposure.getLocation().setCommunity(user.getCommunity());
exposure.setReportingUser(user.toReference());
return exposure;
}
use of de.symeda.sormas.api.user.UserDto in project SORMAS-Project by hzi-braunschweig.
the class EventsFilterForm method applyFacilityFieldsDependencies.
private void applyFacilityFieldsDependencies(TypeOfPlace typeOfPlace, DistrictReferenceDto districtReferenceDto, CommunityReferenceDto communityReferenceDto) {
final UserDto user = UserProvider.getCurrent().getUser();
final boolean visible = typeOfPlace == TypeOfPlace.FACILITY && ((user.getCommunity() != null || communityReferenceDto != null) || (user.getDistrict() != null || districtReferenceDto != null));
final ComboBox facilityField = getField(LocationDto.FACILITY);
final ComboBox facilityTypeField = getField(LocationDto.FACILITY_TYPE);
final ComboBox facilityTypeGroupField = (ComboBox) getMoreFiltersContainer().getComponent(FACILITY_TYPE_GROUP_FILTER);
if (!visible) {
facilityField.clear();
facilityTypeField.clear();
facilityTypeGroupField.clear();
}
facilityField.setVisible(visible);
facilityTypeField.setVisible(visible);
facilityTypeGroupField.setVisible(visible);
}
Aggregations