Search in sources :

Example 1 with DataCleansingMetadata

use of org.openforis.collect.datacleansing.DataCleansingMetadata in project collect by openforis.

the class DataCleansingManagerImpl method loadMetadata.

@Override
public DataCleansingMetadata loadMetadata(CollectSurvey survey) {
    List<DataQuery> dataQueries = dataQueryManager.loadBySurvey(survey);
    List<DataQueryType> dataQueryTypes = dataTypeManager.loadBySurvey(survey);
    for (DataQuery dataQuery : dataQueries) {
        Integer typeId = dataQuery.getTypeId();
        dataQuery.setType(typeId == null ? null : CollectionUtils.findItem(dataQueryTypes, typeId));
    }
    List<DataQueryGroup> dataQueryGroups = dataQueryGroupManager.loadBySurvey(survey);
    for (DataQueryGroup group : dataQueryGroups) {
        List<DataQuery> queries = group.getQueries();
        List<DataQuery> correctQueries = new ArrayList<DataQuery>(queries.size());
        for (DataQuery dataQuery : queries) {
            correctQueries.add(CollectionUtils.findItem(dataQueries, dataQuery.getId()));
        }
        group.removeAllQueries();
        group.allAllQueries(correctQueries);
    }
    List<DataCleansingStep> cleansingSteps = dataCleansingStepManager.loadBySurvey(survey);
    for (DataCleansingStep step : cleansingSteps) {
        step.setQuery(CollectionUtils.findItem(dataQueries, step.getQueryId()));
    }
    List<DataCleansingChain> cleansingChains = dataCleansingChainManager.loadBySurvey(survey);
    for (DataCleansingChain chain : cleansingChains) {
        List<DataCleansingStep> steps = chain.getSteps();
        List<DataCleansingStep> correctSteps = new ArrayList<DataCleansingStep>(steps.size());
        for (DataCleansingStep step : steps) {
            correctSteps.add(CollectionUtils.findItem(cleansingSteps, step.getId()));
        }
        chain.removeAllSteps();
        chain.addAllSteps(correctSteps);
    }
    DataCleansingMetadata metadata = new DataCleansingMetadata(survey, dataQueryTypes, dataQueries, dataQueryGroups, cleansingSteps, cleansingChains);
    return metadata;
}
Also used : ArrayList(java.util.ArrayList) DataQueryType(org.openforis.collect.datacleansing.DataQueryType) DataQueryGroup(org.openforis.collect.datacleansing.DataQueryGroup) DataCleansingMetadata(org.openforis.collect.datacleansing.DataCleansingMetadata) DataCleansingChain(org.openforis.collect.datacleansing.DataCleansingChain) DataCleansingStep(org.openforis.collect.datacleansing.DataCleansingStep) DataQuery(org.openforis.collect.datacleansing.DataQuery)

Example 2 with DataCleansingMetadata

use of org.openforis.collect.datacleansing.DataCleansingMetadata in project collect by openforis.

the class DataCleansingManagerImpl method duplicateMetadata.

@Transactional
@Override
public void duplicateMetadata(CollectSurvey fromSurvey, CollectSurvey toSurvey, User activeUser) {
    DataCleansingMetadata metadata = loadMetadata(fromSurvey);
    saveMetadata(toSurvey, metadata, false, activeUser);
}
Also used : DataCleansingMetadata(org.openforis.collect.datacleansing.DataCleansingMetadata) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with DataCleansingMetadata

use of org.openforis.collect.datacleansing.DataCleansingMetadata in project collect by openforis.

the class DataCleansingManagerImpl method moveMetadata.

@Transactional
@Override
public void moveMetadata(CollectSurvey fromSurvey, CollectSurvey toSurvey, User activeUser) {
    DataCleansingMetadata temporaryMetadata = loadMetadata(fromSurvey);
    saveMetadata(toSurvey, temporaryMetadata, false, activeUser);
    deleteMetadata(fromSurvey);
}
Also used : DataCleansingMetadata(org.openforis.collect.datacleansing.DataCleansingMetadata) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with DataCleansingMetadata

use of org.openforis.collect.datacleansing.DataCleansingMetadata in project collect by openforis.

the class JsonDataCleansingExportTask method execute.

@Override
protected void execute() throws Throwable {
    DataCleansingMetadata metadata = dataCleansingManager.loadMetadata(survey);
    if (!metadata.isEmpty()) {
        DataCleansingMetadataView metadataView = DataCleansingMetadataView.fromMetadata(metadata);
        ObjectMapper mapper = new ObjectMapper();
        mapper.writeValue(resultFile, metadataView);
    }
}
Also used : DataCleansingMetadata(org.openforis.collect.datacleansing.DataCleansingMetadata) DataCleansingMetadataView(org.openforis.collect.datacleansing.DataCleansingMetadataView) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with DataCleansingMetadata

use of org.openforis.collect.datacleansing.DataCleansingMetadata in project collect by openforis.

the class JsonDataCleansingImportTask method execute.

@Override
protected void execute() throws Throwable {
    ObjectMapper objectMapper = new ObjectMapper();
    objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
    DataCleansingMetadataView metadataView = objectMapper.readValue(inputFile, DataCleansingMetadataView.class);
    DataCleansingMetadata metadata = metadataView.toMetadata(survey);
    // TODO handle exceptions
    dataCleansingManager.saveMetadata(survey, metadata, true, activeUser);
}
Also used : DataCleansingMetadata(org.openforis.collect.datacleansing.DataCleansingMetadata) DataCleansingMetadataView(org.openforis.collect.datacleansing.DataCleansingMetadataView) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

DataCleansingMetadata (org.openforis.collect.datacleansing.DataCleansingMetadata)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 DataCleansingMetadataView (org.openforis.collect.datacleansing.DataCleansingMetadataView)2 Transactional (org.springframework.transaction.annotation.Transactional)2 ArrayList (java.util.ArrayList)1 DataCleansingChain (org.openforis.collect.datacleansing.DataCleansingChain)1 DataCleansingStep (org.openforis.collect.datacleansing.DataCleansingStep)1 DataQuery (org.openforis.collect.datacleansing.DataQuery)1 DataQueryGroup (org.openforis.collect.datacleansing.DataQueryGroup)1 DataQueryType (org.openforis.collect.datacleansing.DataQueryType)1