Search in sources :

Example 1 with SamplingDesignImportStatus

use of org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportStatus in project collect by openforis.

the class SamplingDesignImportProcessIntegrationTest method testImport.

@Test
public void testImport() throws Exception {
    SamplingDesignImportProcess process = importCSVFile(VALID_TEST_CSV);
    SamplingDesignImportStatus status = process.getStatus();
    assertTrue(status.isComplete());
    assertTrue(status.getSkippedRows().isEmpty());
    assertEquals(27, status.getProcessed());
    SamplingDesignSummaries samplingDesignSummaries = samplingDesignManager.loadBySurvey(survey.getId(), 0, 30);
    assertNotNull(samplingDesignSummaries);
    assertEquals(26, samplingDesignSummaries.getTotalCount());
    List<SamplingDesignItem> items = samplingDesignSummaries.getRecords();
    assertNotNull(findItem(items, -10000d, 100000d, "1_01", "1"));
    assertNotNull(findItem(items, 200000d, -2000000d, "1_02", "1"));
    assertNotNull(findItem(items, 806090d, 9320050d, "10_114", "7"));
    assertNotNull(findItem(items, 805680d, 9305020d, "10_117", "6"));
}
Also used : SamplingDesignImportProcess(org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportProcess) SamplingDesignSummaries(org.openforis.collect.model.SamplingDesignSummaries) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem) SamplingDesignImportStatus(org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportStatus) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 2 with SamplingDesignImportStatus

use of org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportStatus in project collect by openforis.

the class SamplingDesignImportProcessIntegrationTest method testFlatImport.

@Test
public void testFlatImport() throws Exception {
    SamplingDesignImportProcess process = importCSVFile(VALID_FLAT_TEST_CSV);
    SamplingDesignImportStatus status = process.getStatus();
    assertTrue(status.isComplete());
    assertTrue(status.getSkippedRows().isEmpty());
    SamplingDesignSummaries samplingDesignSummaries = samplingDesignManager.loadBySurvey(survey.getId(), 0, 30);
    assertNotNull(samplingDesignSummaries);
    assertEquals(6, samplingDesignSummaries.getTotalCount());
    List<SamplingDesignItem> items = samplingDesignSummaries.getRecords();
    {
        SamplingDesignItem item = findItem(items, -10000d, 100000d, "1_01");
        assertNotNull(item);
        assertEquals(Arrays.asList("001", "002"), item.getInfoAttributes().subList(0, 2));
    }
    assertNotNull(findItem(items, 200000d, -2000000d, "1_02"));
    assertNotNull(findItem(items, 806340d, 9320050d, "10_114"));
    assertNotNull(findItem(items, 806680d, 9305020d, "10_117"));
    assertNotNull(findItem(items, 80.1234d, -6.908d, "10_115"));
}
Also used : SamplingDesignImportProcess(org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportProcess) SamplingDesignSummaries(org.openforis.collect.model.SamplingDesignSummaries) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem) SamplingDesignImportStatus(org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportStatus) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 3 with SamplingDesignImportStatus

use of org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportStatus in project collect by openforis.

the class SamplingDesignImportProcessIntegrationTest method testInvalidData.

@Test
public void testInvalidData() throws Exception {
    SamplingDesignImportProcess process = importCSVFile(INVALID_TEST_CSV);
    SamplingDesignImportStatus status = process.getStatus();
    assertTrue(status.isError());
    List<ParsingError> errors = status.getErrors();
    assertEquals(6, errors.size());
    assertTrue(containsError(errors, 3, SamplingDesignFileColumn.LEVEL_2, ErrorType.DUPLICATE_VALUE));
    assertTrue(containsError(errors, 4, SamplingDesignFileColumn.LEVEL_2, ErrorType.DUPLICATE_VALUE));
    assertTrue(containsError(errors, 14, SamplingDesignFileColumn.LEVEL_2, ErrorType.EMPTY));
    assertTrue(containsError(errors, 17, SamplingDesignFileColumn.LEVEL_1, ErrorType.EMPTY));
    assertTrue(containsError(errors, 22, SamplingDesignFileColumn.X, ErrorType.EMPTY));
    assertTrue(containsError(errors, 23, SamplingDesignFileColumn.Y, ErrorType.EMPTY));
}
Also used : ParsingError(org.openforis.collect.io.metadata.parsing.ParsingError) SamplingDesignImportProcess(org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportProcess) SamplingDesignImportStatus(org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportStatus) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Example 4 with SamplingDesignImportStatus

use of org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportStatus in project collect by openforis.

the class SamplingDesignImportService method start.

@Secured("ROLE_ADMIN")
public SamplingDesignImportStatusProxy start(String tempFileName, int surveyId, boolean temporary, boolean overwriteAll) throws DataImportExeption, SurveyImportException {
    if (importProcess == null || !importProcess.getStatus().isRunning()) {
        File importFile = new File(tempFileName);
        CollectSurvey survey = temporary ? surveyManager.loadSurvey(surveyId) : surveyManager.getById(surveyId);
        importProcess = new SamplingDesignImportProcess(samplingDesignManager, surveyManager, survey, importFile, overwriteAll);
        importProcess.init();
        SamplingDesignImportStatus status = importProcess.getStatus();
        if (status != null && !importProcess.getStatus().isError()) {
            startProcessThread();
        }
    }
    return getStatus();
}
Also used : SamplingDesignImportProcess(org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportProcess) CollectSurvey(org.openforis.collect.model.CollectSurvey) File(java.io.File) SamplingDesignImportStatus(org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportStatus) Secured(org.springframework.security.access.annotation.Secured)

Aggregations

SamplingDesignImportProcess (org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportProcess)4 SamplingDesignImportStatus (org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportStatus)4 Test (org.junit.Test)3 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)3 SamplingDesignItem (org.openforis.collect.model.SamplingDesignItem)2 SamplingDesignSummaries (org.openforis.collect.model.SamplingDesignSummaries)2 File (java.io.File)1 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)1 CollectSurvey (org.openforis.collect.model.CollectSurvey)1 Secured (org.springframework.security.access.annotation.Secured)1