Search in sources :

Example 16 with FacilityDto

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

the class InfrastructureImporter method insertColumnEntryIntoData.

/**
 * Inserts the entry of a single cell into the infrastructure object.
 */
private void insertColumnEntryIntoData(EntityDto newEntityDto, String value, String[] entityPropertyPath) throws InvalidColumnException, ImportErrorException {
    Object currentElement = newEntityDto;
    for (int i = 0; i < entityPropertyPath.length; i++) {
        String headerPathElementName = entityPropertyPath[i];
        try {
            if (i != entityPropertyPath.length - 1) {
                currentElement = new PropertyDescriptor(headerPathElementName, currentElement.getClass()).getReadMethod().invoke(currentElement);
            } else {
                PropertyDescriptor pd = new PropertyDescriptor(headerPathElementName, currentElement.getClass());
                Class<?> propertyType = pd.getPropertyType();
                // is referenced in the imported object does not exist in the database
                if (!executeDefaultInvoke(pd, currentElement, value, entityPropertyPath)) {
                    if (propertyType.isAssignableFrom(DistrictReferenceDto.class)) {
                        List<DistrictReferenceDto> district;
                        switch(type) {
                            case COMMUNITY:
                                district = FacadeProvider.getDistrictFacade().getByName(value, ((CommunityDto) newEntityDto).getRegion(), false);
                                break;
                            case FACILITY:
                                district = FacadeProvider.getDistrictFacade().getByName(value, ((FacilityDto) newEntityDto).getRegion(), false);
                                break;
                            case POINT_OF_ENTRY:
                                district = FacadeProvider.getDistrictFacade().getByName(value, ((PointOfEntryDto) newEntityDto).getRegion(), false);
                                break;
                            default:
                                throw new UnsupportedOperationException(I18nProperties.getValidationError(Validations.importPropertyTypeNotAllowed, propertyType.getName()));
                        }
                        if (district.isEmpty()) {
                            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExistDbOrRegion, value, buildEntityProperty(entityPropertyPath)));
                        } else if (district.size() > 1) {
                            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importDistrictNotUnique, value, buildEntityProperty(entityPropertyPath)));
                        } else {
                            pd.getWriteMethod().invoke(currentElement, district.get(0));
                        }
                    } else if (propertyType.isAssignableFrom(CommunityReferenceDto.class)) {
                        List<CommunityReferenceDto> community;
                        if (type == InfrastructureType.FACILITY) {
                            community = FacadeProvider.getCommunityFacade().getByName(value, ((FacilityDto) newEntityDto).getDistrict(), false);
                        } else {
                            throw new UnsupportedOperationException(I18nProperties.getValidationError(Validations.importPropertyTypeNotAllowed, propertyType.getName()));
                        }
                        if (community.isEmpty()) {
                            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importEntryDoesNotExistDbOrRegion, value, buildEntityProperty(entityPropertyPath)));
                        } else if (community.size() > 1) {
                            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importDistrictNotUnique, value, buildEntityProperty(entityPropertyPath)));
                        } else {
                            pd.getWriteMethod().invoke(currentElement, community.get(0));
                        }
                    } else {
                        throw new UnsupportedOperationException(I18nProperties.getValidationError(Validations.importPropertyTypeNotAllowed, propertyType.getName()));
                    }
                }
            }
        } catch (IntrospectionException e) {
            throw new InvalidColumnException(buildEntityProperty(entityPropertyPath));
        } catch (InvocationTargetException | IllegalAccessException e) {
            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importErrorInColumn, buildEntityProperty(entityPropertyPath)));
        } catch (IllegalArgumentException e) {
            throw new ImportErrorException(value, buildEntityProperty(entityPropertyPath));
        } catch (ImportErrorException e) {
            throw e;
        } catch (Exception e) {
            logger.error("Unexpected error when trying to import infrastructure data: " + e.getMessage());
            throw new ImportErrorException(I18nProperties.getValidationError(Validations.importUnexpectedError));
        }
    }
    ImportLineResultDto<EntityDto> constraintErrors = validateConstraints(newEntityDto);
    if (constraintErrors.isError()) {
        throw new ImportErrorException(constraintErrors.getMessage());
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) ImportErrorException(de.symeda.sormas.api.importexport.ImportErrorException) IntrospectionException(java.beans.IntrospectionException) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto) DistrictReferenceDto(de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto) InvocationTargetException(java.lang.reflect.InvocationTargetException) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) InvalidColumnException(de.symeda.sormas.api.importexport.InvalidColumnException) ImportErrorException(de.symeda.sormas.api.importexport.ImportErrorException) IOException(java.io.IOException) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) EntityDto(de.symeda.sormas.api.EntityDto) CommunityReferenceDto(de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto) InvalidColumnException(de.symeda.sormas.api.importexport.InvalidColumnException) CommunityDto(de.symeda.sormas.api.infrastructure.community.CommunityDto) PointOfEntryDto(de.symeda.sormas.api.infrastructure.pointofentry.PointOfEntryDto) List(java.util.List)

