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;
}
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();
}
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;
}
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);
}
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;
}
Aggregations