Search in sources :

Example 21 with SessionState

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

the class SessionController method initialize.

@RequestMapping(value = "initialize", method = POST)
@ResponseBody
public UserForm initialize(HttpServletRequest request) {
    SessionState sessionState = sessionManager.getSessionState();
    User user = sessionState.getUser();
    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 22 with SessionState

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

the class UnlockController method clearActiveRecord.

@RequestMapping(value = "/clearActiveRecord.htm", method = RequestMethod.POST)
@ResponseBody
public String clearActiveRecord(HttpServletRequest request) {
    try {
        HttpSession session = request.getSession();
        if (session != null) {
            SessionState sessionState = (SessionState) session.getAttribute(SessionState.SESSION_ATTRIBUTE_NAME);
            if (sessionState != null) {
                CollectRecord activeRecord = sessionState.getActiveRecord();
                if (activeRecord != null) {
                    Integer recordId = activeRecord.getId();
                    if (recordId != null) {
                        recordManager.releaseLock(recordId);
                    }
                    // clear session state
                    sessionState.setActiveRecord(null);
                }
            }
        }
        return "ok";
    } catch (Exception e) {
        LOG.error(e);
        throw new RuntimeException(e);
    }
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord) HttpSession(javax.servlet.http.HttpSession) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 23 with SessionState

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

the class ValidationController method validationReport.

@RequestMapping(value = "/validationReport", method = RequestMethod.GET)
public void validationReport(HttpServletRequest request, HttpServletResponse response, @RequestParam(required = false) String surveyName, @RequestParam(required = false) Integer rootEntityId, @RequestParam(required = false, defaultValue = "en_US") String locale, String[] recordKeys, @RequestParam(required = false) Date modifiedSince) throws IOException {
    ServletOutputStream outputStream = response.getOutputStream();
    try {
        if (surveyName == null || rootEntityId == null || locale == null) {
            outputStream.println("Wrong parameters: please specify 'surveyName' (name of the survey), 'rootEntityId' (root entity id) and 'locale' string rappresentation of locale");
            return;
        }
        CollectSurvey survey = surveyManager.get(surveyName);
        if (survey == null) {
            print(outputStream, "Survey not found");
            return;
        }
        response.setContentType("text/csv");
        String outputFileName = String.format("%s_validation_report_%s.csv", surveyName, Dates.formatDateTime(new Date()));
        response.setHeader("Content-Disposition", "attachment; fileName=" + outputFileName);
        SessionState sessionState = getSessionState(request);
        User user = sessionState.getUser();
        String sessionId = sessionState.getSessionId();
        RecordFilter recordFilter = new RecordFilter(survey, rootEntityId);
        recordFilter.setKeyValues(recordKeys);
        recordFilter.setModifiedSince(modifiedSince);
        if (user.getRole() == UserRole.ENTRY_LIMITED) {
            recordFilter.setOwnerId(user.getId());
        }
        ValidationReportProcess process = new ValidationReportProcess(outputStream, recordManager, messageContextHolder, ReportType.CSV, user, sessionId, recordFilter, true, LocaleUtils.toLocale(locale));
        process.init();
        process.call();
    } catch (Exception e) {
        // outputStream.println("ERROR - Validation of records not completed: " + e.getMessage());
        LOG.error("ERROR - Validation of records not completed: " + e.getMessage(), e);
        throw new RuntimeException(e);
    }
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) User(org.openforis.collect.model.User) ServletOutputStream(javax.servlet.ServletOutputStream) ValidationReportProcess(org.openforis.collect.manager.ValidationReportProcess) CollectSurvey(org.openforis.collect.model.CollectSurvey) Date(java.util.Date) RecordFilter(org.openforis.collect.model.RecordFilter) IOException(java.io.IOException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 24 with SessionState

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

the class SessionListener method sessionDestroyed.

@Override
public void sessionDestroyed(HttpSessionEvent se) {
    SessionManager sessionManager = getSessionManager(se);
    try {
        SessionState sessionState = sessionManager.getSessionState();
        User user = null;
        if (sessionState != null) {
            user = sessionState.getUser();
            if (user != null) {
                sessionManager.sessionDestroyed();
            }
        }
        if (LOG.isInfoEnabled()) {
            String message = "Session destroyed: " + se.getSession().getId();
            if (user != null) {
                message += " username: " + user.getUsername();
            }
            LOG.info(message);
        }
    } catch (InvalidSessionException e) {
    // ignore it, session was anonymous
    }
}
Also used : InvalidSessionException(org.openforis.collect.web.session.InvalidSessionException) SessionState(org.openforis.collect.web.session.SessionState) User(org.openforis.collect.model.User) SessionManager(org.openforis.collect.manager.SessionManager)

Example 25 with SessionState

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

the class RecordController method updateOwner.

@RequestMapping(value = "survey/{surveyId}/data/update/records/{recordId}", method = POST, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public Response updateOwner(@PathVariable("surveyId") int surveyId, @PathVariable("recordId") int recordId, @RequestBody Map<String, String> body) throws RecordLockedException, MultipleEditException {
    String ownerIdStr = body.get("ownerId");
    Integer ownerId = ownerIdStr == null ? null : Integer.parseInt(ownerIdStr);
    CollectSurvey survey = surveyManager.getById(surveyId);
    SessionState sessionState = sessionManager.getSessionState();
    recordManager.assignOwner(survey, recordId, ownerId, sessionState.getUser(), sessionState.getSessionId());
    return new Response();
}
Also used : Response(org.openforis.commons.web.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) SessionState(org.openforis.collect.web.session.SessionState) CollectSurvey(org.openforis.collect.model.CollectSurvey) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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