Search in sources :

Example 1 with SpeciesBackupImportTask

use of org.openforis.collect.io.metadata.species.SpeciesBackupImportTask in project collect by openforis.

the class SurveyRestoreJob method initializeTask.

@Override
protected void initializeTask(Worker task) {
    if (task instanceof SurveyBackupInfoExtractorTask) {
        SurveyBackupInfoExtractorTask t = (SurveyBackupInfoExtractorTask) task;
        File infoFile = backupFileExtractor.extract(SurveyBackupJob.INFO_FILE_NAME);
        t.setFile(infoFile);
    } else if (task instanceof IdmlUnmarshallTask) {
        IdmlUnmarshallTask t = (IdmlUnmarshallTask) task;
        File idmlFile = backupFileExtractor.extractIdmlFile();
        t.setFile(idmlFile);
        t.setSurveyManager(surveyManager);
        t.setValidate(false);
    } else if (task instanceof IdmlImportTask) {
        IdmlImportTask t = (IdmlImportTask) task;
        t.setSurveyManager(surveyManager);
        File idmlFile = backupFileExtractor.extractIdmlFile();
        t.setFile(idmlFile);
        t.setSurveyUri(surveyUri);
        t.setSurveyName(surveyName);
        t.setImportInPublishedSurvey(restoreIntoPublishedSurvey);
        t.setValidate(false);
        t.setUserGroup(userGroup);
        t.setActiveUser(activeUser);
    } else if (task instanceof CodeListImagesImportTask) {
        CodeListImagesImportTask t = (CodeListImagesImportTask) task;
        t.setCodeListManager(codeListManager);
        t.setZipFile(zipFile);
        t.setSurvey(survey);
    } else if (task instanceof SamplingDesignCleanTask) {
        SamplingDesignCleanTask t = (SamplingDesignCleanTask) task;
        t.setSurveyId(survey.getId());
    } else if (task instanceof SamplingDesignImportTask) {
        SamplingDesignImportTask t = (SamplingDesignImportTask) task;
        File samplingDesignFile = backupFileExtractor.extract(SurveyBackupJob.SAMPLING_DESIGN_ENTRY_NAME);
        t.setSamplingDesignManager(samplingDesignManager);
        t.setFile(samplingDesignFile);
        t.setSkipValidation(true);
        t.setOverwriteAll(true);
        t.setSurvey(survey);
    } else if (task instanceof SpeciesBackupImportTask) {
        SpeciesBackupImportTask t = (SpeciesBackupImportTask) task;
        t.setSpeciesManager(speciesManager);
        t.setSurvey(survey);
    } else if (task instanceof SurveyFilesImportTask) {
        SurveyFilesImportTask t = (SurveyFilesImportTask) task;
        t.setSurvey(survey);
        t.setBackupFileExtractor(backupFileExtractor);
    } else if (task instanceof DataCleansingImportTask) {
        DataCleansingImportTask t = (DataCleansingImportTask) task;
        t.setSurvey(survey);
        t.setInputFile(backupFileExtractor.extract(SurveyBackupJob.DATA_CLEANSING_METADATA_ENTRY_NAME));
    }
    super.initializeTask(task);
}
Also used : SurveyBackupInfoExtractorTask(org.openforis.collect.io.internal.SurveyBackupInfoExtractorTask) SpeciesBackupImportTask(org.openforis.collect.io.metadata.species.SpeciesBackupImportTask) SurveyFilesImportTask(org.openforis.collect.io.metadata.SurveyFilesImportTask) CodeListImagesImportTask(org.openforis.collect.io.metadata.CodeListImagesImportTask) SamplingDesignImportTask(org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportTask) IdmlUnmarshallTask(org.openforis.collect.io.metadata.IdmlUnmarshallTask) ZipFile(java.util.zip.ZipFile) File(java.io.File) DataCleansingImportTask(org.openforis.collect.datacleansing.io.DataCleansingImportTask) IdmlImportTask(org.openforis.collect.io.metadata.IdmlImportTask)

Example 2 with SpeciesBackupImportTask

use of org.openforis.collect.io.metadata.species.SpeciesBackupImportTask in project collect by openforis.

