Search in sources :

Example 61 with User

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

the class RecordController method canDeleteRecords.

private boolean canDeleteRecords(int surveyId, Set<Integer> recordIds) {
    CollectSurvey survey = surveyManager.getById(surveyId);
    RecordFilter filter = new RecordFilter(survey);
    filter.setRecordIds(recordIds);
    List<CollectRecordSummary> recordSummaries = recordManager.loadSummaries(filter);
    User loggedUser = sessionManager.getLoggedUser();
    RecordAccessControlManager recordAccessControlManager = new RecordAccessControlManager();
    UserInGroup userInSurveyGroup = userGroupManager.findUserInGroupOrDescendants(survey.getUserGroup(), loggedUser);
    boolean canDeleteRecords = userInSurveyGroup != null && recordAccessControlManager.canDeleteRecords(loggedUser, userInSurveyGroup.getRole(), recordSummaries);
    return canDeleteRecords;
}
Also used : User(org.openforis.collect.model.User) UserInGroup(org.openforis.collect.model.UserInGroup) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) CollectSurvey(org.openforis.collect.model.CollectSurvey) RecordAccessControlManager(org.openforis.collect.manager.RecordAccessControlManager) RecordFilter(org.openforis.collect.model.RecordFilter)

Example 62 with User

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

the class DataService method demote.

protected void demote(Step toStep) throws RecordPersistenceException {
    sessionManager.checkIsActiveRecordLocked();
    SessionState sessionState = sessionManager.getSessionState();
    CollectRecord record = sessionState.getActiveRecord();
    Step fromStep = record.getStep();
    Step exptectedFromStep = toStep.getNext();
    if (exptectedFromStep != fromStep) {
        throw new IllegalStateException("The active record cannot be demoted: it is not in the exptected phase: " + exptectedFromStep);
    }
    CollectSurvey survey = sessionState.getActiveSurvey();
    String userName = sessionState.getUser().getUsername();
    User user = sessionState.getUser();
    Integer recordId = record.getId();
    publishRecordDeletedEvent(record, fromStep.toRecordStep(), userName);
    recordManager.demote(survey, recordId, record.getStep(), user);
    recordManager.releaseLock(recordId);
    sessionManager.clearActiveRecord();
}
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) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 63 with User

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

the class DataService method createRecord.

@Secured(ENTRY)
public RecordProxy createRecord(String rootEntityName, String versionName, Step recordStep) throws RecordPersistenceException, RecordIndexException {
    SessionState sessionState = sessionManager.getSessionState();
    if (sessionState.isActiveRecordBeingEdited()) {
        throw new MultipleEditException();
    }
    CollectSurvey activeSurvey = sessionState.getActiveSurvey();
    User user = sessionState.getUser();
    CollectRecord record = recordManager.instantiateRecord(activeSurvey, rootEntityName, user, versionName, recordStep);
    NodeChangeSet changeSet = recordManager.initializeRecord(record);
    List<RecordEvent> events = new EventProducer().produceFor(changeSet, user.getUsername());
    sessionManager.onEvents(events);
    sessionManager.setActiveRecord(record);
    prepareRecordIndexing();
    RecordProxy recordProxy = new RecordProxy(record, getProxyContext(), true);
    return recordProxy;
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord) NodeChangeSet(org.openforis.collect.model.NodeChangeSet) RecordProxy(org.openforis.collect.model.proxy.RecordProxy) User(org.openforis.collect.model.User) EventProducer(org.openforis.collect.event.EventProducer) MultipleEditException(org.openforis.collect.persistence.MultipleEditException) RecordEvent(org.openforis.collect.event.RecordEvent) CollectSurvey(org.openforis.collect.model.CollectSurvey) Secured(org.springframework.security.access.annotation.Secured)

Example 64 with User

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

the class DataService method saveActiveRecord.

@Transactional
@Secured(ENTRY_LIMITED)
public void saveActiveRecord() throws RecordPersistenceException, RecordIndexException {
    sessionManager.checkIsActiveRecordLocked();
    SessionState sessionState = sessionManager.getSessionState();
    CollectRecord record = sessionState.getActiveRecord();
    User user = sessionState.getUser();
    record.setModifiedDate(new Date());
    record.setModifiedBy(user);
    record.setOwner(user);
    String sessionId = sessionState.getSessionId();
    recordManager.save(record, sessionId);
    if (sessionManager.commitRecordFileChanges(record)) {
        recordManager.save(record, sessionId);
    }
    if (isCurrentRecordIndexable()) {
        recordIndexService.permanentlyIndex(record);
    }
    sessionEventDispatcher.recordSaved(record);
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) Date(java.util.Date) Secured(org.springframework.security.access.annotation.Secured) Transactional(org.springframework.transaction.annotation.Transactional)

Example 65 with User

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

the class SessionService method initSession.

/**
 * Set a locale (language, country) into the session state object
 *
 * @return map with user, sessionId
 * @throws DatabaseVersionNotCompatibleException
 */
// @Secured("isAuthenticated()")
public Map<String, Object> initSession(String locale) throws DatabaseVersionNotCompatibleException {
    databaseVersionManager.checkIsVersionCompatible();
    sessionManager.setLocale(locale);
    SessionState sessionState = sessionManager.getSessionState();
    User user = sessionState.getUser();
    UserProxy userProxy = new UserProxy(user);
    String sessionId = sessionState.getSessionId();
    Map<String, Object> result = new HashMap<String, Object>();
    result.put("user", userProxy);
    result.put("sessionId", sessionId);
    return result;
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) User(org.openforis.collect.model.User) HashMap(java.util.HashMap) UserProxy(org.openforis.collect.model.proxy.UserProxy)

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