Search in sources :

Example 1 with CountryDto

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

the class CountryImporter method insertColumnEntryIntoData.

/**
 * Inserts the entry of a single cell into the infrastructure object.
 */
private void insertColumnEntryIntoData(CountryDto 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();
                if (!executeDefaultInvoke(pd, currentElement, value, entityPropertyPath)) {
                    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<CountryDto> constraintErrors = validateConstraints(newEntityDto);
    if (constraintErrors.isError()) {
        throw new ImportErrorException(constraintErrors.getMessage());
    }
}
Also used : PropertyDescriptor(java.beans.PropertyDescriptor) ImportErrorException(de.symeda.sormas.api.importexport.ImportErrorException) CountryDto(de.symeda.sormas.api.infrastructure.country.CountryDto) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException) InvalidColumnException(de.symeda.sormas.api.importexport.InvalidColumnException) EmptyValueException(de.symeda.sormas.api.utils.EmptyValueException) CsvValidationException(com.opencsv.exceptions.CsvValidationException) ImportErrorException(de.symeda.sormas.api.importexport.ImportErrorException) IOException(java.io.IOException) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvalidColumnException(de.symeda.sormas.api.importexport.InvalidColumnException)

Example 2 with CountryDto

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

the class CountryFacadeEjbTest method testSaveCountryIsoCodeExists.

@Test(expected = ValidationRuntimeException.class)
public void testSaveCountryIsoCodeExists() {
    creator.createCountry("Romania", "ROU", "642");
    CountryDto duplicate = new CountryDto();
    duplicate.setDefaultName("Romania");
    duplicate.setIsoCode("ROU");
    getCountryFacade().save(duplicate);
}
Also used : CountryDto(de.symeda.sormas.api.infrastructure.country.CountryDto) Test(org.junit.Test) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest)

Example 3 with CountryDto

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

the class CountryFacadeEjbTest method testSaveCountryIsoCodeEmpty.

@Test(expected = EmptyValueException.class)
public void testSaveCountryIsoCodeEmpty() {
    CountryDto country = new CountryDto();
    country.setDefaultName("Romania");
    getCountryFacade().save(country);
}
Also used : CountryDto(de.symeda.sormas.api.infrastructure.country.CountryDto) Test(org.junit.Test) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest)

Example 4 with CountryDto

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

the class CountryFacadeEjbTest method testSaveCountryUnoCodeExists.

@Test(expected = ValidationRuntimeException.class)
public void testSaveCountryUnoCodeExists() {
    creator.createCountry("Romania", "ROU", "642");
    CountryDto duplicate = new CountryDto();
    duplicate.setDefaultName("Germany");
    duplicate.setIsoCode("DEU");
    duplicate.setUnoCode("642");
    getCountryFacade().save(duplicate);
}
Also used : CountryDto(de.symeda.sormas.api.infrastructure.country.CountryDto) Test(org.junit.Test) AbstractBeanTest(de.symeda.sormas.backend.AbstractBeanTest)

Example 5 with CountryDto

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

the class InfrastructureController method editCountry.

public void editCountry(String uuid) {
    CountryDto country = FacadeProvider.getCountryFacade().getByUuid(uuid);
    CommitDiscardWrapperComponent<CountryEditForm> editComponent = getCountryEditComponent(country);
    String caption = I18nProperties.getString(Strings.headingEditCountry);
    VaadinUiUtil.showModalPopupWindow(editComponent, caption);
}
Also used : CountryDto(de.symeda.sormas.api.infrastructure.country.CountryDto)

Aggregations

CountryDto (de.symeda.sormas.api.infrastructure.country.CountryDto)12 AbstractBeanTest (de.symeda.sormas.backend.AbstractBeanTest)8 Test (org.junit.Test)8 Country (de.symeda.sormas.backend.infrastructure.country.Country)5 EmptyValueException (de.symeda.sormas.api.utils.EmptyValueException)3 ValidationRuntimeException (de.symeda.sormas.api.utils.ValidationRuntimeException)3 ImportErrorException (de.symeda.sormas.api.importexport.ImportErrorException)2 InvalidColumnException (de.symeda.sormas.api.importexport.InvalidColumnException)2 CsvValidationException (com.opencsv.exceptions.CsvValidationException)1 IntrospectionException (java.beans.IntrospectionException)1 PropertyDescriptor (java.beans.PropertyDescriptor)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Date (java.util.Date)1