Example 17 with FacilityDto

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

the class TravelEntryCreateForm method setValue.

@Override
public void setValue(TravelEntryDto newFieldValue) throws ReadOnlyException, Converter.ConversionException {
    super.setValue(newFieldValue);
    buildDeaContent(newFieldValue);
    UserProvider currentUserProvider = UserProvider.getCurrent();
    JurisdictionLevel userJurisditionLevel = currentUserProvider != null ? UserRole.getJurisdictionLevel(currentUserProvider.getUserRoles()) : JurisdictionLevel.NONE;
    if (userJurisditionLevel == JurisdictionLevel.HEALTH_FACILITY) {
        FacilityDto facility = FacadeProvider.getFacilityFacade().getByUuid(currentUserProvider.getUser().getHealthFacility().getUuid());
        responsibleRegion.setValue(facility.getRegion());
        responsibleRegion.setReadOnly(true);
        responsibleDistrict.setValue(facility.getDistrict());
        responsibleDistrict.setReadOnly(true);
        responsibleCommunity.setValue(facility.getCommunity());
        responsibleCommunity.setReadOnly(true);
    }
}
Also used : UserProvider(de.symeda.sormas.ui.UserProvider) JurisdictionLevel(de.symeda.sormas.api.user.JurisdictionLevel) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto)

Example 18 with FacilityDto

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

the class TestDataCreator method createRDCF.

public RDCF createRDCF(String regionName, String districtName, String communityName, String facilityName) {
    RegionDto region = createRegion(regionName);
    DistrictDto district = createDistrict(districtName, region.toReference());
    CommunityDto community = createCommunity(communityName, district.toReference());
    FacilityDto facility = createFacility(facilityName, region.toReference(), district.toReference(), community.toReference());
    return new RDCF(region, district, community, facility);
}
Also used : DistrictDto(de.symeda.sormas.api.infrastructure.district.DistrictDto) CommunityDto(de.symeda.sormas.api.infrastructure.community.CommunityDto) RegionDto(de.symeda.sormas.api.infrastructure.region.RegionDto) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto)

Example 19 with FacilityDto

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

the class TestDataCreator method createCase.

public CaseDataDto createCase(UserReferenceDto user, PersonReferenceDto cazePerson, Disease disease, CaseClassification caseClassification, InvestigationStatus investigationStatus, Date reportDate, RDCF rdcf, String caseUuid) {
    CaseDataDto caze = CaseDataDto.build(cazePerson, disease);
    if (caseUuid != null) {
        caze.setUuid(caseUuid);
    }
    caze.setReportDate(reportDate);
    caze.setReportingUser(user);
    caze.setCaseClassification(caseClassification);
    caze.setInvestigationStatus(investigationStatus);
    caze.setResponsibleRegion(FacadeProvider.getRegionFacade().getReferenceByUuid(rdcf.region.getUuid()));
    caze.setResponsibleDistrict(FacadeProvider.getDistrictFacade().getReferenceByUuid(rdcf.district.getUuid()));
    caze.setResponsibleCommunity(FacadeProvider.getCommunityFacade().getReferenceByUuid(rdcf.community.getUuid()));
    FacilityDto facility = FacadeProvider.getFacilityFacade().getByUuid(rdcf.facility.getUuid());
    caze.setFacilityType(facility.getType());
    caze.setHealthFacility(facility.toReference());
    caze = FacadeProviderMock.getCaseFacade().save(caze);
    return caze;
}
Also used : CaseDataDto(de.symeda.sormas.api.caze.CaseDataDto) FacilityDto(de.symeda.sormas.api.infrastructure.facility.FacilityDto)

Aggregations

FacilityDto (de.symeda.sormas.api.infrastructure.facility.FacilityDto)19 Date (java.util.Date)6 List (java.util.List)5 Test (org.junit.Test)5 FacilityReferenceDto (de.symeda.sormas.api.infrastructure.facility.FacilityReferenceDto)3 ContentMode (com.vaadin.shared.ui.ContentMode)2 Alignment (com.vaadin.ui.Alignment)2 Button (com.vaadin.ui.Button)2 Component (com.vaadin.ui.Component)2 HorizontalLayout (com.vaadin.ui.HorizontalLayout)2 Label (com.vaadin.ui.Label)2 VerticalLayout (com.vaadin.ui.VerticalLayout)2 Window (com.vaadin.ui.Window)2 ValoTheme (com.vaadin.ui.themes.ValoTheme)2 CaseDataDto (de.symeda.sormas.api.caze.CaseDataDto)2 EventDto (de.symeda.sormas.api.event.EventDto)2 EventParticipantDto (de.symeda.sormas.api.event.EventParticipantDto)2 CommunityDto (de.symeda.sormas.api.infrastructure.community.CommunityDto)2 CommunityReferenceDto (de.symeda.sormas.api.infrastructure.community.CommunityReferenceDto)2 DistrictReferenceDto (de.symeda.sormas.api.infrastructure.district.DistrictReferenceDto)2