Search in sources :

Example 6 with UserDto

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();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSession(javax.servlet.http.HttpSession) FilterChain(javax.servlet.FilterChain) ServletRequest(javax.servlet.ServletRequest) ServletException(javax.servlet.ServletException) FacadeProvider(de.symeda.sormas.api.FacadeProvider) I18nProperties(de.symeda.sormas.api.i18n.I18nProperties) UserDto(de.symeda.sormas.api.user.UserDto) HttpServletResponse(javax.servlet.http.HttpServletResponse) IOException(java.io.IOException) Language(de.symeda.sormas.api.Language) UserFacade(de.symeda.sormas.api.user.UserFacade) HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletResponse(javax.servlet.ServletResponse) WebFilter(javax.servlet.annotation.WebFilter) Closeable(java.io.Closeable) Optional(java.util.Optional) Filter(javax.servlet.Filter) BaseControllerProvider(de.symeda.sormas.ui.utils.BaseControllerProvider) EJB(javax.ejb.EJB) UserFacade(de.symeda.sormas.api.user.UserFacade) Language(de.symeda.sormas.api.Language) HttpSession(javax.servlet.http.HttpSession) Closeable(java.io.Closeable) HttpServletResponse(javax.servlet.http.HttpServletResponse) BaseControllerProvider(de.symeda.sormas.ui.utils.BaseControllerProvider)

Example 7 with UserDto

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);
    }
}
Also used : UserDto(de.symeda.sormas.api.user.UserDto) ActionDto(de.symeda.sormas.api.action.ActionDto)

Example 8 with UserDto

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;
}
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 9 with UserDto

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;
}
Also used : ExposureDto(de.symeda.sormas.api.exposure.ExposureDto) UserDto(de.symeda.sormas.api.user.UserDto)

Example 10 with UserDto

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);
}
Also used : ComboBox(com.vaadin.v7.ui.ComboBox) UserDto(de.symeda.sormas.api.user.UserDto)

Aggregations

UserDto (de.symeda.sormas.api.user.UserDto)274 Test (org.junit.Test)210 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)160 PersonDto (de.symeda.sormas.api.person.PersonDto)142 Date (java.util.Date)138 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)121 RDCFEntities (de.symeda.sormas.backend.TestDataCreator.RDCFEntities)64 ContactDto (de.symeda.sormas.api.contact.ContactDto)57 LocalDate (java.time.LocalDate)57 RDCF (de.symeda.sormas.backend.TestDataCreator.RDCF)56 EventDto (de.symeda.sormas.api.event.EventDto)52 TestDataCreator (de.symeda.sormas.backend.TestDataCreator)47 RegionReferenceDto (de.symeda.sormas.api.infrastructure.region.RegionReferenceDto)43 AbstractBeanTest (de.symeda.sormas.ui.AbstractBeanTest)43 SampleDto (de.symeda.sormas.api.sample.SampleDto)41 File (java.io.File)41 TestDataCreator (de.symeda.sormas.ui.TestDataCreator)31 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)30 CasePersonDto (de.symeda.sormas.api.caze.CasePersonDto)27 ImportResultStatus (de.symeda.sormas.ui.importer.ImportResultStatus)27