Search in sources :

Example 31 with User

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

the class LocalUserManager method save.

@Override
@Transactional(readOnly = false, propagation = REQUIRED)
public User save(User user, User createdByUser) {
    Integer userId = user.getId();
    String rawPassword = user.getRawPassword();
    if (StringUtils.isBlank(rawPassword)) {
        if (userId == null) {
            throw new IllegalArgumentException("Blank password specified for a new user");
        } else {
            // preserve old password
            User oldUser = userDao.loadById(userId);
            user.setPassword(oldUser.getPassword());
        }
    } else {
        String encodedPassword = checkAndEncodePassword(rawPassword);
        user.setPassword(encodedPassword);
    }
    if (userId == null) {
        userDao.insert(user);
        groupManager.createDefaultPrivateUserGroup(user, createdByUser);
        groupManager.joinToDefaultPublicGroup(user, UserGroupRole.ADMINISTRATOR);
    } else {
        userDao.update(user);
    }
    // do not store raw password in cache
    user.setRawPassword(null);
    updateCache(user);
    return user;
}
Also used : User(org.openforis.collect.model.User) Transactional(org.springframework.transaction.annotation.Transactional)

Example 32 with User

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

the class RecordManager method loadDistinctOwners.

public Set<User> loadDistinctOwners(RecordFilter recordFilter) {
    Set<Integer> ownerIds = recordDao.loadDistinctOwnerIds(recordFilter);
    Set<User> owners = new HashSet<User>(ownerIds.size());
    for (Integer ownerId : ownerIds) {
        User owner = userManager.loadById(ownerId);
        owners.add(owner);
    }
    return owners;
}
Also used : User(org.openforis.collect.model.User) HashSet(java.util.HashSet)

Example 33 with User

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

the class RecordManager method save.

@Transactional(readOnly = false, propagation = REQUIRED)
public void save(CollectRecord record, String sessionId) throws RecordPersistenceException {
    User lockingUser = record.getModifiedBy();
    save(record, lockingUser, sessionId, true);
}
Also used : User(org.openforis.collect.model.User) Transactional(org.springframework.transaction.annotation.Transactional)

Example 34 with User

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

the class RecordManager method delete.

@Transactional(readOnly = false, propagation = REQUIRED)
public void delete(int recordId) throws RecordPersistenceException {
    if (isLockingEnabled() && lockManager.isLocked(recordId)) {
        RecordLock lock = lockManager.getLock(recordId);
        User lockUser = lock.getUser();
        throw new RecordLockedException(lockUser.getUsername());
    } else {
        recordDao.delete(recordId);
    }
}
Also used : User(org.openforis.collect.model.User) RecordLockedException(org.openforis.collect.persistence.RecordLockedException) RecordLock(org.openforis.collect.model.RecordLock) Transactional(org.springframework.transaction.annotation.Transactional)

Example 35 with User

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

the class UserDao method loadAll.

@Override
public List<User> loadAll() {
    UserDSLContext dsl = dsl();
    Result<OfcUserRecord> r = dsl.selectFrom(OFC_USER).orderBy(OFC_USER.USERNAME).fetch();
    List<User> users = r != null ? dsl.fromResult(r) : null;
    return users;
}
Also used : User(org.openforis.collect.model.User) UserDSLContext(org.openforis.collect.persistence.UserDao.UserDSLContext) OfcUserRecord(org.openforis.collect.persistence.jooq.tables.records.OfcUserRecord)

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