the class SurveyRestoreJob method addSpeciesImportTasks.

private void addSpeciesImportTasks() {
    List<String> speciesFilesNames = backupFileExtractor.listSpeciesEntryNames();
    for (String speciesFileName : speciesFilesNames) {
        String taxonomyName = FilenameUtils.getBaseName(speciesFileName);
        File file = backupFileExtractor.extract(speciesFileName);
        if (file.length() > 0) {
            SpeciesBackupImportTask task = createTask(SpeciesBackupImportTask.class);
            task.setFile(file);
            task.setTaxonomyName(taxonomyName);
            task.setOverwriteAll(true);
            addTask(task);
        }
    }
}
Also used : SpeciesBackupImportTask(org.openforis.collect.io.metadata.species.SpeciesBackupImportTask) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 3 with SpeciesBackupImportTask

use of org.openforis.collect.io.metadata.species.SpeciesBackupImportTask in project collect by openforis.

the class SpeciesBackupImportJobIntegrationTest method testSpeciesImport.

@Test
public void testSpeciesImport() throws Exception {
    SpeciesBackupImportJob job = importCSVFile(VALID_TEST_CSV);
    assertTrue(job.isCompleted());
    SpeciesBackupImportTask task = (SpeciesBackupImportTask) job.getTasks().get(0);
    assertTrue(task.getSkippedRows().isEmpty());
    TaxonomyDefinition taxonomyDef = survey.getReferenceDataSchema().getTaxonomyDefinition(TEST_TAXONOMY_NAME);
    assertEquals(Arrays.asList("info1", "info2"), taxonomyDef.getAttributeNames());
    {
        String code = "OLE/CAP/macrocarpa";
        TaxonOccurrence occurrence = findByCode(code);
        TaxonOccurrence expected = new TaxonOccurrence(code, "Olea capensis ssp. macrocarpa");
        expected.setInfoAttributes(Arrays.asList("info_value_1", "info_value_2"));
        expected.setTaxonRank(SUBSPECIES);
        assertEquals(expected, occurrence);
    }
    {
        String code = "ALB/ADI";
        TaxonOccurrence occurrence = findByCode(code);
        TaxonOccurrence expected = new TaxonOccurrence(code, "Albizia adianthifolia");
        expected.setInfoAttributes(Arrays.asList("info_value_3", null));
        expected.setTaxonRank(SPECIES);
        assertEquals(expected, occurrence);
    }
}
Also used : SpeciesBackupImportTask(org.openforis.collect.io.metadata.species.SpeciesBackupImportTask) TaxonOccurrence(org.openforis.idm.model.TaxonOccurrence) TaxonomyDefinition(org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition) SpeciesBackupImportJob(org.openforis.collect.io.metadata.species.SpeciesBackupImportJob) CollectIntegrationTest(org.openforis.collect.CollectIntegrationTest) Test(org.junit.Test)

Aggregations

SpeciesBackupImportTask (org.openforis.collect.io.metadata.species.SpeciesBackupImportTask)3 File (java.io.File)2 ZipFile (java.util.zip.ZipFile)2 Test (org.junit.Test)1 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)1 DataCleansingImportTask (org.openforis.collect.datacleansing.io.DataCleansingImportTask)1 SurveyBackupInfoExtractorTask (org.openforis.collect.io.internal.SurveyBackupInfoExtractorTask)1 CodeListImagesImportTask (org.openforis.collect.io.metadata.CodeListImagesImportTask)1 IdmlImportTask (org.openforis.collect.io.metadata.IdmlImportTask)1 IdmlUnmarshallTask (org.openforis.collect.io.metadata.IdmlUnmarshallTask)1 SurveyFilesImportTask (org.openforis.collect.io.metadata.SurveyFilesImportTask)1 SamplingDesignImportTask (org.openforis.collect.io.metadata.samplingdesign.SamplingDesignImportTask)1 SpeciesBackupImportJob (org.openforis.collect.io.metadata.species.SpeciesBackupImportJob)1 TaxonomyDefinition (org.openforis.idm.metamodel.ReferenceDataSchema.TaxonomyDefinition)1 TaxonOccurrence (org.openforis.idm.model.TaxonOccurrence)1