Search in sources :

Example 1 with CampaignFormDataCriteria

use of de.symeda.sormas.api.campaign.data.CampaignFormDataCriteria in project SORMAS-Project by hzi-braunschweig.

the class CampaignDataGrid method setDataProvider.

public void setDataProvider() {
    DataProvider<CampaignFormDataIndexDto, CampaignFormDataCriteria> dataProvider = DataProvider.fromFilteringCallbacks(query -> FacadeProvider.getCampaignFormDataFacade().getIndexList(query.getFilter().orElse(null), query.getOffset(), query.getLimit(), query.getSortOrders().stream().map(sortOrder -> new SortProperty(sortOrder.getSorted(), sortOrder.getDirection() == SortDirection.ASCENDING)).collect(Collectors.toList())).stream(), query -> (int) FacadeProvider.getCampaignFormDataFacade().count(query.getFilter().orElse(null)));
    setDataProvider(dataProvider);
    setSelectionMode(SelectionMode.NONE);
}
Also used : SortProperty(de.symeda.sormas.api.utils.SortProperty) CampaignFormDataIndexDto(de.symeda.sormas.api.campaign.data.CampaignFormDataIndexDto) CampaignFormDataCriteria(de.symeda.sormas.api.campaign.data.CampaignFormDataCriteria)

Example 2 with CampaignFormDataCriteria

use of de.symeda.sormas.api.campaign.data.CampaignFormDataCriteria in project SORMAS-Project by hzi-braunschweig.

the class CampaignFormDataImporter method importDataFromCsvLine.

@Override
protected ImportLineResult importDataFromCsvLine(String[] values, String[] entityClasses, String[] entityProperties, String[][] entityPropertyPaths, boolean firstLine) throws IOException, InterruptedException {
    if (values.length > entityProperties.length) {
        writeImportError(values, I18nProperties.getValidationError(Validations.importLineTooLong));
        return ImportLineResult.ERROR;
    }
    CampaignFormDataDto campaignFormData = CampaignFormDataDto.build();
    campaignFormData.setCreatingUser(userFacade.getCurrentUserAsReference());
    try {
        insertImportRowIntoData(campaignFormData, values, entityProperties);
        campaignFormData.setCampaign(campaignReferenceDto);
        CampaignFormDataDto existingData = FacadeProvider.getCampaignFormDataFacade().getExistingData(new CampaignFormDataCriteria().campaign(campaignFormData.getCampaign()).campaignFormMeta(campaignFormData.getCampaignFormMeta()).community(campaignFormData.getCommunity()).formDate(campaignFormData.getFormDate()));
        if (existingData != null) {
            final CampaignFormDataImportLock lock = new CampaignFormDataImportLock();
            synchronized (lock) {
                handleDetectedDuplicate(campaignFormData, existingData, lock);
                try {
                    if (!lock.wasNotified) {
                        lock.wait();
                    }
                } catch (InterruptedException e) {
                    logger.error("InterruptedException when trying to perform LOCK.wait() in campaign form data import: " + e.getMessage());
                    throw e;
                }
                if (lock.similarityChoice == CampaignFormDataSimilarityChoice.CANCEL) {
                    cancelImport();
                    return ImportLineResult.SKIPPED;
                } else if (lock.similarityChoice == CampaignFormDataSimilarityChoice.SKIP) {
                    return ImportLineResult.SKIPPED;
                } else {
                    FacadeProvider.getCampaignFormDataFacade().overwriteCampaignFormData(existingData, campaignFormData);
                }
            }
        } else {
            FacadeProvider.getCampaignFormDataFacade().saveCampaignFormData(campaignFormData);
        }
    } catch (ImportErrorException | InvalidColumnException | ValidationRuntimeException e) {
        writeImportError(values, e.getLocalizedMessage());
        return ImportLineResult.ERROR;
    }
    return ImportLineResult.SUCCESS;
}
Also used : CampaignFormDataDto(de.symeda.sormas.api.campaign.data.CampaignFormDataDto) ImportErrorException(de.symeda.sormas.api.importexport.ImportErrorException) InvalidColumnException(de.symeda.sormas.api.importexport.InvalidColumnException) CampaignFormDataCriteria(de.symeda.sormas.api.campaign.data.CampaignFormDataCriteria) ValidationRuntimeException(de.symeda.sormas.api.utils.ValidationRuntimeException)

Aggregations

CampaignFormDataCriteria (de.symeda.sormas.api.campaign.data.CampaignFormDataCriteria)2 CampaignFormDataDto (de.symeda.sormas.api.campaign.data.CampaignFormDataDto)1 CampaignFormDataIndexDto (de.symeda.sormas.api.campaign.data.CampaignFormDataIndexDto)1 ImportErrorException (de.symeda.sormas.api.importexport.ImportErrorException)1 InvalidColumnException (de.symeda.sormas.api.importexport.InvalidColumnException)1 SortProperty (de.symeda.sormas.api.utils.SortProperty)1 ValidationRuntimeException (de.symeda.sormas.api.utils.ValidationRuntimeException)1