Search in sources :

Example 26 with UserGroup

use of org.openforis.collect.model.UserGroup in project collect by openforis.

the class SurveyCreator method generateSimpleSurvey.

public CollectSurvey generateSimpleSurvey(SimpleSurveyCreationParameters parameters) throws SurveyStoreException, SurveyImportException {
    String projectName = parameters.getProjectName();
    String internalName = ObjectUtils.defaultIfNull(parameters.getName(), SurveyObjects.adjustInternalName(projectName));
    CollectSurvey existingSurvey = surveyManager.get(internalName);
    if (existingSurvey != null) {
        // TODO move it to validator
        throw new IllegalArgumentException(String.format("Survey with name %s already existing", internalName));
    }
    CollectSurvey survey = createTemporarySimpleSurvey(internalName, parameters.getCodeLists());
    survey.setProjectName(survey.getDefaultLanguage(), projectName);
    survey.setDescription(survey.getDefaultLanguage(), parameters.getDescription());
    UserGroup userGroup = userGroupManager.loadById(parameters.getUserGroupId());
    survey.setUserGroup(userGroup);
    CeoApplicationOptions ceoApplicationOptions = new CeoApplicationOptions();
    ceoApplicationOptions.setBaseMapSource(parameters.getCeoSettings().getBaseMapSource());
    ceoApplicationOptions.setImageryYear(parameters.getCeoSettings().getImageryYear());
    ceoApplicationOptions.setStackingProfile(parameters.getCeoSettings().getStackingProfile());
    SamplingPointGenerationSettings samplingPointGenerationSettings = parameters.getSamplingPointGenerationSettings();
    ceoApplicationOptions.setSamplingPointDataConfiguration(samplingPointGenerationSettings);
    survey.addApplicationOptions(ceoApplicationOptions);
    surveyManager.save(survey);
    SamplingPointDataGenerator generator = new SamplingPointDataGenerator(coordinateOperations, survey, parameters.getSamplingPointsByLevel(), samplingPointGenerationSettings);
    List<SamplingDesignItem> items = generator.generate();
    samplingDesignManager.insert(survey, items, true);
    return survey;
}
Also used : SamplingPointGenerationSettings(org.openforis.collect.metamodel.samplingdesign.SamplingPointGenerationSettings) CeoApplicationOptions(org.openforis.collect.persistence.xml.CeoApplicationOptions) SamplingPointDataGenerator(org.openforis.collect.io.metadata.samplingpointdata.SamplingPointDataGenerator) CollectSurvey(org.openforis.collect.model.CollectSurvey) SamplingDesignItem(org.openforis.collect.model.SamplingDesignItem) UserGroup(org.openforis.collect.model.UserGroup)

Aggregations

UserGroup (org.openforis.collect.model.UserGroup)26 CollectSurvey (org.openforis.collect.model.CollectSurvey)7 UserInGroup (org.openforis.collect.model.UserInGroup)7 ArrayList (java.util.ArrayList)6 User (org.openforis.collect.model.User)4 Timestamp (java.sql.Timestamp)3 LabelledItem (org.openforis.collect.designer.model.LabelledItem)3 Transactional (org.springframework.transaction.annotation.Transactional)3 Date (java.util.Date)2 HashSet (java.util.HashSet)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 AbstractSurveyRestoreJob (org.openforis.collect.io.AbstractSurveyRestoreJob)2 XMLSurveyRestoreJob (org.openforis.collect.io.XMLSurveyRestoreJob)2 SurveySummary (org.openforis.collect.model.SurveySummary)2 Response (org.openforis.commons.web.Response)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 File (java.io.File)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1