Search in sources :

Example 66 with User

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

the class UserSessionService method changePassword.

public OperationResult changePassword(String oldPassword, String newPassword) throws UserPersistenceException {
    SessionState sessionState = sessionManager.getSessionState();
    User currentUser = sessionState.getUser();
    return userManager.changePassword(currentUser.getUsername(), oldPassword, newPassword);
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) User(org.openforis.collect.model.User)

Example 67 with User

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

the class BackupRestoreController method createRecordFilter.

private RecordFilter createRecordFilter(CollectSurvey survey, Integer rootEntityId, boolean onlyOwnedRecords, String[] rootEntityKeyValues) {
    RecordFilter recordFilter = new RecordFilter(survey, rootEntityId);
    // filter by record owner
    if (onlyOwnedRecords) {
        SessionState sessionState = sessionManager.getSessionState();
        User user = sessionState.getUser();
        recordFilter.setOwnerId(user.getId());
    }
    // filter by root entity keys
    recordFilter.setKeyValues(rootEntityKeyValues);
    return recordFilter;
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) User(org.openforis.collect.model.User) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 68 with User

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

the class RecordGenerator method generate.

@Transactional
public CollectRecord generate(int surveyId, NewRecordParameters parameters, RecordKey recordKey) {
    CollectSurvey survey = surveyManager.getById(surveyId);
    User user = loadUser(parameters.getUserId(), parameters.getUsername());
    CollectRecord record = createRecord(survey, user, recordKey);
    if (parameters.isAddSecondLevelEntities()) {
        addSecondLevelEntities(record, recordKey);
    }
    recordManager.save(record);
    return record;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) CollectSurvey(org.openforis.collect.model.CollectSurvey) Transactional(org.springframework.transaction.annotation.Transactional)

Example 69 with User

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

the class SessionManager method checkIsActiveRecordLocked.

public void checkIsActiveRecordLocked() throws RecordUnlockedException {
    SessionState sessionState = getSessionState();
    CollectRecord record = sessionState.getActiveRecord();
    if (record == null) {
        throw new RecordUnlockedException();
    } else if (record.getId() != null) {
        User user = sessionState.getUser();
        String lockId = sessionState.getSessionId();
        try {
            recordManager.checkIsLocked(record.getId(), user, lockId);
            sessionState.keepActiveRecordAlive();
        } catch (RecordUnlockedException e) {
            clearActiveRecord();
            throw e;
        }
    }
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) RecordUnlockedException(org.openforis.collect.persistence.RecordUnlockedException)

Example 70 with User

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

the class SessionManager method loadAuthenticatedUser.

private User loadAuthenticatedUser() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
    if (authentication != null) {
        String name = authentication.getName();
        User user = userManager.loadByUserName(name);
        return user;
    } else {
        return null;
    }
}
Also used : User(org.openforis.collect.model.User) Authentication(org.springframework.security.core.Authentication)

Aggregations

User (org.openforis.collect.model.User)71 CollectRecord (org.openforis.collect.model.CollectRecord)19 CollectSurvey (org.openforis.collect.model.CollectSurvey)19 SessionState (org.openforis.collect.web.session.SessionState)16 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)14 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)12 Transactional (org.springframework.transaction.annotation.Transactional)11 RecordFilter (org.openforis.collect.model.RecordFilter)10 Test (org.junit.Test)8 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)6 RecordUpdater (org.openforis.collect.model.RecordUpdater)6 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)5 Date (java.util.Date)4 UserGroup (org.openforis.collect.model.UserGroup)4 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)4 Secured (org.springframework.security.access.annotation.Secured)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 RecordStep (org.openforis.collect.event.RecordStep)3 Step (org.openforis.collect.model.CollectRecord.Step)3