Search in sources :

Example 1 with User

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

the class RecordDao method createDetachedUser.

private static User createDetachedUser(Integer userId) {
    if (userId == null) {
        return null;
    }
    User user = new User();
    user.setId(userId);
    return user;
}
Also used : User(org.openforis.collect.model.User)

Example 2 with User

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

the class UserDao method loadByUserName.

public User loadByUserName(String userName, Boolean enabled) {
    UserDSLContext dsl = dsl();
    SelectConditionStep<OfcUserRecord> query = dsl.selectFrom(OFC_USER).where(OFC_USER.USERNAME.equal(userName));
    if (enabled != null) {
        String enabledFlag = enabled ? "Y" : "N";
        query.and(OFC_USER.ENABLED.equal(enabledFlag));
    }
    Record r = query.fetchOne();
    User user = r != null ? dsl.fromRecord(r) : null;
    return user;
}
Also used : User(org.openforis.collect.model.User) UserDSLContext(org.openforis.collect.persistence.UserDao.UserDSLContext) OfcUserRecord(org.openforis.collect.persistence.jooq.tables.records.OfcUserRecord) Record(org.jooq.Record) OfcUserRecord(org.openforis.collect.persistence.jooq.tables.records.OfcUserRecord) OfcUserRoleRecord(org.openforis.collect.persistence.jooq.tables.records.OfcUserRoleRecord)

Example 3 with User

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

the class DataExportService 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 4 with User

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

the class DataService method promote.

protected void promote(Step to) throws RecordPersistenceException, RecordPromoteException {
    sessionManager.checkIsActiveRecordLocked();
    SessionState sessionState = sessionManager.getSessionState();
    CollectRecord record = sessionState.getActiveRecord();
    String userName = sessionState.getUser().getUsername();
    Step currentStep = record.getStep();
    Step exptectedStep = to.getPrevious();
    if (exptectedStep == currentStep) {
        User user = sessionState.getUser();
        sessionEventDispatcher.recordSaved(record);
        recordManager.promote(record, user);
        publishRecordPromotedEvents(record, userName);
        recordManager.releaseLock(record.getId());
        sessionManager.clearActiveRecord();
        if (isCurrentRecordIndexable()) {
            recordIndexService.permanentlyIndex(record);
        }
    } else {
        throw new IllegalStateException("The active record cannot be submitted: it is not in the exptected phase: " + exptectedStep);
    }
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) RecordStep(org.openforis.collect.event.RecordStep) Step(org.openforis.collect.model.CollectRecord.Step)

Example 5 with User

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

the class DataService method findAssignableCodeListItems.

/**
 * Gets the code list items assignable to the specified attribute.
 *
 * @param parentEntityId
 * @param attrName
 * @return
 */
@Secured(USER)
public List<CodeListItemProxy> findAssignableCodeListItems(int parentEntityId, String attrName) {
    CollectRecord record = getActiveRecord();
    CollectSurvey survey = (CollectSurvey) record.getSurvey();
    UserGroup surveyUserGroup = survey.getUserGroup();
    User user = sessionManager.getLoggedUser();
    final UserInGroup userInGroup = userGroupManager.findUserInGroupOrDescendants(surveyUserGroup, user);
    if (userInGroup == null) {
        throw new IllegalStateException(String.format("User %s not allowed to access survey %s", user.getUsername(), survey.getName()));
    }
    Entity parent = (Entity) record.getNodeByInternalId(parentEntityId);
    CodeAttributeDefinition def = (CodeAttributeDefinition) parent.getDefinition().getChildDefinition(attrName);
    List<CodeListItem> items = codeListManager.loadValidItems(parent, def);
    List<CodeListItem> filteredItems = new ArrayList<CodeListItem>(items);
    // filter by user group qualifier (if any)
    UserGroup group = userGroupManager.loadById(userInGroup.getGroupId());
    String qualifierName = group.getQualifier1Name();
    String listHierarchicalLevelName = def.getList().isHierarchical() ? def.getHierarchicalLevel() : def.getListName();
    if (qualifierName != null && qualifierName.equals(listHierarchicalLevelName)) {
        CollectionUtils.filter(filteredItems, new Predicate<CodeListItem>() {

            public boolean evaluate(CodeListItem item) {
                return item.getCode().equals(group.getQualifier1Value());
            }
        });
    }
    List<CodeListItemProxy> result = CodeListItemProxy.fromList(filteredItems);
    List<Node<?>> selectedCodes = parent.getChildren(attrName);
    CodeListItemProxy.setSelectedItems(result, selectedCodes);
    return result;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) User(org.openforis.collect.model.User) UserInGroup(org.openforis.collect.model.UserInGroup) Node(org.openforis.idm.model.Node) ArrayList(java.util.ArrayList) UserGroup(org.openforis.collect.model.UserGroup) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) CollectSurvey(org.openforis.collect.model.CollectSurvey) CodeListItem(org.openforis.idm.metamodel.CodeListItem) CodeListItemProxy(org.openforis.collect.metamodel.proxy.CodeListItemProxy) Secured(org.springframework.security.access.annotation.Secured)

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