Search in sources :

Example 11 with SessionState

use of org.openforis.collect.web.session.SessionState in project collect by openforis.

the class CSVDataImportService method start.

@Secured("ROLE_ADMIN")
public DataImportStatusProxy start(String tempFileName, int parentEntityId, Step step, boolean transactional, boolean validateRecords, boolean insertNewRecords, String newRecordVersionName, boolean deleteExistingEntities) throws DataImportExeption {
    if (importJob == null || !importJob.isRunning()) {
        File importFile = new File(tempFileName);
        SessionState sessionState = sessionManager.getSessionState();
        CollectSurvey survey = sessionState.getActiveSurvey();
        if (transactional) {
            importJob = jobManager.createJob(TransactionalCSVDataImportJob.class);
        } else {
            importJob = jobManager.createJob(CSVDataImportJob.BEAN_NAME, CSVDataImportJob.class);
        }
        CSVDataImportSettings settings = new CSVDataImportSettings();
        settings.setRecordValidationEnabled(validateRecords);
        settings.setInsertNewRecords(insertNewRecords);
        settings.setNewRecordVersionName(newRecordVersionName);
        settings.setDeleteExistingEntities(deleteExistingEntities);
        Step[] steps = step == null ? Step.values() : new Step[] { step };
        CSVDataImportInput input = new CSVDataImportInput(importFile, survey, steps, parentEntityId, settings);
        importJob.setInput(input);
        jobManager.start(importJob);
    }
    return getStatus();
}
Also used : TransactionalCSVDataImportJob(org.openforis.collect.io.data.TransactionalCSVDataImportJob) CSVDataImportJob(org.openforis.collect.io.data.CSVDataImportJob) SessionState(org.openforis.collect.web.session.SessionState) CSVDataImportInput(org.openforis.collect.io.data.CSVDataImportJob.CSVDataImportInput) Step(org.openforis.collect.model.CollectRecord.Step) CollectSurvey(org.openforis.collect.model.CollectSurvey) TransactionalCSVDataImportJob(org.openforis.collect.io.data.TransactionalCSVDataImportJob) CSVDataImportSettings(org.openforis.collect.io.data.csv.CSVDataImportSettings) File(java.io.File) Secured(org.springframework.security.access.annotation.Secured)

Example 12 with SessionState

use of org.openforis.collect.web.session.SessionState in project collect by openforis.

the class SpeciesService method getActiveSurvey.

private CollectSurvey getActiveSurvey() {
    SessionState sessionState = sessionManager.getSessionState();
    CollectSurvey activeSurvey = sessionState.getActiveSurvey();
    return activeSurvey;
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 13 with SessionState

use of org.openforis.collect.web.session.SessionState in project collect by openforis.

the class RecordFileController method download.

@RequestMapping(value = "/downloadRecordFile.htm", method = RequestMethod.POST)
public void download(HttpServletRequest request, HttpServletResponse response, @RequestParam("nodeId") Integer nodeId) throws Exception {
    SessionState sessionState = getSessionState(request);
    CollectRecord record = sessionState.getActiveRecord();
    File file = fileManager.getFile(record, nodeId);
    if (file != null && file.exists()) {
        Controllers.writeFileToResponse(response, file);
    } else {
        Integer recordId = record == null ? null : record.getId();
        String fileName = file == null ? null : file.getName();
        Exception e = new Exception("File not found: " + fileName + " record id: " + recordId + " node id: " + nodeId);
        LOG.error(e);
        throw e;
    }
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord) File(java.io.File) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with SessionState

use of org.openforis.collect.web.session.SessionState in project collect by openforis.

the class SessionController method getLoggedUser.

@RequestMapping(value = "user", method = GET)
@ResponseBody
public UserForm getLoggedUser(HttpServletRequest request, HttpServletResponse response) {
    SessionState sessionState = sessionManager.getSessionState();
    User user = sessionState == null ? null : sessionState.getUser();
    if (user == null) {
        HttpResponses.setNoContentStatus(response);
        return null;
    }
    if (sessionState.getLocale() == null) {
        sessionState.setLocale(request.getLocale());
    }
    return new UserController.UserForm(user);
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) User(org.openforis.collect.model.User) UserForm(org.openforis.collect.web.controller.UserController.UserForm) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 15 with SessionState

use of org.openforis.collect.web.session.SessionState in project collect by openforis.

the class ValidationController method validateAllRecords.

@RequestMapping(value = "/validateAllRecords.htm", method = RequestMethod.GET)
public void validateAllRecords(HttpServletRequest request, HttpServletResponse response, @RequestParam String s, @RequestParam String r) throws IOException {
    final ServletOutputStream outputStream = response.getOutputStream();
    try {
        if (s == null || r == null) {
            outputStream.println("Wrong parameters: please specify 's' (survey) and 'r' (root entity name).");
            return;
        }
        SessionState sessionState = getSessionState(request);
        final User user = sessionState.getUser();
        final String sessionId = sessionState.getSessionId();
        print(outputStream, "Starting validation of all records: ");
        final CollectSurvey survey = surveyManager.get(s);
        if (survey == null) {
            print(outputStream, "Survey not found");
            return;
        }
        RecordFilter filter = new RecordFilter(survey);
        filter.setRootEntityId(survey.getSchema().getRootEntityDefinition(r).getId());
        final ValidationMessageBuilder validationMessageHelper = ValidationMessageBuilder.createInstance(messageContextHolder);
        recordManager.visitSummaries(filter, null, new Visitor<CollectRecordSummary>() {

            public void visit(CollectRecordSummary summary) {
                try {
                    String recordKey = validationMessageHelper.getRecordKey(summary);
                    long start = System.currentTimeMillis();
                    print(outputStream, "Start validating record: " + recordKey);
                    Integer id = summary.getId();
                    Step step = summary.getStep();
                    recordManager.validateAndSave(survey, user, sessionId, id, step);
                    long elapsedMillis = System.currentTimeMillis() - start;
                    print(outputStream, "Validation of record " + recordKey + " completed in " + elapsedMillis + " millis");
                } catch (Exception e) {
                    try {
                        String message = "ERROR validating record " + summary.getId();
                        outputStream.println(message);
                        LOG.error(message);
                    } catch (IOException e1) {
                    }
                }
            }
        });
        print(outputStream, "End of validation of all records.");
    } catch (Exception e) {
        outputStream.println("ERROR - Validation of records not completed: " + e.getMessage());
        LOG.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}
Also used : ValidationMessageBuilder(org.openforis.collect.model.validation.ValidationMessageBuilder) SessionState(org.openforis.collect.web.session.SessionState) User(org.openforis.collect.model.User) ServletOutputStream(javax.servlet.ServletOutputStream) Step(org.openforis.collect.model.CollectRecord.Step) IOException(java.io.IOException) IOException(java.io.IOException) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordFilter(org.openforis.collect.model.RecordFilter) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SessionState (org.openforis.collect.web.session.SessionState)44 CollectSurvey (org.openforis.collect.model.CollectSurvey)18 User (org.openforis.collect.model.User)16 CollectRecord (org.openforis.collect.model.CollectRecord)15 Secured (org.springframework.security.access.annotation.Secured)13 Step (org.openforis.collect.model.CollectRecord.Step)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 RecordFilter (org.openforis.collect.model.RecordFilter)7 Locale (java.util.Locale)5 RecordStep (org.openforis.collect.event.RecordStep)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 File (java.io.File)3 HashMap (java.util.HashMap)3 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)3 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)3 Transactional (org.springframework.transaction.annotation.Transactional)3 IOException (java.io.IOException)2 Date (java.util.Date)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 BulkRecordMoveJob (org.openforis.collect.io.data.BulkRecordMoveJob)2